Learning rate warmup

Also known as: warmup steps

On this page 7

Learning rate warmup is a training technique in which the learning rate starts at a small value and rises gradually to its target over the first few hundred or thousand optimization steps, before the main schedule takes over. In artificial intelligence, and especially in the training of transformers and large language models, warmup is a standard safeguard against early divergence and loss spikes.

The number of steps spent in this phase is called the warmup steps or warmup period. Warmup is not a separate optimizer but the first segment of a learning rate schedule: a typical schedule combines a linear warmup with a cosine or linear decay. Its purpose is narrow but important, which is to give the optimizer and the network time to reach a well-conditioned state before full-size updates begin.

Why training needs a warmup phase

Warmup is needed because the first updates of a freshly initialized network are the most dangerous. At initialization, gradients can be large and poorly scaled, the loss surface is often sharply curved, and a full learning rate can push weights into a region from which training never recovers. The symptom is a loss that jumps to very large values or becomes NaN within the first steps.

Adaptive optimizers add a second reason. Adam and AdamW estimate the second moment of gradients with an exponential moving average, and in the first steps that estimate rests on very few samples. Bias correction helps, but the variance of the adaptive step size remains high early on. Warmup keeps the effective step small until the moment estimates become reliable, a point formalized in the analysis behind the RAdam optimizer.

A third reason concerns architecture. In Post-LN transformers, where layer normalization follows the residual connection, gradients near the output are large at initialization, and training without warmup frequently fails. Pre-LN transformers are more tolerant, yet most large-scale recipes still use warmup because it is cheap insurance.

Warmup shapes and key parameters

Warmup is defined by its shape, its length and its starting value. The linear form is by far the most common: the learning rate grows in equal increments from near zero to the peak value. Other shapes exist, but in practice the length of warmup matters more than its exact curve.

ShapeHow the rate growsTypical use
Linear warmupEqual increments to the peakTransformers, language models, most recipes
Exponential warmupMultiplies by a constant factor per stepSome vision and older recurrent models
Constant warmupFixed low rate, then a jump to the peakEarly ResNet training at large batch sizes
Gradual warmup per epochIncrease spread over the first few epochsLarge-batch image classification
Common warmup shapes

The parameters below define a warmup phase in most training frameworks. Values are typical ranges rather than rules, and they depend on model size, batch size and optimizer.

ParameterTypical rangeWhat it affects
Warmup stepsAbout 1 to 10 percent of total stepsStability of the early phase
Absolute warmup lengthHundreds to a few thousand stepsTime before full-size updates
Initial learning rateZero or a small fraction of the peakSize of the very first updates
Peak learning rateSet by the main scheduleSpeed of learning after warmup
Following decayCosine, linear or constantBehavior for the rest of training
Key warmup parameters

Warmup is one of several tools that control the size of early updates, and it is often confused with them. Each technique addresses a different failure mode, so mature recipes usually combine several rather than choosing one.

TechniqueWhat it controlsRelation to warmup
Learning rate warmupStep size at the start of trainingReference technique
Gradient clippingNorm of each gradient updateComplements warmup by capping outliers
Cosine learning rate scheduleStep size during decayUsually follows the warmup phase
Weight decayGrowth of weight magnitudesIndependent regularization
RAdam optimizerVariance of adaptive stepsBuilt-in alternative to explicit warmup
Warmup and neighboring stabilization techniques

The most important distinction is between warmup and gradient clipping. Clipping limits individual extreme updates at any point in training, while warmup limits all updates during a defined early window. A run that still shows loss spikes after warmup ends typically needs clipping, a lower peak rate or data fixes, not a longer warmup.

Setting warmup in practice

Practitioners usually set warmup relative to the total training length and the batch size. Larger batches permit higher peak learning rates, and higher peak rates generally need longer warmup. In fine-tuning, where the model starts from a well-trained checkpoint, warmup is shorter and sometimes omitted, although a brief warmup still protects pretrained weights from an abrupt first update.

  • Pretraining from scratch: linear warmup over roughly 0.5 to 2 percent of steps, often a few thousand steps.
  • Supervised fine-tuning: short warmup of about 3 to 10 percent of a small total step count.
  • Large-batch training: warmup scaled with batch size, combined with the linear scaling rule for the peak rate.
  • Resuming from a checkpoint: a short re-warmup if optimizer state was lost or the data mixture changed.

A useful diagnostic is to plot the loss and gradient norm against the learning rate during the first few thousand steps. Instability that appears exactly when the rate reaches its peak points to a peak that is too high; instability in the first dozen steps points to warmup that is too short or an initialization problem.

Limitations and common mistakes

Warmup cannot rescue a fundamentally unstable configuration. A peak learning rate far above what the model tolerates will still diverge, only later. The table below lists frequent problems and their usual causes.

SymptomLikely causeTypical fix
Loss becomes NaN in early stepsWarmup too short or missingLengthen warmup, check initialization
Loss spikes right after warmupPeak rate too highLower the peak, add gradient clipping
Slow early progressWarmup far too longShorten warmup to a small share of steps
Instability after a resumed runOptimizer state resetRestore state or add a short re-warmup
Warmup symptoms and fixes

Another mistake is counting warmup in epochs on very large datasets, which can turn a sensible setting into tens of thousands of wasted steps. Defining warmup in optimizer steps keeps it comparable across runs and hardware.

In everyday language

Think of a heavy truck leaving a parking lot. The driver does not press the pedal to the floor at once. The truck speeds up gently first. Once it is moving smoothly, it can drive at full speed.

Learning rate warmup does the same for a neural network. At the start, the network knows nothing. Big changes could throw it off course. So training takes small steps at first and grows them over time. The takeaway is simple: a gentle start makes the whole training run safer.

Seen in the real world

A research team pretrains a 1.3-billion-parameter language model for 200,000 optimization steps with AdamW and a peak learning rate of 3e-4. In a first attempt without warmup, the loss jumps to NaN after about forty steps, and two restarts with different random seeds fail the same way.

The team adds linear warmup over 2,000 steps, roughly 1 percent of the run, followed by cosine decay to one tenth of the peak, together with gradient clipping at a norm of 1.0. The loss now falls smoothly through the warmup phase and the run completes without divergence. Because a failed restart on their cluster costs several hours of compute, the change saves far more time than the short warmup costs.