GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
JMLR 2022

Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity

Google simplified mixture-of-experts to one expert per token, fixed its training instabilities, and trained a 1.6-trillion-parameter model. T5-Base-sized compute pretrained up to 7x faster.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2021
AUTHORS
Fedus, Zoph, Shazeer
FROM
Google
PUBLISHED
Jan 2021 · JMLR 2022
CITED BY
5,384Semantic Scholar · Nov 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 19% of this breakdown.

01

The paper in one minute

The 2017 mixture-of-experts layer sent each token to the top k experts, with k of at least two so the router got useful gradients. Switch Transformers asked whether one is enough. Routing each token to a single expert (the "switch") cuts the router's computation, halves the minimum batch each expert needs, and simplifies the communication of tokens between devices. Inside a Transformer, the Switch layer replaces the feed-forward block; attention stays dense.

One expert per token makes balance and capacity central. Every expert gets a fixed buffer of tokens per batch: (tokens ÷ experts) × a capacity factor. When more tokens choose an expert than it has room for, the extras skip the layer and pass through the residual connection unchanged. An auxiliary loss, α × N × Σ f_i × P_i, pushes the share of tokens each expert receives (f) and the router's average probability for it (P) toward an even split.

Sparse models were also unstable. The authors compute the router alone in float32 while the rest of the model stays in bfloat16, which stopped divergence at bfloat16 speed; scale the default weight initialization down by ten; and fine-tune with dropout of 0.4 inside experts and 0.1 elsewhere.

At the same compute per token as T5-Base, Switch models reached T5-Base quality up to 7 times faster, and gains held across 101 languages. A 1.6-trillion-parameter model trained without instability and reached a fixed perplexity 4 times faster than T5-XXL. Sparse models could also be distilled into small dense ones, keeping about 30% of their gain.

THE IDEA, VISUALLY
TOP-1 ROUTING WITH FIXED CAPACITY (SECTION 2.2) 12 tokens, 4 experts, capacity factor 1.0 = 3 slots each the cat sat on the mat and then it ran off fast router in float32: softmax(W_r x), take argmax expert 1 3 routed expert 2 4 routed expert 3 3 routed expert 4 2 routed expert 2 got 4 tokens for 3 slots: one skips the expert and continues through the residual capacity = tokens / experts x capacity factor balancing loss = 0.01 x N x sum(f_i x P_i) router in float32, rest of model in bfloat16 Each expert is a feed-forward block; attention stays dense. Parameters grow with experts, compute per token stays that of one feed-forward block. init scale 0.1, expert dropout 0.4 when fine-tuning TIME TO A QUALITY THRESHOLD (TABLE 1) hours, all at T5-Base compute per token except T5-Large T5-Base never reached T5-Large 131.1 MoE-Base, top-2, CF 1.0 80.1 Switch-Base, CF 1.0 62.8 THE LARGEST MODELS (TABLE 9) T5-XXL 11B params 6.3T FLOPs/seq Switch-XXL 395B, 64 experts 6.3T FLOPs/seq Switch-C 1.6T, 2,048 experts 890B FLOPs/seq Switch-C: 4x faster than T5-XXL to a fixed perplexity Switch-XXL: better after fine-tuning (SQuAD 89.6 vs 87.7) DISTILLING SPARSE INTO DENSE (TABLE 7) 1.1B teacher 37% of gain kept 3.8B teacher 30% of gain kept 14.7B teacher 28% of gain kept student: 223M-parameter T5-Base arXiv 2101.03961, Google, JMLR 2022
The Switch layer replaces a Transformer's feed-forward block with many experts and sends each token to exactly one. Each expert has a fixed number of slots set by the capacity factor; overflow tokens skip the layer through the residual connection. An auxiliary loss keeps the router spreading tokens evenly.
Research notes: the problem, approach and results
7x

faster pretraining than T5-Base at the same compute per token, with 128 experts (abstract, Section 3)

1.6T

parameters in Switch-C, 2,048 experts per layer, trained without observed instability (Table 9)

~30%

of a sparse teacher's quality gain kept when distilled into a 223M dense model at 95%+ compression (Table 7)

THE PROBLEM

Mixture-of-experts promised huge models at constant compute per token, but adoption was held back by complexity, the communication cost of sending each token to several experts, and training that diverged, especially in low-precision bfloat16.

THE IDEA

Route each token to a single expert (k = 1), which cuts router computation and communication and halves the per-expert batch needed. Give each expert a fixed capacity, add a simple load-balancing loss, compute the router in float32 inside an otherwise bfloat16 model, shrink weight initialization tenfold, and use heavier dropout inside experts when fine-tuning.

THE RESULT

At the same compute per token as T5-Base, Switch models reached T5-Base's quality up to 7x faster in pretraining; a 1.6-trillion-parameter Switch-C was 4x faster to a fixed perplexity than T5-XXL. Distilling sparse models into dense T5-Base kept about 30% of their quality gain at 95%+ compression.

02

Why it matters to an FDE

Most deployed mixture-of-experts models descend from choices this paper made, and its vocabulary shows up in serving configurations.

Capacity factor is a quality-versus-memory dial. A low capacity factor saves memory and communication but drops tokens when routing is uneven; a dropped token skips that layer's expert entirely. If an MoE model behaves oddly on unusual inputs, uneven routing with dropped tokens is one cause to check, and some serving stacks expose this setting.

Sparse models are memory-hungry. Switch-C has 1.6 trillion parameters, about 3.1 TB of weights in bfloat16, even though each token touches a small fraction. The same split between parameters stored and parameters used applies to every MoE model you deploy.

Distillation is the exit ramp. If a customer wants an MoE model's quality on modest hardware, the paper shows a dense student can keep a share of the sparse model's gain. Its numbers (about 30%) set an honest expectation: distillation recovers part of the gain, not all of it.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 290 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    Top-1 routing, capacity, the balancing loss, three stability fixes and two misreadings

    Free account
  2. 04How it works

    Router math, capacity and overflow, the auxiliary loss, precision, initialization, parallelism

    Premium
  3. 05The numbers that matter

    Switch versus MoE and T5, the stability ablations, large-model results and distillation

    Premium
  4. 06Try it yourself

    Count dropped tokens by capacity factor, evaluate the balancing loss, and audit the tables

    Premium
  5. 07Where it breaks

    Instability at the top, the fine-tuning anomaly, TPU-specific design, and slips

    Premium
  6. 08Using it on a deployment

    Setting capacity, watching dropped tokens, and when to distill a sparse model into a dense one

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →