Repository navigation
[dynamo] Guard autocast objects by value rather than identity - #193976
Closed
bobrenjc93 wants to merge 2 commits into
Closed
bobrenjc93 wants to merge 2 commits into
bobrenjc93 wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193976
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit 601fded with merge base 1b4e490 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 18, 2026
bobrenjc93
marked this pull request as draft
August 18, 2026 17:53
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
bobrenjc93
added a commit
that referenced
this pull request
Aug 19, 2026
Fifth of six fixes the precompile PR at the top of this stack needs, and a correctness fix for plain torch.compile on its own. A `torch.amp.autocast` object the user holds and reuses reaches the trace as four specialized values -- device, dtype, enabled, cache_enabled -- but the guard installed on it was `ID_MATCH` on the object. That is wrong in both directions. It is too strong for serialization: an address cannot be written to an artifact, so a precompile drops the guard, and a sibling instance holding a different autocast object then silently selects this graph. It is also too weak for the live case, because mutating the object in place leaves the address alone and the stale graph keeps serving. Guard the four fields the trace already specialized on instead. That is what the graph actually depends on, so it is the precise condition, and it serializes. Test Plan: The regression test compiles a module holding an autocast object, then mutates `fast_dtype` on that same object; an id() guard cannot see the change, so without this the second call keeps returning bf16. ``` python test/dynamo/test_ctx_manager.py python test/dynamo/test_misc.py python test/dynamo/test_guard_serialization.py ``` Authored with an AI assistant. ghstack-source-id: e285672 Pull-Request: #193976
bobrenjc93
added a commit
that referenced
this pull request
Aug 20, 2026
Fifth of six fixes the precompile PR at the top of this stack needs, and a correctness fix for plain torch.compile on its own. A `torch.amp.autocast` object the user holds and reuses reaches the trace as four specialized values -- device, dtype, enabled, cache_enabled -- but the guard installed on it was `ID_MATCH` on the object. That is wrong in both directions. It is too strong for serialization: an address cannot be written to an artifact, so a precompile drops the guard, and a sibling instance holding a different autocast object then silently selects this graph. It is also too weak for the live case, because mutating the object in place leaves the address alone and the stale graph keeps serving. Guard the four fields the trace already specialized on instead. That is what the graph actually depends on, so it is the precise condition, and it serializes. Test Plan: The regression test compiles a module holding an autocast object, then mutates `fast_dtype` on that same object; an id() guard cannot see the change, so without this the second call keeps returning bf16. ``` python test/dynamo/test_ctx_manager.py python test/dynamo/test_misc.py python test/dynamo/test_guard_serialization.py ``` Authored with an AI assistant. ghstack-source-id: e285672 Pull-Request: #193976
bobrenjc93
added a commit
that referenced
this pull request
Aug 20, 2026
Fifth of six fixes the precompile PR at the top of this stack needs, and a correctness fix for plain torch.compile on its own. A `torch.amp.autocast` object the user holds and reuses reaches the trace as four specialized values -- device, dtype, enabled, cache_enabled -- but the guard installed on it was `ID_MATCH` on the object. That is wrong in both directions. It is too strong for serialization: an address cannot be written to an artifact, so a precompile drops the guard, and a sibling instance holding a different autocast object then silently selects this graph. It is also too weak for the live case, because mutating the object in place leaves the address alone and the stale graph keeps serving. Guard the four fields the trace already specialized on instead. That is what the graph actually depends on, so it is the precise condition, and it serializes. Test Plan: The regression test compiles a module holding an autocast object, then mutates `fast_dtype` on that same object; an id() guard cannot see the change, so without this the second call keeps returning bf16. ``` python test/dynamo/test_ctx_manager.py python test/dynamo/test_misc.py python test/dynamo/test_guard_serialization.py ``` Authored with an AI assistant. ghstack-source-id: e285672 Pull-Request: #193976
This was referenced Aug 20, 2026
Closed
Closed
This was referenced Aug 22, 2026
Closed
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
1 similar comment
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Fifth of six fixes the precompile PR at the top of this stack needs, and a
correctness fix for plain torch.compile on its own.
A
torch.amp.autocastobject the user holds and reuses reaches the trace asfour specialized values -- device, dtype, enabled, cache_enabled -- but the
guard installed on it was
ID_MATCHon the object. That is wrong in bothdirections. It is too strong for serialization: an address cannot be written to
an artifact, so a precompile drops the guard, and a sibling instance holding a
different autocast object then silently selects this graph. It is also too weak
for the live case, because mutating the object in place leaves the address
alone and the stale graph keeps serving.
Guard the four fields the trace already specialized on instead. That is what
the graph actually depends on, so it is the precise condition, and it
serializes.
Test Plan:
The regression test compiles a module holding an autocast object, then mutates
fast_dtypeon that same object; an id() guard cannot see the change, sowithout this the second call keeps returning bf16.
Authored with an AI assistant.
Differential Revision: D116528371