Pidoku

Mixture of Experts

Module 14 Lesson 14.g 1h 30m Difficulty 4/5

Prerequisites 10.i, 2.f, 14.e

This lesson is about MoE as a model: what the router does, how 2026 models are built, and what that means for memory and bandwidth. Moving tokens between GPUs is 14.e; the kernels, load balancing and engine tuning are 14.h.


Before you start: words you need#

WordPlain meaning
FFNThe feed-forward block in each transformer layer: two or three big matrix multiplies with an activation between (10.i). Most of a dense model’s parameters live here.
ExpertOne small FFN. An MoE layer has many of them side by side.
Router (gate)A tiny linear layer that scores every expert for each token and picks the best few.
Top-kThe k experts with the highest scores for a token. Only those run.
Shared expertAn expert that every token always uses, in addition to its routed ones.
Total / active parametersTotal: everything stored (sets memory). Active: what one token actually uses (sets compute per token) (2.f).
Load balancingTraining tricks that stop the router sending most tokens to a few favourite experts.

1. What is it?#

A mixture-of-experts (MoE) model replaces each layer’s single FFN with E experts and a router. For every token, the router picks k experts; only those run, and their outputs are added together, weighted by the router’s scores.

flowchart LR
  X["token's hidden state"] --> RT["router<br/>score all E experts"]
  RT -->|"top-k"| E3["expert 3"]
  RT -->|"top-k"| E7["expert 7"]
  RT -.->|"not chosen"| EO["the other E-2 experts<br/>idle for this token"]
  X --> SH["shared expert<br/>always runs"]
  E3 --> SUM(("weighted<br/>sum"))
  E7 --> SUM
  SH --> SUM
  SUM --> Y["layer output"]

  class RT queue
  class E3,E7,SH compute
  class EO neutral
  class SUM memory
  class X,Y neutral

The result: a model with a huge number of parameters, of which each token uses only a few percent. In 2026 almost every frontier open model is built this way.

Facts checked on 12 November 2026.


2. Why does it exist?#

Quality grows with parameters; cost per token grows with active parameters. MoE separates the two.

Model (from its model card and config.json)TotalActiveRouted experts, top-kSharedContext
gpt-oss-120b (OpenAI, Aug 2025)117B5.1B128, top-40128k
Qwen3.6-35B-A3B (Alibaba, 2026)35B3B256, top-81262k (up to ~1M)
GLM-5.3 (Z.ai, Aug 2026)~744B*~40B*256, top-811M
Kimi K2.6 (Moonshot, Apr 2026)1T32B384, top-81262k
DeepSeek-V4-Pro (DeepSeek, 2026)1.6T49B384, top-611M
Kimi K3 (Moonshot, Jul 2026)2.8T104B896, top-1621M

* GLM-5’s card gives 744B / 40B; GLM-5.3 uses the same layer shapes, and third-party sources quote 744–753B for it.

Two things stand out:

  • Active parameters are 2–9% of the total. A 1.6T model does about the arithmetic per token of a 49B dense model.
  • Experts got smaller and more numerous. 2023’s Mixtral had 8 large experts, top-2. 2026 models have 128–896 small experts (“fine-grained”), which lets the router combine specialisations more freely.

For inference the trade is not free:

                         dense 49B        MoE 1.6T / 49B active
FLOPs per token          ~98 GFLOP        ~98 GFLOP             same
weights in memory        ~49 GB (FP8)     ~0.9 TB (FP4 experts) ~18x more
bytes read, batch 1      ~49 GB           ~49 GB                similar
bytes read, batch 128    ~49 GB           most of the 0.9 TB    much more (section 5)
GPUs just to hold it     1                8+ (HBM capacity)

MoE trades memory capacity for quality at the same compute. Whether that is a good trade depends on whether you have the memory and enough traffic.


3. Simple analogy#

A hospital of specialists versus one general practitioner.

A dense model is a GP who applies everything they know to every patient. An MoE is a hospital with 384 specialists; each patient sees 6 of them plus the on-duty generalist (the shared expert). Each visit costs about what a GP visit costs, and the hospital knows far more in total. But the hospital must employ all 384 specialists every day, whether or not they see patients. Their salaries are the memory bill.


4. Tiny example: one token through a router#

E = 8 experts, top-2, one token:

router logits:       [1.2, -0.3, 2.9, 0.1, 0.4, 3.1, -1.0, 0.8]
softmax scores:      [.07, .01, .37, .02, .03, .45, .01, .04]   (rounded)
top-2:               expert 5 (0.45) and expert 2 (0.37)
renormalise:         0.45 / 0.82 = 0.55,   0.37 / 0.82 = 0.45
output:              0.55 × expert5(x) + 0.45 × expert2(x)  (+ shared expert, if any)

Six of the eight experts did nothing for this token. With 384 experts and top-6, 378 do nothing.


5. Technical explanation#

Router designs in 2026 models#

SOFTMAX TOP-K            softmax over the expert scores and keep the top k (or take the top k
                         and softmax over those). gpt-oss, Qwen.
SIGMOID + BIAS           score each expert independently with a sigmoid; a per-expert bias,
(aux-loss-free)          nudged during training, steers tokens away from overloaded experts.
                         DeepSeek-V3/V4, Kimi, GLM ("noaux_tc" in their configs).
GROUPED TOP-K            experts are split into groups; a token may only pick from a few groups.
                         Lets engines keep a token's experts on few GPUs or nodes (14.e).
SHARED EXPERTS           1-2 experts every token uses. Learn the common knowledge so routed
                         experts can specialise.
DENSE FIRST LAYERS       the first 1-3 layers are ordinary dense FFNs ("first_k_dense_replace").

Training-era designs you will still read about: expert choice routing (each expert picks its tokens) and capacity factors with token dropping (cap each expert at C × average load and let overflow tokens skip the layer). Modern inference engines are dropless: every token gets all k of its experts, and imbalance is handled by scheduling and redundant experts instead (14.h).

Newer variations#

  • LatentMoE. Kimi K3 describes a “Stable LatentMoE” design (16 of 896 experts active) with a different expert shape from K2’s. Read the config, not the K2 assumptions, before sizing it.
  • Different active counts for prefill and decode. DeepSeek-V4.1-Flash’s model card describes a causal encoder-decoder layout that activates about 8B parameters per token in prefill and 16B in decode, out of a 552B backbone.
  • Hybrid attention plus MoE. Kimi K3 and Qwen3.6 mix linear-attention layers with a few full-attention layers (12.g). That changes the KV cache, not the experts.

Memory: size from total parameters#

weights ≈ total parameters × bytes per parameter (+ scales)

DeepSeek-V4-Pro: ~1.55T expert params at FP4 (~0.56 B/param with scales) ≈ 0.87 TB
                 + ~50B other params at FP8                             ≈ 0.05 TB
                 ≈ 0.92 TB before any KV cache
Kimi K3:         2.8T at MXFP4 (QAT)                                    ≈ 1.5 TB

That is why these models arrive with low-precision checkpoints from the model maker (13.e, 13.g): DeepSeek-V4 ships FP4 experts with FP8 for the rest, Kimi K2 Thinking shipped INT4 trained with quantization-aware training (QAT), and Kimi K3 ships MXFP4 weights with MXFP8 activations. Keep the router and the shared expert at higher precision unless the model maker says otherwise: a wrong routing decision sends the token to the wrong expert entirely.

Bandwidth: the batch decides what you read#

At batch 1, one decode step reads the attention weights, the shared expert and k experts per layer: roughly the active parameters. With more tokens in the step, each token picks different experts, and the set of experts touched grows fast:

expected experts touched per layer ≈ E × (1 − (1 − k/E)^B)      (B tokens, random routing)

Section 6 runs it. By 128 tokens in a step, almost every expert is read. So:

  • At low batch, MoE decode is cheap, like a dense model of the active size.
  • At high batch, each step reads nearly the whole model, but spreads that read over many tokens, so bytes per token still fall.
  • In between, MoE is in the worst place: most experts are read, but for few tokens each.

This is why MoE serving wants either very small batches on very fast memory, or very large batches spread over many GPUs with expert parallelism (14.e, 14.h).

Compute: each expert sees few tokens#

With B tokens in a step, each expert receives on average B × k / E tokens. For DeepSeek-V4-Pro at B = 512, that is 512 × 6 / 384 = 8 tokens per expert: a tiny GEMM with very low arithmetic intensity (6.a). Large MoE models need large global batches, gathered across many GPUs, before their expert GEMMs become efficient. That is the deep reason for attention DP + wide EP.


6. Under the hood#

Share of routed experts touched per layer as the number of tokens in one step grows, for five 2026 models (expert counts from their configs, random routing assumed).

Go
// moe.go — how much of an MoE model one decode step touches, as the batch grows.
package main

import (
	"fmt"
	"math"
)

type model struct {
	name    string
	experts float64 // routed experts per layer
	topK    float64 // routed experts per token
}

// touched is the expected number of distinct experts hit by b tokens,
// assuming each token picks its k experts uniformly at random.
func touched(m model, b float64) float64 {
	return m.experts * (1 - math.Pow(1-m.topK/m.experts, b))
}

func main() {
	models := []model{
		{"gpt-oss-120b", 128, 4},
		{"Qwen3.6-35B-A3B", 256, 8},
		{"GLM-5.3", 256, 8},
		{"DeepSeek-V4-Pro", 384, 6},
		{"Kimi K3", 896, 16},
	}
	batches := []float64{1, 8, 32, 128, 512}
	fmt.Printf("Share of routed experts touched per layer, by tokens in the step\n%-17s", "model")
	for _, b := range batches {
		fmt.Printf("%7.0f", b)
	}
	fmt.Println()
	for _, m := range models {
		fmt.Printf("%-17s", m.name)
		for _, b := range batches {
			fmt.Printf("%6.0f%%", 100*touched(m, b)/m.experts)
		}
		fmt.Printf("   E=%.0f k=%.0f\n", m.experts, m.topK)
	}
}

