Skip to content

Fix DTensor double-backward patch for torch >= 2.13 - #447

Open
luciaquirke wants to merge 1 commit into
mainfrom
fix/dtensor-patch-torch-213
Open

Fix DTensor double-backward patch for torch >= 2.13#447
luciaquirke wants to merge 1 commit into
mainfrom
fix/dtensor-patch-torch-213

Conversation

@luciaquirke

Copy link
Copy Markdown
Collaborator

apply_dtensor_patch replaces Redistribute.backward with a version that reads ctx.backward_dtype and ctx.original_dtype.

torch's Redistribute.forward stored those attributes up to 2.12. From 2.13 it routes dtypes through a _DtypeConfig and stores ctx.bwd_op_dtype / ctx.bwd_out_dtype instead, so the old names are absent and the first backward raises:

AttributeError: 'RedistributeBackward' object has no attribute 'backward_dtype'

This makes fsdp=True unusable for any model.

Reproduction

torch 2.13.0+cu126, gpt2, nproc_per_node=2, fsdp: true — fails on the first backward. Not size- or architecture-specific: it surfaced while trying to train a 7B, but a 124M model fails identically, which is what isolated it to the patch rather than to model scale.

Fix

Read the dtypes through a small helper that accepts either spelling, so the patch keeps working on torch <= 2.12 and on >= 2.13.

With the fix applied, the same gpt2 + FSDP run trains normally.

🤖 Generated with Claude Code

https://claude.ai/code/session_0167XKnE2yoCE162n3jHvxC1

apply_dtensor_patch replaces Redistribute.backward with a version that reads
ctx.backward_dtype and ctx.original_dtype. torch's Redistribute.forward stored
those up to 2.12; from 2.13 it routes dtypes through a _DtypeConfig and stores
ctx.bwd_op_dtype / ctx.bwd_out_dtype instead. The old names are therefore absent
and the first backward raises

    AttributeError: 'RedistributeBackward' object has no attribute 'backward_dtype'

which makes fsdp=True unusable for any model. Reproduced on torch 2.13.0+cu126
with gpt2 and nproc_per_node=2, so it is not size- or architecture-specific.

Read the dtypes through a helper that accepts either spelling, so the patch works
on both. With the fix the same gpt2 + FSDP run trains normally.
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.

1 participant