◆ AI All-in-One

Level 3 In-Depth AI · Deep Learning

Learning Rate Schedules

The best learning rate changes during training. Start gently while the network is chaotic, go fast through the middle, and slow right down at the end to settle into a low point. Warmup, step decay, cosine decay, one-cycle, and how to find a good peak rate with a range test.

Level
●●●●● Easy
Reading
12 min
To learn it well
45 minutes to read, an hour to practise
↗ Plan a path here

Read first

Optimizers: SGD, Momentum and Adam

This leads to

—
The full path from zero — 17 concepts before this one
  1. What Is AI?
  2. Vectors
  3. Derivatives and Slopes
  4. Probability Basics
  5. How Machines Learn
  6. Partial Derivatives and Gradients
  7. Matrices and Matrix Multiplication
  8. The Chain Rule
  9. Supervised, Unsupervised and Reinforcement Learning
  10. Gradient Descent
  11. Supervised Learning
  12. Linear Regression
  13. The Perceptron
  14. Logistic Regression
  15. Neural Networks
  16. Backpropagation
  17. Optimizers: SGD, Momentum and Adam
  18. Learning Rate Schedules

Read them roughly in this order. See it on the concept map →

Why it matters

The learning rate is the most important setting in neural-network training. The Optimizers: SGD, Momentum and Adam chapter treated it as a fixed number. In practice almost nobody keeps it fixed. Every large model you have heard of, from ResNet to GPT-3 to today's open language models, was trained with a learning rate schedule: a rule that changes the learning rate as training goes on.

The difference is not cosmetic. With the wrong schedule, a large Transformer can blow up in its first few hundred steps, or end training noticeably worse than it could have. A good schedule is often worth as much as a better architecture, and it costs nothing extra to run. This chapter explains why the learning rate should change, describes the schedules people actually use, and shows how to find a good peak value quickly.

The intuition

Think of parking a car. You drive fast on the open road, slow down as you approach your street, and creep the last few metres into the space. Driving at full speed all the way means you overshoot. Creeping the whole way means you never arrive.

Training has the same shape, plus a twist at the start.

  • At the start, the weights are random and the gradients are large and erratic. Normalisation statistics and Adam's running averages haven't settled yet. A big step now can throw the network into a bad region it never recovers from. So start gently: this is warmup.
  • In the middle, take big steps. You cover ground fast, and the noise from big steps on random mini-batches helps you skip over small bumps and flat stretches.
  • At the end, big steps stop helping. Each mini-batch gradient is a noisy estimate, so with a large step you keep bouncing around the bottom of the valley instead of settling in it. Shrink the steps and the bouncing dies down: this is decay.
Constant same rate throughout peak 0 end Step decay ÷10 at 1/3 and 2/3 of training peak 0 end Cosine decay half a cosine wave down to 0 peak 0 end Warmup + cosine linear warmup for 10%, then cosine peak 0 end One-cycle up for 30%, then down far below the start peak 0 end Warmup-stable-decay warmup, long flat stretch, short final decay peak 0 end learning rate (vertical) against training step (horizontal)
Fig. 1 Six learning rate schedules, each from the start to the end of training. Constant never changes. Step decay drops by 10 times twice. Cosine decay follows half a cosine wave down to zero. Warmup + cosine adds a short linear ramp at the start. One-cycle rises and then falls far below its starting value. Warmup-stable-decay stays flat for most of training and decays only at the end.

Key idea Use a short warmup, then decay the learning rate towards zero by the end of training. Warmup prevents early blow-ups; decay lets the model settle below the noise floor that a constant rate can't get past. Linear warmup followed by cosine decay is the most common default today.

How it works

Why decay helps: the noise floor

With mini-batch training, each step uses a gradient estimated from a small random sample, so it points roughly downhill plus some random error. Near the minimum, the true gradient is almost zero, but the random error isn't. So with a constant learning rate η\eta, the weights end up jiggling in a cloud around the minimum. The size of the cloud grows with η\eta. The loss can't fall below the level set by this jiggling, which we can call the noise floor.

Shrinking η\eta shrinks the cloud. Here is a real experiment: linear regression on 1,000 noisy examples, trained with mini-batches of 8 for 3,000 steps, starting at η=0.05\eta = 0.05. We measure how far the final loss is above the best possible loss.

Schedule Loss above the best possible
Constant η=0.05\eta = 0.05 0.260
Step decay (÷10 at step 1,000 and 2,000) 0.0035
Cosine decay to 0 0.0044
0.001 0.01 0.1 1 10 100 0 1000 2000 3000 step (mini-batches of 8) loss above the best possible (log scale) constant step decay cosine constant rate: stuck bouncing at the noise floor
Fig. 2 Loss above the best possible during training, on a log scale. All three schedules drop quickly at first. The constant rate then bounces around 0.1 forever. Step decay drops sharply each time the rate is cut, and cosine decay glides down. Both end around 0.004, about 60 times better.

The constant rate gets most of the way in the first 100 steps and then makes no further progress at all. Decaying it, either way, ends about 60 times closer to the best answer. In deep networks the effect is the same: the final sharp drop in a loss curve is usually the moment the learning rate fell.

Step decay

The oldest schedule: keep η\eta constant, then multiply it by a fixed factor (usually 0.1) at chosen points. ResNets on ImageNet were classically trained for 90 epochs with the rate divided by 10 at epochs 30, 60 and 80. It works, but you have to choose when to drop, and the loss curve has abrupt cliffs. A variant, reduce on plateau, drops the rate automatically whenever the validation loss stops improving for a set number of epochs.

Cosine decay

Cosine decay lowers the rate smoothly along half a cosine wave, from the peak ηmax⁡\eta_{\max} at step 0 to a minimum ηmin⁡\eta_{\min} at the final step TT:

ηt=ηmin⁡+12(ηmax⁡−ηmin⁡)(1+cos⁡πtT)\eta_t = \eta_{\min} + \tfrac{1}{2}(\eta_{\max} - \eta_{\min})\left(1 + \cos\frac{\pi t}{T}\right)

At t=0t = 0, cos⁡0=1\cos 0 = 1, so η=ηmax⁡\eta = \eta_{\max}. At t=Tt = T, cos⁡π=−1\cos \pi = -1, so η=ηmin⁡\eta = \eta_{\min}. Halfway, cos⁡(π/2)=0\cos(\pi/2) = 0, so η\eta is exactly halfway between. The curve stays near the peak for a while, falls fastest in the middle, and flattens out at the end. There is only one thing to choose: the total length TT. ηmin⁡\eta_{\min} is often 0, or about 10% of the peak.

Warmup

Warmup ramps the learning rate up from near zero to the peak over the first few hundred or few thousand steps, usually in a straight line. Three reasons it helps:

  • Random starting weights produce large, erratic gradients. Full-size steps based on them can push weights into a bad region, or make activations so large that the loss becomes nan.
  • Adam's estimates start empty. Its average squared gradient vv is based on only a few samples early on, so its per-parameter step sizes are unreliable. A small learning rate protects against that.
  • Large batches allow a larger peak rate, but only if you approach it gradually. In 2017 a team at Facebook trained a ResNet-50 on ImageNet in one hour with batches of 8,192 images. Their recipe was the linear scaling rule (multiply the learning rate by kk when you multiply the batch size by kk) plus 5 epochs of gradual warmup.

Transformers, especially those with the original "post-norm" layout, are notoriously unstable without warmup. The original 2017 Transformer used 4,000 warmup steps.

Warmup plus cosine, worked through

Combine the two and you have today's most common default. Suppose a peak rate of 3×10−43 \times 10^{-4}, 10,000 steps in total, of which the first 500 are warmup.

  • Step 0: the warmup starts at 1% of the peak, 3×10−63 \times 10^{-6}.
  • Step 250: halfway up the ramp, about 1.5×10−41.5 \times 10^{-4}.
  • Step 500: the peak, 3×10−43 \times 10^{-4}. Cosine decay begins and has 9,500 steps to run.
  • Step 2,875: a quarter of the way through the decay. 12(1+cos⁡π4)=12(1+0.707)=0.854\frac{1}{2}(1 + \cos\frac{\pi}{4}) = \frac{1}{2}(1 + 0.707) = 0.854, so η=0.854×3×10−4=2.56×10−4\eta = 0.854 \times 3 \times 10^{-4} = 2.56 \times 10^{-4}.
  • Step 5,250: halfway through the decay, 12(1+0)=0.5\frac{1}{2}(1 + 0) = 0.5, so η=1.5×10−4\eta = 1.5 \times 10^{-4}.
  • Step 10,000: essentially zero.

For a sense of scale at the top end: GPT-3 used a linear warmup over its first 375 million tokens of training, then cosine decay down to 10% of the peak over the next 260 billion tokens.

One-cycle

The one-cycle policy pushes the idea further. The rate starts low, rises to a high peak over about the first 30% of training, then falls to far below where it started. The high middle phase acts as a regulariser and lets training cover ground fast; the long low tail settles the model. Leslie Smith reported in 2017 that this sometimes reaches the same accuracy in several times fewer epochs, which he called super-convergence. In its usual form momentum is cycled the opposite way, low when the learning rate is high. It is the default training method in the fastai library (fit_one_cycle).

Warmup-stable-decay

Cosine decay has an annoying property: you must decide the total training length in advance, because the whole curve depends on TT. If you later want to train longer, the run you have is in the wrong place. Warmup-stable-decay (WSD) holds the rate at its peak for most of training and only decays it in a short final phase, often the last 10–20% of steps. You can branch off a decay phase from any checkpoint of the long flat stretch. Popularised by the MiniCPM models in 2024, it has since been used by several language model teams.

Finding the peak: the range test

All of these schedules still need a peak value. The learning rate range test finds a sensible one in a single short run. Start with a tiny rate, increase it by a constant factor after every mini-batch, and record the loss. Plotted against the learning rate (on a log scale), the loss is flat at first (rate too small to matter), then falls steeply, then bottoms out and shoots up when the rate becomes too large.

On the digits network from Neural Networks, increasing the rate by 10% per step from 10−410^{-4}:

Learning rate Loss
1.0×10−41.0 \times 10^{-4} 2.301
1.2×10−21.2 \times 10^{-2} 2.209
7.9×10−27.9 \times 10^{-2} 1.526
2.0×10−12.0 \times 10^{-1} 0.727
5.3×10−15.3 \times 10^{-1} 0.532
1.41.4 0.730
2.22.2 10.4 (exploded)

A common rule of thumb is to take a peak somewhat below the loss minimum: here the minimum is near 0.5, and around 0.05–0.2, where the loss is still falling steeply, is a reasonable peak. It's a quick heuristic, not a guarantee. Confirm it with a short real run.

In code

Linear warmup followed by cosine decay with PyTorch's built-in schedulers. The schedule is advanced once per optimizer step:

import torch
from torch.optim.lr_scheduler import LinearLR, CosineAnnealingLR, SequentialLR

model = torch.nn.Linear(10, 1)
opt = torch.optim.AdamW(model.parameters(), lr=3e-4)       # 3e-4 is the peak rate
warmup_steps, total_steps = 500, 10_000

warmup = LinearLR(opt, start_factor=0.01, end_factor=1.0, total_iters=warmup_steps)
cosine = CosineAnnealingLR(opt, T_max=total_steps - warmup_steps, eta_min=0.0)
sched = SequentialLR(opt, schedulers=[warmup, cosine], milestones=[warmup_steps])

for step in range(total_steps):
    if step in (0, 250, 500, 2875, 5250, 9999):
        print(f"step {step:5d}  lr {opt.param_groups[0]['lr']:.2e}")
    # ... forward, loss.backward() ...
    opt.step()                 # update the weights first
    sched.step()               # then move the schedule on by one step

# step     0  lr 3.00e-06
# step   250  lr 1.51e-04
# step   500  lr 3.00e-04
# step  2875  lr 2.56e-04
# step  5250  lr 1.50e-04
# step  9999  lr 8.20e-12

A learning rate range test from scratch:

import torch
from torch import nn
from sklearn.datasets import load_digits

digits = load_digits()
X = torch.tensor(digits.data, dtype=torch.float32) / 16
y = torch.tensor(digits.target)

torch.manual_seed(0)
model = nn.Sequential(nn.Linear(64, 128), nn.ReLU(), nn.Linear(128, 10))
opt = torch.optim.SGD(model.parameters(), lr=1e-4, momentum=0.9)
loss_fn = nn.CrossEntropyLoss()

lr, growth = 1e-4, 1.1                      # multiply the learning rate by 1.1 every step
results = []
for step in range(120):
    idx = torch.randint(0, len(X), (64,))
    loss = loss_fn(model(X[idx]), y[idx])
    results.append((lr, loss.item()))
    if loss.item() > 4 * results[0][1]:     # stop once the loss has clearly exploded
        break
    opt.zero_grad(); loss.backward(); opt.step()
    lr *= growth
    for group in opt.param_groups:
        group["lr"] = lr

for lr_, loss_ in results[::10]:
    print(f"lr {lr_:.1e}  loss {loss_:.3f}")
print(f"stopped at lr {results[-1][0]:.1e} with loss {results[-1][1]:.1f}")

# lr 1.0e-04  loss 2.301
# ...
# lr 7.9e-02  loss 1.526
# lr 2.0e-01  loss 0.727
# lr 5.3e-01  loss 0.532
# lr 1.4e+00  loss 0.730
# stopped at lr 2.2e+00 with loss 10.4

Throw this model away afterwards and start the real training from fresh weights.

Common pitfalls

  • Stepping the scheduler per epoch when it was set up per step, or the other way round. A cosine schedule configured for 10,000 steps but stepped once per epoch will barely move. Decide on one unit and use it everywhere.
  • Calling sched.step() before opt.step(). PyTorch warns about this, and it skips the first value of the schedule.
  • Changing the training length without changing TT. If you train for twice as long but leave the cosine length alone, the rate hits zero halfway and the rest of the run is wasted.
  • Resuming without the scheduler's state. Save sched.state_dict() in checkpoints, or the schedule restarts from the beginning, with a fresh warmup in the middle of training.
  • Judging a run before it has decayed. With a cosine or WSD schedule, the loss often looks disappointing until the rate comes down. Compare runs at the end, or at equal points in their schedules.

Watch out If training a Transformer blows up within the first few hundred steps, the usual suspects are no warmup, too short a warmup, or too high a peak rate. Add or lengthen warmup and lower the peak before trying anything more exotic.

Where it leads

A bit of history

Shrinking the step size over time is as old as stochastic gradient descent itself. Robbins and Monro proved in 1951 that a noisy method like SGD converges if the step sizes shrink towards zero, but not too fast. Practitioners used step decay for decades, and it was standard for training image networks through the mid-2010s.

Leslie Smith introduced cyclical learning rates and the range test in 2015, and the one-cycle policy in 2017. Ilya Loshchilov and Frank Hutter proposed cosine annealing with warm restarts (SGDR) in 2016, and plain cosine decay soon became a default. Priya Goyal and colleagues at Facebook showed in 2017 how warmup plus the linear scaling rule allowed huge batches. The 2017 Transformer paper used warmup followed by inverse-square-root decay, and linear warmup plus cosine decay became the standard recipe for language models. Warmup-stable-decay schedules spread from around 2024.

Try it

  1. In the warmup-plus-cosine code, set eta_min=3e-5 (10% of the peak) and print the rate at step 9,999. Check it against the formula.
  2. Write your own LambdaLR function for warmup-stable-decay: 500 warmup steps, flat until step 8,000, then a linear decay to zero at 10,000.
  3. Run the range test with plain SGD (no momentum). Does the loss minimum move to a higher or lower learning rate? Why?

Hint for 3: momentum makes each step about 1/(1−β)=101/(1 - \beta) = 10 times longer in a consistent direction, so it needs a smaller rate for the same effect.

Check your understanding

5 quick questions. Pick an answer to see whether you were right and why. Your best score is saved on this device.

  1. You train with a constant learning rate. The loss drops fast for 100 steps, then bounces around the same level for the remaining 2,900 steps. What would most likely help?

  2. A Transformer's loss turns to nan within the first 200 steps. Which change should you try first?

  3. Cosine decay runs from a peak of 4 × 10⁻⁴ down to 0 over 10,000 steps (no warmup). What is the learning rate at step 5,000?

  4. You planned a 10,000-step cosine schedule but now want to train twice as long, and you don't change the schedule's length T. What happens?

  5. In a learning rate range test, the loss is lowest around η = 0.5 and explodes at η = 2. Which peak rate is a sensible starting choice?

Finished this chapter?

Learn more

Hand-picked courses, books, videos and tutorials for going deeper. See all resources →

Book

Dive into Deep Learning

Zhang, Lipton, Li & Smola · Intermediate · Free

An interactive book with maths, figures and runnable PyTorch code for every chapter. Many universities use it.

Course

Practical Deep Learning for Coders

Jeremy Howard (fast.ai) · Beginner · Free

Top-down and code-first: you train state-of-the-art models in lesson one, then learn how they work. It suits programmers.

Docs

torch.optim

PyTorch · Intermediate · Free

Reference for PyTorch's optimizers and learning-rate schedulers, including the exact update rule each one implements.

Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/dl/learning-rate-schedules.md