Phase 7 · Transformers/
Lesson 7.11advanced2 h

Mixture of Experts

Routing tokens to a few experts: huge capacity, small per-token compute

Most frontier models in 2026 — and open models such as Mixtral, DeepSeek-V3, Qwen3-MoE and Llama 4 — are mixtures of experts. MoE breaks the link between parameter count and per-token compute that scaling laws (7.9 Scaling laws and compute-optimal training) otherwise impose, which is why "parameters" stopped predicting cost in the model landscape (8.1 The LLM lifecycle and model landscape). Understanding routing, load balancing and the memory-versus-compute trade-off is necessary to read model cards, size deployments (7.10 Efficient inference: KV cache, GQA, FlashAttention, speculative decoding, quantization) and fine-tune these models (8.2 Fine-tuning and PEFT).

You'll be able to

  • Explain how an MoE layer replaces the FFN with routed experts and write the top-k gating equation
  • Explain the load-balancing auxiliary loss and capacity factors, and why routers collapse without them
  • Compute total vs active parameters for a real MoE and relate each to memory and latency
  • Describe expert parallelism and the trade-offs that make MoE attractive to frontier labs

Key ideas

  1. An MoE layer replaces the FFN with E expert FFNs and a router that sends each token to the top-k experts, decoupling capacity from per-token compute.
  2. Gating: g = softmax(W_r x); output = Σ over the chosen experts of renormalized gate × expert output. The gate values carry the gradient.
  3. Without balancing, routers collapse onto a few experts; the Switch auxiliary loss α·E·Σ fᵢPᵢ is minimized at uniform usage.
Show 4 more key ideas
  1. Capacity factors bound tokens per expert; overflow tokens skip the expert. DeepSeek-V3 balances with online bias adjustments instead of an auxiliary loss.
  2. Total parameters set memory (all experts must be loaded); active parameters set latency and FLOPs — Mixtral: ≈47B total, ≈13B active.
  3. Expert parallelism spreads experts across GPUs with all-to-all communication, the main training cost of MoE.
  4. MoE gives better loss per training FLOP but worse loss per parameter and is harder to fine-tune and serve on small hardware.

Suggested path through this lesson