Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: could not get source code when running LineProfiler #46

Open
ewayuan opened this issue Apr 25, 2022 · 2 comments
Open

OSError: could not get source code when running LineProfiler #46

ewayuan opened this issue Apr 25, 2022 · 2 comments

Comments

@ewayuan
Copy link

ewayuan commented Apr 25, 2022

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

@Stonesjtu
Copy link
Owner

Stonesjtu commented Apr 26, 2022

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 ?

@ewayuan
Copy link
Author

ewayuan commented May 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants