Skip to content

[user-streams] Switch to fx annotations at trace time - #166472

Closed
mlazos wants to merge 19 commits into
gh/mlazos/46/basefrom
gh/mlazos/46/head
Closed

mlazos wants to merge 19 commits into
gh/mlazos/46/basefrom
gh/mlazos/46/head

Conversation

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 29, 2025 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ 1 Pending, 1 Unrelated Failure

As of commit b2d9489 with merge base 0674e0a (image):

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.

[ghstack-poisoned]
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
mlazos added a commit that referenced this pull request Oct 29, 2025
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Oct 29, 2025
@mlazos

mlazos commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: trunk / linux-jammy-cuda12.8-py3.10-gcc11 / test (default, 2, 5, linux.g6.4xlarge.experimental.nvidia.gpu)

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
Copy Markdown
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

@mlazos

mlazos commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: trunk / linux-jammy-cuda12.8-py3.10-gcc11 / test (default, 2, 5, linux.g6.4xlarge.experimental.nvidia.gpu)

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
Copy Markdown
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

@mlazos

mlazos commented Nov 2, 2025

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -f "unrelated mandatory check failure"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

@github-actions
github-actions Bot deleted the gh/mlazos/46/head branch December 3, 2025 02:20
tfogal added a commit to tfogal/pytorch that referenced this pull request Jun 2, 2026
Upstream pytorch#166472 (mlazos, '[user-streams] Switch to fx annotations at
trace time') changed StreamContextVariable.target_values from a
positional list [stream_var] to a dict {"stream": idx} so
that StreamContextVariable.enter() (inherited from
FxTracebackAnnotateVariable.enter) could feed it to
torch.fx.traceback.annotate.  That broke three other consumers of
target_values -- output_graph.py's stack_ctx_args /
locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of
which iterate it as a positional tuple.  tuple({"stream": 3})
flattens to ("stream",): the int index is silently dropped and
the rebuild call ends up as e.g. torch.cuda.stream("stream"),
which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because
FxTracebackAnnotateVariable.reconstruct_type raises
Unsupported("torch.fx.traceback.annotate escaped from compiled
region") unconditionally, short-circuiting the rebuild before the
dict-vs-positional mismatch can surface.  The visible symptom is a
silent ungraceful graph break that drops the post-break body when a
graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field
    that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract
    happy.

Then StreamContextVariable.reconstruct_type is overridden to push
a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>)
-- installed as a global on the compiled function via
OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0
(target_values is empty), invoking the partial to produce a fresh
StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is
critical: dynamo retraces the resume prologue, and a closure defined
inside torch/_dynamo would be classified as MOD_SKIPLIST'd and
refuse-to-trace, breaking the prologue.  functools.partial is a
builtin that dynamo handles natively, and the wrapped target
(torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from
FxTracebackAnnotateVariable.enter) because the parent passes
self.target_values to annotate, but target_values is now
the positional rebuild-args tuple; the annotation dict lives on
self.annotation.  reconstruct_type is overridden alongside to
bypass FxTracebackAnnotateVariable.reconstruct_type's
unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break:
graph break inside with torch.cuda.stream(s):, asserts two graph
fragments are captured (rather than the post-break body being silently
dropped to eager).  Whole test_streams.py suite: 68 pass, 7
platform-skipped, no regressions.

Authored with Claude.

