Unit 5 of 10 · about 4 hours · derive, implement

Capacity factor and dropless, dropped and padded routing

Static shapes force a fixed per-expert buffer before routing is known. The capacity factor sets that buffer, and the overflow policy decides whether extra tokens skip compute, waste it or stall.

You'll be able to

  • Derive per-expert capacity from tokens, experts and the capacity factor for one batch.
  • Contrast dropless, dropped and padded routing and state what happens to overflow tokens.
  • Compare the Switch capacity rule with the GShard group capacity rule.

Covers

Capacity factor and per-expert token capacityDropless, dropped and padded routing semantics
1

Read

In this order, only the parts listed

0 of 4 done

  1. Expert capacity and its costsSwitch Transformers

    Section 2.2 with Equation 3 and Figure 3: capacity as tokens per batch over experts times the capacity factor, overflow handling, and the finding that Switch performs best at capacity factors 1.0 to 1.25

  2. Capacity, dropping and communicationMixture of Experts Explained

    Switch Transformers capacity equation, the Capacity Factor and communication costs subsection, and the GShard expert-capacity paragraph with overflow via residual connections

  3. Group capacity and overflow policyGShard: Scaling Giant Models with Conditional Computation and Automatic Sharding

    Section 2.2 and Algorithm 1 (arXiv:2006.16668v1): per-group fractional capacity, overflow tokens passed on via residual connections, and random second-expert routing

  4. Capacity factor trade-offsST-MoE: Designing Stable and Transferable Sparse Expert Models

    Table 1 capacity factor definition and Section 5.2 (arXiv:2202.08906v2): raising train and eval capacity improves quality but linearly raises einsum, memory, all-to-all and allreduce costs

2

Focus on

  • Switch capacity is , with the capacity factor and the expert count. For top- routing the numerator counts assignments (), not tokens.
  • Dropped tokens skip expert compute and flow through the residual; padded slots consume expert FLOPs on zeros. Dropless with imbalance still pays padding or irregular shapes.
  • GShard splits the batch into groups with fractional capacity per group; Switch sets one buffer per expert for the whole batch. Both enforce the same idea: at most times the even share fits.
  • Switch keeps quality at to ; larger buys less dropping at linearly higher communication and activation cost.
Common mistakes · 3
  • Forgetting the multiplier: with top- routing each token occupies slots, so capacity from tokens alone under-provisions by a factor of .
  • Treating dropped tokens as lost. They skip the expert but keep their residual stream and reach the next layer; the damage is missing expert compute, not a missing position.
  • Reading GShard and Switch capacities as one rule. GShard rations per group with random second-expert admission; Switch rations per expert over the batch. Compare them, do not merge them.
3

Try it yourself

Closed-book, before checking anything

Closed-book, compute Switch capacity for 16 tokens and 4 experts at (4 slots) and (5 slots). Route 8 tokens to one expert under each and state dropped counts (4 and 3), then state the padded-row cost if dropping is forbidden.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.32 tokens, 8 experts, , top-1 routing. What is the capacity?Answer

    slots per expert.

  2. 2.Same batch with top-2 routing and . What buffer holds the even share?Answer

    slots, because 64 assignments spread over 8 experts.

  3. 3.An expert receives 9 tokens at capacity 5 under dropping. What happens to the 4 extras?Answer

    They skip expert compute and pass through the residual connection to the next layer.

  4. 4.Why can raising the capacity factor hurt step time even as drops fall?Answer

    Every extra slot adds activation memory and all-to-all payload whether or not a real token fills it. Communication and einsum costs grow linearly with the factor.

You're done when

You reproduce the 16-token capacity arithmetic from memory and predict drops and padding for a skewed assignment without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 8 more in the section
  • 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.

  • 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/ and distributed/expert_parallel.py. Build a tiny router-dispatch-expert-combine oracle first, then map each group, placement and all_to_all_single call to it.

  • 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.py and moe.py in a clean checkout. Its own todo lists no multi-GPU correctness test yet, so do not treat it as a reference implementation.

  • 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.

  • PyTorch Distributed - all-to-all collectivePyTorch · reference

    Read all_to_all_single for input_split_sizes and output_split_sizes on dim 0 and its uneven-split example. Use it for the dispatch and combine calls in the tiny oracle, and check zero splits yourself.