Cosine learning rate schedule

Also known as: cosine annealing · cosine decay

On this page 7

A cosine learning rate schedule is a rule that decreases the learning rate from a peak value to a minimum value following the shape of a half cosine wave over the course of a training run. In artificial intelligence and especially in the training of deep neural networks and large language models, it is one of the most widely used default schedules, because it keeps the learning rate high for long enough to make fast progress and then lowers it gently so the model can settle into a good minimum.

The technique is also called cosine annealing or cosine decay. It was popularized by the SGDR method, which added periodic restarts, but most modern training runs use a single cosine decay preceded by a short linear warmup.

How the cosine schedule computes the learning rate

The schedule maps training progress to a learning rate with a simple closed-form formula. At step t out of T total decay steps, the learning rate equals lr_min + 0.5 * (lr_max - lr_min) * (1 + cos(pi * t / T)). At the start the cosine term equals one, so the rate is lr_max; at the end it equals minus one, so the rate is lr_min.

The shape matters more than the formula. The curve is flat near the start, falls fastest in the middle of training and flattens again near the end. This means the optimizer spends a long time at relatively high rates, which favors broad exploration of the loss landscape, and then spends a meaningful number of steps at low rates, which allows fine convergence.

The table shows the fraction of the peak rate that remains at several points of a cosine decay to a minimum of zero.

Training progressShare of peak ratePhase character
0%100%Maximum step size
25%About 85%Still exploring
50%50%Steepest decline
75%About 15%Refining
100%0% or lr_minFinal convergence
Learning rate along a cosine decay

Key parameters and typical values

A cosine schedule is defined by four main hyperparameters, and each one interacts with the optimizer and batch size. Getting the total decay length right is the most consequential choice, because the schedule assumes the run ends exactly when the curve reaches its minimum.

ParameterTypical settingWhat it affects
Peak learning rate1e-4 to 3e-3 for AdamW in transformersSpeed and stability of early training
Minimum learning rate0 to 10% of the peakHow much the model still adapts at the end
Warmup steps0.5% to 5% of total stepsProtection against early divergence
Decay lengthEqual to the planned training stepsWhen the rate reaches its minimum
Parameters of a cosine schedule

Large language model pretraining commonly sets the minimum at about 10% of the peak, which keeps a small amount of plasticity for later continued pretraining. Image classification recipes often decay to zero or near zero because the run is final.

Cosine schedule compared with other schedules

The cosine schedule is one member of the broader learning rate schedule family, and its appeal is that it needs no manual milestones. Step decay requires choosing when to drop the rate, while cosine decay only needs the total length.

ScheduleShapeMain advantageMain drawback
ConstantFlatSimple, easy to resumeWeaker final loss without decay
Step decayDrops at milestonesInterpretable phasesMilestones need tuning
Linear decayStraight line to minimumPredictable, robustLeaves high rate phase shorter
Cosine decayHalf cosine waveStrong results with few settingsTied to a fixed run length
Warmup-stable-decayFlat plateau then short decayAllows extending runsExtra decay phase to tune
Cosine with restartsRepeated cosine cyclesProduces several snapshotsRestarts can disrupt convergence
Common learning rate schedules

Recent research on large models shows that warmup-stable-decay schedules can match cosine decay while making it easier to stop or extend training. Cosine decay nevertheless remains a strong, well-understood baseline that many teams use when the training budget is known in advance.

Configuring cosine decay in practice

Practitioners usually combine cosine decay with a short linear warmup, because adaptive optimizers such as Adam and AdamW can produce unstable updates in the first steps when their moment estimates are still noisy. The warmup ramps the rate from near zero to the peak, and the cosine phase starts immediately afterward.

  • Set the decay length to the real number of steps, counted after gradient accumulation, not per micro-batch.
  • When the batch size grows, the peak rate usually needs retuning, often upward, but only within the range where training stays stable.
  • Pair the schedule with gradient clipping when loss spikes appear near the peak rate.
  • Store the scheduler state in every checkpoint, so a resumed run continues on the same curve.

Common mistakes and limitations

The most frequent problem is a mismatch between the schedule and the actual run length. Because the curve is tied to a fixed horizon, stopping early leaves the model at a high rate, and extending the run beyond the horizon keeps it at the minimum.

SymptomLikely causeFix
Loss stops improving earlyDecay length too shortRecompute steps after accumulation
Final loss worse than expectedRun stopped before decay endedPlan the horizon or use a stable-decay schedule
Divergence in the first stepsMissing or too short warmupAdd warmup of 1% to 2% of steps
Resumed run jumps in lossScheduler state not restoredSave and load scheduler with optimizer
Symptoms, causes and fixes

A further limitation is that the schedule offers no adaptation to the observed loss. It follows the same curve whether training goes well or poorly, which is why teams still monitor validation loss and keep the option to adjust the plan.

Explained without jargon

Imagine parking a car. At first you drive at normal speed toward the space. As you get closer, you slow down more and more. In the last meter, you creep forward very gently.

A cosine schedule does the same for a learning model. It takes big steps early and small steps at the end. The slowdown follows a smooth curve instead of sudden jumps. This helps the model finish in a good, stable place instead of overshooting.

A typical use case

A research team pretrains a 1-billion-parameter language model on 200 billion tokens, which equals about 100,000 optimizer steps at their batch size. The optimizer is AdamW. The rate climbs to its 3e-4 peak during 2,000 warmup steps, then the team lets cosine annealing carry it across the remaining 98,000 steps toward a floor of 3e-5.

In an earlier trial with a constant learning rate, the validation loss flattened at around 2.9. With the cosine schedule, the loss continues to fall in the last third of training and ends noticeably lower. Because the team kept the minimum at 10% of the peak, they can later run continued pretraining on domain data without restarting from scratch.