Skip to content

[graph_trainer] Match Eager FSDP bucket order - #3590

Merged
IvanKobzarev merged 1 commit into
pytorch:mainfrom
IvanKobzarev:orderfix-fsdp-rs-bucket-order
Jun 11, 2026
Merged

IvanKobzarev merged 1 commit into
pytorch:mainfrom
IvanKobzarev:orderfix-fsdp-rs-bucket-order

Conversation

@IvanKobzarev

@IvanKobzarev IvanKobzarev commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Align GraphTrainer FSDP bucket packing order with Eager FSDP2.

Eager FSDP2 packs bucket payloads in managed parameter registration order, while GraphTrainer was packing FSDP collective buckets in FX graph execution order. For reduce-scatter, this changes byte offsets inside NCCL buckets. On multinode
FSDP groups, NCCL may use different channel ring orders per offset, so the same parameter elements can be reduced through a different bf16 accumulation order and lose bitwise parity.

This change derives the FSDP2 module order from traced state FQNs and sorts each FSDP bucket group by that order before delegating to the upstream manual overlap bucketer. The Torchtitan-specific logic is limited to choosing bucket payload
order; upstream still owns merging, insertion, wait remapping, and bucketed-node tagging.

Verified on 64,128,256 TP=1,8 llama3 8b

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 9, 2026
@IvanKobzarev
IvanKobzarev marked this pull request as draft June 9, 2026 16:59
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Match Eager FSDP reduce-scatter bucket order [graph_trainer] Match Eager FSDP bucket order Jun 9, 2026
@IvanKobzarev
IvanKobzarev force-pushed the orderfix-fsdp-rs-bucket-order branch 2 times, most recently from 6906967 to 98bcf11 Compare June 9, 2026 17:39
@IvanKobzarev
IvanKobzarev marked this pull request as ready for review June 9, 2026 17:43
@IvanKobzarev
IvanKobzarev force-pushed the orderfix-fsdp-rs-bucket-order branch 3 times, most recently from 6906967 to bd56b38 Compare June 9, 2026 17:56
sub_placements.append(
# pyrefly: ignore [bad-argument-type, unexpected-positional-argument]
_StridedShard(placement.dim, placement.split_factor)
_StridedShard(placement.dim, split_factor=placement.split_factor)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase over main, this is likely already fixed in main

@SherlockNoMad SherlockNoMad added the ciflow/h100.8 Trigger H100.8 CI label Jun 11, 2026
GT Regional was packing FSDP collective buckets in graph execution order.
Eager FSDP2 packs bucket payloads in managed parameter registration order.
For reduce-scatter, changing the payload order changes byte offsets inside
NCCL buckets; on multinode FSDP groups NCCL may use different ring orders per
channel, so moving parameter elements between offsets can produce different
bf16 accumulation order.

Derive module order from traced state FQNs, which preserve FSDP2's first-seen
parameter order, and use it to order every FSDP bucket group before delegating
to the upstream manual overlap bucketer. This keeps the Torchtitan-specific
logic limited to choosing bucket payload order; upstream still owns merging,
insertion, wait remapping, and bucketed-node tagging.

This also updates the existing _StridedShard call in models/utils.py to pass
split_factor by keyword. CI pyrefly removes the stale suppression there and
then reports the second positional argument, while this form matches the typed
usage elsewhere in GraphTrainer.

Authored by Codex.

Test Plan:

```bash
python -m py_compile \
  torchtitan/experiments/graph_trainer/fsdp_passes.py \
  torchtitan/experiments/graph_trainer/passes.py \
  torchtitan/models/utils.py
```

```bash
git diff --check origin/main...HEAD -- \
  torchtitan/experiments/graph_trainer/fsdp_passes.py \
  torchtitan/experiments/graph_trainer/passes.py \
  torchtitan/models/utils.py
```

```bash
black --check \
  torchtitan/experiments/graph_trainer/fsdp_passes.py \
  torchtitan/experiments/graph_trainer/passes.py \
  torchtitan/models/utils.py
```

```bash
flake8 --config=.flake8 \
  torchtitan/experiments/graph_trainer/fsdp_passes.py \
  torchtitan/experiments/graph_trainer/passes.py \
  torchtitan/models/utils.py
```

```bash
PYTHONPATH=/data/users/ivankobzarev/f/torchtitan-orderfix-main \
  python torchtitan/experiments/graph_trainer/tests/test_passes.py \
    -k TestBucketingPrefetchOrder
```

```bash
lintrunner -a
```

This failed because Torchtitan has no `.lintrunner.toml` in this checkout.
`pre-commit`, `ufmt`, and `pyrefly` are also not installed in the local Python
environment.

MAST 64-GPU TP=1/BS=1 weight-hash validation matched Eager for all 25 steps:

```text
ORDERFIX_GT8B_TP1_BS1_WHASH_Eager_8b-64gpu-64-ivankobzarev-lhpsfjn4
ORDERFIX_GT8B_TP1_BS1_WHASH_GT_Reg_NoCG_8b-64gpu-64-ivankob-t06vk4kk
```

MAST 128-GPU TP=1/BS=1 weight-hash validation matched Eager for all 25 steps:

```text
ORDERFIX_GT8B_TP1_BS1_WHASH_Eager_8b-128gpu-128-ivankobzare-dvg55jz4
ORDERFIX_GT8B_TP1_BS1_WHASH_GT_Reg_NoCG_8b-128gpu-128-ivank-qtz1q3fk
```

MAST 256-GPU TP=1/BS=1 weight-hash validation matched Eager for all 25 steps:

```text
ORDERFIX_GT8B_TP1_BS1_WHASH_Eager_8b-256gpu-256-ivankobzare-jtmfxc4z
ORDERFIX_GT8B_TP1_BS1_WHASH_GT_Reg_NoCG_8b-256gpu-256-ivank-dhm7t4th
```
@IvanKobzarev
IvanKobzarev force-pushed the orderfix-fsdp-rs-bucket-order branch from bd56b38 to ebb67be Compare June 11, 2026 17:23
@IvanKobzarev
IvanKobzarev merged commit 2f1ca1d into pytorch:main Jun 11, 2026
13 of 15 checks passed
IvanKobzarev pushed a commit to IvanKobzarev/torchtitan that referenced this pull request Jun 17, 2026
…esults

Set --training.local_batch_size 16 in the dsv3 run script and record Run 6:
batch-size scaling (B=4/8/16) for MinimalAsyncEP + forced cudagraph + pytorch#3590.
MFU 16.7%->20.6%, tps ~9k->~11.3k, memory ~36->~61 GiB / 95 GiB (no OOM).
Numerics still unverified (needs eager loss_compare).


ghstack-source-id: 0c9db28
Pull-Request: pytorch#3618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants