What is a mixture of experts (MoE) model?
A mixture of experts (MoE) model replaces one large feed-forward layer with many smaller networks, called experts, and a router that sends each token to only a few of them. The model can hold far more parameters than it uses for any single token. Compute per token depends on how many experts run, while total capacity depends on how many exist.
MoE layers sit inside the transformer blocks of many large language models, including Switch Transformer, Mixtral 8x7B and DeepSeek-V3. They let a lab train a model with hundreds of billions of parameters at roughly the per-token cost of a much smaller dense model. The price is memory and engineering: every expert must be stored, the router has to spread work evenly, and the experts are usually split across many GPUs.
Key ideas
- An MoE layer replaces a transformer's feed-forward block with many experts and a router.
- The router is a linear layer and a softmax that scores every expert for each token.
- Only the top-k experts run, and their outputs are mixed by the gate weights.
- Total parameters grow with the number of experts, while compute per token grows with k.
- An auxiliary loss or a routing bias keeps the load spread evenly across experts.
- Every expert must sit in memory, so MoE models trade memory for cheaper compute per token.
Common questions
Is an MoE model the same as an ensemble?
No. An ensemble runs several full models on every input and averages their predictions. An MoE runs one model in which each layer picks a few experts per token, and the experts are trained together with the router. The choice happens inside the network, token by token, not once per input.
Do MoE experts specialize in topics like math or code?
Not in a way people would recognize. The Mixtral authors found that expert choice was almost the same for arXiv papers, biology abstracts and philosophy texts. Routing followed token type and syntax more than subject, so an expert is better seen as a learned slice of the feed-forward layer than as a specialist.
Why are MoE models hard to fine-tune and serve?
The full parameter set must fit in GPU memory even though few experts run per token. Routing can shift during fine-tuning, which can unbalance the load or overfit small datasets. Serving needs expert parallelism and communication between GPUs, and small batches leave most experts idle while still holding them in memory.
Does MoE make inference faster?
Per token, an MoE does about as much arithmetic as a dense model of its active size, so it can be faster than a dense model of its total size. At small batch sizes decoding is limited by memory reads, and reading a few experts is cheaper than reading a full dense layer. At large batch sizes most experts are read anyway, and the speed gain depends on how well the system spreads tokens across GPUs.
Related explainers
- The Transformer Architecture — A visual guide to 'Attention Is All You Need'
- Decoder-Only Transformers — The architecture behind GPT and modern LLMs
- Softmax, Logits & Temperature — Turning raw scores into probabilities
- KV Cache — Why LLM generation caches keys and values, and what it costs
- Quantization — Shrinking model weights to 8 and 4 bits
- Sampling: Temperature, Top-k & Top-p — How a language model picks its next token
References
- Shazeer et al. (2017), "Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer"
- Fedus, Zoph and Shazeer (2021), "Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity"
- Jiang et al. (2024), "Mixtral of Experts"
- DeepSeek-AI (2024), "DeepSeek-V3 Technical Report"
- Gale et al. (2022), "MegaBlocks: Efficient Sparse Training with Mixture-of-Experts"
Last updated