Skip to content

fix: keep the tuple the autograd_function_apply fwd graph returns [9/n] - #2848

Open
bhimrazy wants to merge 1 commit into
bhimrazy/autograd-saved-for-backward-idxfrom
bhimrazy/autograd-fwd-tuple-output
Open

bhimrazy wants to merge 1 commit into
bhimrazy/autograd-saved-for-backward-idxfrom
bhimrazy/autograd-fwd-tuple-output

Conversation

@bhimrazy

Copy link
Copy Markdown
Collaborator

What does this PR do?

Keeps the tuple that the autograd_function_apply fwd graph returns, so thunderfx gives the right shape again.

Problem: since torch 2.12, the fwd subgraph dynamo builds returns its outputs as a tuple, and the caller indexes it:

return ((y,), (l_x_,))
getitem = autograd_function_apply[0]

thunder's lookaside unpacked a one-element tuple to the bare tensor, so [0] indexed into the tensor, and thunderfx returned a scalar where eager gives f32[2].

Fix: return the structure the graph produced. Bare and multi-element outputs are unchanged.

Related CI: test_higher_order_inplace_alias_update, the last failure in the core jobs on ubuntu, macOS and Windows.

Error, torch 2.14, with the rest of this stack
AssertionError: The values for attribute 'shape' do not match: torch.Size([]) != torch.Size([2]).

Part 9 of the breakdown of #2832.

@bhimrazy
bhimrazy added this pull request to stack #2849 September 24, 2026 11:12
@bhimrazy
bhimrazy force-pushed the bhimrazy/autograd-fwd-tuple-output branch from 2a8167f to 9b06fc3 Compare September 24, 2026 12:29
Since torch 2.12, the fwd subgraph dynamo builds returns its outputs as a
tuple, and the caller indexes it:

  return ((y,), (l_x_,))
  getitem = autograd_function_apply[0]

python_return(*sequencify(output)) unpacked a one-element tuple to the bare
tensor, so [0] indexed into the tensor instead, and thunderfx returned a
scalar where eager gives f32[2]. test_higher_order_inplace_alias_update:

  AssertionError: The values for attribute 'shape' do not match: torch.Size([]) != torch.Size([2]).

Return the structure the graph produced. Bare and multi-element outputs are
unchanged.
@bhimrazy
bhimrazy force-pushed the bhimrazy/autograd-fwd-tuple-output branch from 9b06fc3 to f264a8a Compare September 24, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants