Part IV: Parallel Deep Learning and Large Models
Chapter 17: Expert Parallelism and Sparse Distributed Models

Expert Parallelism and Sparse Distributed Models

Chapter 16 spent its energy fitting a dense model across devices: every parameter fired on every token, and the whole problem was carving that uniform computation into pieces small enough to hold. This chapter changes the model so that most of it stays asleep. A mixture-of-experts layer holds many expert sub-networks but routes each token to only a few of them, so the parameter count can grow into the trillions while the compute spent on any single token barely moves. That sparsity buys enormous capacity, and it buys a new distributed problem: the experts live on different machines, and every token must be shipped to the machine holding the expert it was routed to, computed there, and shipped back. This chapter is about that routing, the all-to-all that carries it, and the load-balancing, capacity, and stability machinery that keeps a sparse model trainable across a cluster.

Conceptual illustration for Chapter 17: Expert Parallelism and Sparse Distributed Models

"They built a hundred and twenty-seven of us and promised every token a fair shake. The gate has sent me nothing for three thousand steps. I have so much capacity, and no one to spend it on."

An Expert Nobody Routed To

Chapter Overview

This is the third chapter of Part IV, and it picks up exactly where the dense partitioning of Chapter 16 left off. There the model was dense and the engineering was about cutting a uniform computation across devices; here the model is sparse, and the engineering is about deciding, per token, which small piece of the model to run and then moving the token to wherever that piece lives. The binding constraint shifts again: not device memory and not gradient bandwidth, but the irregular, data-dependent communication of routing. The collective to watch is the all-to-all. Chapter 4 introduced it as the most general of the collectives, every rank sending a distinct message to every other rank, and here it becomes the beating heart of every MoE forward and backward pass.

Read in order, the nine sections take you from "a dense layer wastes capacity by running every parameter on every token" to "a cluster trains and serves a model whose parameter count dwarfs its per-token compute, with tokens routed across machines by a gate and carried there by an all-to-all that the load-balancing machinery keeps from collapsing." The argument is cumulative: sparsity creates the opportunity, routing realizes it, expert parallelism distributes it, the all-to-all pays for it, and load balancing and capacity control are what keep the bargain from falling apart at scale.

Prerequisites

This chapter builds directly on two earlier ones. From Chapter 16: Model, Pipeline, and Sharded Parallelism you carry the four parallelism axes and especially the idea of mapping each axis onto the interconnect tier its collectives demand, because expert parallelism is the fourth axis that the 3D and 4D strategies of that chapter reserved a slot for, and a real frontier MoE model composes expert parallelism with the tensor, pipeline, and sharded data parallelism you learned there. From Chapter 4: Communication Primitives for Distributed Training you carry the all-to-all collective above all, since the entire routing mechanism of an MoE layer is an all-to-all that scatters tokens to their assigned experts and a second all-to-all that gathers the results, and you cannot reason about MoE communication cost without first understanding what an all-to-all moves and how it scales. The chapter assumes comfortable Python and PyTorch, a working picture of a transformer block and where its feed-forward layer sits, and the basic distributed-training vocabulary of ranks, process groups, and collectives from Part I. No prior experience with sparse models or gating networks is required; Section 17.1 motivates the architecture from the dense baseline before any expert is introduced.

Learning Objectives

Chapter Roadmap

What's Next?

This chapter and the two before it assumed a cluster that stays the same size for the whole run: a fixed set of devices, each holding its assigned shard or expert, all present from the first step to the last. Real training at this scale does not get that luxury. Nodes fail, preemptible instances vanish with a moment's warning, and a job that holds thousands of accelerators for weeks will lose some of them. Chapter 18: Elastic and Fault-Tolerant Distributed Training takes up training that survives a changing cluster: checkpointing that lets a job resume without losing days of work, elastic schedulers that grow and shrink the worker set, and the recovery protocols that rebuild the parallelism layout you spent these three chapters constructing after a device drops out. Read it next, and watch the static device map of expert and sharded parallelism become something that has to heal itself while the loss keeps going down.

Bibliography & Further Reading

Foundations of Sparse Mixture-of-Experts

