Paper 52~11 min readJMLR 2022worked math + runnable code
Paper Breakdown

Switch Transformer,
explained.

Mixture-of-experts promised something almost too good — a model with vastly more parameters that costs no more to run per token, because only a slice of it fires each time. But it was fiddly and unstable, and few could scale it. The Switch Transformer made it work by doing less: send each token to just one expert. That single simplification, plus two careful tricks to keep it balanced, carried the design to a trillion parameters. Here's the routing, and the math that keeps it honest.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

The MoE promise

A mixture of experts replaces a transformer's single feed-forward layer with many parallel ones — the experts — and a small router that decides which expert each token should use. The payoff is sparse activation: the model can carry an enormous number of parameters, but each token only touches a few of them, so the compute per token barely rises. Capacity grows without the usual proportional cost in FLOPs.

The catch, before this paper, was that MoE was hard to train. Routing to two or more experts per token added complexity and communication overhead, gradients were noisy, and — worst of all — routers collapsed, funneling most tokens to a handful of favored experts while the rest sat idle. Switch Transformer's contribution was to make MoE simple and stable enough to scale reliably, and its central move was counterintuitive: route less, not more.

The one-sentence version

Give each token exactly one expert, add a loss that keeps experts evenly used and a capacity limit that keeps them balanced — and mixture-of-experts finally scales.

02

Top-1 routing

Earlier MoE work insisted you needed at least two experts per token — the belief was that routing needed a comparison to produce useful gradients. Switch Transformer challenged that and used top-1 routing: the router scores the experts for a token, and the token goes to the single highest-scoring one. Nothing else.

The simplification pays off three ways. Routing computation halves or better. The all-to-all communication that shuffles tokens to their experts across devices shrinks. And the implementation gets dramatically cleaner — one expert per token means fixed, predictable tensor shapes. The router still produces a probability for the chosen expert, which is used to weight the expert's output so gradients flow back to the router. Less machinery, same learning signal.

03

The balancing loss

Left to itself, a router develops favorites — a rich-get-richer loop where a few experts get most tokens, train faster, and get chosen even more, while the rest waste their parameters. Switch counters this with a load-balancing auxiliary loss, added to the training objective, that is minimized only when tokens spread evenly across experts. With N experts, fi the fraction of tokens routed to expert i, and Pi the router's mean probability for expert i:

Laux = N · Σi fi · Pi     minimum = 1 at perfect balance  ·  grows toward N as load skews

The product fi·Pi couples how many tokens an expert actually gets to how confident the router is about it, and the sum is smallest when both are spread uniformly (each 1/N), giving N·N·(1/N)² = 1. Pile everything onto one expert and it climbs toward N. Because it is differentiable through Pi, minimizing it during training actively pushes the router toward even utilization. The runnable version below computes it for balanced and skewed loads.

04

Capacity and dropping

The balancing loss is a soft nudge; hardware needs a hard guarantee. On real accelerators every expert must be given a fixed-size buffer, so Switch sets an expert capacity — the maximum tokens one expert will process in a batch — as tokens-per-expert times a tunable capacity factor:

capacity = ⌈ (tokens / experts) · capacity_factor ⌉

If routing still sends an expert more tokens than its capacity, the overflow tokens are dropped — they skip the expert entirely and pass through unchanged via the residual connection. A capacity factor above 1 adds slack to reduce dropping, at the cost of wasted compute on padding; below 1 saves compute but drops more. It is the explicit lever that trades a little accuracy for guaranteed, hardware-friendly balance.

One token's journey through a Switch layer
RouterScore all experts; pick the single highest (top-1).
Capacity checkIf the chosen expert is full, drop the token (residual passes it through).
ExpertOtherwise the one expert transforms it, scaled by the router's probability.
Aux lossThe load-balancing loss nudges future routing toward even use.
RUN IT YOURSELF

Route, balance, and drop

The three mechanisms that make Switch work, in a handful of functions. Top-1 routing sends a token to the argmax expert; the load-balancing loss reads 1.0 at perfect balance and climbs when the load skews (2.8 here for all-to-one across four experts); expert capacity scales with the capacity factor; and tokens beyond capacity are dropped — all eight going to one expert with capacity four means four are dropped. Change the routing or the capacity factor and watch the loss and the drops respond.

CPython · WebAssembly
05

Scaling to a trillion

With routing simplified and stabilized, the numbers got large. The Switch Transformer scaled to 1.6 trillion parameters — a headline figure at the time — while keeping the compute per token comparable to a far smaller dense model, because only one expert fires per token. That is the whole point of sparsity made concrete: parameters and FLOPs, usually chained together, come apart.

DimensionSwitch behavior
ParametersGrow with the number of experts — into the trillions.
Compute per tokenRoughly constant — one expert runs, whatever the expert count.
Sample efficiencyReached a target quality up to ~7× faster than a dense model at equal compute, in the paper's results.
Memory / commsThe real cost — experts must live in memory and tokens shuffle between devices.

The trade is honest: you pay in memory and cross-device communication for parameters you activate only sparsely. But for large-scale training, spending memory to buy quality-per-FLOP was exactly the right exchange — and it reframed how people thought about scaling.

06

Why it mattered

Switch Transformer took mixture-of-experts from a finicky research idea to a scalable, practical technique, and the modern MoE models that followed — from open trillion-scale releases to the sparse layers rumored inside frontier systems — inherit its recipe: simple top-1-ish routing, an auxiliary balancing loss, and capacity limits. Its specific choices are refined in newer work, but the skeleton is the same.

Its lasting idea is the decoupling itself. For years, "bigger model" meant "more compute," full stop. Sparse expert routing broke that identity, letting parameter count and per-token compute scale on separate dials. That is why mixture-of-experts is now a central tool for building very large models economically — and Switch Transformer is the paper that made the tool dependable.

Worth knowing

The capacity factor is a live production knob: raise it and fewer tokens are dropped (better quality, more wasted compute on padding); lower it and you save compute at some accuracy cost. Balancing that trade is part of tuning any MoE deployment.

Frequently asked

Quick answers

What's the core idea?

Replace the feed-forward layer with many experts and route each token to just one (top-1), so parameters scale huge while compute per token stays roughly constant.

Why the load-balancing loss?

Routers collapse onto a few experts otherwise. The auxiliary loss N·Σ fᵢ·Pᵢ is minimized at even usage, nudging the router to spread tokens across all experts.

What is expert capacity?

A fixed per-expert token budget = ⌈(tokens/experts)·capacity_factor⌉. Tokens beyond it are dropped and skip the layer via the residual — keeping computation hardware-friendly.

How big did it get?

Up to 1.6 trillion parameters, at compute per token comparable to a much smaller dense model, since only one expert activates per token.

Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity · Fedus, Zoph, Shazeer · JMLR 2022 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns