Papers · 2021 · Reading: 26 min, plus 3 in closed details · +5h 45m of resources.
Paper · JMLR 23(120), 2022 · arXiv 2101.03961

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

William Fedus, Barret Zoph, Noam Shazeer
Google Brain · January 2021 (arXiv v1 11 January 2021; JMLR 2022; arXiv v3 June 2022)

In one line: Simplified MoE to top-1 routing with a single balancing loss and selective fp32, reaching T5-Base quality up to 7x faster at equal FLOPs per token (64-expert Switch-Base) and scaling to the 1.6T-parameter Switch-C, 4x faster than T5-XXL to a fixed perplexity and the first trillion-parameter model with reported results.

7x faster
Switch-Base, 64 experts, to T5-Base's quality, same 32 TPUv3 cores and FLOPs per token
7.5x on a step basis; read off curves, no table · Figure 5
62.8 hours
to a fixed quality at capacity factor 1.0, against 80.1 for top-2 MoE
T5-Large: 131.1; T5-Base never gets there · Table 1
1.57T parameters
Switch-C: 2,048 experts in every FFN, trained with no instability
recounted from its configuration to within 0.1% · Table 9

How far to trust it: Believe the engineering: one expert per token, one balancing loss, a float32 router and a smaller initialisation made sparse training cheap and stable enough to reach 1.57T parameters, and the balancing loss and float32 router are still in today's configurations. Treat the size of the speedups (7x, 4x) as single runs read off curves, and the top-1 over top-2 margin as within noise: the same group recommended top-2 a year later. The evidence, point by point.

The idea in one sentence

Replace every other feed-forward block with many expert copies and send each token to exactly one of them, so parameters grow with the number of experts while FLOPs per token stay those of the dense model; one balancing loss, a float32 router and a smaller initialisation make that train stably, and it reached T5-Base's quality 7x faster and 1.57T parameters.

You need the generic MoE layer (router, top-k, load balancing) from Mixture of experts, and T5's encoder-decoder from T5; this page covers what is specific to this paper. The owner's 3D figures step real tokens through a router (its Fig. 3), replay collapse against balancing (Fig. 4) and fill top-2 buffers at several capacity factors (Fig. 5); the two figures here are what Switch adds: top-1 buffers and their trade-off, and the paper's Figure 9.

New terms. Switch layer: a top-1 MoE FFN. Expert capacity: the fixed number of token slots each expert gets per batch. Capacity factor: the multiple of an even share that sets it. Dropped token: one that overflows its expert and skips the layer through the residual. Selective precision: the router alone computed in float32. FLOP-matched: a sparse model with the same FLOPs per token as its dense twin.

One token, one expert: the router picks FFN 2 for "More" and FFN 1 for "Parameters", and scales each output by its gate value
The paper's Figure 2: a Transformer block whose feed-forward layer is replaced by a Switch layer. Two tokens, More and Parameters, each pass through self-attention, then a router whose softmax picks one of four FFN experts (FFN 2 with p = 0.65, FFN 1 with p = 0.8); the chosen expert's output is multiplied by p and added back through the residual.
Notice that only one of the four experts runs per token, and the dashed line carrying p to the multiply: that product is the only path by which the router gets a gradient. Everything else on this page elaborates this picture. On a phone only the right half (the Switch layer itself) is shown. Credit: Fedus, Zoph and Shazeer, Figure 2, JMLR 23(120) 2022, CC BY 4.0 (source).

Problem

§1, §2 intro, §7

Kaplan-era scaling said bigger dense models are better (Kaplan et al. 2020), but in a dense model every parameter is touched by every token, so parameter count and FLOPs per token grow together. Sparse Mixture-of-Experts layers (Shazeer et al. 2017; GShard, Lepikhin et al. 2020) had shown the two can be decoupled: many expert networks, a router picks a few per token. Yet MoE saw little adoption, for three reasons the paper names and attacks head-on (§1, §7):

  • Complexity: top-k routing with k of at least 2, separate auxiliary losses, capacity juggling.
  • Training instability, especially in bfloat16: GShard "trains with float32 precision throughout their MoE Transformer" (§2.4).
  • Communication cost: tokens have to travel to their experts on other devices and back.

The question: can MoE be made simple, stable and fast enough that parameter count becomes a routine fourth scaling axis, beside model size, data and compute, "while keeping the floating point operations (FLOPs) per example constant"? The hypothesis is that "the parameter count, independent of total computation performed, is a separately important axis on which to scale" (§2).

