Welcome to the next lesson in our journey through the mechanics of large-scale pre-training. In our previous discussion, we delved into the Adam optimizer, understanding how its adaptive, per-parameter learning rates are essential for navigating the heterogeneous architecture of Transformers. However, we left a crucial question unanswered: how do we manage the global learning rate, , over the course of a massive training run? Simply picking a single value and holding it constant is rarely the optimal strategy.
This lesson addresses that question by exploring learning rate scheduling. Our objective is to describe the most common strategies used in training large language models—namely, linear warmup and cosine decay—and to understand their critical role in ensuring stable and efficient training. We will move beyond simple heuristics and examine the underlying mathematical and empirical reasons why this dynamic approach is so effective.
To begin, consider the following plot, which illustrates a typical learning rate schedule used in training modern neural networks. This is the shape we will be deconstructing today.

The Stability Dilemma
Before we dissect the schedule, we must first understand the problem it solves. The choice of learning rate presents a classic dilemma:
- A large learning rate promises faster convergence, but if it's too large, especially at the beginning of training, it can cause the optimization process to become unstable and diverge. The loss can explode as the optimizer overshoots minima in the loss landscape.
- A small learning rate is safer and less likely to diverge, but it can lead to painfully slow convergence or cause the model to get trapped in suboptimal local minima.
This dilemma is particularly acute at the very start of training. A randomly initialized network is, by definition, in a chaotic state. The initial gradients can be extremely large and uninformative. Taking a large step based on these early gradients can permanently destabilize the training process. For Transformers, this problem is known to be exacerbated by the architecture itself.
The following video provides a concise explanation of why the original Transformer architecture, in particular, is sensitive to the learning rate at the start of training.
PostLN, PreLN and ResiDual Transformers
The video "PostLN, PreLN and ResiDual Transformers" from Machine Learning Studio explains the initial motivation for using a warmup phase.
Watch the segments from the introduction to the end of the recap, and then the core explanation from "why do we need a warm-up stage". The key insight is that large initial learning rates can cause instability due to large gradients, particularly in the final layers of the network.
From a more formal perspective, this instability is related to the curvature of the loss landscape, which is mathematically described by the Hessian matrix (the matrix of second-order partial derivatives). The maximum stable learning rate for an optimizer like SGD is inversely proportional to the "sharpness" of the loss function, which is the largest eigenvalue of the Hessian, . Crudely, . At the beginning of training, this sharpness can be very high, necessitating a small learning rate.
Phase 1: Linear Warmup
The solution to this initial instability is to not start with the target learning rate, but to build up to it gradually. This is the warmup phase.
Linear warmup is the most common approach. Here, the learning rate is increased linearly from a very small value (often zero) to its target maximum value, , over a specified number of training steps, . The formula for the learning rate at step is:
Typically, is set to 0.
So, why does this work? There are two complementary, deep-seated reasons.
-
Stabilizing Adam's Estimates: As we saw in the last lesson, Adam relies on estimates of the first and second moments of the gradient ( and ). At the very beginning of training, these estimates are based on very few data points and are initialized at zero, making them noisy and biased. A small learning rate during the warmup phase gives Adam's moment estimates time to accumulate more information and become more stable before the optimizer starts taking large steps.
-
Navigating the Loss Landscape: As a recent research paper explains, the primary benefit of warmup is that it allows the network to "self-stabilize" and find a region of the loss landscape that can tolerate a much higher learning rate.
Why Warmup the Learning Rate? Underlying Mechanisms ...
This paper from June 2024 provides a rigorous, Hessian-based analysis of why warmup is so effective. Given your background, this will provide the theoretical depth you're looking for.
First, read the section "Overview of Training Instabilities". This introduces the core concept of the "self-stabilization mechanism," also known as a "catapult," where exceeding the instability threshold leads to a loss spike that, in turn, reduces sharpness and restores stability. Next, read the beginning of Section 4, specifically the subsection on Stochastic Gradient Descent. This explains how warmup makes the self-stabilization process gradual and controlled. It guides the model toward flatter regions of the loss landscape that can handle the high target learning rate to come.
In essence, warmup gently guides the model out of the initial, potentially very sharp and unstable, region of the parameter space. By the end of the warmup period, the model is in a "flatter" region where it can safely handle the much larger target learning rate, enabling rapid convergence for the rest of training.
Phase 2: Cosine Decay
Once the learning rate reaches its peak after the warmup phase, we don't want to keep it there indefinitely. As training progresses and the model gets closer to a good solution, it's beneficial to decrease the learning rate to allow for finer-grained adjustments and to help the optimizer settle into a good minimum.
While a simple linear or exponential decay would work, one of the most effective and popular strategies is cosine decay, also known as cosine annealing. In this scheme, the learning rate is decreased following the shape of a cosine curve.
The intuition is that the cosine function's shape is ideal for this process: it starts with a very gentle slope (decaying slowly), allowing the model to continue exploring the landscape with a relatively high learning rate. Then, the decay accelerates before finally slowing down again as the learning rate approaches its minimum value. This final, slow phase with a very small learning rate acts like a fine-tuning stage.
The following article provides an excellent, detailed mathematical breakdown of a schedule that combines linear warmup with cosine decay.
Why Does Cosine Annealing With Warmup Stabilize Training?
This article by Hongnan Gao offers a clear, formal definition and mathematical intuition for the combined warmup and cosine annealing schedule.
First, read the section "Definition". This presents the full, two-part formula that governs the entire schedule. Pay close attention to the formula for the cosine annealing phase. Next, to truly understand how that formula works, read the section "Mathematical Intuition". It masterfully breaks down the cosine decay formula term by term, explaining how the scaling and shifting produce a curve that smoothly transitions from the maximum learning rate down to the desired final learning rate.
Let's quickly re-examine the core formula for the learning rate multiplier during the cosine decay phase, for a step :
Here:
- is the fraction of the decay period that has elapsed.
- is the desired final learning rate multiplier (e.g., 0.1, meaning the final LR will be 10% of the max LR).
As the reading explains, when (the start of decay), the term is 1, and the expression simplifies to . When (the end of training), the term is -1, and the expression simplifies to . The cosine function ensures a smooth transition between these two points. The actual learning rate is then .
Conclusion
In this lesson, we've deconstructed the learning rate schedule, a critical component for stable and efficient LLM training. We've moved beyond simple heuristics to understand the deep reasons behind its characteristic "ramp up, decay down" shape.
Here are the key takeaways:
- The Stability Problem: A static learning rate is suboptimal. Starting with a high learning rate causes instability and divergence due to the high "sharpness" of the initial loss landscape. Starting with a low one leads to slow training.
- Linear Warmup: This phase gradually increases the learning rate, which serves two purposes: it allows Adam's internal moment estimates to stabilize, and it gently guides the model into flatter regions of the loss landscape that can tolerate a high learning rate.
- Cosine Decay: After the peak, this phase provides a principled and smooth decrease in the learning rate. Its shape is ideal for allowing continued exploration before gradually "fine-tuning" the model in a promising minimum.
- The Main Benefit: Ultimately, the entire purpose of a learning rate schedule is to allow the model to train successfully with a much higher peak learning rate () than would otherwise be possible. This high learning rate is the engine of fast convergence.
We now have the core algorithm (Adam) and a strategy for managing its most important hyperparameter (). However, training LLMs requires processing data in massive batches, often too large to fit into the memory of a single GPU. Our next lesson will tackle this challenge by exploring gradient accumulation, a clever technique that simulates large batch sizes without requiring more hardware memory.