Sixth ML & AI post, and the first Deep Dive in this section — the same split the GPU side of this blog has used since its first few posts. The five Foundations posts so far (Transformer, tokenization, ViT, CLIP, RoPE) all described one dense feed-forward network every token passes through, unmodified, every layer. Mixture of Experts (MoE) changes exactly that piece, and the idea behind it is almost embarrassingly direct once you see it.

The piece being replaced

The Transformer post described each layer's feed-forward block as two linear layers around a ReLU, expanding to d_ff and back down to d_model. Every token that passes through that block uses the exact same weights — a 100-token prompt and a 100,000-token prompt both pay for that same FFN, once per token, every layer. If you want the model to know more, the usual lever is to make that FFN bigger — but that also makes it slower for every token, whether or not that particular token needed the extra capacity.

The idea: many small FFNs, and a router that picks a few

MoE replaces the single FFN with N separate FFNs — called experts — plus a small router network. For each token, the router scores all N experts and selects the top k (commonly k=1 or k=2), and the token is only processed by those k experts; their outputs are combined, weighted by the router's own scores. Every other expert does nothing for that token.

Diagram contrasting a dense feed-forward layer, where every token passes through the same single FFN, against a Mixture of Experts layer, where a router sends each token to only 2 of 6 available expert FFNs, leaving the rest unused for that token

This is the entire idea. What makes it worth a whole post is what it buys: total parameters (the combined size of all N experts) and active parameters per token (the size of just the k experts a given token actually uses) become two different numbers, for the first time. In a dense model those are the same number — making the model bigger always makes every forward pass slower. In an MoE model, you can grow N (and therefore total capacity) while k and the compute per token stay fixed.

Where this started

The idea is older than the current wave of LLMs: Shazeer et al. (2017) introduced the sparsely-gated MoE layer — a noisy top-k router inserted between stacked LSTM layers — and reported greater than 1000x improvements in model capacity with only minor losses in computational efficiency, scaling an MoE layer up to 137 billion parameters for language modeling and machine translation. The architecture target changed (LSTMs then, Transformer FFN blocks now), but the routing idea carried over directly.

The problem sparsity creates: load imbalance

A naively trained router has a failure mode: whichever experts happen to get slightly more traffic early in training receive more gradient updates, get better at their job, and so the router sends them even more traffic next time — a rich-get-richer dynamic that collapses routing onto a handful of experts while the rest sit mostly idle, wasting the parameters you added them for in the first place.

Switch Transformer (Fedus et al., 2021) is the paper that made MoE practical at real scale, and most of its contribution is fixes for exactly this problem:

  • Switch routing: simplify to k=1 — route each token to a single expert, not several — which the paper shows preserves model quality while cutting router computation and communication cost.
  • An auxiliary load-balancing loss, added to the main training loss: loss = α · N · Σᵢ fᵢ · Pᵢ, where fᵢ is the fraction of tokens in a batch actually routed to expert i and Pᵢ is the router's own average probability mass on expert i. Minimizing this term pushes both fᵢ and Pᵢ toward 1/N for every expert — i.e. toward even routing — with α (0.01 in the paper) controlling how strongly this competes against the main task loss.
  • Expert capacity: each expert is only allowed to process (tokens per batch / N) × capacity factor tokens in a given batch. Tokens beyond that cap aren't computed at all — they skip the expert entirely and pass straight through via the residual connection. With a reasonable load-balancing loss in place, the paper reports under 1% of tokens get dropped this way.

With these fixes, Switch Transformer scaled to 1.6 trillion parameters (Switch-C) and reported up to a 7x pretraining speedup over a quality-matched dense T5-Base model, and 4x over T5-XXL, at equal compute budgets.

Where production models landed

Two recent, well-documented models show how this plays out in practice:

  • Mixtral 8x7B (Mistral AI): 8 experts per layer, top-2 routing — 46.7B total parameters, but only 12.9B active per token. Mistral reported it matching or beating Llama 2 70B on most benchmarks, despite activating roughly a fifth as many parameters per token.
  • DeepSeek-V3: a far more fine-grained setup — 256 experts per layer, 8 active per token — 671B total parameters, 37B active per token (about 5.5% activated). It also drops Switch Transformer's auxiliary loss entirely in favor of an auxiliary-loss-free scheme: each expert gets a learned bias term added to its router score, nudged up when that expert is under-used and down when it's over-used, balancing load through a direct feedback signal instead of a loss term that competes with the main training objective.

What this costs elsewhere

None of this is free — it just moves the cost somewhere else. A 671B-parameter model has to be stored somewhere even if only 37B parameters worth of compute happens per token, so MoE models still need the aggregate memory of a genuinely huge dense model spread across many GPUs. And because different tokens in the same batch route to different experts possibly living on different devices, serving an MoE model efficiently requires shuffling token activations between GPUs mid-layer (an all-to-all communication step) — a genuinely different bottleneck than anything the GPU section of this blog has covered so far, where every post so far has assumed a dense, uniform-shaped computation. That's a problem for a future post, not this one.


References

Routing diagram above is original artwork made for this post.