Skip to content

Chapter 5 · Mixture of Experts (MoE)

5.1 What is MoE, and why can it enlarge model capacity without increasing compute? ★★

One-sentence answer

MoE (Mixture of Experts) replaces the FFN in a Transformer with several experts of identical structure but independent parameters, and uses a lightweight router to pick only a few of them to process each token. The total parameter count (which determines how much knowledge the model can store) can then grow many times over with the number of experts, while the active parameter count each token actually uses (which determines compute) stays almost unchanged, decoupling model capacity from per-token compute; the costs are that memory must hold every expert, and that load balancing and communication become engineering problems.

I will address three aspects: the bottleneck of dense models, the structure of MoE, and the difference between total and active parameters.

(1) In a dense model, capacity and per-token compute are bound together.

In a dense model, every token passes through all the parameters: the forward pass costs about \(2N\) FLOPs per token (\(N\) is the parameter count), and total training compute is about \(6ND\) (\(D\) is the number of training tokens; see Chapter 2 of the LLM Training Pipeline direction). The model's capacity (how much knowledge it can hold) and its per-token compute are therefore one and the same: to make the model remember more you add parameters, and adding parameters proportionally increases per-token compute and training cost.

(2) MoE replaces the FFN with "several experts + a router", and each token activates only a few experts.

MoE is designed precisely to break this bond. It replaces the FFN in a Transformer block with \(E\) FFNs of identical structure but independent parameters, called experts, plus a very small router. For each token, the router selects only \(k\) experts (\(k\) much smaller than \(E\)) to process it; the output is a weighted sum of these experts' results, and the other experts do no computation at all for this token:

\[ y = \sum_{i=1}^{E} g_i(x)\, \mathrm{FFN}_i(x), \qquad \text{only } k \ll E \text{ of the } g_i(x) \text{ are non-zero} \]

Here \(x\) is the token's hidden state as it enters the layer, \(\mathrm{FFN}_i\) is the \(i\)-th expert, \(g_i(x)\) is the weight the router assigns to it, and \(y\) is the layer's output. The FFN rather than attention is replaced because, in the standard configuration, the FFN holds about two-thirds of each block's parameters and is considered the main place where knowledge is stored, and it computes each token independently, which makes it a natural fit for "different tokens take different paths"; attention, by contrast, exchanges information between tokens and determines the size of the KV cache, so it stays dense and shared by all tokens. The idea was first proposed by Shazeer et al. (2017) as a sparsely gated MoE layer for LSTMs; GShard (Lepikhin et al. 2020) brought it to Transformers, and Switch Transformer (Fedus et al. 2021) pushed it to the trillion-parameter scale.

(3) The key is to distinguish total parameters from active parameters.

An MoE model has two parameter counts. The total parameter count is all experts plus the shared parts (attention, embeddings, normalization layers); it determines how much knowledge the model can store and also how much memory it occupies. The active parameter count is the parameters each token actually uses, namely the shared parts plus the \(k\) selected experts; it determines per-token compute. Adding experts can multiply the total parameters while per-token compute stays almost the same. In practice, Switch Transformer sped up pretraining by up to 7 times with the same computational resources, and Mixtral 8x7B (Jiang et al. 2024) has 47B total parameters but activates only 13B per token, yet matches or beats Llama 2 70B. Current naming makes the distinction explicit: Qwen3-235B-A22B, for example, means 235B total parameters with 22B activated.

In summary: the essence of MoE is using conditional computation to decouple capacity from compute: there can be many parameters, but each token uses only a small fraction of them.

Going deeper: Mixtral's parameter accounting, and the number of experts as a new scaling axis

(1) Why Mixtral 8x7B has 47B total and 13B active parameters, rather than 56B and 14B.

Only the FFN is copied 8 times; attention, the embeddings and the normalization layers are shared by all experts and counted once.

Part Parameters Activated for each token?
FFNs of the 8 experts (all 32 layers) About 45B Only 2 of them, about 11B
Shared parts (attention, embeddings, etc.) About 1.6B All of it
Total About 47B About 13B

Using the estimate that each token's forward pass costs about \(2 \times\) the active parameters, Mixtral needs about 26 GFLOPs per token, while a dense model with the same total parameters would need about 94 GFLOPs, roughly 3.6 times more. "8x7B" only means "8 experts, with each computation path close to the size of a 7B model"; it is not 8 independent 7B models glued together.

(2) The number of experts is a new scaling axis, but with diminishing returns.

Switch Transformer found that, with FLOPs per token held fixed, doubling the number of experts step by step from 2 to 256 kept lowering test loss and kept reducing the training steps needed to reach a given loss. Kimi K2 calls this the sparsity scaling law: defining sparsity as the ratio of total experts to activated experts, raising sparsity at a fixed number of activated parameters (i.e. fixed FLOPs) consistently lowers both training and validation loss; at a validation loss of 1.5, sparsity 48 saves 1.69 times, 1.39 times and 1.15 times the FLOPs of sparsities 8, 16 and 32 respectively (Kimi Team 2025). They also note, however, that higher sparsity makes the infrastructure more complex, and they settled on activating 8 of 384 experts (sparsity 48). Choosing the number of experts is thus a trade-off between model quality and system efficiency.

Follow-up questions

Follow-up 1: Why does MoE replace the FFN rather than attention?

Because the FFN has many parameters and computes each token separately, whereas attention handles interactions between tokens. In the standard configuration the FFN holds about two-thirds of each block's parameters, so sparsifying it enlarges capacity the most; it computes each token independently, so sending different tokens to different experts causes no interference. Attention's job is to let each token gather information from other tokens; it has fewer parameters and determines the structure of the KV cache, so mainstream designs keep attention dense.

Follow-up 2: At equal active parameters, which is stronger, MoE or dense? And at equal total parameters?

At equal active parameters MoE is stronger; at equal total parameters dense is stronger. Equal active parameters means equal per-token compute, and MoE has far more parameters to store knowledge; at equal total parameters, a dense model uses all of its parameters for every token while MoE uses only a small fraction, so, for example, the 47B Mixtral is weaker than a 47B dense model. This is the central trade-off when choosing between dense and MoE (see 5.7).

Follow-up 3: Does MoE have to be trained from scratch?

Not necessarily; it can be "upgraded" from a dense model. Sparse upcycling (Komatsuzaki et al. 2022) copies the FFN of an already-trained dense model several times to initialize the experts and then continues training, saving the compute of training from scratch; Qwen1.5-MoE-A2.7B, for example, was upcycled from Qwen-1.8B. The drawback is that all experts start from the same point and may find it harder to differentiate (see 5.2).

Common mistakes

  • Do not say that MoE reduces memory: Memory must hold every expert and scales with the total parameter count.
  • Do not describe Mixtral 8x7B as 8 independent 7B models: Only the FFN is replicated, attention and the other parts are shared, and the total is 47B, not 56B.
  • Do not say that each expert is a complete model: An expert is just one FFN within one layer, and every layer routes independently.
  • Do not say that MoE compute is proportional to total parameters: It is proportional to active parameters.

5.2 How does MoE routing work? ★★

One-sentence answer

The router is a linear layer: for each token it computes an affinity score with every expert, takes the \(k\) highest-scoring experts, normalizes over these \(k\) scores to obtain gate weights, and the final output is the weighted sum of these \(k\) experts' outputs. Top-k selection itself is not differentiable, and the router receives gradients through the gate weights. In implementation, tokens have to be grouped by expert and computed in batches. Moreover, experts usually do not specialize by domain in the human sense; their division of labor shows up more as token-level and syntactic patterns, though domain specialization is somewhat more visible in fine-grained MoE.

Figure
(a) Conventional top-2 routing; (b) fine-grained expert segmentation; (c) adding shared experts, i.e. DeepSeekMoE (see 5.4) (Dai et al. 2024, Figure 2)

I will address three aspects: how top-k gating is computed, the forward pass of an MoE layer, and whether experts really specialize by domain.

(1) Top-k gating consists of four steps: scoring, selection, normalization and a weighted sum.

\[ h = W_r\, x \in \mathbb{R}^{E}, \qquad \mathcal{T} = \mathrm{TopK}(h, k), \qquad g_i = \begin{cases} \dfrac{\exp(h_i)}{\sum_{j \in \mathcal{T}} \exp(h_j)}, & i \in \mathcal{T} \\[2mm] 0, & i \notin \mathcal{T} \end{cases}, \qquad y = \sum_{i \in \mathcal{T}} g_i\, \mathrm{FFN}_i(x) \]

Here \(x\) is the token's \(d\)-dimensional hidden state and \(W_r\) is the \(E \times d\) routing matrix; think of each expert as having a \(d\)-dimensional "centroid", so \(h_i\) is the dot product between the token and expert \(i\)'s centroid, measuring how well the token suits that expert. \(\mathcal{T}\) is the set of the \(k\) highest-scoring experts; a softmax over only these \(k\) scores gives the weights \(g_i\); and the final output \(y\) is the weighted sum of the selected experts' outputs, which is then added back to the residual stream through the residual connection. The router has only \(E \times d\) parameters, negligible relative to the whole model. Top-k selection is discrete and not differentiable, but the selected experts' outputs are multiplied by \(g_i\), which is a differentiable function of \(h\), so gradients reach the router through \(g_i\): if an expert's output helped lower the loss, its weight is raised, and the router will tend to send similar tokens to it in the future; experts that were not selected receive no gradient from this token. Even Switch Transformer, with \(k = 1\), multiplies the expert output by the gate value precisely so that the router receives a training signal. The choice of \(k\) is also a trade-off: \(k = 1\) is cheapest in compute and communication but gives each token a single path; \(k = 2\) (GShard, Mixtral) is more stable; and fine-grained MoE selects around 8 from one or two hundred or even more small experts (see 5.4).

(2) The forward pass of an MoE layer groups tokens by expert, and each expert processes only the tokens assigned to it.

Concretely, the router first scores all tokens in a batch and selects each token's \(k\) experts, producing the gate weights; tokens are then reordered by expert ID (permute) so that each expert's tokens are contiguous in memory; each expert then runs its FFN only on the tokens assigned to it; finally, the expert outputs are multiplied by the corresponding gate weights, put back at each token's original position (unpermute) and summed. The engineering difficulty here is that the number of tokens each expert receives is not fixed and changes at every step. GPUs are best at large, regularly shaped matrix multiplications, and simply looping over the experts, each time processing a small and varying number of tokens, launches many small kernels and is very inefficient. Production implementations therefore usually compute all experts at once with a single grouped GEMM; implementations that use expert capacity instead pad or truncate each expert's input to a fixed length in exchange for regular shapes (see 5.3). When the experts are spread across several GPUs, the "group by expert" step becomes cross-GPU all-to-all communication (see 5.6).

(3) Experts usually do not specialize by domain in the human sense.

The name "expert" makes it tempting to think each expert handles one domain, say one for math and one for code. But the analysis in the Mixtral paper found no clear topic-based specialization: the share of tokens each expert receives is similar across the domains of The Pile (math, biology, philosophy, code and so on), with only the synthetic DM Mathematics differing slightly; instead there are patterns at the token and syntax level, for example self in Python and Question in English are often sent to the same expert, indentation tokens in code always go to the same expert, and consecutive tokens are often assigned the same expert (Jiang et al. 2024). This conclusion depends on the expert design, however: OLMoE (Muennighoff et al. 2024), with 64 small experts per layer and 8 activated, shows clear domain specialization on domains such as arXiv and GitHub, whereas Mixtral's expert activations are close to uniform, which the authors suggest may reflect considerable redundancy among Mixtral's experts. The more accurate statement is therefore that the division of labor among experts emerges on its own during training and may reflect domains, vocabulary or syntactic patterns, but does not correspond to human-assigned domains and is hard to interpret directly.

In summary: the core of MoE routing is that each token independently and dynamically selects a few experts in every layer; the router learns through the gate weights, and the experts' division of labor emerges during training and usually does not correspond to human-defined domains.

Going deeper: writing an MoE layer by hand, and several gating variants

(1) The most direct implementation of an MoE layer's forward pass.

"Write an MoE layer by hand" is a common interview coding question, and the following is the most direct version:

# x: [T, d] tokens in the batch;  W_r: [E, d] router;  experts: list of E FFNs
logits = x @ W_r.T                            # [T, E] router scores
topk_val, topk_idx = logits.topk(k, dim=-1)   # [T, k] chosen experts for each token
gates = softmax(topk_val, dim=-1)             # [T, k] weights over the chosen k
y = zeros_like(x)
for e in range(E):
    tok, slot = where(topk_idx == e)          # which tokens chose expert e, and in which slot
    if len(tok) == 0:
        continue
    out = experts[e](x[tok])                  # run expert e only on its own tokens
    y[tok] += gates[tok, slot, None] * out    # weighted add back to each token's output
# the load-balancing loss (5.3) uses softmax(logits) over all E experts

This code loops over the experts one at a time, which is exactly the inefficient version described above; production implementations replace it with three steps: permute, grouped GEMM and unpermute.

(2) Several gating variants.

Variant How it works Used by
Top-k first, then softmax over the selected experts The selected weights sum to 1 Mixtral
Softmax over all experts first, then keep the top-k probabilities Optionally renormalized GShard, Switch Transformer
Sigmoid affinity per expert, then normalize among the selected experts Experts' scores do not compete with one another DeepSeek-V3, GLM-4.5
Add noise to the logits, then take the top-k Encourages exploring different experts Shazeer et al. 2017

The first three variants select the same experts; they differ in the scale of the weights and the form of the gradients.

Follow-up questions

Follow-up 1: Top-k selection is not differentiable, so how does the router get gradients?

Gradients reach the router through the gate weights \(g_i\). The output \(y = \sum_{i \in \mathcal{T}} g_i\,\mathrm{FFN}_i(x)\) is differentiable with respect to \(g_i\), and \(g_i\) is a differentiable function of the router logits, so the loss has a gradient with respect to the router parameters: whichever expert's output does more to lower the loss has its weight raised. Only the selected experts receive this signal, however; the router has no way of knowing whether an unselected expert "would have been better", which is why early work added noise to encourage exploration.

Follow-up 2: What are the pros and cons of top-1 versus top-2 routing?