Signed-off-by: Tom Fogal <[email protected]>

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pytorchmergebot pushed a commit to tfogal/pytorch that referenced this pull request Jun 4, 2026
Upstream pytorch#166472 (mlazos, '[user-streams] Switch to fx annotations at
trace time') changed StreamContextVariable.target_values from a
positional list [stream_var] to a dict {"stream": idx} so
that StreamContextVariable.enter() (inherited from
FxTracebackAnnotateVariable.enter) could feed it to
torch.fx.traceback.annotate.  That broke three other consumers of
target_values -- output_graph.py's stack_ctx_args /
locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of
which iterate it as a positional tuple.  tuple({"stream": 3})
flattens to ("stream",): the int index is silently dropped and
the rebuild call ends up as e.g. torch.cuda.stream("stream"),
which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because
FxTracebackAnnotateVariable.reconstruct_type raises
Unsupported("torch.fx.traceback.annotate escaped from compiled
region") unconditionally, short-circuiting the rebuild before the
dict-vs-positional mismatch can surface.  The visible symptom is a
silent ungraceful graph break that drops the post-break body when a
graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field
    that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract
    happy.

Then StreamContextVariable.reconstruct_type is overridden to push
a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>)
-- installed as a global on the compiled function via
OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0
(target_values is empty), invoking the partial to produce a fresh
StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is
critical: dynamo retraces the resume prologue, and a closure defined
inside torch/_dynamo would be classified as MOD_SKIPLIST'd and
refuse-to-trace, breaking the prologue.  functools.partial is a
builtin that dynamo handles natively, and the wrapped target
(torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from
FxTracebackAnnotateVariable.enter) because the parent passes
self.target_values to annotate, but target_values is now
the positional rebuild-args tuple; the annotation dict lives on
self.annotation.  reconstruct_type is overridden alongside to
bypass FxTracebackAnnotateVariable.reconstruct_type's
unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break:
graph break inside with torch.cuda.stream(s):, asserts two graph
fragments are captured (rather than the post-break body being silently
dropped to eager).  Whole test_streams.py suite: 68 pass, 7
platform-skipped, no regressions.

Authored with Claude.

Signed-off-by: Tom Fogal <[email protected]>

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pytorchmergebot pushed a commit to tfogal/pytorch that referenced this pull request Jun 4, 2026
Upstream pytorch#166472 (mlazos, '[user-streams] Switch to fx annotations at
trace time') changed StreamContextVariable.target_values from a
positional list [stream_var] to a dict {"stream": idx} so
that StreamContextVariable.enter() (inherited from
FxTracebackAnnotateVariable.enter) could feed it to
torch.fx.traceback.annotate.  That broke three other consumers of
target_values -- output_graph.py's stack_ctx_args /
locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of
which iterate it as a positional tuple.  tuple({"stream": 3})
flattens to ("stream",): the int index is silently dropped and
the rebuild call ends up as e.g. torch.cuda.stream("stream"),
which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because
FxTracebackAnnotateVariable.reconstruct_type raises
Unsupported("torch.fx.traceback.annotate escaped from compiled
region") unconditionally, short-circuiting the rebuild before the
dict-vs-positional mismatch can surface.  The visible symptom is a
silent ungraceful graph break that drops the post-break body when a
graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field
    that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract
    happy.

Then StreamContextVariable.reconstruct_type is overridden to push
a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>)
-- installed as a global on the compiled function via
OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0
(target_values is empty), invoking the partial to produce a fresh
StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is
critical: dynamo retraces the resume prologue, and a closure defined
inside torch/_dynamo would be classified as MOD_SKIPLIST'd and
refuse-to-trace, breaking the prologue.  functools.partial is a
builtin that dynamo handles natively, and the wrapped target
(torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from
FxTracebackAnnotateVariable.enter) because the parent passes
self.target_values to annotate, but target_values is now
the positional rebuild-args tuple; the annotation dict lives on
self.annotation.  reconstruct_type is overridden alongside to
bypass FxTracebackAnnotateVariable.reconstruct_type's
unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break:
graph break inside with torch.cuda.stream(s):, asserts two graph
fragments are captured (rather than the post-break body being silently
dropped to eager).  Whole test_streams.py suite: 68 pass, 7
platform-skipped, no regressions.

Authored with Claude.

Signed-off-by: Tom Fogal <[email protected]>

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jun 9, 2026
…4487)

Upstream #166472 ('[user-streams] Switch to fx annotations at trace time') changed `StreamContextVariable.target_values` from a positional list [stream_var] to a dict {"stream": idx} so that StreamContextVariable.enter() (inherited from FxTracebackAnnotateVariable.enter) could feed it to torch.fx.traceback.annotate.  That broke three other consumers of target_values -- output_graph.py's stack_ctx_args / locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of which iterate it as a positional tuple.  tuple({"stream": 3}) flattens to ("stream",): the int index is silently dropped and the rebuild call ends up as e.g. torch.cuda.stream("stream"), which fails with a confusing device-string parse error.