Everything is built on T5: its encoder-decoder, its C4 corpus and its span-corruption objective (15% of tokens dropped, each span replaced by one sentinel); quality is negative log perplexity in nats, higher is better (§2.3). The generic MoE layer (routers, top-k styles, capacity, expert parallelism, current configurations) lives on Mixture of experts.

capacity factor

Illustrative router probabilities (expert 1 is popular); the paper's rules: capacity from Eq. 3 rounded up, slots filled in batch order, first choices before second choices. One box per token slot.

Idea: one expert per token

§2.1, Figure 2, Eq. 1 and 2

The Switch layer. Take T5 and replace the feed-forward network (FFN) in every other Transformer block with N expert FFNs plus a linear router Wr (Figure 2, the figure at the top). The router computes logits h(x) = Wr · x, a softmax turns them into gate values pi(x) = eh(x)i / Σj eh(x)j (Eq. 1), and the token goes to the single expert with the largest one. The layer's output is that expert's output multiplied by its gate value, y = pi(x) Ei(x), the k = 1 case of Eq. 2. The multiplication is what keeps the router differentiable: the choice itself has no gradient, the gate value does.

Top-1 is the core simplification. Shazeer et al. (2017) "conjectured that routing to k > 1 experts was necessary in order to have non-trivial gradients to the routing functions", intuiting that the router could not learn without comparing at least two experts; Ramachandran and Le (2018) found higher k mattered in lower layers. Switch routes to one and claims three benefits (§2.1): (1) less router computation; (2) each expert's batch, its expert capacity, "can be at least halved since each token is only being routed to a single expert"; (3) a simpler routing implementation and lower communication cost. The quality claim, that k = 1 "preserves model quality", is tested in Table 1 below.

The card runs one batch of 12 tokens through a 4-expert layer with the same router probabilities, as Switch (top-1) or as the top-2 MoE Transformer the paper compares against; the steps are the paper's own router function (Code Block 15). Pick a router:

  1. A batch of 12 tokens. The same 12 tokens and the same router probabilities as in the top-2 list, now through a Switch layer: one expert per token.
  2. The router, in float32. Logits Wr · x, one per expert, then a softmax in float32 (selective precision), at a cost of dmodel × experts per token (§3). The bars under each token are its four gate values.
  3. Choose the top 1. Each token keeps only its largest gate value (its outline). Shazeer et al. conjectured this would starve the router of gradient; the gate value multiplying the output still carries one.
  4. Capacity: C slots per expert. One choice per token: C = (12 / 4) × capacity factor, rounded up (Eq. 3). Half of top-2's buffer at the same capacity factor, which is benefit (2) of §2.1.
  5. Dispatch through the all-to-all. Tokens fill their expert's slots in batch order (the cumulative sum in Code Block 15). A token arriving at a full expert is dropped: it skips the layer entirely.
  6. Experts compute every slot. One expert FFN per token: the same FLOPs as T5-Base's dense FFN, plus the router. Empty slots are padding, the price of a capacity factor above 1.0.
  7. Combine, weighted by the gate. Output = pi(x) Ei(x) added to the residual stream; a dropped token "is passed directly to the next layer through the residual connection" (§2.2), unchanged.

Try capacity factor 1.0 in both modes: top-2 computes 24 slots for 12 tokens, top-1 computes 12; top-2 loses only second choices, top-1 loses whole tokens. That trade is the paper's whole bet, and §2.3 measures it.

Expert capacity, the capacity factor and dropped tokens

§2.2, Eq. 3, Figure 3

TPUs compile static shapes, but routing is decided at run time, so each expert gets a fixed buffer (§2.2):

expert capacity = (tokens per batch / number of experts) × capacity factor   (Eq. 3)

  • A capacity factor (CF) above 1.0 "creates additional buffer to accommodate for when tokens are not perfectly balanced", at the price of padding: unused slots are computed and communicated anyway, wasting compute and memory (Figure 3).
  • Tokens that overflow an expert are dropped: "computation is skipped and the token representation is passed directly to the next layer through the residual connection".
  • "Ensuring lower rates of dropped tokens are important for the scaling of sparse expert-models", and the authors saw no dependence of the drop rate on the number of experts, "typically <1%".
  • Low capacity factors (1.0 to 1.25) are the sweet spot in Table 1, and they matter most at large scale, "where model memory is very scarce and the capacity factor will want to be made as small as possible" (§2.3).

