Repository navigation
[aot_autograd] Name the forward output when a kept tangent slot arrives as None - #195358
bobrenjc93 wants to merge 67 commits into
Conversation
[ghstack-poisoned]
🔗 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]
…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]
…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
…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
…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]
|
Thanks for the review. All findings addressed: Fixed in code
Answered in the PR description FAQ
The recursive subclass-attribute pass-through branch and the generic @claude please re-review. |
|
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 Full re-reviewVerification of the previous findings
Compiled autograd BC — resolved, but not by the argument in the FAQThe FAQ answers "CA reuses the same prologue, so the check runs identically." True but orthogonal — my concern was whether CA lets a The actual answer is in Remaining findings
Testing
RecommendationApprove 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. |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
Thanks for the re-review. Addressed at HEAD:
Deferred with rationale in new FAQ entries in the PR description:
|
[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]
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:
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_tangentnow raises for kept slots, naming the output behindthe slot:
The tangent descriptor (a
TangentAOTInputover aPlainAOTOutputor anIntermediateBaseAOTOutputwhosebase_ofnames the user output), the compileid 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:
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]