Stochastic Gradient Descent › Learning Rate Schedules
Language AI HandbookAll chapters Stochastic Gradient Descent › Learning Rate SchedulesOne section · Sections in this chapter7 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Training with a constant learning rate has a fundamental tension. Early in training, you want a large learning rate to explore parameter space and make rapid progress. Late in training, you want a small learning rate to converge precisely to a minimum without oscillating around it. A learning rate schedule resolves this tension by changing over the course of training.
This section covers the most important schedules. All of them modify the base learning rate over training steps or epochs.
Step Decay
Step decay reduces the learning rate by a fixed factor every epochs. If is the decay factor (typically 0.1 or 0.5) and is the current epoch:
where:
- : the learning rate at epoch
- : the initial learning rate
- : the decay factor per drop, a value in (typically 0.1 or 0.5)
- : the number of epochs between drops
- : the number of drops so far (the floor of )
Step decay is simple and predictable. The loss usually decreases smoothly between drops and then jumps to a lower value immediately after each drop, as the optimizer can now make more precise adjustments in the current neighborhood.
The main drawback of step decay is that the sharp transitions can be undesirable. Hyperparameter tuning requires choosing both and , and the performance can be sensitive to these choices.
Exponential Decay
Instead of discrete drops, exponential decay reduces the learning rate continuously at every step:
where:
- : the current training step
- : the decay rate, controlling how quickly the learning rate shrinks
- : the continuous decay factor, which approaches zero as increases
Exponential decay produces a smooth learning rate curve. However, if is too large, the learning rate decays too quickly and training stalls before convergence.
Cosine Annealing
Cosine annealing, introduced by Loshchilov and Hutter (2017) in their "SGDR" paper, is one of the most popular learning rate schedules for modern NLP. It smoothly decreases the learning rate from to following a cosine curve:
where:
- : the learning rate at step
- : the minimum learning rate (often 0 or a very small value like 1e-6)
- : the maximum learning rate (the "base" learning rate)
- : the total number of training steps
- : the cosine term, which starts at 1 (giving ) and ends at (giving ) over the interval
At , the cosine term is 1, so . At , the cosine term is , so .
Cosine annealing has several attractive properties: it starts large, decays slowly at first, then accelerates, and finally decays slowly again near the end. This matches intuitions about optimization: you want large steps early on, more cautious steps in the middle, and very fine-tuning at the end.
The "SGDR" variant adds warm restarts: at the end of a cosine cycle, the learning rate jumps back to and the cycle repeats, often with a longer period. This allows the optimizer to escape any local minimum it has settled into and explore other regions of parameter space.
Learning Rate Warmup
For large language models and transformers, training often begins with a warmup phase where the learning rate is linearly increased from 0 (or a tiny value) to the target learning rate over a number of steps :
where:
- : the number of warmup steps (typically a few hundred to a few thousand)
- : the target learning rate after warmup completes
- : the linear ramp factor, going from 0 to 1
After warmup, the learning rate typically follows a decay schedule (cosine annealing is most common).
Why is warmup necessary? Early in training, the parameters are far from their optimal values. Gradients can be very large in magnitude, and starting with a large learning rate can cause catastrophic parameter updates that destabilize the entire network. By starting small and ramping up, warmup gives the network time to initialize into a reasonable part of parameter space before taking large steps.
In the original transformer (Vaswani et al., 2017), the following combined warmup-decay schedule was used:
where:
- : the model dimension (e.g., 512 in the original transformer), which scales the overall learning rate to be smaller for larger models
- : the decay term active after warmup (polynomial decay)
- : the warmup term active during the warmup phase
- The selects the warmup term early in training and the decay term after
This formula automatically transitions from warmup to decay without requiring separate configuration of the phase boundary.
For most modern transformer training, the practical recommendation is: linear warmup for 1-5% of total training steps, followed by cosine annealing to .