Repository navigation
Conversation
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@pytorchbot label "release notes: dynamo" cc @anijain2305 @jansel @zou3519 @aperson30 — could you please take a look and approve the CI run when you get a chance? Thanks! |
6ff4074 to
76028cc
Compare
…rch#192905) When a `@nested_compile_region` (`outer`) calls another `@nested_compile_region` (`inner`), each `speculate_subgraph` call creates a fresh `SubgraphTracer` with an empty `traced_sources` set (`output_graph.py`). Sources accessed inside `inner` (such as `layer.flag`) are recorded only on `inner`'s `SubgraphTracer.traced_sources` and are never propagated to `subtracer.parent.traced_sources` (`outer`'s `SubgraphTracer`). Additionally, if `inner` hits the subgraph reuse cache (`stamp_out_subgraph`), the inner entry's remapped `traced_sources` and remapped guards are not propagated to the active outer tracer. As a result, `build_reuse_condition` for `outer` sees an empty `traced_sources` set, collects 0 guards on attributes accessed inside `inner`, and silently reuses `outer`'s specialized subgraph on subsequent calls where those attributes differ. Fix this by: 1. Propagating `subtracer.traced_sources` to `subtracer.parent.traced_sources` when `speculate_subgraph` completes. 2. Recording `traced_sources` and `condition` on `InvokeSubgraphReuseEntry` and propagating remapped `traced_sources` and guards in `stamp_out_subgraph`. Fixes pytorch#192905
…subgraph stamp_out_subgraph re-installed every guard of the cached reuse condition under the new call's sources, including the TENSOR_MATCH guards on the subgraph args. Those args were already guarded when the caller wrapped them (and TENSOR_MATCH is a functools.partial bound to the original tensor), so the clone produced a second tensor guard on the same source and guard construction failed with 'Duplicate tensors found' (test_subgraph_reuse_cache_multiple_entries, test_multi_invocation_chunked_loss_with_backward, TestFakeTensorUpdater.test_hop_subgraph_inputs). Only re-install guards on non-arg, non-tensor sources (e.g. attribute reads inside the inner region such as layer.flag), which is what the enclosing region needs to see in its own reuse condition.
76028cc to
417a829
Compare

Fixes #192905
Summary
When a
@nested_compile_region(outer) calls another@nested_compile_region(inner), eachspeculate_subgraphcall creates a freshSubgraphTracerwith an emptytraced_sourcesset (output_graph.py). Sources accessed insideinner(such aslayer.flag) are recorded only oninner'sSubgraphTracer.traced_sourcesand are never propagated tosubtracer.parent.traced_sources(outer'sSubgraphTracer).Additionally, if
innerhits the subgraph reuse cache (stamp_out_subgraph), the inner entry's remappedtraced_sourcesand remapped guards are not propagated to the active outer tracer.As a result,
build_reuse_conditionforoutersees an emptytraced_sourcesset, collects0guards on attributes accessed insideinner, and silently reusesouter's specialized subgraph on subsequent calls where those attributes differ.Fix
subtracer.traced_sourcestosubtracer.parent.traced_sourceswhenspeculate_subgraphcompletes intorch/_dynamo/variables/higher_order_ops.py.traced_sourcesandconditiononInvokeSubgraphReuseEntry(torch/_guards.py) and propagate remappedtraced_sourcesand guards instamp_out_subgraph(torch/_dynamo/variables/invoke_subgraph.py).Test Plan
pytest test/higher_order_ops/test_invoke_subgraph.py -k test_subgraph_reuse_nested_regioncc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98