Cosine Annealing and Warm Restarts
Instead of dropping the learning rate in sudden steps, this schedule glides it down along a smooth cosine curve, and can periodically jump it back up to escape a valley that turned out not to be good enough.
Prerequisites: Learning Rate Schedules, Gradient Descent
A learning rate that stays constant throughout training tends to keep bouncing around near the bottom of the loss surface without ever settling precisely — like trying to park a car by only ever using full acceleration or full brake. Dropping the rate down helps it settle, but a schedule that drops it in sudden steps (say, cutting it by 10x every 30 epochs) creates jarring transitions: training happily cruising at one rate, then abruptly forced into much smaller steps. Cosine annealing smooths that transition into a gentle curve, and warm restarts add a deliberate way to escape a valley the smooth descent settled into too early.
The analogy: coasting a bike to a stop, then pedalling off again
Braking a bicycle in one sudden clamp is jarring; easing off the pedals and letting the bike gradually decelerate to a stop is smooth — that gradual glide, fast at first and slower as you approach zero, is the shape of a cosine curve over its first half. Cosine annealing lets the learning rate glide down exactly like that: fast early, slowing as it nears its minimum. A warm restart is choosing to hop back on and pedal hard again once you've coasted to a stop at some spot, in case a bit further down the road there's a better spot to end up — rather than assuming the first place you coasted to a stop was the only worthwhile one.
The shape of the curve
Cosine annealing sets the learning rate at step (within a cycle of length ) as:
In words: the rate starts at when (since ), glides smoothly down following a cosine curve, and reaches at (since ). Unlike a step schedule, the rate of decrease itself changes smoothly — fastest around the midpoint of the cycle, gentlest near both ends — rather than jumping discontinuously.
A warm restart resets back to once a cycle finishes, sending the learning rate immediately back up to and starting a fresh cosine descent, often with the cycle length doubled each time (a schedule called SGDR). The idea: once the optimizer has settled somewhere by the end of one cosine cycle, a sudden jump back to a high learning rate can kick it out of that spot and let it explore for a potentially better one, while the eventual re-descent lets it settle again.
Worked example 1: one cosine cycle
Let , , cycle length . At : . At (halfway): , so — exactly half the max rate, at the point of steepest descent. At (cycle end): , so . The rate glides from to to smoothly across the cycle, slowing its own descent as it approaches zero.
Worked example 2: a warm restart
Continuing that setup with SGDR-style doubling: right after , the rate resets to and a new cycle of length begins (double the first). At the new cycle's midpoint, into the new cycle: , same relative shape, but now stretched over twice as many steps, giving the optimizer more time to explore and settle in this longer second cycle before the next restart.
What this means in practice
Cosine annealing (often without restarts) is a common default schedule for training modern deep networks because the smooth descent, especially the slow final approach to a low rate, tends to land in a well-settled minimum without the jarring transitions of step schedules. Warm restarts are also useful for generating a series of good, somewhat-different weight snapshots at each cycle's end — a natural feeder into the weight-averaging techniques used in snapshot ensembling and Stochastic Weight Averaging.
Cosine annealing decays the learning rate along a smooth curve instead of sudden steps, and warm restarts periodically snap the rate back up to let the optimizer escape a settled spot and search for a better one, at the cost of a temporary jump back in training loss right after each restart.
Practice
- With , , , what is at ?
- Why does a step-schedule's sudden rate drop create a more jarring transition than cosine annealing's?
- What is one reason you might want the snapshot right before a warm restart rather than right after?
It's tempting to think a warm restart is a step backward — after all, the training loss visibly jumps up right when the rate snaps back to . That jump is the point, not a flaw: it's a deliberate re-exploration step, and the loss is expected to come back down, often to a better place, by the end of the next cycle. Stopping training right after a restart, mistaking the loss spike for a training failure, throws away the cycle before it's had a chance to re-settle.
Related concepts
Practice in interviews
Further reading
- Loshchilov & Hutter, SGDR: Stochastic Gradient Descent with Warm Restarts (2017)