What is mixture of experts?
A mixture-of-experts (MoE) model replaces the feed-forward block in its transformer layers with several parallel blocks, called experts, plus a small router. For each token at each MoE layer, the router scores the experts, sends the token through the top few, usually one or two, and sums their outputs weighted by those scores. The model stores far more parameters than any single token uses: Mixtral 8x7B holds 47B parameters and runs 13B per token.
What does a mixture-of-experts layer do?
In a dense transformer, every token passes through the same feed-forward block in every layer. An MoE layer keeps several copies of that block with separate weights, the experts, and adds a router: a single linear layer that turns the token's hidden state into one score per expert. The layer keeps the top-K scores, softmaxes them into weights, runs the token through those K experts only, and adds up their outputs using the weights. The other experts do no work for that token.
The idea is older than today's LLMs. Shazeer et al. (2017) introduced the sparsely-gated MoE layer with a trainable gating network that picks a sparse combination of up to thousands of experts per example. The Switch Transformer (2021) cut K to 1 and reported that routing each token to a single expert kept quality while reducing routing cost. Mixtral 8x7B uses 8 experts and K = 2, and replaces every feed-forward block with an MoE layer; attention and embeddings stay dense and shared.
In code, the two numbers you care about sit in the model config. Hugging Face Transformers' MixtralConfig calls them num_local_experts (8 experts per layer in the released checkpoint) and num_experts_per_tok (the top-K, 2 experts per token).
Total parameters vs active parameters
Model cards and launch posts quote MoE sizes loosely, and the two numbers measure different costs. The Mixtral paper calls them the sparse parameter count (every weight the model stores) and the active parameter count (the weights one token passes through). Per-token compute is proportional to the active count; the memory to serve the model is proportional to the sparse count. Mixtral 8x7B is 47B total and 13B active, so it computes each token like a 13B dense model and needs the memory of a 47B one.
The name misleads in a second way. "8x7B" suggests 56B, but only the feed-forward blocks are replicated eight times. Attention, embeddings and the output head exist once, which is why the total lands at 46.7B. When you compare an MoE model against a dense one, check which count each side is quoting before you read anything into the comparison.
What changes when you serve an MoE model?
All experts have to be loaded, because the router can pick a different pair for every token at every layer. You size GPU memory for the total count, and quantization shrinks that footprint the same way it does for a dense model. The saving is in compute per token; memory stays at the full model size.
The Mixtral authors say MoE layers add overhead from routing and from the extra memory loads of running more than one expert per device, and that they suit batched workloads where the hardware reaches good arithmetic intensity. Across a batch, different tokens hit different experts, so a large batch keeps most experts busy. Serving stacks spread experts across GPUs with expert parallelism, which ships each token to the GPU that holds its expert and back; uneven routing then overloads some GPUs while others wait.
Training has to fight the same imbalance. The Switch Transformer adds an auxiliary load-balancing loss to push the router toward an even spread, and gives each expert a fixed capacity; tokens past that capacity are dropped and skip the layer through the residual connection. In Transformers, router_aux_loss_coef weights that loss, and the model only returns it when you set output_router_logits.
Are the experts specialists?
The name suggests topic specialists, and the Mixtral routing analysis did not find them. When the authors checked which experts handled text from ArXiv, PubMed, PhilPapers, GitHub and other sources, they found no obvious topic patterns: the distribution was very similar across domains, with DM Mathematics as a marginal exception. Routing looked more aligned with syntax, for example self in Python and Question in English often went to the same expert. You cannot pick out a code expert or a medical expert and call it on its own.
Total vs active parameters, computed from Mixtral's config.json
# config.json from mistralai/Mixtral-8x7B-v0.1 (fields this script reads)
# "hidden_size": 4096, "intermediate_size": 14336, "num_hidden_layers": 32,
# "num_attention_heads": 32, "num_key_value_heads": 8, "vocab_size": 32000,
# "num_local_experts": 8, "num_experts_per_tok": 2
import json
c = json.load(open("config.json")) # mistralai/Mixtral-8x7B-v0.1
d, L, V = c["hidden_size"], c["num_hidden_layers"], c["vocab_size"]
head = d // c["num_attention_heads"]
attn = 2 * d * d + 2 * d * c["num_key_value_heads"] * head # q, o, k, v
expert = 3 * d * c["intermediate_size"] # SwiGLU: gate, up, down
router = d * c["num_local_experts"]
embed = 2 * V * d # input embeddings + lm_head
total = L * (attn + router + c["num_local_experts"] * expert) + embed
active = L * (attn + router + c["num_experts_per_tok"] * expert) + embed
print(f"experts per layer : {c['num_local_experts']}, routed per token: {c['num_experts_per_tok']}")
print(f"total parameters : {total / 1e9:.1f}B (what you load into memory)")
print(f"active per token : {active / 1e9:.1f}B (what each token computes through)")
print(f"bf16 weights : {total * 2 / 2**30:.0f} GiB")
$ python3 moe_params.py
experts per layer : 8, routed per token: 2
total parameters : 46.7B (what you load into memory)
active per token : 12.9B (what each token computes through)
bf16 weights : 87 GiB
Both numbers come from one config. num_local_experts sets how many expert blocks each layer stores, which drives the 87 GiB of bf16 weights you must load; num_experts_per_tok sets how many each token runs through, which drives compute. The script skips the small norm weights and still lands on the paper's 47B total and 13B active.
Common questions
Mixture-of-experts models: frequently asked
Is Mixtral 8x7B a 56B-parameter model?
No. It has 46.7B parameters in total. Only the feed-forward blocks are copied eight times; attention, embeddings and the output head are shared, so the total is well under eight times 7B. Each token uses about 12.9B of those parameters.
Does mixture of experts make inference cheaper?
It cuts compute per token, which scales with the active parameter count. It does not cut memory, because every expert must be loaded. The Mixtral paper also notes routing overhead and says MoE layers fit batched workloads better, so the gain shows most in batched serving.
Can I run an MoE model on a GPU sized for its active parameters?
Not with all the weights on that GPU. The router can choose any expert for any token at any layer, so you need room for the total count. For Mixtral 8x7B that is about 87 GiB in bf16; quantizing the weights shrinks that footprint.
Is mixture of experts the same as an ensemble or a multi-agent setup?
No. An ensemble or a set of agents runs several complete models and combines their answers. An MoE model is one network: the router and experts are trained together, routing happens per token inside each layer, and no expert produces an answer on its own.
Sources
Where these facts come from
- Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer (Shazeer et al., 2017): introduces the sparsely-gated MoE layer and the trainable gating network that picks a sparse set of experts per example
- Switch Transformers (Fedus, Zoph and Shazeer, 2021): top-1 routing, expert capacity, dropped tokens and the auxiliary load-balancing loss
- Mixtral of Experts (Jiang et al., 2024): 8 experts with top-2 routing, the 47B sparse and 13B active parameter counts, serving trade-offs and the routing analysis by domain
- Hugging Face Transformers docs: Mixtral: MixtralConfig fields num_local_experts, num_experts_per_tok, output_router_logits and router_aux_loss_coef
- mistralai/Mixtral-8x7B-v0.1 config.json: the released model's configuration, used for the parameter count in the example