Mixture-of-experts (MoE) models enable practitioners to scale up total parameter count to impressive sizes (with the recent Kimi K3 reaching 2.8T parameters!), while leaving the compute per token (and in the compute-bound regime, cost) at both training and inference unchanged.
To understand how MoE models work, first consider a basic multilayer perceptron in a transformer of width D. It has a hidden layer with (commonly) 4D hidden units (you may find 2.7D MLPs if a gated nonlinearity is used instead of the element-wise ReLU² I use here). Now, what if we could change which hidden units are used for each token? An MoE does exactly this. It uses a router to score num_experts groups of hidden units (the experts), each group of size routed_width, and picks the top num_active groups to be used for that token. However, not every hidden unit is routed: there is usually also a shared expert, a group of shared_width hidden units that every token uses.
To support future projects, such as looped or latent feedback (also called Full Bandwidth) transformers, I need a strong, compute-efficient baseline that maximises capability per FLOP.
Given the gains offered by MoEs, I performed over 140 runs using a custom nanochat repository (nanochat-dl) to systematically study their optimal settings and scaling behaviour, as guidance for future experiments. Throughout, dL denotes a model with L layers and width D = 64L (d12 has 12 layers and D = 768), trained by default on 12 tokens per active parameter (the transformer's matrices and output head, counting only the experts a token uses).
1. Optimal MoE shape#
There are four key parameters that affect an MoE's properties: the number of active experts to be selected (num_active), the width of each routed expert (routed_width), the width of the shared expert (shared_width), and the total number of experts (num_experts). Each token uses shared_width + num_active*routed_width hidden units; keeping this constant (at the dense MLP's 4D) keeps the cost per token the same, while increasing the total number of experts scales total parameters (shared_width + num_experts*routed_width hidden units) independent of compute per token.
You might wonder: if a mixture of experts can choose which experts to route to, why do we need a shared expert at all? Although it is correct that a shared expert is a subset of what an MoE can express (simply have the router always give it the top score), in practice load-balancing techniques such as quantile balancing (which I use for this project) force experts to be selected uniformly. If every token needs the same shared_width hidden units, and the routing is forced to be uniform, then even in the best case each expert has to hold shared_width/num_active of them. That is shared_width*num_experts/num_active hidden units in total doing the work of shared_width: 8 times as many at a sparsity of 1 in 8. Thus, it is important to select the right shared width.

From the sweep, we can see that a shared width of around D is optimal for the wider routed experts (D and D/2), while for D/4 and D/8 the loss is still improving at 2D. If we over-allocate the shared width, we can only lose some efficiency (each extra shared unit is still used by every token, it just cannot specialise), but if we under-allocate it then, as shown above, each missing unit is paid for num_experts/num_active times over. So to stay on the safe side, I picked a shared width of 2D.
Next, let's see how the size of the MoE affects the best routed width. With the shared width fixed, the added parameters are determined by num_experts*routed_width, so at a fixed size, narrower experts mean more of them. The number of possible expert combinations grows combinatorially as routed width decreases, so possibly, with more parameters, narrower experts would become preferred even given the harder routing. The sweep below shows this trend: the preferred routed width keeps decreasing as we increase the number of MoE parameters.

2. Scaling parameters#
So in the previous section we found that a routed width of D/2 or D/4 is optimal (the two perform about the same), and I also decided on a shared width of 2D to stay on the safe side. Let's see what happens when we use a routed width of D/2 and scale the number of experts:

Here, every curve comes from a single fit with one irreducible loss shared by all the models (the scaling law of section 4), in which an MoE counts as a dense model with more effective parameters. The loss steadily decreases with more experts, even though the number of active parameters (and thus compute) stays the same. At 128 experts, the fitted curves predict a 2.1× to 2.5× compute multiplier. Let us see how the loss decreases with the number of total parameters:

Each doubling of the number of experts lowers the loss by about 0.01 bits per byte at every depth; only the smallest model (d4) flattens out at 128 experts.
3. Scaling compute#
At this point, one parameter is left free: the number of experts. There is no optimum based on compute alone, and wall-clock measurements would be overly hardware dependent. Thus, I chose a sparsity of 1 in 8 (1 in 8 routed experts is active per token), as it is roughly the sparsity of older MoE models and seemed like a reasonable tradeoff between loss and total size, giving 4.5× MLP parameters. It turns out that the D/4 routed width performs better, and you can see that the points lie lower, giving a marginal couple-percent compute gain on top:

This only shows us that the new model (64 experts of width D/4, 8 active) reduces loss and gives us a compute multiplier. However, we might also expect that the optimal tokens per parameter (TPP, here per active parameter) would change as we have a large number of experts. So, here, I use the dense models' FLOPs as a reference and vary the MoE depth (which scales the entire model proportionally) at matched total FLOPs, so shallower models, with fewer active parameters, train on more data. After sweeping the compute budgets of dense d6, d8, d10, d12 and d14, here are the results:

We really are able to achieve much better loss at the same total FLOPs. The optimal MoE depth seems to be just slightly under the optimal dense depth, but otherwise the same. If we look more closely at the minimum, we find that the best active parameters and best total parameters have compute-scaling exponents around 0.49 and 0.53 (they differ because the output head, which grows only with the width, is a larger share of the active parameters than the embedding and head are of the total):

Note that to maintain a constant optimal TPP, the scaling exponent would have to lie around 0.5 (meaning additional compute is best split 50:50 in log space between parameters and data). Since the active-parameter scaling exponent is slightly lower, at 0.49, this means that we would prefer allocating slightly more of our additional compute to data. Hence, the optimal TPP would increase slowly (and conversely, since 0.53 > 0.5, tokens per total parameter decreases slowly).
At this small, compute-bottlenecked scale, this won't really matter. But it does have implications when data is limiting instead of compute.
4. Beating dense at equal size#
One interesting finding of this MoE scaling paper is that an MoE can actually beat a dense model, even while matching both compute and total parameters. This is initially really surprising, as intuitively one would expect MoE's additional parameters to be "less effective" than dense ones, since they are not even used all the time. However, if we look at how loss changes with both model parameters and data, we find why.
Here, I model the loss by combining , the irreducible entropy, with a term that shrinks with the parameters and a term that shrinks with the data (training tokens):
counts the active parameters without the embedding and output head. An MoE whose MLP holds times the dense MLP's parameters counts as a dense model with parameters, its effective parameters; the fit gives , so at .
At the optimum point, if we halved the parameters, it would take roughly double the data to make up for the lost capacity, as by the method of Lagrange multipliers the iso-loss curve must be tangent to the iso-FLOP curve at the minimum. However, suppose we were able to get double the data, but only need to reduce our effective model capacity by about a third. Then evidently this gives us an iso-FLOP improvement. This is what the MoE does: with the same total parameters as dense d12, it has only about a third of the active non-embedding parameters (30M against 85M), so the same compute buys 2.2× the data, while its effective parameters drop by only a third. That moves it off the dense iso-FLOP curve and inside the tangent iso-loss curve:

From the fixed-compute sweep above, we can read off the MoE's loss at each dense model's total parameters and plot it against dense:

At the same compute and the same total parameters, the MoE is still ahead of dense: by 0.010 to 0.019 bits per byte, which the fit puts at 1.3× compute at d6 and 1.1× at d14. The black crosses show actual runs at matched compute and total parameters, validating that the MoE models actually exist.
5. Remark#
Since I ran so many experiments, we can actually also see how the CORE score changes with val BPB:

CORE follows the validation loss along one curve for all 148 runs. At the same loss, the dense models score slightly higher (about 0.01).
6. Conclusion#
In conclusion, I ran over 140 pretraining runs across a wide variety of MoE shapes. I settled on a shared_width = 2D, routed_width = D/4, num_experts = 64 and num_active = 8 configuration in the end. All the checkpoints are on Hugging Face, here, and the code used to train the models is nanochat-dl (can also find a copy of the code on Hugging Face).
Notes#
-
Narrower experts are more numerous, so the MoE size is fixed within a panel. The parabola is fitted across depths. ↩
-
Every fitted curve from here on, except the CORE figure's, is one scaling law, fitted once to 56 runs: the dense models, this sweep, and the final shape (64 experts of width D/4, 8 active) at its standard length and at five fixed compute budgets. The legend gives the dense compute needed to match the MoE's loss, at 4 and at 12 layers. ↩
-
The two MoE shapes have the same total size, so the fit gives them one curve. ↩
-
The left part of the curves for the larger budgets is extrapolated. ↩
-
Diamonds are the fit's best size at the five compute budgets that were run; the dashed lines are the same minimum at every compute. ↩
-
An MoE sits at its effective parameter count. The black contour is the best loss on the dense line. ↩
-
Diamonds are interpolated between MoE runs, at the dense model's total parameters. Crosses are actual MoE runs within 15% of that count. ↩