The breakage has been latent since #166472 because FxTracebackAnnotateVariable.reconstruct_type raises Unsupported("torch.fx.traceback.annotate escaped from compiled region") unconditionally, short-circuiting the rebuild before the dict-vs-positional mismatch can surface.  The visible symptom is a silent ungraceful graph break that drops the post-break body when a graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract happy.

Then StreamContextVariable.reconstruct_type is overridden to push a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>) -- installed as a global on the compiled function via OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0 (target_values is empty), invoking the partial to produce a fresh StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is critical: dynamo retraces the resume prologue, and a closure defined inside torch/_dynamo would be classified as MOD_SKIPLIST'd and refuse-to-trace, breaking the prologue.  functools.partial is a builtin that dynamo handles natively, and the wrapped target (torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from FxTracebackAnnotateVariable.enter) because the parent passes self.target_values to annotate, but target_values is now the positional rebuild-args tuple; the annotation dict lives on self.annotation.  reconstruct_type is overridden alongside to bypass FxTracebackAnnotateVariable.reconstruct_type's unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break: graph break inside with torch.cuda.stream(s):, asserts two graph fragments are captured (rather than the post-break body being silently dropped to eager).  Whole test_streams.py suite: 68 pass, 7 platform-skipped, no regressions.

Authored with Claude.

Pull Request resolved: #184487
Approved by: https://github.com/williamwen42, https://github.com/mlazos

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
jemitche1 pushed a commit to jemitche1/pytorch that referenced this pull request Jun 13, 2026
…orch#184487)

Upstream pytorch#166472 ('[user-streams] Switch to fx annotations at trace time') changed `StreamContextVariable.target_values` from a positional list [stream_var] to a dict {"stream": idx} so that StreamContextVariable.enter() (inherited from FxTracebackAnnotateVariable.enter) could feed it to torch.fx.traceback.annotate.  That broke three other consumers of target_values -- output_graph.py's stack_ctx_args / locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of which iterate it as a positional tuple.  tuple({"stream": 3}) flattens to ("stream",): the int index is silently dropped and the rebuild call ends up as e.g. torch.cuda.stream("stream"), which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because FxTracebackAnnotateVariable.reconstruct_type raises Unsupported("torch.fx.traceback.annotate escaped from compiled region") unconditionally, short-circuiting the rebuild before the dict-vs-positional mismatch can surface.  The visible symptom is a silent ungraceful graph break that drops the post-break body when a graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract happy.

Then StreamContextVariable.reconstruct_type is overridden to push a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>) -- installed as a global on the compiled function via OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0 (target_values is empty), invoking the partial to produce a fresh StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is critical: dynamo retraces the resume prologue, and a closure defined inside torch/_dynamo would be classified as MOD_SKIPLIST'd and refuse-to-trace, breaking the prologue.  functools.partial is a builtin that dynamo handles natively, and the wrapped target (torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from FxTracebackAnnotateVariable.enter) because the parent passes self.target_values to annotate, but target_values is now the positional rebuild-args tuple; the annotation dict lives on self.annotation.  reconstruct_type is overridden alongside to bypass FxTracebackAnnotateVariable.reconstruct_type's unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break: graph break inside with torch.cuda.stream(s):, asserts two graph fragments are captured (rather than the post-break body being silently dropped to eager).  Whole test_streams.py suite: 68 pass, 7 platform-skipped, no regressions.

Authored with Claude.

Pull Request resolved: pytorch#184487
Approved by: https://github.com/williamwen42, https://github.com/mlazos

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…orch#184487)

Upstream pytorch#166472 ('[user-streams] Switch to fx annotations at trace time') changed `StreamContextVariable.target_values` from a positional list [stream_var] to a dict {"stream": idx} so that StreamContextVariable.enter() (inherited from FxTracebackAnnotateVariable.enter) could feed it to torch.fx.traceback.annotate.  That broke three other consumers of target_values -- output_graph.py's stack_ctx_args / locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of which iterate it as a positional tuple.  tuple({"stream": 3}) flattens to ("stream",): the int index is silently dropped and the rebuild call ends up as e.g. torch.cuda.stream("stream"), which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because FxTracebackAnnotateVariable.reconstruct_type raises Unsupported("torch.fx.traceback.annotate escaped from compiled region") unconditionally, short-circuiting the rebuild before the dict-vs-positional mismatch can surface.  The visible symptom is a silent ungraceful graph break that drops the post-break body when a graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract happy.

Then StreamContextVariable.reconstruct_type is overridden to push a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>) -- installed as a global on the compiled function via OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0 (target_values is empty), invoking the partial to produce a fresh StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is critical: dynamo retraces the resume prologue, and a closure defined inside torch/_dynamo would be classified as MOD_SKIPLIST'd and refuse-to-trace, breaking the prologue.  functools.partial is a builtin that dynamo handles natively, and the wrapped target (torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from FxTracebackAnnotateVariable.enter) because the parent passes self.target_values to annotate, but target_values is now the positional rebuild-args tuple; the annotation dict lives on self.annotation.  reconstruct_type is overridden alongside to bypass FxTracebackAnnotateVariable.reconstruct_type's unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break: graph break inside with torch.cuda.stream(s):, asserts two graph fragments are captured (rather than the post-break body being silently dropped to eager).  Whole test_streams.py suite: 68 pass, 7 platform-skipped, no regressions.

Authored with Claude.

Pull Request resolved: pytorch#184487
Approved by: https://github.com/williamwen42, https://github.com/mlazos

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…orch#184487)

Upstream pytorch#166472 ('[user-streams] Switch to fx annotations at trace time') changed `StreamContextVariable.target_values` from a positional list [stream_var] to a dict {"stream": idx} so that StreamContextVariable.enter() (inherited from FxTracebackAnnotateVariable.enter) could feed it to torch.fx.traceback.annotate.  That broke three other consumers of target_values -- output_graph.py's stack_ctx_args / locals_ctx_args population, the base
ContextWrappingVariable.reconstruct, and
BlockStackEntry.resume_fn -> ReenterWith.try_finally -- all of which iterate it as a positional tuple.  tuple({"stream": 3}) flattens to ("stream",): the int index is silently dropped and the rebuild call ends up as e.g. torch.cuda.stream("stream"), which fails with a confusing device-string parse error.

The breakage has been latent since pytorch#166472 because FxTracebackAnnotateVariable.reconstruct_type raises Unsupported("torch.fx.traceback.annotate escaped from compiled region") unconditionally, short-circuiting the rebuild before the dict-vs-positional mismatch can surface.  The visible symptom is a silent ungraceful graph break that drops the post-break body when a graph break occurs inside with torch.cuda.stream(s):.

This fix structurally separates the two purposes of target_values:

  * self.annotation = {"stream": idx} is a new dedicated field that enter() passes to torch.fx.traceback.annotate.
  * target_values = () keeps the positional rebuild contract happy.

Then StreamContextVariable.reconstruct_type is overridden to push a 0-arg callable -- functools.partial(torch.cuda.stream, <Stream>) -- installed as a global on the compiled function via OutputGraph.install_global_by_id.  The base
ContextWrappingVariable.reconstruct appends CALL 0 (target_values is empty), invoking the partial to produce a fresh StreamContext just in time for the resume prologue's BEFORE_WITH.

functools.partial (rather than a freshly-defined closure) is critical: dynamo retraces the resume prologue, and a closure defined inside torch/_dynamo would be classified as MOD_SKIPLIST'd and refuse-to-trace, breaking the prologue.  functools.partial is a builtin that dynamo handles natively, and the wrapped target (torch.cuda.stream) is plainly traceable.

enter() is also inlined (rather than inherited from FxTracebackAnnotateVariable.enter) because the parent passes self.target_values to annotate, but target_values is now the positional rebuild-args tuple; the annotation dict lives on self.annotation.  reconstruct_type is overridden alongside to bypass FxTracebackAnnotateVariable.reconstruct_type's unconditional Unsupported raise.

Regression test added at
test/dynamo/test_streams.py::test_target_values_dict_round_trips_through_graph_break: graph break inside with torch.cuda.stream(s):, asserts two graph fragments are captured (rather than the post-break body being silently dropped to eager).  Whole test_streams.py suite: 68 pass, 7 platform-skipped, no regressions.

Authored with Claude.

Pull Request resolved: pytorch#184487
Approved by: https://github.com/williamwen42, https://github.com/mlazos

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo release notes: dynamo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants