On this page
Many of the strongest open models are mixtures of experts (MoE). They have hundreds of billions of parameters, but each token only uses a small fraction of them. That gives them an unusual performance profile: compute like a small model, memory like a big one, and behaviour that changes sharply with batch size.
This guide explains how MoE layers work, works through what they mean for speed and memory with real model numbers, and covers the serving problems they create: expert parallelism, all-to-all communication and load balance.
#How an MoE layer works
In a dense transformer, every token goes through the same MLP in each layer. In an MoE model, the MLP is replaced by many experts (separate MLPs) and a small router. For each token, the router scores the experts and sends the token to the top of them (often 2 to 8 out of dozens or hundreds). The outputs are combined, weighted by the router's scores.
Experts per layer
Experts used per token (top-k)
Weight precision
Memory to hold it
93 GB
all 46.7B parameters, always
Active per token
12.9B
28% of the total
Sparse advantage left
72%
faster than a dense model of the full size
At batch 1 the step reads only the chosen experts, so it costs the same as a small dense model.
Memory-bound decode: step time = bytes read ÷ 3.35 TB/s. Model: 1.6B shared parameters plus 45.1B in experts, split evenly (a Mixtral-like layout). Expert tokens are drawn at random; real routers are less even.
So a model can have, say, 600B total parameters but only around 30B active parameters per token. Attention layers are usually shared (dense), and some designs add a shared expert that every token uses.
Routing happens per token and per layer. The same token can go to different experts in layer 10 and layer 11, and neighbouring tokens in a sentence often go to different experts. Experts don't specialise in neat human topics like "maths" or "French"; their specialisations are learned and usually hard to interpret.
#Some real MoE models
| Model | Total parameters | Active per token | Experts per layer | Chosen per token |
|---|---|---|---|---|
| Mixtral 8x7B | 46.7B | 12.9B | 8 | 2 |
| Qwen3-235B-A22B | 235B | 22B | 128 | 8 |
| DeepSeek-V3 | 671B | 37B | 256 routed + 1 shared | 8 routed + the shared one |
| gpt-oss-120b | 117B | 5.1B | 128 | 4 |
The trend is towards many small experts with several chosen per token, which gives the router finer control and spreads load more evenly than a few big experts.
#What that means for inference
Compute per token follows active parameters. Prefill FLOPs are about . DeepSeek-V3 prefills at roughly the cost of a 37B dense model, not a 671B one.
Memory follows total parameters. All experts must be loaded, because any token might need any expert. DeepSeek-V3 needs about 671 GB in FP8 for weights alone: more than the 640 GB of a node of eight 80 GB H100s, but within a node of eight H200s (141 GB each) or B200s.
Decode speed depends on batch size, and this is the subtle part.
#Worked example: how many experts does a decode step touch?
At batch 1, a decode step reads the shared weights plus only the experts the token chose in each layer. At larger batches, different tokens choose different experts, and the step must read every expert that any token chose.
If routing were uniform and random, the expected number of distinct experts used in one layer by tokens is:
For DeepSeek-V3 ( routed experts, ), with roughly 650B of its 671B parameters in routed experts and about 18B in shared parts, in FP8:
| Batch size | Experts touched per layer | Share of experts | Weights read per step | Per token |
|---|---|---|---|---|
| 1 | 8 | 3% | about 38 GB | about 38 GB |
| 8 | about 57 | 22% | about 164 GB | about 21 GB |
| 32 | about 163 | 64% | about 435 GB | about 14 GB |
| 128 | about 252 | 98% | about 660 GB | about 5 GB |
| 512 | 256 | 100% | about 671 GB | about 1.3 GB |
Real routing isn't uniform, so treat these as rough, but the pattern holds:
- At batch 1, MoE is fast: bytes per token track active parameters, like a 37B model.
- By batch 128, nearly every expert is read every step. The step costs about as much as a 671B dense model's weight read, but it's shared across 128 tokens.
- Each token still does only the active FLOPs, so at large batch the compute per step is much smaller than a dense 671B model's would be.
That combination is why MoE serving is efficient at scale, but only if you can batch. At medium batch sizes (8 to 64), MoE models are in an awkward middle: each step reads many experts, but each expert processes only a handful of tokens, so the expert matrix multiplies are small and inefficient.
#Expert parallelism and all-to-all
Because the total weights are huge, experts are spread across GPUs: expert parallelism. Each token's hidden state must travel to the GPUs holding its chosen experts and come back:
- Dispatch: an all-to-all sends tokens to the GPUs that own their experts.
- Expert compute: each GPU runs its experts on the tokens it received, usually as one grouped matrix multiply.
- Combine: another all-to-all sends results back, where they're weighted and summed.
That's two all-to-alls per MoE layer per step. With 58 MoE layers, that's over 100 all-to-alls per decode step. Within a node over NVLink this is manageable; across nodes over InfiniBand it can dominate, so large deployments put a lot of effort into fast interconnects, overlapping communication with compute, and specialised dispatch and combine kernels (DeepSeek's open-source DeepEP library is one example).
A common layout for large MoE models:
- Attention: data parallel (each GPU handles its own requests' attention) or tensor parallel within a node.
- Experts: expert parallel across all GPUs in the deployment, sometimes 32 to 128 of them ("wide EP").
- Prefill and decode on separate pools, since they want very different batch sizes and parallelism (disaggregation explained).
#The load-balance problem
Routers don't spread tokens evenly. If one expert gets twice its share in a batch, the GPU holding it takes twice as long, and every other GPU waits. Tail latency follows the busiest expert.
Mitigations:
- Training-time balancing, so routers spread load more evenly. Some recent models use balancing methods that don't add an extra loss term, which avoids hurting quality.
- Redundant experts: duplicate the most popular experts on extra GPUs, chosen from observed routing statistics.
- Capacity limits, which cap tokens per expert (with some quality cost if tokens get dropped or rerouted).
- Large batches, which average out routing noise.
Monitor per-GPU expert load in production. Traffic changes (a new language, a new kind of task) can shift which experts are popular.
#Sizing an MoE deployment
- Memory: total parameters times bytes per weight, plus KV cache, decides the minimum number of GPUs.
- Prefill compute: active parameters times tokens, like a dense model of the active size.
- Decode bandwidth: at your batch size, estimate how many distinct experts a step touches (the table above), and read those weights.
- Communication: all-to-all traffic per step grows with batch size times hidden size times .
- Latency target: decides how big a batch you can run, which in turn decides how efficiently you use the experts.
MoE models also often use compressed attention such as MLA, which keeps the KV cache small: about 69 KiB per token for DeepSeek-V3 in 16-bit (GQA vs MQA vs MLA). So memory goes mostly to weights, and a node that holds the weights can hold a lot of context.
#MoE on a single machine
MoE's low active-parameter count makes it attractive locally, as long as the whole model fits in memory:
- Unified-memory machines (Macs, 128 GB mini PCs) are well suited: lots of memory, modest bandwidth, and a model that reads only a few billion parameters per token (DGX Spark vs Mac Studio vs Strix Halo).
- A GPU plus lots of system RAM works with llama.cpp by keeping attention and shared weights on the GPU and the experts in RAM. Only the chosen experts are read from RAM each token, so speed stays usable:
llama-server -m model.gguf -ngl 99 -ot ".ffn_.*_exps.=CPU" -c 16384The -ot (override tensor) pattern sends the expert tensors to the CPU; recent versions also offer simpler flags for the same thing. Check your version's help.
#Common mistakes
- Sizing memory from active parameters. You must hold all of them.
- Benchmarking MoE at batch 1 and expecting the same per-token cost at batch 256, or the reverse.
- Ignoring expert load balance in tail latency.
- Running expert parallelism over slow links without measuring all-to-all time.
- Using tensor parallelism for experts by habit. Splitting many small experts across GPUs creates tiny matrix multiplies; expert parallelism is usually better.
#FAQ
Is a 671B MoE model "better" than a 70B dense model? Usually more capable, because it holds far more parameters, at a per-token compute cost closer to a 37B model. The price is memory and serving complexity.
Why not make every model MoE? At small scale and small batch, the memory cost and engineering complexity outweigh the compute savings. MoE pays off most when you serve at scale with large batches.
Do quantisation and MoE mix? Yes. Experts are often quantised aggressively (FP8, FP4 or lower) because they hold most of the bytes, while attention stays at higher precision. Validate quality on your tasks.
#Go deeper
The mixture of experts lesson covers routing, expert parallelism and the batch-size maths with an interactive explorer, and serving a trillion-parameter hybrid MoE works through a full deployment. For the parallelism options in general, see tensor vs pipeline vs data vs expert parallelism.
moemixture-of-expertsservingparallelisminference-engineering
Found this useful?
Send it to someone who is learning the same thing.
Preparing for an interview?
Next: learn it step by step, free
Capacity planning and cost
Turn traffic and latency targets into a GPU count and a monthly bill. A free lesson with step-through diagrams and a quiz.