Stochastic Gradient Descent › Learning Rate Schedules

Michael BrenndoerferApril 30, 20255 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 66Stochastic Gradient Descent › Learning Rate Schedules
Reading section 7 of 16 · Learning Rate Schedules · 5 minSection 7 of 16 · 5 min

Book contents

Section 7 of 16 · 5 min read

Stochastic Gradient Descent › Learning Rate SchedulesOne section · Sections in this chapter7 / 16 ↓
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

Training with a constant learning rate has a fundamental tension. Early in training, you want a large learning rate to explore parameter space and make rapid progress. Late in training, you want a small learning rate to converge precisely to a minimum without oscillating around it. A learning rate schedule resolves this tension by changing η\eta over the course of training.

This section covers the most important schedules. All of them modify the base learning rate η0\eta_0 over training steps or epochs.

Step Decay

Step decay reduces the learning rate by a fixed factor every kk epochs. If γ\gamma is the decay factor (typically 0.1 or 0.5) and ee is the current epoch:

ηe=η0⋅γ⌊e/k⌋\eta_e = \eta_0 \cdot \gamma^{\lfloor e / k \rfloor}

where:

  • ηe\eta_e: the learning rate at epoch ee
  • η0\eta_0: the initial learning rate
  • γ\gamma: the decay factor per drop, a value in (0,1)(0, 1) (typically 0.1 or 0.5)
  • kk: the number of epochs between drops
  • ⌊e/k⌋\lfloor e / k \rfloor: the number of drops so far (the floor of e/ke/k)

Step decay is simple and predictable. The loss usually decreases smoothly between drops and then jumps to a lower value immediately after each drop, as the optimizer can now make more precise adjustments in the current neighborhood.

The main drawback of step decay is that the sharp transitions can be undesirable. Hyperparameter tuning requires choosing both γ\gamma and kk, and the performance can be sensitive to these choices.

Exponential Decay

Instead of discrete drops, exponential decay reduces the learning rate continuously at every step:

ηt=η0⋅e−λt\eta_t = \eta_0 \cdot e^{-\lambda t}

where:

  • tt: the current training step
  • λ>0\lambda > 0: the decay rate, controlling how quickly the learning rate shrinks
  • e−λte^{-\lambda t}: the continuous decay factor, which approaches zero as tt increases

Exponential decay produces a smooth learning rate curve. However, if λ\lambda is too large, the learning rate decays too quickly and training stalls before convergence.

Cosine Annealing

Cosine annealing, introduced by Loshchilov and Hutter (2017) in their "SGDR" paper, is one of the most popular learning rate schedules for modern NLP. It smoothly decreases the learning rate from ηmax⁡\eta_{\max} to ηmin⁡\eta_{\min} following a cosine curve:

ηt=ηmin⁡+12(ηmax⁡−ηmin⁡)(1+cos⁡(πtT))\eta_t = \eta_{\min} + \frac{1}{2}\left(\eta_{\max} - \eta_{\min}\right)\left(1 + \cos\left(\frac{\pi t}{T}\right)\right)

where:

  • ηt\eta_t: the learning rate at step tt
  • ηmin⁡\eta_{\min}: the minimum learning rate (often 0 or a very small value like 1e-6)
  • ηmax⁡\eta_{\max}: the maximum learning rate (the "base" learning rate)
  • TT: the total number of training steps
  • cos⁡(πt/T)\cos(\pi t / T): the cosine term, which starts at 1 (giving ηmax⁡\eta_{\max}) and ends at −1-1 (giving ηmin⁡\eta_{\min}) over the interval [0,T][0, T]

At t=0t = 0, the cosine term is 1, so η0=ηmax⁡\eta_0 = \eta_{\max}. At t=Tt = T, the cosine term is −1-1, so ηT=ηmin⁡\eta_T = \eta_{\min}.

Cosine annealing has several attractive properties: it starts large, decays slowly at first, then accelerates, and finally decays slowly again near the end. This matches intuitions about optimization: you want large steps early on, more cautious steps in the middle, and very fine-tuning at the end.

The "SGDR" variant adds warm restarts: at the end of a cosine cycle, the learning rate jumps back to ηmax⁡\eta_{\max} and the cycle repeats, often with a longer period. This allows the optimizer to escape any local minimum it has settled into and explore other regions of parameter space.

Learning Rate Warmup

For large language models and transformers, training often begins with a warmup phase where the learning rate is linearly increased from 0 (or a tiny value) to the target learning rate over a number of steps TwarmupT_{\text{warmup}}:

ηt=ηmax⁡⋅tTwarmupfor t≤Twarmup\eta_t = \eta_{\max} \cdot \frac{t}{T_{\text{warmup}}} \quad \text{for } t \leq T_{\text{warmup}}

where:

  • TwarmupT_{\text{warmup}}: the number of warmup steps (typically a few hundred to a few thousand)
  • ηmax⁡\eta_{\max}: the target learning rate after warmup completes
  • t/Twarmupt / T_{\text{warmup}}: the linear ramp factor, going from 0 to 1

After warmup, the learning rate typically follows a decay schedule (cosine annealing is most common).

Why is warmup necessary? Early in training, the parameters are far from their optimal values. Gradients can be very large in magnitude, and starting with a large learning rate can cause catastrophic parameter updates that destabilize the entire network. By starting small and ramping up, warmup gives the network time to initialize into a reasonable part of parameter space before taking large steps.

In the original transformer (Vaswani et al., 2017), the following combined warmup-decay schedule was used:

ηt=dmodel−0.5⋅min⁡(t−0.5,  t⋅Twarmup−1.5)\eta_t = d_{\text{model}}^{-0.5} \cdot \min\left(t^{-0.5},\; t \cdot T_{\text{warmup}}^{-1.5}\right)

where:

  • dmodeld_{\text{model}}: the model dimension (e.g., 512 in the original transformer), which scales the overall learning rate to be smaller for larger models
  • t−0.5t^{-0.5}: the decay term active after warmup (polynomial decay)
  • t⋅Twarmup−1.5t \cdot T_{\text{warmup}}^{-1.5}: the warmup term active during the warmup phase
  • The min⁡\min selects the warmup term early in training and the decay term after

This formula automatically transitions from warmup to decay without requiring separate configuration of the phase boundary.

For most modern transformer training, the practical recommendation is: linear warmup for 1-5% of total training steps, followed by cosine annealing to ηmin⁡≈0\eta_{\min} \approx 0.