Warmup: define the ramp and what follows
学习率预热
Compare warmup endpoints and show why a gentle start cannot fix an unstable final learning rate.
warmupThe early updates can need a different scale
At initialization, features, gradients and optimizer statistics are still changing. Immediately applying the rate intended for later training can make the beginning fragile. Warmup schedules a smaller rate first and then reaches a target rate; it is a short initial phase, not a complete training schedule.
Goyal and colleagues, Section 2.2, describe gradual warmup for their large-minibatch ImageNet setup, reaching the target over five epochs. That duration and setting are not universal defaults. The PyTorch 2.8 LinearLR parameters illustrate why a ramp needs explicit start, end and duration conventions.
Choose whether the first rate is zero
Use a zero-based optimizer-update index t. Our positive-start ramp has W updates through the ramp, reaches η* on update W−1 and then holds it:
Its first rate is η*/W, not zero. The sum follows from the arithmetic series 1+…+W. Two alternatives make different promises: a zero-start ramp reaches the target on update W, while a constant warmup holds a low rate and then jumps:
The superscripts label zero-start and constant variants. These are our explicitly defined policies; they are not a claim to reproduce every LinearLR call sequence. A zero first rate makes the parameter update vanish for plain SGD, but optimizers such as Adam may still update their moment state if their step is executed.
Warmup cannot repair an unstable final rate
Consider f(θ)=2θ² with initial θ=1. Its gradient is 4θ:
Once warmup ends, the same constant multiplier repeats. For a nonzero state, a target rate strictly between zero and 1/2 contracts this quadratic; a rate above 1/2 makes the magnitude grow. A sufficiently gentle start can hide that problem for a while, but it cannot change the eventual multiplier.
With W=4 and η*=2/5, the first rates are 1/10,1/5,3/10,2/5, and θ₄=9/625. With η*=3/5, θ₄=−56/625 is initially small, yet every later step multiplies it by −7/5. This is an explicit counterexample to treating a successful warmup as a stability certificate.
Run the ramp and the phase after it
The complete Python 3.12 standard-library program uses exact fractions and records rates, positions and losses. Length zero means no warmup; length one in the positive-start policy immediately uses the target. The separate zero-start policy keeps its different endpoint convention visible.
from fractions import Fraction as F
def warm_rate(t,base=F(2,5),length=4,mode='linear'):
base=F(base)
if type(t) is not int or not 0<=t<=1000 or type(length) is not int or not 0<=length<=1000:raise ValueError('bounded nonnegative integer counters required')
if not 0<base<=1 or mode not in ('linear','constant','none','zero-start'):raise ValueError('valid base rate and mode required')
if length==0 or mode=='none':return base
if mode=='linear':return base*min(F(1),F(t+1,length))
if mode=='zero-start':return base*min(F(1),F(t,length))
return base/length if t<length else base
def fit(base=F(2,5),steps=12,mode='linear'):
if type(steps) is not int or not 0<=steps<=64:raise ValueError('bounded integer steps required')
theta=F(1);rows=[]
for t in range(steps):
rate=warm_rate(t,base,mode=mode);theta-=rate*4*theta
rows.append((rate,theta,2*theta*theta))
return rows
if __name__=='__main__':
for mode in ('linear','constant','zero-start','none'):
rows=fit(mode=mode);print(mode,'first five rates:',[str(r[0]) for r in rows[:5]],'12-step loss:',round(float(rows[-1][2]),9))
for base in (F(2,5),F(3,5)):
rows=fit(base);print('base',str(base),'position at updates 4 and 12:',str(rows[3][1]),round(float(rows[11][1]),9))
print('first four linear rates sum:',str(sum(warm_rate(t) for t in range(4))))
Actual output:
linear first five rates: ['1/10', '1/5', '3/10', '2/5', '2/5'] 12-step loss: 1.17e-07
constant first five rates: ['1/10', '1/10', '1/10', '1/10', '2/5'] 12-step loss: 9.477e-06
zero-start first five rates: ['0', '1/10', '1/5', '3/10', '2/5'] 12-step loss: 3.25e-07
none first five rates: ['2/5', '2/5', '2/5', '2/5', '2/5'] 12-step loss: 9.477e-06
base 2/5 position at updates 4 and 12: 9/625 0.000241865
base 3/5 position at updates 4 and 12: -56/625 -1.322306994
first four linear rates sum: 1
The large-target run looks controlled at the end of warmup and grows afterward. The stable-target comparisons show that ramp shape changes the finite-step path, but do not establish a universally best ramp. All examples optimize the same scalar objective; no ImageNet training is reproduced.
The schedule costs O(1) arithmetic per call. In a real experiment, record duration in the chosen unit, target rate, starting factor, the first and last applied warmup rates, and the policy that follows warmup.
Do not confuse warmup with a restart
Warmup increases the rate at the start of a phase. A cosine restart increases the rate again later while ordinarily retaining learned weights. Resetting model weights, resetting optimizer moments and advancing the scheduler are separate operations.
Large-batch linear rate scaling is an approximation under specific training conditions, not a reason to multiply rates without limit. Warmup duration may depend on architecture, initialization, normalization, batch size and optimizer. Some runs do not need it, and a long low-rate phase can waste a fixed training budget.
The transition to a later decay schedule needs an explicit boundary: does the decay count from training start or from the end of warmup? Avoid accidentally multiplying two ramps or stepping one scheduler per microbatch and the other per optimizer update. Plot the actual applied rates before launching a long experiment.
Check the handoff
- With W=4 and target 0.4, what is the first positive-start rate?
Answer 1: 0.1.
- When does the zero-start variant first reach its target?
Answer 2: At index W, one update later than the positive-start convention.
- Does the small θ₄ at target 0.6 prove later stability?
Answer 3: No. Subsequent magnitude grows by a factor 1.4 per step in this example.
- Does a zero learning rate necessarily freeze Adam’s state?
Answer 4: No. The parameter may stay fixed while moments and counters still update.
Treat the ramp as an explicit policy
The large-batch paper motivates gradual warmup in its experimental setting; the fixed API shows the need for endpoint definitions. Our policies, sums and unstable-final-rate counterexample are original. Continue with learning-rate schedules, Adam and cosine annealing.
Make a prediction, then check
Can warmup make an unstable eventual constant rate stable in the shown nonzero quadratic trajectory?
Learning objectives
- Distinguish positive-start and zero-start endpoints.
- Analyze stability after warmup ends.
Prerequisites & connections
Explore related knowledge →References
- Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour — arXiv1706.02677v1
Priya Goyal; Piotr Dollár; Ross Girshick; Pieter Noordhuis; Lukasz Wesolowski; Aapo Kyrola; Andrew Tulloch; Yangqing Jia; Kaiming He · 2017 - lr_scheduler.LinearLR — 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:
- Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour — arXiv1706.02677v1 · Fixedv1 physical3 Section2.2: constant versus gradual warmup, five-epoch large-batch setup; not a universal duration or rate-scaling theorem.
- lr_scheduler.LinearLR — PyTorch 2.8 · Fixed2.8 LinearLR start_factor/end_factor/total_iters definitions read; our applied-update endpoints are explicitly separate, not a copied API example.
Related topics