Cosine Learning Rate Schedule › The Cosine Decay Formula
Language AI HandbookAll chapters Cosine Learning Rate Schedule › The Cosine Decay FormulaOne section · Sections in this chapter4 / 14 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The cosine schedule derives its shape from the cosine function, which decreases smoothly from 1 to over a half-period. By remapping this interval to span from the initial learning rate down to a minimum value, we get a decay profile that is gentle near the boundaries and steeper in the middle.
Cosine annealing refers to any learning rate schedule that uses the cosine function to interpolate between a maximum and minimum value. The term "annealing" comes from the metallurgical process of slowly cooling a material to reduce defects, analogizing the cooling of the learning rate to stabilize model parameters.
Basic Cosine Decay
We want a function that starts at when and ends at when , following a smooth cosine curve in between. The standard cosine decay formula achieves this as follows:
where:
- : the learning rate at step
- : the peak learning rate at the start of the schedule (after any warmup period)
- : the floor learning rate, often set to 0 or a small fraction of such as
- : the current step index, ranging from 0 to
- : the total number of decay steps
- : the cosine term that drives the smooth interpolation from 1 (at ) to (at )
The expression is sometimes called the "raised cosine" because it shifts and scales the cosine from its natural range up into the range . Multiplying by stretches this unit interval to the desired learning rate range, and adding lifts the floor.
To see why this particular construction works, think of it as a two-step transformation. The raw cosine takes values in : it equals at , passes through at , and reaches at . We want a multiplier that goes from 1 to 0 (not from 1 to ), so we add 1 and divide by 2 to get . This quantity ranges from 1 down to 0. Multiplying by scales that unit range to match the desired learning rate range, and adding ensures we never go below the floor.
Verification at boundary values. Let us confirm the formula produces the right values at and :
At :
At :
The schedule begins at and ends exactly at , as intended. At the midpoint , the cosine evaluates to , giving a learning rate of exactly the average .
The Decay Rate at Each Phase
One of the most instructive ways to understand the cosine schedule is to look at the derivative of with respect to . The derivative tells us how fast the learning rate is falling at each step:
The sine function starts at zero, rises to its maximum at , and falls back to zero at . This means the learning rate is decreasing most rapidly at the midpoint of training, and barely changing at all at the very beginning and very end. Compare this with linear decay, where the derivative is a constant at every step: the rate of decrease is the same regardless of how far along training has progressed.
This derivative structure is exactly what we want. At the start of training, gradients are large and noisy, and a slowly-changing learning rate gives the optimizer time to orient itself without the additional disruption of a rapidly shifting step size. Near the end of training, the learning rate itself is already very small, and a nearly flat derivative means the optimizer is making barely-perceptible adjustments to the rate, allowing for very fine-grained convergence. The middle phase, where the learning rate is most actively shrinking, corresponds to the period when the optimizer is making the transition from broad exploration to local refinement.
Why Smooth Decay Matters
Step decay schedules drop the learning rate by a fixed factor at discrete checkpoints. This creates a jarring discontinuity each time the rate drops: the optimizer is cruising along at one scale and suddenly the effective step size contracts by an order of magnitude. In practice, these drops often coincide with sudden sharp decreases in training loss followed by a plateau at the new rate. While this works, it makes scheduling sensitive to the choice of when to drop.
After each step-decay drop, the loss tends to spike briefly as the optimizer adjusts to the new scale, then quickly drops to a lower floor than before. This "shock and reset" behavior works, but it suggests the model is doing a kind of forced convergence at each checkpoint rather than settling smoothly. The timing of drops has to be chosen carefully: too early and the model has not finished benefiting from the higher rate; too late and it has been oscillating around a minimum without making progress.
Linear decay, covered in the Learning Rate Decay chapter, avoids this problem with a straight-line decrease. However, linear decay is fastest right at the start, when the model may still be in a phase where slightly larger steps would help exploration, and it decreases at a uniform rate that ignores the characteristic phases of learning.
Cosine decay allocates decay budget differently. The rate decreases slowly at first, giving the model time to make larger initial progress. It decelerates more rapidly through the middle of training when parameters are converging broadly. Near the end, the rate again slows its descent, allowing the model to settle delicately into a local minimum without overshooting. This pacing matches the natural phases of gradient descent quite well.
There is also a practical advantage: cosine decay requires no manual checkpoint selection. With step decay, you choose specific milestones, and if they are wrong for your architecture, problem, or batch size, performance suffers. The cosine schedule adapts its budget continuously and automatically based solely on the current step fraction .

The Raised Cosine: A Worked Numerical Example
To make the formula concrete, let us trace through the exact values at several checkpoints for a schedule with , , and steps. These values are typical for training a medium-sized language model with AdamW.
At : , so . This is the peak, as expected.
At (25% through training): . So:
The learning rate has decayed from to approximately , a reduction of only about 13% despite being 25% through training. This is the "slow start" effect at work.
At (midpoint): , so . This is exactly the midpoint between and .
At (75% through training): . So:
By 75% of training, the learning rate has fallen to about , already very close to the minimum of . The remaining 25% of training will use a very small, slowly-changing learning rate, which is ideal for final refinement.
At : , so .
This worked example illustrates the curve's pacing clearly: the cosine schedule changes slowly near its peak, drops most rapidly around the midpoint, and slows again near the floor. A linear schedule also reaches the midpoint value of at step 500, but it reaches at about step 148 rather than step 250. Cosine therefore spends roughly 70% more steps above in this example; both schedules still spend half of training above the midpoint value.