6aba126f1e
Update
...
[ghstack-poisoned]
2025-10-19 17:06:08 +00:00
568d2f3ae7
[Dynamo][Logging] Add sources/types to LazyVariableTracker logging ( #165402 )
...
Fixes #162860
This task add the variable source attrition to LazyVariableTracker when output trace bytecode
Test plan -- test/dynamo/test_error_messages.py ErrorMessagesTest.test_variable_tracker_source_attribution
The output is as specified in the prior mentioned Github issue.
<img width="961" height="59" alt="Screenshot 2025-10-13 at 10 19 44 PM" src="https://github.com/user-attachments/assets/fb27da3f-d00b-437b-bf2e-52e892572cd7 " />
This is specifically for the log setup with ``TORCH_LOGS=trace_bytecode``
Pull Request resolved: https://github.com/pytorch/pytorch/pull/165402
Approved by: https://github.com/Lucaskabela , https://github.com/williamwen42
Co-authored-by: William Wen <williamwen@meta.com >
2025-10-15 23:23:09 +00:00
dec9a59992
[dynamo][logging] Add most recent bytecode to graph break with torch._dynamo.graph_break() and verbose ( #164422 )
...
https://github.com/pytorch/pytorch/issues/162858 The issue described the feature implemented.
This adds to the existing graph break log with the latest 20 (or viable user frame) bytecode instructions. The scenario is when the graph_break happens without errors. It happens during the case when user calling torch._dynamo.graph_break().
Meanwhile, in the testing, one can find that the generated frame based on step() is not deterministic as sometimes it reached the maximum amount, sometimes it generated the less than that. The bytecode generation is python version dependent. Thus, the testing plan excludes the bytecode output but generated the total bytecode line count.
This is a helpful process to understand bytecode transformation, symbolic convert, and convert frame. It is a helpful task to provide hands-on experience with dynamo workflow.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164422
Approved by: https://github.com/williamwen42 , https://github.com/mlazos
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com >
2025-10-10 17:33:06 +00:00
af4c29fea8
[dynamo, nested graph breaks] fix nested step graph break related issues ( #162737 )
...
Turns out codegen'ing a nested step graph break is significantly more complicated than first thought. The optimized function should actually do:
- call graph/load values/do side effects etc.
- call into the leaf's resume function, but skipped (this essentially step graph break function for just the leaf function)
- call into all the other resume functions, traced.
This PR also adds `torch._dynamo.step_unsupported()`, which can be used for internal testing purposes to better test step graph break handling.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162737
Approved by: https://github.com/Lucaskabela
ghstack dependencies: #160601
2025-10-08 22:02:52 +00:00
486b4d2414
[dynamo, nested graph breaks] move cell codegen before side effects codegen ( #160601 )
...
This is needed because if we codegen cells for nested frames AFTER side effects, then reconstruction could get messed up. From below:
>The added test case demonstrates the reconstruction failure if we kept cell codegen at the original place (only happens with nested graph breaks since we reconstruct nested frame cells from VariableTracker rather than directly using LOAD_CLOSURE).
>At a high level, what happened before this change was that side_effects was pruning the cells (I don't recall exactly why this happens), and because cells were codegen'd after the side effects were applied, we were unable to properly reconstruct the cell. The error I was seeing was a list/tuple IndexError.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/160601
Approved by: https://github.com/mlazos
2025-10-08 22:02:52 +00:00
c855f8632e
Pyrefly suppressions 7/n ( #164913 )
...
Adds suppressions to pyrefly will typecheck clean: https://github.com/pytorch/pytorch/issues/163283
Almost there!
Test plan:
dmypy restart && python3 scripts/lintrunner.py -a
pyrefly check
step 1: delete lines in the pyrefly.toml file from the project-excludes field
step 2: run pyrefly check
step 3: add suppressions, clean up unused suppressions
before: https://gist.github.com/maggiemoss/4b3bf2037014e116bc00706a16aef199
after:
INFO 0 errors (6,884 ignored)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164913
Approved by: https://github.com/oulgen
2025-10-08 07:27:17 +00:00
fd3e15c14f
Fix typo in class definition of bytecodedispatchtable ( #164762 )
...
ghstack-source-id: 84f0d7bb7e3780ca75473782abfae530010be56e
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164761
Fixes the type in naming of bytecodedispatchtable
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164762
Approved by: https://github.com/StrongerXi , https://github.com/williamwen42
2025-10-07 04:36:09 +00:00
5a66ff4915
[dynamo, 3.14] fix _detect_and_normalize_assert_statement for 3.14 ( #164005 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164005
Approved by: https://github.com/anijain2305 , https://github.com/atalman
2025-10-03 22:07:54 +00:00
69c5c08a01
Revert "[dynamo, 3.14] fix _detect_and_normalize_assert_statement for 3.14 ( #164005 )"
...
This reverts commit 5ed4672477c71492a2f41ac0395dd0630446d6a5.
Reverted https://github.com/pytorch/pytorch/pull/164005 on behalf of https://github.com/williamwen42 due to broke some tests e.g. https://github.com/meta-pytorch/autoparallel/actions/runs/18167350261/job/51719783636?pr=179 ([comment](https://github.com/pytorch/pytorch/pull/164005#issuecomment-3357433475 ))
2025-10-01 17:47:22 +00:00
cc8b14d09a
[2/N] Simplify "in" operation for containers of a single item ( #164323 )
...
These issues are detected by ruff [FURB171](https://docs.astral.sh/ruff/rules/single-item-membership-test/#single-item-membership-test-furb171 ).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164323
Approved by: https://github.com/justinchuby , https://github.com/Skylion007
2025-10-01 05:39:11 +00:00
5ed4672477
[dynamo, 3.14] fix _detect_and_normalize_assert_statement for 3.14 ( #164005 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164005
Approved by: https://github.com/anijain2305
ghstack dependencies: #161838 , #161555 , #161839 , #163009 , #163109 , #163110 , #163191 , #163292 , #163796 , #163818 , #163919 , #163920 , #164004
2025-09-30 17:43:03 +00:00
0657de9c61
[dynamo, 3.14] support LOAD_COMMON_CONSTANT ( #163919 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163919
Approved by: https://github.com/anijain2305 , https://github.com/mlazos
ghstack dependencies: #161838 , #161555 , #161839 , #163009 , #163109 , #163110 , #163191 , #163292 , #163796 , #163818
2025-09-30 17:42:47 +00:00
9278b18ec0
[dynamo, 3.14] fix WITH_EXCEPT_START ( #163292 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163292
Approved by: https://github.com/anijain2305
ghstack dependencies: #161838 , #161555 , #161839 , #163009 , #163109 , #163110 , #163191
2025-09-30 17:42:26 +00:00
44677ad917
[dynamo, 3.14] support LOAD_CONST on slice, codegen LOAD_CONST slice instead of BINARY/STORE_SLICE ( #163110 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163110
Approved by: https://github.com/anijain2305
ghstack dependencies: #161838 , #161555 , #161839 , #163009 , #163109
2025-09-30 17:42:11 +00:00
1c9987fdf4
[dynamo, 3.14] fix context managers ( #163109 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163109
Approved by: https://github.com/anijain2305 , https://github.com/mlazos
ghstack dependencies: #161838 , #161555 , #161839 , #163009
2025-09-30 17:42:03 +00:00
7cbc011700
[dynamo, 3.14] support some bytecodes, fix CALL_FUNCTION_EX ( #163009 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163009
Approved by: https://github.com/anijain2305
ghstack dependencies: #161838 , #161555 , #161839
2025-09-30 17:41:56 +00:00
09c774145e
[dynamo, 3.14] Python dynamo changes to get basic programs working ( #161839 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161839
Approved by: https://github.com/Lucaskabela , https://github.com/anijain2305
ghstack dependencies: #161838 , #161555
2025-09-30 17:41:49 +00:00
f9fa138a39
[BE] Delete all pre py-3.10 checks ( #163653 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163653
Approved by: https://github.com/jansel
ghstack dependencies: #163648 , #163649
2025-09-23 23:22:53 +00:00
7dcb568c8f
Turn on capture_scalar_outputs when fullgraph=True ( #163121 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163121
Approved by: https://github.com/laithsakka
2025-09-18 21:24:15 +00:00
b26d4c9a7a
Make dynamo preserving stack trace work with inlined nn modules ( #162992 )
...
Differential Revision: [D82478646](https://our.internmc.facebook.com/intern/diff/D82478646 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162992
Approved by: https://github.com/williamwen42
ghstack dependencies: #162557 , #162558 , #162559 , #162682
2025-09-18 00:43:23 +00:00
559e8d1c20
[doc]: Small typos ( #162982 )
...
Small typo fixes
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162982
Approved by: https://github.com/ezyang , https://github.com/zou3519
2025-09-16 17:42:19 +00:00
5ac112b569
[dynamo] Graph break on on user-defined class in compiled region ( #161670 )
...
Currently, user-defined classes inside of a compiled frame will cause the whole
frame to be skipped by dynamo. This change defers the Unsupported exception
until the __build_class__ builtin is actually called, which allows a graph break
to be inserted.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161670
Approved by: https://github.com/williamwen42 , https://github.com/guilhermeleobas
2025-09-10 04:39:20 +00:00
a3e26d1727
Revert "[dynamo] Graph break on on user-defined class in compiled region ( #161670 )"
...
This reverts commit e2545487de3dbbe663e3f0adb699547a14da0f6a.
Reverted https://github.com/pytorch/pytorch/pull/161670 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it is failing a trunk test ([comment](https://github.com/pytorch/pytorch/pull/161670#issuecomment-3272626391 ))
2025-09-09 23:40:26 +00:00
e2545487de
[dynamo] Graph break on on user-defined class in compiled region ( #161670 )
...
Currently, user-defined classes inside of a compiled frame will cause the whole
frame to be skipped by dynamo. This change defers the Unsupported exception
until the __build_class__ builtin is actually called, which allows a graph break
to be inserted.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161670
Approved by: https://github.com/williamwen42 , https://github.com/guilhermeleobas
2025-09-09 21:07:49 +00:00
0ff8eabf13
Revert "[dynamo] Graph break on on user-defined class in compiled region ( #161670 )"
...
This reverts commit 146371483318e17929daefd37c8e459d9d6d47bb.
Reverted https://github.com/pytorch/pytorch/pull/161670 on behalf of https://github.com/jeanschmidt due to seems to have introduced https://github.com/pytorch/pytorch/actions/runs/17507127561/job/49733379267 and https://github.com/pytorch/pytorch/actions/runs/17507127561/job/49733379271 ([comment](https://github.com/pytorch/pytorch/pull/161670#issuecomment-3261241229 ))
2025-09-06 06:18:57 +00:00
1463714833
[dynamo] Graph break on on user-defined class in compiled region ( #161670 )
...
Currently, user-defined classes inside of a compiled frame will cause the whole
frame to be skipped by dynamo. This change defers the Unsupported exception
until the __build_class__ builtin is actually called, which allows a graph break
to be inserted. Fixes #161562
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161670
Approved by: https://github.com/williamwen42 , https://github.com/guilhermeleobas
2025-09-06 00:04:57 +00:00
f36f285953
[dynamo] change error_on_graph_break/fullgraph semantics ( #161747 )
...
This PR implements the semantics change to `torch._dynamo.error_on_graph_break`:
- ~`torch.compile` now has a new `error_on_graph_break` kwarg that serves as a lower-priority toggle for erroring/continuing on graph breaks~
- `error_on_graph_break` is a new internal `torch.compile `setting that is lower-priority than `fullgraph`. It allows the user to toggle erroring/continuing on graph breaks.
- `error_on_graph_break` does nothing when `fullgraph=True`
- `error_on_graph_break` does NOT guarantee a single graph
Followup [DONE]: need to change the programming model docs to reflect the 3 graph break modes for compilation:
- `fullgraph=True`: enforce one graph, no graph breaks, cannot be toggled
- `fullgraph=False, error_on_graph_break=True`: errors on graph breaks, latter can be toggled during compile time
- `fullgraph=False, error_on_graph_break=False`: resumes tracing on graph breaks, latter can be toggled during compile time
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161747
Approved by: https://github.com/mlazos
ghstack dependencies: #161739
2025-09-04 17:10:17 +00:00
480c739112
Capture TypeError in CONTAINS_OP
( #161069 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161069
Approved by: https://github.com/anijain2305
2025-09-04 04:49:09 +00:00
d5643e8f3a
[dynamo, nested graph breaks] support nested graph breaks that cause skipped frames ( #160470 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/160470
Approved by: https://github.com/anijain2305
ghstack dependencies: #159329 , #159678 , #159817 , #160138 , #159786
2025-09-03 02:47:07 +00:00
1041805c1e
[dynamo, nested graph breaks] prevent excessive recompilations ( #159786 )
...
Nested continuation function code objects are now unique w.r.t. stack trace below (and including) the current code object.
Without this change, e.g. in the added test, `f3` would be recompiled on the second graph break.
Followup: we can skip guards on continuation functions.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159786
Approved by: https://github.com/anijain2305
ghstack dependencies: #159329 , #159678 , #159817 , #160138
2025-08-27 21:53:37 +00:00
6562646dab
[dynamo, nested graph breaks] clean up comments and codegen ( #160138 )
...
Fix comments to reflect that we no longer codegen cells to be sent to resume function as inputs - they are instead codegen'd after the unsupported instruction in order to build resume functions that are closures.
Also simplify some codegen.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/160138
Approved by: https://github.com/anijain2305
ghstack dependencies: #159329 , #159678 , #159817
2025-08-27 21:53:37 +00:00
d0a242e547
[dynamo, nested graph breaks] support nested closures ( #159817 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159817
Approved by: https://github.com/anijain2305
ghstack dependencies: #159329 , #159678
2025-08-27 21:53:37 +00:00
3f8090809f
[dynamo, nested graph breaks] support nested graph breaks x context managers ( #159678 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159678
Approved by: https://github.com/anijain2305
ghstack dependencies: #159329
2025-08-27 21:53:37 +00:00
10d93325b1
[dynamo, nested graph breaks] support very simple nested graph breaks ( #159329 )
...
e.g. this graph breaks once now:
```python
import torch
torch._dynamo.config.nested_graph_breaks = True
def inner(x):
x = x + 1
torch._dynamo.graph_break()
return x + 2
@torch.compile(backend="eager")
def outer(x):
return inner(x)
print(outer(torch.ones(3)))
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159329
Approved by: https://github.com/anijain2305
2025-08-27 21:53:37 +00:00
7c8f049d54
[OrderedDict] Implement OrderedDict.move_to_end(key, last=False)
( #155152 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155152
Approved by: https://github.com/anijain2305
ghstack dependencies: #160156 , #155072
2025-08-27 15:46:40 +00:00
8b78ba07b1
[dynamo, nested graph breaks] add nested graph break tests ( #144516 )
...
Note: nested graph break tests (and wrapped tests) are xfailed/skipped for now - we will iteratively enable the tests as more of the nested graph break implementation is complete.
Differential Revision: [D81084809](https://our.internmc.facebook.com/intern/diff/D81084809 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144516
Approved by: https://github.com/anijain2305
2025-08-27 03:00:56 +00:00
6686974ddd
Revert "[dynamo, nested graph breaks] add nested graph break tests ( #144516 )"
...
This reverts commit 9a756c2d710a0680bac93ab0b42db519ec2dc6cf.
Reverted https://github.com/pytorch/pytorch/pull/144516 on behalf of https://github.com/atalman due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/144516#issuecomment-3225659358 ))
2025-08-26 20:40:17 +00:00
a4fb65701b
Revert "[dynamo, nested graph breaks] support very simple nested graph breaks ( #159329 )"
...
This reverts commit 8dab6d4c414bf997297804008c3da893e69cd51f.
Reverted https://github.com/pytorch/pytorch/pull/159329 on behalf of https://github.com/atalman due to failing internally ([comment](https://github.com/pytorch/pytorch/pull/159329#issuecomment-3225617445 ))
2025-08-26 20:24:10 +00:00
6afd766401
Revert "[dynamo, nested graph breaks] support nested graph breaks x context managers ( #159678 )"
...
This reverts commit 02fa5bf6d80fa4baa6bb6dd2fa6a16d88852da91.
Reverted https://github.com/pytorch/pytorch/pull/159678 on behalf of https://github.com/atalman due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/159678#issuecomment-3225597425 ))
2025-08-26 20:16:36 +00:00
a7aa480e55
Revert "[dynamo, nested graph breaks] support nested closures ( #159817 )"
...
This reverts commit ef0ef6f93f7ef6d16d71a6997b72185504acd4b6.
Reverted https://github.com/pytorch/pytorch/pull/159817 on behalf of https://github.com/atalman due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/159817#issuecomment-3225586996 ))
2025-08-26 20:13:33 +00:00
caf98fde0d
Revert "[dynamo, nested graph breaks] clean up comments and codegen ( #160138 )"
...
This reverts commit ac6316caaa74513cbcf3c7f9269bc23cd74749db.
Reverted https://github.com/pytorch/pytorch/pull/160138 on behalf of https://github.com/atalman due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/160138#issuecomment-3225546707 ))
2025-08-26 20:01:26 +00:00
46576f5a16
Revert "[dynamo, nested graph breaks] prevent excessive recompilations ( #159786 )"
...
This reverts commit 67d31f6b281d3b15b205756fc7ebc450cdde1dab.
Reverted https://github.com/pytorch/pytorch/pull/159786 on behalf of https://github.com/atalman due to failing internal tests ([comment](https://github.com/pytorch/pytorch/pull/159786#issuecomment-3225535752 ))
2025-08-26 19:54:22 +00:00
74124d1b46
[reland] [dynamo] Refactor convert_frame.compile_frame to be self contained function. [5/n] ( #161514 )
...
Summary:
convert_frame.compile_frame used to take a callback transform function which will capture the frame object it has, but the frame information is not passed directly into compile_frame function.
This PR changes the signature of compile_frame so that frame information is directly passed in the function without taking a callback. This makes it easier to build fullgraph capture API on top of compile_frame.
Test Plan:
CI
Rollback Plan:
Differential Revision: D81041296
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161514
Approved by: https://github.com/tugsbayasgalan
2025-08-26 19:16:05 +00:00
e795450a35
Revert "[dynamo] Refactor convert_frame.compile_frame to be self contained function. [5/n] ( #160900 )"
...
This reverts commit 447d34b5f80fb7350f79decd855cb599cab39083.
Reverted https://github.com/pytorch/pytorch/pull/160900 on behalf of https://github.com/atalman due to reverting since can't land existing diff internally, will need to reland it ([comment](https://github.com/pytorch/pytorch/pull/160900#issuecomment-3224029031 ))
2025-08-26 12:45:59 +00:00
67d31f6b28
[dynamo, nested graph breaks] prevent excessive recompilations ( #159786 )
...
Nested continuation function code objects are now unique w.r.t. stack trace below (and including) the current code object.
Without this change, e.g. in the added test, `f3` would be recompiled on the second graph break.
Followup: we can skip guards on continuation functions.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159786
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281 , #144516 , #159329 , #159678 , #159817 , #160138
2025-08-26 00:58:38 +00:00
ac6316caaa
[dynamo, nested graph breaks] clean up comments and codegen ( #160138 )
...
Fix comments to reflect that we no longer codegen cells to be sent to resume function as inputs - they are instead codegen'd after the unsupported instruction in order to build resume functions that are closures.
Also simplify some codegen.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/160138
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281 , #144516 , #159329 , #159678 , #159817
2025-08-26 00:58:38 +00:00
ef0ef6f93f
[dynamo, nested graph breaks] support nested closures ( #159817 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159817
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281 , #144516 , #159329 , #159678
2025-08-26 00:58:28 +00:00
02fa5bf6d8
[dynamo, nested graph breaks] support nested graph breaks x context managers ( #159678 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159678
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281 , #144516 , #159329
2025-08-26 00:58:18 +00:00
8dab6d4c41
[dynamo, nested graph breaks] support very simple nested graph breaks ( #159329 )
...
e.g. this graph breaks once now:
```python
import torch
torch._dynamo.config.nested_graph_breaks = True
def inner(x):
x = x + 1
torch._dynamo.graph_break()
return x + 2
@torch.compile(backend="eager")
def outer(x):
return inner(x)
print(outer(torch.ones(3)))
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159329
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281 , #144516
2025-08-26 00:58:07 +00:00
9a756c2d71
[dynamo, nested graph breaks] add nested graph break tests ( #144516 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144516
Approved by: https://github.com/anijain2305
ghstack dependencies: #157971 , #159281
2025-08-26 00:57:58 +00:00