Cyclical rates: how many updates make a cycle?
循环学习率
Compute asymmetric triangular schedules, amplitude decay and a full-cycle contraction despite transient growth.
cyclical-learning-ratesA cycle has an upward leg and a downward leg
A learning rate need not decrease throughout training. A cyclical policy repeatedly raises and lowers it inside specified bounds. The important practical details are the period, the two leg lengths, the amplitude rule and the event that advances the clock.
Leslie Smith’s paper, Section 3, describes triangular policies and a learning-rate range test. The fixed PyTorch 2.8 CyclicLR interface allows different rising and falling lengths and an optional momentum cycle. We implement the rate sequence and plain-gradient updates, with no momentum cycling.
Half a cycle is only half when the legs match
Let U and D be positive integer counts for the upward and downward legs. For a zero-based update index t:
q counts completed cycles and u is the position within a cycle. The period is U+D, not necessarily 2U. The triangular shape and two amplitude choices are:
Use a=1 for triangular, and a=2⁻ᑫ for triangular2. The latter halves the distance above the lower bound after each completed cycle; it does not halve the lower bound. At t=U the first peak is reached, and at t=C the next cycle starts at the lower bound.
With U=2, D=3, lower rate 1/10 and upper rate 4/5, the first cycle applies 1/10,9/20,4/5,17/30,1/3. The rate at t=5 is 1/10 and belongs to the next cycle. Plotting both endpoints gives six samples around a five-update cycle; that does not make the period six.
A temporarily expanding step can belong to a contracting cycle
The program optimizes f(θ)=2θ². Each step multiplies θ by 1−4η. For a repeating triangular schedule, the whole-cycle multiplier is fixed:
The peak rate 4/5 has multiplier −11/5, which expands magnitude if repeatedly held constant. Yet the complete five-step product has magnitude below one. Thus this particular fixed scalar quadratic contracts at cycle endpoints while its loss can rise within a cycle. This calculation is not a general explanation or guarantee for neural-network training.
For triangular 2 the amplitude changes each cycle, so the same constant product cannot be raised to k. Compute each cycle’s factors separately. The first three peaks in our example are 4/5,9/20,11/40, approaching the unchanged lower bound.
Run complete cycles instead of judging one peak
The complete Python 3.12 standard-library program uses rational arithmetic, unequal leg lengths and two amplitude policies. It prints the actually applied rates and optimizes the same quadratic under each policy.
from fractions import Fraction as F
def rate_at(t,up=2,down=3,low=F(1,10),high=F(4,5),mode='triangular'):
low,high=F(low),F(high)
if type(t) is not int or not 0<=t<=10000 or any(type(v) is not int or not 1<=v<=1000 for v in (up,down)):raise ValueError('bounded integer clock and positive phase lengths required')
if not 0<=low<=high<=1 or mode not in ('triangular','triangular2'):raise ValueError('ordered rates and supported mode required')
cycle,phase=divmod(t,up+down)
shape=F(phase,up) if phase<=up else 1-F(phase-up,down)
amplitude=F(1) if mode=='triangular' else F(1,2**cycle)
return low+(high-low)*amplitude*shape
def train(steps=10,mode='triangular',theta=F(1),start=0):
if type(steps) is not int or not 0<=steps<=64:raise ValueError('bounded integer step count required')
theta=F(theta);rows=[]
for t in range(start,start+steps):
rate=rate_at(t,mode=mode);theta-=4*rate*theta;rows.append((rate,theta,2*theta*theta))
return rows
if __name__=='__main__':
for mode in ('triangular','triangular2'):
rows=train(mode=mode)
print(mode,'rates:',[str(r[0]) for r in rows])
print('five / ten-step position:',str(rows[4][1]),str(rows[9][1]))
print('largest loss in first cycle:',str(max(r[2] for r in rows[:5])))
print('first three triangular2 peaks:',[str(rate_at(t,mode='triangular2')) for t in (2,7,12)])
print('zero start stays zero:',all(r[1]==0 for r in train(theta=0)))
Actual output:
triangular rates: ['1/10', '9/20', '4/5', '17/30', '1/3', '1/10', '9/20', '4/5', '17/30', '1/3']
five / ten-step position: 836/1875 698896/3515625
largest loss in first cycle: 1397792/390625
triangular2 rates: ['1/10', '9/20', '4/5', '17/30', '1/3', '1/10', '11/40', '9/20', '1/3', '13/60']
five / ten-step position: 836/1875 -3344/3515625
largest loss in first cycle: 1397792/390625
first three triangular2 peaks: ['4/5', '9/20', '11/40']
zero start stays zero: True
The first cycle can exceed the initial loss of two before returning to a smaller endpoint. The two policies share that first cycle, then take different paths as triangular 2 reduces its amplitude. Neither result selects a universal winner.
The final zero-initialization check is deliberate: at the exact minimum the gradient is zero, so even rates that would amplify a perturbation leave this trajectory unchanged. A flat range-test loss therefore cannot by itself establish stability around the solution. The phase calculation uses O(1) arithmetic, apart from exact fraction bit cost; the optimizer still determines gradient cost and state requirements.
A range test is a diagnostic run, not independent trials
Smith’s range test raises the rate during a short run to help select plausible bounds. Later measurements inherit weights from earlier rates, so they are not separate experiments started from identical initialization. Use the trace as a diagnostic, then validate chosen bounds under the full training protocol.
The cited API advances after each trained batch and can cycle momentum inversely to the learning rate. With gradient accumulation, decide whether “batch” means a microbatch or an optimizer update in your own integration. A rate-only reproduction must disable or separately account for momentum cycling.
Our program implements triangular and triangular 2 only. Other scaling rules, unequal per-group bounds and changing cycle lengths need their own definitions. Cycles do not eliminate hyperparameter selection, repair leakage or guarantee escape from a stationary point. Compare complete budgets and state the checkpoint-selection rule.
Count phases and separate local from cycle behavior
- What is the period when U=2 and D=3?
Answer 1: Five updates.
- What does triangular 2 halve?
Answer 2: The amplitude above the fixed lower bound, once per completed cycle.
- Does an expanding peak step prove this entire cycle diverges?
Answer 3: No. The exact whole-cycle multiplier is 836/1875 in the example.
- Does zero loss during a range test prove a large rate is stable to perturbations?
Answer 4: No. A trajectory exactly at the minimum can stay fixed even when nearby errors would grow.
Publish the rate trace with the result
The paper supplies the cyclic idea and range-test motivation; the fixed API documents phase lengths, amplitude policies and optional momentum cycling. Our asymmetric rational cycles, contraction product and stationary-point caution are original. Continue with cosine annealing and learning-rate schedules.
Make a prediction, then check
For unequal upward and downward lengths, what is the full period?
Learning objectives
- Compute asymmetric phases without off-by-one errors.
- Distinguish a peak update from a cycle endpoint.
Prerequisites & connections
Explore related knowledge →References
- Cyclical Learning Rates for Training Neural Networks — arXiv1506.01186v6
Leslie N. Smith · 2017 - lr_scheduler.CyclicLR — PyTorch 2.8
PyTorch contributors
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source scope, explicit assumptions, original calculations and counterexamples, runnable tests and bilingual review; not independent human or second-agent review.
- Single-agent authored technical review: bounded primary-source locations, assumptions, original derivations, exact/literal references and matching bilingual equations/examples/exercises. Not independent human or second-agent review.
- Four focused CPython3.12.4 tests passed per chapter. Adaptive accumulators and moments, coefficient/update ordering, checkpoint continuation and schedule boundaries are checked against expanded histories, exact products, literal values and known stability cases. Adagrad/Adam/AdamW use NumPy1.26.4; the other five use the standard library.
- Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
- Bilingual charts generated with Matplotlib3.9.1 from the executed schedule functions; plotted values may extend past the printed run and are explicitly labeled as schedule samples. Both SVGs and source samples are hash-bound.
Source locations checked:
- Cyclical Learning Rates for Training Neural Networks — arXiv1506.01186v6 · Fixedv6 physical2–3 Sections3.1–3.3: triangular shape, half-cycle stepsize, triangular2 and range-test motivation; empirical recommendations not generalized.
- lr_scheduler.CyclicLR — PyTorch 2.8 · Fixed2.8 CyclicLR definition: step_size_up/down, triangular/triangular2, after-batch calls and inverse cycle_momentum option.
Related topics