Volume VII · A Committee of Specialists
A Committee of Specialists
A hospital employs a thousand specialists and sends no patient past all of them. A triage desk reads the chart, picks two, and the patient sees two. The payroll covers a thousand people; each visit costs two consultations. A mixture-of-experts model is that hospital, and the triage desk is the part that is hard to train.
The mental model
A mixture-of-experts layer separates how much a model holds from how much it computes. A small router sends each token to a few of many feed-forward experts: every parameter is paid for in memory, and only the chosen few are paid for in arithmetic. The price is a router that must be forced to share the work.
The block that is two-thirds feed-forward
Fourteen lectures went into attention, and attention is the smaller half of a transformer block. In the classic layout the feed-forward network expands the hidden width d to 4d and projects back, which costs 2 × d × 4d = 8d² parameters. The four attention projections cost 4d². So roughly two thirds of a block's weights live in the feed-forward network, and that is the part a mixture of experts replaces.
The replacement is mechanical. Keep attention exactly as it is, shared by every token. Take the single feed-forward network and make E copies of it, each with its own weights and each called an expert. Add a router, a small learned layer that looks at the token and decides which experts it visits. The block still has one input and one output; in between, the token passes through k experts instead of one network.
A router is one matrix and a top-k
The router is as small as a layer can be. For a token with hidden vector x of width d, it multiplies by a matrix Wr of shape d × E, which yields one score per expert. Keep the k highest, weight them, and add up what those experts return.
Take eight experts and k = 2, which is Mixtral's setting. Suppose the router scores one token as 2.1, 1.5, 0.4, −0.3 and four lower values. Experts 1 and 2 survive. The softmax is taken over those two scores alone: e2.1 ≈ 8.17 and e1.5 ≈ 4.48, so the weights are 0.65 and 0.35. The layer's output is 0.65 times the first expert's answer plus 0.35 times the second's. The six other experts contribute nothing and cost nothing.
The router's own cost is negligible. At Mixtral's hidden width of 4,096 and eight experts, Wr holds 4,096 × 8 ≈ 33 thousand numbers per layer, against the hundreds of millions in the experts it chooses between. One small matrix decides where hundreds of millions of parameters get spent.
The idea of letting a gating network divide labour among sub-networks is older than deep learning: Jacobs, Jordan, Nowlan and Hinton described adaptive mixtures of local experts in 1991. What made it a language-model technique was scale. Shazeer and colleagues, in 2017, put a sparsely-gated layer with up to thousands of experts between the layers of an LSTM and reported models of up to 137 billion parameters — more than a thousandfold the capacity of the baselines at comparable computation. Their router added tunable noise to the scores before taking the top k, to keep experts from settling into a rut; the problem that noise was fighting is the subject of § 15.5.
Pay for the parameters, compute with a few
Here is the whole attraction in one pair of formulas. Writing Pattn for the parameters that every token uses and Pffn for one expert:
Total parameters set how much the model can store. Active parameters set how much arithmetic each token costs. In a dense model the two are the same number. Here they separate, and the gap is a free choice of E and k.
Mixtral 8x7B makes the gap concrete. Mistral's January 2024 paper reports 46.7 billion total parameters and 12.9 billion active per token. The name is misleading: eight experts of seven billion would be 56 billion, but only the feed-forward networks are replicated. The published dimensions let you rebuild the totals. Each of 32 layers has a hidden width of 4,096 and an expert hidden width of 14,336, and each gated expert holds three matrices: 3 × 4,096 × 14,336 ≈ 176 million parameters.
| Quantity | Arithmetic | Result |
|---|---|---|
| One expert | 3 × 4,096 × 14,336 | ≈ 176M |
| All experts | 32 layers × 8 experts × 176M | ≈ 45.1B of 46.7B total |
| Experts that run | 32 layers × 2 experts × 176M | ≈ 11.3B |
| Everything else | attention, embeddings, norms, routers | ≈ 1.6B, paid by every token |
| Active per token | 11.3B + 1.6B | ≈ 12.9B, matching the paper |
The experts are 97% of the weights, and a quarter of them run. That is the trade the model card states: compute near a 13-billion-parameter dense model, with the capacity of a much larger one. The paper reports quality at or above Llama 2 70B on most benchmarks, at a fraction of the per-token arithmetic.
Switch: one expert is enough
The 2017 recipe sent every token to at least two experts, on the belief that a router only learns if it can compare experts for the same token. In 2021 Fedus, Zoph and Shazeer published the Switch Transformer, which sets k = 1 and gets the router's gradient from the single gate value alone. The simplification is real: half the expert compute per token, no combining step, and less communication when experts live on different devices. The paper reports up to a sevenfold pre-training speedup over a dense T5 baseline at equal computation, and trained models up to 1.6 trillion parameters.
Switch also introduced the knob that makes the next section matter. Experts live on different accelerators, and a tensor must have a fixed shape, so each expert gets a fixed capacity: the number of tokens per batch divided by the number of experts, times a capacity factor slightly above one. A token routed to an expert that is already full is dropped — it skips the layer and rides the residual connection to the next one. A dropped token is not lost, but it did not get the computation the router wanted for it.
Fedus and colleagues also recorded the stabilisers that kept a trillion-parameter sparse model training: run the router's softmax in 32-bit floats even when everything else is in lower precision, initialise with a smaller scale, and regularise the experts. The follow-up ST-MoE paper added a penalty on the size of the router's logits, the router z-loss, because large logits make the softmax unstable. Routers are the numerically delicate part of a model whose bulk is numerically tame.
Why routers collapse
Start all E experts from random weights and the router from random weights. At step zero the router's choices are nearly arbitrary. Some expert, by luck, receives slightly more tokens than the others. It trains on more data, so it improves faster. The router, which is rewarded for sending tokens to whichever expert lowers the loss, sends it more. The loop closes in a few thousand steps.
That is expert collapse, and it has three costs. The starved experts are dead weight: the model paid for parameters it will never use, which defeats the purpose of buying capacity. The favoured experts overflow and drop tokens. And on a cluster where each expert sits on its own device, the slowest, most overloaded device sets the pace of the whole step, so imbalance is a hardware problem as well as a modelling one.
The standard remedy is an auxiliary load-balancing loss, added to the language-modelling loss. Switch's version is compact. For one layer and a batch, let fi be the fraction of tokens actually dispatched to expert i and Pi the mean router probability assigned to it:
Read its range. If routing is uniform, fi = Pi = 1/N, the sum is N · (1/N)² = 1/N, and the loss is α whatever N is — the factor of N exists to make the floor independent of expert count. If routing collapses onto one expert, f and P are both one-hot, the sum is 1, and the loss is αN. A worked case with four experts: dispatch fractions (0.7, 0.1, 0.1, 0.1) and mean probabilities (0.6, 0.2, 0.1, 0.1) give Σ fP = 0.46, so the loss is 4 × 0.46 = 1.84 α, against 1.00 α balanced and 4.00 α collapsed.
Why use both f and P? The dispatch fraction fi is a count of argmax decisions, so it has no gradient. The probability Pi is smooth. The gradient of the loss with respect to Pi is therefore αN · fi: the busier an expert already is, the harder its router probability is pushed down. The loss is a thermostat built from one measured quantity and one differentiable one.
There is a second design that guarantees balance by construction. In Expert Choice routing (Zhou et al., 2022) the experts choose their tokens instead of tokens choosing experts: each expert takes its top-scoring tokens from the batch, up to a fixed budget, so no expert is ever overloaded. The usual objection is that an expert picking from a whole batch looks at positions a generating model has not produced yet, which sits badly with left-to-right decoding. The production models in this lecture and the next route token-first.
What Mixtral's experts turned out to know
The committee metaphor invites a wrong picture: a biology expert, a law expert, a code
expert. Mixtral's authors looked for it and did not find it. They measured which experts
handled text from different domains, including scientific papers, biomedical abstracts and
philosophy, and reported no obvious pattern by topic. What they did find was structure at
the level of syntax: the same expert tended to handle a particular token such as the Python
keyword self, and adjacent tokens were routed to the same experts more often
than chance would predict.
Specialist is a loose word
An expert is a feed-forward network that the router happened to send a certain kind of token to, and "kind" can be as low-level as a token's grammatical role. Nothing in the training objective asks for subject-matter experts, and Mixtral's routing analysis suggests none appeared. The committee is useful for the budget argument. It is a poor guide to what any one member knows. Whether a different design can make specialisation sharper is the first question of the next lecture.
Two problems remain with the Mixtral design, and both come from there being only eight experts. With two chosen out of eight, a token has just 28 possible expert pairings, which is a coarse menu. And whatever knowledge every token needs — basic syntax, common words — has no home of its own, so it is learned again inside several experts. The next lecture takes the opposite approach to both: more experts, each smaller, and a few kept aside for everyone.
| Work | Where the experts sit | Routing | Note |
|---|---|---|---|
| Shazeer et al. (2017) | Between LSTM layers | Noisy top-k | Up to 137B parameters; added balancing losses on importance and load |
| GShard (2020) | Transformer FFN, in alternate layers | Top-2, with capacity limits | A 600B-parameter translation model, sharded by expert |
| Switch Transformer (2021) | Transformer FFN | Top-1 | Up to 1.6T parameters; the f·P auxiliary loss |
| Mixtral 8x7B (2024) | Every FFN | Top-2 of 8 | 46.7B total, 12.9B active; open weights |
Read the primary source
- Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer — Shazeer et al., 2017.
- GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding — Lepikhin et al., 2020.
- Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity — Fedus, Zoph, Shazeer, 2021.
- ST-MoE: Designing Stable and Transferable Sparse Expert Models — Zoph et al., 2022.
- Mixture-of-Experts with Expert Choice Routing — Zhou et al., 2022.
- Mixtral of Experts — Mistral AI, 2024.