Unit 9 of 10 · about 4 hours · explain
FSDP with expert-sharded parameters and EP, TP and DP groups
Expert parameters need a different sharding than everything else. One flat FSDP wrap mixes the meshes; the composed plan keeps them separate and testable.
You'll be able to
- Explain how FSDP shards expert weights on the sparse mesh while dense state stays on the dense mesh.
- Compose EP, TP and data-parallel groups without double-counting ranks.
- State the validation rules that reject a bad composition.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Sparse FSDP and expert placementsTorchTitan - MoE Model and Parallelism
resolve_sparse_fsdp_meshversusresolve_fsdp_mesh, andapply_fsdp_to_decoderwithedp_mesh: routed-expert parameters use the sparse mesh while other parameters use the dense meshRead after the tiny oracle passes; record the mesh choice, do not run the trainer.
- Expert parameter placementsTorchTitan - MoE Model and Parallelism
expert_param_placement_sparse(EP shards dim 0, FSDP reshards EDP_SHARD) versusreplicated_param_placement_sparsefor shared expert state - Combining expert, model and data parallelismSwitch Transformers
Sections 5.4 and 5.5: expert plus data parallelism, then expert plus model plus data parallelism with the data, weight and expert partitioning strategies
Focus on
- Two meshes over the same ranks: dense storage and forward views for attention, router and shared experts; the sparse view for routed experts. Rank sets overlap; parameter sets do not.
- Expert weights shard dim 0 on EP and reshard on EDP_SHARD under FSDP. Shared experts and the gate stay dense-family placements.
- EP borrows ranks from the dense grid, so group sizes obey the borrowing rule, not an independent product. Degrees that ignore it fail validation.
- Switch Sections 5.4 and 5.5 are the conceptual version of the TorchTitan code: same composition, XLA-era vocabulary instead of DeviceMesh.
Common mistakes · 3
- Applying one FSDP wrap to a whole MoE layer. Dense and expert parameters need different meshes; a single wrap shards one family wrongly.
- Overlapping EP all-to-all with FSDP reduce-scatter on the same ranks without a plan. The collectives contend; order and overlap need explicit design, not hope.
- Reading Switch group vocabulary as DeviceMesh code. Translate sharding intent, not API names, across the XLA to PyTorch gap.
Try it yourself
Closed-book, before checking anything
dp_shard = 4, tp = 2, ep = 4: dense mesh axes, sparse mesh axes, edp_shard, experts per rank at , and the placement of expert weights, gate, shared experts and attention weights. State the three validation checks.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Which parameters use the sparse mesh?Answer
Only routed-expert weights. Gate, shared experts, attention and dense MLPs stay on the dense mesh.
2.State the three composition validation checks.Answer
epdivides the sparse region;ep >= tp; .3.What does EDP_SHARD reshard under FSDP?Answer
The expert weights after EP sharding: FSDP gathers and releases them around compute while dense state follows the DP mesh.
4.Why do Switch Sections 5.4 and 5.5 still matter for a DeviceMesh stack?Answer
They define the composition semantics (which dims shard, which replicate, which collectives appear) that the mesh code implements.
You're done when
Your mesh table places every parameter family correctly and rejects a bad degree with the exact rule it breaks.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 10 more in the section
- TorchTitan - MoE Model and ParallelismPyTorch · support
Read the MoE model files and their parallelization plan only after the tiny oracle passes, at a pinned commit. Record how a production PyTorch stack composes EP, expert FSDP and the other mesh dimensions.
- Switch TransformersGoogle Research · support
Read Section 2 for simplified routing, the capacity factor and the load-balancing loss, and Section 5 for combining data, model and expert parallelism. Reproduce its capacity arithmetic for one batch.
Also in this section
- Ultra-Scale Playbook - Expert ParallelismHugging Face · primary
Read Expert Parallelism and its interaction with DP in the 5D summary. Derive tokens, bytes and expected imbalance for one top-k routing example; use the linked MoE introduction only if the architecture is unfamiliar.
- How to Scale Your Model - Expert Parallelism on GPUsGoogle DeepMind · support
Read the expert-parallelism part of Rooflines for LLM Scaling on GPUs and work its quiz before the answer. Use it for the all-to-all cost half of your MoE accounting.
- TorchFeather - Expert ParallelismTorchFeather · required
Watch the video segments from 16:49:58 (MoE) through 18:36:24 (expert parallelism), 19:01:56 (all-to-all dispatch and combine) and 19:27:38 (expert tensor parallelism), then trace
model/moe/anddistributed/expert_parallel.py. Build a tiny router-dispatch-expert-combine oracle first, then map each group, placement andall_to_all_singlecall to it. - Mixture of Experts ExplainedHugging Face · required
Study routing, capacity, token dropping, auxiliary loss and the expert-parallelism sections. Implement the small routing examples and verify conservation of token contributions through combine; group composition and FSDP interaction come from the papers and TorchTitan.
- GShard: Scaling Giant Models with Conditional Computation and Automatic ShardingLepikhin et al. (ICLR 2021) · support
Read the mixture-of-experts layer: top-2 gating, expert capacity, the auxiliary loss and random routing. Compare its capacity rule with Switch.
- ST-MoE: Designing Stable and Transferable Sparse Expert ModelsZoph et al. (2022) · support
Read the stability section that introduces the router z-loss and compare it with the auxiliary balancing loss.
- DeepSeek-V3 Technical Report - MoE SectionsDeepSeek-AI (2024) · support
Read the DeepSeekMoE architecture (shared and fine-grained experts, auxiliary-loss-free balancing, node-limited routing) and the all-to-all communication design. Its throughput figures are its own cluster's results.
- TensorTonic - Top-k MoE Router with Load StatisticsTensorTonic · support
Solve Top-k MoE Router with Load Statistics, including its lower-index tie rule, before building dispatch.
- Bumblebee - Router, Dispatcher and Expert PrimitivesBumblebee · depth
Only as a possible capstone target: read
primitive/modules/router.py,dispatcher.py,experts.pyandmoe.pyin a clean checkout. Its own todo lists no multi-GPU correctness test yet, so do not treat it as a reference implementation. - PyTorch Distributed - all-to-all collectivePyTorch · reference
Read
all_to_all_singleforinput_split_sizesandoutput_split_sizeson dim 0 and its uneven-split example. Use it for the dispatch and combine calls in the tiny oracle, and check zero splits yourself.