# What Is a Mixture-of-Experts Model?

> How a router picks a few experts for each token, why the model is cheap to run but heavy to store, and the trade-offs, explained for your AI interview.

**In short:** A Mixture-of-Experts (MoE) model splits the feed-forward part of a layer into several expert sub-networks and sends each token to only a few of them. The whole model is large to store, but each token only pays for the experts it uses, so it runs cheaper than a normal (dense) model of the same size.

AI and LLM interview question Q026, LLM fundamentals. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-a-mixture-of-experts-model

## Say it in 30 seconds

A Mixture-of-Experts model is split into many expert sub-networks. For each token, a small router picks two of the eight experts in each Mixtral layer and mixes their answers. The other six do no work for that token, so each token is cheaper to process. But every expert still has to sit in memory, so the model is heavy to serve. And the experts are not neat topic specialists. For a team, I'd treat it as more capacity for the work per token, with a bigger memory bill.

## Say it in 2 minutes

A normal, or dense, model uses every one of its weights for every token it reads. A Mixture-of-Experts model, or MoE, cuts the feed-forward block of a layer into many expert sub-networks. A small learned router looks at each token and picks a few experts to do the work. Shazeer and colleagues brought a sparsely-gated version of this layer to large networks in 2017, and Mistral's Mixtral is a well-known example.

Here is why it is worth it. Mixtral has 47B parameters in total, but only 13B are active for each token, so the work per token is far smaller than the model's size. The catch is memory. All the experts have to be stored to serve the model, and routing adds overhead. So the memory bill follows the full size of the model, and the work for each token follows the experts that run.

Experts are not neat topic specialists. The Mixtral authors looked at text from different domains and saw no obvious pattern by topic. The paper says the expert choice appears to follow syntax more than the domain, so I would not explain it to a team as one expert per subject.

When someone asks me about MoE, I say three things: the router picks a few experts per token, the work per token is low, and memory and routing are the costs. Then I would measure latency and memory on our own hardware before choosing it.

## What is a Mixture-of-Experts model, in plain words?

A language model breaks your text into tokens, small pieces such as words or parts of words, and works through them layer by layer. In a dense model, every weight in a layer works on every token. A Mixture-of-Experts model, or MoE, splits the feed-forward block of a layer (the weights that transform each token) into many expert sub-networks, and sends each token to only a few of them.

Think of a hospital triage desk. A triage nurse does not send every patient to every specialist. A chest pain case goes to cardiology and a broken wrist to orthopaedics, and only those two teams spend time on it. An MoE model does the same for each token: a router sends it to two of eight experts in a layer, and the other six do no work for that token.

- **Expert:** One of several smaller sub-networks inside a layer, each with its own weights.
- **Router:** A small learned part that scores the experts for each token and picks the top few.
- **Token:** A small piece of text, such as a word or part of a word, that the model works on.
- **Active parameters:** The weights that actually run for one token. In an MoE model, that is far fewer than the total.
- **Dense model:** A model where every weight works on every token.

## How does a Mixture-of-Experts layer work?

In a transformer, each layer has a block of feed-forward weights that transforms every token. An MoE layer swaps that one block for many smaller blocks, called experts, with a router in front. The Mixtral paper says each of its layers holds eight feed-forward blocks, which it calls experts.

*Diagram, One token through one Mixture-of-Experts layer: One token through one MoE layer, with made-up router weights. Only the two picked experts do work for this token. Their outputs are mixed by weight, and the result moves on.*
1. The token reaches the router first.
2. Top choice: Expert 2, the highest score, with weight 0.6.
3. Second choice: Expert 5, with weight 0.4. The other six stay idle.
4. Expert 2's answer joins the mix at 60%.
5. Expert 5's answer joins the mix at 40%.

1. **Score:** The router gives every expert a score for this token.
2. **Pick:** It keeps the top two. Mixtral's router picks two of its eight experts for each token.
3. **Mix:** The two chosen experts process the token, and their answers are blended by weight.
4. **Move on:** The blended result goes to the next layer, and the cycle repeats.

Mistral says the router is trained with the experts: "we train experts and routers simultaneously".

> "A trainable gating network determines a sparse combination of these experts to use for each example." (Shazeer and colleagues, 2017)
>
> "For every token, at each layer, a router network selects two experts to process the current state and combine their outputs." (Mixtral paper, 2024)

## What does it save, and what does it cost?

The Switch Transformer paper starts from the usual setup: "In deep learning, models typically reuse the same parameters for all inputs." MoE breaks that habit by selecting different parameters for each incoming example.

- **Saves: Less work per token.** Only the picked experts run, so the work per token stays low even when the total size grows.
- **Costs: Memory for every expert.** Every expert must be stored and served, so the memory bill follows the full size, not the active part.
- **Costs: Routing adds overhead.** The router and the sending of tokens to experts add work that a dense model does not have.

*Diagram, Dense model against Mixture-of-Experts, per token: A dense model runs every weight for each token, so its work per token grows with its size. A Mixture-of-Experts model runs only the picked experts, so its work per token stays low. Both still store the full model.*
1. A dense model pushes each token through all of its weights.
2. A Mixture-of-Experts model pushes it through only the picked experts.

The Switch Transformer paper says that "widespread adoption has been hindered by complexity, communication costs and training instability", and it sets out simpler routing to help.

> "the SMoEs layer introduces additional overhead due to the routing mechanism and due to the increased memory loads when running more than one expert per device" (Mixtral paper, 2024)

## What do the numbers look like for a real model?

The Mixtral paper, submitted in January 2024, describes Mixtral, a Sparse Mixture of Experts (SMoE) language model. Each layer has eight experts, and a router sends each token to two of them. The model has 47B parameters in total, but only 13B are active for each token.

Take a made-up hospital that runs such a model itself, to summarise discharge notes. Each token costs roughly the work of its 13B active parameters, but the server must hold all 47B weights in memory. So the GPU is sized for the full model, while much of the per-token work follows the active part.

Here is a tiny router with made-up scores. It picks two of eight experts for each of four tokens, then counts the runs.

```python
import math
EXPERTS = 8
TOP_K = 2
# Made-up router scores: one per expert, for four tokens of a claims note.
SCORES = {
    "water": [0.1, 2.3, 0.2, 0.4, 1.9, 0.0, 0.3, 0.5],
    "damage": [1.8, 0.2, 0.1, 2.5, 0.3, 0.4, 0.2, 0.1],
    "invoice": [0.2, 0.1, 2.0, 0.3, 0.2, 2.2, 0.4, 0.6],
    "approved": [0.3, 0.4, 0.2, 0.1, 0.5, 0.2, 2.4, 1.1],
}
def softmax(scores):
    top = max(scores)
    exps = [math.exp(s - top) for s in scores]
    total = sum(exps)
    return [e / total for e in exps]
def route(token):
    probs = softmax(SCORES[token])
    picks = sorted(range(EXPERTS), key=lambda i: probs[i], reverse=True)[:TOP_K]
    total = sum(probs[i] for i in picks)
    return [(i + 1, round(probs[i] / total, 2)) for i in picks]
runs = 0
for token in SCORES:
    picks = route(token)
    runs += len(picks)
    print(token, "->", picks)
print("expert runs:", runs, "of", EXPERTS * len(SCORES), "possible")
```

Output:

```text
water -> [(2, 0.6), (5, 0.4)]
damage -> [(4, 0.67), (1, 0.33)]
invoice -> [(6, 0.55), (3, 0.45)]
approved -> [(7, 0.79), (8, 0.21)]
expert runs: 8 of 32 possible
```

The demo runs 8 expert slots out of 32 possible. That is a quarter of the expert work. The other six experts sit idle for each token, but they still take up memory.

## Are the experts topic specialists?

Many beginners say each expert handles one subject, such as maths or code. The Mixtral paper tested text from different domains, and it found that "Surprisingly, we do not observe obvious patterns in the assignment of experts based on the topic."

The paper adds that the choice of experts "appears to be more aligned with the syntax rather than the domain". The selected experts "can be different at each timestep". So the router learns its own split, which is not a tidy set of subject experts.

> **Tip:** Asked about specialists? Say the router learns its own split, and that it can change from token to token. Don't promise one expert per subject.

### How would you choose between a dense and an MoE model for a bank?

I would start with the real traffic: how many questions per minute, how long the answers run, and how much GPU memory we own. An MoE model can be cheaper per token, but only if all of its weights fit on the hardware we have.

Then I would test both on our own policy questions, not on public benchmarks, and measure latency, because routing adds overhead. If the dense model fits and is fast enough, I would pick the simpler one.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: many expert sub-networks, and a router that picks a few per token.
- [ ] Why it is cheaper per token: only the picked experts run.
- [ ] The cost: every expert must sit in memory, and routing adds overhead.
- [ ] Experts are not tidy topic specialists.
- [ ] When it fits: more capacity for the work per token, if you can serve the memory.
- [ ] Honest about limits: measure on your own traffic before choosing.

**Common traps**

- Trap: "Each expert is a specialist in one subject." Better: Not in any tidy way. The Mixtral paper found no obvious pattern by topic; the expert choice seems tied to syntax more than subject.
- Trap: "An MoE model is smaller, so it is cheaper to host." Better: It is cheaper per token. Storage is the cost: all the experts must fit in memory.
- Trap: "Every expert runs for every token." Better: Only the picked experts run. The rest sit idle for that token, but they still take up memory.

## Can you spot the wrong statement?

**Spot the wrong statement:** A team plans a self-hosted MoE model with eight experts per layer and two active per token. Which statement is wrong?

A. The router scores all eight experts for each token.
B. The GPU budget only has to hold the two active experts, since the rest stay idle.
C. Each token uses about a quarter of the expert work in that layer.
D. The experts and the router are trained together.

**Answer:** B. Idle experts still take up memory. A served MoE keeps every expert loaded, so the memory bill follows the full size of the model, while the work per token follows the active part.

**Quick check:** An insurance claims triage agent runs an MoE model with 8 experts per layer and 2 picked per token. Which statement is true?

A. Each token runs all eight experts.
B. Each token runs about a quarter of the expert work in that layer.
C. Only the two picked experts need memory on the server.
D. The same two experts are picked for every token on a given topic.

**Answer:** B. Two of eight is a quarter of the expert work. Memory still holds all eight, and the picks can change from token to token.

## Can you answer these from memory?

**Flash cards**

- **What is a Mixture-of-Experts model?** A model split into many expert sub-networks. A router picks a few for each token.
- **What is the router?** A learned scorer that picks which experts run for each token.
- **Why is it cheaper per token?** Only the picked experts run. The rest sit idle for that token.
- **What is the main cost?** All experts must sit in memory, and routing adds overhead.
- **Are experts topic specialists?** Not in any tidy way. The Mixtral paper found no obvious pattern by topic.
- **Who described the sparsely-gated MoE layer for large networks?** Shazeer and colleagues, in a 2017 paper on arXiv.

## Likely follow-up questions

- Q025 Open-weight vs closed API models: trade-offs? https://designervenkat.online/interview/ai/open-weight-vs-closed-api-models
- Q027 What is a reasoning ("thinking") model? https://designervenkat.online/interview/ai/what-is-a-reasoning-model
- Q028 What is test-time compute? https://designervenkat.online/interview/ai/what-is-test-time-compute
- Q030 Why are input and output tokens priced differently? https://designervenkat.online/interview/ai/why-are-input-and-output-tokens-priced-differently
- Q036 When is a small language model enough? https://designervenkat.online/interview/ai/when-is-a-small-language-model-enough
