Mixture of Experts at Scale

Mixture of Experts (MoE) is a conditional computation architecture in which a learned routing function dynamically activates only a sparse subset of specialized sub-networks ("experts") per input token, enabling model capacity to scale independently of per-token FLOPs. It matters in modern AI because it breaks the classical compute-capacity coupling in dense transformers, allowing trillion-parameter models to be trained and served at the inference cost of models an order of magnitude smaller. The counterintuitive fact: despite routing being a discrete, non-differentiable operation, MoE models trained with soft auxiliary losses routinely outperform dense models at matched compute budgets, and the experts spontaneously specialize without explicit supervision.

The core insight

The fundamental insight of MoE is that not every parameter needs to participate in every forward pass — a router can learn to ask "which expert knows about this token?" and route accordingly, so the model pays only the FLOPs of the activated experts rather than the full parameter count. This decouples two quantities that are fused in dense models: total parameters (which determines representational capacity and memorization) and active parameters per token (which determines inference cost and training throughput). The "aha moment" is realizing that language, vision, and multimodal data are highly heterogeneous — different tokens genuinely require different computations — and MoE is the architecture that makes this statistical heterogeneity structurally explicit. Scaling laws therefore change: an MoE model at fixed FLOPs can see far more data with far more capacity, shifting the Pareto frontier of the loss-vs-compute tradeoff.

How It Works

Routing and Gating

In a standard Sparse MoE layer with EE experts {f1,…,fE}\{f_1, \ldots, f_E\}, each expert is a feed-forward network (FFN). For input token representation x∈Rd\mathbf{x} \in \mathbb{R}^d, the router computes a logit vector:

1
h(x)=Wrx+ϵ,ϵ∼N(0,σ2I)\quad \mathbf{h}(\mathbf{x}) = \mathbf{W}_r \mathbf{x} + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \sigma^2 I)

Explanation: The router projects the token embedding through a learned weight matrix Wr∈RE×d\mathbf{W}_r \in \mathbb{R}^{E \times d}, with optional Gaussian noise ϵ\epsilon (used in Noisy Top-kk Gating to encourage exploration during training). The Top-kk gate selects the kk experts with the highest logits and computes a sparse softmax over them:

2
G(x)=Softmax⁡ ⁣(TopK⁡ ⁣(h(x), k))\quad G(\mathbf{x}) = \operatorname{Softmax}\!\left(\operatorname{TopK}\!\left(\mathbf{h}(\mathbf{x}),\, k\right)\right)

Explanation: Only the kk largest entries of h(x)\mathbf{h}(\mathbf{x}) survive the TopK operation (the rest are set to −∞-\infty before softmax), so the resulting gate vector G(x)∈REG(\mathbf{x}) \in \mathbb{R}^E has exactly kk nonzero entries that sum to one. The layer output is the gated sum of selected expert outputs:

3
MoE(x)=∑i=1EGi(x) fi(x)\quad \text{MoE}(\mathbf{x}) = \sum_{i=1}^{E} G_i(\mathbf{x})\, f_i(\mathbf{x})

Explanation: Because Gi(x)=0G_i(\mathbf{x}) = 0 for all non-selected experts, only kk experts are actually evaluated — this is the source of the computational savings.

Load Balancing

Let B\mathcal{B} be a batch of TT tokens. The auxiliary load-balancing loss (Fedus et al., 2022) penalizes deviations from uniform expert utilization:

4
Laux=α⋅E∑i=1Efi⋅Pi,fi=1T∑t=1T1[token t routed to expert i],Pi=1T∑t=1TGi(xt)\quad \mathcal{L}_{\text{aux}} = \alpha \cdot E \sum_{i=1}^{E} f_i \cdot P_i, \quad f_i = \frac{1}{T}\sum_{t=1}^{T}\mathbf{1}[\text{token } t \text{ routed to expert } i], \quad P_i = \frac{1}{T}\sum_{t=1}^{T} G_i(\mathbf{x}_t)

Explanation: fif_i is the fraction of tokens dispatched to expert ii (non-differentiable), PiP_i is the mean routing probability for expert ii (differentiable), their dot product forms a differentiable proxy for load imbalance, and α\alpha is a hyperparameter (typically 10−210^{-2}) controlling the strength of the regularization.

Expert Capacity and Token Dropping

Each expert is assigned a capacity C=⌊(T/E)⋅κ⌋C = \lfloor (T / E) \cdot \kappa \rfloor where κ≥1\kappa \geq 1 is the capacity factor. Tokens routed to an expert beyond its buffer are dropped:

5
Ltotal=LCE(θmodel)+Laux(θr)+β Lz(θr),Lz=1T∑t=1T(log⁡∑i=1Eehi(xt))2\quad \mathcal{L}_{\text{total}} = \mathcal{L}_{\text{CE}}(\theta_{\text{model}}) + \mathcal{L}_{\text{aux}}(\theta_r) + \beta\, \mathcal{L}_{z}(\theta_r), \quad \mathcal{L}_z = \frac{1}{T}\sum_{t=1}^{T}\left(\log \sum_{i=1}^{E} e^{h_i(\mathbf{x}_t)}\right)^2

Explanation: The router-z loss Lz\mathcal{L}_z (introduced in ST-MoE, Zoph et al. 2022) penalizes large router logit magnitudes, preventing the router from becoming overconfident and collapsing to routing all tokens to a single expert, with β\beta a small coefficient (typically 10−310^{-3}).

researcher · Geoffrey Hinton | b. 1947 | Foundational neural network research enabling deep MoE

Hinton's work on backpropagation, distributed representations, and the Boltzmann machine established the theoretical substrate on which modern deep expert networks are built. While not an MoE author directly, his 1991 collaboration with Jacobs and Jordan on "Adaptive Mixtures of Local Experts" — the direct intellectual ancestor of modern MoE — came from his group at the University of Toronto. Hinton received the 2018 Turing Award alongside LeCun and Bengio, and famously left Google in 2023 to speak freely about AI risk.

researcher · Noam Shazeer | b. 1978 | Sparse Mixture of Experts for deep learning at scale

Shazeer, while at Google Brain, co-authored the landmark 2017 paper "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer" (with Azalia Mirhoseini, Krzysztof Maziarz, Andy Davis, Quoc Le, Geoffrey Hinton, and Jeff Dean), which demonstrated for the first time that sparse MoE could be applied to LSTM language models at the billion-parameter scale while maintaining training stability. His key contributions were Noisy Top-k Gating and the capacity-buffer mechanism that prevented expert overflow. Shazeer later co-founded Character.AI and is widely credited with writing some of the most impactful (and deliberately obfuscated) code in Google's production infrastructure.

Figure
Sparse MoE Layer — Token Routing and Expert Dispatch
Sparse MoE Layer: Top-2 Routing (E=4 Experts) Token x₁ Token x₂ Token x₃ Token x₄ Router W_r · x Top-k(·) Expert 1 (FFN) Expert 2 (FFN) Expert 3 (FFN) Expert 4 (idle) G₁=0.6 G₂=0.4 G₃=0.7 Σ Gᵢfᵢ(x) Weighted Sum out Active expert Idle expert (token dropped) Router dispatch (gated)
Figure
MoE Scaling: Capacity vs. FLOPs Pareto Frontier
MoE vs Dense: Loss–Compute Pareto Frontier Training FLOPs (log scale) Val Loss Dense MoE ΔLoss Same loss, ~4–8× fewer FLOPs 10²² 10²³ 10²⁴ 10²⁵

Intuition

The Mental Model

Imagine a hospital with many specialists — a cardiologist, a neurologist, an orthopedist, and so on. When you arrive, a triage nurse (the router) reads your chart and sends you to the two most relevant specialists; the others don't see you at all and continue their other work. The hospital's total expertise is enormous, but your visit only consumes the time of two doctors. A generalist hospital of the same size would employ only generalists: cheaper per doctor, but none as deep. MoE makes your neural network a hospital of specialists: the router is triage, each FFN layer is a specialist clinic, and the gate weights are how much you weight each specialist's opinion before you leave. The subtlety is that nobody told the specialists what to specialize in — they learned it, the same way doctors self-select into specialties based on what they found interesting and were good at during training. The hard engineering problem is ensuring the hospital doesn't just send everyone to the same two most-popular doctors, overwhelming them while the others sit idle — that's the load-balancing problem.

Historical Development

Origins · 1 minhow this was discovered
History
1991
Jacobs, Jordan, Nowlan & Hinton publish "Adaptive Mixtures of Local Experts" (Neural Computation), introducing the original MoE framework with a soft gating network trained jointly with experts via EM — the direct intellectual ancestor of all modern MoE.
1994
Jordan & Jacobs extend to Hierarchical MoE (HME), establishing the tree-structured routing that prefigures modern hierarchical expert designs, and providing the EM convergence analysis.
2014
Eigen, Ranzato & Sutskever apply MoE to deep networks with ReLU gating, demonstrating that modern deep experts can outperform single networks — but without sparse routing, the compute advantage was absent.
2017
Shazeer et al. (Google Brain) publish "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer," introducing Noisy Top-k Gating and demonstrating 1000× capacity increase in LSTM LMs at matched FLOPs on one billion tokens — the paper that relaunched modern MoE research.
2021
Lepikhin et al. publish GShard, training a 600B-parameter MoE Transformer for multilingual MT across 2048 TPUs with Top-2 routing and capacity factors, establishing the distributed systems infrastructure for MoE at scale.
2021
Fedus, Zoph & Shazeer publish Switch Transformer (JMLR 2022), showing Top-1 routing is sufficient, achieving 7× training speedup over T5-XXL with simpler load balancing, and scaling to 1.6T parameters.
2022
Zoph et al. publish ST-MoE, introducing the router-z loss and dropout-based regularization, systematically studying training instabilities and establishing best practices for MoE fine-tuning.
2022–2023
Evidence accumulates (from GLaM, Mixtral, and internal reports) that sparse MoE models match or exceed dense model quality at 2–4× the parameter count but with inference FLOPs equivalent to models 4–8× smaller.
2024
Mixtral 8×22B (Mistral AI) and DeepSeek-MoE demonstrate that open MoE models with fine-grained expert decomposition and shared-expert isolation can match GPT-4-class quality at significantly reduced inference cost, democratizing MoE research.

Why It Matters

Real-World Impact
GLaM (Google, 2021)A 1.2T-parameter MoE language model with 64 experts per layer and Top-2 routing; at inference it activates 97B parameters per token, achieving GPT-3 quality with 1/3 the energy cost and 1/2 the FLOPs per training token — the first large-scale empirical proof that MoE outperforms dense at matched compute.
Switch Transformer (Google, 2022)1.6T parameters with Top-1 routing and capacity factor 1.25; achieved 4–7× pre-training speedup over T5 at equivalent computational budget, demonstrating that simplicity (k=1) outperforms k=2 in many regimes — counterintuitively, less routing complexity improved stability.
Mixtral 8×7B (Mistral AI, 2024)Open-weight MoE with 8 experts per FFN layer, Top-2 routing, 46.7B total parameters, 12.9B active per token; outperforms LLaMA 2 70B on most benchmarks while using ~6× fewer active parameters at inference — made large MoE models accessible to academic researchers.
GPT-4 (OpenAI, 2023)While not officially confirmed, widespread credible reporting describes GPT-4 as an MoE architecture with ~8 experts and ~220B active parameters per forward pass out of a much larger total; this would explain its quality-to-inference-cost ratio and the reported training configuration involving H100 clusters.
DeepSeek-MoE (2024)Introduces fine-grained expert segmentation (splitting FFN intermediate dimension into many small experts) and shared experts (always-active experts capturing common knowledge), achieving better expert specialization than coarse-grained designs and establishing new SOTA on MoE efficiency.
Google's Pathways / GeminiThe Gemini family of models uses MoE components in its training pipeline, and the Pathways infrastructure was explicitly designed to support dynamic routing across heterogeneous accelerator pods — MoE is a core architectural motivation for Pathways' disaggregated compute model.
WideNet and Vision MoEApplications of MoE to vision transformers (ViT-MoE) demonstrate that the concept generalizes beyond language, with expert specialization observed across semantic categories — different experts activate for different visual concepts — validating the universality of conditional computation.

Prerequisites

What This Leads To

See Also

Transformer Architecture · Conditional Computation · Expert Parallelism and All-to-All Communication · Scaling Laws for Neural Language Models · Knowledge Distillation

Before this