A bigger feedforward layer usually means a slower one — every token has to pass through every parameter. What if a model could have dozens of feedforward blocks, each specialized, and every token only ever paid the cost of the two or so that actually matter for it?
Four small experts, one router. Pick a token and watch which two experts light up — the other two contribute nothing to the output and never even get evaluated.
A mixture-of-experts layer replaces one feedforward block with of them plus a router. The router scores every expert, keeps only the top , renormalizes their scores to sum to 1, and combines just those:
- — the mixture-of-experts layer's output for this input.
- — the input token or vector being routed.
- — the number of experts kept per token (top- routing).
- — the router's raw score for each expert, given input .
- — the router's (softmax) score for expert , before renormalizing over just the selected top-.
- — indices ranging over experts, restricted to the top- selected ones.
- — the output of the -th expert sub-network applied to .
- Unselected experts aren't down-weighted — they're never run
Every expert outside the top contributes exactly zero — not a small weight, but literally never computed.
- Total capacity and per-token compute decouple
A model can have far more total parameters than a dense one while running only a fraction of them per token.
Token and token activate completely disjoint pairs of experts — zero overlap. Each token gets routed to whichever specialists the router thinks fit it best, and the rest of the model, for that token, might as well not exist.
Four experts, router weights , top-2 routing:
- Token x=2 routes to experts 2 and 0
Router logits: . Softmax, subtracting the max logit () for stability:
- Sum
- Full probabilities:
- expert 0
- expert 1
- expert 2
- expert 3
Top-2 are expert 2 () and expert 0 (), summing to . Renormalizing:
- for expert 2
- for expert 0
Experts 1 and 3 are never evaluated.
- The combined output blends only the selected two
Expert 2's output is , expert 0's is . Combined: — a weighted blend of exactly two specialists, not all four.
- A different token activates a disjoint pair entirely
Token flips every router logit's sign, routing instead to experts 3 and 1 — the exact two experts that sat idle for . Same router, same experts, completely different active subset.
Find the token, among the three candidates, that routes to expert 1.
Mixture-of-experts decouples a model's total parameter count from its per-token compute cost: adding more experts adds capacity, but as long as stays fixed, every token still only touches of them. That's the entire mechanism behind how modern large language models scale to hundreds of billions of parameters while keeping inference cost close to a much smaller dense model's. The next chapter asks the question this raises directly: given a compute budget, how should it actually be spent — more parameters, or more data?