torch_mem_profile.py 707 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Christian Heider Nielsen"
  4. __doc__ = r"""
  5. Created on 31-10-2020
  6. """
  7. from pathlib import Path
  8. import torch
  9. from pytorch_memlab import LineProfiler
  10. from apppath import ensure_existence
  11. if __name__ == "__main__":
  12. def inner():
  13. """ """
  14. torch.nn.Linear(100, 100).cuda()
  15. def outer():
  16. """ """
  17. linear = torch.nn.Linear(100, 100).cuda()
  18. linear2 = torch.nn.Linear(100, 100).cuda()
  19. inner()
  20. with LineProfiler(outer, inner) as prof:
  21. outer()
  22. with open(ensure_existence(Path("exclude")) / "test.html", "w") as f:
  23. f.write(prof.display()._repr_html_())