Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186442
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (4 Unrelated Failures)As of commit f6587ef with merge base 757703a ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
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. |
|
Before (buggy): After (fixed): |
|
@pytorchbot label "topic: not user facing" |
|
Verified this fixes the crash seen with Inductor in pytorch/torchtitan#3497 |
|
@claude Review |
|
Claude finished @aditvenk's task in 2m 10s —— View job PR Review: Wait nested AsyncCollectiveTensor in DTensor under subclass codegen
Overall: This is a well-reasoned fix for a real correctness/crash bug. The approach is sound -- handling ACT as a special case in the recursive unwrap codegen is the right call since ACT is a transient wrapper that may or may not be present at runtime. Implementation (
|
aorenste
left a comment
There was a problem hiding this comment.
[blocker] This is a forward-only fix and shouldn't land as the nested-ACT fix without completing the backward side. Top-level ACTs are resolved in process_inputs at trace time (so they never enter the traced metadata); this PR instead keeps the nested ACT in the metadata and handles it only in the unwrap codegen. That divergence leaves a backward correctness gap.
Backward/tangent gap: the top-level scan in process_inputs is non-recursive, so a nested ACT survives into the traced metadata -- including the tangent metadata derived from forward outputs. A grad-requiring DTensor(_local_tensor=ACT) that reaches a forward output via passthrough / view-only ops (ACT unwraps on non-view compute, so only those preserve it) records _local_tensor: AsyncCollectiveTensor in the tangent meta; at backward, autograd supplies a plain-local cotangent and process_runtime_tangent raises Expected a AsyncCollectiveTensor tangent but got a plain Tensor -- the same mismatch the top-level unwrap exists to prevent, one level down. (Static analysis, not reproduced; the new tests are forward-only so it is uncovered.)
The fix -- generalize the top-level mechanism to ACT paths. Make process_inputs recurse, resolve nested ACTs at trace time (record (input_index, attr_path) instead of flat indices) and re-wait per-path at runtime. That gives one mechanism for top-level and nested, fixes forward and backward together, and removes the divergence. It supersedes this PR's unwrap-codegen ACT branch: once the ACT is gone from the metadata, that branch is dead code. The forward crash (torchtitan #3497) is real, but the path-based fix covers it too -- so landing the codegen version first just means redoing and reverting it.
It also subsumes the top-level act_input_indices wait in _codegen_subclass_wrapper_source, which today is unconditional (args[i] = args[i].trigger_wait()) and so crashes under non-strict tracing / direct aot_* entry points when the runtime arg has already collapsed to a plain tensor (same 'Tensor' object has no attribute 'trigger_wait' -- there's no dynamo type-guard there). The path-based re-wait would carry the type and guard uniformly.
1e69f01 to
e47c6c4
Compare
|
@claude Check failing tests in latest CI run |
|
Claude finished @aditvenk's task in 1m 47s —— View job Checking Failing Tests in Latest CI Run
SummaryThere is 1 failing test in the latest CI run, and it is a pre-existing trunk failure (not introduced by this PR). Failed job: Failed test: Error: The test fails when calling Verdict: Unrelated to this PRThe pytorch-bot already flagged this as BROKEN TRUNK -- this same test also fails on the merge base commit ( No action needed from this PR. Rebasing onto |
aorenste
left a comment
There was a problem hiding this comment.
[blocker] This is close but needs a little change: I think this is doing too much work at runtime instead of unwrapping the subclasses directly into waits.
(Claude Review) [cleanup] Follow-up test gap (not blocking). The runtime wait for act_input_paths on a warm AOTAutograd cache hit depends on the field surviving the ViewAndMutationMeta pickle round-trip. That holds today (the whole GenericAOTAutogradResult, metadata included, is pickled wholesale), and test_different_act_input_paths covers the cache key. What is untested is the hit path: compile with an ACT input -> populate the cache -> drop the in-memory compiled fn -> recompile into a cache hit -> assert the wrapper still emits trigger_wait(). If metadata serialization is ever narrowed to a field subset (as some other inductor caches do), this field would be silently dropped and the in-flight-read bug this PR fixes would regress on warm caches with nothing catching it. A small warm-cache regression test would lock the contract.
|
@aorenste thanks for your feedback. I have changed to avoiding unwrapping at runtime. PTAL again. Thanks |
|
@pytorchbot merge |
|
@claude review failures in latest CI run whether they are caused by this PR |
|
Claude finished @aditvenk's task in 3m 35s —— View job CI failure review — all 4 failures are caused by this PR
The only failing workflow on the latest commit is trunk (the 1 & 2.
|
| Failure | Caused by this PR? |
|---|---|
test_compile_dtensor_local_tensor_act_backward_passthrough (CUDA, ROCm) |
Yes — new test incompatible with the compiled-autograd test wrapper |
test_act_input_paths_cache_hit (macOS) |
Yes — missing distributed-build skip guard |
test_act_wait_nested_codegen (macOS) |
Yes — missing distributed-build skip guard / ACT type not loaded |
LinearCrossEntropyLoss (inductor-cpu) |
No — pre-existing broken trunk |
None of these are flaky or infra-related; all three new-test failures need code changes before merge. The merge attempt failed specifically on #1.
c35db20 to
92fb510
Compare
|
@claude can you rebase on top of main fixing merge conflicts reported? |
|
Claude finished @aditvenk's task in 2m 21s —— View job Rebase onto
|
AOTAutograd previously handled AsyncCollectiveTensor inputs only when the ACT was itself a top-level input. Nested ACTs, such as a DTensor whose _local_tensor is an ACT from async redistribution or FSDP2 async all-gather, could survive into traced subclass metadata. That created two related problems. Forward execution under Inductor could use in-flight data if the ACT was not waited before the compiled graph consumed it, and backward metadata could record an ACT tangent expectation even though autograd later supplies a plain local tensor cotangent. Fix this by making process_inputs recursively resolve ACTs through traceable wrapper subclass attributes. It records each ACT location as an input index plus attribute path, waits at trace time before fakification, and stores those paths on ViewAndMutationMeta. The generated subclass wrapper then follows the same paths at runtime and waits only if the runtime leaf is still an ACT, so direct AOTAutograd entry points also tolerate a later plain tensor at a path that was ACT during tracing. Because the ACT paths affect the runtime wrapper, include them in the AOTAutograd cache key. This specializes cached entries by the ACT path set rather than patching loaded metadata after cache lookup; keeping the paths in the key makes the wrapper contract explicit and avoids reusing a compiled wrapper with stale ACT path assumptions. When nested ACT resolution rebuilds a wrapper input, preserve Dynamo's symbolic context on the replacement. Without that, fakeification can allocate source-less shape symbols and Inductor can fail while emitting shape guards for the compiled graph. Fixes #180614 Test Plan: ```bash python test/distributed/tensor/test_dtensor_compile.py TestDTensorCompile.test_compile_waits_act_nested_in_dtensor_local_tensor TestDTensorCompile.test_direct_aot_dtensor_local_tensor_act_to_plain_no_crash TestDTensorCompile.test_compile_dtensor_local_tensor_act_backward_passthrough python test/distributed/test_c10d_functional_native.py ACTCompileTest.test_direct_aot_top_level_act_path_accepts_plain_runtime_input python test/dynamo/test_aot_autograd_cache.py AOTAutogradCachePicklerTests.test_different_act_input_paths git diff --check python -m py_compile torch/_functorch/_aot_autograd/frontend_utils.py torch/_functorch/_aot_autograd/subclass_codegen.py torch/_functorch/aot_autograd.py test/distributed/tensor/test_dtensor_compile.py test/distributed/test_c10d_functional_native.py test/dynamo/test_aot_autograd_cache.py lintrunner -a -m origin/main lintrunner -a ``` Authored with assistance from an AI assistant.
Strengthen the nested ACT DTensor regression tests by asserting that the
measured second invocation reuses the graph compiled from the ACT input. Without
that precondition, a future guard change could recompile on the second call and
make the tests pass through retracing instead of exercising the runtime ACT path.
The torch.compile test now uses CompileCounterWithBackend("inductor") and the
direct AOTAutograd test counts fw_compiler invocations, matching the two
different compilation paths under test.
Test Plan:
```bash
python test/distributed/tensor/test_dtensor_compile.py TestDTensorCompile.test_compile_waits_act_nested_in_dtensor_local_tensor TestDTensorCompile.test_direct_aot_dtensor_local_tensor_act_to_plain_no_crash TestDTensorCompile.test_compile_dtensor_local_tensor_act_backward_passthrough
python -m py_compile test/distributed/tensor/test_dtensor_compile.py
git diff --check
lintrunner -a -m origin/main
lintrunner -a
```
Authored with assistance from an AI assistant.
The previous path-based runtime wait followed ACT paths before input unwrapping and rebuilt wrapper subclasses with waited leaves. That worked but did too much runtime work: a wrapper could be reconstructed once per ACT path, and the wait logic lived beside rather than inside the existing subclass unwrap codegen. Instead, group ACT paths at codegen time and thread the relevant path set through the input unwrapping emitter. Top-level ACT paths now emit a guarded wait around the plain input, and nested ACT paths emit the guarded wait at the exact subclass leaf that is appended to the flat compiled-graph inputs. This preserves the plain-runtime fallback while avoiding runtime wrapper reconstruction. The follow-up tests split the contracts: subclass codegen tests assert the generated top-level and nested ACT wait source, while the AOTAutograd cache test only verifies that an ACT-path compile produces a cache miss followed by a hit. Test Plan: ```bash python test/functorch/test_subclass_codegen.py ``` ```bash python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_act_input_paths_cache_hit AOTAutogradCachePicklerTests.test_different_act_input_paths ``` ```bash python test/distributed/tensor/test_dtensor_compile.py TestDTensorCompile.test_compile_waits_act_nested_in_dtensor_local_tensor TestDTensorCompile.test_direct_aot_dtensor_local_tensor_act_to_plain_no_crash TestDTensorCompile.test_compile_dtensor_local_tensor_act_backward_passthrough ``` ```bash python test/distributed/test_c10d_functional_native.py ACTCompileTest.test_direct_aot_top_level_act_path_accepts_plain_runtime_input ``` ```bash python -m py_compile test/functorch/test_subclass_codegen.py test/dynamo/test_aot_autograd_cache.py torch/_functorch/_aot_autograd/frontend_utils.py torch/_functorch/_aot_autograd/subclass_codegen.py ``` ```bash git diff --check ``` ```bash lintrunner -a -m origin/main lintrunner -a ``` Authored with assistance from an AI assistant.
The ACT input path type appears across the tracing, cache, metadata, and subclass codegen layers. Add shared aliases in the AOTAutograd schemas module and use them at API boundaries and mutable metadata fields so the path contract is named consistently instead of repeating the nested tuple annotation. Also share the lazy ACT type lookup used by tracing and subclass codegen. The helper only imports AsyncCollectiveTensor if distributed functional collectives are already loaded, avoiding an eager distributed import from unrelated AOT Autograd paths. While updating the tracing-side use, hoist the Dynamo tracing context lookup out of the ACT input scan loop. Test Plan: ```bash python -m py_compile torch/_functorch/_aot_autograd/schemas.py torch/_functorch/_aot_autograd/frontend_utils.py torch/_functorch/_aot_autograd/subclass_codegen.py torch/_functorch/_aot_autograd/autograd_cache.py torch/_functorch/aot_autograd.py ``` ```bash python -m py_compile torch/_functorch/_aot_autograd/utils.py torch/_functorch/_aot_autograd/frontend_utils.py torch/_functorch/_aot_autograd/subclass_codegen.py ``` ```bash python test/functorch/test_subclass_codegen.py ``` ```bash python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_act_input_paths_cache_hit AOTAutogradCachePicklerTests.test_different_act_input_paths ``` ```bash python test/distributed/test_c10d_functional_native.py ACTCompileTest.test_direct_aot_top_level_act_path_accepts_plain_runtime_input ``` ```bash python test/distributed/tensor/test_dtensor_compile.py TestDTensorCompile.test_compile_waits_act_nested_in_dtensor_local_tensor TestDTensorCompile.test_compile_dtensor_local_tensor_act_backward_passthrough ``` ```bash lintrunner -a -m origin/main lintrunner -a ``` Authored with assistance from an AI assistant.
The generated ACT wait helper previously resolved AsyncCollectiveTensor from sys.modules on each runtime invocation and used an exact type check. Trace-time ACT path recording uses isinstance, so pass the already-loaded ACT type into the generated helper and use the same isinstance check at runtime. This avoids repeating module lookup on the hot path and keeps trace-time and runtime ACT detection aligned. The warm AOTAutograd cache test now verifies that the cache-hit wrapper actually waits the runtime ACT input. Result equality alone is not enough because wait_tensor on the test tensor is an identity; the test now patches wait_tensor and checks the ACT completed flag on the warm cache-hit call. Test Plan: ```bash python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_act_input_paths_cache_hit AOTAutogradCachePicklerTests.test_different_act_input_paths ``` ```bash python test/functorch/test_subclass_codegen.py ``` ```bash python -m py_compile test/dynamo/test_aot_autograd_cache.py torch/_functorch/_aot_autograd/subclass_codegen.py ``` ```bash git diff --check ``` ```bash lintrunner -a -m origin/main ``` ```bash lintrunner -a ``` Authored with assistance from an AI assistant.
The nested ACT regression tests added by this stack exposed two test-environment assumptions. The cache and source-codegen tests require distributed because they need the AsyncCollectiveTensor type, while macOS CI can build without distributed. Guard those tests so they skip cleanly in non-distributed builds. The new DTensor backward passthrough test is valid for the normal AOTAutograd path, but compiled-autograd's auto-generated DTensor suite currently graph breaks in DTensor backward while calling the global-shape helper. Skip this single test in the compiled-autograd wrapper until that DTensor backward path is supported there. Finally, let subclass codegen import the ACT type when ACT input paths are present. The broad input-processing path still uses the no-side-effect helper, so ordinary AOTAutograd compilations do not import distributed just to check for ACTs. Test Plan: ```bash python test/functorch/test_subclass_codegen.py TestSubclassCodegen.test_act_wait_top_level_codegen TestSubclassCodegen.test_act_wait_nested_codegen ``` ```bash python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_act_input_paths_cache_hit AOTAutogradCachePicklerTests.test_different_act_input_paths ``` ```bash python test/inductor/test_compiled_autograd.py TestDTensorCompileWithCompiledAutograd.test_compile_dtensor_local_tensor_act_backward_passthrough ``` ```bash python -m py_compile torch/_functorch/_aot_autograd/utils.py torch/_functorch/_aot_autograd/subclass_codegen.py test/functorch/test_subclass_codegen.py test/dynamo/test_aot_autograd_cache.py test/inductor/test_compiled_autograd.py ``` ```bash git diff --check ``` ```bash lintrunner -a -m origin/main lintrunner -a ``` Authored with assistance from an AI assistant.
After rebasing onto main, subclass wrapper codegen emits the output index bookkeeping for these ACT wait wrappers even though their output metadata is plain. The tests still cover the same ACT wait insertion points, but their inline expected sources need to reflect the current generated wrapper shape. Test Plan: ```bash python test/distributed/tensor/test_dtensor_compile.py TestDTensorCompile.test_compile_waits_act_nested_in_dtensor_local_tensor TestDTensorCompile.test_direct_aot_dtensor_local_tensor_act_to_plain_no_crash TestDTensorCompile.test_compile_dtensor_local_tensor_act_backward_passthrough ``` ```bash python test/distributed/test_c10d_functional_native.py ACTCompileTest.test_direct_aot_top_level_act_path_accepts_plain_runtime_input ``` ```bash python test/dynamo/test_aot_autograd_cache.py AOTAutogradCacheTests.test_act_input_paths_cache_hit AOTAutogradCachePicklerTests.test_different_act_input_paths ``` ```bash python test/functorch/test_subclass_codegen.py TestSubclassCodegen.test_act_wait_top_level_codegen TestSubclassCodegen.test_act_wait_nested_codegen ``` ```bash lintrunner -a ``` Authored with assistance from an AI assistant.
92fb510 to
f6587ef
Compare
|
@claude review failing tests in latest CI whether they are caused by this PR |
|
Claude finished @aditvenk's task in 59s —— View job CI failure review — all failures are unrelated to this PR
On the latest commit
The 2 failing workflows are
These are exactly the failures Dr. CI already classified in the PR status comment: the three inductor timm/torchbench model failures are FLAKY (matched against existing trunk flakes), and the VerdictNone of the current CI failures are caused by this PR. All are model-benchmark flakes or a pre-existing trunk regression-test failure, in code paths unrelated to nested-ACT resolution. Notably, the earlier real PR-caused failures (the compiled-autograd backward-passthrough test and the two macOS distributed-build skip-guard failures) are now resolved — the Dr. CI's banner reflects this: "You can merge normally! (4 Unrelated Failures)." Rebasing onto |
|
@pytorchbot merge |
1 similar comment
|
@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 |
|
Can't merge closed PR #186442 |
AOTAutograd previously handled AsyncCollectiveTensor inputs only when the ACT was itself a top-level input. Nested ACTs, such as a DTensor whose `_local_tensor` is an ACT from async redistribution or FSDP2 async all-gather, could survive into traced subclass metadata. That created two related problems: forward execution under Inductor could use in-flight data if the ACT was not waited before the compiled graph consumed it, and backward metadata could record an ACT tangent expectation even though autograd later supplies a plain local tensor cotangent. Fix this by making `process_inputs` recursively resolve ACTs through traceable wrapper subclass attributes. It records each ACT location as an input index plus attribute path, waits at trace time before fakification, and stores those paths on `ViewAndMutationMeta`. At runtime, the generated subclass wrapper now threads those recorded ACT paths into the existing input unwrapping codegen. Top-level ACT paths emit a guarded wait around the plain input, and nested ACT paths emit the guarded wait at the exact subclass leaf that is appended to the compiled graph's flat inputs. This avoids rebuilding wrapper subclasses at runtime and still tolerates direct AOTAutograd entry points where a path that was ACT during tracing is later a plain tensor. Because ACT paths affect the generated runtime wrapper, include them in the AOTAutograd cache key. This specializes cached entries by the ACT path set rather than patching loaded metadata after cache lookup. When nested ACT resolution rebuilds a wrapper input during tracing, preserve Dynamo's symbolic context on the replacement. Without that, fakeification can allocate source-less shape symbols and Inductor can fail while emitting shape guards for the compiled graph. Fixes pytorch#180614 Pull Request resolved: pytorch#186442 Approved by: https://github.com/aorenste
AOTAutograd previously handled AsyncCollectiveTensor inputs only when the ACT was itself a top-level input. Nested ACTs, such as a DTensor whose `_local_tensor` is an ACT from async redistribution or FSDP2 async all-gather, could survive into traced subclass metadata. That created two related problems: forward execution under Inductor could use in-flight data if the ACT was not waited before the compiled graph consumed it, and backward metadata could record an ACT tangent expectation even though autograd later supplies a plain local tensor cotangent. Fix this by making `process_inputs` recursively resolve ACTs through traceable wrapper subclass attributes. It records each ACT location as an input index plus attribute path, waits at trace time before fakification, and stores those paths on `ViewAndMutationMeta`. At runtime, the generated subclass wrapper now threads those recorded ACT paths into the existing input unwrapping codegen. Top-level ACT paths emit a guarded wait around the plain input, and nested ACT paths emit the guarded wait at the exact subclass leaf that is appended to the compiled graph's flat inputs. This avoids rebuilding wrapper subclasses at runtime and still tolerates direct AOTAutograd entry points where a path that was ACT during tracing is later a plain tensor. Because ACT paths affect the generated runtime wrapper, include them in the AOTAutograd cache key. This specializes cached entries by the ACT path set rather than patching loaded metadata after cache lookup. When nested ACT resolution rebuilds a wrapper input during tracing, preserve Dynamo's symbolic context on the replacement. Without that, fakeification can allocate source-less shape symbols and Inductor can fail while emitting shape guards for the compiled graph. Fixes pytorch#180614 Pull Request resolved: pytorch#186442 Approved by: https://github.com/aorenste
AOTAutograd previously handled AsyncCollectiveTensor inputs only when the ACT was itself a top-level input. Nested ACTs, such as a DTensor whose
_local_tensoris an ACT from async redistribution or FSDP2 async all-gather, could survive into traced subclass metadata. That created two related problems: forward execution under Inductor could use in-flight data if the ACT was not waited before the compiled graph consumed it, and backward metadata could record an ACT tangent expectation even though autograd later supplies a plain local tensor cotangent.Fix this by making
process_inputsrecursively resolve ACTs through traceable wrapper subclass attributes. It records each ACT location as an input index plus attribute path, waits at trace time before fakification, and stores those paths onViewAndMutationMeta.At runtime, the generated subclass wrapper now threads those recorded ACT paths into the existing input unwrapping codegen. Top-level ACT paths emit a guarded wait around the plain input, and nested ACT paths emit the guarded wait at the exact subclass leaf that is appended to the compiled graph's flat inputs. This avoids rebuilding wrapper subclasses at runtime and still tolerates direct AOTAutograd entry points where a path that was ACT during tracing is later a plain tensor.
Because ACT paths affect the generated runtime wrapper, include them in the AOTAutograd cache key. This specializes cached entries by the ACT path set rather than patching loaded metadata after cache lookup.
When nested ACT resolution rebuilds a wrapper input during tracing, preserve Dynamo's symbolic context on the replacement. Without that, fakeification can allocate source-less shape symbols and Inductor can fail while emitting shape guards for the compiled graph.
Fixes #180614
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98