Learning Rate Schedules
Warmup, cosine annealing, cyclic LR, and why the schedule shape changes what you find.
You are training a ResNet from scratch. You pick a learning rate and run 90 epochs. If you picked too high — say $α = 0.1$ when $0.01$ is appropriate — loss oscillates from epoch 1 and the model never converges. If you picked too low — $α = 0.0001$ — loss decreases smoothly but stops at 72% accuracy when the same architecture should reach 76%. Congratulations, you found a mediocre minimum and permanently settled there. No single fixed learning rate gives you both the early progress you need and the fine-grained convergence required to reach the best basin. This is not a tuning problem. It is a structural mismatch between one constant value and a landscape that requires different step sizes at different phases of training.
The solution is to make the learning rate change over time. But how? The crudest version is step decay: drop $α$ by a factor of 10 at epoch 30 and epoch 60. This is the classic ResNet schedule and it works. The problem is the suddenness. Wherever the optimizer happens to be at epoch 30, that basin is now where it will stay — a sharp drop removes the energy needed to escape. If the optimizer landed in a slightly sharp basin at epoch 29, it is now trapped there.
Before we even get to decay strategies, there is a problem at the very start. Early in training, gradient directions are unreliable: weights are far from any useful configuration, batch statistics are noisy, and Adam's second moment estimate $v_t$ has not stabilized from zero. Applying the full learning rate at step 1 means taking large steps in arbitrary directions. Warmup — linearly ramping $α$ from near-zero to the target value over the first 1%–5% of training steps — gives gradient estimates time to accumulate before large steps are applied. For transformers, skipping warmup causes early embedding corruption that is nearly impossible to recover from.
NOT this. Most people think warmup is an Adam-specific trick to work around bias correction. Actually, warmup solves a different problem: gradient direction reliability. Even with perfect bias correction, the gradient direction at step 1 is computed on one mini-batch of a randomly-initialized model — it is essentially noise. Warmup says "do not trust this yet, take small steps until the signal stabilizes." Bias correction fixes the magnitude of early moments; warmup is about not acting aggressively on unreliable directions.
After the stable phase, cosine annealing replaces step decay's abrupt drop with a smooth curve: $α(t) = α_{min} + 0.5(α_{max} - α_{min})(1 + cos(πt/T))$. The gradual decrease means the optimizer keeps exploring broadly early and narrows its search gradually rather than stopping abruptly. Empirically, cosine annealing finds flatter basins than step decay, delivering 0.5%–2% better test accuracy on standard benchmarks. The mechanism: in the high-$α$ phase, the optimizer can still occasionally escape mediocre basins. As $α$ decreases continuously, exploration narrows and the optimizer settles into the flattest basin it has found.
OneCycleLR (Smith, 2018) goes further: ramp $α$ up from $α_{min}$ to a peak 5–10x higher than a typical constant rate over 30% of steps, then cosine decay down over the remaining 70%. The high-$α$ peak phase is aggressive exploration. The long decay phase is fine-grained convergence. This "super-convergence" has achieved matching accuracy in 10–20x fewer epochs on some tasks. The canonical transformer schedule — linear warmup, cosine decay to near zero — is structurally identical: aggressive early phase, extended fine-grained final phase.
Key points
- Use linear warmup for 1%–5% of total steps, then cosine decay to near zero — this is the production-proven schedule for most deep learning. For ResNets: warmup over 5 epochs, then cosine decay. For transformers: warmup over 4% of training tokens, then cosine or linear decay. Peak learning rate: $1e$-$4$ to $3e$-$4$ for transformers, $0.1$ for ResNet+SGD. Getting the warmup length wrong by 2x costs less than getting it completely absent — absent warmup on transformers causes divergence in the first few hundred steps with near-certainty.
- The most common production trap: using a fixed learning rate because "it converged." A model that "converged" on a fixed LR has actually found a basin and stopped exploring. It may have found a mediocre basin early and gotten stuck. Symptom: training loss stabilizes but is 5%–10% above published benchmarks for your architecture. Fix: add cosine decay — if loss continues improving after adding the schedule, you were prematurely converged. If loss does not improve further, you have actually found a good basin and the schedule is just confirming it. The schedule costs nothing to add.
- Diagnostic: loss that decreases fast, then plateaus 20+ epochs before the end = the schedule dropped $α$ too early or too sharply. With step decay: plateau after a step drop means the jump was too large — the optimizer lost the ability to escape the current basin but is not yet in a flat enough one to stay. Fix: use a smaller step factor (0.5 instead of 0.1) or switch to cosine annealing. With cosine: plateau in the middle of the schedule means the peak $α$ was too low — the early phase did not explore broadly enough. Fix: increase peak $α$ by 3x and rerun. Log $α$ alongside loss at each step to see exactly when plateaus align with schedule changes.
Learning rate schedules change which regions of the loss landscape are accessible: warmup prevents corrupt early steps, cosine annealing prevents premature basin-locking, and OneCycleLR combines aggressive exploration with fine-grained convergence — together they are worth 5%–10% accuracy over a naive fixed rate.
Recap
- No single fixed LR is best across a whole run: too high and the loss oscillates from epoch 1; too low and the optimizer locks into a mediocre minimum. You want big steps early to cover ground, small steps late to settle — hence a *schedule*.
- Warmup ramps α from near-zero over the first ~1–5% of steps: early gradients are unreliable in *direction*, not just biased in magnitude, so a big early step on a fresh unstable model can blow it up.
- Warmup fixes direction reliability, not just Adam's bias: even with perfect bias correction the step-1 gradient is essentially noise, so warmup is still needed — the two are separate problems.
- Step decay locks the basin abruptly: dropping the rate 10× at a milestone freezes the optimizer wherever it happens to be at that moment — cosine decay anneals smoothly to near zero instead, avoiding a premature lock-in.
- Cosine annealing tends to find flatter basins than step decay, worth roughly 0.5–2% test accuracy on benchmarks — the smooth glide-down lets the optimizer keep settling rather than snapping into place.
- OneCycleLR: ramp up to a 5–10× peak over the first ~30% of steps, then cosine-decay the rest — aggressive exploration up front, fine convergence at the end.
- Canonical Transformer schedule = linear warmup + cosine decay to near zero, worth 5–10% accuracy over a naive fixed rate; it also pairs with early stopping so training both moves fast and lands cleanly.
Check your understanding
Q1. A transformer language model diverges in the first 100 training steps when trained with Adam and α=1e-4, β2=0.999. No warmup is used. What is the likely cause and fix?
- `A) The divergence is caused by the learning rate α=1e-4 being too large for a transformer. Transformers require a much smaller initial learning rate — closer to 1e-6 — because attention weight matrices are unusually sensitive to parameter perturbations early on, and pushing α above roughly 5e-6 reliably overflows the softmax logits. Fix: drop α by 2 orders of magnitude and train without warmup.`
- `B) The divergence is caused by β2=0.999 being too high for the first 100 steps. With β2=0.999, the second moment accumulates slowly and stays near zero early on, so the effective learning rate α/√(near-zero) balloons well above the intended 1e-4 — in practice by roughly 30x at step 1. Fix: use β2=0.9 for the first 100 steps, then switch to 0.999 once the second moment has stabilized.`
- `C) Without warmup, Adam's bias correction makes the very first steps close to α·sign(gradient) — a fixed magnitude of α applied to every parameter regardless of gradient size. Gradient magnitudes vary by orders of magnitude across layers early on (embedding layers especially), so this uniform step is poorly calibrated. Fix: warmup over 2000-4000 steps, ramping α from near-zero to 1e-4.`
- `D) The divergence occurs because Adam's bias correction makes early steps too large. At step t=1 with β1=0.9, the bias correction factor 1/(1−β1^1) = 10 amplifies the first moment 10x, and the denominator's own correction compounds this to roughly 100x the intended step, hurling weights to extreme values within a few tokens. Fix: disable bias correction entirely for the first 100 steps.`
Q2. Why does cosine annealing consistently outperform step decay in practice, even though both eventually reduce the learning rate to the same final value?
- `A) Step decay drops the learning rate suddenly at fixed milestones, which "freezes" the optimizer in whatever basin it occupies — not enough lr left to escape a sharp basin. Cosine decreases lr continuously instead: broad exploration early, narrowing gradually, settling into a flat region rather than locking in prematurely. Empirically worth roughly 0.5-2% test accuracy over step decay.`
- `B) Cosine annealing outperforms step decay because it requires fewer hyperparameters. Step decay requires specifying both the decay factor and the milestone epochs, which are sensitive to the specific dataset and architecture. Cosine annealing only requires the total number of training steps, which is always known in advance. The performance advantage comes from avoiding the human error of choosing wrong milestones, not from any inherent mathematical property of the cosine curve.`
- `C) Cosine annealing and step decay perform equivalently in terms of final test accuracy. Cosine annealing appears to win in benchmarks because it is typically compared to step decay with non-optimal milestone placement. When step decay milestones are tuned precisely to the dataset — for example, using a held-out validation set to find the optimal decay point — it matches or exceeds cosine annealing performance.`
- `D) Cosine annealing outperforms step decay because it is compatible with Adam's momentum terms, while step decay is designed only for SGD. Adam accumulates momentum in m and v that must be gradually reset as the learning rate changes; the sudden drop in step decay disrupts this momentum accumulation. Cosine annealing's gradual decay allows Adam's moments to adjust proportionally, maintaining the correct effective step size throughout training.`
Q3. Two models train with OneCycleLR: Model A uses a peak lr of 0.1, Model B uses a peak lr of 0.01 (standard for that architecture). Both train for the same number of steps. Which two of the following statements are true?
- `A) Model A's higher peak lr drives more aggressive exploration of the loss landscape and can escape sharper minima — but risks instability (NaNs, oscillating loss) if 0.1 is too high for the architecture, which is common for transformers.`
- `B) Model A and Model B always reach identical final test accuracy, because OneCycleLR normalizes the total area under the lr curve so the peak value chosen makes no difference to the outcome.`
- `C) Model B's conservative peak lr gives a smoother, more reliable training curve, but is more likely to settle into a nearby sharper minimum with worse generalization than Model A would find if it stays stable.`
- `D) Peak lr only changes how fast warmup ramps up — OneCycleLR's built-in gradient clipping guarantees stability at any peak value, so there is no real stability tradeoff between the two models.`
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →