What is a mixture of experts model?

4 min readMarkdown

A mixture of experts model, or MoE, splits most of its weightsWeightsThe full set of a model's parameters, stored in a file.Read more into many smaller blocks called experts. For each tokenTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more, a small router picks a few of them and skips the rest. A dense model has no such split, and every weight runs for every token.

Only part of an MoE model runs per token

MoE models list two sizes. Total parametersParameterOne learned number inside a model. An 8B model has about eight billion of them.Read more is everything in the file, and active parameters is what runs for each token. gpt-oss-120b has about 117B total and about 5B active.

The router decides afresh for every token and in every layer. One token might go to experts 3 and 17, the next to 8 and 41.

Over a whole answer, most experts get used. For any single token, most sit idle.

Some weights are shared and always run, such as the attention layers. The active count includes those. So "5B active" means about 5 billion weights are read for each token, out of 117 billion stored.

Dense

Every parameter runs for every token. Speed and memory both follow the full size.

Mixture of experts

A few experts run per token. Memory follows total size, and speed follows active size.

Why a 120B MoE can decode faster than a 70B dense model

Writing a token means reading the weights it needs out of memory. That makes decodeDecodeThe phase where the model writes its answer one token at a time. Limited by memory bandwidth.Read more speed a matter of how many bytes move per token, as What makes a model fast? explains. A dense 70B at 4-bit reads about 42 GB for every token. gpt-oss-120b reads only its active part, a few GB.

On an M5 Max Mac Studio, the numbers come out like this.

ModelTypeMemory neededMeasured decode speed
70B at Q4Denseabout 42 GBabout 13 tok/s
gpt-oss-120bMoE, about 5B activeabout 61 GBabout 76 tok/s

The MoE is larger on disk and several times faster. It reads far fewer bytes per token, and on the same memory system that is all that counts.

Rule of thumb

Size an MoE by total parameters. Estimate its speed by active parameters.

Quality sits between the two numbers. An MoE with 120B total and 5B active usually beats a 5B dense model by a wide margin. It does not always match a dense model of its full size. Which size of model do I need? places both kinds by class.

You still need the memory for all of it

The router picks different experts for every token, and nobody knows in advance which. So every expert has to sit in fast memory, ready. A 120B MoE needs the memory of a 120B model, even though it runs like a much smaller one.

That makes MoE models a natural fit for machines with lots of memory and modest bandwidth, such as 128 GB Macs and Are the big unified-memory boxes worth it?. They have room to hold the whole model, and the small active size keeps decode quick.

On a PC with a 24 GB graphics card, the picture is harder. The model does not fit on the card, and offloadingOffloadRunning part of a model on the CPU because it does not fit in VRAM.Read more the rest to system RAM slows it down. MoE models handle this better than dense ones, because only the chosen experts are read from RAM for each token. Will the model fit in my memory? covers offloading.

The catch

PrefillPrefillThe phase where the model reads your prompt. Limited by compute.Read more does not get the same discount. Reading a long prompt sends tokens to many different experts at once, so more of the model is in play. An MoE can stream answers quickly and still make you wait on a long prompt, especially on machines with modest compute.

Try it

Look up two models in your runtimeRuntimeThe software that loads a model file and runs it.Read more's model page, one dense and one MoE, with similar file sizes. Run both with --verbose in Ollama on the same short prompt and compare the eval rate each one prints.

Go deeperThat's enough

How the router works

Each MoE layer has a small router network. It scores every expert for the current token, keeps the top few, and blends their outputs by those scores. The router is trained along with the experts, so experts drift towards handling different kinds of tokens.

The name suggests specialists in law or biology. In practice the specialisation is murkier, more about token types and patterns than topics.

Expert offloading

Because experts are large and only a few run per token, some runtimes can keep the shared layers on the GPU and the experts in system RAM. That keeps the parts that run every time on fast memory. It is how people run large MoE models on a single gaming GPU plus plenty of RAM. How do I make it faster? covers the settings.

Why serving MoE is different

With many users, different tokens in a batch want different experts. A server has to keep all experts busy and balanced, which is harder than batching a dense model. That is why large MoE models on servers are often spread across several GPUs by expert, covered in How do several GPUs in one box work together?.