TL;DR
Learning rate warmup means starting training with a small learning rate and raising it step by step over the first part of training, before the normal schedule takes over. It solves a specific problem: Adam and similar optimizers scale each step using averages of past gradients, and in the first few steps those averages rest on almost no data. Large early steps built on that thin evidence can push the model into a poor region that training then struggles to leave.
Builds on: Adam, Learning Rate · Leads to: RAdam, learning-rate schedules
Where it's used
Training Transformers for translation and language modelling. The original Transformer paper by Vaswani and colleagues used a linear warmup over the first 4,000 updates, followed by a decay in proportion to the inverse square root of the step number. The RAdam paper reports a concrete case: training a Transformer on the IWSLT'14 German-to-English translation task without warmup raised the training loss from about 3 to around 10.
Training image classifiers with very large batches. A very large batch gives a less noisy gradient, so a large step can look safe, but the first steps can still move the weights a long way from their random starting point in a convolutional network. The RAdam paper says warmup was originally proposed for very large batches, citing the large-minibatch work of Goyal and colleagues in 2017.
Fine-tuning a pretrained model. Pretrained weights already encode useful structure. A short warmup keeps the first updates small, so the new data is less likely to overwrite that structure in a few bad steps. This is one reason fine-tuning often uses a smaller rate than training from scratch. The argument is practical; the RAdam paper does not test this case.
How it works
Use one weight and a loss whose gradient we can compute by hand. We will track only the first four steps, with a target learning rate of and warmup length 4.
- Set the schedule. Warmup length is steps. For step , the rate is . Check: step 1 uses , and step 4 uses .
- Run step 1 with gradient . Adam keeps two averages: , the average of gradients, and , the average of squared gradients. After one gradient both averages are built from that single number, so the bias-corrected estimates are and . The normalized direction is . Check: the step is .
- Run step 2 with gradient again. The averages now rest on two equal numbers, so the normalized direction is still 1. The step is . Check: the weight moved by 0.05, which is twice the first move because the rate doubled.
- Run step 3 with gradient . The normalized direction is still 1, and the step is .
- Run step 4 with gradient . The step is , the full target rate. Check: total movement after four steps is .
- Now see what the warmup protects against. Suppose instead the first gradient were and the second were , a sudden spike. Adam's averages now hold very little evidence about the scale of gradients, so the step on that spike is hard to predict from the past. Without warmup, the rate on step 2 would be the full . With warmup, it is only , so the same spike moves the weight half as far.
flowchart LR A[Few gradients seen] --> B[Averages m and v are noisy] B --> C[Adaptive step can be erratic] C --> D[Warmup keeps the rate small] D --> E[Averages settle, rate rises]
- linear warmup, 4 steps
- constant rate
The math
Definition
Let be the target learning rate and the warmup length in steps. The scheduled rate at step is
The rate rises linearly from near zero to over the first steps, then stays at (or follows whatever schedule comes next).
Step 2 in symbols: what Adam computes
Adam keeps two exponential moving averages, with decay rates and , the defaults given in the Adam paper. The first average is of the gradient , and the second is of its square:
Both start at zero, so they are biased toward zero early. Correct the bias by dividing by :
The update then uses the warmed-up rate:
Here is a tiny constant that prevents division by zero.
Step 2 in symbols: the first step is always the rate
After one gradient, , so . Similarly , so . Ignoring , the normalized direction is . The first step therefore has size exactly , whatever the gradient's magnitude. This is why the walkthrough used and got a normalized direction of 1, and it is why the first steps depend so heavily on the rate.
Step 3 in symbols: few samples, unreliable scale
Adam's normalized direction is roughly . When is built from only a few gradients, it is a noisy estimate of the true gradient scale. The RAdam paper argues that this estimate has large variance early in training, and that warmup works by reducing that variance: it keeps the rate small until the averages contain enough samples to be trusted. The argument concerns the adaptive term, so it applies to Adam and related methods such as RMSProp, and not to plain SGD, which has no such term.
Step 4 in symbols: the total movement
With the linear schedule and a constant normalized direction of 1 for the first steps, the weight moves
For and this gives , which matches the total in step 5 of the walkthrough. Holding the full rate for the same four steps (with the same unit direction) would move the weight . In general, with the direction held at 1, the ratio is , which falls toward one half as warmup gets longer.
Worked examples
Take one weight, a gradient , and the target rate .
- Without warmup, the rate at step 1 is .
- The first step size is , because Adam's normalized direction is 1.
- With linear warmup over , the rate at step 1 is .
- The first step size is now .
Answer: warmup cut the first move from to , a factor of four.
Keep and . Every gradient is , so the normalized direction is 1 at every step.
- Step 1 uses .
- Step 2 uses .
- Step 3 uses .
- Step 4 uses .
- The weight moves a total of .
- Check with the formula . The two agree.
- From step 5 on, the rate stays at 0.1 and the weight moves 0.1 per step.
Answer: after four steps the weight has moved 0.25 and the rate has reached its target. A run that held 0.1 from the start would have moved 0.4 in the same four steps.
Suppose a team trains a small Transformer for translation with Adam and a target rate of . In the first run they skip warmup.
- Suppose that within the first few dozen steps, the loss falls for a while, then jumps and does not recover. The model settles in a poor state.
- In the second run they add a linear warmup over the first 1,000 steps, so the rate on step is .
- On step 10 the rate is , which is a hundredth of the target. Early steps are now tiny, while Adam's averages collect data.
- By step 1,000 the rate reaches , and the loss keeps falling without the jump.
Try it: with the linear schedule above, what is the rate on step 250, and what fraction of the target is it? Answer: , which is one quarter of the target.
Common mistakes and tradeoffs
Mistake: "Warmup is only needed for huge models." It is tempting to think warmup matters only at extreme scale. In fact the cause is the adaptive averages, which are unreliable at the start of any run. The RAdam paper's clearest demonstration is a translation Transformer, and it notes similar phenomena in BERT pre-training, so the problem is not specific to one kind of model.
Mistake: "Warmup can be any length, so pick a short one." It is tempting to use a few steps and move on. In fact warmup length matters. In a CIFAR10 test in the RAdam paper, using a ResNet-20 classifier, Adam with 100 steps of warmup at a rate of 0.1 reached only 90.13 percent test accuracy, while RAdam reached 91.06 at the same rate. The authors also note that for some warmup lengths Adam with warmup is more sensitive to the choice of learning rate.
Mistake: "Warmup replaces the learning rate decay." It is tempting to think a warmup handles the whole schedule. In fact warmup handles only the start. Many recipes pair it with a later decay, such as cosine annealing, which lowers the rate as training converges.
Tradeoffs. Warmup adds a hyperparameter, the warmup length, and that length has to be chosen for each setup. Too short and the early instability returns; too long and training wastes steps at a rate that is too low. Methods such as RAdam remove the need for a hand-set length by rectifying the adaptive term directly, at the cost of a more involved optimizer. RAdam itself falls back to SGD with momentum for its first few updates, while its variance is still divergent. Plain SGD has no adaptive averages, so the variance argument does not apply to it; warmup is still used there, mainly for very large batches, the setting it was first proposed for.
History
Warmup was first proposed for training with very large batches. The RAdam paper says it was originally proposed for SGD in that setting, citing Goyal and colleagues in 2017.
The Transformer paper by Vaswani and colleagues in 2017 used a linear warm-up followed by decay. The RAdam paper notes that the state of the art in neural machine translation at the time used Adam with linear warmup.
Only in 2019 did the RAdam paper give a theoretical account. Its authors argued that the adaptive term has large variance early in training, and that warmup works by reducing that variance. The paper also proposed RAdam, an Adam variant that rectifies the variance directly.
Recap
- Adam scales each step by averages of past gradients. The averages are unreliable in the first few steps.
- The first Adam step has size equal to the learning rate, whatever the gradient, so the rate at the start matters most.
- Linear warmup raises the rate from near zero to the target over steps: .
- The RAdam paper argues that warmup works by reducing the variance of the adaptive term early on, which is why it stabilizes training.
- Read next: RAdam, which removes the need for a hand-set warmup, and cosine annealing, which handles the decay after warmup.
Check yourself
QuestionAdam has on step 1 and the first gradient is . What is the size of the first step, ignoring ?Show answer
Answer: 0.2. After one gradient, and , so the normalized direction is , with magnitude 1. The step size is , whatever the gradient's magnitude.
QuestionA linear warmup has and . What is the rate on step 3?Show answer
Answer: 0.06. The formula is .
QuestionWhy does warmup help Adam more than it helps plain SGD, in terms of what the optimizer knows at the start?Show answer
Answer: Adam keeps running averages of the gradient and its square, and those averages are built from very few gradients in the first steps. Their scale is an unreliable estimate, so the normalized step can be erratic. Warmup keeps the rate small until the averages contain enough data. Plain SGD does not normalize by a running estimate of gradient size, so it does not have this early-stage unreliability in the same way.
QuestionYou train a model with a rate that warms up over 2,000 steps, then decays. A colleague says the warmup length does not matter as long as there is some warmup. Is that right?Show answer
Answer: No. The length affects the outcome. Too short a warmup leaves the early instability in place, and too long a warmup spends many steps at a low rate. The RAdam paper reports that Adam with a 100-step warmup at a rate of 0.1 reached only 90.13 percent on CIFAR10, and that for some warmup lengths Adam with warmup is more sensitive to the learning rate, so the choice is a real tuning decision.
QuestionIn one sentence, what does the warmup schedule do after step ?Show answer
Answer: It holds the rate at the target , because is at least 1 and the minimum is 1. Any later decay is a separate schedule applied on top.