This lesson is about the distributed-systems problem that mixture-of-experts models create: where the experts live and how tokens reach them. The model itself is 14.g; the kernels, load balancing and engine tuning are 14.h.
Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Mixture of experts (MoE) | A model whose feed-forward block is many small networks (“experts”). A small router sends each token to only a few of them (its top-k). Taught in 14.g. |
| Expert parallelism (EP) | Putting different experts on different GPUs, instead of copying or slicing every expert onto every GPU. |
| Dispatch / combine | The two data movements in an EP layer: send each token to the GPUs that hold its chosen experts (dispatch), then bring the results back (combine). |
| All-to-all | A collective where every GPU sends a different piece of data to every other GPU (9.f). Dispatch and combine are all-to-alls. |
| Attention DP | Running attention data-parallel: each GPU handles attention for its own requests with its own KV cache (14.b). Paired with EP, this is the standard 2026 layout. vLLM’s posts call it DEP. |
| Wide EP | EP across a large group: 32, 64 or 72 GPUs, usually inside one NVL72 rack or across several servers. |
| Barrier | A point where every GPU must arrive before any can continue. The slowest GPU decides when everyone moves on. |
1. What is it?#
In an MoE layer each token uses k of E experts: 6 of 384 in DeepSeek-V4-Pro, 16 of 896 in Kimi K3. Expert parallelism spreads the experts over GPUs. Tokens travel to the experts, not the other way round.
flowchart LR
subgraph G0["GPU 0"]
A0["attention for<br/>its own requests"] --> R0["router: top-k"]
X0["experts 0-95"]
end
subgraph G1["GPU 1"]
A1["attention for<br/>its own requests"] --> R1["router: top-k"]
X1["experts 96-191"]
end
subgraph G2["GPU 2"]
A2["attention for<br/>its own requests"] --> R2["router: top-k"]
X2["experts 192-287"]
end
subgraph G3["GPU 3"]
A3["attention for<br/>its own requests"] --> R3["router: top-k"]
X3["experts 288-383"]
end
R0 & R1 & R2 & R3 ==>|"dispatch<br/>all-to-all"| X0 & X1 & X2 & X3
X0 & X1 & X2 & X3 -.->|"combine<br/>all-to-all"| A0 & A1 & A2 & A3
class A0,A1,A2,A3 compute
class R0,R1,R2,R3 queue
class X0,X1,X2,X3 memoryThe layout above is attention DP + EP: attention is cheap to copy and its KV cache is per request, so each GPU runs attention for its own requests; the experts are huge, so each GPU holds only a share. Every MoE layer then has two all-to-alls.
Facts checked on 12 November 2026.
2. Why does it exist?#
PROBLEM Frontier open models are 0.3–2.8 trillion parameters, ~95% of them in experts.
DeepSeek-V4-Pro's routed experts alone are ~870 GB even at FP4.
WHY Copying every expert onto every GPU (pure DP) is impossible.
Slicing every expert across GPUs (TP) makes each expert's matrix tiny,
and TP's all-reduces grow with the group (14.c).
FIX Give each GPU whole experts. Move the few tokens that need them.
TRADE-OFFS
✓ memory per GPU falls as 1/EP: more GPUs → fewer experts each
✓ per-GPU weight reads per decode step fall too (section 6) — the reason wide EP is fast
✓ each expert stays a full-size matrix, so its GEMMs are efficient
✗ two all-to-alls per MoE layer, every step, across the whole EP group
✗ routing is data-dependent: some GPUs get more tokens than others
✗ every all-to-all is a barrier; the most loaded GPU sets the pace
✗ every GPU must step together, even one with no requests (it runs a dummy pass)For dense models there is nothing to expert-parallelise. For small MoE models that fit on one server (gpt-oss-120b, Qwen3.6-35B-A3B), TP or plain DP is usually simpler and fast enough.
3. Simple analogy#
A hospital with specialists in different buildings.
Each patient (token) needs 6 of 384 specialists, spread over 32 buildings. Each building also has a reception desk (attention) that sees its own patients. For every visit:
- Reception decides which specialists each patient needs (the router).
- Shuttles take every patient to the right buildings (dispatch).
- Specialists see their patients.
- Shuttles bring everyone back to their own reception (combine).
The shuttles are the network cost. And if one specialist is suddenly popular, their building has a queue while the others wait for the last shuttle to leave. That queue is load imbalance.
4. Tiny example: one dispatch#
4 GPUs, 8 experts (2 per GPU), top-2, and 6 tokens per GPU (24 in all). The router picks:
tokens sent to GPU → GPU0 GPU1 GPU2 GPU3 (experts 0-1, 2-3, 4-5, 6-7)
from GPU 0 (6 tokens × 2 = 12 copies) 3 5 2 2
from GPU 1 2 6 1 3
from GPU 2 4 4 2 2
from GPU 3 1 7 3 1
--- --- --- ---
copies each GPU must compute 10 22 8 8 (fair share: 12)- Each GPU sends a different count to each other GPU. That is an all-to-all, and the counts are only known after the router runs, so the engine first exchanges the counts, then the data.
- GPU 1 got 22 copies, nearly twice its fair share. Everyone else finishes early and waits for it before the combine. Effective use: 48 / (4 × 22) = 55%.
- About three quarters of the copies left their home GPU: with EP over N GPUs, only about 1/N of routed copies stay local.
5. Technical explanation#
One MoE layer, step by step#
1. Router (on each GPU, for its own tokens): top-k experts and weights per token.
2. Layout: count tokens per destination GPU; reorder them so each destination's tokens are
contiguous; exchange the counts.
3. DISPATCH all-to-all: send each token's hidden vector (often quantized to FP8) to every GPU
that holds one of its experts.
4. Expert compute: each GPU runs a grouped GEMM over its local experts (14.h).
5. COMBINE all-to-all: send results back (usually BF16).
6. Weighted sum of the k results per token, plus the shared expert if the model has one.The shared expert (DeepSeek, Kimi, GLM, Qwen use 1–2) runs on every token, so engines keep it local to each GPU (replicated, or TP-sliced inside the attention group). Only routed experts move.
How much moves#
Per token, per MoE layer:
dispatch ≈ k × d_model × 1 byte (FP8) combine ≈ k × d_model × 2 bytes (BF16)
remote share ≈ (EP − 1) / EPFor DeepSeek-V4-Pro (k = 6, d = 7168, 61 MoE layers) that is about 129 KB per token per layer, and about 7.9 MB per token per decode step. Two properties matter:
- The bytes per GPU barely change with EP size. Each GPU sends its own tokens; wider EP only makes slightly more of them remote.
- The number of transfers is large. 61 layers × 2 all-to-alls = 122 barriers per decode step. At tens of microseconds each, the start-up latency alone is a few milliseconds. That is why decode needs special low-latency kernels and why engines overlap communication with compute.
Why all-to-all is harder than all-reduce#
An all-reduce sends the same kind of data in a fixed ring or tree (9.f) and can use switch offload (NVLS). An all-to-all sends different, data-dependent amounts between every pair, so:
- sizes are unknown until the router runs (an extra exchange, or a worst-case buffer);
- every pair of GPUs is a separate flow, so it stresses the network’s bisection bandwidth (9.d), not just each link;
- it is a barrier twice per layer, so one slow GPU or one hot link delays everyone.
The kernels that make it fast#
Plain NCCL all-to-all was too slow for MoE decode, so specialised libraries appeared:
| Library | What it does | Where you meet it |
|---|---|---|
| DeepEP (DeepSeek, open source) | Dispatch/combine kernels in two flavours: high-throughput (large batches, prefill; NVLink inside a node, RDMA between nodes) and low-latency (decode; compatible with CUDA graphs). V2 moved onto an NCCL GIN backend with larger scale-up domains, and V2.5 removed V1 and NVSHMEM; dispatch and combine now always use some SMs (the old zero-SM RDMA path was V1 only; see 25.i). | vLLM, SGLang, TensorRT-LLM |
| pplx-kernels (Perplexity) | Portable dispatch/combine kernels | vLLM pplx, SGLang pplx |
| FlashInfer NVLink all-to-all | One-sided and two-sided all-to-all over multi-node NVLink (MNNVL), i.e. across an NVL72 | vLLM, SGLang flashinfer |
| MoRI (AMD) | Dispatch/combine on Instinct GPUs | vLLM, SGLang on ROCm |
| Mooncake EP, NIXL EP | EP backends built on the Mooncake and NIXL transfer engines (9.e) | vLLM moonep, nixl_ep; SGLang mooncake, nixl |
Selecting them, in vLLM v0.32.0:
# 2 nodes × 8 GPUs, DeepSeek-class model: attention DP=16, experts EP=16
vllm serve deepseek-ai/DeepSeek-V4-Flash \
--data-parallel-size 16 --data-parallel-size-local 8 \
--enable-expert-parallel \
--all2all-backend deepep_low_latency # decode-heavy; deepep_high_throughput for prefillvLLM’s v0.32.0 list of --all2all-backend values is naive, pplx, deepep_high_throughput,
deepep_low_latency, deepep_v2, mori_high_throughput, mori_low_latency, moonep,
nixl_ep, allgather_reducescatter (the default) and flashinfer_nvlink_one_sided /
flashinfer_nvlink_two_sided. The EP size is TP × DP when --enable-expert-parallel is on.
SGLang’s equivalent is --moe-a2a-backend (deepep, mooncake, nixl, mori, flashinfer,
pplx, …) with --deepep-mode auto|normal|low_latency. Lesson 19.a shows how vLLM coordinates
the DP ranks.
Why wide EP is fast: per-GPU weight reads#
Decode is memory-bound (2.e): its speed is set by bytes read from HBM per step. With attention DP
- EP, the global batch is large (every GPU’s requests together), so every expert gets some tokens, and each GPU reads only its local experts:
expert bytes read per GPU per step ≈ (E / EP) × layers × bytes per expertDouble the EP size and each GPU reads half as many expert weights, while its all-to-all bytes stay about the same. Up to the point where communication or imbalance dominates, wider EP makes every step shorter. That is why the best published DeepSeek, Kimi and GLM results run EP 32–72 on GB200/GB300 NVL72 racks, where the whole all-to-all stays on NVLink (7.d).
Keeping the all-to-all off slow links#
- Inside one NVLink domain (8 GPUs on HGX, 72 on NVL72) the all-to-all runs at hundreds of GB/s per GPU. Across servers it drops to 45–90 GB/s per GPU over RDMA (9.e’s table).
- Node-limited routing. DeepSeek-V3 trained its router so a token’s experts span at most
4 nodes, which bounds cross-node traffic by construction. Many later models use grouped
routing (
topk_group,n_groupin their configs) for the same reason. - Hierarchical dispatch. DeepEP’s high-throughput kernels send once over RDMA to the destination node, then fan out over NVLink inside it.
Load imbalance is a distributed problem#
Because dispatch and combine are barriers, the GPU with the most routed tokens decides the step time for all of them (section 4). Imbalance has two sources: popular experts (the router’s choices) and uneven attention work (some DP ranks hold long prompts). The fixes, covered in 14.h, are redundant copies of hot experts placed by a load balancer (EPLB), larger batches that average out, and scheduling that keeps DP ranks evenly loaded.
EP or TP for the experts?#
| EP (whole experts per GPU) | TP inside each expert | |
|---|---|---|
| Collective | 2 all-to-alls per MoE layer | 1 all-reduce per MoE layer |
| Memory per GPU | E/N experts | 1/N of every expert |
| GEMM shape | full-size per expert | tiny slices, poor efficiency at large N |
| Imbalance | yes | no |
| Use when | many experts, large group, NVL72 or multi-node | few experts, model fits on one server |
Engines also mix them, for example TP=2 inside each expert group and EP across groups, or TP for attention plus EP for experts inside an 8-GPU server.
6. Under the hood#
What each GPU reads from HBM and sends over the all-to-all per decode step, for a
DeepSeek-V4-Pro-class model (config values from its config.json), 64 decode tokens per GPU.
// ep.go — wide expert parallelism: what each GPU reads and what it sends, per decode step.
package main
import "fmt"
func main() {
// DeepSeek-V4-Pro-class MoE, from its config.json.
const (
layers = 61 // MoE layers
experts = 384 // routed experts per layer
topK = 6 // routed experts per token
hidden = 7168.0 // d_model
expertFF = 3072.0 // moe_intermediate_size
bytesParam = 0.5625 // FP4 weights + one FP8 scale per 16 values
perGPUTok = 64.0 // decode tokens per GPU per step (attention DP)
hbmTBs = 8.0 // B300-class HBM bandwidth, TB/s
nvlinkGBs = 700.0 // achieved one-way NVLink 5 per GPU, GB/s
rdmaGBs = 45.0 // achieved 400 Gb/s RDMA per GPU, GB/s
)
expertBytes := 3 * hidden * expertFF * bytesParam // gate, up, down
// Per token per MoE layer: dispatch k copies in FP8, combine k results in BF16.
tokBytes := topK * hidden * (1 + 2)
fmt.Printf("one expert: %.1f MB; all routed experts: %.0f GB\n\n",
expertBytes/1e6, expertBytes*experts*layers/1e9)
fmt.Printf("%4s %8s %12s %10s %12s %10s %10s\n",
"EP", "exp/GPU", "weights/GPU", "HBM read", "a2a/GPU", "NVLink", "RDMA")
for _, ep := range []float64{8, 16, 32, 64, 72} {
local := experts / ep
wBytes := local * layers * expertBytes
remote := (ep - 1) / ep // share of routed copies that leave the GPU
a2a := perGPUTok * tokBytes * layers * remote
fmt.Printf("%4.0f %8.1f %10.1fGB %8.2fms %10.1fMB %8.2fms %8.2fms\n",
ep, local, wBytes/1e9, wBytes/(hbmTBs*1e12)*1e3,
a2a/1e6, a2a/(nvlinkGBs*1e9)*1e3, a2a/(rdmaGBs*1e9)*1e3)
}
}Output:
one expert: 37.2 MB; all routed experts: 870 GB
EP exp/GPU weights/GPU HBM read a2a/GPU NVLink RDMA
8 48.0 108.8GB 13.60ms 440.7MB 0.63ms 9.79ms
16 24.0 54.4GB 6.80ms 472.2MB 0.67ms 10.49ms
32 12.0 27.2GB 3.40ms 488.0MB 0.70ms 10.84ms
64 6.0 13.6GB 1.70ms 495.8MB 0.71ms 11.02ms
72 5.3 12.1GB 1.51ms 496.7MB 0.71ms 11.04msHow to read it:
- EP=8 does not even fit: 109 GB of experts per GPU leaves too little room on a 180–288 GB GPU once attention weights and KV cache are added, and it costs 13.6 ms of expert reads per step.
- Each doubling of EP halves the expert reads. At EP=72 they take about 1.5 ms.
- The all-to-all bytes stay at ~0.5 GB per GPU per step. Over NVLink that is ~0.7 ms; over 400 Gb/s RDMA it is ~11 ms, more than all the weight reads. Wide EP across ordinary servers is communication-bound; inside an NVL72 it is not.
- The model ignores the 122 per-step barrier latencies, attention and imbalance. Those are what stop the curve: vLLM’s DeepSeek-V4.1-Flash work found an untuned DEP32 slower than DEP16 (17.6 ms versus 13.8 ms per step) until the communication and balancing paths were optimised (vLLM blog, October 2026).
7. Performance implications#
- Wide EP raises per-GPU decode throughput for large MoE models, because each GPU reads fewer expert bytes per step. vLLM reports its MoE-kernel time for DeepSeek-V4.1-Flash falling from 13.4 ms at DEP4 to 6.0 ms at DEP32 (project’s own benchmark, GB200/GB300).
- It needs a big global batch. If the total batch across the EP group is small, many experts get no tokens and the GPUs still pay every barrier. Wide EP is a high-throughput layout.
- Prefill and decode want different kernels: high-throughput dispatch for prefill’s large token counts, low-latency dispatch for decode. This is a main reason large MoE deployments disaggregate prefill and decode (14.j): each pool can use its own EP size and kernels.
- Interconnect sets the ceiling. The same model on HGX servers over InfiniBand typically runs EP 16–32 with heavy overlap; on NVL72 it runs EP 32–72.
- Published scale, for reference (all vendor or project benchmarks): SGLang served DeepSeek-V3 on 96 H100s with prefill/decode disaggregation and EP in 2025; on GB300 NVL72 in 2026, SemiAnalysis InferenceX measured about 6,200 output tokens/s per GPU for DeepSeek-V4-Pro with Dynamo + vLLM at ~27 tokens/s per user (8k in / 1k out), up to 2.8x a GB200 NVL72.
8. Production implications#
- Choose EP only when the model needs it. If the model fits on one server, TP or DP is simpler and more robust.
- Keep the EP group inside one NVLink domain if you can. One NVL72 rack per EP group is the 2026 sweet spot for trillion-parameter MoE models.
- The whole EP group is one failure domain. All ranks step together; one dead GPU stops the group. Plan restart, drain and upgrade for the group (23.e). Elastic EP (dropping a failed rank without a full restart) is appearing in SGLang and vLLM; check its status for your version.
- Ranks with no work still run. A DP rank with zero requests runs a dummy forward pass so the all-to-all completes. Do not read its “busy” GPU as useful work.
- Watch per-rank load, not just averages. Track tokens per DP rank and per expert; imbalance is invisible in aggregate throughput.
- Gang-schedule. All pods of an EP group must land together in the right rack (Grove, LeaderWorkerSet; 21.c, 21.j).
9. Common mistakes#
- Using EP for a model that fits with TP. You pay all-to-alls and imbalance for nothing.
- Wide EP over a slow network. At 400 Gb/s per GPU, the all-to-all can cost more than the expert reads it saves.
- Expecting wide EP to help at low traffic. It needs a large global batch.
- Ignoring the barrier. One overloaded GPU or one slow link sets everyone’s step time.
- Running attention TP across the EP group for an MLA model. The latent KV cache gets copied; use attention DP (14.b, 14.c).
- One all-to-all backend for everything. Prefill and decode want different kernels.
- Treating “37B active” as “serves like a 37B model”. Memory follows total parameters; the communication follows the EP layout (14.g).
10. Hands-on exercise#
- Run
ep.go. ChangerdmaGBsto 90 (800 Gb/s per GPU). At which EP size do the expert reads drop below the RDMA all-to-all time? - Change the model to Kimi K3 (896 experts, top-16, 92 MoE layers; take the expert sizes from its
config.json, and note that its “LatentMoE” design changes the expert shape). How many GPUs does EP need so the experts take under 60 GB per GPU? - Redo section 4 with a random router in a few lines of Python or Go. Run 1,000 trials at 6, 64 and 512 tokens per GPU. How does the max/mean load ratio change?
- Run
nccl-tests’alltoall_perfon your GPUs for 1 MB to 1 GB messages, then compare withall_reduce_perfat the same sizes. - If you have two 8-GPU nodes, serve an MoE model with
--enable-expert-paralleland two different--all2all-backendvalues. Compare ITL at concurrency 16 and 512.
11. Interview questions#
- What is expert parallelism, and why is it paired with attention data parallelism?
- Walk through one MoE layer under EP. Which steps communicate?
- Why does an all-to-all cost more than an all-reduce of the same size?
- Why do per-GPU weight reads fall as EP grows, while all-to-all bytes per GPU do not?
- Why do engines ship separate high-throughput and low-latency dispatch kernels?
- What is node-limited routing, and what problem does it solve?
- When would you shard experts with TP instead of distributing them?
12. Further reading#
Checked on 12 November 2026.
- [ESTABLISHED] Lepikhin et al., “GShard” (2020) — expert parallelism and all-to-all
- [ESTABLISHED] DeepSeek-AI, “DeepSeek-V3 Technical Report” (2024) — node-limited routing, dispatch and combine at scale
- [REFERENCE] DeepEP — the dispatch/combine kernels
- [REFERENCE] vLLM — expert parallel deployment
- [REFERENCE] SGLang — expert parallelism
- [ESTABLISHED] LMSYS — DeepSeek with PD disaggregation and large-scale expert parallelism on 96 H100s (May 2025)
- [EMERGING] vLLM — Serving DeepSeek-V4.1-Flash with P/D disaggregation and Wide-EP on GB300 NVL72 (October 2026) — project’s own benchmark
- [EMERGING] SemiAnalysis InferenceX — GB300 vs GB200 NVL72 on DeepSeek-V4-Pro