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

William Fedus, Barret Zoph, Noam Shazeer

2021 · JMLR

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

Problem

Framing

Dense Transformer scaling raises both quality and compute cost together. The paper argues that parameter count can scale independently by replacing dense FFNs with single-expert routed sparse FFNs, yielding up to 7×7\times faster pre-training at matched FLOPs and scaling to trillion-parameter language models.

Currently Used Methods

Foundational

Proposed Method

Architecture

Switch Transformer replaces each dense Transformer FFN with a bank of NN FFN experts plus a router. Each token is sent to exactly one expert, then scaled by its router probability; self-attention and residual structure stay unchanged.

Switch Transformer encoder block: a standard self-attention block followed by a sparse Switch FFN layer that routes each token to one of several FFN experts and rescales the expert output by the router gate.

Loss / Objective

Training adds a load-balancing auxiliary term to the language-model loss.

L=LLM+αNi=1NfiPi\mathcal{L} = \mathcal{L}_{\mathrm{LM}} + \alpha N \sum_{i=1}^{N} f_i P_i fi=1TxB1{argmaxp(x)=i},Pi=1TxBpi(x)f_i = \frac{1}{T} \sum_{x \in B} \mathbf{1}\{\operatorname{argmax} p(x) = i\}, \qquad P_i = \frac{1}{T} \sum_{x \in B} p_i(x)

Sampling Rule / Algorithm

Routing is top-1 expert selection with fixed per-expert capacity.

pi(x)=eh(x)ijeh(x)j,y=pi(x)Ei(x),i=argmaxipi(x)p_i(x) = \frac{e^{h(x)_i}}{\sum_j e^{h(x)_j}}, \qquad y = p_{i^\ast}(x) E_{i^\ast}(x), \qquad i^\ast = \operatorname{argmax}_i p_i(x) expert capacity=tokens per batchnumber of experts×capacity factor\text{expert capacity} = \frac{\text{tokens per batch}}{\text{number of experts}} \times \text{capacity factor}

Training Procedure

Evaluation

Datasets

Metrics

Headline results

Results table

Table 1: Benchmarking Switch versus MoE.

ModelCapacity FactorQuality after 100k steps (Neg. Log Perp.) (↑)Time to Quality Threshold (hours) (↓)Speed (examples/sec) (↑)
T5-Base-1.731Not achieved†1600
T5-Large-1.550131.1470
MoE-Base, Top-22.0-1.54768.7840
MoE-Base, Top-21.25-1.55980.71000
Switch-Base2.0-1.55472.8860
Switch-Base1.25-1.55365.0910
Switch-Base+1.25-1.56162.81000

Ablations

Method Strengths and Weaknesses

Strengths

Weaknesses

Suggestions from the authors

Links

Prior Papers

Further Papers