Skip to content

FSDP2 / DDP: only keep torchao weights FSDP2 cannot shard out of fully_shard and the DDP broadcast - #15373

Merged
danielhanchen merged 3 commits into
mainfrom
dh/s7-fsdp2-torchao-fp8-only
Oct 26, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
dh/s7-fsdp2-torchao-fp8-only

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

#15001 keeps frozen load_in_fp8 weights (torchao Float8Tensor) out of FSDP2 sharding and out of the DDP broadcast. Its classifier matches every torchao tensor subclass outside torchao.float8, which catches two cases it should leave alone:

  • Frozen NF4 weights (NF4Tensor, QLoRA) are kept replicated under FSDP2Config(shard_frozen=True). Each rank holds the full packed weight instead of half of it.
  • Trainable int8 mixed precision training weights (Int8MixedPrecisionTrainingLinearWeight) are refused under FSDP2 (cannot shard trainable float8 parameters) and under DDP (NotImplementedError).

Both classes implement the FSDP2 all-gather hooks and the DDP flatten, and both trained before #15001.

Fix

  • fsdp2_native._float8_params now keeps a torchao subclass out of fully_shard only when its class implements no FSDP2 all-gather extension (fsdp_pre_all_gather). That covers Float8Tensor, AffineQuantizedTensor, and the inference int8 / int4 weights (Int8Tensor, IntxUnpackedToInt8Tensor), which implement only the ops their linear needs: fully_shard's split fails on them (NotImplementedError: Int8Tensor dispatch: ... aten.split). NF4Tensor, the int8 mixed precision training weight and torchao.float8 training weights implement the extension and go to fully_shard.
  • On the DDP side, frozen tensor subclass weights are still left out of the broadcast. Trainable weights are refused when they store float8 or when DDP's start-up broadcast cannot flatten them (Int8Tensor, AffineQuantizedTensor), so trainable int8 training weights and NF4 reach DDP as they did before Keep frozen load_in_fp8 weights out of FSDP2 sharding and the DDP broadcast #15001.

Tests

tests/test_fp8_torchao_distributed_gloo.py gets four new cases; the first three run on 2 CPU gloo ranks, the Int8Tensor one in one process.

test main this PR
frozen NF4, shard_frozen=True: both MLP weights are DTensors holding 32768 packed bytes per rank (half of 2 x 32768) fail (replicated, 0 DTensors) pass
trainable int8 mixed precision weights shard, backward gives finite grads fail (NotImplementedError) pass
DDP keeps trainable int8 weights and ignores frozen NF4; FSDP2 finds no float8 weights fail pass
frozen Int8Tensor (Int8WeightOnlyConfig) stays replicated; trainable is refused by FSDP2 and DDP up front pass pass (fails on the first revision of this PR, which sent it to fully_shard)
the 7 existing Float8Tensor FSDP2 / DDP cases pass pass

test_fsdp2_native_int8_gloo.py, test_float8_training_fsdp2_gloo.py and test_fsdp2_native_units.py still pass (72 tests with test_float8_training.py). The classifier was also run over the torchao weight classes on torchao 0.15 and 0.18 against what fully_shard and DDP actually accept: 0 wrong moves.

Not covered: GPU / NCCL runs, an end-to-end QLoRA training run under FSDP2, torchao versions other than 0.15 and 0.18, multi-node.

…fp8 weights

The frozen-weight classifier from #15001 matched every torchao tensor subclass
outside torchao.float8. Frozen NF4 weights were then replicated under
shard_frozen (twice the packed bytes per rank) and trainable int8 mixed
precision training weights were refused under FSDP2 and DDP, although both
implement the hooks they need. Match only subclasses that store float8.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T14:25:04.063214Z 46e7b44 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: a17ef9f82c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen danielhanchen changed the title FSDP2 / DDP: only treat torchao weights that store float8 as load_in_fp8 weights FSDP2 / DDP: only keep torchao weights FSDP2 cannot shard out of fully_shard and the DDP broadcast Oct 26, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 46e7b449cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f93c871 into main Oct 26, 2026
@danielhanchen
danielhanchen deleted the dh/s7-fsdp2-torchao-fp8-only branch October 26, 2026 17:25
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