Skip to content

[guards] Keep a wrapper subclass's requires_grad across guard serialization - #194318

Closed
bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1017/basefrom
gh/bobrenjc93/1017/head
Closed

bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1017/basefrom
gh/bobrenjc93/1017/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A traceable wrapper subclass is reconstructed by __tensor_unflatten__, which
derives the outer tensor's autograd metadata from its inner tensors. For a
subclass whose outer requires_grad is not implied by any inner -- a
TwoTensor built from two non-grad halves and then
requires_grad_(True)'d -- that loses the flag, and the rebuilt TENSOR_MATCH
then demands requires_grad=0 from every input. The artifact serves nothing
in training, permanently and silently: the guard simply never matches.

The producer side also differed from the dense-tensor branch, which passes
requires_grad=obj.requires_grad to empty_like while this one did not, so
the bit was not even recorded. Both halves are needed; the load side is the one
that does the work.

Setting the flag is conditional because doing it on a non-leaf raises, and a
subclass whose inners DO require grad already comes back with a correct
non-leaf outer.

Narrower than it sounds: DTensor is unaffected, since its outer flag is implied
by _local_tensor.

Test Plan:

python test/dynamo/test_guard_serialization.py
python test/test_precompile.py

The new test builds the case the existing subclass coverage misses -- inners
that do not require grad under an outer that does -- and asserts both that the
loaded manager accepts the captured tensor and that it still rejects one
without the flag, so it cannot pass by simply dropping the check.

Authored with an AI assistant.

Differential Revision: D116884332

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194318

Note: Links to docs will display an error until the docs builds have been completed.

❌ 24 New Failures, 1 Unrelated Failure

As of commit 380213f with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have 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.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 21, 2026
This was referenced Aug 21, 2026
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 21, 2026
This was referenced Aug 22, 2026
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362; this change lives in #195362 (with the guard-drop policy half in #195360). Closing to consolidate review there. The branch is kept on GitHub.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1017/head branch November 12, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request module: dynamo topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant