Search

Search papers and lessons

Cyclical Learning Rate

Level 3 · 10 min read

A cyclical learning rate moves the step size up and down between two bounds on a fixed triangle wave, instead of only decreasing it, and it often trains a network in fewer steps.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Optimizers
  • Linear algebra
  • Losses & regularization
  • ReadReady to readNot yet

TL;DR

A cyclical learning rate changes the step size of training on a repeating triangle: it climbs from a low value to a high value, falls back, and repeats, instead of only shrinking over time. Leslie Smith proposed it in 2015 as a simple way to pick and move the learning rate, and in his experiments networks often reached good accuracy in fewer steps than with a fixed rate.

Builds on: Stochastic Gradient Descent, Learning Rate · Leads to: SGD with warm restarts, SGDR

Where it's used

Image classifiers. Smith's experiments trained standard convolutional networks to label photos in CIFAR-10, a common benchmark of small labelled images, with a triangle wave between two bounds. He reported that the cyclical schedule reached accuracy comparable to a carefully tuned fixed rate, in fewer training iterations.

Fast training budgets. When a team can afford only a few epochs, a short cycle lets it see the high-rate and low-rate phases several times in one run, without a separate search for a decay schedule.

Warm restarts. Later work by Loshchilov and Hutter, in SGDR, used the same idea with a smooth cosine curve, restarting the rate at its high value on purpose so the model can settle into a new region after each restart.

How it works

Take a tiny training run with 9 steps. Set the lowest rate to 0.001 and the highest to 0.01. Let one half-cycle last 2 steps, so the full cycle is 4 steps long.

  1. Start at the floor. At step 0 the rate is the lowest value, 0.001. Check: it equals the lower bound.
  2. Climb halfway. Each step moves a fixed fraction of the way from the lower bound to the upper bound. Over the first half-cycle of 2 steps, the rate covers the full gap of 0.009 in 2 steps, so each step adds 0.0045. At step 1 the rate is 0.001 + 0.0045 = 0.0055. Check: it sits halfway between the bounds.
  3. Reach the peak. At step 2 the rate is 0.001 + 0.009 = 0.01. Check: it equals the upper bound.
  4. Fall back. Over the next 2 steps the rate comes down by 0.0045 each step. At step 3 it is 0.0055, and at step 4 it is back to 0.001. Check: the cycle has returned to the floor.
  5. Repeat. Steps 5 to 8 repeat steps 1 to 4. The rate at step 5 is 0.0055, at step 6 it is 0.01, at step 7 it is 0.0055, and at step 8 it is 0.001.

The rate never stays put. It keeps cycling between the same two values while the loss goes down overall, because each mini-batch update uses the current rate.

01234567800.0020.0040.0060.0080.010.012training steplearning rate
  • cyclical rate
The rate climbs from 0.001 to 0.01 over 2 steps, falls back over 2 steps, and repeats. The dots mark the floors and peaks.

The math

Definition: Triangular cyclical learning rate

Let ηmin⁡\eta_{\min} be the lower bound, ηmax⁡\eta_{\max} the upper bound, and ss the half-cycle length in steps. The rate at step tt is

ηt=ηmin⁡+(ηmax⁡−ηmin⁡)max⁡ ⁣(0,  1−xt),xt=∣ts−2⌊1+t2s⌋+1∣.\eta_t = \eta_{\min} + (\eta_{\max} - \eta_{\min}) \max\!\left(0,\; 1 - x_t\right), \qquad x_t = \left|\frac{t}{s} - 2\left\lfloor 1 + \frac{t}{2s} \right\rfloor + 1\right|.

Here ⌊⋅⌋\lfloor \cdot \rfloor rounds down, so the rate is a triangle wave in tt with period 2s2s.

Step 2 in symbols: the linear climb

Within the first half-cycle, 0≤t≤s0 \le t \le s, the floor ⌊1+t/(2s)⌋\lfloor 1 + t/(2s) \rfloor is 1, so xt=∣t/s−1∣x_t = |t/s - 1|. For t≤st \le s that gives xt=1−t/sx_t = 1 - t/s, and

ηt=ηmin⁡+(ηmax⁡−ηmin⁡) ts.\eta_t = \eta_{\min} + (\eta_{\max} - \eta_{\min})\, \frac{t}{s}.

The rate rises in a straight line from ηmin⁡\eta_{\min} at t=0t=0 to ηmax⁡\eta_{\max} at t=st=s. With ηmin⁡=0.001\eta_{\min}=0.001, ηmax⁡=0.01\eta_{\max}=0.01, s=2s=2, at t=1t=1 this gives 0.001+0.009⋅1/2=0.00550.001 + 0.009 \cdot 1/2 = 0.0055, matching step 2 above.

Step 4 in symbols: the fall

In the second half-cycle, s≤t<2ss \le t < 2s, the floor ⌊1+t/(2s)⌋\lfloor 1 + t/(2s) \rfloor is still 1, so xt=∣t/s−1∣=t/s−1x_t = |t/s - 1| = t/s - 1, which is non-negative here. Then

ηt=ηmin⁡+(ηmax⁡−ηmin⁡)(1−(ts−1))=ηmax⁡−(ηmax⁡−ηmin⁡) t−ss.\eta_t = \eta_{\min} + (\eta_{\max} - \eta_{\min})\left(1 - \left(\tfrac{t}{s} - 1\right)\right) = \eta_{\max} - (\eta_{\max} - \eta_{\min})\,\frac{t - s}{s}.

At t=3t=3 this is 0.01−0.009⋅1/2=0.00550.01 - 0.009 \cdot 1/2 = 0.0055. At t=4t=4 the rate reaches the floor, η4=0.001\eta_4 = 0.001, and the next climb begins.

Step 5 in symbols: periodicity

The function has period 2s2s, so ηt+2s=ηt\eta_{t+2s} = \eta_t. For the example, η5=η1=0.0055\eta_5 = \eta_1 = 0.0055, η6=η2=0.01\eta_6 = \eta_2 = 0.01, and so on.

00.511.522.533.5400.0020.0040.0060.0080.010.012training step trate
  • one full period
One period of the triangle wave. The same shape repeats for every later block of 4 steps.

Worked examples

Example
Example 1: the 9-step run
  1. Lower bound 0.001, upper bound 0.01, half-cycle s=2s=2.
  2. At t=0t=0: x0=∣0−2⋅1+1∣=1x_0 = |0 - 2 \cdot 1 + 1| = 1, so η0=0.001+0.009⋅0=0.001\eta_0 = 0.001 + 0.009 \cdot 0 = 0.001.
  3. At t=2t=2: ⌊1+2/4⌋=⌊1.5⌋=1\lfloor 1 + 2/4 \rfloor = \lfloor 1.5 \rfloor = 1, so x2=∣2/2−2⋅1+1∣=∣1−2+1∣=0x_2 = |2/2 - 2 \cdot 1 + 1| = |1 - 2 + 1| = 0, and η2=0.001+0.009⋅1=0.01\eta_2 = 0.001 + 0.009 \cdot 1 = 0.01.
  4. At t=4t=4: ⌊1+4/4⌋=2\lfloor 1 + 4/4 \rfloor = 2, so x4=∣4/2−4+1∣=∣2−4+1∣=1x_4 = |4/2 - 4 + 1| = |2 - 4 + 1| = 1, and η4=0.001\eta_4 = 0.001.
  5. Interpretation: the rate returns to the floor at every multiple of the period 4 and peaks halfway between.

Try it: find η6\eta_6 from the formula. Answer: ⌊1+6/4⌋=⌊2.5⌋=2\lfloor 1 + 6/4 \rfloor = \lfloor 2.5 \rfloor = 2, so x6=∣6/2−4+1∣=∣3−4+1∣=0x_6 = |6/2 - 4 + 1| = |3 - 4 + 1| = 0 and η6=0.01\eta_6 = 0.01.

Example
Example 2: a standard cycle

Set the bounds to 0.01 and 0.1 and the half-cycle to s=50s = 50 steps, so the full cycle is 100 steps.

  1. At t=0t=0 the rate is the floor, 0.01.
  2. At t=25t=25 (halfway up the climb) the rate is 0.01+(0.1−0.01)⋅25/50=0.01+0.045=0.0550.01 + (0.1 - 0.01) \cdot 25/50 = 0.01 + 0.045 = 0.055.
  3. At t=50t=50 the rate is the peak, 0.1.
  4. At t=75t=75 the rate has come halfway back down, 0.1−0.09⋅25/50=0.0550.1 - 0.09 \cdot 25/50 = 0.055.
  5. At t=100t=100 it is back to 0.01, and the next cycle begins.
  6. Interpretation: over one 100-step block the rate spends equal time in the lower and upper half of its range, so the average rate over a full cycle is 0.055.

Try it: what is the rate at t=130t=130? Answer: 130130 is 30 steps into the second cycle, so it is on the climb at 0.01+0.09⋅30/50=0.01+0.054=0.0640.01 + 0.09 \cdot 30/50 = 0.01 + 0.054 = 0.064.

Example
Example 3: a realistic image-classifier run

Train an image classifier on 50000 training images with a batch size of 128, meaning each update uses 128 images. One epoch is a full pass over all 50000 images, which takes ⌈50000/128⌉=391\lceil 50000 / 128 \rceil = 391 steps. Pick a half-cycle of 2 epochs, so s=782s = 782 steps.

  1. The full cycle is 2s=15642s = 1564 steps, which is 4 epochs.
  2. Over a 10-epoch run there are 10⋅391=391010 \cdot 391 = 3910 steps.
  3. Number of full cycles: 3910/1564=2.53910 / 1564 = 2.5. The run ends two full cycles plus 782782 steps into the third, which is exactly half a cycle, so the rate is at its peak.
  4. Suppose the bounds come from a short sweep: raise the rate over one cycle and note the rates where the loss falls fastest and where it starts to rise. Use those as the lower and upper bounds.
  5. Interpretation: the run ends at a learning rate near its peak, which is a poor place to stop. Choosing a total length that is a whole number of cycles makes the last rate return to the floor.

Try it: with the same settings, how many epochs should the run last to end exactly at a floor? Answer: the run must cover a whole number of 4-epoch cycles, so 4, 8 or 12 epochs. The shortest, 4 epochs, ends at a floor.

Common mistakes and tradeoffs

It is tempting to think a learning rate should only go down, because lowering it helps the final fit. In fact a high rate helps the search escape flat regions and poor spots, which is why Smith's schedule goes back up. The decay happens within each cycle, and the peaks are the exploration.

It is tempting to think a cyclical schedule needs no tuning. In fact the two bounds still matter. Smith suggested a short sweep that raises the rate slowly and watches the loss, then uses the rates where the loss falls fastest and where it starts to rise. This is a cheap search, but it is still a search.

It is tempting to think the cycle must always be long. In fact a short cycle gives more chances to pass through good rates, but it can also keep the rate high at the end of training. Stop the run at a floor, or add a final decay.

Use a cyclical rate when you want a fast run with little tuning, or when you suspect a fixed rate is stuck. Do not use it when a single well-chosen decay, such as Cosine Annealing alone, already works, or when training must end at a precise final value without a final decay. Warmup is often combined with a cyclical rate to start gently before the first peak. Adaptive methods such as Adam scale each parameter's step themselves, but they still take a base rate, and that base rate can follow a cycle too.

History

For most of the early deep learning era, practitioners picked one fixed learning rate and lowered it by hand when the loss stopped improving. Smith's 2015 arXiv preprint argued that this was a poor use of time, and that a simple triangle wave between two bounds was just as good and far cheaper to set up. The idea spread quickly among practitioners, partly because it needed no extra parameters beyond the bounds and the cycle length. Loshchilov and Hutter's SGDR, published in 2016, took the same spirit and used smooth cosine curves with warm restarts, which became a common alternative.

Recap

  • Stochastic Gradient Descent, a version of gradient descent, takes steps whose size is the Learning Rate.
  • A cyclical learning rate sets that size on a triangle wave between a lower and an upper bound.
  • The wave has a half-cycle length ss, so its period is 2s2s. The formula is linear on each half.
  • The high rates act as exploration and the low rates as settling, and the cycle repeats.
  • Choose the bounds with a short sweep, and end the run at a floor or add a final decay.

What to read next: SGD with warm restarts, which replaces the triangle with a smooth cosine, and SGDR for its original statement.

Check yourself

QuestionRecall: what shape does the learning rate follow under a triangular cyclical schedule?Show answer

A triangle wave. It rises linearly from the lower bound to the upper bound over one half-cycle, falls linearly back to the lower bound over the next half-cycle, and then repeats.

QuestionCompute: the lower bound is 0.002, the upper bound is 0.02, and the half-cycle is 3 steps. What is the rate at step 1?Show answer

The rate climbs linearly over the first half-cycle, so at step 1 it is 0.002+(0.02−0.002)⋅1/3=0.002+0.006=0.0080.002 + (0.02 - 0.002) \cdot 1/3 = 0.002 + 0.006 = 0.008.

QuestionWhy: why would a schedule that raises the rate again help, when lowering it steadily seems more natural?Show answer

A higher rate lets the parameters take larger steps, which helps them move out of flat regions and poor spots that a small rate would stay in. The lower phases then let the parameters settle. Repeating the cycle combines the two, where a steady decay commits to a region early.

QuestionApplied: a team trains for 10 epochs with a cycle of 4 epochs. Their run ends at the peak of the third cycle. What should they change?Show answer

They should end at a floor, so the final rate is low. They could train for 8 epochs, which ends exactly at a floor after two full cycles, or add a short final decay so the last steps use a low rate.

Sources