Skip to content

[aot_autograd] Name the forward output when a kept tangent slot arrives as None - #195358

Closed
bobrenjc93 wants to merge 67 commits into
gh/bobrenjc93/1098/basefrom
gh/bobrenjc93/1098/head
Closed

bobrenjc93 wants to merge 67 commits into
gh/bobrenjc93/1098/basefrom
gh/bobrenjc93/1098/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

When the compiled backward is handed None for a tangent slot it requires, the
first thing to fail is inductor, several frames below AOTAutograd:

assert_size_stride_grouped((tangents_1, tangents_3), ((s10,), (s10,)), ((1,), (1,)), 'input')
TypeError: expected Tensor() for op: input

That names a codegen'd variable, the grouped members are neither positional nor
complete, and it does not say which member was None, so it cannot be mapped
back to a user output.

process_runtime_tangent now raises for kept slots, naming the output behind
the slot:

The compiled backward in compiled graph [1/0] was handed None instead of a
Tensor for tangent 1, the gradient of the intermediate base behind forward
output 0. The backward requires this tangent, so this is a bug in
AOTAutograd or the backend (materialize_grads / mark_non_differentiable
mismatch); please report it.
The forward output was created here:
<stack trace>

The tangent descriptor (a TangentAOTInput over a PlainAOTOutput or an
IntermediateBaseAOTOutput whose base_of names the user output), the compile
id and the creation stack are already passed in, so no metadata or schema field
is added, and both prologue shapes reach the same check. A None for a dropped
slot, and the recursive call for subclass attributes, still pass through.

This is a diagnostic, not a fix: the one known cause (an output aliasing
another returned slot) is fixed in the commit below, and the current error
gives a reporter nothing to send back.

Test Plan:

python test/functorch/test_aotdispatch.py
python test/dynamo/test_aot_autograd_cache.py
python test/test_precompile.py
python test/dynamo/test_package.py

Three tests: the end-to-end message, driving a None into the intermediate-base
slot by patching out the dealias from the commit below; the same under subclass
tangents next to a TwoTensor output, through the has_subclass branch; and
dropped None slots still passing through silently.

Authored with an AI assistant.

[no ci]

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 2, 2026
…es as None

When the compiled backward is handed a None for a tangent slot it requires,
the first thing to notice is inductor, several frames below AOTAutograd:

    assert_size_stride_grouped((tangents_1, tangents_3), ((s10,), (s10,)), ((1,), (1,)), 'input')
    TypeError: expected Tensor() for op: input

That names a codegen'd variable, and the members of a grouped assert are
whichever graph inputs the first scheduler node to read them happens to read
(inductor/scheduler.py feeds codegen_deferred_input_asserts from
node.read_writes.reads), so the tuple is neither positional nor complete. It
cannot be mapped back to a user output by hand, and it does not say which of
the two members was the None.

Raise from process_runtime_tangent instead, for kept slots only, naming the
output behind the slot:

      tangent index         : 1
      received              : None (type NoneType, expected a Tensor)
      tangent descriptor    : TangentAOTInput(output=IntermediateBaseAOTOutput(base_of=PlainAOTOutput(idx=0)))
      descriptor expression : __output_tangent(__intermediate_base(output[0]))
      grad_output slot      : 4 of 5 slots returned by the compiled autograd.Function
      that slot holds       : intermediate base 0 (not a user output)
      user output index     : 0 (the output this intermediate base backs)
      its OutputType        : OutputType.alias_of_intermediate_save_as_output
      its requires_grad     : True (requires_grad_for_backward=True)
      its dtype             : torch.float32

followed by the three cases in which autograd hands back a None at all -- a
non-differentiable dtype, ctx.mark_non_differentiable, or a non-Tensor in that
slot -- and which of them this slot is, chosen by the recorded dtype. The
taxonomy is exhaustive against _process_backward_mode_ad in custom_function.cpp,
so the message can state that reaching it is a bug in AOTAutograd or the backend
rather than something the model asked for.

The dtype has to be captured in make_runtime_safe(), alongside
traced_tangent_metas: it is the last point at which the fake traced_tangents
still exist, and it is gone by the time the prologue is codegen'd. Everything
else is already available where all_surviving is built, so it is baked into the
prologue as one constant -- a frozen `KeptTangentInfo` dataclass shared by
every call -- and costs an argument load per tangent, measured at 0.5ns. Both
prologue shapes thread it: the plain loop and the has_subclass
chained-generator branch, whose codegen passes `_kept_tangent_info_` into
process_runtime_tangent positionally and independently of the loop branch.

Only kept slots raise. A None for a slot the backward dropped is legitimate and
still passes through untouched, as does the recursive call
process_runtime_tangent makes for subclass attributes.

This is a diagnostic, not a fix. It exists because the two causes found so far
-- an output aliasing another returned slot, fixed in the commit below, and a
non-differentiable dtype, which is structurally unreachable since
all_surviving keeps outputs on requires_grad_for_backward and an integer output
can never have it -- do not explain every report, and the current error gives a
reporter nothing to send back.

Test Plan:

```
python test/functorch/test_aotdispatch.py
python test/dynamo/test_aot_autograd_cache.py
python test/test_precompile.py
python test/dynamo/test_package.py
```

Four tests. The end-to-end message, driving a None back into the
intermediate-base slot by patching out the dedup from the commit below, and
asserting on the message with assertRaisesRegex. The same under subclass
tangents: a subclass output forbids output aliasing, so it uses the
sibling-output dedup case next to a TwoTensor output, which routes the prologue
through the has_subclass branch -- the trailing arguments are unread on the
happy Tensor path, so an argument reorder confined to that codegen string
would pass everything else and surface only as a garbled diagnostic; this test
fails under exactly that mutation and asserts the message names user forward
output 1 and its creation site. The non-differentiable-dtype arm, driven
directly since it cannot be reached end to end. And a negative test that six
legitimately-None dropped slots still pass through silently.

Authored with an AI assistant.

ghstack-source-id: 994d379
Pull-Request: #195358
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 2, 2026
…es as None

When the compiled backward is handed a None for a tangent slot it requires,
the first thing to notice is inductor, several frames below AOTAutograd:

    assert_size_stride_grouped((tangents_1, tangents_3), ((s10,), (s10,)), ((1,), (1,)), 'input')
    TypeError: expected Tensor() for op: input

That names a codegen'd variable, and the members of a grouped assert are
whichever graph inputs the first scheduler node to read them happens to read
(inductor/scheduler.py feeds codegen_deferred_input_asserts from
node.read_writes.reads), so the tuple is neither positional nor complete. It
cannot be mapped back to a user output by hand, and it does not say which of
the two members was the None.

Raise from process_runtime_tangent instead, for kept slots only, naming the
output behind the slot:

      tangent index         : 1
      received              : None (type NoneType, expected a Tensor)
      tangent descriptor    : TangentAOTInput(output=IntermediateBaseAOTOutput(base_of=PlainAOTOutput(idx=0)))
      descriptor expression : __output_tangent(__intermediate_base(output[0]))
      grad_output slot      : 4 of 5 slots returned by the compiled autograd.Function
      that slot holds       : intermediate base 0 (not a user output)
      user output index     : 0 (the output this intermediate base backs)
      its OutputType        : OutputType.alias_of_intermediate_save_as_output
      its requires_grad     : True (requires_grad_for_backward=True)
      its dtype             : torch.float32

followed by the three cases in which autograd hands back a None at all -- a
non-differentiable dtype, ctx.mark_non_differentiable, or a non-Tensor in that
slot -- and which of them this slot is, chosen by the recorded dtype. The
taxonomy is exhaustive against _process_backward_mode_ad in custom_function.cpp,
so the message can state that reaching it is a bug in AOTAutograd or the backend
rather than something the model asked for.

The dtype has to be captured in make_runtime_safe(), alongside
traced_tangent_metas: it is the last point at which the fake traced_tangents
still exist, and it is gone by the time the prologue is codegen'd. Everything
else is already available where all_surviving is built, so it is baked into the
prologue as one constant -- a frozen `KeptTangentInfo` dataclass shared by
every call -- and costs an argument load per tangent, measured at 0.5ns. Both
prologue shapes thread it: the plain loop and the has_subclass
chained-generator branch, whose codegen passes `_kept_tangent_info_` into
process_runtime_tangent positionally and independently of the loop branch.

Only kept slots raise. A None for a slot the backward dropped is legitimate and
still passes through untouched, as does the recursive call
process_runtime_tangent makes for subclass attributes.

This is a diagnostic, not a fix. It exists because the two causes found so far
-- an output aliasing another returned slot, fixed in the commit below, and a
non-differentiable dtype, which is structurally unreachable since
all_surviving keeps outputs on requires_grad_for_backward and an integer output
can never have it -- do not explain every report, and the current error gives a
reporter nothing to send back.

Test Plan:

```
python test/functorch/test_aotdispatch.py
python test/dynamo/test_aot_autograd_cache.py
python test/test_precompile.py
python test/dynamo/test_package.py
```

Four tests. The end-to-end message, driving a None back into the
intermediate-base slot by patching out the dedup from the commit below, and
asserting on the message with assertRaisesRegex. The same under subclass
tangents: a subclass output forbids output aliasing, so it uses the
sibling-output dedup case next to a TwoTensor output, which routes the prologue
through the has_subclass branch -- the trailing arguments are unread on the
happy Tensor path, so an argument reorder confined to that codegen string
would pass everything else and surface only as a garbled diagnostic; this test
fails under exactly that mutation and asserts the message names user forward
output 1 and its creation site. The non-differentiable-dtype arm, driven
directly since it cannot be reached end to end. And a negative test that six
legitimately-None dropped slots still pass through silently.

Authored with an AI assistant.

ghstack-source-id: d18ad01
Pull-Request: #195358
bobrenjc93 added a commit that referenced this pull request Sep 2, 2026
…es as None

When the compiled backward is handed a None for a tangent slot it requires,
the first thing to notice is inductor, several frames below AOTAutograd:

    assert_size_stride_grouped((tangents_1, tangents_3), ((s10,), (s10,)), ((1,), (1,)), 'input')
    TypeError: expected Tensor() for op: input

That names a codegen'd variable, and the members of a grouped assert are
whichever graph inputs the first scheduler node to read them happens to read
(inductor/scheduler.py feeds codegen_deferred_input_asserts from
node.read_writes.reads), so the tuple is neither positional nor complete. It
cannot be mapped back to a user output by hand, and it does not say which of
the two members was the None.

Raise from process_runtime_tangent instead, for kept slots only, naming the
output behind the slot:

      tangent index         : 1
      received              : None (type NoneType, expected a Tensor)
      tangent descriptor    : TangentAOTInput(output=IntermediateBaseAOTOutput(base_of=PlainAOTOutput(idx=0)))
      descriptor expression : __output_tangent(__intermediate_base(output[0]))
      grad_output slot      : 4 of 5 slots returned by the compiled autograd.Function
      that slot holds       : intermediate base 0 (not a user output)
      user output index     : 0 (the output this intermediate base backs)
      its OutputType        : OutputType.alias_of_intermediate_save_as_output
      its requires_grad     : True (requires_grad_for_backward=True)
      its dtype             : torch.float32

followed by the three cases in which autograd hands back a None at all -- a
non-differentiable dtype, ctx.mark_non_differentiable, or a non-Tensor in that
slot -- and which of them this slot is, chosen by the recorded dtype. The
taxonomy is exhaustive against _process_backward_mode_ad in custom_function.cpp,
so the message can state that reaching it is a bug in AOTAutograd or the backend
rather than something the model asked for.

The dtype has to be captured in make_runtime_safe(), alongside
traced_tangent_metas: it is the last point at which the fake traced_tangents
still exist, and it is gone by the time the prologue is codegen'd. Everything
else is already available where all_surviving is built, so it is baked into the
prologue as one constant -- a frozen `KeptTangentInfo` dataclass shared by
every call -- and costs an argument load per tangent, measured at 0.5ns. Both
prologue shapes thread it: the plain loop and the has_subclass
chained-generator branch, whose codegen passes `_kept_tangent_info_` into
process_runtime_tangent positionally and independently of the loop branch.

Only kept slots raise. A None for a slot the backward dropped is legitimate and
still passes through untouched, as does the recursive call
process_runtime_tangent makes for subclass attributes.

This is a diagnostic, not a fix. It exists because the two causes found so far
-- an output aliasing another returned slot, fixed in the commit below, and a
non-differentiable dtype, which is structurally unreachable since
all_surviving keeps outputs on requires_grad_for_backward and an integer output
can never have it -- do not explain every report, and the current error gives a
reporter nothing to send back.

Test Plan:

```
python test/functorch/test_aotdispatch.py
python test/dynamo/test_aot_autograd_cache.py
python test/test_precompile.py
python test/dynamo/test_package.py
```

Four tests. The end-to-end message, driving a None back into the
intermediate-base slot by patching out the dedup from the commit below, and
asserting on the message with assertRaisesRegex. The same under subclass
tangents: a subclass output forbids output aliasing, so it uses the
sibling-output dedup case next to a TwoTensor output, which routes the prologue
through the has_subclass branch -- the trailing arguments are unread on the
happy Tensor path, so an argument reorder confined to that codegen string
would pass everything else and surface only as a garbled diagnostic; this test
fails under exactly that mutation and asserts the message names user forward
output 1 and its creation site. The non-differentiable-dtype arm, driven
directly since it cannot be reached end to end. And a negative test that six
legitimately-None dropped slots still pass through silently.

Authored with an AI assistant.

ghstack-source-id: d18ad01
Pull-Request: #195358
bobrenjc93 added a commit that referenced this pull request Sep 2, 2026
…es as None

When the compiled backward is handed a None for a tangent slot it requires,
the first thing to notice is inductor, several frames below AOTAutograd:

    assert_size_stride_grouped((tangents_1, tangents_3), ((s10,), (s10,)), ((1,), (1,)), 'input')
    TypeError: expected Tensor() for op: input

That names a codegen'd variable, and the members of a grouped assert are
whichever graph inputs the first scheduler node to read them happens to read
(inductor/scheduler.py feeds codegen_deferred_input_asserts from
node.read_writes.reads), so the tuple is neither positional nor complete. It
cannot be mapped back to a user output by hand, and it does not say which of
the two members was the None.

Raise from process_runtime_tangent instead, for kept slots only, naming the
output behind the slot:

      tangent index         : 1
      received              : None (type NoneType, expected a Tensor)
      tangent descriptor    : TangentAOTInput(output=IntermediateBaseAOTOutput(base_of=PlainAOTOutput(idx=0)))
      descriptor expression : __output_tangent(__intermediate_base(output[0]))
      grad_output slot      : 4 of 5 slots returned by the compiled autograd.Function
      that slot holds       : intermediate base 0 (not a user output)
      user output index     : 0 (the output this intermediate base backs)
      its OutputType        : OutputType.alias_of_intermediate_save_as_output
      its requires_grad     : True (requires_grad_for_backward=True)
      its dtype             : torch.float32

followed by the three cases in which autograd hands back a None at all -- a
non-differentiable dtype, ctx.mark_non_differentiable, or a non-Tensor in that
slot -- and which of them this slot is, chosen by the recorded dtype. The
taxonomy is exhaustive against _process_backward_mode_ad in custom_function.cpp,
so the message can state that reaching it is a bug in AOTAutograd or the backend
rather than something the model asked for.

The dtype has to be captured in make_runtime_safe(), alongside
traced_tangent_metas: it is the last point at which the fake traced_tangents
still exist, and it is gone by the time the prologue is codegen'd. Everything
else is already available where all_surviving is built, so it is baked into the
prologue as one constant -- a frozen `KeptTangentInfo` dataclass shared by
every call -- and costs an argument load per tangent, measured at 0.5ns. Both
prologue shapes thread it: the plain loop and the has_subclass
chained-generator branch, whose codegen passes `_kept_tangent_info_` into
process_runtime_tangent positionally and independently of the loop branch.

Only kept slots raise. A None for a slot the backward dropped is legitimate and
still passes through untouched, as does the recursive call
process_runtime_tangent makes for subclass attributes.

This is a diagnostic, not a fix. It exists because the two causes found so far
-- an output aliasing another returned slot, fixed in the commit below, and a
non-differentiable dtype, which is structurally unreachable since
all_surviving keeps outputs on requires_grad_for_backward and an integer output
can never have it -- do not explain every report, and the current error gives a
reporter nothing to send back.

Test Plan:

```
python test/functorch/test_aotdispatch.py
python test/dynamo/test_aot_autograd_cache.py
python test/test_precompile.py
python test/dynamo/test_package.py
```

Four tests. The end-to-end message, driving a None back into the
intermediate-base slot by patching out the dedup from the commit below, and
asserting on the message with assertRaisesRegex. The same under subclass
tangents: a subclass output forbids output aliasing, so it uses the
sibling-output dedup case next to a TwoTensor output, which routes the prologue
through the has_subclass branch -- the trailing arguments are unread on the
happy Tensor path, so an argument reorder confined to that codegen string
would pass everything else and surface only as a garbled diagnostic; this test
fails under exactly that mutation and asserts the message names user forward
output 1 and its creation site. The non-differentiable-dtype arm, driven
directly since it cannot be reached end to end. And a negative test that six
legitimately-None dropped slots still pass through silently.

Authored with an AI assistant.

ghstack-source-id: d18ad01
Pull-Request: #195358
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All findings addressed:

Fixed in code

  • InputMutationAOTOutput slots were unnamed. The None-tangent message now
    has an InputMutationAOTOutput arm alongside PlainAOTOutput /
    IntermediateBaseAOTOutput, rendering the mutated input (via PlainAOTInput
    it reads as "the mutation of forward input N", otherwise it falls back to the
    descriptor's .expr()). About a third of reachable kept slots are
    input-mutation tangents, so they no longer drop to the opaque expr().
  • "please report it" had no destination. It now points at
    https://github.com/pytorch/pytorch/issues, matching the report-this hints
    elsewhere in the tree (e.g. partitioners.py).
  • Truthiness vs is not None. The three guards in this branch
    (tangent_desc, compile_id_str, tangent_stack_trace) now use
    is not None, consistent with the sibling _raise_tangent_metadata_error.
  • Test coverage.
    • test_none_tangent_for_a_dropped_slot_still_passes_through gained a
      structural assertion (spying process_runtime_tangent to confirm the kept
      tangent count is strictly below the seven returns, i.e. the dropped None
      slots never reach the check), not just numerics.
    • New test_none_tangent_names_a_mutated_input exercises the input-mutation
      arm directly (forcing an end-to-end None into a kept input-mutation slot is
      fragile, so it drives the renderer).
    • Both _dealias_marked_returns-patched error tests got a one-line comment
      noting that the dedup runs at backward time, so the backward must stay
      inside the patch for the None to survive.

Answered in the PR description FAQ

  • Why fail over degrade (a None in a kept slot is a real missing dependency;
    zero-filling would silently miscompute).
  • tangent_idx is None as the recursive-vs-top-level discriminator (the
    invariant is real; an explicit flag would touch the codegen strings and the
    signature for one internal recursion; possibly tightenable to an assert
    later).
  • Three-way descriptor->message duplication (the three sites render different
    shapes/intents across two modules; a shared helper adds coupling for little
    gain).
  • Compiled-autograd BC: CA re-uses the identical codegen'd prologue via
    call_aot_bwd_prologue, so this check runs the same in both paths and
    introduces no regression; materialize_grads differences are orthogonal and
    pre-existing.
  • graph_capture.py all_outputs[output_desc.idx] mutated-input misalignment:
    pre-existing, guarded (degrades to "no stack trace"), tracked separately.

The recursive subclass-attribute pass-through branch and the generic
tangent_desc.expr() fallback remain covered indirectly; happy to add a
targeted unit test for the fallback if you'd like it explicit.

@claude please re-review.

@claude

claude Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 22m 50s —— View job


Re-reviewed — all four code fixes landed correctly and the compiled-autograd BC concern is now resolved (I confirmed it in the C++ rather than taking the FAQ's argument, which addressed a different question); what remains is an off-by-one between the message's tangent N and the graph's tangents_N+1, which matters because name-mapping is this PR's whole purpose.

Full re-review

Verification of the previous findings

Finding Status
InputMutationAOTOutput unnamed Fixed — runtime_wrappers.py:3787-3792. Traced the descriptor by hand: TangentAOTInput(InputMutationAOTOutput(PlainAOTInput(idx=2))) → out=InputMutationAOTOutput, via="", falls to the new arm → "the mutation of forward input 2". Both construction sites (collect_metadata_analysis.py:798, input_output_analysis.py:287) produce exactly this shape, so the whole inp_surviving third is now named.
please report it had no destination Fixed — 3806.
Truthiness vs is not None Fixed — all three guards (3779, 3795, 3799) now use is not None, matching _raise_tangent_metadata_error.
Dropped-slot test asserted only numerics Fixed — the spy at test_aotdispatch.py:5498 plus assertLess(len(set(kept_tangent_idxs)), 7).
Input-mutation arm untested Fixed — test_none_tangent_names_a_mutated_input:5528.
_dealias_marked_returns patch-ordering undocumented Fixed — 5422-5423, 5446.

Compiled autograd BC — resolved, but not by the argument in the FAQ

The FAQ answers "CA reuses the same prologue, so the check runs identically." True but orthogonal — my concern was whether CA lets a None arrive at a surviving slot that eager would have zero-filled. Identical prologues would then mean identical new failures, not zero.

The actual answer is in torch/csrc/autograd/python_function.cpp:261: PyNode::apply_with_saved_impl calls to_py_args(inputs, &_device_guard) — the same function the eager path uses at 485. So the materialize_grads / was_default_constructed() / materialize_non_diff_grads logic at 513-519 runs in both paths, from one implementation. Combined with requires_grad_for_backward ⟹ requires_grad (collect_metadata_analysis.py:730) excluding every surviving slot from non_diff_indices (runtime_wrappers.py:3499-3504), a surviving slot is zero-materialized under CA exactly as under eager. No BC risk. Worth putting that citation in the FAQ in place of the prologue-identity argument, since it's the load-bearing one.

Remaining findings

  • runtime_wrappers.py:3803 — tangent {tangent_idx} is 0-based, but the codegen'd names it exists to demystify are 1-based. traced_tangents become the joint graph's tangents_1..N in order, and all_surviving is the same list, so slot idx is tangents_{idx+1}. The first test's message reads tangent 1 for what inductor calls tangents_2 — a reader holding the assert_size_stride_grouped((tangents_1, tangents_3), ...) traceback from the PR description has to know to add one. Since bridging exactly that gap is the point of the change, spell it out: for tangent 1 (tangents_2 in the backward graph). Fix this →

  • 3802 interpolates {x!r} on an arbitrary object. For the None case this is right, but the branch fires for any non-Tensor. If a future path routes something with a large or raising __repr__ here, the diagnostic either balloons or is replaced by an exception from inside the error path. type(x).__name__ (or x!r only when x is None) is safer for the same information.

  • 3782-3792 — via composes into nonsense for one combination, and the eager which is discarded. via="the intermediate base behind " is set before the InputMutationAOTOutput arm can run, so a hypothetical IntermediateBaseAOTOutput(base_of=InputMutationAOTOutput(...)) renders as "the intermediate base behind the mutation of forward input N". I don't think that shape is constructed today (base_of always comes from a flat_f_outs desc at collect_metadata_analysis.py:625), so this is cosmetic. Separately, which = tangent_desc.expr() at 3778 is computed and thrown away on every named path — fold it into an else.

Testing

  • test_none_tangent_for_a_dropped_slot_still_passes_through depends on the same codegen-binding-order fragility the other two tests now document, but doesn't say so. _codegen_backward_prologue binds _process_tangent_=AOTDispatchAutograd.process_runtime_tangent by value at runtime_wrappers.py:3143, so patching the class attribute only reaches the prologue because torch._dynamo.reset() precedes the with and torch.compile(f, ...) is invoked inside it (5510-5512). Reorder those two lines and the spy silently records nothing while the test still passes. One comment, same as 5422-5423.

  • assertLess(len(set(kept_tangent_idxs)), 7) is loose enough to survive a real regression. For this f the surviving set is exactly two slots (x * 3 and the one intermediate base for y[0:4]/y[4:8]), so anything up to 6 passes. assertEqual(sorted(set(kept_tangent_idxs)), [0, 1]) pins the actual behavior and would fail if the drop logic changed. Fix this →

  • test_none_tangent_names_a_mutated_input drives the renderer, not the plumbing. Reasonable given how hard the end-to-end case is to force, and the comment says so. But it passes meta=None positionally, which only works because the None branch precedes every meta use — a future reorder gives a confusing AttributeError instead of a clear failure. It also leaves the descriptor→index alignment the message depends on unverified. A cheap complement: compile a function that mutates a differentiable input and assert fw_metadata.traced_tangents_descs[0] is TangentAOTInput(InputMutationAOTOutput(...)). That pins the assumption the new arm rests on without needing a None.

  • Recursive-branch and generic-expr()-fallback coverage: still absent, as you note. I'd take the fallback test (one line, given the direct-call harness you just built) and skip the recursive one — I still believe that branch is unreachable, and a test asserting unreachable behavior is not worth much until it's either tightened to an assert or proven live.

Recommendation

Approve with nits. Nothing here blocks landing. The 0-based/1-based mismatch is the one I'd fix before merge because it undercuts the stated goal; the rest are polish.

· branch `gh/bobrenjc93/1098/head`

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. Addressed at HEAD:

  • runtime_wrappers.py tangent index (0-based vs 1-based, the blocking nit): fixed. The message now reads for tangent {tangent_idx} (tangents_{tangent_idx + 1} in the backward graph), so the human-facing index lines up with the codegen'd tangents_N names it exists to demystify. The three assertRaisesRegex in test_aotdispatch.py are updated to match (tangent 1 \(tangents_2 ..., tangent 0 \(tangents_1 ...).

Deferred with rationale in new FAQ entries in the PR description:

  • {x!r} vs type(x).__name__ on the internal-error path.
  • via composition and the which = tangent_desc.expr() initializer (it's the fallback for non-TangentAOTInput/unnamed-output paths, not dead code).
  • the dropped-slot test nits (compile-inside-patch is load-bearing; assertLess pins the invariant without change-detecting the exact kept-set; meta=None sentinel; the expr() fallback is covered by descriptor tests).

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 closed this Sep 19, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1098/head branch November 17, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request release notes: dynamo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant