skip to content
← Scientific Spaces English

Beyond MuP, Part 3: Special Treatment for Special Cases

After so many related blog posts, many readers are likely already familiar with the Muon optimizer—even if the theoretical details remain hazy, it has probably left the impression of being an "optimizer tailored specifically for matrix parameters." However, this statement is not entirely accurate: for instance, for the embedding layer on the input side and the LM head on the output side, although their parameters are also matrices, they are not well-suited for Muon (see "A Guide to the Muon Optimizer: Quick Start and Key Details").

Why do they receive such "special treatment"? In this post, we will adopt the three stability metrics proposed in the opening article to explore the initialization rules for different types of layers and their corresponding steepest descent directions, thereby answering this question.

Recap #

In the first article, Beyond MuP, Part 1: Three Characteristics of a Good Model, we proposed three stability metrics:

All three metrics share a unified format: compute the RMS of the output, and then take the over the input. Here, denotes the input, denotes the parameters, and can represent a single layer, a block, or even the entire model, depending on our ability to compute the .

Because the domain of is not bounded, the maximum does not always exist. Consequently, we sometimes need to augment the model with certain operations, which in turn guides model design. For example, in the previous article, Beyond MuP, Part 2: Linear Layers and Steepest Descent, to compute the stability metrics of a linear layer, we equipped it with In Norm. Furthermore, by combining this with the idea of steepest descent, we reproduced the derivation of the Muon optimizer.

Steepest descent is not a new concept; it answers the question of "what optimizer should be used given a stability metric," whereas the core contribution of the "Beyond MuP" series is answering the question of "what stability metric should be used," providing calculation formulas for stability metrics that apply to arbitrary layers.

The Embedding Layer #

Now let us consider the embedding layer, which is arguably the simplest layer: the input is an index , and the output is the corresponding vector, namely , where is a matrix, and denotes 's -th row. It is straightforward to calculate:

Notice that "dependency stability" is absent here, because the inputs to an embedding layer are discrete token IDs, and two IDs cannot be subtracted. Of course, one could force the calculation by converting them into one-hot vectors, but that brings no new information; moreover, from the perspective of backpropagation, we do not need to backpropagate into token IDs any further, so there is no need to consider their stability.

The remaining two stability results are the maximum row norm of or (multiplied by ). We use forward stability and dependency stability only to guide initialization, and it instructs us to use zero mean and variance to initialize . As for update stability, Eq. tells us that, although both are matrices, the metric for measuring "stability" in an embedding layer should not be the spectral norm, but rather the maximum row norm, which leads to its steepest descent direction not being Muon.

To find the steepest descent for an embedding layer, we need to solve the optimization problem

This problem is actually straightforward to solve; we only need to apply the Cauchy-Schwarz inequality:

Equality holds at , which means that the steepest descent suitable for an embedding layer applies RMS Norm to the gradient row by row (Normalized SGD).

The Output Head #

Next, let us look at the LM head. On the surface, this is also a linear layer, whose input is , weights are , and output is , usually also equipped with RMS Norm. In every respect it looks like a linear layer, so why is it not suitable for Muon?

Responsible for the Loss #

The answer is that the LM head needs to be "responsible" for the loss.

Note that steepest descent serves training. From an inference perspective, the model takes several tokens as input to predict the next token; but from a training perspective, the true "model" is: taking several tokens and the next token as input to compute the loss. That is, both data and labels are actually inputs, and the true output is in fact the loss. For preceding layers, we can disregard labels and the loss, but the LM head, as the final layer "bordering" the loss, cannot avoid taking into account the effects of labels and the loss.

Therefore, the input to the LM head becomes and the index of the next token , and the output becomes the cross-entropy loss, namely

where is 's column . Since is a complicated nonlinear function of , its three metrics cannot be computed exactly; our goal is to seek as tight an upper bound as possible.

Forward Stability #

First is the relatively simple forward stability; by straightforward relaxation, we have

Therefore,

If we omit the constant , then it becomes a lower bound, so this bound is fairly tight in the asymptotic sense. To make it , the initialization variance of the LM head should be chosen as .

An Important Inequality #

As for the remaining two metrics, because they involve taking differences, computing them is somewhat more complex. We first prove an inequality that will be used:

The proof is not difficult, but requires a bit of technique: denote the right-hand side by , then by the monotonicity of , it readily follows that

This proves that

By symmetry, swapping and also holds, thereby proving the original inequality.

Dependency Stability #

Using inequality and the Cauchy-Schwarz inequality, we have

Therefore,

The result is cut from the same cloth as forward stability. The calculation here is similar to that for the embedding layer: because the label is a discrete ID, we do not need to consider its backpropagation, so the denominator only needs to consider the difference between .

Update Stability #

Finally, regarding update stability, we again apply inequality and the Cauchy-Schwarz inequality:

Therefore,

It is not hard to see that the three stability metrics of the LM Head are essentially identical to those of the Embedding layer: both are the maximum row/column norm of the parameter matrix or its increment. This means that the steepest descent for the LM Head is also Normalized SGD, with the difference being that the LM Head applies column-wise RMS Norm. In addition, all three metrics for the LM Head are multiplied by , so its initialization standard deviation and learning rate both scale as , whereas for the Embedding layer they scale as , which means they will differ slightly when transferring across widths.

Other modules #

Besides linear layers, the Embedding layer, and the LM Head, common Transformer models usually include several other parameters or layers that need to be analyzed separately. Let us review them one by one here.

Hadamard product #

As we know, after RMS Norm, there is usually a multiplication by a vector (Hadamard product), namely , to regulate the output scale. This parameter is not a matrix, so it is not suitable for the previously discussed Muon or Normalized SGD.

We could systematically compute the three stability metrics for based on the original definitions and then analyze its initialization and steepest descent, but there is also a cleverer shortcut: notice that , that is, and multiplied via Hadamard product equals matrix-multiplied with the diagonal matrix , which turns it into a special linear layer, namely , allowing us to reuse the conclusions for linear layers.

According to the previous article, 's initial spectral norm should be . Here, is a square matrix, so it is precisely , and since is also a diagonal matrix, we can simply let be initialized to the identity matrix to satisfy this requirement, which corresponds to initializing to all ones.

As for the optimizer, let the gradient of be ; then the gradient of is . Since we know the steepest descent for a linear layer is Muon, namely , and for a diagonal matrix we have , so the steepest descent for the parameter is SignSGD.

Linear Bias Term #

Traditional linear layers usually also have a bias vector , meaning that the complete linear operation is , though in recent years open-source models have basically eliminated bias terms, giving them little presence nowadays. But for completeness, we will still include a discussion of them here.

After adding the bias vector, the three stability metrics are

Among them, dependency stability is identical to the case without bias, so we only need to look at forward stability and update stability. For simplicity, we use the inequality , and assuming retains its original initialization, the part already achieves , so we only need ; for simplicity, in practice one typically zero-initializes .

Similarly, , if we consider setting , then the parameter will perform steepest descent with as the stability metric, and the result is also Normalized SGD.

Attention Scaling #

Using the forward stability metric, we can also re-derive the scaling factor of the Attention mechanism. Let . If are treated as linear layers, we can consider that we have already achieved and , and then according to the Cauchy-Schwarz inequality,

Here, is the dimension of , namely Head Dim. Clearly, the above expression is ; to make it , we must multiply by a scaling factor on the order of , which differs from the previous (refer to "A Brief Discussion on Transformer Initialization, Parameterization, and Normalization").

Which one is actually correct? In fact, both are. is the average result under random initialization, whereas is a limiting value applicable across the entire training process. Nor does it require us to directly change the scaling factor to , but rather suggests that being inversely proportional to may yield better transferability, and the two are compatible. For example, suppose that at , using as the scaling factor works well; then, when transferring to , one might consider changing the scaling factor to rather than .

In fact, constrained by Flash Attention, the design space for Head Dim is quite limited: it is typically 128 and generally at most 256. Therefore, in practice there is almost no issue of transferring parameters across Head Dim, so this result is mostly purely theoretical.

Summary #

Finally, the main results of these two posts are summarized as follows:

Among them, the steepest descent directions for the Embedding and LM Head are row-wise and column-wise Normalized SGD, respectively, which is consistent with works such as Scion; as for the transfer rules for variance and learning rates, they agree with the conclusions of MuP. In these two posts, however, all of them are derived based on the "three stability metrics" we proposed, indicating that we have indeed found a unified form of stability measurement for arbitrary layers.