Learning-Rate Schedules & Warmup
Step, cosine and linear decay, warmup, and why the schedule matters as much as the peak.
Train the same network twice with the same optimizer and the same peak learning rate, once at a constant rate and once with the rate decaying to zero, and the second run can finish at a loss several times lower. The shape of the learning rate over time is a hyperparameter in its own right. This lesson derives why it must start large and end small, compares the schedules in use (step, cosine, linear, inverse square root, one-cycle and warmup–stable–decay), explains warmup, and confronts an awkward fact: most schedules must know in advance when training will stop.
What you’ll learn
- Derive, for SGD on a noisy quadratic, how the final loss splits into a term set by the summed learning rate and a noise term set by the final rate, and use it to explain why schedules decay.
- Write down step, exponential, cosine, linear, inverse-square-root, one-cycle and warmup–stable–decay schedules, and identify which of them need the length of the run in advance.
- Explain what warmup does, where it came from, and the three explanations offered for it.
- Implement warmup with cosine decay in PyTorch, and choose the peak rate, the final rate and the schedule together rather than one at a time.
Two jobs for one learning rate
The learning rate has two jobs that pull in opposite directions. Early in training it sets the speed of progress, and larger is better, up to the stability threshold. Late in training it sets the size of SGD's noise ball, which Mini-Batch SGD & Momentum showed is proportional to , and smaller is better. A learning-rate schedule gives the two jobs to different parts of the run. To see exactly how, follow SGD along one direction of a quadratic loss while the rate changes.
Take , with curvature and its minimum at , and mini-batch gradients whose noise has mean and variance . A step is linear, so the mean and variance of follow exact recursions:
The mean forgets the starting point at a rate set by the summed learning rate , the area under the schedule. When every is small, :
The variance sums the noise injected at every step, each contribution damped by all later steps. Contributions older than about steps have died out, so if the rate changes little over that window, the variance tracks the stationary value for the current rate (derived in Gradient Noise, Batch Size & Scaling Rules):
Adding the two pieces, the final excess loss splits into a term that only a large area can shrink and a term that only a small final rate can shrink:
A constant rate must compromise: a large forgets the start quickly but keeps the noise term large, a small one does the reverse. A schedule escapes the trade-off by staying large while the area accumulates and ending small. Two details matter in practice.
- Flat directions set the pace. The forgetting term needs , so the flattest directions need the most area. Decaying too early starves them.
- Decay too fast and the noise freezes in. Step 3 assumed the rate changes slowly compared with the relaxation time . Flat directions relax slowly, so during a quick decay they keep most of the noise they carried at the peak.
A real network has directions of every curvature, and the same two effects show up in experiments. Kaplan et al. (2020, appendix D.6) concluded for language models that "the choice of learning rate schedule is mostly irrelevant, as long as the total summed learning rate is sufficiently large, and the schedule includes a warmup period and a final decay to near-vanishing learning rate."
A warmup–stable–decay schedule holds its peak for the first 80% of the run and then decays linearly to zero. Ignoring warmup, what fraction of a constant schedule's summed learning rate does it keep? (Cosine decay to zero keeps half.)
Show the answer
0.9
: the stable phase keeps all of its area and the linear ramp keeps half of its own. Cosine keeps , and a step schedule that divides by 10 at 50% and again at 75% keeps . More area buys more progress along flat directions; the price is a shorter decay.
A catalog of schedules
Almost every schedule multiplies a peak rate by a shape factor, after a short warmup. They differ in where they spend their area and in whether they must know the total number of steps in advance.
| Schedule | Shape after warmup | Needs ? | Origin and typical use |
|---|---|---|---|
| Step decay | constant, divided by 10 at preset points | yes, for the milestones | ResNets: start at and divide by 10 when the error plateaus (He et al., 2016); on ImageNet, at epochs 30, 60 and 80 of 90 (Goyal et al., 2017) |
| Exponential | implicitly: is chosen for a planned length | a smooth version of step decay | |
| Cosine | , often floored at 10% | yes | SGDR (Loshchilov & Hutter, 2017); the default for large language models, e.g. GPT-3 decayed to 10% over 260 billion tokens (Brown et al., 2020) |
| Linear decay | yes | BERT: 10,000 warmup steps, then linear decay (Devlin et al., 2019); worst-case optimal in convex theory | |
| Inverse square root | no | the original transformer (Vaswani et al., 2017) | |
| Cyclical, one-cycle | triangles between two bounds; one-cycle rises and falls once, then drops far lower | yes, for one-cycle | Smith (2017); with one-cycle, Smith & Topin (2019) trained a ResNet-56 on CIFAR-10 to 92.4% in 10,000 iterations, against 91.2% after about 80,000 with a piecewise-constant schedule |
| Warmup–stable–decay | until , then down to over the last fraction | only to start the decay | Zhai et al. (2022) for vision transformers; named by Hu et al. (2024) |
With and , as in the base transformer, what is the peak learning rate of this schedule, in units of ?
Show the answer
7 × 10⁻⁴
The two branches meet at , where the rate is . The base models trained for 100,000 steps, by which point the rate had fallen to of its peak. It never reaches zero, which is why Zhai et al. (2022) added a final cooldown when they used it.
The horizon problem
Every schedule in the table except inverse square root is defined relative to the total number of steps , which ties the schedule to a decision that is often not final.
- Stopping early. A cosine run planned for steps and stopped at is still at half its peak rate. It never had a cooldown, so its loss sits well above what a run planned for reaches.
- Planning too long. Hoffmann et al. (2022) found that setting the cosine length more than 25% beyond the steps actually trained clearly hurts. Intermediate losses of long cosine runs therefore overstate the loss of shorter, fully decayed runs, which they named as one bias in earlier scaling-law fits (Neural Scaling Laws discusses how much it mattered).
- Continuing. A finished cosine run sits at its smallest rate, where progress is slow, and warming the rate back up makes the loss jump before it recovers (Hägele et al., 2024).
So every training length you want to compare, and every point of a scaling law, costs a run from scratch. Theory says the problem is real, not an artifact of bad schedules:
Part (ii) explains why the old step recipe worked so well; part (iii) is the theoretical face of the horizon problem. Schedules Without a Horizon shows how practice gets around it: by branching short cooldowns off a long constant-rate run, or by averaging iterates instead of decaying the rate.
You train with a cosine schedule planned for 100,000 steps but must stop at 50,000. How will the result compare with a run whose cosine was planned for 50,000 steps from the start?
- Worse: at step 50,000 your rate is still half the peak, so you stop on a noise floor without the final decay
- About the same: both took 50,000 steps with the same peak rate
- Better, because the higher rate kept exploring the landscape
- It cannot be predicted from the schedules alone
Show the answer
A. Worse: at step 50,000 your rate is still half the peak, so you stop on a noise floor without the final decay
Half way through a cosine the factor is . Your run is still at half its peak and has had no cooldown, while the matched run spent its last steps at small rates and shed most of its noise floor. Same steps, same peak, different ending: this is the horizon problem.
Warmup
A warmup raises the rate from near zero to its peak over the first steps, usually linearly. It began as a fix for specific failures. He et al. (2016) found that their 110-layer CIFAR ResNet would not start converging at a rate of , so they trained at until the training error fell below 80%, about 400 iterations, and then switched up. Goyal et al. (2017) needed more for ResNet-50 at a batch of 8,192 images, where the linear scaling rule set the peak to :
| Warmup over the first 5 epochs | Top-1 error |
|---|---|
| none: from the first step | |
| constant: , then a jump to | |
| gradual: linear from to | |
| reference: batch 256 at , no warmup needed |
Transformers made warmup standard: 4,000 steps for the original model, 10,000 for BERT and 375 million tokens for GPT-3. Three explanations are offered, and they predict different things.
- Adam's statistics. In the first steps averages only a handful of squared gradients, and the bias correction of inflates early updates; both effects fade within a few multiples of steps.
- Early curvature. Near initialization the loss can be sharper than the peak rate tolerates, . Small early steps let training move to flatter regions first (Gilmer et al., 2022; Kalra & Barkeshli, 2024).
- Architecture. At initialization the original Post-LN transformer has large gradients in its last layers, whatever its depth, and fails to train without warmup; the Pre-LN arrangement often trains without it (Xiong et al., 2020; Normalization & Stability in Transformers).
Why Warmup Works derives each mechanism and weighs the evidence.
Think first In Goyal et al.'s table, the constant warmup, a low rate for five epochs and then a jump to the full rate, did worse than no warmup at all. Why might a jump be worse than a ramp?
At the switch the step size grows 32-fold at once, and the training error spiked right there. One consistent reading, developed in Why Warmup Works, is that the stability limit is local: training at a small rate can drift into sharper regions, so a jump lands far above the local limit , whereas a ramp raises the rate in small increments that the curvature, and the optimizer's running averages, can adjust to.
Schedules in practice
import math
import torch
opt = torch.optim.AdamW(model.parameters(), lr=3e-4, weight_decay=0.1)
warmup, total = 2_000, 100_000
def factor(step): # multiplies the peak rate 3e-4
if step < warmup: # linear warmup from almost 0
return (step + 1) / warmup
progress = (step - warmup) / (total - warmup)
return 0.1 + 0.9 * 0.5 * (1 + math.cos(math.pi * progress)) # cosine to 10%
sched = torch.optim.lr_scheduler.LambdaLR(opt, factor)
for step in range(total):
loss = loss_fn(model, next(batches))
opt.zero_grad(); loss.backward(); opt.step()
sched.step() # once per optimizer step, after opt.step()LambdaLR multiplies the base rate by factor(step). Step the scheduler once per optimizer step, not once per epoch, and save sched.state_dict() with each checkpoint so that a resumed run continues the schedule. The same shape is available from built-ins, SequentialLR with LinearLR and CosineAnnealingLR; CosineAnnealingWarmRestarts implements SGDR, CyclicLR Smith's triangles and OneCycleLR the one-cycle policy, which by default also cycles the momentum.
Tune the peak under the schedule you will use. The best peak depends on the shape: with a constant rate and a short cooldown, the best rate is about half the best cosine peak (Hägele et al., 2024). Sweeping the peak under one schedule and then switching to another leaves the run mistuned.
Choose the final rate deliberately. Decaying cosine to 10% of the peak is a convention, not an optimum. Bergsma et al. (2025) found that linear decay all the way to zero beat cosine to 10% and other common schedules for language models trained at compute-optimal lengths, by more as the runs got longer; Hägele et al. (2024) saw lower final rates improve perplexity but sometimes hurt downstream benchmarks.
The schedule interacts with the batch size and the weight decay. What SGD's noise depends on is , so growing the batch can replace decaying the rate: Smith, Kindermans, Ying & Le (2018) matched the learning curves of decaying schedules by multiplying the batch size at the milestones instead, with fewer parameter updates. In AdamW the decay applied per step is , so weight decay fades during a cooldown (What Weight Decay Really Does).
Key takeaways
- For SGD on a noisy quadratic, the final excess loss is about : a forgetting term set by the summed rate and a noise term set by the final rate. Schedules exist to get a large area and a small final rate; flat directions need area and a slow enough decay.
- The common shapes are step decay, cosine (often to 10%), linear decay to zero, inverse square root, one-cycle and warmup–stable–decay. All but inverse square root need the total step count, and Hoffmann et al. (2022) found that overestimating it by more than 25% clearly hurts; for least squares, no schedule makes the last iterate optimal without a known horizon.
- Warmup ramps the rate up over the first hundreds to thousands of steps. It began as a fix for very deep ResNets and large-batch SGD; the explanations offered are Adam's unsettled statistics, sharp early curvature and the large early gradients of Post-LN transformers.
- Tune the peak under the schedule you will use, choose the final rate deliberately, step the scheduler once per optimizer step, and remember that batch size and weight decay interact with the schedule.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A team plans a cosine schedule that decays to zero over steps, but stops after . What fraction of the peak rate is it using at its last step?
- About , as at the end of any cosine run
- , the usual cosine floor
Show the answer
C.
At the last step the run is two thirds of the way through the planned cosine, so the rate is of the peak. The run never cooled down, which is why Hoffmann et al. (2022) found that overestimating the length by more than 25% clearly hurts.
For SGD on a noisy quadratic, the final excess loss is about , where is the summed learning rate. What does this predict?
- Only the final rate matters, so any schedule that ends at zero is optimal
- A good schedule needs both a large summed rate, for progress along flat directions, and a small final rate, for low noise
- Only the summed rate matters, so a constant rate is optimal
- Only the peak matters, because it sets the stability limit
Show the answer
B. A good schedule needs both a large summed rate, for progress along flat directions, and a small final rate, for low noise
The first term shrinks only when is large, which needs area under the schedule, most of all for flat directions; the second shrinks only when the final rate is small. A constant rate cannot do both. Cosine, linear and warmup–stable–decay schedules are different compromises between area and the length of the decay.
Which statement about the inverse-square-root schedule is correct?
- It peaks at and then decays like without ever reaching zero, so it needs no total step count
- It peaks at , so warmup must be added separately
- It decays to zero at a planned final step
- Its peak does not depend on the model width
Show the answer
A. It peaks at and then decays like without ever reaching zero, so it needs no total step count
For the branch is the smaller one, a linear ramp; the branches cross at ; afterwards the rate is . No total step count appears anywhere, which suits runs of unknown length, but without a final decay the last iterate keeps a noise floor.
In the widget's noisy quadratic, warmup never lowers the final loss, and a peak above the stability limit still diverges, only later. Why does this not show that warmup is useless?
- Because the widget uses plain SGD, and warmup only matters for adaptive optimizers
- Because warmup only matters at small batch sizes
- Because the widget trains for only 1,000 steps
- Because the model's curvature, and so its stability limit, never changes; in real networks the sharpness and the optimizer's statistics change early in training, which is what warmup exploits
Show the answer
D. Because the model's curvature, and so its stability limit, never changes; in real networks the sharpness and the optimizer's statistics change early in training, which is what warmup exploits
Warmup can only help if the start of training differs from the rest: curvature that is sharp early and then relaxes, Adam's unsettled moment estimates, or the large early gradients of Post-LN transformers. A fixed quadratic has none of these, so a slow start only costs progress.
Go deeper
- Why Warmup Works · Adam’s noisy second moments, early instability, and how warmup tames them.
- Schedules Without a Horizon · Warmup–stable–decay, schedule-free optimization and why cooldowns work.
- Weight Averaging: SWA, EMA & Model Soups · Averaging weights along a run or across runs, and why it works at all.
Further reading
- I. Loshchilov & F. Hutter, "SGDR: Stochastic gradient descent with warm restarts," ICLR (2017).
- P. Goyal, P. Dollár, R. Girshick, P. Noordhuis, L. Wesolowski, A. Kyrola, A. Tulloch, Y. Jia & K. He, "Accurate, large minibatch SGD: Training ImageNet in 1 hour," arXiv:1706.02677 (2017).
- R. Ge, S. M. Kakade, R. Kidambi & P. Netrapalli, "The step decay schedule: A near optimal, geometrically decaying learning rate procedure for least squares," NeurIPS (2019).
- G. Zhang, L. Li, Z. Nado, J. Martens, S. Sachdeva, G. E. Dahl, C. J. Shallue & R. Grosse, "Which algorithmic choices matter at which batch sizes? Insights from a noisy quadratic model," NeurIPS (2019).