Skip to content

Commit

Permalink
Make start compiling stack trace omit framework frames (#119251)
Browse files Browse the repository at this point in the history
Summary:
Fixes pytorch/pytorch#119238

Here's what it looks like now:

```
$ TORCH_LOGS=+torch._dynamo.convert_frame python a.py
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG] torchdynamo start compiling f /data/users/ezyang/b/pytorch/a.py:3, stack (elided 5 frames):
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG]   File "/data/users/ezyang/b/pytorch/a.py", line 7, in <module>
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG]     f(torch.randn(2))
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG]   File "/data/users/ezyang/b/pytorch/torch/_dynamo/eval_frame.py", line 453, in _fn
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG]     return fn(*args, **kwargs)
[2024-02-05 18:52:07,248] [0/0] torch._dynamo.convert_frame: [DEBUG]
$ cat a.py
import torch

torch.compile
def f(x):
    return x * 2

f(torch.randn(2))
```

The eval_frame frame is intentionally present, since what happens is you run the torch.compile wrapper, and then you actually hit the user frame to be compiled.

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

X-link: pytorch/pytorch#119251
Approved by: https://github.com/yanboliang, https://github.com/mlazos

Reviewed By: atalman

Differential Revision: D53498616

Pulled By: ezyang

fbshipit-source-id: b859ce4cd32970a5c60094b90ece9946130a3c6f
  • Loading branch information
ezyang authored and facebook-github-bot committed Feb 7, 2024
1 parent 71cc87a commit 46188bf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion userbenchmark/dynamo/dynamobench/_dynamo/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def debug_dump(name, code: types.CodeType, extra="") -> None:
)


def debug_insert_nops(frame, cache_size, hooks, _) -> Optional[GuardedCode]:
def debug_insert_nops(
frame, cache_size, hooks, _, *, skip: int = 0
) -> Optional[GuardedCode]:
"""used to debug jump updates"""

def insert_nops(instructions, code_options):
Expand Down

0 comments on commit 46188bf

Please sign in to comment.