Repository navigation
Conversation
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
…t FSDP ranks This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > Routed-expert weights `[num_experts, rows, cols]` used `Shard(0)` when the > expert FSDP degree is at most the number of local experts, and `Shard(1)` > otherwise. `Shard(0)` pads whenever the local experts don't divide evenly > (e.g. 12 local experts over 8 ranks hold 2, 2, 2, 2, 2, 2, 0, 0 experts), and > `Shard(1)` needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on every > all-gather and reduce-scatter. > > `_expert_shard_placement` now picks: > - `Shard(0)` when the local experts divide evenly over the expert FSDP > ranks: each rank holds whole experts, with no padding; > - otherwise `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. > > Two cases keep the old `Shard(1)` / padded `Shard(0)` rule until they support > `BlockShard` storage: > - DistMuon: its storage-placement handling only understands `Replicate`, > `Shard`, and `_StridedShard`. `TrainingEngine.Config` turns off the new > `parallelism.expert_fsdp_block_shard` flag when an optimizer param group uses > DistMuon. > - Tensor subclasses with FSDP extensions (float8/MXFP8 grouped experts): > FSDP2 raises `NotImplementedError` for `BlockShard` with them. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > `_expert_shard_placement` returns `Shard(0)` for evenly divisible local > experts, `BlockShard` otherwise, and the old rule for subclasses and with > `use_block_shard=False`. Not yet validated end to end: the deepseek_v3 debug > model run needs the `grain` data loader, and importing `TrainingEngine` fails > in the local env (`spmd_types` version mismatch), so the DistMuon flag flip > is untested here. ghstack-source-id: fcdb8a2 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
…t FSDP ranks This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > Routed-expert weights `[num_experts, rows, cols]` used `Shard(0)` when the > expert FSDP degree is at most the number of local experts, and `Shard(1)` > otherwise. `Shard(0)` pads whenever the local experts don't divide evenly > (e.g. 12 local experts over 8 ranks hold 2, 2, 2, 2, 2, 2, 0, 0 experts), and > `Shard(1)` needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on every > all-gather and reduce-scatter. > > Expert placements are now: > - `Shard(0)` when the local experts divide evenly over the expert FSDP > ranks: each rank holds whole experts, with no padding; > - otherwise `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. > > Two cases keep the old `Shard(1)` / padded `Shard(0)` rule until they support > `BlockShard` storage: > - DistMuon: its storage-placement handling only understands `Replicate`, > `Shard`, and `_StridedShard`. `TrainingEngine.Config` turns off the new > `parallelism.expert_fsdp_block_shard` flag when an optimizer param group uses > DistMuon. > - Tensor subclasses with FSDP extensions (float8/MXFP8 grouped experts): > FSDP2 raises `NotImplementedError` for `BlockShard` with them. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > The placement rule picks `Shard(0)` for evenly divisible local > experts, `BlockShard` otherwise, and the old rule for subclasses and with > `expert_fsdp_block_shard=False`. Not yet validated end to end: the deepseek_v3 debug > model run needs the `grain` data loader, and importing `TrainingEngine` fails > in the local env (`spmd_types` version mismatch), so the DistMuon flag flip > is untested here. ghstack-source-id: a71e080 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
…t FSDP ranks This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > Routed-expert weights `[num_experts, rows, cols]` used `Shard(0)` when the > expert FSDP degree is at most the number of local experts, and `Shard(1)` > otherwise. `Shard(0)` pads whenever the local experts don't divide evenly > (e.g. 12 local experts over 8 ranks hold 2, 2, 2, 2, 2, 2, 0, 0 experts), and > `Shard(1)` needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on every > all-gather and reduce-scatter. > > Expert placements are now `Shard(0)` when the local experts divide evenly > over the expert FSDP ranks (each rank holds whole experts, with no padding), > and otherwise `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. > > Known limitations when the local experts don't divide evenly (evenly > divisible runs are unchanged): > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Both used `Shard(1)` or padded `Shard(0)` before. Supporting `BlockShard` in > FSDP2 extensions (torchao) and in DistMuon's storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: d7a9b6b Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
…t FSDP ranks This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > Routed-expert weights `[num_experts, rows, cols]` used `Shard(0)` when the > expert FSDP degree is at most the number of local experts, and `Shard(1)` > otherwise. `Shard(0)` pads whenever the local experts don't divide evenly > (e.g. 12 local experts over 8 ranks hold 2, 2, 2, 2, 2, 2, 0, 0 experts), and > `Shard(1)` needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on every > all-gather and reduce-scatter. > > Expert placements are now `Shard(0)` when the local experts divide evenly > over the expert FSDP ranks (each rank holds whole experts, with no padding), > and otherwise `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. > > Known limitations when the local experts don't divide evenly (evenly > divisible runs are unchanged): > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Both used `Shard(1)` or padded `Shard(0)` before. Supporting `BlockShard` in > FSDP2 extensions (torchao) and in DistMuon's storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: 07efce1 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > When the expert FSDP degree is larger than the number of local experts, > routed-expert weights `[num_experts, rows, cols]` used `Shard(1)` to avoid > padding. That needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on > every all-gather and reduce-scatter. They now use > `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. All other > cases keep `Shard(0)` as before. > > Known limitations in the cases that used `Shard(1)`: > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Supporting `BlockShard` in FSDP2 extensions (torchao) and in DistMuon's > storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: a09fd85 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > When the expert FSDP degree is larger than the number of local experts, > routed-expert weights `[num_experts, rows, cols]` used `Shard(1)` to avoid > padding. That needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on > every all-gather and reduce-scatter. They now use > `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. All other > cases keep `Shard(0)` as before. > > Known limitations in the cases that used `Shard(1)`: > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Supporting `BlockShard` in FSDP2 extensions (torchao) and in DistMuon's > storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: 4380d7b Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > When the expert FSDP degree is larger than the number of local experts, > routed-expert weights `[num_experts, rows, cols]` used `Shard(1)` to avoid > padding. That needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on > every all-gather and reduce-scatter. They now use > `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. All other > cases keep `Shard(0)` as before. > > Known limitations in the cases that used `Shard(1)`: > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Supporting `BlockShard` in FSDP2 extensions (torchao) and in DistMuon's > storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: 4349a67 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > When the expert FSDP degree is larger than the number of local experts, > routed-expert weights `[num_experts, rows, cols]` used `Shard(1)` to avoid > padding. That needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on > every all-gather and reduce-scatter. They now use > `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. All other > cases keep `Shard(0)` as before. > > Known limitations in the cases that used `Shard(1)`: > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Supporting `BlockShard` in FSDP2 extensions (torchao) and in DistMuon's > storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: 4349a67 Pull-Request: #4989
weifengpy
added a commit
that referenced
this pull request
Oct 1, 2026
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review. > When the expert FSDP degree is larger than the number of local experts, > routed-expert weights `[num_experts, rows, cols]` used `Shard(1)` to avoid > padding. That needs `rows % fsdp_degree == 0` and costs a chunk-cat copy on > every all-gather and reduce-scatter. They now use > `BlockShard.split_leading(shape, 2)`, which shards the merged > `num_local_experts * rows` dim like `Shard(0)` of the flattened weight: no > padding and no reorder copies, for any FSDP degree. With EP > 1 the expert > params become `(R, BlockShard, Shard(0))` on the sparse mesh. All other > cases keep `Shard(0)` as before. > > Known limitations in the cases that used `Shard(1)`: > - float8/MXFP8 grouped experts (tensor subclasses with FSDP extensions): > FSDP2 raises `NotImplementedError` for `BlockShard` with them; > - DistMuon: it raises `NotImplementedError` for `BlockShard` storage when the > optimizer is built. > Supporting `BlockShard` in FSDP2 extensions (torchao) and in DistMuon's > storage handling are follow-ups. > > `BlockShard` is imported unconditionally, following torchtitan's > latest-nightly requirement, so this needs a nightly that includes the PyTorch > stack (pytorch/pytorch#199232 -> #199235 -> #199234). > > Test Plan > > Not yet validated end to end: the deepseek_v3 debug model run needs the > `grain` data loader, and importing the trainer fails in the local env > (`spmd_types` version mismatch). `torchtitan.distributed.fsdp` imports. ghstack-source-id: f432bbf Pull-Request: #4989
tianyu-l
reviewed
Oct 2, 2026
| expert_placements: dict[nn.Parameter, Shard | BlockShard] = { | ||
| # Merge the [num_experts, rows] dims; each block is the rest. | ||
| param: ( | ||
| BlockShard(block_numels=(math.prod(param.shape[2:]),)) |
Contributor
There was a problem hiding this comment.
discussed offline:
- the benefit is that this allows flattened dim-0 and dim-1 to be used together for FSDP sharding
- question is when it'd be useful? It is useful when non of
num_experts // EP degreeorfeaturedim is larger than EDP degree -- the former is the reason we shard on dim-1, but the latter sounds ... surprising
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
This PR was authored with an AI assistant (Claude Code). The description below is AI-generated and is pending author review.