Unit 4 of 10 · about 4 hours · explain
Expert process groups, expert tensor parallelism and expert state ownership
Groups decide which ranks exchange tokens and which own each expert. Every later claim about sharding, placement or accounting rests on this mapping.
You'll be able to
- Explain expert-parallel groups, expert ownership and why EP composes with data parallelism.
- Distinguish expert parallelism (shard across experts) from expert tensor parallelism (shard within each expert).
- State which parameters live on which mesh for dense versus expert-sharded state.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Expert parallelism and its 5D interactionUltra-Scale Playbook - Expert Parallelism
Chapter 7, Expert Parallelism: independent experts on different workers without splitting matrix multiplies; Chapter 8, 5D Parallelism in a Nutshell: EP along experts composed with DP along batch, and the note that some implementations treat EP as DP with routing
- EP and expert tensor parallelism walkthroughTorchFeather - Expert Parallelism
16:49:58 (MoE) through 18:36:24 (expert parallelism), and 19:27:38 (expert tensor parallelism)
- EP, ETP and combined application codeTorchFeather - Expert Parallelism
ExpertParallel._partition_fn(shard on the expert dim),ExpertTensorParallel(two-dim sharding over the EP and ETP mesh),ReordererSequenceParallel(token split with rank offsets) andapply_moe_ep_tpbranch logic - Production mesh compositionTorchTitan - MoE Model and Parallelism
MeshAxisNameEP and EDP_SHARD entries,build_meshdense and sparse views, and the rule thatepdivides the sparse region withedp_shard = dp_shard * cp * tp / ep;config/validation.pyrequiresep >= tpandnum_experts % ep == 0Read after the tiny oracle passes; record the mapping, do not run the trainer.
Focus on
- EP shards the expert dimension: each rank owns whole experts. Non-MoE layers are unaffected, so EP alone leaves dense compute replicated; compose it with DP over the batch.
- Expert tensor parallelism additionally shards within each expert (
Shard(1)onw1andw3,Shard(2)onw2in TorchFeather). EP chooses the expert; ETP chooses the shard. - TorchTitan borrows dense ranks for the sparse region instead of multiplying the world size by EP. Dense state uses the DP mesh; expert weights shard on EP with FSDP over EDP_SHARD.
- Validation is mechanical: divides the sparse region, , and .
Common mistakes · 3
- EP borrows ranks, so the world-size product counts dense axes only. Multiplying by EP again double-counts ranks and invents groups that do not exist.
- ETP is not a bigger EP. EP without ETP keeps each owned expert whole; ETP splits every expert and needs its own mesh dimension and collectives.
- Expert weights and dense weights need different FSDP meshes. Wrapping a whole MoE layer in one FSDP unit mixes them and breaks the sparse sharding.
Try it yourself
Closed-book, before checking anything
dp_shard = 4 and tp = 2 plus ep = 4 over 12 experts: derive the sparse region (8 ranks), edp_shard = 2, the two EP groups, 3 experts per rank, and which mesh each of w1, the router gate and the attention weights lives on.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.World size 8,
dp_shard = 4,tp = 2,ep = 4. What isedp_shardand how many experts per rank with ?Answeredp_shard = 4 * 2 / 4 = 2; each EP rank owns experts.2.Why must EP be composed with DP instead of used alone?Answer
EP only affects MoE layers. Without DP over the batch, all ranks would redundantly compute every non-MoE block.
3.What breaks if with ?Answer
10 is not divisible by 4, so experts cannot split evenly; validation rejects it. Each rank must own the same count of whole experts.
4.Where do the router gate weights live relative to the experts?Answer
On the dense side: the gate sees every local token before dispatch, so it is not expert-sharded. Only the expert MLPs shard on EP.
You're done when
You can draw the dense and sparse meshes for the 8-rank example from memory, with every parameter family on its mesh and every rejected configuration named.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 9 more in the 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.
- 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. - 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.
Also in this section
- 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.
- 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. - 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.
- 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.