14.e explained how tokens travel between GPUs; 14.g explained the model. This lesson is the serving engineering on top: the kernels, overlap, load balancing and engine settings that decide whether an MoE deployment runs at full speed or at half.
Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Grouped GEMM | One kernel launch that runs many matrix multiplies of different sizes, one per expert (11.c). |
| Permute / unpermute | Reordering tokens so each expert’s tokens sit next to each other in memory, then putting the results back in the original order. |
| Fused MoE kernel | A kernel that does routing, permutation, the expert GEMMs and the weighted sum with few launches and few trips to HBM. |
| Overlap | Running communication and compute at the same time on different streams (5.e), so the all-to-all is hidden behind useful work. |
| Micro-batch | Here: one half of a step’s batch. Two halves take turns computing and communicating. |
| EPLB | Expert-parallel load balancer: measures how busy each expert is and places extra copies of hot experts so every GPU gets similar work. |
| Balancedness | Mean GPU load ÷ busiest GPU load in an MoE layer. 1.0 is perfect; 0.5 means half the GPUs’ time is spent waiting. |
1. What is it?#
MoE serving is everything an engine does so that the expert layers, which hold almost all the weights, run at hardware speed. Five pieces matter:
1. KERNELS fused routing + permutation + grouped GEMM, in FP8 or FP4
2. OVERLAP hide dispatch and combine behind compute (two-batch or single-batch overlap)
3. BALANCE EPLB: redundant copies of hot experts, re-placed while serving
4. BATCHING big enough global batches for efficient expert GEMMs, evenly spread over DP ranks
5. LAYOUT different EP sizes and kernels for prefill and for decode (14.j)Facts checked on 12 November 2026.
2. Why does it matter?#
The same model on the same GPUs can run at very different speeds depending on these choices. Three examples from public 2026 results (all project or vendor benchmarks):
- vLLM’s DeepSeek-V4.1-Flash work found an untuned DEP32 decode step (17.6 ms) slower than DEP16 (13.8 ms) until communication and balancing were fixed.
- In the same work, EPLB raised the main model’s expert balancedness from 0.35 to 0.94.
- SGLang’s documentation states that two-batch overlap unlocks “up to 2x throughput”.
None of these is a new model or new hardware. They are serving engineering.
3. Simple analogy#
A sorting office with 384 delivery vans.
Parcels (tokens) arrive mixed up. Sorting them by van first (permutation) lets each van load in one go (grouped GEMM), instead of driving off with one parcel at a time. While one batch of vans is out, the next batch is being sorted (overlap). And if one neighbourhood suddenly gets ten times the parcels, you send three vans there instead of one (redundant experts) rather than making every other driver wait at the depot.
4. Tiny example: sorting before the GEMM#
Six tokens, top-1, four experts. The router output:
token: t0 t1 t2 t3 t4 t5
expert: 2 0 2 3 0 2
permute (counting sort by expert):
expert 0: [t1, t4] offset 0
expert 1: [] offset 2
expert 2: [t0, t2, t5] offset 2
expert 3: [t3] offset 5
one grouped GEMM: each thread-block tile works on one expert's contiguous rows
unpermute: write each result back to its token's original slot, times its router weightWithout the sort, each warp would handle tokens for different experts, reading different weight matrices: divergence (6.c) and scattered memory access (6.b). With it, each expert’s tokens are one contiguous block. The sort is a counting sort over E buckets, which is cheap.
5. Technical explanation#
The expert kernels#
A production MoE layer, per GPU, looks like this:
router GEMM + top-k tiny; often fused with the score normalisation
permute (+ dispatch under EP) fused into the all-to-all kernel in DeepEP-style backends
grouped GEMM: gate + up FP8 or FP4 weights; one launch for all local experts
activation (SwiGLU) fused into the GEMM epilogue
grouped GEMM: down
unpermute (+ combine under EP) weighted sum of k results, plus the shared expertThe kernel families you will see selected in logs:
| Kernel family | Where it comes from | Typical use |
|---|---|---|
| Triton fused MoE | vLLM, SGLang | portable default, many GPUs |
| DeepGEMM | DeepSeek | FP8 (and newer FP4) grouped GEMMs on Hopper and Blackwell |
| CUTLASS grouped GEMM | NVIDIA | FP8/FP4 on Blackwell |
| FlashInfer / TensorRT-LLM MoE | NVIDIA, FlashInfer | Blackwell FP4 (flashinfer_trtllm, flashinfer_cutlass, flashinfer_mxfp4 in SGLang) |
| AITER / MoRI | AMD | Instinct GPUs |
SGLang chooses with --moe-runner-backend; vLLM picks from the model’s quantization and the
hardware (18.j). Check the start-up log: falling back to a generic kernel for a FP4 model can cost
a large factor.
Tokens per expert are few. With attention DP + wide EP, a decode step might bring 8–64 tokens to each expert (14.g). A grouped GEMM with 8 rows is memory-bound: it reads the whole expert’s weights for very little arithmetic. That is why expert weights are FP4 and why per-GPU expert bytes (14.e) dominate decode time.
Overlap: hiding the all-to-all#
Each MoE layer has dispatch, expert compute, combine. Run naively, the GPU’s compute units sit idle during both all-to-alls. Two ways to fill that time:
TWO-BATCH OVERLAP (SGLang --enable-two-batch-overlap; vLLM --enable-dbo, "dual batch overlap")
split the step's batch into micro-batches A and B
A: attention ─ dispatch ─ experts ─ combine ─ attention ...
B: attention ─ dispatch ─ experts ─ combine ...
while A communicates, B computes, and the other way round
SINGLE-BATCH OVERLAP (SGLang --enable-single-batch-overlap)
overlap inside one batch: e.g. run the shared expert, or the next chunk of the expert GEMM,
while the dispatch or combine for another part is in flightTwo-batch overlap needs each half to be big enough to be worth running; vLLM has
--dbo-decode-token-threshold and --dbo-prefill-token-threshold to decide when to split.
DeepEP’s low-latency kernels help here because they need only a few SMs (V1 used none; V2 sizes the SM count analytically, see 25.i), leaving the rest for the other half-batch.
EPLB: balancing experts while serving#
Routing is uneven, and because dispatch and combine are barriers, the GPU with the most tokens sets everyone’s step time (14.e). EPLB attacks it in three moves:
- Measure how many tokens each expert received over a window of steps.
- Replicate the hottest experts into spare “redundant” slots, so their load is split.
- Re-place all expert copies across GPUs so each GPU’s total load is about equal, and move the weights there, periodically.
DeepSeek open-sourced its algorithm (EPLB) in 2025: hierarchical placement (balance across nodes first, then within a node) for prefill, and global placement for decode. Both engines now ship it:
# vLLM v0.32.0
vllm serve <moe-model> --data-parallel-size 32 --enable-expert-parallel \
--enable-eplb \
--eplb-config '{"window_size": 1000, "step_interval": 3000, "num_redundant_experts": 32}'
# SGLang
python -m sglang.launch_server --model-path <moe-model> --tp-size 32 --ep-size 32 --dp-size 32 --enable-dp-attention \
--moe-a2a-backend deepep --enable-eplb --ep-num-redundant-experts 32vLLM’s documented defaults: window_size 1000 steps, step_interval 3000 steps,
num_redundant_experts 0 (32 suggested for large deployments), use_async true, with a
choice of weight-transfer communicator (NCCL variants, NIXL, …). vLLM’s October 2026 post
reports rebalancing a DEP32 deployment in under a second without stopping decode. A static
alternative is --expert-placement-strategy round_robin, which spreads adjacent (often
correlated) experts over GPUs instead of keeping them together (linear).
Redundant experts cost memory. 32 extra experts on DeepSeek-V4-Pro is 32 × 61 layers × ~37 MB ≈ 73 GB across the group, or about 2.3 GB per GPU at EP=32: modest, but it comes out of the KV cache.
Balancing the attention side too#
With attention DP, each rank’s attention work depends on its own requests. A rank holding three 64k-token conversations runs a much longer attention than one holding short chats, and the next all-to-all waits for it. Engines address this with:
- DP-aware routing: the front end sends new requests to the least-loaded DP rank, by KV usage and queued tokens, not by request count (19.a).
- Aligned prefill admission: vLLM’s
--prefill-schedule-intervaladmits prefills only every Nth step, on all ranks together, so one rank’s prefill does not stretch everyone’s step. - Disaggregation: keeping prefills off the decode ranks entirely (14.j).
vLLM measured the cost of rank imbalance for DeepSeek-V4.1-Flash prefill: 5.9% throughput lost at DEP2, 13.6% at DEP4 (project’s own benchmark). Wider groups suffer more.
Batching and speculative decoding#
- MoE wants big global batches. Per-expert GEMMs need tokens; the all-to-all latency needs amortising. A wide-EP decode deployment is tuned for hundreds to thousands of concurrent sequences.
- Speculative decoding helps MoE decode. The verification step processes several tokens per sequence, which multiplies tokens per expert without adding sequences. DeepSeek, Kimi and GLM models ship multi-token-prediction (MTP) heads, and DeepSeek-V4.1-Flash ships a DSpark drafter; the draft model can be an MoE with its own EPLB (13.n, 13.o).
Where the time goes (illustrative)#
Measured breakdowns differ by model, GPU and backend. A typical unoptimised wide-EP decode step spends roughly a third of the MoE layer’s time in dispatch and combine, a third to a half in the expert GEMMs, and the rest in routing, permutation and the weighted sum. Overlap can hide most of the communication; FP4 shrinks the GEMM share. Profile your own deployment (22.h) rather than trusting any single breakdown, including this one.
6. Under the hood#
A small simulation of EPLB: 256 experts with skewed popularity on 32 GPUs. It compares a plain linear placement, a greedy placement without copies, and greedy placement with redundant copies of the hottest experts. Each placement is planned on one window of traffic and then evaluated on the next window, where every expert’s load drifts a little.
// eplb.go — expert load balancing: redundant copies of hot experts, placed greedily.
package main
import (
"fmt"
"math"
"math/rand"
"sort"
)
const (
experts = 256
gpus = 32
)
// balance = mean GPU load / max GPU load. 1.0 is perfect; every step waits for the max.
func balance(load []float64) float64 {
var sum, max float64
for _, l := range load {
sum += l
max = math.Max(max, l)
}
return sum / float64(len(load)) / max
}
// plan gives the hottest experts extra copies, then places copies heaviest-first on the
// least-loaded GPU with room. It returns, for each expert, the GPUs holding a copy.
func plan(pop []float64, redundant int) [][]int {
copies := make([]int, experts)
for i := range copies {
copies[i] = 1
}
for r := 0; r < redundant; r++ {
best := 0
for e := range pop {
if pop[e]/float64(copies[e]) > pop[best]/float64(copies[best]) {
best = e
}
}
copies[best]++
}
type slot struct {
expert int
load float64
}
var slots []slot
for e, p := range pop {
for c := 0; c < copies[e]; c++ {
slots = append(slots, slot{e, p / float64(copies[e])})
}
}
sort.Slice(slots, func(i, j int) bool { return slots[i].load > slots[j].load })
room := (len(slots) + gpus - 1) / gpus
load := make([]float64, gpus)
count := make([]int, gpus)
where := make([][]int, experts)
for _, s := range slots {
g := -1
for i := range load {
if count[i] < room && (g < 0 || load[i] < load[g]) {
g = i
}
}
load[g] += s.load
count[g]++
where[s.expert] = append(where[s.expert], g)
}
return where
}
// run spreads each expert's actual load evenly over its copies.
func run(pop []float64, where [][]int) float64 {
load := make([]float64, gpus)
for e, gs := range where {
for _, g := range gs {
load[g] += pop[e] / float64(len(gs))
}
}
return balance(load)
}
func main() {
rng := rand.New(rand.NewSource(7))
// Skewed expert popularity (Zipf-like), shuffled so hot experts are not adjacent.
past := make([]float64, experts)
for i := range past {
past[i] = 1 / math.Pow(float64(i+1), 0.8)
}
rng.Shuffle(experts, func(i, j int) { past[i], past[j] = past[j], past[i] })
// The next window's traffic drifts: each expert's load changes by up to about ±30%.
next := make([]float64, experts)
for i := range next {
next[i] = past[i] * math.Exp(0.3*rng.NormFloat64())
}
linear := make([][]int, experts) // experts 0-7 on GPU 0, 8-15 on GPU 1, ...
for e := range linear {
linear[e] = []int{e / (experts / gpus)}
}
fmt.Printf("%-28s %10s %10s\n", "placement", "planned", "next window")
fmt.Printf("%-28s %10.2f %10.2f\n", "linear, no copies", run(past, linear), run(next, linear))
for _, r := range []int{0, 16, 32, 64} {
w := plan(past, r)
fmt.Printf("%-28s %10.2f %10.2f\n", fmt.Sprintf("greedy, %d redundant", r), run(past, w), run(next, w))
}
}Output:
placement planned next window
linear, no copies 0.29 0.28
greedy, 0 redundant 0.31 0.30
greedy, 16 redundant 0.98 0.59
greedy, 32 redundant 1.00 0.65
greedy, 64 redundant 1.00 0.64How to read it:
- Without copies, placement alone cannot help: the hottest expert carries more than a fair GPU’s share by itself, so balance stays near 0.3 whatever you do. Roughly 70% of every MoE layer’s time is waiting.
- A few redundant copies fix the planned window almost perfectly.
- Traffic drifts. Evaluated on the next window, the same plan falls to about 0.6. That is why
EPLB measures and re-places continuously (
window_size,step_interval) rather than once at start-up, and why real deployments land around 0.9 rather than 1.0. - The simulation ignores network topology (hierarchical placement keeps copies inside a node) and the cost of moving weights.
7. Performance implications#
- Kernel choice for FP4/FP8 experts can change MoE layer time by several times. Verify which backend was selected.
- Overlap hides much of the all-to-all at large batch; at small batch there is not enough work to hide behind, and the barrier latencies show.
- Balancedness is throughput. At 0.5, half of every MoE layer is waiting; going from 0.35 to 0.94 is worth more than most kernel tuning.
- DP-rank imbalance grows with group size. Wider EP reads fewer weights per GPU (14.e) but waits for more stragglers.
- Prefill and decode differ: prefill brings thousands of tokens and wants high-throughput kernels and fewer, larger ranks (vLLM’s V4.1-Flash prefill ran best at DEP2); decode wants low-latency kernels and the widest EP the network allows.
8. Production implications#
- Turn on EPLB for wide EP, with some redundant experts, and log balancedness
(
log_balancednessin vLLM, the expert distribution recorder in SGLang). - Treat expert load and per-rank load as first-class metrics next to TTFT and ITL (23.h).
- Budget KV memory after redundant experts and overlap buffers. Both take HBM.
- Split prefill and decode once EP is wide; they want different kernels and EP sizes (14.j).
- Change one knob at a time and benchmark with your traffic: overlap thresholds, redundant experts, EP size and all-to-all backend interact.
- Expect the defaults to lag the hardware. Blackwell FP4 MoE paths and NVL72 all-to-all backends improve almost every release; re-benchmark after upgrades (19.d).
9. Common mistakes#
- Per-expert loops instead of a grouped GEMM. Hundreds of launches per layer.
- Not sorting tokens by expert. Divergence and scattered memory access.
- No overlap. The all-to-all sits fully exposed on the critical path.
- EPLB planned once. Traffic drifts; the placement must follow.
- Balancing experts but not DP ranks. One rank with long prompts stalls the group.
- Low concurrency on a wide-EP deployment. All the barriers, none of the batching.
- Trusting a single “where the time goes” breakdown. Profile your own model and GPUs.
10. Hands-on exercise#
- Run
eplb.go. Lower the drift from 0.3 to 0.1, then raise it to 0.5. How quickly must you re-plan to stay above 0.8? - Change the skew exponent from 0.8 to 0.5 and 1.2. How many redundant experts does each need to reach 0.9 on the planned window?
- Write the permute → grouped GEMM → unpermute forward pass in PyTorch (use a loop over expert segments as a stand-in for the grouped GEMM) and check it against the naive per-token loop.
- On a small MoE served with vLLM or SGLang, record expert loads per layer for a real prompt mix. Plot the hottest-expert / mean ratio per layer.
- If you have 8+ GPUs, serve an MoE model with EP and toggle two-batch overlap (
--enable-dboin vLLM,--enable-two-batch-overlapin SGLang). Measure throughput at concurrency 64 and 1,024.
11. Interview questions#
- Why must tokens be sorted by expert before the expert GEMM?
- What is two-batch overlap, and when does it fail to help?
- How does EPLB work, and why must it run continuously?
- What does a balancedness of 0.35 mean for step time?
- Why does attention-side imbalance matter in an MoE deployment?
- Why do prefill and decode want different MoE kernels and EP sizes?
- How does speculative decoding interact with MoE efficiency?
12. Further reading#
Checked on 12 November 2026.
- [REFERENCE] DeepSeek EPLB — the expert-parallel load balancer algorithm
- [REFERENCE] DeepSeek profile data — two-batch overlap traces from DeepSeek’s own serving
- [REFERENCE] vLLM — expert parallel deployment (EPLB, DBO, backends)
- [REFERENCE] SGLang — expert parallelism (overlap, EPLB, backends)
- [EMERGING] vLLM — Serving DeepSeek-V4.1-Flash with P/D disaggregation and Wide-EP on GB300 NVL72 (October 2026) — project’s own benchmark
- [ESTABLISHED] Gale et al., “MegaBlocks: Efficient Sparse Training with Mixture-of-Experts” (2022) — dropless MoE and block-sparse kernels