skip to content
← Scientific Spaces English

MoE Journey, Part 9: The Debate over Gate Normalization

Tracing back the history of MoE, we can all find that in earlier years, when an MoE router acted as a gate to multiply onto the experts, it almost always used Softmax activation, and even now it remains one of the standard forms of MoE. However, to coordinate with Loss-Freeload balancing, DeepSeek changed the activation function to Sigmoid and demonstrated that this is also quite a competitive approach, prompting deeper reflection and experimentation on the form of the router.

Even within discussions of Softmax, there are two slightly different practices: whether to apply Softmax first and then select the top-, or to select the top- first and then apply Softmax? The latter can also be understood as selecting the top- and then performing normalization once more, namely Re-Norm. So, should the gate's activation function be normalized, and if so, should one normalize and then select the top- or apply Re-Norm? This is precisely the topic this post aims to discuss.

Problem Description #

As we know, the general form of an MoE is

Here, actually plays two roles: when it is used to select the top- experts, its role is Router; when it is multiplied onto the experts, its role is Gate. From the design perspective of MoE, 's core role is obviously Router, while the role of Gate is to provide gradients for it during training.

The question we want to discuss can also be understood as how to more scientifically construct , so that the router can obtain better gradients. For a long time, the standard answer has consistently been Softmax, namely

where are logits directly projected by a linear layer. However, although this answer is "standard", I have not found any explanation for it; everyone seems to have simply accepted it and carried it on, which once left me very confused about the training mechanism of MoE.

Other Choices #

As mentioned at the beginning, DeepSeek experimented with Sigmoid activation in Loss-Free load balancing, and later also used it in DeepSeek-V3, where its success demonstrated that non-Softmax activations can also achieve good results. This inspired everyone to explore more general practices; for instance, ReMoE used ReLU activation, while our geometric perspective in MoE Journey, Part 1: Starting from Geometric Meaning allows the use of any non-negative activation function.

In addition, regarding the form of MoE, there is also the choice of Re-Norm, which changes to

that is, for the selected top- , performing normalization once again. For Softmax, this is equivalent to using to select the top-, setting the unselected ones to , and then applying Softmax. The benefit of Re-Norm is making the forward computation numerically more stable, but note that when using Re-Norm, must be greater than 1; otherwise, will have zero gradient, making training impossible.

Taking into account current practices from all sides, the performance of these MoE variants is much the same, with none holding a significant advantage. Since practice cannot determine a clear winner, let us investigate theoretically which form is more scientifically sound.

Design Principles #

Our goal is to find a first principle closer to the essence and use it to derive the gating mechanism of current MoEs.

Therefore, the first question is naturally what this "principle" is. For simplicity, let us first consider . As we know, the most important characteristic of an MoE is sparsity: it first determines the experts to activate via a router, and then computes only those experts, thereby scaling up parameter count while controlling computational cost. If we take only this idea, then the naive model should be

that is, picking the expert with the highest score from router to activate the corresponding expert. This form is completely fine for inference, but during training, the router will receive no gradient at all and thus cannot be updated, so we must find a way to design gradients for the router. How do we design gradients for the router? To answer this question, we must first think clearly about what kind of router we need.

Since only 1 expert can be activated, we naturally hope that this expert is the one with the best performance. If we use to denote the loss function, our expectation can be written as

This is precisely the design principle we are looking for.

Objective Transformation #

However, the objective is not yet a loss function that can be directly used for training; it still requires further transformation. To this end, we construct two distributions. The first is a target distribution constructed based on the loss function, , defined as

This distribution has nothing to do with the router; for the router's learning, it counts as a "target distribution". The second distribution is based on to construct the predicted distribution , for which there are many possibilities; for instance, itself is the distribution (if is already normalized), or is 's Softmax (where is logits), or some normalization method other than Softmax. In short, is some probability distribution representation of the router, with its parameters denoted by .

We transform the objective into closing the distance between and , thereby providing gradients for . To this end, we consider minimizing the KL divergence

With a slight rearrangement, we obtain

As we can see, this objective consists of three terms. The first term is the negative entropy ; minimizing it means maximizing entropy, which in effect encourages the model to explore thoroughly. We can consider that load balancing has already assumed a similar role, so we set it aside for now; the third term is independent of , which means it is independent of , so the equivalent loss function is

Straight-Through Estimation #

Taking the gradient of the equivalent loss yields

The key here is using to isolate a factor of , so that the summation can be converted into an expectation, thereby achieving the sparse computation goal of MoE through sampling. Some readers may have already recognized that this is precisely REINFORCE in policy gradients! (See "Viewing Optimization from Sampling: A Unified Perspective on Differentiable and Non-Differentiable Optimization", "Policy Gradients and Zeroth-Order Optimization: Different Routes to the Same Goal")

The problem with REINFORCE is its high noise. Intuitively, this is because it places outside the loss function ; if possible, we would much rather use a "reparameterized" form with inside . To derive such a form, we leverage the invariance of REINFORCE to baseline subtraction to get

where the approximate equality comes from a first-order Taylor approximation at , and represents Stop Gradient. Ultimately, we obtain a Straight-Through Estimator (STE) that "uses in the forward pass and in the backward pass" to provide gradients for the router.

Final Form #

While STE provides a viable training scheme, due to the inconsistency between the forward and backward passes, it often achieves only suboptimal results. At this point, a very neat improvement is to change each expert to ! Repeating the derivation above, we have

This transformation is very ingenious and well worth savoring. By changing the expert from to , we eliminate the Stop Gradient, achieve consistency between the forward and backward passes, and theoretically raise the ceiling on model performance.

Now, we can answer the question from the beginning:

If we require a top-down probabilistic derivation, then the router, when serving as a gate, should be normalized, but should not undergo Re-Norm.

Sampling or Not #

A detail worth noting is that implies that we should sample from , but in practice we usually just select Top-; how should we understand this difference?

This is actually a trade-off between diversity and stability. Random sampling encourages the model to explore more thoroughly, but sampling increases gradient variance and introduces additional instability; directly selecting Top- is relatively stable, but raises concerns about the model getting trapped in suboptimal solutions or even collapsing. Fortunately, various load balancing strategies are now very mature and have already encouraged comprehensive exploration to a certain extent, so selecting Top- remains the mainstream choice.

If you want to maintain stability while sampling, you can expand slightly on Top- rather than opening up sampling completely—for example, by first selecting Top-, and then among the experts randomly picking , or adding slight noise to the logits of before selecting Top-, which increases randomness without straying too far from the original Top-, thus balancing stability.

Related Work #

To clarify, the derivation in this post is not actually new; I distilled and modified it from Dr. Liyuan Liu's paper 《Sparse Backpropagation for MoE Training》, which also has a preceding paper, 《Bridging Discrete and Backpropagation: Straight-Through and Beyond》 and a follow-up paper, 《GRIN: GRadient-INformed MoE》.

Even though these are already papers from back in 2023 and 2024, to deepen one's understanding of MoE routers, I still strongly recommend reading this trilogy. They provide a unified probabilistic framework for designing gradients for various discretization operations. Of course, the probabilistic framework also has its limitations, namely that it is rather formalized, making it feel a bit "tied hand and foot" in practice.

For example, when , if we extend the previous results in parallel, it should be

That is, taking the joint distribution and the sum of the expert pair as the basic unit to convert Top-2 into Top-1. However, the MoE we have been using all along is actually of the form , which makes it difficult to find an exact probabilistic derivation.

At this point, a more "relaxed" way of understanding it might be to simply treat it as an analogue of MaxPooling without forcing a probabilistic interpretation; of course, one can also choose the geometric interpretation in MoE Journey, Part 1: Starting from Geometric Meaning. In general, the probabilistic framework merely proves the feasibility of a certain scheme, but in principle does not rule out the feasibility of other schemes.

Summary #

Starting from first principles, this article attempts to explore the design of the Router and Gate in MoE, providing a probabilistic interpretation for gate normalization.