So far, seven articles have been written in the "MoE Journey" series, five of which center on MoE routing and load balancing. In terms of routing form, they can be divided into two categories: static computation and dynamic computation; in terms of methods for achieving load balancing, they can also be divided into two categories: Aux-Loss and Loss-Free, where Loss-Free can be further divided into the SignSGD scheme proposed by DeepSeek and the QB scheme I proposed.
There is also a detail: the Loss-Free schemes we discussed earlier all achieve balance in the sense of a global batch, whereas in many cases we add a sequence-level Aux Loss to avoid extreme sequence-level imbalance. If we believe that every Aux-Loss scheme has a corresponding Loss-Free counterpart, how should sequence-level Loss-Free balance be implemented? This is precisely the topic to be explored in this post.
Recap of Previous Posts #
First, let us review our previous explorations of load balancing. In MoE Journey, Part 2: Scarcity Is Not the Worry; Imbalance Is, we discussed the load balancing problem of MoE for the first time, proposing the Aux Loss solution—that is, adding an auxiliary loss function to promote balance. The drawback of Aux Loss is that it involves an additional weight coefficient to tune, while its advantage is that the granularity of balancing can be freely adjusted, allowing balance at the sequence, group, or global level (of course, the more global it is, the greater the communication overhead).
Starting from MoE Journey, Part 3: A Different Approach to Allocation, we discussed load balancing strategies in the Loss-Free form, which adjust the degree of balance by introducing an extra bias term and hand-crafting a SignSGD-style rule to update it. This paradigm is more flexible than Aux Loss and is infra-friendly. In MoE Journey, Part 4: Invest More Where It's Hard, we extended it to MoEs with dynamic numbers of activated experts.
And in MoE Journey, Part 6: Optimal Allocation Promotes Balance, we looked at the load balancing problem from the perspective of optimal allocation; by alternately solving the dual objective, we obtained a new load balancing strategy, Quantile Balancing (QB). Strictly in terms of results, it can be viewed as a new, more accurate solving method for the bias term in Loss-Free schemes. Next, in MoE Journey, Part 7: A Minimalist Solution to Dynamic Activation, we likewise extended QB to dynamic MoE.
Here lies a detail: the bias term introduced by Loss-Free is globally shared, so currently all Loss-Free schemes, without exception, can only achieve global load balancing. As mentioned earlier, if needed, Aux Loss can also be used to promote sequence-level balance; does Loss-Free also have a corresponding sequence-level balancing scheme?
Local Centering #
Coincidentally, @ChangJonathanC in the article 《Causal Routing Bias for Aux-Loss-Free MoE Training》, also explored related ideas. The author proposed two approaches. Let's briefly examine them first, which will also make it easier to compare with our own approach later. Let
Then, use
In this way, in the new
Test-Time Training #
The idea behind the second scheme is actually quite intuitive as well. In MoE Journey, Part 3: A Different Approach to Allocation, didn't we introduce a bias term to control global balance? This bias term is updated using SignSGD. That being the case, we can mimic TTT's idea of "test-time training", activating experts token by token along the sequence dimension and updating this bias term based on the distribution of already activated experts.
Taking
where
This idea can preserve sequence causality while also guaranteeing almost absolute balance at the sequence level, but because every step requires selecting the Top-
The Optimal Solution #
Next, the approach proposed in this post is called "Moving Quantile Balancing (MQB)". As the name implies, it evolved from "Quantile Balancing (QB)". To this end, let us first briefly review QB.
In the order I wrote them, first came MoE Journey, Part 6: Optimal Allocation Promotes Balance, followed by MoE Journey, Part 7: A Minimalist Solution to Dynamic Activation, but in fact the latter is much simpler both conceptually and methodologically, so we will start with the latter. As before, given
To simultaneously ensure load balancing and control the average number of activations to be
That is to say, sorting
In fact, this is merely another representation of Expert Choice. As we know, the problem with Expert Choice is that it breaks causality (it is non-causal), which can also be seen from the fact that it computes
Moving Quantile #
Earlier, @ChangJonathanC 's "test-time training" scheme gave me some inspiration. We can compute the bias term token by token based on QB along the sequence dimension. Since QB can directly express the optimal solution for the bias term based on
My initial idea was
CQB is viable in principle, but because quantiles cannot be updated incrementally, CQB has to read the entire data history to perform quantile computation at every step. Its computational complexity increases linearly, making the total complexity quadratic. To alleviate this problem, and also to better reflect local balance, my idea was to set a window
In this way, the operation turns from "Cumulative Quantile" into "Moving Quantile", and the corresponding scheme becomes the prototype of "Moving Quantile Balancing (MQB)". It is very similar to SWA (Sliding Window Attention), has linear complexity, and theoretically can also be parallelized. The reason it is still an "early prototype" is again that quantiles cannot be updated incrementally, resulting in a single-step complexity that remains relatively high, so we still need to find a way to improve it.
Binning Estimation #
All the obstacles mentioned in the previous section are essentially constrained by the fact that "quantiles are nonlinear and cannot be updated incrementally." Is there any possibility that we could manage to linearize it, even if only approximately? Fortunately, here we really can!
A key fact is that: As long as the distribution of a variable is known, quantiles can be obtained via cumulative probability, and distributions can be updated incrementally!Therefore, the key here is to convert the estimation of quantiles into the estimation of distributions. For this, we use binned counting, also known as "histogram approximation". First, assume that router scores
In this way, we obtain an
That is, after binning
The General Case #
So far, our discussion has been based on the dynamic-activation MoE variant, which activates every expert for which
How, then, should Top-
That is, for Top-
To reduce the impact on the primary task, auxiliary loss schemes can lower the loss coefficient, whereas with MQB, we can consider taking a weighted average of the scores before and after:
That is, by introducing
Other Details #
After binning, the core operation of MQB also becomes EMA. So after circling back, we return to EMA, in a form similar to @ChangJonathanC 's first proposed scheme, except that the target of the EMA is different. @ChangJonathanC 's scheme directly applies EMA to the
This change is somewhat like linear attention expanding capacity via outer products to memorize more information, and the optimality of QB also guarantees that it achieves sequence-level balance, rather than remaining an empirical heuristic. Another similarity to linear attention is that EMA is essentially an RNN, so during inference an additional
It should also be pointed out that, whether with QB or MQB, they are only used for expert activation decisions. The gating function that is ultimately multiplied with the experts is still computed based on the original router scores before subtracting the bias terms. This is a common feature of all loss-free schemes, ensuring that the balancing intervention terms do not directly alter the MoE formulation, in order to minimize the impact on the main model.
Finally, regarding the binning method, my current experiments apply a Sigmoid activation followed by
Experimental Results #
For MQB, I ran some simple experiments on a MoE model configuration with about 3B total parameters and top-4 out of 128 routing. The exponential moving average coefficient for MQB is 0.99, the default number of bins is 100, and MaxVio is used as the load balancing metric. Since the first MoE layer is the most imbalanced, below we only demonstrate the results on the first layer.
First is
As can be seen,
Further Thoughts #
From the experiments above, we can further confirm that perfect sequence-level balance (
Overall, this post only answers "how to achieve sequence-level load balancing in a loss-free way." However, as to whether sequence-level load balancing is necessary, why it is needed, and to what extent it is needed, we cannot provide a definitive answer. A preliminary understanding is that extreme sequence-level imbalance might impair the sequence's own performance (collapsing into a smaller model), so we want to encourage a certain degree of sequence-level balance.
Besides MQB, there are actually other schemes that can also achieve sequence-level balance in a loss-free manner. For example, in "Where Does DeepSeek V4's tid2eid Come From?", we introduced Hash Routing, which can also be considered a simple scheme for enforcing sequence balance. But Hash Routing already redefines the routing form and represents an unconventional approach.
The value of a scheme like MQB lies in the fact that it is better compatible with standard MoE formulations and transforms "tuning the auxiliary loss coefficient" into "tuning an interpretable local bias term," allowing us to control the intervention strength more intuitively, while its parallelizability also ensures efficiency. Since it only affects router decisions without injecting gradients, its impact on the primary task's performance is also kept as minimal as possible.
Summary #
Centered around "how to achieve sequence-level load balancing in a loss-free manner," this post started from the original Quantile Balancing (QB) and progressively derived a method named Moving Quantile Balancing (MQB), successfully achieving this goal. However, whether sequence-level balance is truly necessary and to what degree it should be enforced remain an open question.


