Stonesjtu / pytorch_memlab

Profiling and inspecting memory in pytorch
MIT License
1.01k stars 37 forks source link

Nor working #50

Open cdcseacave opened 1 year ago

cdcseacave commented 1 year ago

for me it does not work at all I even tried your example code, without profiler does nothing, with profiler tag it does not compile, see bellow: image

Stonesjtu commented 1 year ago

you need to import the function at first

from pytorch_memlab import profile_every
cdcseacave commented 1 year ago

still does not produce any output:

import torch
from pytorch_memlab import LineProfiler
from pytorch_memlab import profile_every

@profile_every(1)
def inner():
    torch.nn.Linear(100, 100).cuda()

def outer():
    linear = torch.nn.Linear(100, 100).cuda()
    linear2 = torch.nn.Linear(100, 100).cuda()
    inner()

with LineProfiler(outer, inner) as prof:
    outer()
prof.display()

output:

ubuntu@65:~$ python prof.py
No data collected
Stonesjtu commented 1 year ago

try:

import torch
from pytorch_memlab import LineProfiler
from pytorch_memlab import profile_every

@profile_every(1)
def inner():
    torch.nn.Linear(100, 100).cuda()

def outer():
    linear = torch.nn.Linear(100, 100).cuda()
    linear2 = torch.nn.Linear(100, 100).cuda()
    inner()

outer()
cdcseacave commented 1 year ago
ubuntu@65:~$ python prof.py
## inner

active_bytes reserved_bytes line code
         all            all
        peak           peak
      80.00K          2.00M    5 @profile_every(1)
                               6 def inner():
     120.00K          2.00M    7     torch.nn.Linear(100, 100).cuda()