Skip to content

[dynamo] Prevent recompile on hoistable opaque objects#176643

Closed
anijain2305 wants to merge 4 commits intogh/anijain2305/1069/basefrom
gh/anijain2305/1069/head
Closed

[dynamo] Prevent recompile on hoistable opaque objects#176643
anijain2305 wants to merge 4 commits intogh/anijain2305/1069/basefrom
gh/anijain2305/1069/head

Conversation

@anijain2305
Copy link
Contributor

@anijain2305 anijain2305 commented Mar 5, 2026

Stack from ghstack (oldest at bottom):

Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @Lucaskabela @jataylo

…raph reuse

Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 5, 2026

🔗 Helpful Links

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

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

✅ You can merge normally! (6 Unrelated Failures)

As of commit 0ed8bab with merge base 0857433 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

pytorch-bot bot commented Mar 5, 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.

)

gm = inline_invoke_subgraph(gm)
with dynamo_timed("inline_invoke_subgraph"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to this PR - but I hope its ok. In case, anyone has objections, I can open a new PR.

@anijain2305 anijain2305 requested review from angelayi and zou3519 and removed request for zou3519 March 5, 2026 20:47
@anijain2305 anijain2305 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Mar 6, 2026
…le for subgraph reuse"

Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
@anijain2305 anijain2305 changed the title [dynamo] Track ctor_arg_sources on TorchScriptObjectVariable for subgraph reuse [dynamo] Prevent recompile on hoistable opaque objects Mar 6, 2026
Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
@anijain2305 anijain2305 requested a review from angelayi March 6, 2026 19:16
@anijain2305
Copy link
Contributor Author

@angelayi Thanks for the review. I changed the implementation to further support no recompiles on opaque objects.

Comment on lines +183 to +186
if should_hoist(self.value):
with tx.output.tracing_context.guards_context.skip_guard_install():
constant_args = var_args.as_python_constant()
constant_kwargs = var_kwargs.as_python_constant()
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to distinguish between if self.value has a source or not here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we don't because the tests are all passing and I do have a test for this somewhere

Copy link
Contributor

Choose a reason for hiding this comment

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

def test_hoist_cache_hits(self):

@anijain2305
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo

[ghstack-poisoned]
@anijain2305
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: inductor / unit-test / inductor-test / test (inductor_cpp_wrapper, 1, 2, linux.g5.4xlarge.nvidia.gpu)

Details for Dev Infra team Raised by workflow job

@anijain2305
Copy link
Contributor Author

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@anijain2305
Copy link
Contributor Author

@pytorchbot merge -i

sandy-gags pushed a commit to sandy-gags/pytorch that referenced this pull request Mar 12, 2026
…raph reuse

Capture sources from constructor args in OpaqueObjectClassVariable and
thread ctor_arg_sources through TorchScriptObjectVariable and
synthetic_graph_input so subgraph reuse can apply source replacement
to resolve new constructor arg values on stamp-out.

ghstack-source-id: bb03798
Pull Request resolved: pytorch/pytorch#176643
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants