Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

LABS · 18  /  ARCHITECTURE

The Switchboard.

A trillion-parameter model that runs like a small one? The trick is a switchboard. Instead of pushing every token through every weight, a router sends each token to just a few of many experts — so the model stores a giant and pays for a sliver. Route the tokens, overload an expert, then balance the load.

Act 1 · The router picks
Each token, a few experts
The router scores every expert for the incoming token and picks the top-k (here 2 of 8). Only those experts run; the rest stay dark. Send tokens through and watch the switchboard light up — different tokens, different experts.
0
Tokens routed
2 / 8
Experts active / token
25%
Compute used / token
Two of eight experts run per token — so this layer does a quarter of the work a dense layer would, while holding 8 experts' worth of knowledge. Scale "8" to "256" and the sparsity gets dramatic.
Act 2 · Capacity vs compute
Store a giant, pay for a sliver
MoE decouples two numbers that are locked together in dense models: total parameters (the knowledge you store) and active parameters (the compute you pay per token). Slide the expert count and top-k, and watch them diverge.
Experts64
Top-k (experts per token)8
— B
Total parameters
stored in VRAM
— B
Active / token
compute + speed
—×
Sparsity ratio
This is the whole pitch. DeepSeek-V3 stores 671B parameters but activates ~37B per token — frontier knowledge at mid-model compute cost. Fine-grained MoE (many small experts) pushes the ratio further.
Act 3 · The failure mode
One expert does all the work
Left alone, the router plays favorites — a few experts get flooded while others sit idle and never learn. That's wasted capacity and a system bottleneck. Send a burst with balancing off to watch it collapse, then switch it on.
—
Busiest expert load
—
Idle experts
—
Imbalance (CV)
lower = more even
Balancing off: traffic piles onto favorites, the rest starve. On: tokens spread evenly, every expert learns and the busy one stops being a bottleneck. DeepSeek-V3 does this loss-free — a per-expert routing bias, no tax on the training objective.

Why sparse beats dense — for the money

In a dense transformer, every token flows through every parameter. Doubling the model doubles both its knowledge and the cost of every token — capacity and compute are welded together. Mixture-of-experts breaks the weld.

Replace one big feed-forward block with many parallel experts and a small router. For each token, the router scores the experts and activates only the top-k — the rest never run. So you can pile on experts to grow total capacity, while per-token compute stays pinned to just the k that fire. Store a giant; pay for a sliver.

Active vs total — the number that confuses everyone

Total parameters set memory (every expert sits in VRAM). Active parameters set speed and cost (only the shared layers plus the chosen experts run). DeepSeek-V3: 671B total, ~37B active. When a spec sheet quotes both, this is why.

The catch: balance

Sparsity's dark side is load imbalance. Routers naturally collapse onto a few favorite experts — those overload while others atrophy, wasting the capacity you paid for and jamming the GPUs that host the hot experts. The classic fix was an auxiliary loss penalizing imbalance, but it fights the main objective (you pay quality for balance). DeepSeek-V3's answer is loss-free: a per-expert bias used only for routing, nudged up for underused experts and down for overloaded ones — balance from a feedback controller, not a tax.

Why it's everywhere now

Scaling laws want bigger models; budgets don't want bigger bills. MoE resolves the tension, so several frontier open models — DeepSeek-V3, Kimi K2, Mixtral — are sparse. Fine-grained MoE (many small experts, higher top-k) refines the same idea, and the MoE paper traces the lineage.

The picture: one token through the switchboard

token x routerz = W·xsoftmaxkeep top-2 E1 46.6% runs E2 28.3% runs E3 10.4% idle E4 6.3% idle E5 3.8% idle E6 2.3% idle E7 1.4% idle E8 0.9% idle mix0.622·E1(x)+ 0.378·E2(x)= y
The same token as the worked example below. The router is a single matrix multiply, so scoring all eight experts is cheap. Only the two winners do real work: their probabilities, 0.466 and 0.283, are divided by their sum, 0.749, to give gates of 0.622 and 0.378. The six dashed experts hold weights in memory but spend nothing on this token. A different token lights a different pair, which is why every expert must stay loaded even though each token uses a quarter of them.

Cost and trade-offs: what MoE saves and what it spends

Per token, per layer. d is the model width, F one expert’s hidden width, N the number of experts, k how many fire, T the tokens in a batch. Time is compute; space is weights or buffers held in memory.

CaseTimeSpaceWhy
Dense feed-forward blockO(d·F)O(d·F)Every token pays for every weight. Grow the block and both columns grow together.
MoE layer, top-k of NO(k·d·F + N·d)O(N·d·F)Compute follows k, memory follows N. That split is the whole idea.
The router itselfO(N·d)O(N·d)Say d = 4,096 and N = 64: 262,144 router weights, against 134,217,728 in one expert with F = 4d. A rounding error.
Picking the top kO(N) per tokenO(k)A scan over N scores. Negligible next to running one expert.
Capacity buffersO(1) per tokenO(c·T·k) slots in totalWith the page’s 4,096 tokens, top-2, 8 experts and c = 1.25: 1,280 slots each. Raise c and fewer tokens drop, but more slots sit padded and empty.
All-to-all across GPUs2·k·d values sent per tokenone send and one receive bufferWith experts on different GPUs each token travels out and back. At k = 8 and d = 4,096 that is 65,536 values per token per layer, 131,072 bytes in 16-bit.
Raising k, say 8 → 16 of 64about 2× expert computeunchangedMemory is set by N, so k is a pure compute knob. The widget’s default, top-8 of 64, runs 12.5% of the expert weights per token; top-16 would run 25%.
Adding experts, 8 → 64 at fixed krouter grows 8×, still tiny8× expert weightsCapacity climbs while per-token compute barely moves. The price is VRAM, plus a harder balancing problem: more experts that can starve.
Fine-grained splitsame as coarsesame as coarse8 experts of width F at top-2 and 64 of width F/8 at top-16 cost the same. The first has 28 possible expert pairs; the second about 489 trillion combinations to specialise with.

Read the table as a trade: MoE swaps FLOPs for memory and network. That pays off when you are compute-bound, as in training and large-batch serving. It pays off less on one GPU with tiny batches, where the bottleneck is loading weights, and many experts get touched anyway. Before reaching for MoE, ask which wall you are hitting: if it is VRAM, sparsity makes it worse; if it is FLOPs per token, sparsity is the cheapest way through.

Where this shows up: model cards, serving and interviews

  • Sizing hardware from a model card

    Memory follows the total. At 2 bytes a weight, 46.7B parameters need about 93 GB just for weights, though the model computes like a 13B one. At 671B, 16-bit weights alone are 1,342 GB. That is why large MoE models ship and serve in lower precision and across many GPUs. The active count tells you speed; the total tells you how many cards to buy. Quote both when you compare an MoE with a dense model, or the comparison is meaningless.

  • The research lineage

    Sparsely gated experts were scaled up by Shazeer et al. in 2017 (Outrageously Large Neural Networks), with top-k gating over thousands of experts. GShard used top-2 routing with a per-expert capacity. Switch Transformer cut it to top-1 and is the source of the balance loss in the step-by-step section. Today’s fine-grained designs refine the same switchboard rather than replace it.

  • Serving in production

    Experts are spread over GPUs (expert parallelism), so every MoE layer is a shuffle: send each token to its experts’ GPUs, compute, send it back. Throughput then depends on the network and on balance. One hot expert makes its GPU the straggler every other GPU waits for, which is why balance is an operations problem as well as a training one. A serving team watches per-expert token counts the way a web team watches per-shard traffic: a skewed histogram is a latency bug waiting to happen.

  • Interview angles

    Expect: “Why is an MoE fast but big?” (active versus total). “What happens to a token when its expert is full?” (dropped from that expert, carried by the residual). “Why not just raise k?” (compute climbs back toward dense). “What does load balancing buy you?” (expert quality and throughput). A good answer names both the memory bill and the all-to-all.

Expert routing, step by step

One token through a router, how capacity and the balancing loss behave, and the active-versus-total arithmetic. The example uses 8 experts and top-2 so every number fits on the page; the widget defaults are 64 experts and top-8.

One token, four moves

  1. Score. The router is a small linear layer: one logit per expert, z = W·x.
  2. Pick. Softmax the logits and keep the top-k experts.
  3. Renormalize. Divide the kept probabilities by their sum so the gate weights add to 1. Some designs skip this step.
  4. Mix. Output y = Σ gᵢ · Eᵢ(x) over the chosen experts. The other experts never run for this token.

Worked example

  1. Logits for experts 1 to 8: 2.0, 1.5, 0.5, 0.0, −0.5, −1.0, −1.5, −2.0. Softmax gives 46.6%, 28.3%, 10.4%, 6.3%, 3.8%, 2.3%, 1.4% and 0.9%.
  2. Top-2 keeps experts 1 and 2, which hold 74.9% of the mass. Renormalized, the gates are 0.622 and 0.378.
  3. Capacity. With 4,096 tokens, top-2 and 8 experts the average load is 1,024 tokens per expert. A capacity factor of 1.25 gives every expert room for 1,280; a token routed to a full expert is dropped from that expert and passes through on the residual connection alone.
  4. Balance loss. The Switch Transformer penalty is α · N · Σ fᵢ·Pᵢ, with fᵢ the fraction of tokens sent to expert i and Pᵢ its mean router probability. With 4 experts and an even split it equals α. If 5 of 8 tokens pile onto one expert, with fractions (0.625, 0.125, 0.125, 0.125) and probabilities (0.4, 0.2, 0.2, 0.2), it rises to 1.3α.
  5. Active versus total. DeepSeek-V3 activates about 37B of 671B parameters per token (5.5%); Mixtral 8x7B, per Mistral, about 12.9B of 46.7B (28%). Memory follows the total, speed follows the active.

Knobs and pitfalls

Raise k for quality and pay in compute; add experts for capacity and pay in memory. The balancing weight α is a trade: too small and experts collapse, too large and it hurts the main loss, which is what DeepSeek's bias approach avoids. In serving, experts are spread across GPUs, so every layer needs an all-to-all exchange of tokens, and a hot expert becomes the slowest GPU. Small batches touch many experts at once, so MoE's memory-bandwidth savings shrink at low batch sizes.

Check yourself

Four questions. The router will grade you.

See every answer, with the reasoning
  1. In an MoE layer, how many experts run for each token?

    Answer: Only the top-k the router picks (often 2) — Top-k routing: a few experts fire, the rest stay dark — that’s the sparsity.

  2. What sets an MoE model’s memory footprint?

    Answer: Total parameters — every expert sits in VRAM — Memory follows total params; compute and speed follow active params. DeepSeek-V3: 671B total, 37B active.

  3. Why do MoE models need load balancing?

    Answer: Routers collapse onto favorite experts, overloading some while others idle and never learn — Imbalance wastes capacity and jams the GPUs hosting hot experts.

  4. What is DeepSeek-V3’s approach to balancing?

    Answer: Loss-free: a per-expert routing bias nudged by usage, no tax on the training objective — A feedback controller on routing, so balance doesn’t come at the cost of quality.

Finished this one? 0 / 61 Labs done
NextThe Million-Token Bill — Sparse Attention Next on the “The transformer, opened up” ladder · rung 5 of 5

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Labs