Learning rates, warmup, and batch size
Here is a frustrating fact about the cosine schedule. To use it you must decide, before step one, exactly how long the run will be, because the curve's shape depends on its end point. If you later find you have budget for 20 percent more tokens, you cannot just keep going. The learning rate is already near its floor, and stretching the curve after the fact means restarting. Chinchilla's authors found the length matters, too. Setting the cosine cycle much longer than the actual run made the final loss noticeably worse (Hoffmann et al. 2022), which means every point on a scaling-law plot needed its own run from scratch.
This section is about the three numbers that set the pace of training, the learning rate, how it changes over time, and the batch size, and about the theory that tells us how they should relate. We will derive warmup length from Adam's second-moment estimate, see why the loss falls sharply when the learning rate decays, meet the warmup-stable-decay schedule that removes the fixed-length problem, and derive the critical batch size, beyond which more GPUs stop buying speed.
Throughout, is the learning rate at step , its peak, the total number of steps, the batch size, Adam's second-moment decay, and the minibatch gradient. Warmup and cosine decay themselves were introduced in §0.6 and used for our GPT in §6.3.
Warmup, derived from Adam's second moment
Why does Adam need warmup at all? §5.7 gave the qualitative answer. In the first steps, the second-moment estimate rests on very few gradients, so it is noisy, and dividing by its square root makes the steps large and erratic. Let's make that quantitative.
Adam's bias-corrected second moment is a weighted average of past squared gradients,
How many gradients is that average really based on? For a weighted average of independent samples with equal variance, the variance is times the variance of one sample, so the effective sample size is (with weights summing to one). Summing the geometric series,
In plain words, early on , every gradient so far counts fully, and as it saturates at
which is 1,999 for and 39 for . (This is exactly the constant in RAdam, Liu et al. 2020, who reached it by approximating the exponential average with a simple moving average.)
Now the variance. If the gradient coordinate has mean near zero and variance , as it nearly does early in training, then with , and the step size is proportional to . A chi-square with degrees of freedom has , so
which is infinite for and close to 1 only when is in the tens. In plain words, until Adam has seen a few dozen gradients, the variance of its step size is huge, because the denominator can by chance be tiny. RAdam turns this into an algorithm, using plain momentum SGD until its approximation of exceeds 4, and afterwards multiplying Adam's step by a rectification factor chosen so that the step's variance is the same as it would be with an infinite average. Ma and Yarats (2021) showed that ordinary linear warmup does the same job if it lasts about steps, 2,000 steps for and 40 for , the time it takes to approach its limit.
With , after 2 steps one coordinate in a hundred takes a step almost 10 times the learning rate, eight times the median, which is the "large and erratic" early behavior in numbers. After 200 steps the tail is tame. The first line also shows what the warmup rule means. At , , so has reached percent of its limit.
Why, then, do large runs warm up for thousands of steps even with ? LLaMA 3 405B warmed up for 8,000 steps, DeepSeek-V3 and OLMo 2 for 2,000. Adam's variance is one reason, and the other reasons are about the network rather than the optimizer. At initialization, gradients are large and change direction quickly, the loss surface is sharp in some directions, and post-LN or deep models have the gradient profiles of §5.7. A recent account (Kalra & Barkeshli 2024) argues that warmup's main effect is to let the network move into flatter regions that tolerate the peak learning rate. In practice, warmup length is set empirically, somewhere around 0.1 to 1 percent of the run, and longer warmup also reduces the final loss's sensitivity to the peak learning rate (Wortsman et al. 2023).
How many gradients does Adam's second moment average?
Write effective_samples(t, beta2) returning from the closed form above (it must work for NumPy arrays of t), and warmup_steps_for(beta2, frac=0.95) returning the smallest integer step at which .
Why the loss falls when the learning rate decays
Anyone who has watched a training run has seen it. The loss creeps down slowly at a constant learning rate, then plunges as the learning rate decays. The simplest model that explains it is one coordinate of a quadratic with a noisy gradient. Let the loss be with curvature , and let the minibatch gradient be , with noise of mean zero and variance . One SGD step is
Take the variance of both sides. The noise is independent of , so in the steady state, with ,
and the expected excess loss is
In plain words, at a fixed learning rate the parameters never settle. They bounce around the minimum with a spread that grows with and with the gradient noise, and the loss carries a floor proportional to . Lowering lowers the floor within about steps, which is the sudden drop. A large learning rate makes fast progress along directions where the loss is still falling, and pays for it with noise in directions where it has already bottomed out. A good schedule spends most of the run at a high rate, for progress, and the end at a low one, to remove the noise. (Real loss surfaces have both kinds of directions at once, which some authors picture as a river flowing down a narrow valley. The high rate moves you along the river, and the decay drops you to its bed.)
The constant-rate losses match the formula, and decaying the rate at the end removes most of the floor in just 100 steps. That is the whole case for decay schedules, and the reason the end of training matters so much for data, too (annealing in §8.4).
Cosine, and its fixed-length problem
Recall the cosine schedule from §0.6 (Loshchilov & Hutter 2017, adopted by GPT-3, Chinchilla, and LLaMA). It warms up and then follows half a cosine from to a floor , usually 10 percent of the peak,
It works well, and it has the problem from the start of this section, that is baked in. Halfway through, the rate is already down to 55 percent of the peak, so the run has started paying the "decay" price long before the end. You cannot extend it without a second warmup or a strange-shaped tail, and every run length on a scaling-law plot needs its own run.
The floor itself is a choice worth questioning. Bergsma et al. (2025) compared decaying to 10 percent of the peak with decaying linearly all the way to zero, at the best peak rate for each, across model sizes, batch sizes, and datasets. Decay to zero won consistently, and the gap grew with the number of tokens per parameter. In one comparison a 610M model trained for 80 tokens per parameter with linear decay to zero beat the same model trained for 200 tokens per parameter with a 10 percent floor. The noisy quadratic of the last section suggests why. Whatever learning rate is left at the end sets the noise floor the model finishes on.
Warmup-stable-decay
The fix is to separate the two jobs. Hold the learning rate constant at its peak for most of the run, and do all the decaying in a short cooldown at the end. This warmup-stable-decay schedule (WSD) was named in MiniCPM (Hu et al. 2024), which decayed over the last 10 percent of tokens and found that 2.5 percent was too short. DeepSeek LLM used a step version, dropping to 31.6 percent of the peak () after 80 percent of the tokens and to 10 percent after 90 percent (DeepSeek-AI 2024). Hägele et al. (2024) studied the idea systematically and found the following.
- A constant rate followed by a cooldown matches cosine's final loss, and it scales the same way with model size.
- Gains from a longer cooldown level off at about 20 percent of the run. On long runs, 5 to 10 percent is nearly as good.
- The shape of the cooldown matters. A shape, which drops the rate quickly at first and then slowly, beat a linear one, and the gap grew with run length.
- Because the stable phase is shared, one long run with cooldowns branched off at several points gives models of several lengths, which cut the cost of their scaling-law experiments by about half.
With a cooldown that starts at step and lasts until , writing , the three common shapes are
In plain words, climb, cruise, then land, and the landing can be any monotone curve from the peak to the floor. DeepSeek-V3 combined the ideas. Its learning rate warmed up to over 2,000 steps, stayed constant for the first 10 trillion tokens, followed a cosine down to over 4.3 trillion tokens, and then ran two short constant stages at and for the final 500 billion (DeepSeek-AI 2024).
The toy loss in the designer is the noisy quadratic above with a slowly improving "progress" term added, so it reproduces the drop at cooldown and the advantage of a long stable phase, but it is too simple to reproduce the fine differences between cooldown shapes that Hägele et al. measured on real models. Use it to build intuition about when loss falls, not to pick a shape.
A warmup-stable-decay schedule
Write wsd_lr(step, total, peak, warmup, decay_frac, shape="linear", min_lr=0.0). Steps count from 0. For step < warmup, return peak * (step + 1) / warmup. The cooldown starts at t_d = total - round(decay_frac * total). For warmup <= step < t_d, return peak. For t_d <= step < total, let x = (step - t_d) / (total - t_d) and return min_lr + (peak - min_lr) * f(x) with f one of "linear" (), "sqrt" (), or "cosine" (). For step >= total, return min_lr. Raise ValueError for an unknown shape or if the warmup reaches past t_d.
The gradient noise scale and the critical batch size
Now batch size. With more GPUs you can process a bigger batch in the same time. Does that make training proportionally faster? Up to a point. McCandlish et al. (2018) gave the cleanest account of where that point is, and the derivation is short enough to do in full.
Let be the true gradient, the Hessian, and the covariance of the per-example gradient, so a batch of examples estimates with covariance . Take one step of size along the minibatch gradient , and expand the loss to second order,
using . This is a quadratic in , minimized at
with , the best step with an exact gradient, the corresponding improvement, and the gradient noise scale
In plain words, a batch much smaller than is dominated by noise, so the best step and the progress per step both grow linearly with , and a batch much larger than is almost an exact gradient, so more examples barely help. If the Hessian is a multiple of the identity, the noise scale simplifies to , the total gradient variance over the squared gradient norm, which can be measured cheaply.
Two famous rules fall out of at once. For , , so the best learning rate grows linearly with the batch size, the linear scaling rule that Goyal et al. (2017) used to train ResNet-50 with batches of 8,192 images. For it saturates, which is why the linear rule eventually fails.
Steps against examples
Now ask how many steps and how many examples a run needs to reach a fixed loss. Suppose each step makes the optimal progress , and let be the number of steps with an infinite batch. Since each step makes of the infinite-batch progress,
with , the examples needed with a tiny batch. Then and , so
In plain words, there is a hyperbolic trade-off between time (steps) and compute (examples). The critical batch size is the balanced point, where a run takes twice the minimum steps and twice the minimum examples. Below it, doubling the batch nearly halves the steps for almost no extra compute. Above it, doubling the batch nearly doubles the compute for almost no saving in time. McCandlish et al. measured critical batch sizes from about 20 for a small autoencoder to more than 10 million for Dota 5v5, and found that the noise scale grows as training progresses, because shrinks as the loss falls while the noise does not. That is the reason for batch-size ramps.
How do you measure during a run, without per-example gradients? With two batch sizes. A minibatch gradient's squared norm satisfies , a line in . Measure it at a small batch (for example one GPU's gradient before the all-reduce) and a large one (the all-reduced gradient), and solve the two equations,
each unbiased. Their ratio is a biased estimate of , so in practice both are averaged over many steps before dividing (McCandlish et al. 2018, Appendix A).
Estimate the gradient noise scale from two batch sizes
Implement noise_scale(G_small, G_big, B_small, B_big). G_small and G_big are arrays of shape (n_steps, P) holding, for each of n_steps steps, a gradient averaged over B_small examples and one averaged over B_big examples. Compute the unbiased estimates of and per step, average each over steps, and return (trace_sigma, g2, b_simple) with b_simple = trace_sigma / g2.
Time against compute at a given batch size
Write steps_and_examples(B, B_noise, S_min) returning (S, E) from the formulas above, and batch_for_slowdown(B_noise, max_extra_compute) returning the largest batch size for which the run uses at most max_extra_compute times more examples than beyond the minimum (so max_extra_compute = 0.1 means ). Both must work with NumPy arrays.
Batch-size ramps, and how the learning rate should move with the batch
Because the noise scale is small early in training and grows as the loss falls, a fixed large batch wastes data at the start. So large runs ramp the batch size. GPT-3 increased its batch linearly from 32,000 tokens to its full 3.2 million over the first 4 to 12 billion tokens, depending on model size (Brown et al. 2020). PaLM went from 512 to 1,024 to 2,048 sequences (1 to 4 million tokens) at steps 50,000 and 115,000. LLaMA 3 405B started at 4 million tokens with sequences of 4,096, moved to 8 million tokens and sequences of 8,192 after 252 million tokens, and to 16 million after 2.87 trillion. DeepSeek-V3 ramped from 3,072 to 15,360 sequences over its first 469 billion tokens.
How should the learning rate change when the batch does? For SGD in the small-batch regime, the derivation above says linearly. For Adam the answer is different. Malladi et al. (2022) derived from a stochastic differential equation approximation of Adam that when the batch is multiplied by , the dynamics are preserved by the square-root rule,
In plain words, with a batch times larger the run takes times fewer steps, so each step must make times the progress while adding no more noise per example. When noise dominates Adam's denominator, shrinks by along with the noise, so the same already makes each step's drift times larger, and a learning rate times larger supplies the rest of the factor . The same keeps the noise added per example unchanged, which is why the two requirements agree. The betas must shorten their memory in proportion, because each step now covers times as many examples, so the averages should span the same number of examples rather than the same number of steps. The rule holds only below the critical batch size, like the linear rule for SGD.
At the frontier, teams fit learning rate and batch size directly as power laws in compute. DeepSeek LLM found the near-optimal values for its models followed and , with the training compute and in tokens (DeepSeek-AI 2024). For FLOPs, that is a batch of about 21 million tokens and a learning rate of about , close to what they used for their 67B model. The optimal batch grows with compute, because bigger runs reach lower losses where the noise scale is larger, and the optimal learning rate shrinks slowly. How such hyperparameters transfer across model sizes is the subject of §9.5.
Two recent results refine this picture. Zhang et al. (2024) separated the effects of model size and data size on the critical batch size and found that it grows mainly with the amount of data trained on, not with the number of parameters, so a longer run can use a larger batch even at a fixed model size. And Marek et al. (2025) looked at the other end, very small batches, and found that they train language models well, down to a batch of one sequence, provided Adam's is adjusted so that the second moment's half-life measured in tokens stays fixed. With the decay after steps of tokens each, holding the half-life fixed when the batch goes from to gives , which to first order is the of the square-root rule above. Both results say the same thing from different sides. Batch size is a statement about how many tokens each optimizer step averages, and the other hyperparameters should be set in tokens too.
In PyTorch
In PyTorch, any schedule is a LambdaLR that multiplies the base learning rate by a function of the step. Here is WSD with a cooldown, checked against the formula.
Read more
- McCandlish et al. (2018). An Empirical Model of Large-Batch Training. The gradient noise scale, the critical batch size, and how to measure them.
- Hägele et al. (2024). Scaling Laws and Compute-Optimal Training Beyond Fixed Training Durations. Constant learning rate with cooldown, cooldown shapes, and cheaper scaling laws.
- Hu et al. (2024). MiniCPM. The warmup-stable-decay schedule, with its decay-length experiments.
- Liu et al. (2020). On the Variance of the Adaptive Learning Rate and Beyond, with Ma and Yarats (2021), On the adequacy of untuned warmup for adaptive optimization. Why Adam needs warmup, and how long.
- Malladi et al. (2022). On the SDEs and Scaling Rules for Adaptive Gradient Algorithms. The square-root scaling rule for Adam.
- DeepSeek-AI (2024). DeepSeek LLM, Scaling Open-Source Language Models with Longtermism. The multi-step schedule and fitted scaling laws for batch size and learning rate.
- Bergsma et al. (2025). Straight to Zero: Why Linearly Decaying the Learning Rate to Zero Works Best for LLMs. The case against a 10 percent floor.
- Zhang et al. (2024). How Does Critical Batch Size Scale in Pre-training?, with Marek et al. (2025), Small Batch Size Training for Language Models: When Vanilla SGD Works, and Why Gradient Accumulation Is Wasteful. The critical batch grows with data, and small batches work when is set in tokens.