pytorch_memlab icon indicating copy to clipboard operation
pytorch_memlab copied to clipboard

OSError: could not get source code when running LineProfiler

Open ewayuan opened this issue 2 years ago • 2 comments

Hi, when I trying to use the LineProfiler example, the following error message pops up:

import torch

from pytorch_memlab import LineProfiler

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() ... Traceback (most recent call last): File "", line 1, in File "/home/wyuancs/miniconda3/envs/response-selection/lib/python3.8/site-packages/pytorch_memlab/line_profiler/line_profiler.py", line 45, in init self.add_function(func) File "/home/wyuancs/miniconda3/envs/response-selection/lib/python3.8/site-packages/pytorch_memlab/line_profiler/line_profiler.py", line 59, in add_function first_line = inspect.getsourcelines(func)[1] File "/home/wyuancs/miniconda3/envs/response-selection/lib/python3.8/inspect.py", line 979, in getsourcelines lines, lnum = findsource(object) File "/home/wyuancs/miniconda3/envs/response-selection/lib/python3.8/inspect.py", line 798, in findsource raise OSError('could not get source code') OSError: could not get source code

How could I solve this problem? I tried to search online, but not find any solution

ewayuan avatar Apr 25 '22 03:04 ewayuan

Can you try copy-paste these lines into a python source file and then runs it.


before edit

Do you execute these codes in python xxx.py, python terminal, or ipython terminal ?

Stonesjtu avatar Apr 26 '22 08:04 Stonesjtu

Hi, Thanks for your reply. I'm using python xxx.py

ewayuan avatar May 08 '22 04:05 ewayuan