Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (2): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202428
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 10 Unrelated FailuresAs of commit 19cbe31 with merge base e68ed49 ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: NEW FAILURES - The following jobs have failed:
NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @aditvenk's task in 1m 33s —— View job The fix holds up for both reported failures; there are two small issues, one stale comment and one leftover recursion case I'm not sure about. PR Review: #202428SummaryThe PR makes derived SymNodes (outputs of Code Quality
Testing
RecommendationApprove, after fixing the stale comment. Regression tests cover both issues, and they also cover the tangent-dependency trap that rules out a simpler "first registration wins" policy. The recursion case above is worth a decision either way but doesn't block. |
|
@claude Are the CI failures due to this PR? |
|
Claude finished @aditvenk's task in 52s —— View job No. None of the CI failures come from this PR. Every failing job ran pytest 9.2.0, and pytest crashes inside its own junitxml reporter after the test has already finished, whether the test passed or was skipped. DetailsWhat the logs showI downloaded the logs for the 3 jobs Dr. CI lists as "NEW FAILURES". All three fail the same way:
Traceback (the same in every job):
The 7 What to doDr. CI says main fixed this in #202385 by pinning pytest to 9.1.1, but I couldn't confirm that from this checkout. After that fix lands, rebase onto main (or have these jobs re-run on a merge base that includes it) and they should go green. You can also ask for a merge with |
aorenste
left a comment
There was a problem hiding this comment.
(Reviewed by me, assisted by AI)
Re-review is opt-in: once you've pushed a fix, click Re-request review next to the reviewer under Reviewers -- new commits alone don't re-notify. Requesting a review
Since #185865, DTensor sharding propagation runs under disable_proxy_modes_tracing(), so the global sizes it produces are SymNodes that make_fx never tracked. When one is later used with tracing on, get_proxy_slot() resolves it through tracer.sympy_expr_tracker (a map from a symbol to a tracked SymInt with that value) or rebuilds it from its sympy expression with _build_proxy_for_sym_expr(). Two bugs in that fallback broke torch.compile of tensor-parallel models with dynamic shapes. 1. Infinite recursion in the AOTAutograd joint trace (#201624) In backward, the contiguity computation calls sym_max(size, 1) on an untracked global size s50. The result simplifies to s50, so it becomes sympy_expr_tracker[s50]. Under AOTAutograd its proxy is a lazy thunk that resolves its untracked input when forced. That lookup returns sympy_expr_tracker[s50], the thunk being forced, which runs again and recurses forever. Forward-only compiles are not thunkified, which is why they worked. The same cycle can also close through other ops and symbols, e.g. p == s1 computed from an untracked s0 while q == s0 is computed from an untracked s1. The fix makes lookups skip providers that are still being computed. _compute_proxy(), the body of every lazy SymInt proxy, adds its result to the new tracer.symnodes_being_forced while it resolves its arguments. Each sympy_expr_tracker entry also records the entry it replaced (prev), so every symbol keeps a stack of providers, newest first. The new _lookup_sympy_expr(), used by both get_proxy_slot() and _build_proxy_for_sym_expr(), walks down that stack past providers in symnodes_being_forced. In the example above, forcing sym_max(s50, 1) now resolves s50 to the provider registered before it, such as an input's sym_size, instead of to itself. Writes keep main's last-writer-wins behavior, so a lookup only changes when its newest provider is mid-computation. Everything a lookup returns in that window is forced on the same stack, and Thunk.force() only marks a thunk done after it returns, so on main that lookup re-enters the provider's thunk and recurses forever. Every changed outcome was therefore a RecursionError on main. If every provider is mid-computation, the lookup misses and tracing fails with "is not tracked with proxy" instead of hanging. Cycles that close through a registered thunk rather than a table lookup are not covered and still recurse, as on main. The cost is a set add/discard per forced lazy SymInt and one dict read per symbol registration; the skip loop only runs on the fallback path. Alternatives considered were rules restricting which SymInts may become entries, such as first registration wins, or no entries computed from untracked SymInts. AOTAutograd registers tangent placeholders before the forward runs, so each such rule either lets a tangent keep a symbol, making the forward graph depend on tangents_1, or misses cycles that close after later writes. test_unbacked_global_size_no_tangent_dependency and test_build_proxy_untracked_symint_no_tangent_dependency cover the tangent cases. 2. Rebuilt Max/Min nodes that Inductor cannot lower (#201838) _sympy_handlers() mapped sympy Max/Min to the helpers _nary_sym_max/_nary_sym_min. When _build_proxy_for_sym_expr() rebuilds a Max/Min on the get_proxy_slot path (e.g. contiguous strides like Max(1, u0) of a DTensor with unbacked sizes), the helper becomes an FX node target, which Inductor rejects as "is not an OpOverload". _build_proxy_for_sym_expr() already folds n-ary expressions into binary calls, so map Max/Min directly to torch.sym_max/torch.sym_min and delete the helpers. The exact #201838 repro already passes on main since #193416; this fixes the remaining _nary_sym_max failure. The new DTensor backward tests also run under compiled autograd, where DTensor's backward graph-breaks, so they are added to known_graph_breaks_tests in test_compiled_autograd.py. Fixes #201624 Fixes #201838 Test Plan: The new tests fail on main and pass with this change. The #201624 and #201838 repros pass on 2x B200, with gradients matching eager. Compile time is unchanged (make_fx of ~6000 SymInt ops: median 1.74-1.78 s on main, 1.72-1.77 s with this change). ``` python test/test_dynamic_shapes.py -k test_build_proxy python -m pytest test/distributed/tensor/test_dtensor_compile.py python -m pytest test/inductor/test_compiled_autograd.py -n 8 torchrun --nproc_per_node=2 repro_201624.py torchrun --nproc_per_node=2 repro_201838.py ``` No new failures in related suites, including: ``` python -m pytest test/test_proxy_tensor.py -n 4 python -m pytest test/functorch/test_aotdispatch.py -n 8 python -m pytest test/dynamo/test_subclasses.py -n 4 python -m pytest test/export/test_export.py -n 8 python -m pytest test/inductor/test_torchinductor_dynamic_shapes.py -k cuda -n 8 ``` This PR was authored with the assistance of an AI coding agent.
a2d10e3 to
2dab055
Compare
There was a problem hiding this comment.
Automated review of 2dab055: nothing blocking; ready for human review.
This PR fixes two make_fx bugs that show up with DTensor and dynamic shapes. It skips a SymNode whose lazy proxy is being forced, falling back through a prev chain on _SympyExprTrackerValue (# 201624), and it rebuilds sympy Max/Min as torch.sym_max/sym_min (# 201838). Recommendation: Needs Discussion. The description needs updating to match the design, and a forward-side test should confirm whether the prev fallback can create a forward-to-tangent dependency.
⚪ 2 non-blocking findings
pytorch/torch/fx/experimental/proxy_tensor.py
Line 366 in 2dab055
The PR description describes a fix that is no longer in the code. It says _sym_register "now passes derived=True to set_proxy_slot" and that "a derived SymNode never overwrites an existing sympy_expr_tracker entry". At HEAD there is no derived parameter, and every registration still overwrites the entry. The fix is now the prev chain plus symnodes_being_forced, skipped inside _lookup_sympy_expr. The "first registration wins" alternatives paragraph is also written against the old design. PyTorch uses the PR body as the commit message, so the history would record the wrong mechanism. Rewrite the "Fix:" and "Agent details" sections to describe the current design.
pytorch/torch/fx/experimental/proxy_tensor.py
Line 1620 in 2dab055
The fallback in _lookup_sympy_expr can pick a tangent's size for a cycle in the forward graph (low confidence: reasoned through, not run). When the newest entry is being forced, the lookup walks to entry.prev, which is just the provider registered before it, whatever its source. In an AOTAutograd joint trace, tangents are tracked after primals but before the forward body, so the chain for s0 is primal size tangent size(s) X. Example: forward X = torch.sym_max(m, 1) (simplifies to s0) on an untracked m with expr s0, then x.new_zeros(X). Forcing X skips X and resolves m to the tangent's sym_size, so forward zeros depends on a tangent and the partitioner fails ("Node was invalid, but is output"). Not a regression (main recurses forever), but the fix only covers the backward-side cycle. Add a forward-side variant to test_build_proxy_untracked_symint_no_tangent_dependency (using aot_function, for the dedupe_symints reason in that test's docstring) with n = torch.sym_max(m, 1) passed to new_zeros. If it fails, skip tangent-derived providers, following the "primals get their SymInts set first" rationale at proxy_tensor.py:338-343, instead of taking prev blindly.
This review is AI-generated and advisory. Each new automated review replaces the previous one.
aorenste
left a comment
There was a problem hiding this comment.
(Reviewed by me, assisted by AI)
Merging is self-service: comment @pytorchbot merge and the bot lands it once required checks pass. Merging your Change | Bot commands
| if len(args) == 1 and isinstance(args[0], (list, tuple)): | ||
| n_args = ( | ||
| tuple( | ||
| tracer.symnodes_being_forced.add(out.node) |
There was a problem hiding this comment.
[cleanup] Raise a clear error when a SymInt's proxy computation re-enters itself, instead of recursing until RecursionError:
if out.node in tracer.symnodes_being_forced:
raise RuntimeError(f"Cycle while computing the proxy for {out}")
tracer.symnodes_being_forced.add(out.node)The fallback can still close a cycle that the skip never sees. When an untracked compound SymInt is resolved outside the forcing window, _build_proxy_for_sym_expr permanently binds it to the newest provider, which can be the derived SymInt computed from it. The cycle then runs through symnode_tracker and never reaches _lookup_sympy_expr:
def f(x):
with maybe_enable_thunkify():
with disable_proxy_modes_tracing():
w = x.shape[0] * 2 # untracked, 2*s0
X = w // 2 # traced, simplifies to s0
return x.new_zeros(w), x.new_zeros(X)
make_fx(f, tracing_mode="symbolic")(torch.randn(4))Resolving w binds it to 2 * X, and X's argument is w, so this recurses forever. Swapping the two new_zeros calls traces fine, so whether tracing succeeds depends on use order. Main recurses in both orders, so this is fine as a follow-up.
A lazy SymInt proxy can still end up depending on itself through symnode_tracker, where the sympy_expr_tracker skip from the previous commit never looks. When an untracked compound SymInt is resolved outside any forcing window, _build_proxy_for_sym_expr() binds it to the newest provider of its symbols, which can be a SymInt computed from it: ``` w = x.shape[0] * 2 # untracked, 2*s0 half = w // 2 # traced, simplifies to s0 x.new_zeros(w) # w is rebuilt as 2 * half, and half's operand is w ``` Forcing w forces half, whose operand w is now tracked and mid-force, so Thunk.force() runs w again and recurses until RecursionError, as on main. _compute_proxy() now raises "Cycle while computing the proxy for ..." when it is re-entered for the same SymInt. This also turns one contrived case that used to finish into this error: a re-entered computation that resolves further down the provider stack used to complete by computing the proxy twice, leaving a duplicate graph node. That case recurses forever on main. Test Plan: The new test fails on main and on the previous commit with RecursionError and passes with this change. Across the DTensor program matrices and the suites below, the guard fires only in that test. ``` python test/test_dynamic_shapes.py -k test_build_proxy python -m pytest test/distributed/tensor/test_dtensor_compile.py python -m pytest test/inductor/test_compiled_autograd.py -n 8 python -m pytest test/test_proxy_tensor.py -n 4 python -m pytest test/functorch/test_aotdispatch.py -n 8 ``` This PR was authored with the assistance of an AI coding agent.
|
@claude Are any of the failures on CI caused by this PR? |
|
Claude finished @aditvenk's task in 50s —— View job No, none of the CI failures on DetailsWhat the logs showI downloaded the logs for the 2 jobs Dr. CI lists as "NEW FAILURES", plus one of the cpp_wrapper jobs:
The traceback is the same in every job: No log mentions Root causeOn this branch, The other failing jobs have the same crash or are known trunk issues: one What to doRebase onto main and re-run CI, or merge with |
|
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 3 jobs have failed, first few of them are: inductor / unit-test / inductor-cpu-test / test (inductor_amx, 6, 7, mt-l-x86iamx-8-64), inductor / unit-test / inductor-cpu-test / test (inductor_amx, 5, 7, mt-l-x86iamx-8-64), inductor / unit-test / inductor-test-cuda132 / test (inductor_cpp_wrapper, 1, 2, mt-l-x86aavx2-11-41-a10g) Details for Dev Infra teamRaised by workflow job |
|
@claude Are these failures due to this PR? #202428 (comment) |
|
Claude finished @aditvenk's task in 37s —— View job No. None of the 3 jobs that blocked the merge come from this PR. They are the same pytest 9.2.0 / Details
The jobs that blocked the merge
I re-checked the The log never mentions Why it happenspytest 9.2.0 keys What to do
|
|
@pytorchbot merge -i |
…ytorch#202428) ## Linked issue or supporting maintainer Fixes pytorch#201624 Fixes pytorch#201838 ## BC-breaking? No ## Summary (human written only) This PR fixes two bugs in DTensor x dynamic shapes. DTensor shard prop runs under disable_proxy_modes_tracing(), so SymNodes it creates are untracked: make_fx has no proxy for them in symnode_tracker. When one is used later, get_proxy_slot falls back to sympy_expr_tracker[symbol], or to _build_proxy_for_sym_expr, which rebuilds it from its sympy expression. 1) In backward, sym_max(Y, 1) runs on an untracked Y whose expression is s50. The result X simplifies to s50 as well. _sym_register gives X a lazy thunk proxy that depends on Y, and set_proxy_slot overwrote sympy_expr_tracker[s50] with X. Forcing X's thunk resolves Y, which through sympy_expr_tracker is X again and so on recurses. Fix: Resolving an untracked SymInt through sympy_expr_tracker now skips any SymInt whose lazy proxy is mid-computation, falling back to the provider it replaced. Since writes are unchanged, behavior only differs from main where main recursed forever. 2) _build_proxy_for_sym_expr rebuilt sympy Max/Min as FX nodes with target _nary_sym_max/_nary_sym_min which Inductor cannot lower. Fix: Substitute to torch.sym_max/torch.sym_min because _build_proxy_for_sym_expr now splits many-arg expression into chain of two-argument calls. So the helpers are not needed anymore. ## Agent details (if applicable) Since pytorch#185865, DTensor sharding propagation runs under disable_proxy_modes_tracing(), so the global sizes it produces are SymNodes that make_fx never tracked. When one is later used with tracing on, get_proxy_slot() resolves it through tracer.sympy_expr_tracker (a map from a symbol to a tracked SymInt with that value) or rebuilds it from its sympy expression with _build_proxy_for_sym_expr(). Two bugs in that fallback broke torch.compile of tensor-parallel models with dynamic shapes. 1. Infinite recursion in the AOTAutograd joint trace (pytorch#201624) In backward, the contiguity computation calls sym_max(size, 1) on an untracked global size s50. The result simplifies to s50, so it becomes sympy_expr_tracker[s50]. Under AOTAutograd its proxy is a lazy thunk that resolves its untracked input when forced. That lookup returns sympy_expr_tracker[s50], the thunk being forced, which runs again and recurses forever. Forward-only compiles are not thunkified, which is why they worked. The same cycle can also close through other ops and symbols, e.g. p == s1 computed from an untracked s0 while q == s0 is computed from an untracked s1. The fix makes lookups skip providers that are still being computed. _compute_proxy(), the body of every lazy SymInt proxy, adds its result to the new tracer.symnodes_being_forced while it resolves its arguments. Each sympy_expr_tracker entry also records the entry it replaced (prev), so every symbol keeps a stack of providers, newest first. The new _lookup_sympy_expr(), used by both get_proxy_slot() and _build_proxy_for_sym_expr(), walks down that stack past providers in symnodes_being_forced. In the example above, forcing sym_max(s50, 1) now resolves s50 to the provider registered before it, such as an input's sym_size, instead of to itself. Writes keep main's last-writer-wins behavior, so a lookup only changes when its newest provider is mid-computation. Everything a lookup returns in that window is forced on the same stack, and Thunk.force() only marks a thunk done after it returns, so on main that lookup re-enters the provider's thunk and recurses forever. Every changed outcome was therefore a RecursionError on main. If every provider is mid-computation, the lookup misses and tracing fails with "is not tracked with proxy" instead of hanging. Cycles that close through a registered thunk rather than a table lookup are not covered and still recurse, as on main. The cost is a set add/discard per forced lazy SymInt and one dict read per symbol registration; the skip loop only runs on the fallback path. Alternatives considered were rules restricting which SymInts may become entries, such as first registration wins, or no entries computed from untracked SymInts. AOTAutograd registers tangent placeholders before the forward runs, so each such rule either lets a tangent keep a symbol, making the forward graph depend on tangents_1, or misses cycles that close after later writes. test_unbacked_global_size_no_tangent_dependency and test_build_proxy_untracked_symint_no_tangent_dependency cover the tangent cases. 2. Rebuilt Max/Min nodes that Inductor cannot lower (pytorch#201838) _sympy_handlers() mapped sympy Max/Min to the helpers _nary_sym_max/_nary_sym_min. When _build_proxy_for_sym_expr() rebuilds a Max/Min on the get_proxy_slot path (e.g. contiguous strides like Max(1, u0) of a DTensor with unbacked sizes), the helper becomes an FX node target, which Inductor rejects as "is not an OpOverload". _build_proxy_for_sym_expr() already folds n-ary expressions into binary calls, so map Max/Min directly to torch.sym_max/torch.sym_min and delete the helpers. The exact pytorch#201838 repro already passes on main since pytorch#193416; this fixes the remaining _nary_sym_max failure. The new DTensor backward tests also run under compiled autograd, where DTensor's backward graph-breaks, so they are added to known_graph_breaks_tests in test_compiled_autograd.py. Test Plan: The new tests fail on main and pass with this change. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#202428 Approved by: https://github.com/aorenste
…ytorch#202428) ## Linked issue or supporting maintainer Fixes pytorch#201624 Fixes pytorch#201838 ## BC-breaking? No ## Summary (human written only) This PR fixes two bugs in DTensor x dynamic shapes. DTensor shard prop runs under disable_proxy_modes_tracing(), so SymNodes it creates are untracked: make_fx has no proxy for them in symnode_tracker. When one is used later, get_proxy_slot falls back to sympy_expr_tracker[symbol], or to _build_proxy_for_sym_expr, which rebuilds it from its sympy expression. 1) In backward, sym_max(Y, 1) runs on an untracked Y whose expression is s50. The result X simplifies to s50 as well. _sym_register gives X a lazy thunk proxy that depends on Y, and set_proxy_slot overwrote sympy_expr_tracker[s50] with X. Forcing X's thunk resolves Y, which through sympy_expr_tracker is X again and so on recurses. Fix: Resolving an untracked SymInt through sympy_expr_tracker now skips any SymInt whose lazy proxy is mid-computation, falling back to the provider it replaced. Since writes are unchanged, behavior only differs from main where main recursed forever. 2) _build_proxy_for_sym_expr rebuilt sympy Max/Min as FX nodes with target _nary_sym_max/_nary_sym_min which Inductor cannot lower. Fix: Substitute to torch.sym_max/torch.sym_min because _build_proxy_for_sym_expr now splits many-arg expression into chain of two-argument calls. So the helpers are not needed anymore. ## Agent details (if applicable) Since pytorch#185865, DTensor sharding propagation runs under disable_proxy_modes_tracing(), so the global sizes it produces are SymNodes that make_fx never tracked. When one is later used with tracing on, get_proxy_slot() resolves it through tracer.sympy_expr_tracker (a map from a symbol to a tracked SymInt with that value) or rebuilds it from its sympy expression with _build_proxy_for_sym_expr(). Two bugs in that fallback broke torch.compile of tensor-parallel models with dynamic shapes. 1. Infinite recursion in the AOTAutograd joint trace (pytorch#201624) In backward, the contiguity computation calls sym_max(size, 1) on an untracked global size s50. The result simplifies to s50, so it becomes sympy_expr_tracker[s50]. Under AOTAutograd its proxy is a lazy thunk that resolves its untracked input when forced. That lookup returns sympy_expr_tracker[s50], the thunk being forced, which runs again and recurses forever. Forward-only compiles are not thunkified, which is why they worked. The same cycle can also close through other ops and symbols, e.g. p == s1 computed from an untracked s0 while q == s0 is computed from an untracked s1. The fix makes lookups skip providers that are still being computed. _compute_proxy(), the body of every lazy SymInt proxy, adds its result to the new tracer.symnodes_being_forced while it resolves its arguments. Each sympy_expr_tracker entry also records the entry it replaced (prev), so every symbol keeps a stack of providers, newest first. The new _lookup_sympy_expr(), used by both get_proxy_slot() and _build_proxy_for_sym_expr(), walks down that stack past providers in symnodes_being_forced. In the example above, forcing sym_max(s50, 1) now resolves s50 to the provider registered before it, such as an input's sym_size, instead of to itself. Writes keep main's last-writer-wins behavior, so a lookup only changes when its newest provider is mid-computation. Everything a lookup returns in that window is forced on the same stack, and Thunk.force() only marks a thunk done after it returns, so on main that lookup re-enters the provider's thunk and recurses forever. Every changed outcome was therefore a RecursionError on main. If every provider is mid-computation, the lookup misses and tracing fails with "is not tracked with proxy" instead of hanging. Cycles that close through a registered thunk rather than a table lookup are not covered and still recurse, as on main. The cost is a set add/discard per forced lazy SymInt and one dict read per symbol registration; the skip loop only runs on the fallback path. Alternatives considered were rules restricting which SymInts may become entries, such as first registration wins, or no entries computed from untracked SymInts. AOTAutograd registers tangent placeholders before the forward runs, so each such rule either lets a tangent keep a symbol, making the forward graph depend on tangents_1, or misses cycles that close after later writes. test_unbacked_global_size_no_tangent_dependency and test_build_proxy_untracked_symint_no_tangent_dependency cover the tangent cases. 2. Rebuilt Max/Min nodes that Inductor cannot lower (pytorch#201838) _sympy_handlers() mapped sympy Max/Min to the helpers _nary_sym_max/_nary_sym_min. When _build_proxy_for_sym_expr() rebuilds a Max/Min on the get_proxy_slot path (e.g. contiguous strides like Max(1, u0) of a DTensor with unbacked sizes), the helper becomes an FX node target, which Inductor rejects as "is not an OpOverload". _build_proxy_for_sym_expr() already folds n-ary expressions into binary calls, so map Max/Min directly to torch.sym_max/torch.sym_min and delete the helpers. The exact pytorch#201838 repro already passes on main since pytorch#193416; this fixes the remaining _nary_sym_max failure. The new DTensor backward tests also run under compiled autograd, where DTensor's backward graph-breaks, so they are added to known_graph_breaks_tests in test_compiled_autograd.py. Test Plan: The new tests fail on main and pass with this change. This PR was authored with the assistance of an AI coding agent. Pull Request resolved: pytorch#202428 Approved by: https://github.com/aorenste
Linked issue or supporting maintainer
Fixes #201624
Fixes #201838
BC-breaking?
No
Summary (human written only)
This PR fixes two bugs in DTensor x dynamic shapes.
DTensor shard prop runs under disable_proxy_modes_tracing(), so SymNodes it creates are untracked: make_fx has no proxy for them in symnode_tracker. When one is used later, get_proxy_slot falls back to sympy_expr_tracker[symbol], or to _build_proxy_for_sym_expr, which rebuilds it from its sympy expression.
Fix: Resolving an untracked SymInt through sympy_expr_tracker now skips any SymInt whose lazy proxy is mid-computation, falling back to the provider it replaced. Since writes are unchanged, behavior only differs from main where main recursed forever.
Fix: Substitute to torch.sym_max/torch.sym_min because _build_proxy_for_sym_expr now splits many-arg expression into chain of two-argument calls. So the helpers are not needed anymore.
Agent details (if applicable)
Since #185865, DTensor sharding propagation runs under disable_proxy_modes_tracing(), so the global sizes it produces are SymNodes that make_fx never tracked. When one is later used with tracing on, get_proxy_slot() resolves it through tracer.sympy_expr_tracker (a map from a symbol to a tracked SymInt with that value) or rebuilds it from its sympy expression with _build_proxy_for_sym_expr(). Two bugs in that fallback broke torch.compile of tensor-parallel models with dynamic shapes.
ColwiseParallel/RowwiseParallelnn.Linearfail withRecursionErrorin the AOTAutograd joint graph trace #201624)In backward, the contiguity computation calls sym_max(size, 1) on an untracked global size s50. The result simplifies to s50, so it becomes sympy_expr_tracker[s50]. Under AOTAutograd its proxy is a lazy thunk that resolves its untracked input when forced. That lookup returns sympy_expr_tracker[s50], the thunk being forced, which runs again and recurses forever. Forward-only compiles are not thunkified, which is why they worked. The same cycle can also close through other ops and symbols, e.g. p == s1 computed from an untracked s0 while q == s0 is computed from an untracked s1.
The fix makes lookups skip providers that are still being computed. _compute_proxy(), the body of every lazy SymInt proxy, adds its result to the new tracer.symnodes_being_forced while it resolves its arguments. Each sympy_expr_tracker entry also records the entry it replaced (prev), so every symbol keeps a stack of providers, newest first. The new _lookup_sympy_expr(), used by both get_proxy_slot() and _build_proxy_for_sym_expr(), walks down that stack past providers in symnodes_being_forced. In the example above, forcing sym_max(s50, 1) now resolves s50 to the provider registered before it, such as an input's sym_size, instead of to itself.
Writes keep main's last-writer-wins behavior, so a lookup only changes when its newest provider is mid-computation. Everything a lookup returns in that window is forced on the same stack, and Thunk.force() only marks a thunk done after it returns, so on main that lookup re-enters the provider's thunk and recurses forever. Every changed outcome was therefore a RecursionError on main. If every provider is mid-computation, the lookup misses and tracing fails with "is not tracked with proxy" instead of hanging. Cycles that close through a registered thunk rather than a table lookup are not covered and still recurse, as on main. The cost is a set add/discard per forced lazy SymInt and one dict read per symbol registration; the skip loop only runs on the fallback path.
Alternatives considered were rules restricting which SymInts may become entries, such as first registration wins, or no entries computed from untracked SymInts. AOTAutograd registers tangent placeholders before the forward runs, so each such rule either lets a tangent keep a symbol, making the forward graph depend on tangents_1, or misses cycles that close after later writes. test_unbacked_global_size_no_tangent_dependency and test_build_proxy_untracked_symint_no_tangent_dependency cover the tangent cases.
view(batch_size, seq_len, -1)feeding aRowwiseParallellinear fails underdynamic=True:mul expected 2 arguments, got 3#201838)_sympy_handlers() mapped sympy Max/Min to the helpers _nary_sym_max/_nary_sym_min. When _build_proxy_for_sym_expr() rebuilds a Max/Min on the get_proxy_slot path (e.g. contiguous strides like Max(1, u0) of a DTensor with unbacked sizes), the helper becomes an FX node target, which Inductor rejects as "is not an OpOverload". _build_proxy_for_sym_expr() already folds n-ary expressions into binary calls, so map Max/Min directly to torch.sym_max/torch.sym_min and delete the helpers. The exact #201838 repro already passes on main since #193416; this fixes the remaining _nary_sym_max failure.
The new DTensor backward tests also run under compiled autograd, where DTensor's backward graph-breaks, so they are added to known_graph_breaks_tests in test_compiled_autograd.py.
Test Plan:
The new tests fail on main and pass with this change.
This PR was authored with the assistance of an AI coding agent.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo