AI Logic

Learning Rate Schedulers

Step Decay

Updated:

Learning rate graphs for step decay, with the learning rate on a log scale. The left panel is ResNet-50 on ImageNet (Goyal et al.), with epochs on the horizontal axis: it starts at 0.1, is multiplied by 0.1 at epochs 30, 60 and 80, and ends at epoch 90. The right panel is ResNet on CIFAR-10 (He et al.), with iterations on the horizontal axis: it starts at 0.1, is multiplied by 0.1 at 32k and 48k, and training ends at 64k

What is step decay?

Step decay is a learning rate scheduler that lowers the learning rate in steps by a fixed factor (usually 1/10) each time a chosen point is reached. Training moves quickly with a large learning rate in the first part, and once the loss stops decreasing easily, the learning rate is lowered to fine-tune.

It was not proposed in a specific paper; it is a standard approach that has long been used in deep learning. The textbook Dive into Deep Learning also introduces keeping the learning rate constant within intervals as "a common strategy for training deep networks". Smith et al. (2017) likewise call the following "standard training": train with a learning rate of about 0.1, and when test accuracy plateaus, divide it by 10 and continue, repeating this 2 to 3 times.

In the CIFAR-10 experiments of the ResNet paper (He et al., 2015), training starts at a learning rate of 0.1, divides it by 10 at 32,000 and 48,000 iterations, and ends at 64,000 iterations (right of the figure at the top). Settings like this have long been used for image classification CNNs.

Theory (how the learning rate is set)

The step decay procedure is as follows.

  1. Choose the initial learning rate η0\eta_0. For image classification such as ResNet, 0.1 with SGD and momentum is common.
  2. Choose the decay factor γ\gamma. 1/10 (γ=0.1\gamma = 0.1) is the most common.
  3. Choose when to decay. There are two ways.
    • Decay every fixed interval ss (PyTorch's StepLR)
    • List the epochs at which to decay (PyTorch's MultiStepLR; these points are called milestones)
  4. Each time such a point is reached, multiply the learning rate by γ\gamma.

With a fixed interval, the learning rate at epoch (or step) tt is given by the following formula.

ηt=η0⋅γ⌊t/s⌋\eta_t = \eta_0 \cdot \gamma^{\lfloor t / s \rfloor}

When the decay points are listed as m1<m2<…m_1 < m_2 < \dots, the learning rate is multiplied by γ\gamma once for each milestone passed by tt.

ηt=η0⋅γ ∣{ i:mi≤t }∣\eta_t = \eta_0 \cdot \gamma^{\,\left|\{\, i : m_i \le t \,\}\right|}

With the ImageNet setting of Goyal et al. (2017) (η0=0.1\eta_0 = 0.1, γ=0.1\gamma = 0.1, milestones 30, 60, 80, 90 epochs in total), the learning rate is as follows (left of the figure at the top).

Epoch0-2930-5960-7980-89
Learning rate0.10.010.0010.0001

When the learning rate is divided by 10 at each step, consecutive levels differ by a factor of 10. On a linear scale, every level after the first looks almost like 0, so the figure at the top uses a logarithmic vertical axis.

Why does lowering the learning rate help?

With a large learning rate, even when the weights get close to the bottom of the loss valley, they move too far along the gradient and bounce around the bottom. The variation in gradients from one mini-batch to the next also translates directly into large fluctuations when the learning rate is large. Lowering the learning rate shrinks each update and lets the weights get closer to the bottom of the valley.

Dive into Deep Learning explains that keeping the learning rate constant within intervals and lowering it only once progress has stalled helps reach a better solution. In practice, training with step decay is well known to produce a staircase-shaped learning curve, in which loss and error drop by a step right after each learning rate cut.

As an analogy, it is like driving quickly toward a distant destination and then walking the last stretch to fine-tune the position.

Settings used in practice

Step decay has been used in papers on representative image classification models.

PaperTaskInitial learning rateDecay ruleTraining length
He et al. (2015) ResNetImageNet0.1Divide by 10 when the error plateausUp to 600,000 iterations
He et al. (2015) ResNetCIFAR-100.1Divide by 10 at 32k and 48k iterations64k iterations
Goyal et al. (2017)ImageNet (ResNet-50)0.1 (for a mini-batch of 256)Divide by 10 at epochs 30, 60 and 8090 epochs

Papers on other schedulers often use step decay as the baseline. Smith and Topin (2017) report that for ResNet-56 on CIFAR-10, step decay reached 91.2% accuracy in about 80,000 iterations, while One Cycle reached 92.4% in 10,000 iterations. Rather than showing that step decay is inferior, this result shows that a cleverer learning rate schedule can sometimes reach the same accuracy with fewer updates.

Practical considerations

step_size and milestones of PyTorch's StepLR and MultiStepLR are counted in calls to scheduler.step(). If step() is called every epoch, as in the official documentation examples, specify them in epochs. If it is called every mini-batch, milestones=[30, 60, 80] means steps 30, 60 and 80, and the learning rate is fully decayed at the very start of training.

The decay points must be re-chosen to match the training length. If the number of training epochs changes but the milestones stay the same, training may end before the learning rate has decreased enough, or spin its wheels for a long time at a small learning rate. Having many settings to choose is the biggest weakness of step decay.

Keep the following points in mind as well.

  • Check that the loss has plateaued just before decaying: lowering the learning rate while the loss is still decreasing switches to a small learning rate too early and can reduce the final accuracy.
  • When the timing is hard to choose, decay based on a validation metric: PyTorch's ReduceLROnPlateau lowers the learning rate when the validation loss or another metric has not improved for a set number of evaluations. This is close to the "divide by 10 when the error plateaus" rule in ResNet's ImageNet experiments. Call step() with the validation metric.
  • When starting from a large learning rate, combine it with warmup: when Goyal et al. scale up the learning rate for large mini-batches, they use step decay after warmup.

Comparison with other learning rate schedulers

The table compares step decay with the schedulers it is often compared with, from the same viewpoints.

SchedulerHow the learning rate decreasesWhat must be set in advanceTypical use
Step decayIn steps at chosen timesWhen to decay and by what factorReproducing tasks with established settings
Cosine annealingSmoothly along a cosine curveTotal steps, maximum and minimumMany tasks with a fixed total number of steps
Polynomial decayPolynomially toward 0Total steps and the powerSegmentation and similar tasks
One CycleRaised once, then lowered sharplyTotal steps and maximumWhen fast convergence in short training is the goal
WSDHeld constant, then lowered in a short final phaseWhen to start decayingPretraining large language models and similar

Some rules of thumb for choosing:

  • To reproduce a paper's results, use the same step decay as the paper: the settings, including the decay points, are already fixed, so they can be used as is.
  • When choosing a new setup, start with cosine annealing: there is no need to choose decay points, so fewer settings are required.
  • If the training length is not fixed, consider ReduceLROnPlateau: it decays while monitoring a validation metric, so the timing does not need to be fixed in advance.

PyTorch example

Show code
python
import torch
import torch.nn as nn

model = nn.Sequential(nn.Flatten(), nn.Linear(28 * 28, 256), nn.ReLU(), nn.Linear(256, 10))
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9, weight_decay=1e-4)

# Multiply the LR by 0.1 at epochs 30, 60 and 80 (same shape as Goyal et al.'s ImageNet setting)
# milestones count scheduler.step() calls -> call step() every epoch
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[30, 60, 80], gamma=0.1)
# For a fixed interval, use StepLR (x0.1 every 30 epochs: 0.1 -> 0.01 -> 0.001)
# scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=30, gamma=0.1)

