Switch Transformer

The paper makes sparse Mixture-of-Experts scaling simpler by routing each token to one expert.

Metadata

FieldValue
PaperSwitch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity
AuthorsWilliam Fedus, Barret Zoph, Noam Shazeer
Year2021 preprint; 2022 journal
VenueJMLR 2022
arXiv2101.03961
JMLR23(120):1-39
Statusfull note started

One-Line Takeaway

Switch Transformer replaces dense feed-forward layers with sparse expert layers and uses top-1 routing so model capacity can grow faster than per-token compute.

Question

Dense Transformers use the same parameters for every token. If a model has hidden states

then a standard Transformer block applies the same feed-forward network to every token:

Increasing model size usually increases the computation each token must pay. If width grows from to , or if more layers are added, every token uses more FLOPs.

Mixture-of-Experts changes this contract:

The paper asks:

Can sparse expert routing be simplified enough to make very large parameter-count Transformers practical to train?

Main Claim

Top-1 expert routing is sufficient for effective sparse Transformer scaling. Instead of mixing multiple expert outputs, each token is sent to one selected expert.

For experts:

the router computes a probability distribution:

where:

The selected expert is:

The Switch layer output is approximately:

The key simplification is:

Earlier MoE variants often used top-2 routing:

Switch uses:

This reduces routing complexity, expert communication, and expert combination cost.

Architecture Contract

ComponentInputOutputRole
Token hidden staterouter logitschoose expert
Routertoken stateexpert index and gate valueconditional path
Expert FFNassigned tokenstransformed token statessparse capacity
Capacity ruletoken assignmentsaccepted/dropped tokensbound per-expert load
Load-balancing lossrouter statisticsauxiliary scalar lossprevent expert collapse

The Switch layer replaces the dense FFN sublayer in a Transformer block:

Attention remains dense. Sparsity is applied mainly to the feed-forward block.

Dense FFN Baseline

A standard Transformer feed-forward network is:

For hidden width and intermediate width , parameter count is roughly:

Every token uses this same computation:

If the dense FFN is made wider, both parameter count and per-token compute increase.

Expert FFN Layer

Switch Transformer creates expert FFNs:

Total expert parameters become:

But each token only evaluates one expert:

So the expert parameter pool grows with , while per-token expert compute remains close to one FFN:

This is conditional computation.

Router

The router is usually a linear classifier over experts:

The top expert is:

The gate value is:

The output is:

This means routing is discrete in expert choice but still uses a continuous gate multiplier.

Capacity Factor

If every token chooses the same expert, sparse routing breaks. One expert receives too many tokens, other experts are idle, and distributed training becomes imbalanced.

For a batch with tokens and experts, the ideal tokens per expert are:

Switch defines an expert capacity:

where is the capacity factor.

If expert receives more than tokens, extra tokens are usually dropped or bypassed depending on implementation. This introduces a real architectural tradeoff:

Capacity FactorEffect
low better memory/compute bound, more token drops
high fewer drops, worse load and memory overhead

Capacity factor is not a small engineering detail. It changes model quality, throughput, and training stability.

Load-Balancing Loss

The router needs pressure to use experts evenly. Let:

be the fraction of tokens routed to expert , and let:

be the average router probability assigned to expert .

A common Switch-style auxiliary objective is:

The goal is not to make every token equally likely for every expert. The goal is to discourage collapse where one expert dominates the batch.

The full training loss becomes:

For language modeling:

Why Top-1 Routing Matters

Top-2 routing gives each token two expert paths:

This can improve routing robustness, but it doubles expert computation and increases communication.

Top-1 routing uses:

This has several practical consequences:

  • fewer expert calls per token;
  • simpler combine/scatter logic;
  • lower communication volume;
  • easier scaling to many experts;
  • more sensitivity to routing mistakes.

The paper’s bet is that the simplicity is worth the reduced redundancy.

Where Sparsity Is and Is Not

Switch Transformer is sparse in the FFN path. It is not sparse everywhere.

BlockDense or SparseComment
token embeddingdenseevery token embedded
self-attentiondenseall tokens attend according to standard attention pattern
expert FFNsparseeach token uses one expert
residual streamdenseall tokens continue through shared layers
output headdensetask-dependent

This is why “trillion parameter model” does not mean every token touches a trillion parameters.

Scaling Interpretation

Dense scaling:

Sparse MoE scaling:

The useful metric is not just parameter count:

but also:

This is why Switch belongs in both architecture and systems discussions.

Communication Pattern

In distributed training, experts may be sharded across devices. Routing then requires token dispatch:

This creates all-to-all communication. A sparse expert layer can be compute-efficient but communication-heavy.

The real throughput depends on:

  • batch size;
  • sequence length;
  • number of experts;
  • expert placement;
  • network bandwidth;
  • capacity factor;
  • token dropping rate;
  • precision format;
  • implementation kernel quality.

This is the main reason MoE is an architecture-systems paper, not just a modeling paper.

Evidence Reading

The paper’s evidence is centered on language-model pretraining and transfer. The core result is that sparse expert capacity can improve scaling efficiency compared with dense T5-like baselines under the evaluated setup.

ClaimEvidence TypeWhat It SupportsCaveat
Top-1 routing can train wellcomparison to dense and sparse baselinesone-expert routing is viabletied to LM setup and routing details
Sparse models improve compute efficiencypretraining loss and transfer resultsmore parameters can help at similar active computenot equivalent to universal speedup
Very large parameter counts are trainabletrillion-parameter-scale experimentsconditional compute enables huge modelssystems stack matters
Load balancing is necessaryauxiliary loss and capacity designrouter collapse is a real failure modebalancing may fight specialization

Benchmark Card

