skip to content
← Scientific Spaces English

Making Model Training More Scientific, Part 9: Classical Adaptive Gradient Algorithms

The first eight articles in this series have all centered around SGD and its learning rates. Starting from this article, we will officially enter the world of adaptive gradient algorithms. It can be said that all current adaptive gradient algorithms share a common origin, namely the classic 2011 work 《Adaptive Subgradient Methods for Online Learning and Stochastic Optimization》—that is, the famous AdaGrad paper.

This paper generalizes the classical convergence results of SGD to a general preconditioner matrix form, and then deduces that the optimal preconditioner matrix is precisely the second moment of the gradient (to the power), and then takes a diagonal approximation to obtain AdaGrad. Although AdaGrad itself is not particularly popular, subsequent works it inspired, such as RMSProp and Adam, are undisputed mainstream optimizers. Not only that, subsequent optimizers like Shampoo and KL-Shampoo can still be considered its legacy.

In this article, let us revisit this classic work together.

Analysis of Difficulties #

In fact, in previous articles, we also briefly discussed the idea of adaptive learning rates, such as in Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients, but that was still tuning a scalar learning rate within the SGD framework. This time, we consider a general update rule

where is a positive-definite symmetric matrix, and is usually also called a "preconditioner". We can view it as a matrix version of the learning rate. Obviously, when , it reduces to SGD.

Why extend to a matrix learning rate? From the perspective of input and output alone, we want to input a gradient vector and output an update vector. The most general linear transformation between vectors is matrix multiplication, so a matrix learning rate is the ultimate generalization. As for the restriction of positive definiteness, it is to ensure that holds for any , so that is still a direction that decreases the loss.

In this section, let us first briefly analyze what difficulties arise for a general if we directly apply the proof procedure of SGD. The starting point of all previous proofs is the following identity:

Then we manage to isolate to one side, and then connect it to the loss value via the convexity assumption:

However, when considering the general update rule , if we still adopt the same identity, there will appear . Due to the extra , even if we assume convexity of the loss function, we cannot connect this term to the loss function anymore—the right-hand side of the convexity inequality can only be a clean ; with sandwiched in between, it cannot be applied.

Generalizing the Identity #

Therefore, we must simultaneously generalize this identity. The idea behind this generalization is to utilize the identity . Note that is an outer product of vectors, and the result is a matrix. This means we can first establish a matrix version of the identity at the outer product level, and then take on both sides at an appropriate moment to recover the scalar form. In the matrix version of the identity, can be moved out smoothly.

Specifically, we have (for simplicity, we will later denote as ):

Multiplying both sides on the right by , and rearranging gives

Taking on both sides and then repeatedly using , we get

This is our desired identity, where , which we call the "Mahalanobis norm"; the Euclidean norm is just , which we abbreviate as . Now the left-hand side recovers , allowing us to connect it with the convexity inequality , at the cost of replacing the distance metric on the right-hand side from the Euclidean norm with a time-varying Mahalanobis norm.

Classical Bounding #

The subsequent steps are largely identical to Making Model Training More Scientific, Part 1: Convergence of the Average Loss in SGD and Making Model Training More Scientific, Part 2: Extending the Results to Unbounded Domains. On the left-hand side, we likewise use inequality to connect it with the loss, and then sum over to get

However, since in the first summation on the right-hand side, is not , the terms cannot cancel out. Here we need the classic trick from Making Model Training More Scientific, Part 1: Convergence of the Average Loss in SGD:

To continue bounding, we need to impose an assumption on : for any , is positive semidefinite, abbreviated as , which is equivalent to the previous non-increasing learning rate assumption. In addition, for any positive semidefinite matrix , it also holds that , so . This bound is actually very loose, but it is sufficient for qualitative conclusions.

Using the assumptions and inequalities above, and dropping the non-positive term , we have

where , which is a common upper bound for all . If in doubt about this step, we can simply, as in Making Model Training More Scientific, Part 1: Convergence of the Average Loss in SGD, assume that optimization takes place within a bounded domain; then all naturally have a common upper bound .

First Results Emerge #

Substituting the inequalities from the previous section back into Eq. , and taking to be the theoretical optimum , we get

For simplicity, consider first the case where is a constant; rearranging gives

This is the average loss convergence result for . Now, turning our thinking around: for a good optimizer, the right-hand side of the above inequality should be as small as possible. Therefore, minimizing the upper bound might help us find a better optimizer, which aligns with the idea in Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients. To this end, we first use the assumption to obtain , and thus

That is to say, when all take the same , a smaller upper bound can be achieved. Next, we rewrite the right-hand side of the above inequality as

where is the (unnormalized) second-moment matrix. It is not hard to see that is actually a redundant parameter, and the true independent variable is , which tells us that can be set to any arbitrary positive number. For simplicity, we choose , which makes , so minimizing the upper bound is equivalent to

Interestingly, this is essentially the optimization objective of PSGD!

Solving the Objective #

To solve the above objective, we once again use the cyclic property of the trace to rewrite the two terms as

Then, using the AM-GM inequality, we obtain

Next, using the Cauchy-Schwarz inequality, we get

The equality condition for the Cauchy-Schwarz inequality is that there exists , such that , that is, , and the condition for equality in the AM-GM inequality is , which upon substitution further determines that , so the optimal solution is

This is the AdaGrad paper's most classic result, and it can truly be considered the "ancestor" of adaptive learning rate optimizers based on second moments. From this, we can see that adjusting the learning rate based on second moments is not some off-the-cuff heuristic trick, but the natural product of the principle of "minimizing the convergence upper bound". When is not invertible, we can add a to it, which is an implementation detail and will not be elaborated on in the theoretical derivation.

Intuitively, is essentially performing a "whitening" operation on the gradient, making updates more isotropic, which shares the exact same philosophy as the Muon optimizer today.

Variants #

However, , while theoretically optimal, violates causality because it assumes that we know the gradients at all time steps right from the start. We should already be familiar with this episode; in Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients, we have already encountered this, and the solution is to truncate the sum to the current time step:

It is worth pointing out that the so-defined still satisfies , so up to , the convergence conclusion still holds. However, if we were to retain the full matrix , both the memory and computational costs would be extremely expensive, making it impractical. A simple solution is to consider a diagonal approximation, namely taking from only its diagonal part and then taking the square root:

This is what we know as the AdaGrad optimizer, where denotes the Hadamard product, and the division between two vectors is also element-wise in the Hadamard sense. Notice that the learning rates for each component in AdaGrad are monotonically decreasing, which is usually considered an unfavorable property in practical training (in the later stages of training, the model easily "gets stuck" and stops learning), so RMSProp replaces the sum with an exponential moving average (EMA):

Note that while switching to an EMA often yields better empirical results, it can no longer guarantee , marking the point where theory and practice "part ways". If we further add momentum, we arrive at the classic of classics—the Adam optimizer (for simplicity, bias correction is omitted here):

Before Muon, Adam was the most mainstream optimizer, bar none; even with Muon, Adam remains a crucial component of mainstream optimizers (for embeddings, LM heads, etc.). As for RMSProp, it is typically used in training generative models, especially GANs, because for such models, adding momentum tends to cause mode collapse.

In addition to these classical optimizers, newer optimizers like PSGD, Shampoo, KL-Shampoo, and AdaBK are really just another structured approximation of or for matrix multiplication parameters. In other words, to this day, the preconditioning matrix derived from AdaGrad, , remains one of the key guiding principles for optimizers.

Summary #

This post reviewed AdaGrad, the foundational work of adaptive gradient algorithms, and reproduced its complete derivation along the route of "convergence analysis → minimizing the upper bound → optimal preconditioning matrix". It is fair to say that AdaGrad's idea of "adjusting the learning rate based on gradient second moments" is virtually the common underlying principle behind all subsequent adaptive learning rate optimizers.