Skip to content

fix(dynamo): clone folded constants returned as graph outputs - #4443

Open
curry-zzl wants to merge 2 commits into
pytorch:mainfrom
curry-zzl:fix/clone-folded-constant-outputs
Open

fix(dynamo): clone folded constants returned as graph outputs#4443
curry-zzl wants to merge 2 commits into
pytorch:mainfrom
curry-zzl:fix/clone-folded-constant-outputs

Conversation

@curry-zzl

Copy link
Copy Markdown

Description

Constant folding can replace input-independent tensor factories such as torch.zeros with registered _frozen_param* attributes. When one of these constants is returned directly across a graph break, eager code may mutate the returned tensor in-place. That mutation then changes the registered constant and leaks state into later top-level invocations.

This change extends repair_input_as_output to clone direct graph outputs backed by folded constants, preserving the registered constant while keeping constant folding enabled.

A regression test mutates the first returned tensor and verifies that both a subsequent output and the underlying _frozen_param remain unchanged.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented the non-obvious graph-break behavior
  • I have added a test to verify the fix
  • New and existing unit tests pass locally with my changes

Validation

  • python -m py_compile passes for the modified pass and test.
  • The focused pytest collection in the development container is blocked because the source checkout does not contain the generated torch_tensorrt._version module. The equivalent regression was validated in the installed runtime environment.

@meta-cla

meta-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Hi @curry-zzl!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jul 29, 2026
@meta-cla meta-cla Bot added the cla signed label Jul 29, 2026
@meta-cla

meta-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@github-actions
github-actions Bot requested a review from zewenli98 July 29, 2026 07:34
@narendasan
narendasan requested a review from apbose July 29, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant