Bug description
When Torch-TensorRT Dynamo constant folding replaces an input-independent tensor factory result with a persistent folded parameter, the same tensor may also be returned directly as a graph output.
If eager code after a graph break mutates that output in-place, the mutation changes the persistent folded tensor stored on the compiled graph module. Later invocations then observe state left by earlier invocations.
This can cause output contamination across repeated calls or otherwise independent test cases.
Relevant lowered graph shape
A problematic graph has the equivalent structure:
_frozen_param0 = self._frozen_param0
return (_frozen_param0,)
The graph output aliases persistent module state rather than returning fresh storage.
Reproduction outline
- Compile a function containing an input-independent tensor factory operation.
- Introduce a graph break after the factory result is produced.
- Return the folded tensor from the compiled subgraph.
- Mutate that tensor in-place in eager code after the graph break.
- Invoke the compiled function again.
- The second invocation observes the mutation from the first invocation.
The problem is specific to a folded tensor that is also a graph output and is subsequently mutated. A normal eager execution creates fresh tensor storage for each invocation.
Expected behavior
Each invocation should preserve eager semantics. A folded constant exposed as a graph output must not allow downstream mutation to modify the persistent folded parameter used by later invocations.
Actual behavior
The graph directly returns the persistent folded parameter, so downstream in-place operations can mutate compiler-owned state and affect later calls.
Suggested direction
Materialize fresh storage at the graph-output boundary for persistent folded tensors, while preserving the output metadata and the original device semantics.
Additional context
This report intentionally contains only a generic description and minimized graph shape. No proprietary model code, data, logs, or environment details are included.
Bug description
When Torch-TensorRT Dynamo constant folding replaces an input-independent tensor factory result with a persistent folded parameter, the same tensor may also be returned directly as a graph output.
If eager code after a graph break mutates that output in-place, the mutation changes the persistent folded tensor stored on the compiled graph module. Later invocations then observe state left by earlier invocations.
This can cause output contamination across repeated calls or otherwise independent test cases.
Relevant lowered graph shape
A problematic graph has the equivalent structure:
The graph output aliases persistent module state rather than returning fresh storage.
Reproduction outline
The problem is specific to a folded tensor that is also a graph output and is subsequently mutated. A normal eager execution creates fresh tensor storage for each invocation.
Expected behavior
Each invocation should preserve eager semantics. A folded constant exposed as a graph output must not allow downstream mutation to modify the persistent folded parameter used by later invocations.
Actual behavior
The graph directly returns the persistent folded parameter, so downstream in-place operations can mutate compiler-owned state and affect later calls.
Suggested direction
Materialize fresh storage at the graph-output boundary for persistent folded tensors, while preserving the output metadata and the original device semantics.
Additional context
This report intentionally contains only a generic description and minimized graph shape. No proprietary model code, data, logs, or environment details are included.