Which files to set the breakpoints in?
vimarsh6739 opened this issue · 12 comments
Hi, I'm trying to use depyf
on the following example(it is a simplified form of the README with only the eager backend).
import torch
from torch import _dynamo as torchdynamo
from typing import List
@torch.compile(backend="eager")
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
def main():
for _ in range(100):
toy_example(torch.randn(10), torch.randn(10))
if __name__ == "__main__":
import depyf
with depyf.prepare_debug("./dump_src_dir"):
main()
with depyf.debug():
main()
It produces the following output in ./dump_src_dir
➜ dump_src_dir ls
'__compiled_fn_0 Captured Graph 0.py' full_code_for_toy_example_0.py __transformed_code_1_for_torch_dynamo_resume_in_toy_example_at_8.py
'__compiled_fn_3 Captured Graph 0.py' __transformed_code_0_for_torch_dynamo_resume_in_toy_example_at_8.py
'__compiled_fn_4 Captured Graph 0.py' __transformed_code_0_for_toy_example.py
Which files am I supposed to set the breakpoints in? The code just falls through no matter where I set the breakpoint.
Oh I see. Is it necessary to use VSCode/VS here? I'm manually setting the breakpoint after opening the file in vim (using breakpoint()
).
Do you use pdb
in vim? Sorry but I don't know how to use vim for debugging :( Not sure what would be wrong with vim.
Yes, I'm using pdb
. breakpoint()
implicitly calls pdb.set_trace()
(according to the docs here).
By "manually setting breakpoint", do you mean you modify the code to add breakpoint()
? That would not work though. You need to set breakpoint using debuggers. You can use pdb
b file:line
.
These *.py
files are not executed directly by Python. And the modification you made to them will not take any effect.
Oh ok, so if I want to use pdb, should I set a breakpoint()
before calling main()
in the depyf.debug()
context window?
This seems to work. I'm closing this. Thank you for the quick response!
I essentially set a breakpoint()
in the original code like this.
with depyf.debug():
breakpoint()
main()
Wow that's a good solution 👍
@vimarsh6739 I added a breakpoint
inside depyf.debug
, so you don't have to add one any more! In addition, the program does not ask for input, so pdb
users should be happy now. Try it out!
I just pulled in the updates, and this seems to work! Thanks for this.