Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity
TL;DR. Switch Transformers replace some dense FFN layers with many expert FFNs and send each token to just one of them. Each expert gets a fixed buffer of slots. Tokens that overflow are dropped and pass through the residual. A small auxiliary loss keeps the load even. This simple recipe trains a 1.6T-parameter model and gives up to a 7× pretraining speedup over T5 at the same FLOPs per token.
Why it matters now. Most open frontier LLMs are now mixture-of-experts (see DeepSeek-V3). If you fine-tune one as an embedding model, reranker or search agent, you inherit its router, its load-balancing loss and its capacity limits. The Switch paper is the cleanest place to learn the three knobs every later MoE paper changes: how many experts per token (top-k), how much buffer (capacity factor), and how load is balanced.
Key idea
Section titled “Key idea”A router with weights scores token against experts and takes a softmax:
Switch keeps only the top expert, , and outputs . Multiplying by is what gives the router a gradient.
Experts run as fixed-size batched matmuls, so each needs a static buffer (Eq. 3):
To keep the load balanced, the paper adds (Eq. 4):
Here is the fraction of tokens sent to expert and is the mean router probability for expert over the batch. The loss is smallest under uniform routing, where it equals . The paper uses .
Key results
Section titled “Key results”- Speed at equal FLOPs (§2.5, Table 1). With 128 experts on every other FFN layer, Switch-Base at capacity factor 1.0 reaches negative log perplexity −1.50 in 62.8 h. MoE-Base (top-2) takes 80.1 h and T5-Large takes 131.1 h. Switch is better than top-2 at small capacity factors.
- Step speedup (§3). A 64-expert Switch-Base matches T5-Base’s step-450k quality at step 60k, a 7.5× speedup. It is also 2.5× faster than T5-Large, which uses 3.5× more FLOPs per token.
- Precision (Table 2). Full bfloat16 diverged (−3.780). Selective precision matched float32 quality (−1.716 versus −1.718) at bfloat16 speed (1390 versus 1160 examples per second).
- Trillion scale (§5). Switch-C (1.6T) is 4× faster than T5-XXL to the same perplexity. Switch-XXL beats T5-XXL by 0.061 negative log perplexity at 250k steps.
- Downstream and distillation (§4–5). All 101 mC4 languages improve over mT5, and 91% get 4× or larger speedups. Distilling into a dense model keeps about 30% of the gain at 95%+ compression.
Limitations & open questions
Section titled “Limitations & open questions”- Instability at the largest dense-like scale. Switch-XXL was unstable while Switch-C was not. The tricks above do not fully explain this.
- Parameters versus FLOPs downstream. On SQuAD, Switch-C scores 87.7 against 89.6 for Switch-XXL, which has fewer parameters but about 10× more FLOPs per token. Pretraining perplexity gains do not transfer one-to-one.
- Dropped tokens depend on batch composition, so a token’s output can change with what else is in the batch. This is awkward for deterministic serving.
- Balance loss tension. A large α can hurt quality and a small one can let load collapse. Aux-loss-free balancing targets exactly this.
Connections
Section titled “Connections”- Builds on: the dense Transformer FFN block. Uses: knowledge distillation for compression.
- Next in this group: Mixtral (top-2 in every layer), DeepSeekMoE (fine-grained and shared experts), aux-loss-free balancing.
- In production: DeepSeek-V3. Compare with how scaling laws treat parameter count when parameters are not all active.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
A Switch layer sees T = 512 tokens per batch, N = 8 experts, capacity factor 1.25 and α = 0.01. (a) How many slots does each expert get? (b) The router sends 120 tokens to expert 3. What happens to them? (c) Compute the auxiliary loss under perfectly uniform routing, and under collapse where every token picks expert 1 and the mean router probability on expert 1 is 0.9. (d) Which factor in the loss carries the gradient, and in which direction does it push?
What a strong answer covers
- (a) Capacity = (512 / 8) × 1.25 = 80 slots per expert.
- (b) 80 tokens are processed. The other 40 overflow: they skip the expert and reach the next layer through the residual connection unchanged.
- (c) Uniform: fᵢ = Pᵢ = 1/8, so Σ fᵢPᵢ = 8 · 1/64 = 1/8. Times N = 8 gives 1, so the loss is α = 0.01. Collapse: f₁ = 1 and P₁ = 0.9, so the loss is 0.01 · 8 · 0.9 = 0.072.
- (d) fᵢ comes from an argmax count and is not differentiable. The gradient flows only through Pᵢ and equals α·N·fᵢ, so it lowers router probability most on the most overloaded experts.
- The factor N keeps the loss at α under uniform routing for any expert count, so one α can be reused when N changes.
- Mechanism
Switch multiplies the chosen expert's output by its router probability pᵢ(x), not by a renormalised weight of 1. Explain why this detail is what lets top-1 routing learn at all, and why earlier work expected that at least two experts per token were needed.
What a strong answer covers
- Choosing the argmax expert is not differentiable. The only path from the task loss to the router weights W_r is the scalar pᵢ(x) that scales the expert output.
- If the top-1 weight were renormalised to 1, the router would get no task gradient. Only the auxiliary loss would train it.
- With pᵢ(x) in the output, the gradient raises pᵢ when the expert's output reduces the loss and lowers it when the output hurts. This is a learned signal about routing quality.
- Shazeer et al. (2017) conjectured k > 1 was needed so the router could compare experts. Switch shows one expert is enough when the weight carries the gradient. It also halves expert compute and communication relative to top-2.
- What if…
Table 1 compares Switch-Base (top-1) with MoE-Base (top-2) at capacity factors 2.0, 1.25 and 1.0. Describe how the comparison changes as the capacity factor falls, and explain what the time-to-quality column shows that the step-100k quality column hides.
What a strong answer covers
- At capacity factor 2.0, top-2 MoE has slightly better quality at step 100k (−1.547 versus −1.554 negative log perplexity). At 1.0, Switch is better (−1.561 versus −1.572).
- Switch is faster at every setting, up to 1000 versus 860 examples per second at capacity factor 1.0. This is because top-1 sends each token to one expert, so there is less compute and less all-to-all traffic.
- Time to reach −1.50 is the fair metric: Switch-Base at capacity factor 1.0 takes 62.8 hours, against 80.1 hours for MoE-Base and 131.1 hours for T5-Large.
- A small capacity factor saves memory and communication. Switch tolerates it because dropped tokens were rare (the paper reports under 1%).
- Switch-Base+ is scaled up to match MoE-Base speed and reaches the best quality (−1.534). This shows the right comparison is quality per unit of wall-clock time.
- Critique
The paper stabilises training with three tricks: computing the router in float32 only locally, scaling the initialisation by 0.1, and using a higher dropout inside experts during fine-tuning. Yet Switch-XXL was still unstable while Switch-C was not. Critique how much these tricks explain, and design an experiment that would locate the source of instability.
What a strong answer covers
- Selective precision targets the softmax exponent. A full bfloat16 run diverged (−3.780), while casting only the router input to float32 recovered float32 quality (−1.716) at bfloat16 speed (1390 examples per second).
- Initialisation at 0.1× cut seed variance a lot (−2.72 ± 0.01 versus −3.60 ± 0.68 early in training). This treats early instability, not late spikes.
- XXL uses about 10× the FLOPs per token of Switch-C. Its instability suggests that per-token compute or width matters, not just the router, so the tricks are incomplete.
- Experiment: log the max router logit, router entropy and expert load over training. Then ablate one variable at a time (router precision, a penalty on logit size, α, learning rate) at XXL width. Check whether spikes follow logit growth or something else.
- Design
You want a 1B-active-parameter backbone for a dense retriever and a listwise reranker, trained and served on one 8-GPU academic node. Argue whether a Switch-style sparse backbone with many experts is a good choice. Cover training, query-time latency at small batch, and fine-tuning on small labelled IR sets.
What a strong answer covers
- Training: sparse models reach a given loss much faster per FLOP (the paper reports a 7× step-time speedup over T5-Base with 64 experts). But all expert weights must fit in memory, and expert parallelism adds all-to-all traffic across GPUs.
- Serving: at batch size 1, decoding is memory-bound and every expert must stay resident. Latency follows bytes loaded, so total parameters still cost memory even when FLOPs are small.
- Fine-tuning: the paper uses expert dropout 0.4 for small tasks. Its SQuAD result (Switch-C 87.7 versus Switch-XXL 89.6, with about 10× fewer FLOPs per token for C) warns that parameters do not replace per-token compute downstream.
- Alternative: distil to a dense model. The paper keeps about 30% of the sparse gain at 95% or more compression.
- Measure nDCG@10 on BEIR and latency per query against a FLOP-matched dense model and a memory-matched dense model.
- Research idea
Switch reports gains with as few as two experts and steady gains as the expert count grows at fixed FLOPs per token. Propose an experiment that separates the benefit of extra parameters from the benefit of learned, content-based routing.
What a strong answer covers
- Controls: a hash router (fixed random token-to-expert map) with the same experts, and a dense model with the same total parameters.
- If hash routing matches learned routing, the gain is mostly parameter count. DeepSeekMoE's Table 1 already reports a gap at small scale (Pile loss 1.932 for Hash Layer versus 1.881 for Switch).
- Probe specialisation: measure mutual information between expert choice and token identity, position and domain. Then perturb routing at test time and measure the loss increase.
- Repeat across expert counts (2 to 128) and model sizes to see whether the advantage of learned routing grows or shrinks.