Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186515
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ No Failures, 3 PendingAs of commit ff5ae12 with merge base fca7466 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review these changes |
|
Claude finished @jansel's task in 1m 20s —— View job Code Review: Fix AOTAutograd wrapper subclass metadata mutation
Overall: This is a well-structured fix for a real problem (issue #114975). The approach of teaching Design Feedback
The function returns the first tensor attr name only when all tensor attrs match the outer metadata. This is conservative and correct for
def _consume_placeholders(placeholders: list[bool]) -> None:
out_idx_ref[0] += sum(placeholders)This correctly advances the output index past any symbolic symint slots that would otherwise be consumed by Runtime path redundancy ( The runtime Potential Issue
outer_size_from_attr = getattr(meta, "outer_size_from_attr", None)
outer_stride_from_attr = getattr(meta, "outer_stride_from_attr", None)Since Test CoverageThe tests are thorough:
The comment update on Minor NitIn VerdictLooks good. The approach correctly separates subclasses where outer metadata tracks inner attrs (use runtime values) from subclasses with independent outer metadata (use recorded values). The fallback is conservative — if any ambiguity exists, it falls back to the existing static path. |
AOTAutograd was still rejecting metadata mutations on traceable wrapper subclass inputs with a blanket guard. Removing that guard alone was not enough: metadata collection could record fake wrapper output strides and subclass output wrapping would bake those stale outer strides into __tensor_unflatten__ at runtime. In the issue repro this produced a TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer stride stayed at (4, 4, 1). Teach SubclassCreationMeta to record when a wrapper subclass's outer size or stride tracks its tensor attrs. Runtime reconstruction and generated subclass wrapping code now use the runtime attr size/stride in those cases, while subclasses whose outer metadata differs from their attrs continue to use the recorded explicit outer metadata. With correct runtime wrapper metadata in place, remove the obsolete blanket metadata-mutation guard. The first generated-code path for attr-derived metadata over-advanced the flat output cursor in dynamic nested subclass cases, causing CI to read past the returned tensor leaves. The codegen now reconstructs attr-derived metadata without consuming nonexistent output slots and slices saved activations from the tail of the compiled outputs, so it also handles training graphs that still return dynamic SymInt metadata before activations. The alternative was to keep a narrower ban for metadata-mutated subclass inputs, but the runtime mutation epilogue and subclass dispatch path already handle the metadata-only case once output wrappers are rebuilt from runtime metadata. Fixes #114975 Generated by my agent Test Plan: - Direct original repro with eager-vs-compiled recursive outer/inner metadata assertions: passed - python test/functorch/test_subclass_codegen.py -v - python test/dynamo/test_subclasses.py -k test_subclass_TwoTensor_TwoTensor_TwoTensor -v - python test/functorch/test_aotdispatch.py -k subclass_metadata_mutation -v, with local torchvision import bypass due local CUDA-version mismatch in torchvision - Simple dynamic aot_function training smoke with TwoTensor and backward: passed - git diff --check && lintrunner -a ghstack-source-id: 2cfa5ad Pull-Request: #186515
|
My agent says I fixed the Dr. CI failure in test/dynamo/test_subclasses.py::TestTwoTensorSubclass::test_subclass_TwoTensor_TwoTensor_TwoTensor. The generated subclass wrapper no longer skips flat output slots when size/stride come from runtime attrs, and saved activations are sliced from the output tail so dynamic SymInt metadata cannot leak into activations. |
|
@claude review these changes |
|
Claude finished @jansel's task in 2m 27s —— View job Code Review: Fix AOTAutograd wrapper subclass metadata mutation
Overall: This is a solid fix for #114975. The approach — teaching Key Observations1. The old 2. The "all tensor attrs must agree" invariant is conservative and correct. For TwoTensor (where 3. Runtime path in
4. Both callers of One Potential ConcernInteraction with the backward epilogue path ( The backward wrapping path at Test CoverageThorough and well-targeted:
VerdictLooks good to land. The implementation is clean, the fallback to static metadata is conservative (safely handles subclasses where inner tensor metadata diverges from outer), and the |
|
Will this work with dynamic shapes? |
AOTAutograd was still rejecting metadata mutations on traceable wrapper subclass inputs with a blanket guard. Removing that guard alone was not enough: metadata collection could record fake wrapper output strides and subclass output wrapping would bake those stale outer strides into __tensor_unflatten__ at runtime. In the issue repro this produced a TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer stride stayed at (4, 4, 1). Teach SubclassCreationMeta to record when a wrapper subclass's outer size or stride tracks its tensor attrs. Runtime reconstruction and generated subclass wrapping code now use the runtime attr size/stride in those cases, while subclasses whose outer metadata differs from their attrs continue to use the recorded explicit outer metadata. With correct runtime wrapper metadata in place, remove the obsolete blanket metadata-mutation guard. The generated attr-derived metadata path still needs to keep the flat output cursor aligned with the compiled output layout. Dynamic graphs can return symbolic size and stride slots between subclass tensor leaves even when reconstruction reads size/stride from a runtime tensor attr. The wrapper now advances past those slots without using their stale values, so later subclass outputs are reconstructed from the correct flat tensor and opaque slots. The alternative was to keep a narrower ban for metadata-mutated subclass inputs, but the runtime mutation epilogue and subclass dispatch path already handle the metadata-only case once output wrappers are rebuilt from runtime metadata. Fixes #114975 Generated by my agent Test Plan: - Direct original repro with eager-vs-compiled recursive outer/inner metadata assertions: passed - python test/functorch/test_subclass_codegen.py -v - python test/distributed/tensor/test_dtensor_compile.py -k test_split_with_symint_split_size -v - python test/dynamo/test_subclasses.py -k test_subclass_TwoTensor_TwoTensor_TwoTensor -v - python test/functorch/test_aotdispatch.py -k subclass_metadata_mutation -v, with local torchvision import bypass due local CUDA-version mismatch in torchvision - Simple dynamic aot_function training smoke with TwoTensor and backward: passed - git diff --check && lintrunner -a ghstack-source-id: 5fc775f Pull-Request: #186515
|
My agent says yes, this now works with dynamic shapes. I reproduced the Dr. CI failure in test/distributed/tensor/test_dtensor_compile.py::TestDTensorCompileE2E::test_split_with_symint_split_size: generated wrapping reconstructed size/stride from a runtime tensor attr but did not advance past the SymInt metadata slots still returned by the compiled graph, so the next DTensor output read an int as its tensor attr. The update advances the flat output cursor past those dynamic SymInt slots without using their values, and adds a focused codegen regression test for multiple attr-derived subclass outputs separated by SymInt metadata slots. I verified test_split_with_symint_split_size, test_subclass_codegen.py, subclass_metadata_mutation coverage, and lintrunner. |
|
@claude review these changes |
|
Claude finished @jansel's task in 7m 15s —— View job Code Review: Fix AOTAutograd wrapper subclass metadata mutation
Overall: The fix is sound and the latest changes are correct. The core idea — recording Answer to @mlazos: does this work with dynamic shapes?Yes, and it's specifically the dynamic case the
The non-codegen runtime path ( One concern worth a note (not blocking)
Minor
TestsGood coverage: the VerdictLooks good to land — the dynamic-shapes path is handled correctly. Consider the one-line comment on |
AOTAutograd was still rejecting metadata mutations on traceable wrapper subclass inputs with a blanket guard. Removing that guard alone was not enough: metadata collection could record fake wrapper output strides and subclass output wrapping would bake those stale outer strides into __tensor_unflatten__ at runtime. In the issue repro this produced a TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer stride stayed at (4, 4, 1). Teach SubclassCreationMeta to record when a wrapper subclass's outer size or stride tracks its tensor attrs. Runtime reconstruction and generated subclass wrapping code now use the runtime attr size/stride in those cases, while subclasses whose outer metadata differs from their attrs continue to use the recorded explicit outer metadata. With correct runtime wrapper metadata in place, remove the obsolete blanket metadata-mutation guard. The generated attr-derived metadata path also has to tolerate both compiled output layouts used by dynamic subclass graphs. Some graphs return symbolic size and stride slots between subclass tensor leaves, while nested attr-derived cases can return only the tensor leaves. The generated wrapper now uses a runtime flat-output cursor and only advances past recorded SymInt placeholder slots when the compiled graph actually returned subclass SymInt outputs, keeping later nested outputs aligned without relying on stale metadata values. The alternative was to keep a narrower ban for metadata-mutated subclass inputs, but the runtime mutation epilogue and subclass dispatch path already handle the metadata-only case once output wrappers are rebuilt from runtime metadata. Fixes #114975 Generated by my agent Test Plan: - Direct original repro with eager-vs-compiled recursive outer/inner metadata assertions: passed - python test/functorch/test_subclass_codegen.py -v - python test/dynamo/test_subclasses.py -k test_subclass_TwoTensor_TwoTensor_TwoTensor -v - python test/distributed/tensor/test_dtensor_compile.py -k test_split_with_symint_split_size -v - python test/functorch/test_aotdispatch.py -k subclass_metadata_mutation -v, with local torchvision import bypass due local CUDA-version mismatch in torchvision - git diff --check - lintrunner -a ghstack-source-id: e49e917 Pull-Request: #186515
|
@claude review these changes |
|
My agent says I fixed the remaining Dr. CI failure in test/dynamo/test_subclasses.py::TestTwoTensorSubclass::test_subclass_TwoTensor_TwoTensor_TwoTensor. The generated subclass wrapper now uses a runtime flat-output cursor and only skips recorded SymInt size/stride placeholders when the compiled graph actually returned subclass SymInt outputs, so nested attr-derived TwoTensor outputs that return only tensor leaves stay aligned while DTensor dynamic-shape outputs with SymInt slots still work. I verified the failing test, test_subclass_codegen.py, test_split_with_symint_split_size, subclass_metadata_mutation coverage with the local torchvision bypass, git diff --check, and lintrunner. |
|
Claude finished @jansel's task in 4m 31s —— View job Code Review: Fix AOTAutograd wrapper subclass metadata mutation
Overall: The PR is in good shape and already has @mlazos's approval. This pass focuses on what's new since my last review — the latest commit ( What changed since the last reviewThe previous design advanced a compile-time
This correctly handles the case the third commit was chasing: a wrapper generated with symbolic placeholders, but a compiled graph specialization that doesn't actually emit the symint outputs. Walking One real asymmetry worth a look (non-blocking)
def _build_tuple(outer, placeholders):
for val, is_sym in zip(outer, placeholders):
if is_sym:
...
state.emit("_out_idx += 1") # <-- always consumes, regardless of the flagSo the two paths disagree about when symint slots are present:
For the subclasses this PR targets (TwoTensor and friends, where outer tracks inner) the attr path is always taken, so this is latent today. But if Minor
TestsCoverage is thorough. The two new unit tests ( VerdictLooks good to land. The runtime-cursor rework is the correct way to handle graphs that conditionally emit symint outputs, and it answers @mlazos's dynamic-shapes question directly. The only thing I'd consider before/after landing is making the |
|
@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 |
AOTAutograd was still rejecting metadata mutations on traceable wrapper subclass inputs with a blanket guard. Removing that guard alone was not enough: metadata collection could record fake wrapper output strides and subclass output wrapping would bake those stale outer strides into __tensor_unflatten__ at runtime. In the issue repro this produced a TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer stride stayed at (4, 4, 1). Teach SubclassCreationMeta to record when a wrapper subclass's outer size or stride tracks its tensor attrs. Runtime reconstruction and generated subclass wrapping code now use the runtime attr size/stride in those cases, while subclasses whose outer metadata differs from their attrs continue to use the recorded explicit outer metadata. With correct runtime wrapper metadata in place, remove the obsolete blanket metadata-mutation guard. The alternative was to keep a narrower ban for metadata-mutated subclass inputs, but the runtime mutation epilogue and subclass dispatch path already handle the metadata-only case once output wrappers are rebuilt from runtime metadata. Fixes pytorch#114975 Generated by my agent Test Plan: - Direct original repro with eager-vs-compiled recursive outer/inner metadata assertions: passed - python test/functorch/test_subclass_codegen.py -v - python test/functorch/test_aotdispatch.py -k subclass_metadata_mutation -v, with local torchvision import bypass due environment failure importing torchvision::nms - Targeted test_aotdispatch.py tests with the same torchvision import bypass: TestAOTDispatch.test_aot_dispatch_input_metadata_mutation, TestAOTAutograd.test_input_mutation_aliases_bases_out_of_order, TestAOTDispatch.test_aot_dispatch_input_data_and_metadata_mutation, TestAOTAutogradWithDynamo.test_compute_outer_size_and_stride_bug, TestAOTAutogradWithDynamo.test_subclass_dynamic_stride - Extra dynamic torch.compile(backend="aot_eager", dynamic=True) TwoTensor output metadata smoke script - git diff --check && lintrunner -a Pull Request resolved: pytorch#186515 Approved by: https://github.com/mlazos
AOTAutograd was still rejecting metadata mutations on traceable wrapper subclass inputs with a blanket guard. Removing that guard alone was not enough: metadata collection could record fake wrapper output strides and subclass output wrapping would bake those stale outer strides into __tensor_unflatten__ at runtime. In the issue repro this produced a TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer stride stayed at (4, 4, 1). Teach SubclassCreationMeta to record when a wrapper subclass's outer size or stride tracks its tensor attrs. Runtime reconstruction and generated subclass wrapping code now use the runtime attr size/stride in those cases, while subclasses whose outer metadata differs from their attrs continue to use the recorded explicit outer metadata. With correct runtime wrapper metadata in place, remove the obsolete blanket metadata-mutation guard. The alternative was to keep a narrower ban for metadata-mutated subclass inputs, but the runtime mutation epilogue and subclass dispatch path already handle the metadata-only case once output wrappers are rebuilt from runtime metadata. Fixes pytorch#114975 Generated by my agent Test Plan: - Direct original repro with eager-vs-compiled recursive outer/inner metadata assertions: passed - python test/functorch/test_subclass_codegen.py -v - python test/functorch/test_aotdispatch.py -k subclass_metadata_mutation -v, with local torchvision import bypass due environment failure importing torchvision::nms - Targeted test_aotdispatch.py tests with the same torchvision import bypass: TestAOTDispatch.test_aot_dispatch_input_metadata_mutation, TestAOTAutograd.test_input_mutation_aliases_bases_out_of_order, TestAOTDispatch.test_aot_dispatch_input_data_and_metadata_mutation, TestAOTAutogradWithDynamo.test_compute_outer_size_and_stride_bug, TestAOTAutogradWithDynamo.test_subclass_dynamic_stride - Extra dynamic torch.compile(backend="aot_eager", dynamic=True) TwoTensor output metadata smoke script - git diff --check && lintrunner -a Pull Request resolved: pytorch#186515 Approved by: https://github.com/mlazos
Stack from ghstack (oldest at bottom):
AOTAutograd was still rejecting metadata mutations on traceable wrapper
subclass inputs with a blanket guard. Removing that guard alone was not
enough: metadata collection could record fake wrapper output strides and
subclass output wrapping would bake those stale outer strides into
tensor_unflatten at runtime. In the issue repro this produced a
TwoTensor whose inner tensors had stride (8, 4, 1) while the wrapper outer
stride stayed at (4, 4, 1).
Teach SubclassCreationMeta to record when a wrapper subclass's outer size
or stride tracks its tensor attrs. Runtime reconstruction and generated
subclass wrapping code now use the runtime attr size/stride in those cases,
while subclasses whose outer metadata differs from their attrs continue to
use the recorded explicit outer metadata. With correct runtime wrapper
metadata in place, remove the obsolete blanket metadata-mutation guard.
The alternative was to keep a narrower ban for metadata-mutated subclass
inputs, but the runtime mutation epilogue and subclass dispatch path already
handle the metadata-only case once output wrappers are rebuilt from runtime
metadata.
Fixes #114975
Generated by my agent
Test Plan: