Skip to content

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

Closed
bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1050/basefrom
gh/bobrenjc93/1050/head
Closed

bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1050/basefrom
gh/bobrenjc93/1050/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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 and costs an argument load per tangent, measured at
0.5ns.

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

Three tests: the end-to-end message, driving a None back into the
intermediate-base slot by patching out the dedup from the commit below; 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.

Differential Revision: D117125058

[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 23, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 20 New Failures

As of commit e71b5ff with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have failed:

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

This was referenced Aug 23, 2026
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362; this change lives in #195358. Closing to consolidate review there. The branch is kept on GitHub.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1050/head branch November 11, 2026 01:46
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 topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant