Simple Algorithm
Deep Learning · Representation · 22 min

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 η/B\eta/B, and smaller is better. A learning-rate schedule ηt\eta_t 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.

DerivationSGD under a schedule, one direction at a time
  1. mt+1=(1−ηth) mt,vt+1=(1−ηth)2 vt+ηt2 σ2B,E[L(θt)]=h2(mt2+vt)m_{t+1}=(1-\eta_th)\,m_t,\qquad v_{t+1}=(1-\eta_th)^2\,v_t+\eta_t^2\,\frac{\sigma^2}{B},\qquad\E\big[\loss(\theta_t)\big]=\frac h2\big(m_t^2+v_t\big)

    Take L(θ)=h2θ2\loss(\theta)=\frac h2\theta^2, with curvature hh and its minimum at 00, and mini-batch gradients hθt+ξth\theta_t+\xi_t whose noise has mean 00 and variance σ2/B\sigma^2/B. A step θt+1=(1−ηth)θt−ηtξt\theta_{t+1}=(1-\eta_th)\theta_t-\eta_t\xi_t is linear, so the mean mtm_t and variance vtv_t of θt\theta_t follow exact recursions:

  2. mT=∏t<T(1−ηth)  θ0  ≈  e−hST θ0m_T=\prod_{t<T}(1-\eta_th)\;\theta_0\;\approx\;e^{-hS_T}\,\theta_0

    The mean forgets the starting point at a rate set by the summed learning rate ST=∑t<TηtS_T=\sum_{t<T}\eta_t, the area under the schedule. When every ηth\eta_th is small, 1−ηth≈e−ηth1-\eta_th\approx e^{-\eta_th}:

  3. vT=σ2B∑t<Tηt2∏s=t+1T−1(1−ηsh)2  ≈  ηT σ22Bhv_T=\frac{\sigma^2}{B}\sum_{t<T}\eta_t^2\prod_{s=t+1}^{T-1}(1-\eta_sh)^2\;\approx\;\frac{\eta_T\,\sigma^2}{2Bh}

    The variance sums the noise injected at every step, each contribution damped by all later steps. Contributions older than about 1/(ηh)1/(\eta h) 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):

  4. E[L(θT)]  ≈  h2 θ02 e−2hST⏟forgetting the start  +  ηT σ24B⏟noise at the final rate\E\big[\loss(\theta_T)\big]\;\approx\;\underbrace{\tfrac h2\,\theta_0^2\,e^{-2hS_T}}_{\text{forgetting the start}}\;+\;\underbrace{\frac{\eta_T\,\sigma^2}{4B}}_{\text{noise at the final rate}}

    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 η\eta 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 hST≳1hS_T\gtrsim1, 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 1/(ηh)1/(\eta h). 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."

Predict before you look

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

0.8+12×0.2=0.90.8+\tfrac12\times0.2=0.9: the stable phase keeps all of its area and the linear ramp keeps half of its own. Cosine keeps 1T∑t12(1+cos⁡πtT)≈12\frac1T\sum_t\frac12\big(1+\cos\frac{\pi t}T\big)\approx\frac12, and a step schedule that divides by 10 at 50% and again at 75% keeps 0.5+0.025+0.0025≈0.530.5+0.025+0.0025\approx0.53. 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 ηmax⁡\eta_{\max} 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 TT in advance.

ScheduleShape after warmupNeeds TT?Origin and typical use
Step decayconstant, divided by 10 at preset pointsyes, for the milestonesResNets: start at 0.10.1 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γt\gamma^timplicitly: γ\gamma is chosen for a planned lengtha smooth version of step decay
Cosine12(1+cos⁡πtT)\frac12\big(1+\cos\frac{\pi t}{T}\big), often floored at 10%yesSGDR (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 decay1−t/T1-t/TyesBERT: 10,000 warmup steps, then linear decay (Devlin et al., 2019); worst-case optimal in convex theory
Inverse square rootTw/t\sqrt{T_w/t}nothe original transformer (Vaswani et al., 2017)
Cyclical, one-cycletriangles between two bounds; one-cycle rises and falls once, then drops far loweryes, for one-cycleSmith (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–decay11 until (1−c)T(1-c)T, then down to 00 over the last fraction cconly to start the decayZhai et al. (2022) for vision transformers; named by Hu et al. (2024)
Shapes are relative to the peak. For the decaying schedules tt counts the steps after warmup, for inverse square root the steps since the start. Step decay was the vision default of the 2010s and cosine the language-model default; warmup–stable–decay has been adopted for several open language models, as of the mid-2020s.
ηt={ηmax⁡ tTw,t<Twηmin⁡+ηmax⁡−ηmin⁡2(1+cos⁡π (t−Tw)T−Tw),Tw≤t≤T\eta_t=\begin{cases}\eta_{\max}\,\dfrac{t}{T_w}, & t<T_w\\[8pt]\eta_{\min}+\dfrac{\eta_{\max}-\eta_{\min}}{2}\Big(1+\cos\dfrac{\pi\,(t-T_w)}{T-T_w}\Big), & T_w\le t\le T\end{cases}
Linear warmup followed by cosine decay. Loshchilov & Hutter (2017) introduced the cosine as one cycle of SGDR, which restarts the rate at its peak after each cycle and can lengthen the cycles by a factor TmultT_{\text{mult}}, so that good models appear at many points of a run. Language models usually set ηmin⁡=0.1 ηmax⁡\eta_{\min}=0.1\,\eta_{\max}.
ηt=d−1/2⋅min⁡(t−1/2,  t Tw−3/2)\eta_t=d^{-1/2}\cdot\min\big(t^{-1/2},\;t\,T_w^{-3/2}\big)
The original transformer's schedule (Vaswani et al., 2017), with model width dd and Tw=4000T_w=4000 warmup steps: a linear ramp up to step TwT_w, then decay like 1/t1/\sqrt t. It needs no horizon but never decays to zero. Its d−1/2d^{-1/2} is an early instance of tying the rate to width (μP & Hyperparameter Transfer).
Predict before you look

With d=512d=512 and Tw=4000T_w=4000, as in the base transformer, what is the peak learning rate of this schedule, in units of 10−410^{-4}?

Show the answer

7 × 10⁻⁴

The two branches meet at t=Twt=T_w, where the rate is d−1/2Tw−1/2=1/512×4000=1/1431≈6.99×10−4d^{-1/2}T_w^{-1/2}=1/\sqrt{512\times4000}=1/1431\approx6.99\times10^{-4}. The base models trained for 100,000 steps, by which point the rate had fallen to 4000/100000=20%\sqrt{4000/100000}=20\% 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 TT, which ties the schedule to a decision that is often not final.

  • Stopping early. A cosine run planned for TT steps and stopped at T/2T/2 is still at half its peak rate. It never had a cooldown, so its loss sits well above what a run planned for T/2T/2 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.

Check your understanding

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?

  1. Worse: at step 50,000 your rate is still half the peak, so you stop on a noise floor without the final decay
  2. About the same: both took 50,000 steps with the same peak rate
  3. Better, because the higher rate kept exploring the landscape
  4. 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 12(1+cos⁡π2)=12\frac12(1+\cos\frac\pi2)=\frac12. 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 TwT_w 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 0.10.1, so they trained at 0.010.01 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 3.23.2:

Warmup over the first 5 epochsTop-1 error
none: 3.23.2 from the first step24.84%±0.3724.84\% \pm 0.37
constant: 0.10.1, then a jump to 3.23.225.88%±0.5625.88\% \pm 0.56
gradual: linear from 0.10.1 to 3.23.223.74%±0.0923.74\% \pm 0.09
reference: batch 256 at 0.10.1, no warmup needed23.60%±0.1223.60\% \pm 0.12
ResNet-50 on ImageNet, mean and standard deviation over 5 runs (Goyal et al., 2017, Table 1). After the constant warmup the training error spiked at the switch and never fully recovered; the gradual ramp closed the gap to small-batch training.

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 v^t\hat{\mathbf v}_t averages only a handful of squared gradients, and the bias correction of m^t\hat{\mathbf m}_t inflates early updates; both effects fade within a few multiples of 1/(1−β)1/(1-\beta) steps.
  • Early curvature. Near initialization the loss can be sharper than the peak rate tolerates, λmax⁡>2/ηmax⁡\lambda_{\max}>2/\eta_{\max}. 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 2/λmax⁡2/\lambda_{\max}, whereas a ramp raises the rate in small increments that the curvature, and the optimizer's running averages, can adjust to.

Schedules in practice

python
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 η/B\eta/B, 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 ηtλ\eta_t\lambda, 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 h2θ02e−2hST+ηTσ2/(4B)\frac h2\theta_0^2e^{-2hS_T}+\eta_T\sigma^2/(4B): a forgetting term set by the summed rate STS_T 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.

Question 1

A team plans a cosine schedule that decays to zero over 1.5T1.5T steps, but stops after TT. What fraction of the peak rate is it using at its last step?

  1. About 0%0\%, as at the end of any cosine run
  2. 10%10\%, the usual cosine floor
  3. 25%25\%
  4. 50%50\%
Show the answer

C. 25%25\%

At the last step the run is two thirds of the way through the planned cosine, so the rate is 12(1+cos⁡2π3)=12(1−12)=0.25\frac12\big(1+\cos\frac{2\pi}3\big)=\frac12\big(1-\frac12\big)=0.25 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.

Question 2

For SGD on a noisy quadratic, the final excess loss is about h2θ02e−2hST+ηTσ24B\frac h2\theta_0^2e^{-2hS_T}+\frac{\eta_T\sigma^2}{4B}, where STS_T is the summed learning rate. What does this predict?

  1. Only the final rate matters, so any schedule that ends at zero is optimal
  2. A good schedule needs both a large summed rate, for progress along flat directions, and a small final rate, for low noise
  3. Only the summed rate matters, so a constant rate is optimal
  4. 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 hSThS_T 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.

Question 3

Which statement about the inverse-square-root schedule ηt=d−1/2min⁡(t−1/2, tTw−3/2)\eta_t=d^{-1/2}\min\big(t^{-1/2},\,tT_w^{-3/2}\big) is correct?

  1. It peaks at t=Twt=T_w and then decays like 1/t1/\sqrt t without ever reaching zero, so it needs no total step count
  2. It peaks at t=1t=1, so warmup must be added separately
  3. It decays to zero at a planned final step TT
  4. Its peak does not depend on the model width
Show the answer

A. It peaks at t=Twt=T_w and then decays like 1/t1/\sqrt t without ever reaching zero, so it needs no total step count

For t<Twt<T_w the branch tTw−3/2tT_w^{-3/2} is the smaller one, a linear ramp; the branches cross at t=Twt=T_w; afterwards the rate is d−1/2t−1/2d^{-1/2}t^{-1/2}. No total step count appears anywhere, which suits runs of unknown length, but without a final decay the last iterate keeps a noise floor.

Question 4

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?

  1. Because the widget uses plain SGD, and warmup only matters for adaptive optimizers
  2. Because warmup only matters at small batch sizes
  3. Because the widget trains for only 1,000 steps
  4. 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

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).