Output:

Share of routed experts touched per layer, by tokens in the step
model                  1      8     32    128    512
gpt-oss-120b          3%    22%    64%    98%   100%   E=128 k=4
Qwen3.6-35B-A3B       3%    22%    64%    98%   100%   E=256 k=8
GLM-5.3               3%    22%    64%    98%   100%   E=256 k=8
DeepSeek-V4-Pro       2%    12%    40%    87%   100%   E=384 k=6
Kimi K3               2%    13%    44%    90%   100%   E=896 k=16

How to read it:

  • Only the ratio k/E matters for this curve: models with the same k/E (1/32 for the first three) behave the same.
  • By 32 tokens, 40–64% of the experts are read; by 128, nearly all. A server at moderate load reads most of the model every step.
  • Real routers are not uniform. Popular experts are hit more often, so slightly fewer experts are touched, and the load on each is less even. Measure it on your traffic (14.h, exercise 2).

7. Performance implications#

MoE MODELS ARE
  ✓ cheap in FLOPs per token (set by active parameters)
  ✗ expensive in memory capacity (set by total parameters)
  ✗ expensive in memory bandwidth at moderate batch (most experts read for few tokens)
  ✓ efficient at very large batch across many GPUs (wide EP)
  ✓ excellent quality per FLOP

THEY SUIT
  ✓ high-throughput serving on large, NVLink-connected GPU groups (NVL72)
  ✓ providers with enough traffic to fill big global batches

THEY SUIT LESS
  ✗ one or two GPUs at low traffic (small MoEs like gpt-oss-120b excepted)
  ✗ memory-constrained hardware, because the total must be resident

An MoE with 49B active parameters does not serve like a 49B dense model. It needs the memory of its total size, reads anywhere between its active and total size per step depending on batch, and adds communication across GPUs.


8. Production implications#

  • Size memory from total parameters, at the precision you will actually serve.
  • Size bandwidth from experts touched at your batch, not from active parameters.
  • Use the model maker’s low-precision checkpoint (FP4, MXFP4, INT4 QAT) when one exists; it was trained or calibrated for it.
  • Keep the router at high precision unless the checkpoint already does otherwise.
  • Read the config. n_routed_experts, num_experts_per_tok, n_shared_experts, first_k_dense_replace, topk_group and moe_intermediate_size decide memory, routing and EP layout.
  • Small MoEs are different. gpt-oss-120b (MXFP4 experts, ~65 GB checkpoint) runs on one 80 GB GPU; Qwen3.6-35B-A3B on a workstation card. For them, plain DP replicas are usually right (14.b).

9. Common mistakes#

  1. Sizing memory from active parameters. Off by 10–30x.
  2. Assuming MoE decode costs like a dense model of the active size. True at batch 1, false at batch 32.
  3. Assuming tokens are dropped at inference. Modern engines are dropless; capacity factors are a training-era tool.
  4. Quantizing the router aggressively. Routing errors are not small errors.
  5. Assuming one model family’s shapes. K3 is not K2 with more experts; V4.1-Flash is not V4-Flash. Read each config.
  6. Deploying a trillion-parameter MoE on a few GPUs at low traffic. All the memory, none of the batching benefit.

10. Hands-on exercise#

  1. Run moe.go. Add Mixtral 8x7B (E = 8, k = 2). Why is its curve so steep?
  2. Run a small MoE (Qwen3.6-35B-A3B or gpt-oss-20b) and record, per layer, the experts chosen for each token over a few thousand real prompts. Compare the touched-experts curve with the uniform formula. Which experts are hot?
  3. From DeepSeek-V4-Flash’s config.json, compute total expert parameters and active parameters per token. Compare with the model card’s 284B / 13B.
  4. Compute the average tokens per expert per step for Kimi K3 at a global batch of 4,096 tokens. Is that GEMM compute-bound or memory-bound on a B300 (6.a)?
  5. Quantize the router of a small MoE to INT4 and measure how often the top-k choice changes on 1,000 prompts.

11. Interview questions#

  1. What does MoE decouple, and why is that attractive?
  2. Does a “1.6T total, 49B active” model serve like a 49B model? Explain carefully.
  3. Derive the expected number of experts touched by B tokens. What does it imply for decode?
  4. What is a shared expert, and why do most 2026 MoE models have one?
  5. What is aux-loss-free load balancing?
  6. Why are inference engines dropless, and what replaces capacity factors?
  7. Why do MoE models ship as FP4 or INT4 checkpoints, and which part stays at higher precision?

12. Further reading#

Checked on 12 November 2026.

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in