FieldValue
Main task familylanguage-model pretraining and transfer
Architecture familysparse Mixture-of-Experts Transformer
Replaced componentTransformer FFN sublayer
Routingtop-1 expert choice
Main comparisondense T5-style Transformer baselines
Key metricspretraining loss, downstream task quality, speed, parameter count
Core hyperparametersnumber of experts , capacity factor , auxiliary loss weight
Not directly testeduniversal MoE behavior in all modalities or small-data regimes

Comparison to Dense Transformer

PropertyDense TransformerSwitch Transformer
FFN pathshared FFN for all tokensrouted expert FFN
Parameters used per tokenmost layer parametersone expert plus shared blocks
Total capacitytied to dense width/depthgrows with expert count
Routingnonelearned token-to-expert router
Main systems issuedense computedispatch, all-to-all, imbalance
Failure modeundercapacity or overcomputeexpert collapse, token drops, routing noise

Dense Transformers are simpler and often better for small/medium regimes. Switch becomes attractive when the system can support sparse routing and the workload benefits from large capacity.

Comparison to Earlier MoE

Earlier sparse MoE designs commonly used top-k routing, often top-2. Switch simplifies this to top-1.

DesignRoutingBenefitCost
Top-2 MoEtwo experts per tokenredundancy, smoother routingmore compute and communication
Switchone expert per tokensimpler, faster, easier scalingless routing redundancy

The paper’s contribution is not inventing MoE. It is showing that a simplified version can scale effectively.

Expert Specialization

A tempting interpretation is:

That is not guaranteed. Experts may specialize by:

  • token type;
  • language;
  • syntax;
  • frequency;
  • domain;
  • position;
  • optimization artifact;
  • hardware load pattern.

Router analysis is needed before making semantic claims about experts.

Failure Modes

Expert Collapse

If many tokens choose one expert:

for some expert , the model loses parallelism and effective capacity.

Token Dropping

If an expert exceeds capacity:

some tokens cannot be processed by that expert. This can degrade quality, especially if dropped tokens are not random.

Router Instability

The router is trained jointly with the model. Small changes in hidden states can change expert assignment:

can flip discontinuously. This makes optimization more delicate than a dense FFN.

Communication Bottleneck

If all-to-all communication dominates, sparse compute does not translate into wall-clock speedup.

Implementation Notes

Batch and Sequence Shape

For hidden states:

tokens are often flattened:

The router maps:

Assignments:

Then tokens are grouped by expert, processed, and scattered back to original order.

Precision

Sparse routing can be numerically sensitive. Router logits and probabilities may need more stable precision than the expert FFN path, depending on implementation.

Metrics to Log

For an MoE run, track:

  • expert load histogram;
  • token drop rate;
  • router entropy;
  • auxiliary loss;
  • per-expert throughput;
  • all-to-all communication time;
  • quality at fixed active FLOPs;
  • quality at fixed wall-clock time.

Without these metrics, parameter count claims are hard to interpret.

Molecular and Structural Modeling Reading

Switch-style MoE can be relevant outside language, but it should be treated carefully.

Possible uses:

  • route tokens by modality: protein, ligand, text, assay metadata;
  • route residues/atoms by local environment type;
  • allocate experts to different sequence families or structural regimes;
  • build large conditional-capacity models where only part of the model activates per example;
  • specialize experts for tasks such as scoring, generation, and refinement.

Risks:

  • small scientific datasets may not support many experts;
  • routing can learn dataset artifacts;
  • expert specialization can amplify data imbalance;
  • distributed MoE complexity may outweigh modeling benefit;
  • if the task needs geometric equivariance, MoE does not provide it by itself.

For structure-based modeling, MoE is usually a capacity/scaling mechanism, not the core inductive bias. It should complement graph, geometric, or sequence architecture choices rather than replace them.

Common Misreadings

”A trillion-parameter sparse model uses a trillion parameters per token.”

No. The model may have a huge total parameter count, but each token activates only a subset.

”MoE is just an ensemble.”

It is not a standard ensemble because experts are inside one model, trained jointly, and selected per token by a learned router.

”Top-1 routing is obviously worse than top-2.”

Top-2 has redundancy, but top-1 can win on simplicity, speed, and scaling. The tradeoff is empirical and systems-dependent.

”Load balancing means all experts learn the same thing.”

Load balancing encourages even usage. It does not force identical functions. In fact, useful MoE wants both balanced usage and meaningful specialization.

”Sparse compute removes systems bottlenecks.”

Sparse compute changes the bottlenecks. Communication, routing, and capacity management become central.

Later-Paper Checklist

When reading later MoE, routing, sparse scaling, or expert-model papers, ask:

  • Is routing top-1, top-2, top-k, hash-based, task-based, or learned?
  • What is the active parameter count per token?
  • What is the total parameter count?
  • Is quality compared at fixed FLOPs, fixed wall-clock, or fixed parameter count?
  • What is the token drop rate?
  • How is expert load balanced?
  • Does the paper report router entropy or load histograms?
  • Is the speedup measured end-to-end or only theoretical?
  • Does routing specialize semantically or only balance systems load?
  • What happens in small-data or domain-shift settings?

Why It Matters

Switch Transformer is a key architecture paper because it made sparse expert scaling feel operationally simple:

It is also a useful reminder that modern architecture is often inseparable from systems. The architectural idea only works if routing, dispatch, memory, and communication are handled well.

Limitations

  • Evidence is centered on language-model pretraining and transfer.
  • MoE benefits depend strongly on distributed systems implementation.
  • Expert routing introduces new failure modes.
  • Token dropping can make training behavior harder to reason about.
  • Parameter count can be misleading without active compute and throughput.
  • Sparse capacity may be unnecessary or harmful in small-data regimes.

Connections