for epoch in range(90):
    model.train()
    for _ in range(100):                          # Mini-batches per epoch (dummy)
        images = torch.randn(64, 1, 28, 28)
        labels = torch.randint(0, 10, (64,))
        optimizer.zero_grad()
        loss = criterion(model(images), labels)
        loss.backward()
        optimizer.step()
    scheduler.step()                              # Call once at the end of each epoch
    if epoch in (0, 29, 30, 60, 80):
        print(epoch, scheduler.get_last_lr())     # 0.01 from epoch 30, 0.001 from 60, 0.0001 from 80


# Without fixed points: multiply by 0.1 if the validation loss has not improved for 10 epochs
optimizer2 = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
plateau = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer2, mode="min", factor=0.1, patience=10)
for epoch in range(5):
    model.eval()
    with torch.no_grad():
        val_loss = criterion(model(torch.randn(64, 1, 28, 28)), torch.randint(0, 10, (64,)))
    plateau.step(val_loss)                        # Call with the validation metric

FAQ

Q. When should StepLR be used and when MultiStepLR?
A.

Use StepLR to decay at a fixed interval (e.g. every 30 epochs), and MultiStepLR to list decay points freely (e.g. epochs 30, 60 and 80). When reproducing a paper's settings, MultiStepLR, which lets the points be listed, is often easier to match.

Q. Is the decay factor always 1/10?
A.

1/10 is the most common, but it is not a rule. The example in the textbook Dive into Deep Learning uses 1/2. When decaying more times, the per-step factor is sometimes made milder.

Q. Which is better, step decay or cosine annealing?
A.

It depends on the task and setup; neither is always better. Step decay makes it easy to reproduce papers' settings, while cosine annealing requires no decay points. When choosing a new setup, trying cosine annealing first, with fewer settings to choose, is the easy option.

References

  1. PyTorch Documentation, "StepLR."
  2. PyTorch Documentation, "MultiStepLR."
  3. PyTorch Documentation, "ReduceLROnPlateau."
  4. A. Zhang, Z. C. Lipton, M. Li, and A. J. Smola, "Dive into Deep Learning," Section 12.11 Learning Rate Scheduling.
  5. K. He, X. Zhang, S. Ren, and J. Sun, "Deep Residual Learning for Image Recognition," CVPR, 2016.
  6. P. Goyal et al., "Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour," arXiv:1706.02677, 2017.
  7. L. N. Smith and N. Topin, "Super-Convergence: Very Fast Training of Neural Networks Using Large Learning Rates," arXiv:1708.07120, 2017.