The capacity rule and token dropping were inherited from GShard (Appendix B); what Switch changes is that with one expert per token the same capacity factor buys half the buffer.

The stage runs this on real routing: the page's toy Switch layer (the Train tab's settings: 16 experts, top-1, α = 0.01, trained 1,500 steps at capacity factor 1.25, seed 1) routes one held-out batch of 512 tokens, and the same choices are buffered at several capacity factors.

  1. One expert per token. The router sends each of the 512 tokens to one of 16 experts; each column is an expert, its height the tokens it was sent. A perfect split would be 32 each; this trained router gives 7 to 67, with the balancing loss on.
  2. Capacity factor 1.0: 32 slots. The glass plane is each expert's buffer. What sticks out above it (red) is dropped and travels round the experts on the residual path: 148 of 512 tokens (28.9%). The same number of slots, 148 of 512, sit empty below the plane as padding: an expert that is short cannot lend its room to one that overflows.
  3. Capacity factor 1.25: 40 slots. The paper's training setting: 93 tokens dropped (18.2%), and 221 of 640 slots padded. Every slot is computed and sent through the all-to-all whether it is filled or not.
  4. Capacity factor 2.0: 64 slots. The released evaluation setting: 4 tokens dropped (0.8%), but 516 of 1,024 slots computed are padding, so half the expert compute and all-to-all traffic carries nothing.
  5. Top-2 at 1.25: 80 slots. The toy's top-2 twin, trained the same way: 1,024 assignments (second choices paler), so each buffer is 80 slots, 1,280 in all, twice top-1's 640 at the same capacity factor. No first choice is dropped and 55 second choices are, so every token in this batch keeps at least one expert.
  6. The trade-off. Top-1 again, the four capacity factors side by side: tokens dropped (red) against slots padded (glass), 293 and 37 at 0.5, 148 and 148 at 1.0, 93 and 221 at 1.25, 4 and 516 at 2.0. The batch's error falls from 0.41 to 0.11 as fewer tokens skip this single layer (passing every token through unchanged scores 0.62).

The routing is recorded from the toy (mk_cap_data.cjs, the Train tab's code); only the buffer size changes between steps 2 to 4. Over all 2,048 held-out tokens the same layer drops 28.1%, 17.5% and 1.6% at capacity factors 1.0, 1.25 and 2.0. A one-layer toy is far less balanced than the paper's models (under 1%), and a drop costs it far more; measured over three seeds with each capacity factor trained: the Train tab's sweep.

One differentiable balancing loss

§2.2, Eq. 4 to 6, Code Block 14

Left alone, a router sends more tokens to whichever experts are already good, which then get better: imbalance, overflow and drops. For each Switch layer the paper adds one auxiliary loss to the training loss (Eq. 4):

loss = α · N · Σi fi · Pi

  • fi is the fraction of the batch's T tokens actually dispatched to expert i, an argmax count with no gradient (Eq. 5).
  • Pi is the fraction of router probability given to expert i, averaged over the batch, which is differentiable (Eq. 6). The paper's footnote warns of the easy confusion: pi(x) is one token's probability, Pi the batch average.
  • Both should be 1/N; the loss "is minimized under a uniform distribution". The factor N keeps it constant as the expert count changes, since uniform routing gives Σ fiPi = 1/N.
  • α = 10-2 throughout, from a sweep of 10-1 to 10-5 in powers of 10: large enough to balance load quickly, small enough not to interfere with the cross-entropy objective.
  • It replaces the separate load-balancing and importance-weighting losses of Shazeer et al. (2017), following the simplification of Mesh TensorFlow and GShard.
a router collapses: every token goes to expert 1, with probability close to 1. With N = 8 experts, what does the loss become (in units of α)?
The pseudocode's version, and a typo in it

Code Block 14 computes it per core: the mean over experts of f · P, times "num_experts ^ 2", which is N · Σ fiPi, the same as Eq. 4. Read literally as Python, ^ is a bitwise exclusive or (128 ^ 2 = 130); the real moe.py writes float(experts_dim.size * experts_dim.size), a square.

Training tricks: a float32 router, a smaller initialisation, expert dropout

§2.4, Tables 2 to 4

Selective precision. Routing makes "hard-switching" decisions in every Switch layer, and bfloat16 "can exacerbate issues in the softmax computation for our router" (§2.4). Pure bfloat16 diverged; pure float32 is stable but pays for float32 tensors in the all-to-all (1,160 examples a second against bfloat16's 1,390). The fix: cast the router's input to float32, compute only the router function in float32, locally on each device, and recast the dispatch and combine tensors to bfloat16 at the end of the function, so "no expensive float32 tensors are broadcast through all-to-all communication operations". Float32's stability at bfloat16's speed:

bfloat16 has the same exponent range as float32, so nothing overflows. Ten experts have router logits of 128 and one has 128.5. In float32 the top expert's probability is 0.142. In bfloat16 it is about

A smaller initialisation. Weights are drawn from a truncated normal with σ = √(s/n), n the fan-in, values beyond two standard deviations resampled. The paper recommends cutting T5's default scale s = 1.0 by ten, to 0.1: better quality and far less variance early in training (Table 3: −2.72 ± 0.01 against −3.60 ± 0.68 after 3.5k steps, three seeds each), and the same scheme trained everything from the 223M baseline to over a trillion parameters.

Expert dropout. Fine-tuning tasks are small and a Switch model has far more parameters than its FLOP-matched dense twin, so overfitting is worse. Raising dropout everywhere hurts; dropout 0.1 outside the experts and 0.4 inside the experts' intermediate layer is best (Table 4):

Switch against the top-2 MoE (Table 1)

§2.3, Table 1

The head-to-head: T5-Base, T5-Large, a top-2 MoE-Base and Switch-Base, both sparse models with 128 experts in every other FFN layer, all on 32 TPUv3 cores, quality after 100k steps and hours to a negative log perplexity of −1.50 (Table 1). Switch is FLOP-matched to T5-Base; the top-2 MoE runs two experts per token, so its FLOPs are larger.

  • On wall-clock, Switch wins at low capacity factors: 62.8 hours at CF 1.0 against 80.1 for MoE-Base, and 65.0 against 80.7 at 1.25. At CF 2.0 the order flips: MoE-Base reaches the threshold in 68.7 hours, Switch-Base in 72.8.
  • Per step the two are within hundredths: MoE-Base is ahead at CF 2.0 (−1.547 against −1.554), Switch at 1.25 and 1.0. Switch "perform[s] better at lower capacity factors".
  • Switch-Base+ spends Switch's speed advantage on size (hidden 768 to 896 until it matches MoE's speed) and is best per step of all (−1.534).
  • T5-Base never reaches −1.50 in 100k steps; T5-Large takes 131.1 hours.
  • The authors' own caveat: MoE-Base slowing from 840 to 790 examples a second when its capacity factor drops from 2.0 to 1.25 "is unexpected", and speed "is both a function of the algorithm and the implementation details" (footnote 5).

Scaling at fixed FLOPs per token

§3, Figures 4 to 6, Appendix D

With the C4 corpus (over 180B target tokens) the models are not data-bound, and the number of experts is "the most efficient dimension for scaling": compute per token stays nearly fixed because each token still sees one expert, and the router only adds a cost of O(dmodel × experts) (§3).

  • Step basis (Figure 4): doubling the experts from 2 up to 256 (14.7B parameters), all FLOP-matched to the 223M T5-Base, improves test loss every time. Switch-Base with 64 experts reaches at step 60k the quality T5-Base reaches at step 450k: a 7.5x step speedup. Larger models are also more sample efficient, as Kaplan et al. found.
  • Time basis (Figure 5): routing costs communication and router compute, so steps are slower, but at a fixed budget on 32 TPUv3 cores Switch-Base 64 reaches T5-Base's quality "in one-seventh the time": the headline 7x.
  • Against a bigger dense model (Figure 6): Switch-Base is more sample efficient than T5-Large and 2.5x faster in wall-clock, although T5-Large applies 3.5x more FLOPs per token (425B against 124B per sequence in Table 9 is 3.4x). Switch-Large, FLOP-matched to T5-Large, then goes further.
  • Few experts (Appendix D, Figure 12): as few as 2, 4 or 8 experts improve on T5-Base, fitting on ordinary GPUs or TPUs ("one expert per core" is the recommendation).

None of these figures has printed values: the 7x, 7.5x and 2.5x are the authors' readings of their curves, and this page repeats them rather than re-reading the curves. The Train tab runs the expert-count sweep on a toy at equal FLOPs per token.

More experts, same FLOPs per token: every doubling lowers the loss, and every Switch curve sits far above T5-Base
The paper's Figure 4. Left: test loss against sparse model parameters on a log axis for Switch-Base with 1, 2, 4, 8, 16, 32, 64, 128 and 256 experts, falling from 6.0 to about 4.85. Right: negative log perplexity against training step up to 450k for T5-Base and Switch-Base with 16, 32, 64 and 128 experts; all Switch curves lie well above T5-Base.
Notice the left panel's steady fall per doubling of experts (1e, one expert, is a dense model the size of T5-Base), and on the right the horizontal gap: Switch-Base 64e reaches at step 60k the quality T5-Base reaches at 450k. No values are printed; the multipliers below are the authors' readings. On a phone the two panels are stacked. Credit: Fedus, Zoph and Shazeer, Figure 4, JMLR 23(120) 2022, CC BY 4.0 (source).

Downstream: fine-tuning, distillation, 101 languages

§4, Tables 5 to 8, Figures 7 and 8

Fine-tuning (§4.1). Baselines T5-Base (223M) and T5-Large (739M), each with a FLOP-matched Switch twin, all four pretrained for 576B tokens.

The protocol: data, steps, dropout, tasks and metrics

Pretraining with 220 (1,048,576) tokens per batch for 550k steps on an improved C4 with intra-example duplicates removed (Lee et al. 2021), so the baselines differ slightly from Raffel et al. Fine-tuning: dropout 0.1 except 0.4 in the Switch layers, batch 1M for 16k steps, validation every 200 steps, peak reported. Tasks: GLUE and SuperGLUE as token-proportional mixtures, CNNDM and XSum (Rouge-2), SQuAD and ARC, closed-book Natural Questions, Web Questions and TriviaQA (exact match), Winogrande and ANLI (accuracy).

Switch beats its FLOP-matched T5 on 10 of 11 tasks at Base and 9 of 11 at Large, including SuperGLUE (+4.4 and +2.0) and large gains on Winogrande, closed-book TriviaQA and XSum. The exceptions are ARC: T5-Base wins the Challenge set and T5-Large the Easy set (Table 5).

Distillation (§4.2). A trillion-parameter model is hard to deploy, so the sparse teacher is distilled into the dense T5-Base (distillation in general: Distillation and Small Language Models). Two tricks help: initialise the student's non-expert layers from the teacher (possible because the models are FLOP-matched, so those layers have the same shapes), and train on 0.25 of the teacher's probabilities mixed with 0.75 of the ground-truth label. Together they keep about 30% of the quality gain with about one-twentieth of the parameters (Table 6; quality gain = the share of the gap between teacher and plain T5-Base). The shares recompute exactly (recomputed).

Distillation across teacher sizes and after fine-tuning (Tables 7 and 8)

Across teachers of 1.1B to 14.7B parameters, 37% of the gain survives at 82% compression and 28% at 99% (Table 7); a 7.4B Switch-Base fine-tuned on SuperGLUE distils into T5-Base keeping 30% (74.6 to 76.6 against the teacher's 81.3, Table 8). Three of the five compression percentages need the student counted as 0.2B rather than 223M (recomputed).

Multilingual (§4.3). mSwitch-Base against mT5-Base, pretrained 1M steps on mC4's 101 languages (107 tasks with script variants): negative log perplexity improves in all 101 languages (Figure 7); the step speedup to mT5-Base's final quality averages 5x, and 91% of languages get 4x or more (Figure 8; speedup = baseline steps divided by Switch steps to the same quality). Both figures are images only.

Data, model and expert parallelism

§5, Figure 9, Eq. 7

More experts give diminishing returns, so §5 lays out how to also grow the dense dimensions (dmodel, dff) by combining three ways of splitting work across N cores, arranged by Mesh TensorFlow as a logical mesh of n data-parallel by m model-parallel ways, N = n × m. The FFN, h = x Win and y = ReLU(h) Wout, is the example; B tokens per batch, E experts of capacity C. The paper's Figure 9 is an image; the stage redraws it for 16 cores, one strategy per step, with each strategy's communication from §5.1 to §5.5.

  1. Data parallelism (§5.1). Every core holds the whole FFN (the same glass plate on all 16: a copy, 4.72M weights) and 1/16 of the batch, 65,536 tokens (a different colour per core). "No communication is needed until the entire forward and backward pass is finished", then the gradients are all-reduced.
  2. Model parallelism (§5.2). Every core holds all 1,048,576 tokens and a 1/16 slice of dff (0.29M weights, a thin plate). The second matrix multiplication sums over the split dff, so the cores all-reduce a [B, dmodel] tensor in the forward pass, 1.50 GiB sent per core, and again in the backward pass.
  3. Model and data parallelism (§5.3), as in the largest T5 models and GPT-3. Each row of four cores is one data shard of 262,144 tokens; along a row the FFN is cut into four slices of 1.18M weights, and each row all-reduces [B/n, dmodel] in each pass, 384 MiB per core forward.
  4. Expert and data parallelism (§5.4), Switch's native layout (Switch-Base and Switch-C). Sixteen data shards of 65,536 tokens and 16 experts, one per core: a distinct full-size plate on every core, 75.5M distinct weights over all 16, while each core still holds 4.72M weights and does the same FLOPs per token. Each core routes its own tokens, then one all-to-all of [E, C, dmodel] sends them to their experts and another brings the outputs back: 192 MiB per core forward (the arcs from one core; every core does the same).
  5. Expert, model and data parallelism (§5.5), Switch-XXL. Four experts, one per row, each split four ways over dff (1.18M weights per core). A larger dff means more FLOPs per token, but m is taken from n: four data shards of 262,144 tokens, and the all-to-all is joined by the rows' all-reduces, 1.13 GiB per core forward.

Same colour on several cores: a copy; distinct colours: distinct weights (glass plates, width to scale with the weights a core holds) or tokens (blocks, height to scale with tokens per core). Numbers: the released Switch-Base FFN (dmodel 768, ReLU, dff 3072, as many parameters as Table 9's GEGLU 2048), 220 tokens per batch, capacity factor 1.0, bfloat16, one FFN layer forward; FLOPs per token 9.44M in every layout, 2 per weight, one expert per token.

The dispatch tensor and the all-to-all shapes (Eq. 7)

Each core's router builds a binary dispatch tensor of shape [n, B/n, E, C], gathers its tokens with one einsum (Eq. 7) into [n, E, C, dmodel], and an all-to-all of size [E, C, dmodel] reshards from the data dimension to the expert dimension; a second all-to-all brings the outputs back.

  • Adding model parallelism (§5.5) raises FLOPs per token by widening dff, but memory per core then forces m up, and with N fixed, n and the batch down; the all-to-all and model parallelism's all-reduces add up, and "the best mapping is empirically determined".
  • Model parallelism costs an all-reduce in each pass, data parallelism one for the gradients (§5.1, §5.2); the tensor-parallel layout is Megatron-LM's. How each parallelism and the all-to-all cost in general is on Distributed Training.

Towards a trillion parameters

§5.6, Table 9, §8

Two large models, both trained on C4 (Table 9):

  • Switch-XXL, 395B parameters, FLOP-matched to T5-XXL (6.3T FLOPs per sequence, dmodel 4096, dff 10240 GEGLU, 64 heads, experts in every other layer), which uses model parallelism for its larger dimensions at the cost of extra communication. Table 9 says 64 experts, but 64 experts count to 201B; the released configuration has 128, which counts to 394.5B (recount).
  • Switch-C, 1.571T parameters: 2,048 experts in every FFN layer, 15 layers per stack, dmodel 2080, dff 6144, expert and data parallelism only, so its dense dimensions are much smaller than T5-XXL's and it needs only 890B FLOPs per sequence. Its parameters recount to 1,571.3B and its FLOPs to 894B from the configuration alone.

Sample efficiency against T5-XXL. After 250k steps, "both Switch Transformer variants" beat T5-XXL's −1.147 "by over 0.061", a gap worth noting because T5-XXL needed another 250k steps to gain 0.052; by 500k steps Switch-XXL leads by 0.087 (footnote 10: a lower bound, since T5-XXL trained on an easier C4 with duplicates). Recomputed from the same table, Switch-XXL's lead is 0.061 and Switch-C's 0.051, so "over 0.061" holds for one of the two. The abstract's 4x speedup over T5-XXL is stated for Switch-C in the caption of Table 9, "to a fixed perplexity (with the same compute budget)"; the table itself shows Switch-C at 250k steps level with T5-XXL at 500k (−1.096 against −1.095).

Stability. Switch-C "exhibits no training instability at all"; Switch-XXL, with "nearly 10x larger FLOPs per sequence", is sometimes unstable and was not trained for T5's full 1M steps. From Table 9, 6.3T / 890B is 7.1x, not nearly 10x.

Switch-C has four times Switch-XXL's parameters (1,571B against 395B); Switch-XXL applies about seven times Switch-C's FLOPs per token. Fine-tuned on SQuAD, which scores higher?
Fine-tuning a partly trained Switch-XXL: the numbers

Switch-XXL checkpoint after 503B tokens, about half of T5-XXL's; multi-task training for efficiency): SQuAD 89.7 against a state of the art of 91.3; SuperGLUE test 87.5 against T5's 89.3 and a state of the art of 90.0; ANLI 65.7 against a previous best of 49.4. On closed-book knowledge tasks without salient span masking it beats the previous best T5-XXL: Natural Questions 34.4 against 32.8, Web Questions 41.0 against 37.2, TriviaQA 47.5 against 42.9. Switch-XXL has the state-of-the-art upstream perplexity, but "its gains have not yet fully translated to SOTA downstream performance", and upstream gains carry better to knowledge tasks than to reasoning (Appendix E).

In short: state-of-the-art upstream perplexity, state of the art on ANLI and closed-book knowledge tasks, still behind on SQuAD and SuperGLUE, with half of T5-XXL's training tokens.

Appendices: what else was tried

Appendices A to F

Experts in attention help in float32 but diverge in bfloat16; rerouting overflow to a second-choice expert brings nothing; multiplicative jitter is the router's exploration noise; upstream quality predicts downstream quality, less well for Switch on reasoning at large scale.

Each appendix, with its numbers
  • Switch for attention (Appendix A, Table 10): Switch layers replacing the query, key and value weight matrices (experts linear or FFN) improve quality in float32 (−1.524 against −1.548 at 100k steps with 32 experts) but diverge in bfloat16, so they were left for future work.
  • No-Token-Left-Behind (Appendix B, Figure 11): overflowing tokens rerouted, iteratively, to their next-best expert, so almost nothing is dropped. No empirical benefit; the authors suspect that sending a token to a different expert than the one it is associated with hurts.
  • Exploration (Appendix C, Table 11): the router never sees how an alternative expert would have done, a contextual-bandit exploration problem. Argmax −1.471, sampling from the softmax −1.570, input dropout −1.480, multiplicative input jitter −1.468; jitter is used throughout. In moe.py it multiplies the router's input by a uniform draw from 1 − 10-2 to 1 + 10-2, a function documented as making models "more resilient to rounding errors introduced by bfloat16"; Code Block 15 instead adds the draw to the logits: a shift of about 1 that a softmax ignores, plus noise of at most 0.01. (Table 11's caption says "lower is better"; for negative log perplexity higher is better, as everywhere else in the paper.)
  • Upstream to downstream (Appendix E, Figure 13): better pretraining means better fine-tuning for both families; at a fixed perplexity the dense model often does better on SuperGLUE, especially at large scale, while Switch does better on TriviaQA. "Further statistics ... would be necessary to confirm these observations."
  • Pseudocode (Appendix F): the load-balancing loss, the router and the distributed Switch layer in Mesh TensorFlow, the basis of this page's animation and toy.

How much of this to believe

Tables 1 to 11, Figures 4 to 8

What holds up.

  • The mechanism. One expert per token, the f · P loss, a float32 router and a smaller init are each simple and released as code (t5x, Mesh TensorFlow); the balancing loss and the higher-precision router are still in today's models (Then and now).
  • Big effects are well outside any plausible noise. Selective precision against bfloat16 (−1.716 against a diverged −3.780), and Switch against FLOP-matched T5 on pretraining: 0.23 nats at Base and 0.15 at Large after 250k steps in Table 9, when the only seed spread the paper reports is 0.01 (Table 3, 0.1x init).
  • The table arithmetic checks out almost everywhere: every distillation share in Tables 6 to 8 recomputes, T5-Base's 223M and 124B FLOPs and Switch-C's 1,571B and 890B come out of the configurations alone (checks).
  • The authors flag their own weak spots (footnote 5 on speed, Switch-XXL's instability and reasoning transfer in §5.6 and §8, footnote 10 on T5-XXL's data), which counts in their favour.

What is weaker.

  • Single runs with no error bars for every quality comparison except Table 3, and Table 3 itself is thin: three seeds each, a mean gap of 0.88 nats with a standard error of 0.39 (t of about 2.2 on two degrees of freedom), so its clear finding is the variance (0.01 against 0.68), not the mean. Table 1's per-step differences between Switch and MoE are 0.006 to 0.011 nats; ST-MoE (beyond this paper) later measured top-2 at +0.004 over top-1 and called it a small gain (§5.2). Table 4's winning dropout setting leads on GLUE by 0.5 points and ties or trails elsewhere; Table 11's chosen jitter leads argmax by 0.003.
  • The headline speedups are read off curves. 7x, 7.5x, 2.5x, 5x and 91% come from Figures 4 to 8 with no printed values; the 4x over T5-XXL is a caption.
  • Wall-clock comparisons are implementation-bound: Table 1 mixes the algorithm with Mesh TensorFlow's TPUv3 kernels, and ST-MoE found the top-1 against top-2 speed gap "negligible" at 8x the scale.
  • The fine-tuning protocol takes the best of 80 validation checkpoints (every 200 steps for 16k) on validation sets, the same for both sides, so the comparison is fair but the absolute numbers are optimistic.

Internal inconsistencies exist but are all minor (the expert count of Switch-XXL in Table 9 is the one a user would trip over).

The seven internal inconsistencies, each checked
  • Table 9's 64 experts for Switch-XXL (128 in the released code, and only 128 gives 395B); "nearly 10x" FLOPs (7.1x); "over 0.061" for both large models (Switch-C is 0.051); "100x more parameters" in Table 6's caption (3.8B against 223M is 17x; the text says one-twentieth); 14 heads for Switch-Base in Table 1's caption (12 in Table 9); Table 11's "lower is better"; T5-Large's GEGLU row in Table 9 counts to 750M and 433B, while the released ReLU configuration gives 738M and 425B, matching the text's 739M and the table's FLOPs.

Verdict. Believe the engineering and the direction: sparse top-1 MoE with these fixes trains stably and beats FLOP-matched dense T5 by a wide margin, per step and per hour. Treat the exact multipliers as single-run readings, and the top-1 over top-2 conclusion as a statement about small TPU models in 2020: the margin is within noise, and the same group recommended top-2 a year later.

What it takes to use this

§7, released code
  • Code and weights: JAX code and all checkpoints in t5x (Apache 2.0); model configurations as gin files in flaxformer; the original Mesh TensorFlow layer in moe.py. Hugging Face hosts ports from switch-base-8 to switch-c-2048.
  • Hardware: memory scales with total parameters, compute with active ones. The paper's own comparisons ran on 32 TPUv3 cores; "one expert per core" is its rule of thumb, and 2 to 8 experts already help on commodity accelerators (§7, Appendix D).
  • Settings the released configurations use: train capacity factor 1.25 (1.0 for Switch-C), evaluation capacity factor 2.0 (4.0 for Switch-XXL), α = 0.01, router in float32, experts in every other layer (every layer for Switch-C).
  • When it pays: pretraining at a fixed compute budget, and knowledge-heavy tasks. When it buys less: memory-bound deployment (distillation keeps only about 30% of the gain), reasoning-heavy fine-tuning at large scale (Appendix E), and GPU stacks with dropless kernels, which have since replaced capacity factors (Then and now).

Why it matters (beyond the paper)

§9 Conclusion

This is the paper that made sparse MoE practical. It showed top-k with k > 1 was not necessary, compressed MoE's losses into one balancing loss, showed bfloat16 sparse training works with a local float32 router, and named the vocabulary the field still uses: expert capacity, capacity factor, token dropping, expert parallelism, sparse against active parameters. It made parameter count a scaling axis separate from FLOPs, and Switch-C was the first trillion-parameter model with reported results: GShard had trained a 1T MoE in bfloat16 but "encountered several trainability issues with numerical stability, hence did not include the results" (GShard).

The lineage runs straight through GLaM (top-2 of 64 experts in every other layer, 1.2T parameters; GLaM) and ST-MoE (router z-loss, top-2 at capacity factor 1.25; ST-MoE) to Mixtral (top-2 of 8 coarse experts in every layer, open weights) and to DeepSeekMoE and DeepSeek-V3 (fine-grained plus shared experts, and auxiliary-loss-free bias balancing, which addresses the balance against quality tension the f · P loss introduced). Its pain points were as influential as its fixes: token dropping motivated dropless kernels (MegaBlocks: "never drops tokens"), and its instability at scale motivated the router z-loss line of work (ST-MoE). Line by line, with sources: Then and now.

Where the recipe stands now (as of October 2026)

High-sparsity MoE is today's default frontier recipe (GPT-4-class models, Llama 4, Qwen3-MoE, Kimi K2); the models and their current configurations are compared on Topic: llm-landscape and Mixture of experts.

Connections