Repository navigation
[precompile] Capture the caller's calls and keep their gradients - #195927
Closed
bobrenjc93 wants to merge 58 commits into
Closed
bobrenjc93 wants to merge 58 commits into
bobrenjc93 wants to merge 58 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195927
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 3, 2026
Closed
Closed
Closed
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
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):
A training example runs a real backward, which accumulates into the caller's
tensors. The dynamo session now snapshots and clears the gradients every
example could accumulate into before the calls and restores the SAME grad
objects afterwards, as the make_fx path already did, so a capture cannot
double the gradients of the documented warmup-step-then-capture flow;
keep_example_grads=True turns that off for a caller whose example IS their
live training step, and the make_fx tracer refuses it. The snapshot reads
.grad only off leaves and retained-grad tensors, so a non-leaf example input no
longer warns twice per capture. A graph the compiler short-circuited to
noop_graph_call is recorded as an eager artifact rather than reported as a
compiled graph that lost its code, and capture pins bypass_autograd_cache_key
so AOTAutogradCache no longer has to KEY a graph before it can be recorded.
The session also grows what the accumulating capture above this commit needs:
the enter exception path drains in-flight calls BEFORE any teardown and
runs the region cleanup in a finally; re-entering an active session raises
PackageError; a resumable session keeps its compiled region across cycles,
gates only on the errors the current cycle raised, and is torn down by
retire(); snapshot_artifact() renders everything captured so far from
policy-filtered copies of the code entries; collect_results/example_results
retain what each example call returned for the on-disk form.
Test Plan:
Authored with an AI assistant.
[no ci]