Skip to content
DAH
Wiki/ArchitecturesAlgorithmActive

Mixture-of-experts routing

Sparse transformer layers send each token to a few of many expert networks, decoupling parameter count from per-token compute; the router and its load balancing decide whether the experts are actually used.

On this page14 sections
Why other work relies on it

Several of the largest open language models (for example DeepSeek-V3) are mixture-of-experts models, so routing and load balancing set their training stability and serving cost.

A model made of many specialist sub-networks, where each word is sent to only a few of them.

  1. 1Many experts, small router
  2. 2Each token goes to top-k experts
  3. 3Load collapses without balancing
  4. 4Balance by loss, capacity or bias

What it is for. In a transformer language model most of the arithmetic sits in the feed-forward sub-layer of each block: two large matrix multiplications applied to every token (a token is a word piece, represented as a vector). Making the model "know more" usually means making these matrices bigger, and the cost per token grows with them. A mixture-of-experts (MoE) layer breaks that link: it keeps many smaller feed-forward networks, called experts, and sends each token through only a few of them.

An analogy. Think of a hospital with 64 specialists and a triage nurse. Each patient sees only the two most relevant specialists, so the hospital's total expertise grows with the number of specialists while each visit costs the same. The analogy breaks in one important way: the nurse (the router) and the specialists are trained together from scratch, so nobody decides in advance what each expert is for.

The mechanism. The router is a small matrix WrW_r. For a token vector xx it computes one score per expert, s=Wrxs = W_r x, turns the scores into positive weights that add to one with the softmax function (pi=esi/∑jesjp_i = e^{s_i} / \sum_j e^{s_j}, which exaggerates the largest scores), keeps the top kk experts, and outputs

y=∑i∈top-kpi Ei(x),y = \sum_{i \in \text{top-}k} p_i \, E_i(x),

the weighted sum of the chosen experts' outputs Ei(x)E_i(x). With 64 experts and k=2k = 2, the layer holds 64 experts' worth of parameters but each token pays for only 2.

The hard part: load balance. Training nudges the router toward experts that already help, so a few experts can end up taking almost every token while the rest stay untrained. When experts live on different GPUs, the busiest one also makes every other GPU wait. Three families of fixes exist:

  • an auxiliary loss, an extra penalty added to the training error that grows when the load is uneven; it works but pulls the model away from its real objective;
  • expert-choice routing, where each expert picks its tokens, so loads are equal by construction;
  • auxiliary-loss-free balancing, used in DeepSeek-V3: add a per-expert bias to the scores and nudge it up for under-used experts and down for over-used ones, like a thermostat.

Costs and open questions. Moving tokens to experts on other GPUs needs all-to-all communication, and each expert gets a different number of tokens, which needs special matrix-multiply kernels. Which balancing method is best for the largest models is not settled in public: the controlled comparisons were run on models of a few billion parameters, and large technical reports describe one choice without a side-by-side test. How to scale the number and size of experts with the compute budget is studied by MoE scaling laws.

Go deeper

The full technical text.

The idea

In a mixture-of-experts (MoE) transformer, the feed-forward sub-layer of a block is replaced by many parallel feed-forward networks (experts) plus a small router. For each token the router scores all experts and sends the token to the top-k of them (k is typically 1 to 8); the outputs are combined with the router weights. Total parameters grow with the number of experts, but per-token compute grows only with k. Shazeer et al. (2017) introduced the sparsely-gated layer for recurrent networks; GShard (2020) and the Switch Transformer (2021) brought it to transformers, with Switch simplifying routing to a single expert per token.

The load-balancing problem

A learned router tends to collapse onto a few favoured experts, leaving others untrained and creating stragglers when experts live on different devices. The classic fix is an auxiliary loss that penalises uneven expert load, plus a capacity factor that drops tokens beyond an expert's buffer. The auxiliary loss adds gradients unrelated to the language-modelling objective, so its weight trades balance against quality. Alternatives include expert-choice routing (experts pick tokens, so load is balanced by construction; Zhou et al., 2022), fine-grained and shared experts (DeepSeekMoE, 2024), and auxiliary-loss-free balancing (Wang et al., 2024), which adds a per-expert bias to the routing scores, adjusted from recent load, and was used in DeepSeek-V3.

Systems side

MoE layers need all-to-all communication to move tokens to experts and variable-sized matrix multiplications per expert. Block-sparse and grouped GEMM kernels (for example MegaBlocks) avoid dropping tokens and padding.

Open questions

Which balancing method is best at frontier scale is not settled independently: the controlled comparisons at 15.7B and 228.7B total parameters are the DeepSeek-V3 authors' own ablations, without released logs, and a 2025 report on an extremely sparse 20B model (Sigma-MoE-Tiny, one of 96 experts active) found the standard balancing loss ineffective in lower layers. Scaling-law work for MoE (Clark et al., 2022; Krajewski et al., 2024) models how the number and granularity of experts change the compute-optimal model size, and hyperparameter transfer rules for MoE are an active topic (see the μP entry).

Words on this page (10)
Words on this page
mixture of experts
A network with many specialist sub-networks where each token is sent to only a few of them.
router
The small part of a mixture-of-experts model that chooses which experts handle each token.
transformer
The neural-network design behind modern chatbots, in which every word looks at every other word through attention.
parameter
One of the adjustable numbers inside a model. Large language models have billions of them.
loss
A single number measuring how wrong the model is on the training or test text. Lower is better.
GPU
A chip with thousands of small cores, used to train and run neural networks quickly.
token
A chunk of text, often a word or part of a word, that a language model reads as one unit.
softmax
A function that turns a list of scores into positive weights summing to one, giving most weight to the largest scores.
load balancing
Spreading work evenly across workers or machines so none sits idle while another is overloaded.
feed-forward network
Here, the two matrix multiplications with a nonlinearity between them that each transformer block applies to every token separately.
New to this? Read first (3)
New to this? Read first

Understanding map

map of the whole wiki →

What to read before Mixture-of-experts routing (left), and what builds on it: entries that depend on it and its open problems (right). Every box links to its page.

  1. Start with
  2. Step 2
  3. Step 3
  4. Then

Open problems & questions

Progress timeline

  1. Dec 27, 2024
    DeepSeek-V3 technical report

    A large MoE model trained with auxiliary-loss-free balancing is described in a technical report (preprint).

    source
  2. Aug 28, 2024
    Auxiliary-loss-free balancing proposed

    Wang et al. balance load by adjusting a per-expert routing bias instead of adding a loss term; tested up to 3B parameters and 200B tokens (preprint).

    source
  3. Aug 28, 2024
    Method proposed
    Related to: Does auxiliary-loss-free balancing beat auxiliary-loss routing at 20B+ total parameters?

    Reported gains over auxiliary-loss balancing up to 3B parameters and 200B tokens.

    source
  4. Feb 18, 2022
    Expert-choice routing

    Zhou et al. let experts select tokens so that load is balanced by construction.

    source
  5. Jan 11, 2021
    Switch Transformer

    Fedus, Zoph and Shazeer simplify routing to one expert per token and train sparse models with up to a trillion parameters.

    source
  6. Jan 23, 2017
    Sparsely-gated MoE layer

    Shazeer et al. report a layer with up to thousands of experts and a trainable gating network, increasing capacity without proportional compute.

    source