Learning Rate Decay › Inverse Square Root Decay
Language AI HandbookAll chapters Learning Rate Decay › Inverse Square Root DecayOne section · Sections in this chapter5 / 15 ↓
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
Inverse square root decay, popularized by the original Transformer paper "Attention Is All You Need," has a distinctive profile: it decreases quickly at first and then levels off gradually. This behavior makes it well-matched to how optimization often proceeds: rapid early progress followed by slower refinement.
Mathematical Foundation
The schedule is named for its decay rate: the learning rate is proportional to the inverse of the square root of the step count. This means the rate falls rapidly at first (the difference between step 1 and step 4 is large) and then changes slowly at large step counts (the difference between step 10,000 and step 10,001 is tiny). On a log-log scale, the decay appears as a straight line with slope .
The schedule is:
where:
- : the peak learning rate reached after warmup
- : the number of warmup steps
- : the current step
This form describes the decay phase while capping the rate at for . In practice, it is usually paired with a separate linear warmup that increases the learning rate from zero to the peak. After warmup, the term equals , and the schedule follows a true inverse square root curve.
A common combined form that includes the linear warmup is the original Transformer formulation:
where:
- : the model hidden dimension (used as a scaling factor in the original Transformer)
- The first argument governs the decay phase
- The second argument governs the linear warmup phase
The minimum of the two quantities ensures a smooth transition: during warmup the linear term is smaller (it is small because is small), and after warmup the inverse square root term takes over (it is smaller because shrinks faster than the linear term grows). The crossover happens exactly at , where both terms equal .
Comparing Decay Rates Across Schedules
To understand why inverse square root is preferred over exponential for long training runs, it helps to compare how aggressively each schedule reduces the learning rate. With exponential decay at per step, after 100,000 steps the learning rate has fallen to , which is effectively zero. With inverse square root, after 100,000 steps from a warmup of 4,000 steps, the learning rate is times the peak, a reduction to 20% of peak. For pre-training runs that span hundreds of thousands of steps, this gentler decay means the model is still making meaningful learning rate-scaled gradient steps even late in training.
This is particularly important for large language model pre-training, where the model is learning from a dataset so large that many distinct learning signals appear throughout training. An exponential schedule would reduce the learning rate to near zero long before the dataset is exhausted, effectively stopping learning. The inverse square root schedule allows the model to continue learning from later portions of the data with a non-negligible step size.
Warmup: Why Start Small?
The warmup period addresses a specific training instability. At the very start of training, the model parameters are random, the gradient estimates are highly noisy, and the loss surface is poorly characterized. A large learning rate in this regime can cause the loss to explode or send the model into a region of parameter space that is very difficult to escape.
Linear warmup starts the learning rate near zero and increases it steadily over the first several thousand steps. By the time the learning rate reaches its peak value, the model has already made some initial progress, gradient estimates have stabilized, and the optimizer's momentum and variance estimates (in Adam) have had time to accumulate. The peak learning rate can then safely be much larger than if training had started at full speed.
The warmup is especially important for Adam. Adam estimates the first and second moments of the gradient using exponential moving averages. At step one, these estimates are initialized to zero and have not yet had time to reflect the true gradient distribution. Early updates with a large learning rate are based on these poorly calibrated estimates, which can cause wild oscillations. Warmup gives the moment estimates time to converge before the learning rate reaches its full value.
A warmup period is a phase at the beginning of training during which the learning rate is increased from a small value to the target rate. Linear warmup increases the rate by a fixed amount each step. Warmup prevents instability caused by noisy gradients and poorly calibrated optimizer statistics early in training.
The warmup length is typically set to 4,000 to 10,000 steps for transformer training, though the optimal value depends on batch size and model size. Larger models and larger batches generally benefit from longer warmup. With very large batch sizes (as in distributed training), the signal-to-noise ratio in gradient estimates is higher because more samples are averaged, but the learning rate is also larger due to linear scaling, so the need for warmup does not disappear.
Warmup Length and the Batch Size Relationship
An underappreciated aspect of warmup is how it interacts with batch size. When you double the batch size, the linear scaling rule (introduced by Goyal et al. in 2017 for ImageNet training with SGD) recommends doubling the learning rate to maintain the same relative update magnitude. But doubling the learning rate without extending warmup often causes instability. The convention in large-batch training is to also scale the warmup duration: if you multiply batch size by , multiply warmup steps by as well. This gives the optimizer time to accumulate reliable statistics before taking the larger steps that the scaled learning rate demands.
def transformer_schedule(t, d_model, warmup_steps):
t = max(t, 1)
return d_model ** (-0.5) * min(t ** (-0.5), t * warmup_steps ** (-1.5))
d_model = 512
warmup_steps = 4000
steps = np.arange(1, 40001)
transformer_lrs = np.array(
[transformer_schedule(t, d_model, warmup_steps) for t in steps]
)
peak_step = int(np.argmax(transformer_lrs))
peak_lr = float(transformer_lrs[peak_step])Peak learning rate: 0.000699 Peak reached at step: 4000 LR at step 10000: 0.000442 LR at step 40000: 0.000221
The peak learning rate is reached exactly at the warmup step, after which the schedule decays as . The learning rate at step 40,000 is roughly 32% of its peak value, showing how slowly the inverse square root falls compared to exponential decay.
