FFN & MoE · January 2024
Mixtral-Style Coarse MoE
intermediate
routing
Sparsely activate a small number of large experts per token. Coarser than DeepSeekMoE but operationally simpler — the workhorse design that introduced production MoE to most open-weights users.
§ 1 · Premise
Production MoE before DeepSeekMoE
A dense Llama-2-style 7B decoder uses ~13 GFLOPs per token at the FFN stage and stores all 7B parameters in HBM. A GShard / Switch-style MoE replaces the dense FFN with parallel expert FFNs and a small gating network that picks the top- for each token, so activated parameters scale with while total parameters scale with (Shazeer et al. 2017, eq. 2). The question Mixtral 8x7B (Jiang et al. 2024, arXiv 2401.04088) takes on is not whether sparse MoE works — Switch (Fedus et al. 2021) had already crossed the trillion-parameter line and GShard (Lepikhin et al. 2020) had shown encoder-side scaling — but whether the small-, top-2, full-sized-expert recipe is operationally clean enough to ship as an open-weights flagship.
The 2017–2023 sparse-MoE literature had converged on a recipe sitting roughly at to FFN-sized experts per layer with top-1 or top-2 routing and an auxiliary balance loss on the gate (Fedus et al. 2021, §2.2). The variants disagreed on which expert size and which . Sparse-MoE 2017 used many small LSTM experts; Switch used top-1 over hundreds; GShard used top-2 over hundreds; ST-MoE (Zoph et al. 2022) used top-2 over 64. Mixtral picks the coarsest viable point: , , expert size equal to a full Llama 2 FFN. The choice matters because it determines what hardware layout works and what auxiliary loss schedule needs tuning.
The Mixtral contribution is not a new primitive. It is an open-weights demonstration that the , top-2, SwiGLU-expert recipe trains stably at the 13B-active scale, serves on single-node 8-way expert-parallel hardware without bespoke kernels, and reaches Llama-2-70B quality at ~5× lower inference compute (Jiang et al. 2024, Table 4). For the basic top-K gating math and the noisy-top-K trick on which this whole recipe rests, see Sparse MoE; this entry focuses on what is specific to the Mixtral configuration.
The contribution in one sentence: take the smallest- top-2 MoE that still gives meaningful specialization, retrain at production scale, and ship it open-weights under MIT.
§ 2 · Derivation
Eight experts, top-2, normalized over selection
Start from the dense Llama-2 FFN at the position-wise layer:
with and . Mixtral 8x7B uses , (Jiang et al. 2024, Table 1). The dense FFN parameter cost per layer is , and the per-token FLOP cost is .
Mixtral replaces this single FFN with independent SwiGLU experts , each parameterized exactly like the dense . A linear gate produces logits . The layer output is
where is the index set of the two largest logits and the gate weights are the renormalized softmax restricted to the selected pair:
This is the load-bearing difference from Sparse-MoE 2017’s gate, which softmaxes over all logits and then masks the non-top- entries to zero (Shazeer et al. 2017, eq. 3). The Mixtral form (Jiang et al. 2024, eq. 4) softmaxes only over the selected . The two choices differ when the gate is poorly calibrated: with -wide softmax, the post-mask weights can collectively be far below 1, attenuating the expert outputs and forcing the residual to do the work; with -only softmax, the weights always sum to 1, so the expert block always contributes its full magnitude to the residual stream. The Mixtral team chose the second form to keep the residual budget consistent regardless of how spiky the gate is.
Why and not 64? With each expert covers a wider slice of input semantics, so specialization is coarse: a single expert ends up handling both code syntax and English grammar rather than one fine-grained concept each. DeepSeekMoE (Dai et al. 2024, arXiv 2401.06066, §2.2) measures this directly and shows the coarse design redundantly stores common-knowledge weights across every expert, since every token has to hit some expert for basic linguistic competence. The Mixtral counter is operational: fits cleanly into 8-way expert-parallel hardware, the gate’s 8-way classification is well-conditioned, and the balance loss only needs to push toward a uniform distribution over 8 buckets — all of which fail more often at .
Why top-2 and not top-1? Top-1 (Switch) gives one bit of routing signal per token and forces the dispatch to handle a discrete categorical choice with no soft fallback; if expert overflows its capacity, the token is dropped (residual passes through unchanged). Top-2 gives a soft second choice that absorbs capacity overflow gracefully — the gate weights $g_1
- g_2 = 1$ adapt to which of the two experts actually accepts the token. The empirical case for top-2 over top-1 was made by GShard (Lepikhin et al. 2020, §3) and confirmed at scale by ST-MoE (Zoph et al. 2022, Table 5), which reports a 0.3–0.6 perplexity point quality gap.
Mixtral inherits the load-balancing auxiliary loss from Switch (Fedus et al. 2021, eq. 4), unchanged in form:
where is the fraction of tokens in the batch whose top-2 set contains expert and
is the gate’s mean softmax probability (over all , not over the selected pair) for
expert . The product is jointly minimized when both quantities are uniform
at , so the sum is bounded below by and is bounded above by when
all tokens collapse to one expert. The factor in front rescales so has a
consistent meaning across . Mixtral’s released code uses (Hugging Face
transformers reference implementation,
MixtralSparseMoeBlock).
The product, not or alone, is what makes the loss gradient-tractable: is a non-differentiable count, but is differentiable in , so the gradient on the gate is — a weighted softmax-cross-entropy-style update that pulls toward proportionally to how over-used expert currently is. The discrete count acts as a stop-gradient target. See Fedus et al. 2021, §2.3 for the same derivation.
Parameter and FLOP accounting. Per MoE layer Mixtral stores FFN-plus-gate parameters, i.e., . Per token only experts fire, so the per-token FFN FLOP cost is of the equivalent -dense cost, matching the dense FLOP cost of a 13B-parameter dense FFN. Total parameter footprint: 46.7B across 32 layers (Jiang et al. 2024, Table 1); active per token: 12.9B. The ratio active/total is the coarse end of the MoE spectrum; DeepSeek V3 sits near 0.06 and Kimi K2 near 0.032.
§ 3 · Reference implementation
Top-2 with renormalization over the pair
def mixtral_moe(x, experts, gate, K=2):
# x: [B, T, d_model] gate.weight: [E, d_model] experts: list of E SwiGLU FFNs
logits = gate(x) # [B, T, E]
topk_logits, topk_idx = logits.topk(K, dim=-1) # [B, T, K]
# Renormalize softmax over the K selected logits only — not over E
weights = topk_logits.softmax(-1) # [B, T, K], sums to 1 along K
# Dispatch each token to its K experts; combine outputs by weights
return dispatch_and_combine(x, experts, topk_idx, weights)
def load_balance_loss(logits, topk_idx, alpha=0.02):
# logits: [B, T, E] topk_idx: [B, T, K]
E = logits.shape[-1]
P = logits.softmax(-1).mean(dim=(0, 1)) # [E] mean gate prob
one_hot = scatter_to_onehot(topk_idx, E) # [B, T, E] in {0, 1}
f = one_hot.float().mean(dim=(0, 1)) # [E] selection fraction
return alpha * E * (f * P).sum()
The dispatch step is the implementation pain point. A naive for i in range(E): x[mask_i] = f_i(x[mask_i]) is correct but serializes the experts. Production implementations gather
tokens into a [E, capacity, d_model] tensor, run all experts in parallel as a batched
matmul, then scatter back — see the
Megablocks kernel for the standard form.
§ 4 · Empirical evidence
What Mixtral 8x7B and follow-ups measure
Quality vs dense Llama 2 70B. Jiang et al. 2024 Table 2 reports Mixtral 8x7B matching or exceeding Llama 2 70B on MMLU (70.6 vs 69.9), HellaSwag (86.7 vs 85.4), Arc-C (66.0 vs 64.9), and TriviaQA (77.6 vs 73.7), with the largest gap on code (HumanEval 40.2 vs 32.3) and math (MATH 28.4 vs 13.8). The active parameter count is 12.9B vs Llama 2 70B’s 70B, so the quality-per-active-FLOP gap is roughly 5×. Total parameter count is 46.7B vs 70B, so the quality-per-stored-byte gap is roughly 1.5× — a meaningful but smaller win.
Expert specialization. Jiang et al. 2024 §5 measures expert-routing distributions across domains (ArXiv math, biology, PhilPapers, etc.) and finds no clean per-domain specialization — the routing distribution looks roughly uniform within each domain. The paper’s interpretation: with each expert is too coarse for domain-level specialization to be visible; the specialization is happening at a sub-token (syntactic) level that the routing histogram does not resolve. This is the empirical hook DeepSeekMoE (Dai et al. 2024, §4) uses to argue for finer .
Comparison to OLMoE. Muennighoff et al. 2024 (arXiv 2409.02060, §4) train OLMoE-1B-7B with , — Mixtral’s recipe scaled to many small experts but without DeepSeekMoE’s shared experts. They report (Table 6) that this fine-grained-coarse variant beats Mixtral 8x7B at matched active parameters on most benchmarks, with the biggest gap on multitask reasoning. The OLMoE ablation (§5.1) attributes the gain to the finer granularity — same conclusion as DeepSeekMoE’s, but reached with the Mixtral-style aux-loss design.
Independent reproduction at scale. Mixtral 8x22B (Mistral AI, April 2024) keeps the same recipe with , , 56 layers, 141B total, 39B active. The public configuration confirms the , choice scales to the next size class without architectural changes. No formal ablation paper accompanies this release.
Auxiliary-loss sensitivity. The Mistral team has not published an sweep. The Switch authors (Fedus et al. 2021, §3.2) sweep and find a wide plateau around ; the Mixtral default sits in this plateau. ST-MoE (Zoph et al. 2022, §3.1) confirms the same plateau at top-2 with . There is no public Mixtral-specific re-ablation of to point to.
Routing instability. A practitioner-side measurement from the Hugging Face team (Mixtral fine-tuning notes) reports that long-tail fine-tuning data can collapse the gate to using only 2–3 of 8 experts unless the auxiliary loss is kept on. This matches the Switch result (Fedus et al. 2021, §3.1) that the aux loss is load-bearing during distribution shift, not only during pretraining.
I don’t know of a public ablation isolating the renormalize-over- choice vs softmax-over- -then-mask. The Sparse-MoE 2017 form and the Mixtral form should differ in the gate’s gradient when the top- logits are not the dominant entries; whether this matters at the , regime has not been measured in any paper I can cite.
Adopted by
- Mixtral 8x7B · Mistral AI — Reference implementation — 8 SwiGLU experts per layer, top-2 routing, all 32 transformer layers MoE. [source]
- OLMoE 1B/7B · Allen Institute for AI (AI2) — Top-8 routing across 64 small experts; coarse-MoE recipe without DeepSeekMoE's shared experts. [source]
Lineage
- Predecessors
- Switch TransformerSwitch
- Successors
- DeepSeekMoEDeepSeekMoE
Cite
BibTeX entry for the original paper
@article{arxiv2401_04088,
title = {Mixtral of Experts},
author = {Mistral AI},
year = {2024},
eprint = {2401.04088},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.04088}
} Or cite the paper directly: arXiv:2401.04088.
Export
BibTeX
@article{arxiv_2401_04088,
title = {Mixtral of Experts},
author = {Mistral AI},
year = {2024},
eprint = {2401.04088},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2401.04088}
} CSL JSON
{
"id": "arxiv_2401_04088",
"type": "article-journal",
"title": "Mixtral of Experts",
"author": [
{
"literal": "Mistral AI"
}
],
"issued": {
"date-parts": [
[
2024
]
]
},
"URL": "https://arxiv.org/abs/2401.04088",
"number": "2401.04088",
"source": "arXiv"
} RIS
TY - JOUR
TI - Mixtral of Experts
AU - Mistral AI
PY - 2024
JO - arXiv
AN - arXiv:2401.04088
UR - https://arxiv.org/abs/2401.04088
ER -