Skip to content

Fix codegen subclass wrapper dropping trailing args (e.g. rng state)#177202

Closed
aorenste wants to merge 1 commit intogh/aorenste/214/basefrom
gh/aorenste/214/head
Closed

Fix codegen subclass wrapper dropping trailing args (e.g. rng state)#177202
aorenste wants to merge 1 commit intogh/aorenste/214/basefrom
gh/aorenste/214/head

Conversation

@aorenste
Copy link
Copy Markdown
Contributor

@aorenste aorenste commented Mar 11, 2026

Stack from ghstack (oldest at bottom):

The codegen'd subclass wrapper only iterated over inp_metas when
building unwrapped_args, but FunctionalizedRngRuntimeWrapper appends
rng seed/offset to args after inp_metas. The old data-driven loop
in runtime_unwrap_tensor_subclasses passed these through because it
iterated over all args. Add an extend() call to forward any trailing
args not covered by inp_metas.

Authored with Claude.

The codegen'd subclass wrapper only iterated over inp_metas when
building unwrapped_args, but FunctionalizedRngRuntimeWrapper appends
rng seed/offset to args after inp_metas. The old data-driven loop
in runtime_unwrap_tensor_subclasses passed these through because it
iterated over all args. Add an extend() call to forward any trailing
args not covered by inp_metas.

Authored with Claude.

[ghstack-poisoned]
@aorenste aorenste requested a review from bdhirsh as a code owner March 11, 2026 21:42
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 11, 2026

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit dff529c with merge base 3d71ad9 (image):

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 11, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

aorenste added a commit that referenced this pull request Mar 11, 2026
The codegen'd subclass wrapper only iterated over inp_metas when
building unwrapped_args, but FunctionalizedRngRuntimeWrapper appends
rng seed/offset to args after inp_metas. The old data-driven loop
in runtime_unwrap_tensor_subclasses passed these through because it
iterated over all args. Add an extend() call to forward any trailing
args not covered by inp_metas.

Authored with Claude.

ghstack-source-id: 5e2d54b
Pull Request resolved: #177202
@aorenste aorenste added ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Mar 11, 2026
@aorenste aorenste requested review from Lucaskabela and huydhn March 11, 2026 21:46
)
_codegen_unwrap_subclass(state, meta, inp_var, indent=1)

# Pass through any trailing args not covered by inp_metas
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are no trailing args here? i.e len(inp_metas) == len(args)? Should we gate this emit behind that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - looking closer... it looks like we're supposed to pass along extra runtime parameters - so we don't know at codegen time how many extra there will be.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think this PR is good then - just wanted to make sure we did the diligence to think of this case :)

@aorenste aorenste requested a review from Lucaskabela March 12, 2026 01:46
)
_codegen_unwrap_subclass(state, meta, inp_var, indent=1)

# Pass through any trailing args not covered by inp_metas
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think this PR is good then - just wanted to make sure we did the diligence to think of this case :)

@aorenste
Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
…ytorch#177202)

The codegen'd subclass wrapper only iterated over inp_metas when
building unwrapped_args, but FunctionalizedRngRuntimeWrapper appends
rng seed/offset to args after inp_metas. The old data-driven loop
in runtime_unwrap_tensor_subclasses passed these through because it
iterated over all args. Add an extend() call to forward any trailing
args not covered by inp_metas.

Authored with Claude.
Pull Request resolved: pytorch#177202
Approved by: https://github.com/Lucaskabela
@github-actions github-actions bot deleted the gh/aorenste/214/head branch April 12, 2026 02:25
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 Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants