In Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients, we entered a new chapter on scheduling learning rates based on gradients. But as mentioned at the end of the previous post, when deriving the optimal learning rate for the final loss under dynamic gradients, we encountered difficulties in the proof. Specifically, the optimal learning rate sequence we "guessed" using the calculus of variations is very difficult to verify via bounding when substituted into the result; therefore, let alone being an optimal solution, we could not even determine whether this sequence was a feasible solution.
In this post, however, we will resolve this issue by obtaining a more precise result through an ingenious construction. Judging from the proof process, the result this time may have reached a level of precision that cannot be further improved. This breakthrough also comes from the paper 《Optimal Linear Decay Learning Rate Schedules and Further Refinements》.
First, let us revisit the earlier conclusion. At the end of the previous post, we obtained Making Model Training More Scientific, Part 4: A New Identity, a New Learning Rate's general version of the result:
We want to find a sequence that minimizes the right-hand side of the inequality above. Through continuous approximation and the calculus of variations, we "guessed" that the answer is
where . However, we cannot substitute it in to prove it—or rather, proving it would require introducing some extra assumptions. If we try to substitute it in, we find that the main problem is that in Eq. , the denominator on the right-hand side is (), which prevents us from ensuring that is bounded, making various bounds very difficult. If we could further improve the denominator on the right-hand side of the result to , then the proof would follow naturally.
This post accomplishes the final proof precisely by further improving the precision of , yet not by directly and explicitly improving it, but rather by constructing the optimal learning rate sequence from the top down through careful bounding, thereby implicitly achieving the effect of improved precision.
Specifically, our starting point is Making Model Training More Scientific, Part 4: A New Identity, a New Learning Rate's identity:
We let , where denotes the expectation over all . Substituting this into the above equation gives
From now on, we must keep firmly in mind the principle of "no bounding unless necessary" to achieve the highest possible precision. Now, we use convexity to perform the first bounding:
Note that this requires each to depend at most on , which can be satisfied in stochastic optimization; furthermore, the first equality in the second line requires , which is also clearly satisfied. Substituting into Eq. yields
In the post Making Model Training More Scientific, Part 4: A New Identity, a New Learning Rate, the next step was to bound 's and separately and then sum them up; bounding them separately amplified the error and created trouble for subsequent proofs.
Therefore, in this section, we combine them into a single formula through identity transformations before considering bounding, in order to achieve higher precision. First, we still assume that the learning rate is independent of the data , so the expectation can be placed outside:
The more complicated part is the second term. Using to swap the summation order yields
After adding , it happens that cancels out, and simplifying the remainder yields
As long as we denote the part indicated in the equation above as , then the right-hand side takes the standard form of (weighted) average loss convergence:
Some readers might feel that something is off: in the above inequality, is the gradient at rather than at ; can it really not be substituted into the previous conclusion? Regarding this, we explicitly noted in Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients that setting it to the gradient at the current point, , serves to establish the relationship between and the loss function via convexity, but here that relationship is not needed, so replacing it with is completely fine.
Now, substituting conclusion into equation , and performing a second relaxation, we obtain
Here we denote . That is to say, if we use the learning rate to execute SGD, its final loss satisfies the inequality above. Because the relaxation was carried out more cautiously, this upper bound is theoretically tighter than conclusion , but it is relatively implicit, as it requires us to first, from , solve for , before substituting into the right-hand side for verification; however, solving explicitly for is no trivial matter.
However, we can work in reverse: first derive the optimal , and then from obtain the optimal . The minimum value of the right-hand side above was already derived in our previous article Making Model Training More Scientific, Part 5: Fine-Tuning Learning Rates Based on Gradients, and the answer is:
Then the optimal is
This is precisely equation ! With this, we have completed the proof of optimality for equation .
As for this result itself, we already provided an initial interpretation in the previous article: the first term, , is inversely proportional to the squared gradient norm, which can explain the necessity of an early warmup, since gradients are usually larger in early stages; decays monotonically to zero, which explains the necessity of learning rate decay. In particular, if we assume that the gradient norm is constant, we obtain a linear decay learning rate, which is a commonly used learning rate schedule in practice.
The idea is actually quite simple: just pick an arbitrary learning rate schedule to train once, and then use the gradient information to compute the optimal learning rate , checking whether its curve aligns with the learning rate schedule we chose. If there is a severe deviation, we need to adjust the learning rate schedule and retrain, which is termed "Refinement" in the paper. This practice is well suited to scenarios where many preliminary exploratory runs precede the formal training.
The paper provides several examples of refined learning rates, most of which exhibit a "Warmup-Decay" profile. In particular, in most experiments, the gradient norm is nearly constant during the middle and late stages, so the optimal decay shape during these stages closely resembles linear decay:
Some examples of refined learning rates
Finally, the above results are for SGD, where , which in practice can only be approximated by , where is the L2 norm; for adaptive learning rate optimizers such as Adam, the paper suggests using , which is inversely proportional to the L1 norm. We will discuss adaptive learning rate optimizers in subsequent articles.
If we specify our own learning rate schedule , and want to see just how optimal it is, doing so currently seems quite troublesome, because Eq. is a semi-implicit result: to substitute it into the right-hand side for verification, one must solve the equation . It is not that this equation is particularly hard to solve, but rather that its solution is not concise, making it inconvenient to carry out proofs with the exact solution.
Here, through further relaxation, we convert it into an explicit result in terms of . The bounding trick is slightly subtle—I pondered it for a long time—but once written out, it is quite straightforward to understand:
Here, is understood as . Summing both sides over , we obtain
Substituting yields , and then replacing with yields , and then combining this with the definition of yields . Finally, slightly rewriting the right-hand side of Eq. and substituting these inequalities, we have
Here, we did not relax the last two terms because, according to the definition of , we must have , so is infinite at both and . This also tells us that actually has only free parameters, yet the corresponding "unknowns" number . The number of equations is smaller than the number of unknowns, which provides us with a degree of freedom that we can flexibly adjust.
Still by definition, we have . Due to the existence of this "flexibly adjustable degree of freedom", we can choose , which explicitly gives , whence
I have not found this result in any literature, so I tentatively consider it new; its precision is higher than that of . Of course, result is not actually applicable to learning rate sequences that end at 0, so in practice they are not easily compared directly. However, looking at the constant coefficients of the first two leading terms, that of is , whereas in the formula above it is , so on average the precision should be twice as high.
At the end of the previous post, we mentioned the difficulty of proving the optimal learning rate schedule for the terminal loss. In this post, through careful, top-down bounding and construction, we completed this proof and obtained a higher-precision result, while also discussing the inspiration this result provides for the "Warmup-Decay" mechanism of learning rates.
Figure 3 from Optimal Linear Decay Learning Rate Schedules and Further Refinements (2310.07831v2); matching English original retained. Source attribution.