Mixture-of-experts router
How a mixture-of-experts router really works: per-token, per-layer top-k with renormalised gates, expert capacity and dropped tokens, auxiliary-loss vs DeepSeek bias vs Expert Choice balancing, active vs total parameters of real models, experts touched per batch, and the all-to-all traffic of expert parallelism.
Added
How to use it
A mixture-of-experts (MoE) layer replaces one feed-forward network with many experts and a small router that sends each token to only a few of them. This tool takes the mechanism apart, one tab at a time. The router is a toy with random scores, so the tokens mean nothing, but every rule it follows is the real one.
How to use it
-
Router. Each row is a token and each column an expert. Every token’s router logits go through a softmax (or, as in DeepSeek-V3, a sigmoid per expert). The token keeps its top-k experts, and their scores are renormalised into gates that sum to 1. The layer’s output is the gated sum \$y = \sum g_i E_i(x)\$. Capacity factor sets each expert’s capacity at ⌊cf × T × k ÷ E⌋ token slots. Slots beyond it are dropped (red ✕). As in GShard, every token’s first choice is placed before any second choice. A token that loses every slot passes through on the residual connection only. Popularity skew makes some experts more attractive, which is how an unbalanced router behaves. Switch Routing to Expert choice and each expert picks its own top tokens instead: every expert is exactly full, but some tokens get nothing. The step-by-step panel works one token through logits → scores → top-k → gates. The table below it shows the same token at six layers: routing is decided again at every layer.
-
Load balancing. The same skewed router is trained for a number of steps, balancing only, four ways. None is the baseline. Auxiliary loss is Switch Transformer’s α·E·Σ fᵢ·Pᵢ, minimised by gradient descent on a per-expert logit offset. Bias balancing is DeepSeek-V3’s method: a per-expert bias is added to the score only when choosing the top-k, and nudged by ±γ after each step. Expert Choice is the fourth. The charts show the busiest expert’s load ÷ the mean, and the share of token slots dropped at the capacity factor you set. The table shows what each method did to the gate values. The auxiliary loss balances by bending the router’s probabilities, so it competes with the model’s real objective. The bias never changes a kept expert’s score.
-
Active vs total. Published MoE models with their experts computed from the configuration (hidden size d, expert width f, three d×f matrices per SwiGLU expert): routed experts, always-on shared experts, the rest (attention, embeddings, dense layers), and the parameters one token actually uses. Compute follows the active count, but memory must hold the total.
-
Experts touched. With uniform routing, B tokens use E × (1 − (1 − k/E)^B) of a layer’s E experts. Mixtral’s 8 experts are almost all busy by batch 16. DeepSeek-V3 needs about 22 tokens to touch half of its 256. Add draft tokens to see why speculative decoding helps an MoE less (Section 33 of the book). Verifying γ drafts per sequence sends B × (γ + 1) tokens through the layer, and at small batch those extra tokens pull in experts that plain decoding would never read. The speed-up counts weight bytes only, which is what bounds a decode step.
-
All-to-all. Under expert parallelism every MoE layer runs two all-to-alls. Dispatch sends each token’s hidden vector to the GPUs holding its k experts. Combine brings the outputs back to the token’s home GPU. The tab gives bytes per token, per GPU per layer, and per forward step, split between NVLink and the network, and a bandwidth-only time. Network copies: once per node models DeepSeek-V3’s scheme. A token crosses the network once per node it needs and is fanned out over NVLink on arrival. Max nodes per token caps those nodes (DeepSeek-V3 uses 4).
Limits
-
The router is a toy: logits are random normals plus a fixed per-expert popularity, not a trained model’s hidden states. Real routing is skewed and correlated, so tokens next to each other share experts more often than here. Experts touched and all-to-all assume uniform, independent routing, which is the most scattered case.
-
The balancing simulation trains only the balancing, with no language-modelling loss to trade against. Its learning rates and γ are in the toy’s units. DeepSeek-V3’s γ = 0.001 acts on its own sigmoid scores.
-
Bandwidth-only all-to-all times ignore latency, congestion, and the overlap with computation that production systems (DeepSeek’s DualPipe, for example) rely on.
-
Active counts computed from the configuration differ slightly from the published ones. The remainder ("other") absorbs attention, embeddings, norms and biases. OpenAI’s gpt-oss active counts leave out the embedding table.
Sources
| Model | Total | Active | Experts | Per token | Source (as of October 2026) |
|---|---|---|---|---|---|
Mixtral 8x7B |
46.7 B |
12.9 B |
8 |
2 |
Mistral AI, Mixtral of experts (2023); Jiang et al., arXiv:2401.04088 |
DeepSeek-V3 |
671 B |
37 B |
256 + 1 shared |
8 |
DeepSeek-AI, DeepSeek-V3 Technical Report (sigmoid gating, auxiliary-loss-free bias balancing with γ = 0.001, node-limited routing to 4 nodes, FP8 dispatch and BF16 combine) |
gpt-oss-120b |
116.8 B |
5.13 B |
128, no shared |
4 |
OpenAI, gpt-oss-120b & gpt-oss-20b model card (Table 1) |
gpt-oss-20b |
20.9 B |
3.61 B |
32, no shared |
4 |
the same |
Llama 4 Maverick |
400 B |
17 B |
128 + 1 shared |
1 |
Meta, The Llama 4 herd (2025), MoE in every other layer |
Llama 4 Scout |
109 B |
17 B |
16 + 1 shared |
1 |
the same |
Qwen3-235B-A22B |
235 B |
22 B |
128 |
8 |
Qwen Team, Qwen3 Technical Report |
Switch-C |
1,571 B |
— |
2,048 |
1 |
Fedus, Zoph & Shazeer, Switch Transformers (capacity factor, auxiliary loss α = 0.01) |
-
Lepikhin et al., GShard (2020): top-2 routing, expert capacity, and first choices placed before second choices.
-
Zhou et al., Mixture-of-Experts with Expert Choice Routing (2022).
-
Leviathan, Kalman & Matias, Fast Inference from Transformers via Speculative Decoding (2023): expected tokens per verification (1 − αγ+1) ÷ (1 − α).
-
Link speeds: NVIDIA H100 (NVLink 900 GB/s bidirectional, 450 GB/s each way) and GB200 NVL72 (1.8 TB/s per GPU), ConnectX-7 (400 Gb/s InfiniBand NDR) and ConnectX-8 (800 Gb/s XDR); the DeepSeek-V3 report’s measured 160 GB/s NVLink and 50 GB/s InfiniBand on H800. Every one is listed with its source on the All-to-all tab.
Related: AI hardware calculator (MoE memory and decode speed), floating-point inspector (FP8 dispatch, MXFP4 experts), ML maths (softmax and attention).
Companion to the Mixture-of-Experts section of _AI Acceleration: From Transistors to Trillion-Parameter Models.
Linking to an example
Links can be written by hand. Put the tab after #: router, balance, params, touched
or alltoall. Numbers are plain decimals (0.002, not 2e-3 with a `). In a URL ` means a
space, so a value never needs one.
| Parameter | Meaning | Example |
|---|---|---|
|
Router: number of experts (2–64) |
|
|
Router: experts per token |
|
|
Router: tokens in the batch (1–128) |
|
|
Router: capacity factor |
|
|
Router: popularity skew (0 = even) |
|
|
Router: random seed |
|
|
|
|
|
Renormalise the gates over the top-k ( |
|
|
|
|
|
The token worked step by step (from 0) |
|
|
Load balancing: experts, experts per token, tokens per step, steps |
|
|
Load balancing: popularity skew and seed |
|
|
Auxiliary-loss strength (learning rate × α) |
|
|
Bias step γ |
|
|
Capacity factor for the dropped share |
|
|
|
|
|
Experts touched: batch (sequences) |
|
|
Draft tokens γ per sequence (0 = plain decode) |
|
|
Acceptance rate α |
|
|
Bytes per weight |
|
|
All-to-all: expert-parallel GPUs |
|
|
GPUs per NVLink domain |
|
|
Tokens per GPU per step |
|
|
Bytes per value for dispatch and combine |
|
|
Send once per node ( |
|
|
Max nodes per token (0 = no limit) |
|
|
|
|
|
|
|
|
One of the presets below; parameters given with it override the preset’s |
|
Presets:
example= |
Shows |
|---|---|
|
Mixtral-style routing: 16 tokens, each to 2 of 8 experts, softmax gates renormalised over the two (open) |
|
Routing is per token and per layer: neighbouring tokens pick different experts, and one token’s experts change from layer to layer (open) |
|
A skewed router at capacity factor 1.0: popular experts overflow and token slots are dropped (open) |
|
Expert Choice on the same scores: every expert full, some tokens chosen by none (open) |
|
DeepSeek-V3-style gating: sigmoid scores, top-k, renormalised (open) |
|
No balancing vs auxiliary loss vs DeepSeek-V3’s bias vs Expert Choice over 200 steps (open) |
|
Mixtral 8x7B: 46.7 B total, 12.9 B active (open) |
|
DeepSeek-V3: 671 B total, 37 B active (open) |
|
gpt-oss-120b: 4 of 128 experts and no shared expert (open) |
|
A decode batch of 16 touches nearly all of Mixtral’s experts (open) |
|
Speculative decoding on DeepSeek-V3 at batch 1: drafts scatter across experts and most of the gain is lost (open) |
|
DeepSeek-V3’s training layout: EP 64 over 8 nodes, FP8 dispatch, BF16 combine, at most 4 nodes per token (open) |
|
The same dispatch and combine inside one NVL72 NVLink domain (open) |
For example ?e=16&k=4&gate=sigmoid&skew=1#router
routes 16 tokens to 4 of 16 experts with sigmoid gates and a skewed router.
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.