Why do transformer recipes use warmup followed by cosine or linear decay? How would you choose a learning rate for a new model?
Answer
Model answer, written in a candidate's voice
In short
- Warmup ramps LR up gradually so Adam’s noisy first/second-moment estimates and unnormalised activations settle before large steps are taken.
- Cosine or linear decay shrinks steps late in training, letting the model settle into the wide low-loss region found at high LR.
- Choose LR via a short LR range test, then scale it with batch size (roughly linear for SGD, closer to square root for Adam).
- Monitor loss spikes and instability; back off LR or extend warmup if they appear.
- Learned or adaptive schedules exist — e.g. MetaGradients, used in DeepMind’s published Google Maps ETA GNN work to adapt the LR for stability — rather than relying only on hand-tuned curves.
In full
The core reason is that early training is fragile: Adam’s moment estimates are noisy and activations are not yet well-behaved, so a short warmup ramps the LR up gradually and prevents large, destabilising steps. As training progresses, decaying the LR — cosine or linear — reduces step size and gradient noise so the model can settle into the wide, low-loss region it found while the LR was high, rather than bouncing around it. For a new model I would run a short LR range test, sweeping LRs and plotting the loss, then pick a value in the stable region before the loss starts rising, and rescale it whenever the batch size changes — roughly linearly for SGD and closer to square-root scaling for Adam, with diminishing returns at very large batches. I would also monitor loss spikes during the run and back off the LR or extend warmup if instability appears. Hand-tuned schedules are not the only option: learned or adaptive schedules exist, such as MetaGradients, which DeepMind’s published work on graph-network ETA prediction for Google Maps used to adapt the learning rate during training and make it more stable.
What a strong answer covers
- Warmup stabilises early updates when Adam statistics are noisy and activations are unnormalised.
- Decay helps convergence into flatter regions.
- LR range test; scale the LR with batch size; monitor loss spikes.
- Learned or adaptive schedules exist (for example, meta-gradient methods that adapt the learning rate online for training stability).
Common mistakes
- changing batch size without adjusting the LR
- treating loss divergence as a data bug before checking the LR.