Top-1 is cheaper; top-2 is more stable. Top-1 sends each token to a single expert, minimizing compute and communication, and Switch Transformer showed that it works; but each token has only one path, a routing mistake is costly, and the router's gradient signal is weaker. Top-2 adds one expert's worth of compute and communication, but combining two experts makes the output smoother and training more stable, and it usually works better. Fine-grained MoE activates more experts (e.g. 8) because each expert is smaller, so the total compute stays manageable.

Follow-up 3: What is expert-choice routing, and why do decoder-only LLMs rarely use it?

It lets experts choose tokens instead of letting tokens choose experts. In expert choice (Zhou et al. 2022), each expert picks a fixed number of its highest-scoring tokens from the whole batch, so the load is perfectly balanced by construction and no auxiliary loss is needed. The cost is that some tokens may not be picked by any expert, and an expert has to see all the tokens in the batch before choosing, including later tokens of the same sequence, which breaks the causality of autoregressive generation; mainstream decoder-only LLMs therefore rarely use it.

Common mistakes

  • Do not say that gradients flow through all experts: Only the selected experts and their gate weights receive gradients.
  • Do not say that "math questions" can be routed to a "math expert": Routing happens per token and per layer, and the experts' division of labor emerges on its own during training.
  • Do not say that routing is done per sequence: Every token selects its experts independently in every MoE layer.

5.3 Why does MoE need load balancing, and how is the auxiliary loss designed? ★★

One-sentence answer

Without constraints, MoE falls into routing collapse through a "rich get richer" feedback loop: a few experts receive most of the tokens while the rest sit idle, which wastes capacity, creates compute bottlenecks under expert parallelism, and leads to dropped tokens. The classic fix is an auxiliary load-balancing loss \(\alpha \cdot E \cdot \sum_i f_i P_i\), where \(f_i\) is the fraction of tokens actually sent to expert \(i\) and \(P_i\) is the router's average probability for it, with gradients flowing through the differentiable \(P_i\) to push down the probabilities of overloaded experts. Its cost is that it conflicts with the language-modeling objective, so the coefficient needs balancing; many implementations also cap each expert's capacity, and tokens beyond the cap are dropped.

I will address three aspects: the cause and consequences of routing collapse, the design of the auxiliary loss, and expert capacity with token dropping.

(1) Routing collapse comes from a feedback loop, and it wastes capacity and slows computation.

At the start of training the router is randomly initialized, and some experts happen to receive slightly more tokens; the experts that get more tokens receive more gradient updates and become better; the router notices that they work well and sends them even more tokens; so they get even more training. As the loop continues, a few experts grow stronger and stronger, while the rest receive almost no tokens and never get trained well, so the router is even less likely to choose them, ending in routing collapse. It has three consequences:

  • Wasted capacity: Experts that go unused are parameters that occupy memory for nothing, the model's effective capacity shrinks to something close to a small dense model, and MoE loses its point.
  • Poor compute efficiency: Under expert parallelism (see 5.6), different experts live on different GPUs, the most heavily loaded GPU sets the speed of the whole layer, and the other GPUs just wait.
  • Dropped tokens: If each expert has a capacity cap, tokens that do not fit into an overloaded expert are dropped (see (3) below), which hurts quality.

(2) The auxiliary loss penalizes imbalance through "actual load × routing probability".

The classic fix is to add an auxiliary loss on top of the language-modeling loss. Switch Transformer's version (Fedus et al. 2021) is:

\[ \mathcal{L}_{\text{aux}} = \alpha \cdot E \cdot \sum_{i=1}^{E} f_i\, P_i, \qquad f_i = \frac{1}{T}\sum_{t=1}^{T} \mathbb{1}\{\text{token } t \text{ is routed to expert } i\}, \qquad P_i = \frac{1}{T}\sum_{t=1}^{T} p_i(x_t) \]

Here \(T\) is the number of tokens in a batch, \(f_i\) is the fraction of tokens actually sent to expert \(i\), \(p_i(x_t)\) is the router's softmax probability for token \(x_t\) on expert \(i\), \(P_i\) is its average over the batch, and \(\alpha\) is the loss coefficient (Switch uses 0.01). The product of \(f_i\) and \(P_i\) is used because \(f_i\) is a counted fraction and not differentiable, whereas \(P_i\) is an average of probabilities and is differentiable. Differentiating with respect to \(P_i\) gives a gradient proportional to \(f_i\), so the more heavily loaded an expert, the harder its routing probability is pushed down, and tokens are pushed toward lightly loaded experts. When routing is perfectly uniform, \(f_i = P_i = 1/E\) and the loss equals exactly \(\alpha\), independent of the number of experts, so \(\alpha\) can be reused across configurations. The auxiliary loss has a fundamental tension, however: its gradient conflicts with the language-modeling objective. If \(\alpha\) is too small, it cannot stop collapse; if \(\alpha\) is too large, the router spreads tokens evenly for the sake of balance regardless of their content, experts cannot specialize, and language-modeling quality drops. This is exactly the motivation for the later auxiliary-loss-free method (see 5.5).

(3) Expert capacity caps how many tokens each expert can process, and tokens beyond it are dropped.

In many implementations (especially GShard and Switch Transformer on TPUs), the number of tokens each expert can process in a batch is capped; this cap is called the expert capacity, and it equals a capacity factor times the number of tokens each expert would receive under uniform routing (the formula is in "Going deeper" below). The cap exists because the hardware and communication libraries want fixed-shape tensors, so a fixed-size buffer has to be allocated for each expert in advance. If an expert receives more tokens than its capacity, the extra tokens are dropped: they skip the expert computation in this layer and pass unchanged to the next layer through the residual connection, so they get no processing from this layer's FFN. A capacity factor above 1 leaves slack and reduces dropping, at the cost of useless computation on empty slots and more memory and communication bandwidth; Switch Transformer found that capacity factors of 1.0 to 1.25 suffice, and with the auxiliary loss usually fewer than 1% of tokens are dropped. Dropping tokens causes an extra problem at inference, however: whether a token is dropped depends on the token distribution of the other requests in the same batch, so the same input can produce different outputs in different batches. The trend today is therefore dropless MoE: MegaBlocks (Gale et al. 2022) uses block-sparse matrix operations to handle a different number of tokens per expert without a fixed capacity, and DeepSeek-V3, thanks to good load balancing, drops no tokens in either training or inference.

In summary: the goal of load balancing is to give every expert enough tokens while interfering as little as possible with the language-modeling objective; the auxiliary loss and the capacity cap are the classic tools, but the former conflicts with the main objective and the latter drops tokens, which motivated the later auxiliary-loss-free method and dropless implementations.

Going deeper: the gradient of the loss, the scope of the statistics, and computing the capacity

(1) The gradient, and normalization under top-k.

Differentiating with respect to \(P_i\) gives \(\partial \mathcal{L}_{\text{aux}} / \partial P_i = \alpha E f_i\), i.e. each expert's probability is pushed down with a force proportional to its actual load. A tiny extreme example: with only 2 experts and every token going to expert 1, \(f = (1, 0)\); if the average routing probabilities are \(P = (0.9, 0.1)\), the loss is \(\alpha \cdot 2 \cdot 0.9 = 1.8\alpha\), far above the uniform value \(\alpha\), and the gradient acts only on \(P_1\). With top-k routing, each token is counted \(k\) times, so \(f_i\) is usually further divided by \(k\) to keep the loss at \(\alpha\) under uniform routing.

(2) Over what scope the load is counted.

\(f_i\) and \(P_i\) can be counted over a single sequence, a micro-batch, or the whole global batch (the tokens of all data-parallel replicas together), and different scopes give constraints of very different strength.

Scope Strength of the constraint Benefit Risk Used by
Single sequence Strongest Every sequence is balanced internally Even a document of pure code must use all experts evenly, so experts can hardly specialize DeepSeek-V3's complementary loss (tiny coefficient)
Micro-batch Strong Simple to implement A micro-batch often holds only a few sequences, possibly from one domain, so the problem is similar to the row above Many early implementations
Global batch Weakest Lets tokens from one domain concentrate on a few experts, leaving room for specialization Overall balance does not guarantee balance at every step and on every GPU Qwen3 (Qiu et al. 2025)

(3) Computing the expert capacity.

\[ \text{capacity} = \mathrm{CF} \times \frac{k \cdot T}{E} \]

Here \(\mathrm{CF}\) is the capacity factor and \(k \cdot T / E\) is the number of tokens each expert would receive under perfectly uniform routing. For example, with \(T = 4096\), \(k = 2\), \(E = 64\) and \(\mathrm{CF} = 1.25\), each expert processes at most \(1.25 \times 128 = 160\) tokens.

Follow-up questions

Follow-up 1: What happens if the load-balancing coefficient is too large or too small?

Too small fails to stop collapse; too large hurts language-modeling quality. With too small a coefficient, the feedback loop still lets a few experts monopolize the tokens; with too large a coefficient, the router tends to spread tokens evenly to make the loss small, ignoring how well tokens actually match experts, so experts cannot specialize and the language-modeling loss rises. In practice the coefficient is usually small (e.g. 0.01 or less) and has to be tuned experimentally.

Follow-up 2: Why does counting the load over the global batch favor expert specialization?

Because the larger the scope, the more local imbalance is allowed. A micro-batch may contain only a few sequences from one domain, say all code; requiring balance within it forces code tokens to be spread evenly across all experts, so no code expert can form. Counting over the global batch only requires the data as a whole to be balanced: code tokens may concentrate on a few experts, as long as tokens from other domains go to other experts. Qwen3 adopts this approach (Qiu et al. 2025).

Follow-up 3: Why does token dropping make inference results nondeterministic?

Because whether a token is dropped depends on the tokens of other requests in the same batch. If tokens from other requests happen to flood the same expert, that expert overflows and some tokens are dropped; with a different set of requests, the same token might not be dropped. The same input can therefore produce different outputs in different batches, which is a real headache for online serving and one reason dropless implementations have become mainstream.

Common mistakes

  • Do not say that the auxiliary loss takes gradients directly through \(f_i\): \(f_i\) is a count and not differentiable; the gradient comes from \(P_i\).
  • Do not say that more balanced is always better: An overly strong balance constraint prevents expert specialization and hurts quality.
  • Do not say that a dropped token's output is zero: It passes unchanged to the next layer through the residual connection; it only skips this layer's expert computation.

5.4 What are fine-grained experts and shared experts? ★

One-sentence answer

Both come from DeepSeekMoE. Fine-grained experts split each expert into \(m\) smaller experts while also multiplying the number of activated experts by \(m\), so total parameters and per-token compute stay the same, but the number of possible expert combinations grows enormously and each expert can become more specialized; shared experts are experts that every token always passes through, absorbing general knowledge and reducing duplication among the routed experts. The costs are mainly on the engineering side: small matrix multiplications are inefficient, and communication becomes more fragmented.

I will address three aspects: the two problems of conventional MoE, how the two improvements work, and their costs together with what the industry has chosen.

(1) Conventional coarse-grained MoE suffers from knowledge hybridity and knowledge redundancy.

DeepSeekMoE (Dai et al. 2024) pointed out that conventional MoE (say, choosing 2 out of 8 or 16 experts) has two problems that limit how specialized experts can become:

  • Knowledge hybridity: With few experts, each expert is forced to cover many different kinds of knowledge and can hardly specialize.
  • Knowledge redundancy: Some knowledge is needed by almost every token (such as basic grammar and common expressions), so different experts each have to learn it separately, wasting parameters on duplicates.

(2) Fine-grained segmentation makes combinations more flexible, and shared experts isolate general knowledge.

  • Fine-grained expert segmentation: Split each expert into \(m\) smaller experts (each with \(1/m\) of the original FFN hidden dimension) and multiply the number of activated experts by \(m\). Total parameters and per-token compute stay the same, but the number of possible combinations grows enormously: choosing 2 out of 16 experts gives only 120 combinations, while splitting into 64 experts and choosing 8 gives about 4.4 billion. The more flexible the combinations, the more each small expert can take charge of narrower, more specialized knowledge, with the pieces combined as needed.
  • Shared expert isolation: Set aside a few experts as shared experts that every token always passes through, with no routing (the formula is in "Going deeper" below). The shared experts absorb general knowledge, so the routed experts do not need to relearn it and can focus on their own specialized knowledge, reducing redundancy.

(3) The costs are mainly on the engineering side, and shared experts are not strictly necessary.

Once experts become more numerous and smaller, each small expert's matrix multiplication shrinks and GPU utilization drops, so special kernels such as grouped GEMM are needed to execute many small matrix multiplications together; at the same time, each token is sent to more destinations, and all-to-all communication becomes more fragmented. Even so, fine-grained experts have become standard practice in today's large MoE models: the number of experts has grown from Mixtral's 8 to DeepSeek-V3's 256, Kimi K2's 384 and even Qwen3.5's 512. Shared experts vary from model to model: DeepSeek-V3, Kimi K2, GLM-5 and Qwen3.5 all use 1 shared expert, while Qwen3's MoE drops shared experts and gpt-oss does not use them either, showing that the design is not essential.

In summary: fine-grained experts and shared experts respectively address experts that are not specialized enough and general knowledge stored redundantly; the former has become standard practice in large MoE models, while the latter varies by model.

Going deeper: the formula, DeepSeekMoE's results, and a scaling law for granularity

(1) An MoE layer with shared experts.

\[ y = x + \sum_{i=1}^{K_s} \mathrm{FFN}^{(s)}_i(x) + \sum_{i=1}^{N_r} g_i\, \mathrm{FFN}^{(r)}_i(x) \]

Here \(x\) is the residual, \(K_s\) is the number of shared experts, and \(\mathrm{FFN}^{(s)}_i\) is the \(i\)-th shared expert, computed for every token; \(N_r\) is the number of routed experts, \(\mathrm{FFN}^{(r)}_i\) is the \(i\)-th routed expert, and \(g_i\) is its gate weight, non-zero only for the selected experts.

(2) Combination counts and DeepSeekMoE's results.

