TL;DR
Loshchilov and Hutter train neural networks with stochastic gradient descent, but they change the learning rate on a schedule. The rate falls along a cosine curve within a run, then jumps back up to its maximum at a "warm restart" and falls again, with each run longer than the last. The authors report that this reaches good test error on CIFAR-10 and CIFAR-100 two to four times faster than the step schedule used at the time, and that snapshots taken before each restart can be averaged into an ensemble at no extra training cost.
Builds on: Stochastic Gradient Descent, Momentum, Cosine Annealing · Leads to: SGD with warm restarts
Why it mattered
Deep networks were then the best-performing method for many classification problems, and training them on large datasets often took several days even on high-performance GPUs, so any speedup had real value. With snapshot ensembles the authors report new state-of-the-art results on CIFAR-10 and CIFAR-100, and they also show gains on a dataset of brain recordings and on a downsampled version of ImageNet.
The paper's practical contribution is a simple recipe. In its own words, the schedule needs only two hyperparameters, the initial learning rate and the total number of epochs. The solution it reports is the one at the end of the last completed run, so the stopping point is fixed by the schedule rather than searched for.
The problem
Stochastic Gradient Descent updates the parameters using the gradient computed on a small batch of data, and a Learning Rate sets the step size. The learning rate is the main knob in training. A large rate moves quickly but cannot settle into a narrow minimum. A small rate settles but is slow.
The common practice at the time was a step schedule: keep the learning rate constant, then divide it by a fixed constant at set epochs. The drop epochs must be chosen in advance, so the schedule commits to a training length before anything is known about the run. The paper is concerned with anytime performance, meaning how good the model is at any point during training, and a fixed step schedule gives little guidance on that.
Second-order methods such as L-BFGS were not in favour for deep networks because of stochastic gradients, ill-conditioning and saddle points. Adaptive methods such as Adam approximated the inverse curvature in a cheap diagonal way. The paper's narrower aim is anytime performance: plain SGD with momentum, the optimiser behind the best residual networks, can reach good error sooner if its learning-rate schedule is changed.
The authors also draw on earlier restart ideas from gradient-free and gradient-based optimisation. Those restarts reset a search to explore again, or reset an accelerated method when it starts to oscillate. The paper adapts the spirit of a restart to SGD by raising the learning rate, not by starting from scratch.
How it works
The method has one repeating cycle. Think of a tiny run: the maximum learning rate is 0.1, the minimum is 0, and the first run lasts 4 epochs.
- Start a run at the maximum. At the first step of the run the learning rate equals its maximum, here 0.1. The parameters continue from where the previous run ended, so the restart does not throw away what was learned. Momentum carries over too.
- Decay along a cosine. The rate falls over the run as half a cosine wave. After 1 of the 4 epochs it is about 0.085, after 2 epochs it is 0.05, and after 3 epochs it is about 0.015.
- Reach the minimum at the end. At the end of the run the rate is 0, its minimum.
- Warm restart. The next run begins at the maximum again, and its length is multiplied by a factor . A setting the paper uses for its ensembles starts with 10 epochs and doubles the length each time, so the restarts come at epochs 10, 30, 70 and 150.
- Report a solution. Because the rate is high right after a restart, the parameters can be worse there. The paper therefore reports the solution at the end of the most recent completed run, where the rate is at its minimum, not the last step.
flowchart LR A["Run 1: rate falls 0.1 to 0"] --> B["Restart: rate back to 0.1"] B --> C["Run 2: twice as long, falls to 0"] C --> D["Restart"] D --> E["Run 3: falls to 0"] E --> F["Report end of last finished run"]
The restart is a rise in the learning rate, not a reset of the parameters. The paper notes that this rise can temporarily worsen performance, which is why the reporting step matters.
The math
Stochastic gradient descent updates the parameters with
where is the gradient on the -th batch and is the learning rate. The paper uses SGD with Nesterov momentum, which keeps a velocity , starting at zero, and updates it with a momentum rate that sets how much of the old velocity is kept:
Within restart number , which lasts epochs, the learning rate is
where is the number of epochs since the last restart, updated at every batch so it can take fractional values.
Step 1: the start of a run
When , the cosine term is , so . This is the warm restart: the rate jumps back to its maximum.
Step 2: the decay
As grows, the fraction moves from 0 to 1, and the angle moves from 0 to . The cosine moves from 1 to , so the factor moves from 1 to 0, and the rate falls smoothly from the maximum to the minimum.
Step 3: the end of a run
When , the cosine is , so . The paper's recommended solution is taken at this point.
Step 4: the run lengths
With epochs in the first run and multiplier , run has length , so the restart epochs are cumulative sums of these lengths. For and , the lengths are 10, 20, 40 and 80, and the restarts come at epochs 10, 30, 70 and 150.
Worked examples
Example 1: the rate across one short run (tiny)
- Set the maximum , the minimum , and the run length epochs.
- At : the cosine is , so the rate is .
- At : the angle is , the cosine is 0, so the rate is .
- At : the angle is , the cosine is , so the rate is .
- Interpretation: the rate is high at the start, half the maximum at the middle, and zero at the end, with a smooth fall in between.
Example 2: when the restarts come (standard)
- The setting the paper uses for its ensembles on CIFAR is with .
- Run 1 has length 10, so the first restart is at epoch 10.
- Run 2 has length , so the second restart is at epoch .
- Run 3 has length , so the third restart is at epoch .
- Run 4 has length , so the fourth restart is at epoch .
- These are the epochs the paper uses for its ensemble snapshots, taken right before each restart: 30, 70 and 150.
- Interpretation: the gap between restarts doubles, so later runs spend more epochs refining the solution and fewer epochs exploring.
Example 3: how much the ensemble helped (realistic)
- The paper's single WRN-28-10 model, the median of 16 runs, had a CIFAR-10 test error of 4.03 percent.
- Averaging three snapshots from one run (M = 3) gives 3.51 percent.
- The relative reduction is , which is about 0.129, or 12.9 percent.
- Averaging 16 runs with three snapshots each gives 3.14 percent.
- The relative reduction from the single model is , which is about 0.221, or 22.1 percent.
- Interpretation: more than half of the total gain (0.52 of 0.89 points) comes from snapshots of one run, which are free in compute, and the rest from independent runs, which cost full training each.
Try it: on CIFAR-100, the single model has error 19.57 percent and the 16-run ensemble has 16.21 percent. What is the relative reduction? Answer: , which is about 0.172, or 17.2 percent.
Results
CIFAR-10 and CIFAR-100, single models. The paper reproduces the default schedule of the wide residual network WRN-28-10 with an initial rate of 0.1 and 0.05. With 0.05 the median test errors over 5 runs were 4.13 percent on CIFAR-10 and 20.21 percent on CIFAR-100. With warm restarts starting at 10 epochs and doubling, the errors were 4.03 and 19.58 percent. On the wider WRN-28-20, the same restart setting reached 3.74 and 18.70 percent.
Speed. The paper says test errors near 4 percent on CIFAR-10 and near 20 percent on CIFAR-100 are reached about 2 to 4 times faster than with the default schedule. Its introduction states that SGDR needs 2 to 4 times fewer epochs for comparable or better results.
Overfitting. SGDR lowers the training loss faster until about epoch 120. After that the default schedule overfits, and its test error rises. The SGDR runs show only very mild overfitting.
Ensembles. Table 2 reports ensembles of snapshots. One run with one snapshot gives 4.03 and 19.57. One run with three snapshots gives 3.51 and 17.75. Three runs with three snapshots each give 3.25 and 16.64. Sixteen runs with three snapshots each give 3.14 and 16.21, the best numbers reported. These are ensembles of the same architecture, not new architectures.
EEG recordings. On a brain-signal classification dataset, the authors report a median reference error of about 9 percent, which snapshots of one run improved by 1 to 2 points, and snapshots from both settings improved by 2 to 3 points.
Downsampled ImageNet. At 32 by 32 pixels, the best SGDR setting (starting at 10 epochs, doubling, initial rate 0.01) reached a top-1 error of 39.24 percent and a top-5 error of 17.17 percent. The paper compares this with AlexNet's results on full-size ImageNet, 40.7 and 18.2 percent, which used images with about 50 times as many pixels. The authors call these preliminary experiments and note that longer runs and hyperparameter tuning would likely improve the numbers.
Limits. The ImageNet experiment uses 32 by 32 images and is labelled preliminary; the authors say longer runs and tuning would likely improve the numbers. Their experiments use wide residual networks on CIFAR, and the paper itself lists ImageNet and MS COCO as future work. The recommendation to report the end of a run, not the last step, is motivated by the rise in error right after a restart.
Reading guide
- Section 1 (introduction): needs Stochastic Gradient Descent and Momentum. The four schedules in Figure 1 are the best visual summary of the method, so look at them before the equations.
- Section 2.1 and 2.2 (related work): the restart ideas from gradient-free search and from accelerated gradient methods. You can skip them on a first reading; the method does not depend on them.
- Section 3 (the method): needs Cosine Annealing and the Learning Rate. Equation 5 is the formula in the math section above, and the paragraphs around it define the restart and the recommended solution.
- Section 4.1 and 4.2 (CIFAR experiments): the architecture is a residual network variant, and Trigonometric Functions explain the cosine in the schedule. Table 1 is the core evidence.
- Section 4.3 (ensembles): needs Ensemble Learning, the idea of averaging the predictions of several models. The table reports the numbers used above.
- Sections 4.4 and 4.5 (EEG and downsampled ImageNet): supporting experiments with smaller claims.
- Sections 5 and 6 (discussion and conclusion): the claims about anytime performance and about the two hyperparameters.
Check yourself
QuestionIn SGDR, what happens to the learning rate at a warm restart, and what happens to the parameters?Show answer
QuestionUsing the schedule with maximum 0.1, minimum 0 and run length 4 epochs, what is the learning rate after 1 epoch?Show answer
QuestionWhy does the paper report the solution at the end of the last completed run rather than the last step?Show answer
QuestionA team wants to use snapshots to build an ensemble without extra training time. Which epochs does the paper use, and why are those snapshots useful?Show answer
Sources
- Loshchilov and Hutter, "SGDR: Stochastic Gradient Descent with Warm Restarts", arXiv:1608.03983 (2016): https://arxiv.org/abs/1608.03983
- DOI record for arXiv:1608.03983: https://doi.org/10.48550/arXiv.1608.03983