What Is Mixture of Experts (MoE) in LLMs? Explained Simply
Mixture of experts (MoE) lets an LLM route each token to a few expert sub-networks, so it uses only part of its parameters at a time. Learn how routing works, total vs active parameters, and the trade-offs.
Short answer: Mixture of experts (MoE) is a neural network design in which a small router sends each token to only a few of many "expert" sub-networks instead of through the whole model. That lets an LLM hold a very large number of parameters while using only a fraction of them for each token, which saves computation but not memory.
Mixture of experts explained: what is the main idea?
The main idea of mixture of experts is that not every part of a model needs to work on every token. In a normal dense model, every parameter is used for every token. In an MoE model, some layers are split into several experts, and a router picks which few experts handle each token.
Inside a transformer, each block has an attention part and a feed-forward part. MoE models usually replace the feed-forward part with a set of expert feed-forward networks plus a router. Attention and the other parts stay shared by all tokens.
How does the router choose experts?
The router, also called the gating network, is a small learned layer that gives every expert a score for the current token. The model keeps the top few experts, often one or two, runs the token through them, and combines their outputs, weighted by the router's scores. This happens separately for each token and in each MoE layer, so two words in the same sentence can go to different experts.
This toy NumPy script shows one routing step with 8 experts and top-2 routing. The numbers are random; in a real model the router and experts are learned during training.
import numpy as np
rng = np.random.default_rng(0)
num_experts, top_k, dim = 8, 2, 4
token = rng.normal(size=dim) # one token's vector
router = rng.normal(size=(dim, num_experts)) # learned in a real model
experts = [rng.normal(size=(dim, dim)) for _ in range(num_experts)]
scores = token @ router # one score per expert
chosen = np.argsort(scores)[-top_k:] # the 2 highest-scoring experts
weights = np.exp(scores[chosen]) / np.exp(scores[chosen]).sum()
# Only the chosen experts do any work for this token
output = sum(w * (token @ experts[i]) for w, i in zip(weights, chosen))
print("Experts used:", chosen, "weights:", weights.round(2))
print("Output:", output.round(2))Only 2 of the 8 expert matrices were used for this token. The experts are not assigned topics by hand; whatever specialisation they develop is learned, and it often does not match neat human subjects like "maths" or "history".
What do total and active parameters mean?
Total parameters are all the weights stored in an MoE model; active parameters are the ones actually used for one token. Here is a hypothetical model with made-up round numbers, not any real model:
Part | Parameters stored | Used per token |
|---|---|---|
Shared parts (attention, embeddings, etc.) | 2 billion | 2 billion |
Experts: 8 experts of 1 billion each, top-2 routing | 8 billion | 2 billion |
Total | 10 billion | 4 billion active |
For each token, this model does roughly the work of a 4-billion-parameter dense model, yet it can draw on 10 billion parameters of learned knowledge. But all 10 billion must still be loaded into memory, because the next token may need different experts. Parameters are counted per token, which is why routing happens token by token.
Dense model vs mixture of experts: what are the trade-offs?
A mixture of experts model trades simpler engineering for more capacity per unit of computation:
Aspect | Dense model | Mixture of experts |
|---|---|---|
Parameters used per token | All of them | Shared parts plus a few experts |
Computation per token | Grows with total size | Grows with active size |
Memory needed | All parameters | Still all parameters |
Training | Simpler | Needs load balancing; can be less stable |
Serving | Simpler | Experts may sit on different devices, adding communication |
Load balancing is the main training difficulty. A router can learn to send most tokens to a few favourite experts, leaving others unused. Training therefore usually adds an extra balancing objective and limits how many tokens one expert can take at a time.
Is a mixture of experts model the same as a small model?
No. A mixture of experts model is usually a large model that spends less computation per token, while a small model simply has fewer parameters in total. If you want to run a model on your own computer, an MoE model still needs enough memory for every expert. For the size question itself, see small language models vs LLMs.
Common mistakes
Thinking each expert is a subject specialist. Specialisation is learned and rarely that tidy.
Assuming MoE needs less memory. It needs less computation per token, not less memory.
Comparing models by total parameters only. For MoE, also look at active parameters.
Confusing MoE with multi-agent systems or ensembles. MoE is one model and one forward pass; the routing happens inside its layers.
Frequently Asked Questions
Is mixture of experts a new idea?
No. Mixtures of experts were studied in the early 1990s. A widely cited step towards today's use was a 2017 paper on sparsely-gated mixture-of-experts layers (Shazeer and colleagues), which applied the idea to very large neural networks.
Do MoE models always give better answers?
No. MoE is a way to use computation efficiently, not a guarantee of quality. A well-trained dense model can beat a poorly trained MoE model, so compare models on your own tasks.
What is top-k routing?
Top-k routing means the router keeps only the k experts with the highest scores for each token, for example k = 2. A smaller k means less computation per token.
Can you fine-tune a mixture of experts model?
Yes, MoE models can be fine-tuned, but you still need memory for all the experts, and keeping the routing balanced adds some extra care compared with a dense model.
Key Takeaway
Mixture of experts lets an LLM store many parameters but use only a few experts per token, chosen by a learned router. It saves computation, not memory, and it brings its own training and serving challenges.
Ready to start? You will learn how modern LLM systems are built, evaluated and deployed, including the trade-offs behind model choice. Begin with the free course AI Engineering with LLMs: Advanced.
Related articles
More in LLM
What Hardware Do You Need to Run a Local LLM?
Local LLM hardware requirements come down to memory. Learn the parameters × bytes rule, a worked 7B example, how quantization helps, and whether you need a GPU.
6 min readNov 30, 2026What Is a Reasoning Model? How "Thinking" AI Works
A reasoning model is an LLM that writes out intermediate thinking before it answers. Learn how it works, when it helps, and why it is slower and uses more tokens.
6 min readNov 28, 2026Small Language Models vs LLMs
What a small language model (SLM) is, how it differs from a large language model, and how to choose between them for cost, privacy and quality.
4 min readNov 24, 2026What Is a Transformer? Attention Explained Simply
A plain-English guide to the transformer, the design behind modern language models: what attention means, how it works step by step, and a tiny Python example you can run.
5 min readNov 18, 2026What Are Open-Source LLMs? Run One Locally With Ollama
What open-source LLMs are, why people run them locally, and how Ollama lets you download and use one with a few commands.
3 min readNov 9, 2026What Are Top-k and Top-p in LLMs? How Do They Control AI Output?
Top-k and Top-p are sampling techniques that control which candidate tokens an LLM can choose from during generation. Understanding them is important for controlling creativity, diversity, and consistency in AI applications.
2 min readAug 30, 2026
Comments
Sign in to join the discussion.