The combination counts are \(\binom{16}{2} = 120\) and \(\binom{64}{8} = 4{,}426{,}165{,}368\). The paper reports that DeepSeekMoE 2B matches GShard 2.9B, which has 1.5 times its expert parameters and compute, and approaches a dense model with the same total parameters (the upper bound for MoE); scaled to 16B, it matches LLaMA2 7B with only about 40% of the compute (Dai et al. 2024).

(3) Expert granularity also has a scaling law.

Krajewski et al. (2024) incorporated granularity into scaling laws as a hyperparameter and found that the common practice of making each expert as large as the original FFN is not optimal at almost any compute budget, with the optimal granularity becoming finer as the compute budget grows. This is consistent with the industry trend toward ever more experts.

Follow-up questions

Follow-up 1: Are finer-grained experts always better?

No; the quality gains diminish while hardware efficiency keeps falling. Finer experts give more flexible combinations and fuller specialization, but each expert's matrix multiplication gets smaller and harder for the GPU to saturate; each token has more destinations, so communication becomes more fragmented and more expensive; and router compute and load balancing also get harder. The optimal granularity is therefore a compromise between quality and system efficiency, and it depends on the compute budget and the hardware.

Follow-up 2: How does a shared expert differ from "keeping part of the FFN dense"?

Computationally they are almost the same; the difference is in design intent. A shared expert is simply an FFN activated for every token, placed in parallel with the routed experts in the same layer, which is computationally equivalent to keeping a dense path inside the MoE layer. Its point is the division of labor: this dense path is dedicated to absorbing general knowledge, so that the routed experts can focus on their own specialized knowledge.

Common mistakes

  • Do not say that fine-grained segmentation increases compute: Total parameters and per-token compute stay the same; what changes is how experts can be combined.
  • Do not say that shared experts are routed too: They are activated for every token and do not go through the router.
  • Do not say that every modern MoE has shared experts: Qwen3 and gpt-oss do not.

5.5 How does auxiliary-loss-free load balancing work? ★

One-sentence answer

DeepSeek-V3 gives each expert a bias \(b_i\) that is added to the affinity score only when selecting the top-k, and does not enter the computation of the gate weights; after each training step the bias is adjusted according to load: an overloaded expert's bias is decreased by \(\gamma\), and an underloaded expert's bias is increased by \(\gamma\). Load balancing is thus achieved by changing "whom to choose", with no extra gradient introduced into the language-modeling objective, and the gate weights still reflect how well each token truly matches each expert; it also keeps a sequence-level balance loss with a tiny coefficient to prevent extreme imbalance within a single sequence.

I will address three aspects: why it is needed, how it works, and its results together with the complementary measures.

(1) Motivation: the gradient of the auxiliary loss conflicts with the language-modeling objective.

As 5.3 explained, the auxiliary loss pushes down the routing probabilities of overloaded experts through gradients, but these gradients do not point in the same direction as reducing the language-modeling loss. Too small a coefficient fails to stop collapse, and too large a coefficient makes the router spread tokens evenly regardless of their content, hurting quality. DeepSeek therefore proposed a load-balancing method that does not rely on a loss function (Wang et al. 2024) and adopted it in DeepSeek-V3.

(2) How it works: the bias affects only expert selection, and it is adjusted according to load like a feedback controller.

\[ g_i \propto \begin{cases} s_i, & s_i + b_i \in \mathrm{TopK}\big(\{s_j + b_j\}_{j=1}^{N_r},\ k\big) \\ 0, & \text{otherwise} \end{cases}, \qquad b_i \leftarrow \begin{cases} b_i - \gamma, & \text{expert } i \text{ overloaded} \\ b_i + \gamma, & \text{expert } i \text{ underloaded} \end{cases} \]

Here \(s_i\) is the token's affinity score for expert \(i\) (computed with a sigmoid in DeepSeek-V3), \(b_i\) is expert \(i\)'s bias, \(N_r\) is the number of routed experts, and \(\gamma\) is the bias update speed. Top-k selection uses \(s_i + b_i\), but the gate weight multiplied onto the expert's output is still determined by the original \(s_i\) (then normalized among the selected experts; \(\propto\) denotes the value before normalization). The bias is not learned by gradient descent; instead, at the end of each training step the load of each expert over the whole batch is measured, overloaded experts have \(b_i\) decreased by \(\gamma\), and underloaded experts have \(b_i\) increased by \(\gamma\). As an overloaded expert's bias keeps shrinking, it becomes harder and harder to select, and tokens naturally flow to idle experts until the load is balanced. Load balancing is thus achieved entirely by adjusting "whom to choose", with no extra gradient interfering with the language-modeling objective; and because the bias does not enter the gate weights, the way expert outputs are weighted still reflects only how well each token truly matches each expert.

(3) Results and complementary measures: better balance and better quality, supplemented by a sequence-level loss and node limits.

The experiments of Wang et al. (2024) show that, compared with baselines using an auxiliary loss, this method achieves both better load balance and lower language-modeling loss. DeepSeek-V3 adds two complementary measures on top of it: to prevent extreme imbalance within a single sequence, it keeps a sequence-level balance loss with a tiny coefficient (0.0001); and it limits each token to at most 4 nodes (see 5.6). With this strategy, DeepSeek-V3 drops no tokens in either training or inference (DeepSeek-AI 2024). Later models such as GLM-4.5 also adopted this auxiliary-loss-free load balancing (GLM-4.5 Team 2025).

In summary: the core of the auxiliary-loss-free method is moving load balancing from the loss function to the selection rule: a bias that is adjusted by load, takes no part in gradients and stays out of the gate weights regulates the selection, avoiding any conflict with the language-modeling objective.

Going deeper: DeepSeek-V3's concrete settings, and a comparison of load-balancing methods

(1) DeepSeek-V3's settings.

  • Bias update speed: \(\gamma = 0.001\) for the first 14.3T tokens and 0 for the last 500B tokens, i.e. the bias is frozen at the end of training.
  • Sequence-level balance loss: A coefficient of 0.0001, used only to prevent extreme imbalance within a single sequence.
  • Node-limited routing: Each token is sent to at most 4 nodes, chosen by the sum of the highest affinity scores of the experts on each node, and experts are then selected on those nodes.
  • Expert configuration: 1 shared expert and 256 routed experts, with 8 routed experts activated per token; the first 3 layers use dense FFNs.

(2) Comparing load-balancing methods.

Method How it balances Interference with the language-modeling objective Used by
Auxiliary loss An extra loss pushes down the routing probabilities of overloaded experts Yes, growing with the coefficient \(\alpha\) GShard, Switch Transformer
Capacity cap + token dropping A hard cap per expert; overflow tokens skip the expert No gradient conflict, but dropped tokens lose computation GShard, Switch Transformer (together with the auxiliary loss)
Global-batch auxiliary loss The same loss, with load counted over the whole global batch Yes, but a looser constraint that allows specialization Qwen3
Auxiliary-loss-free bias A per-expert bias shifts the top-k selection and is updated each step None: the bias is not trained by gradient and does not enter the gate weights DeepSeek-V3 (plus a tiny sequence-level loss), GLM-4.5

Follow-up questions

Follow-up 1: Why is the bias used only for selecting experts and not for computing the gate weights?

Because the bias is a knob for regulating load, not a measure of match quality. If the bias were also added to the gate weights, an expert whose bias was raised merely because it was idle would have its output given excessive weight, distorting the layer's output, i.e. sacrificing the quality of the model's computation for the sake of balance. Using the bias only for selection confines load balancing to "whom to choose", while "how to combine the chosen experts" is still decided by the true affinities.

Follow-up 2: Is the bias learned by gradient descent? What happens if the update speed \(\gamma\) is too large or too small?

It is not learned by gradient descent; it is adjusted directly from load statistics. At each step one only checks whether each expert is overloaded or underloaded and adds or subtracts a fixed step \(\gamma\). If \(\gamma\) is too large, the biases change sharply and the same kind of token switches experts frequently from step to step, making routing unstable; if \(\gamma\) is too small, the biases cannot keep up with changes in load and correct imbalance too slowly. DeepSeek-V3 sets \(\gamma\) to 0 at the end of training so that routing stays stable in the final phase.

Follow-up 3: If the method is auxiliary-loss-free, why does DeepSeek-V3 still keep a sequence-level loss?

Because the bias is adjusted from the load of the whole batch and cannot control extreme cases within a single sequence. Even when the batch is balanced overall, the tokens of one long sequence may all crowd onto a few experts, creating a local hot spot during inference or computation. The sequence-level loss, with its tiny coefficient, only guards against such extremes, and its interference with the language-modeling objective is negligible.

Common mistakes

  • Do not say that the auxiliary-loss-free method has no balance loss at all: DeepSeek-V3 still keeps a sequence-level balance loss with a coefficient of 0.0001.
  • Do not say that the bias is added to the gate weights: It affects only the top-k selection.
  • Do not say that the bias is learned by backpropagation: It is adjusted directly by a fixed step according to the load statistics at each step.

5.6 What are the engineering challenges of MoE in training and inference? ★★

One-sentence answer

In training, the large number of experts requires expert parallelism, and every MoE layer needs all-to-all communication before and after the experts, with heavy traffic and low cross-machine bandwidth, while load imbalance creates straggler GPUs; router logits are prone to instability in low precision, which is usually handled by computing the router in fp32 and adding a router z-loss. In inference, memory must hold every expert while each token uses only the active parameters; with a very small batch only a few experts need to be read and decoding is fast, but as the batch grows almost every expert is activated, and a much larger batch is needed to saturate the GPU; and since MoE sparsifies only the FFN, it does not shrink attention's KV cache.

I will address four aspects: expert parallelism and communication, numerical stability in training, memory and batch effects at inference, and the KV cache.

(1) Expert parallelism places experts on different GPUs, and every MoE layer needs two all-to-all communications.

Large MoE models have too many experts to keep a copy on every GPU. Expert parallelism (EP) places different experts on different GPUs so that each GPU stores only some of them; dense parts such as attention are still split with data, tensor or pipeline parallelism (see Chapter 3 of the LLM Training Pipeline direction). The problem is that the experts a GPU's tokens need may live on other GPUs, so every MoE layer performs two all-to-all communications: in dispatch, each GPU sends its tokens to the GPUs holding their target experts; after the experts compute, in combine, the results are sent back to the GPUs the tokens came from and summed with the gate weights. The forward pass has these two communications per layer, the backward pass has two more, and the traffic grows in proportion to the number of tokens, \(k\) and the hidden dimension. All-to-all is expensive because it is many-to-many communication in which every GPU exchanges data with every other GPU; GPUs within a machine are linked by fast NVLink, while traffic across machines goes over networks such as InfiniBand with several times less bandwidth, so once experts are spread across machines, communication easily becomes the bottleneck. Load imbalance also directly affects efficiency: the GPUs holding popular experts process far more tokens than the others, and the whole layer waits for them. There are three common kinds of mitigation:

  • Limit how many nodes each token reaches: For example, DeepSeek-V3 sends each token to at most 4 nodes, choosing nodes first and then experts within them, which cuts cross-machine traffic.
  • Overlap communication with computation: Compute one chunk of data while another is in flight; DeepSeek-V3 designed the DualPipe pipeline schedule for this and open-sourced DeepEP, a dedicated all-to-all communication library.
  • Good load balancing: See 5.3 and 5.5, to avoid straggler GPUs.

(2) Numerical instability in the router is a major reason MoE training diverges more easily than dense training.

MoE models are more prone than dense models to loss spikes and even divergence, and one major cause is the router: router logits can grow larger and larger during training, softmax contains an exponential, and in low-precision formats such as bf16 the rounding errors of large values are amplified by the exponential; meanwhile, top-k selection is discrete, so a tiny perturbation of the logits can change the selected experts and abruptly switch the token's computation path, which shows up as discontinuous jumps during training. Switch Transformer's response was selective precision: computing the router in fp32 while keeping the rest in bf16, together with a smaller initialization scale. ST-MoE (Zoph et al. 2022) found this insufficient at larger scales and proposed the router z-loss, which penalizes the square of the log-sum-exp of the router logits, keeping the logits in a smaller range and reducing numerical error (the formula is in "Going deeper" below). In their experiments, the z-loss stabilized training without hurting quality. In addition, MoE has a problem specific to RL post-training: the same token may be routed to different experts before and after a parameter update, or in the training engine versus the inference engine, which makes the token-level importance ratio fluctuate wildly; routing replay or the sequence-level GSPO is commonly used to mitigate it (see Chapter 8 of the LLM Training Pipeline direction).

(3) At inference, memory scales with total parameters and compute with active parameters, and MoE's benefit depends on the batch size.

The most striking feature of MoE at inference is that memory and compute are decoupled: memory must hold every expert, because the next token might be routed to any of them, while each token's computation uses only the active parameters. For example, Mixtral 8x7B's 47B parameters take about 94 GB in bf16, more than one 80 GB GPU can hold, yet each token's compute is like that of a 13B dense model. Decode is limited by memory bandwidth, and most of each step's time goes into reading weights from memory (see Chapter 0 of the Inference, Evaluation and Deployment direction), and at each step MoE has to read "every expert selected by at least one token in this step", so the batch size determines MoE's benefit:

  • With a very small batch, MoE has a big advantage: For a single user, for example, only \(k\) experts per layer are used, so only those \(k\) experts plus the shared parts need to be read, close to the active parameter count. As long as the whole model fits in memory, Mixtral generates at close to the speed of a 13B model rather than a 47B one.
  • As the batch grows, the advantage gradually disappears: With \(B\) tokens each choosing \(k\) experts, soon almost every expert is selected at every step, and the amount read approaches the total parameter count, similar to a dense model of the same size; worse, each expert receives only about \(Bk/E\) tokens, far fewer than the \(B\) tokens each weight matrix processes in a dense model, so each weight read does very little computation and the GPU's compute units are starved. To make MoE compute-bound, it needs a much larger batch than a dense model (roughly \(E/k\) times larger).

This explains how MoE is typically deployed: in large-scale online serving, experts are spread across many GPUs with expert parallelism and many concurrent requests are pooled into large batches, so every expert receives enough tokens and MoE's small per-token compute can fully turn into throughput and cost advantages; at inference DeepSeek-V3 also replicates heavily loaded experts to ease hot spots. Conversely, in local or single-user settings the bottleneck is mainly whether the model fits in memory, which is usually handled with quantization or by keeping some experts in CPU memory.

(4) MoE does not shrink the KV cache, so it is usually paired with KV-efficient attention.

MoE sparsifies only the FFN, while the KV cache comes from attention. Attention in an MoE is still dense and shared by all tokens, so an MoE model's KV cache is exactly as large as that of a dense model with the same attention configuration; activating only a few experts does not shrink it (see Chapter 1 of the Inference, Evaluation and Deployment direction for how the KV cache is computed). With long contexts and large batches, once MoE has pushed FFN compute down, the KV cache becomes an even more prominent share of decode's memory and bandwidth cost. MoE is therefore usually paired with KV-efficient attention: DeepSeek-V3 and Kimi K2 use MLA, Qwen3-235B-A22B uses GQA (only 4 KV heads for 64 query heads), and Qwen3.5 uses linear attention in 3 out of every 4 layers (these methods are covered in Chapter 2). Think of the division of labor this way: MoE cuts the FFN's compute, while methods such as GQA and MLA cut attention's KV cache, and the two are complementary.

In summary: MoE turns a compute problem into a memory, communication and scheduling problem: per-token FLOPs go down, but whether that turns into speed and cost advantages depends on how well the system around it, including expert parallelism, load balancing and batch size, is designed.

Going deeper: communication volume, the router z-loss, estimating batch effects, and DeepSeek-V3's inference deployment

(1) A rough estimate of communication volume.

In dispatch, each token sends out \(k\) copies of its \(d\)-dimensional hidden state. For DeepSeek-V3, with \(d = 7168\) and \(k = 8\), the dispatch volume per token per MoE layer is about \(8 \times 7168 \times 2 \approx 115\) KB in bf16, and DeepSeek-V3 halves it by quantizing the activations to FP8 before dispatch. Node-limited routing cuts cross-machine traffic further: each token is sent over InfiniBand to at most 4 nodes, and once it arrives it is forwarded over NVLink to the GPUs holding its target experts.

(2) The router z-loss.

\[ \mathcal{L}_z = \frac{1}{T}\sum_{t=1}^{T}\Big(\log \sum_{j=1}^{E} e^{h_j^{(t)}}\Big)^2, \qquad \mathcal{L} = \mathcal{L}_{\text{CE}} + c_B\, \mathcal{L}_{\text{aux}} + c_z\, \mathcal{L}_z \]

Here \(h_j^{(t)}\) is token \(t\)'s routing logit for expert \(j\), and \(\log \sum_j e^{h_j}\) is the log-sum-exp of the logits, roughly tracking the size of the largest logit; the total loss \(\mathcal{L}\) is a weighted sum of the language-modeling loss \(\mathcal{L}_{\text{CE}}\), the load-balancing loss and the z-loss, with coefficients \(c_B\) and \(c_z\); ST-MoE uses \(c_z = 0.001\). ST-MoE also compared an alternative stabilizer, tighter update clipping, which stabilized training too but clearly hurt quality.

(3) Estimating batch effects.

\[ \text{tokens per expert per step} \approx \frac{B \cdot k}{E}, \qquad \Pr(\text{a given expert is idle in a step}) \approx \Big(1 - \frac{k}{E}\Big)^{B} \]

Here \(B\) is the number of tokens in this decode step's batch, and the second expression assumes routing is roughly uniform and independent. For example, with \(E = 256\), \(k = 8\) and \(B = 64\), each expert receives on average only 2 tokens, whereas each weight matrix of a dense model processes 64 tokens; meanwhile the probability that a given expert is idle is about \((1 - 8/256)^{64} \approx 0.13\), i.e. about 87% of experts have to be read at every step.

(4) DeepSeek-V3's inference deployment.

Stage Minimum deployment unit Attention parallelism MoE parallelism Key points
Prefill 4 nodes, 32 GPUs TP4 + sequence parallelism, DP8 EP32 32 redundant experts deployed, replicating heavily loaded experts
Decode 40 nodes, 320 GPUs TP4 + sequence parallelism, DP80 EP320 Each GPU hosts only 1 expert, with another 64 GPUs hosting redundant and shared experts

At decode the experts are spread more thinly, so each GPU stores less expert weight and can leave more memory for the KV cache and larger batches; the tokens from all requests that chose the same expert are sent to the same GPU and computed as one batch. These are the configurations given in the technical report; in the online inference system DeepSeek described publicly in 2025, the decode stage uses EP144 spanning 18 nodes (DeepSeek-AI 2025), showing that the exact degree of parallelism is adjusted to the hardware and the load.

Follow-up questions

Follow-up 1: Why does MoE need a larger batch to saturate the GPU?

Because each expert receives only a small fraction of the tokens in the batch. Whether decode saturates the GPU depends on how much computation is done per weight read, i.e. how many tokens each weight matrix processes at once. In a dense model each weight matrix processes all \(B\) tokens of the batch, while in MoE each expert processes on average only about \(Bk/E\) tokens, an arithmetic intensity about \(E/k\) times lower. MoE therefore needs a batch roughly \(E/k\) times larger to reach the same GPU utilization, which is also why it suits large-scale, high-concurrency serving.

Follow-up 2: How do you run an MoE model locally when GPU memory is insufficient?

There are two main approaches: quantization and expert offloading. Quantization compresses the weights to 4 bits, bringing Mixtral's 47B parameters down to about 24 GB, close to the capacity of a 24 GB consumer GPU (quantization is covered in Chapter 3 of the Inference, Evaluation and Deployment direction). Expert offloading exploits MoE's sparsity by keeping most experts in CPU memory and copying the selected ones to the GPU only when needed; the problem is that PCIe bandwidth is more than an order of magnitude lower than GPU memory bandwidth, so copying an expert takes far longer than computing with it, and it is usually combined with caching recently used experts (consecutive tokens often choose the same experts) and prefetching the next layer's experts in advance. Such methods suit only single-user, low-throughput settings.

Follow-up 3: Can MoE reduce the KV cache?

No. The KV cache is determined by attention's number of layers, number of KV heads and head dimension, while MoE changes only the FFN. An MoE model's KV cache is exactly the same as that of a dense model with the same attention configuration; reducing it requires attention-side designs such as GQA, MLA or linear attention.

Common mistakes

  • Do not say that MoE inference is always faster than a dense model with the same total parameters: With large batches almost every expert has to be read, and the advantage depends on the deployment.
  • Do not say that MoE reduces the KV cache: The KV cache is determined by attention, and MoE sparsifies only the FFN.
  • Do not say that MoE inference memory depends only on the active parameters: Every expert must be loaded, so memory scales with total parameters.
  • Do not say that MoE training instability can only be fixed by tuning the learning rate: The router's numerical problems need dedicated tools such as an fp32 router and the z-loss.

5.7 How do you choose between dense and MoE? ★

One-sentence answer

At equal training compute MoE is stronger; at equal total parameters dense is stronger. MoE trades more memory and a more complex system for less compute per token, which suits settings where compute is the main constraint, serving scale is large and expert parallelism is feasible, and this is why most frontier open models in 2025 and 2026 use MoE; in memory-constrained on-device deployment, at low concurrency, or when simple deployment matters, a dense model is often more suitable.

I will address three aspects: the essential difference between the two, how to choose based on constraints, and the recent design trends.

(1) The essential difference: MoE pays with memory and system complexity to get less compute per token.

At equal training compute, MoE has far more parameters to store knowledge and therefore performs better; at equal total parameters, a dense model uses all of its parameters for every token and is therefore stronger. MoE's costs show up in three ways: memory scales with total parameters, so deployment needs more GPUs; both training and inference are more complex, requiring load balancing, all-to-all communication and handling of router instability; and fine-tuning is trickier, since ST-MoE found that MoE overfits more easily than dense models on small datasets (Zoph et al. 2022).

(2) The choice depends on the constraints: compute, memory, concurrency and engineering capacity.

  • Settings that favor MoE: Training compute is the main constraint and you want the best quality per training FLOP; online serving is large-scale and high-concurrency, so large batches can be pooled; and there are enough GPUs and engineering capacity for expert parallelism.
  • Settings that favor dense: Memory is constrained, such as on-device or on a single GPU, where total parameters are the bottleneck; concurrency is low, so MoE's large-batch advantages go unused; or you want deployment, fine-tuning and quantization to be as simple as possible. Small models from about 1B to 30B are therefore still mostly dense: Qwen3's 0.6B to 32B models and Gemma 3, for example, are all dense. That said, small MoE models (such as Qwen3-30B-A3B and gpt-oss-20b) decode quickly for a single user as long as they fit in memory, and are also popular for local deployment.

(3) The trend: frontier models have broadly moved to sparser, fine-grained MoE.

From 2024 to 2026, most frontier models with published architectures use MoE, and three trends stand out:

  • Experts are becoming more numerous and finer: From Mixtral's 2 out of 8 experts to 6 to 10 out of 256 to 512 experts.
  • Sparsity keeps increasing: Active parameters as a share of total parameters have fallen from about 28% for Mixtral to 3% to 5%, so the same compute supports ever larger total capacity, a choice backed by Kimi K2's sparsity scaling law (see 5.1).
  • Load balancing keeps evolving: From a strong auxiliary loss, to a global-batch auxiliary loss, to the auxiliary-loss-free bias method.

Meanwhile, MoE is almost always paired with KV-efficient attention (see 5.6).

In summary: choosing between dense and MoE is not about "which is more advanced" but about trading off compute, memory and system complexity; MoE has become mainstream for large-scale training and serving, while dense retains its advantages where resources are constrained and simple deployment is the priority.

Going deeper: comparing dense and MoE, and representative MoE models from 2023 to 2026

(1) Comparing dense and MoE.

Dense MoE
Parameters used per token All of them Shared parts + the \(k\) selected experts
Compute per token Proportional to total parameters Proportional to active parameters
Memory for weights Proportional to total parameters (equal to active) Proportional to total parameters (much larger than active)
Quality at equal training compute Baseline Better: more capacity for the same FLOPs
Quality at equal total parameters Better Worse
Training difficulty Stable and simple Load balancing, router instability, possible token dropping
Parallelism Data, tensor, pipeline Additionally needs expert parallelism and all-to-all communication
Decode at small batch Reads all weights each step Reads only the active experts; fast if the model fits
Decode at large batch Good GPU utilization Reads nearly all experts; needs much larger batches
Fine-tuning Straightforward More prone to overfitting on small datasets
Best fit Memory-constrained, on-device, simple deployment Large-scale serving, best quality per training FLOP

(2) Representative MoE models and their sparsity.

Model Release Total params Active params Active share Expert configuration
Mixtral 8x7B (Jiang et al. 2024) Dec 2023 47B 13B About 28% 2 of 8, no shared expert
DeepSeek-V3 (DeepSeek-AI 2024) Dec 2024 671B 37B About 5.5% 8 of 256, 1 shared expert
Qwen3-235B-A22B (Yang et al. 2025) Apr 2025 235B 22B About 9.4% 8 of 128, no shared expert
Llama 4 Maverick (Meta 2025) Apr 2025 400B 17B About 4.3% 1 of 128, 1 shared expert, alternating with dense layers
Kimi K2 (Kimi Team 2025) Jul 2025 1.04T 32B About 3.1% 8 of 384, 1 shared expert
gpt-oss-120b (OpenAI 2025) Aug 2025 117B 5.1B About 4.4% 4 of 128, no shared expert
Qwen3.5-397B-A17B (Qwen Team 2026) Feb 2026 397B 17B About 4.3% 10 of 512, 1 shared expert
GLM-5 (GLM-5 Team 2026) Feb 2026 744B 40B About 5.4% 8 of 256, 1 shared expert
DeepSeek-V4-Pro (DeepSeek-AI 2026) Apr 2026 1.6T 49B About 3.1% 6 of 384, 1 shared expert
DeepSeek-V4-Flash (DeepSeek-AI 2026) Apr 2026 284B 13B About 4.6% 6 of 256, 1 shared expert

"Expert configuration" gives the number of routed experts activated per token out of the total routed experts in each MoE layer. Since 2025, flagship MoE models mostly activate between 3% and 6% of their parameters, while total parameters have reached the trillion scale.

Follow-up questions

Follow-up 1: Why do most frontier models now choose MoE?

Because in training and large-scale serving, MoE delivers more quality per unit of compute. Training cost is driven mainly by active parameters: DeepSeek-V3's full training took only about 2.788M H800 GPU hours, and the most fundamental reason is that its 671B of total capacity needs only 37B parameters of compute per token (DeepSeek-AI 2024); on the serving side, frontier models have enough concurrency to turn MoE's small per-token compute into cost advantages through expert parallelism and large batches. Note, however, that many closed models do not disclose their architectures, so "most" refers mainly to models with published architectures.

Follow-up 2: What should you watch out for when fine-tuning an MoE model?

Guard against overfitting, and pay attention to which parameters are updated. ST-MoE found that when MoE models are fine-tuned on small datasets, training loss goes lower while validation quality gets worse; updating only the non-MoE parameters (such as attention) works about as well as updating all parameters, whereas updating only the expert parameters works worse; and MoE fine-tuning tends to prefer smaller batches and higher learning rates (Zoph et al. 2022). In addition, the fine-tuning data is distributed differently from pretraining, so the routing load may become unbalanced again, and the load of each expert should keep being monitored.

Follow-up 3: Is MoE a good fit for small models?

It depends on the deployment setting. On a memory-constrained device, total parameters are the bottleneck, and a dense model in the same memory performs better; if memory is sufficient and decoding speed is the main goal, a small MoE (such as Qwen3-30B-A3B) can, for a single user, run at roughly the speed of a 3B model while performing far better than a 3B model, which is why it is also popular for local deployment.

Common mistakes

  • Do not say that MoE is better than dense in every respect: At equal total parameters dense is stronger, and MoE's memory and deployment costs are higher.
  • Do not treat an MoE and a dense model with the same active parameters as equivalent: Their compute is similar, but MoE needs far more memory.
  • Do not say that small models should always use MoE: In memory-constrained settings such as on-device deployment, total parameters are the bottleneck, and dense is often more suitable.