← Explainer Library

Interactive Explainer

Mixture of Experts, Live

Four linear experts and a softmax gate, trained jointly in your browser on a piecewise 2-D regression. Watch the gate carve the input plane into four regions, the experts specialise inside their regions, and the load-balancing auxiliary loss wake up dead experts. Toggle soft mixture vs top-1 hard routing.

Prelude

Why MoE

A single dense network has to learn one function for every input. As models grow, more parameters means more compute on every forward pass — the cost of capacity scales linearly with capacity itself.

Mixture of Experts decouples them. You have $E$ expert networks and a small gating network. For each input, the gate picks one or two experts; only those run. A model can have 8× the parameters of a dense counterpart but cost roughly 1× the compute — provided routing is sparse.

The slogan. MoE pays for parameters in memory, not in flops. As of 2026 every frontier-scale model (GPT-OSS, Mixtral, DeepSeek-V3, Llama-MoE) is some flavour of MoE.
Step 1

The model in one line

Each expert $f_e$ is a function (we use linear: $f_e(x) = w_e^\top x + b_e$). The gate $g(x) \in \Delta^E$ is a softmax over $E$ logits. The model output is a weighted mixture; the gradient flows into both the experts (where they were used) and the gate (which gets a signal pushing it toward better routings).

Hard top-1 routing replaces the soft mixture with $\hat e = \arg\max g_e(x)$ — only one expert runs per input. We use a straight-through gradient so the gate still learns.

Step 2

Train it live

The toy task: a 2-D plane carved into four quadrants, each with a different linear truth function. A single linear model can't fit it; four linear experts plus a gate can.

step 0 MSE
Gating regions (one colour per expert)
Per-expert prediction error
Loss curve + expert utilisation
What to watch for. With soft mixture + no balance loss the gate sometimes collapses onto a single expert (dead expert problem). Turn on load-balance and the balance term penalises uneven utilisation; the four-way split usually appears within ~150 steps. Switch to top-1 for the Switch-Transformer-style routing — Voronoi-like region boundaries appear instead of a smooth softmax mixture.
Step 3

The auxiliary load-balance loss

Without intervention the gate has every reason to collapse: the easiest local minimum is "always pick expert 1". The auxiliary loss pushes the gate toward uniform utilisation:

$f_e$ is the fraction of tokens routed to expert $e$ and $P_e$ is the average gate probability for expert $e$ over the batch. The product is minimised when both are uniform ($1/E$). The Switch Transformer paper introduced this exact form and it's what every modern MoE uses.

Step 4

What scales, what hurts, what production looks like

Step 5

Where MoE shows up beyond LLMs

Final takeaway. MoE is the cheapest way to give a model more "knowledge" per parameter. As long as routing is sparse and balancing is in place, you get capacity without flops. Once you have it, dense scaling looks wasteful.
Step 6

Expert parallelism — the systems story

Past ~1B parameters per expert, you can't fit all experts on one GPU. The standard sharding pattern (Lepikhin et al., 2020):

The all-to-all is what makes MoE training systems hard. Frameworks: GShard, Tutel, Megablocks, DeepSpeed-MoE.

Step 7

Frontier MoE comparison

ModelTotal paramsActive / token# expertsTop-kNotable trick
Switch Transformer (2021)up to 1.6T~1/Eup to 20481Aux load-balance loss; expert capacity
GLaM (2021)1.2T97B642Routing balance via aux loss; sparsity at training
Mixtral 8×7B (2023)47B13B82Open-weight; outperforms Llama-2 70B
DeepSeek-V3 (2024)671B37B256 + 1 shared8Aux-loss-free balancing via per-expert bias
Mixtral 8×22B (2024)141B39B82Same architecture, scaled experts
Qwen2-MoE A14B (2024)57B14B64 + 4 shared4Shared experts always active
Step 8

Reading list