Eduspheria Wiki
Core9 min read

Mixture of Experts

Why frontier models pay for parameters only when they're used — routing, top-k experts, and the load-balancing game.

Every transformer so far was dense: every token flows through every parameter. MoE (mixture of experts) changes one thing — the block's MLP is replaced by several parallel MLPs (experts) plus a tiny router that picks which ones actually process each token. Capacity grows with the number of experts; per-token compute does not.

Start here

A dense model is one huge kitchen where every ingredient passes through every station. An MoE model is a food court: a greeter (the router) sends each dish to one or two relevant stalls. You can build forty stalls — cost only rises for the dishes actually routed.

The routing step

For each token, a small linear layer produces one logit per expert, and the top-kk experts are selected:

router(x)=top-k(softmax(Wrx))\text{router}(x) = \text{top-}k\big(\text{softmax}(W_r x)\big)

The token is then processed by only those experts' FFNs, and their outputs are blended (weighted by router probability). With kk a small fraction of the expert pool (Mixtral: 2 of 8; DeepSeek-V3: 8 of 256), per-token FLOPs stay a small fraction of the dense equivalent while total parameters grow linearly with experts. This decoupling — parameters ≠ FLOPs — is the entire commercial point: MoE models buy capacity they serve cheaply.

Watch it work:

The router sends each token to the expert(s) that process it best

The
syntax82%
entities5%
actions10%
time3%
cat
syntax6%
entities88%
actions3%
time3%
chased
syntax6%
entities5%
actions77%
time12%
the
syntax88%
entities6%
actions3%
time3%
mouse
syntax3%
entities86%
actions8%
time3%
yesterday
syntax2%
entities7%
actions6%
time85%
.
syntax77%dropped
entities12%
actions6%
time5%

Each expert caps how many tokens it accepts (the "expert capacity" knob). Overflow tokens are dropped — routed through a residual path with no expert processing, which is exactly the failure mode a load-balancing loss exists to prevent. Scores are heuristic; a real router is learned and self-organizes its experts.

Things to try in the artifact: switch top-1 → top-2 (quality knob — more expert perspectives per token, more FLOPs); then drop expert capacity to ×1 and watch tokens get dropped — routed to no expert at all, processed only by the residual path. Dropped tokens are why the loss has a second term.

The load-balancing problem

Left alone, routers collapse: one expert gets slightly better early and wins everything, the others starve and never train. Two standard fixes, usually used together:

L=LCE+αne=1nfePe\mathcal{L} = \mathcal{L}_{\text{CE}} + \alpha \cdot n\sum_{e=1}^{n} f_e \, P_e

where fef_e is the fraction of tokens that landed on expert ee and PeP_e the mean router probability for it. The product is minimized when traffic is spread evenly — an anti-concentration penalty, the opposite spirit of most losses. Router z-losses (computed in fp32 to keep the logits numerically tame) patch the remaining instability.

Careful

MoE is not free lunch. All experts sit in GPU memory whether or not they run (capacity without FLOPs still costs RAM); training is harder to keep stable; fine-tuning is more finicky; and the "experts" are not human-legible specialists — analysis finds them splitting by token/syntax patterns, not "the biology expert". You trade engineering complexity for a better params-per-FLOP ratio.

Who actually ships MoE

ModelExpertsActive per tokenNote
Mixtral 8×7B82~47B params, ~13B active
DeepSeek-V3256 + 1 shared8~671B params, ~37B active
GPT-4 (reported)8–162never officially confirmed
Llama 416–128 (varies)variesMoE across the lineup

One shared "always-on" expert plus routed experts is the modern pattern — common operations don't need routing overhead at all.

Next: the other half of every block — positions and normalization.

This lesson has exercises attached — predicting where a token routes and diagnosing an expert-collapse scenario — once the exercises layer ships.