Shazeer, N., Mirhoseini, A., Maziarz, K., Davis, A., Le, Q., Hinton, G., Dean, J. "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer." arXiv:1701.06538, 2017. arxiv.org/abs/1701.06538

The paper that introduced the sparsely-gated MoE layer, top-$k$ routing, and the load-balancing loss, the architectural foundation for Sections 17.2 and 17.3.

📄 Paper

Clark, A., de las Casas, D., Guy, A., Mensch, A., Paganini, M., Hoffmann, J., et al. "Unified Scaling Laws for Routed Language Models." arXiv:2202.01169, 2022. arxiv.org/abs/2202.01169

The study that derives scaling laws for routed (MoE) models and quantifies how parameter count and per-token compute decouple, the analytical backbone of Section 17.1.

📄 Paper

Routing, Load Balancing, and Stability

Fedus, W., Zoph, B., Shazeer, N. "Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity." arXiv:2101.03961, 2021. arxiv.org/abs/2101.03961

The work that simplified routing to top-1, introduced the capacity factor and token dropping, and stabilized large MoE training, the direct basis for Sections 17.3 and 17.7.

📄 Paper

Zhou, Y., Lei, T., Liu, H., Du, N., Huang, Y., Zhao, V., Dai, A., Chen, Z., Le, Q., Laudon, J. "Mixture-of-Experts with Expert Choice Routing." arXiv:2202.09368, 2022. arxiv.org/abs/2202.09368

The paper that inverts the routing direction so experts choose tokens, giving perfect load balance by construction, the expert-choice alternative compared in Sections 17.3 and 17.6.

📄 Paper

Distributed MoE Systems

Lepikhin, D., Lee, H., Xu, Y., Chen, D., Firat, O., Huang, Y., Krikun, M., Shazeer, N., Chen, Z. "GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding." arXiv:2006.16668, 2020. arxiv.org/abs/2006.16668

The system that scaled MoE to 600 billion parameters with automatic sharding and the all-to-all dispatch-and-combine pattern, the basis for the expert parallelism of Sections 17.4 and 17.5.

📄 Paper

Rajbhandari, S., Li, C., Yao, Z., Zhang, M., Aminabadi, R. Y., Awan, A. A., Rasley, J., He, Y. "DeepSpeed-MoE: Advancing Mixture-of-Experts Inference and Training to Power Next-Generation AI Scale." arXiv:2201.05596, 2022. arxiv.org/abs/2201.05596

The framework that pairs expert parallelism with optimized MoE inference and distillation, a primary reference for the distributed training and serving of Sections 17.4 and 17.8.

📄 Paper

Hwang, C., Cui, W., Xiong, Y., Yang, Z., Liu, Z., Hu, H., et al. "Tutel: Adaptive Mixture-of-Experts at Scale." arXiv:2206.03382, 2022. arxiv.org/abs/2206.03382

The system that makes the all-to-all and expert placement adaptive at runtime to handle dynamic load, deepening the communication discussion of Section 17.5.

📄 Paper

DeepSeek-AI. "DeepEP: An Efficient Expert-Parallel Communication Library." GitHub, 2025. github.com/deepseek-ai/DeepEP

An open communication library specialized for the dispatch-and-combine all-to-all of expert parallelism, a current production reference for the routing kernels of Section 17.5.

🛠️ Tool

Open Frontier MoE Models

Jiang, A. Q., Sablayrolles, A., Roux, A., Mensch, A., Savary, B., Bamford, C., et al. "Mixtral of Experts." arXiv:2401.04088, 2024. arxiv.org/abs/2401.04088

The open-weight sparse MoE language model with eight experts and top-2 routing, a concrete reference architecture for the layer, routing, and serving of Sections 17.2 and 17.8.

📄 Paper

DeepSeek-AI. "DeepSeek-V3 Technical Report." arXiv:2412.19437, 2024. arxiv.org/abs/2412.19437

The report behind a frontier fine-grained MoE model with shared experts and auxiliary-loss-free load balancing, the current state of the art for Sections 17.6 and 17.9.

📄 Paper