Gradient Noise, Batch Size & Scaling Rules
The SDE view of SGD, the gradient noise scale and the critical batch size.
Change the batch size and you must change the learning rate, but by how much, and how far does a bigger batch keep paying? This lesson treats SGD's noise quantitatively three ways: as a diffusion whose temperature is , with an exact stationary spread and fluctuation–dissipation identities; as a per-step trade-off that defines the gradient noise scale and the critical batch size; and as an implicit regularizer that every finite step adds to the loss.
What you’ll learn
- State the weak-approximation theorem for stochastic modified equations, derive the linear scaling rule as an invariance of the SDE, state the square-root rule for Adam, and say where both fail.
- Derive the Ornstein–Uhlenbeck stationary variance , compare it with the exact discrete result, and prove the fluctuation–dissipation relation .
- Derive the optimal step and progress per step as functions of , the gradient noise scale and the steps–examples trade-off, and estimate the noise scale from two batch sizes.
- Derive the implicit regularizer of gradient descent by backward error analysis, and state its stochastic counterpart.
SGD as a diffusion
The Machine Learning course's Batch Size, Learning Rate & Noise introduces this diffusion picture and the critical batch size; here both are made precise and taken further. One SGD step is , with noise and . Measure time in units of the learning rate, . In one step the drift moves as far as the gradient flow does in time , and the noise adds covariance , which is what a Brownian motion with diffusion matrix accumulates in time . Matching these two moments gives a stochastic differential equation:
Multiply the batch size by and the learning rate by . The diffusion coefficient does not change, and neither does the drift: it is literally the same equation.
Time advances by per step, so reaching time takes times fewer steps, each with times more examples. While the SDE approximates both runs, the larger batch reaches the same distribution of outcomes in times fewer steps and the same number of examples: perfect scaling, which is the linear scaling rule.
Adaptive methods divide the step by a running root-mean-square of the gradient, which itself grows with the noise, so the matching changes. For RMSprop and Adam, Malladi, Lyu, Panigrahi & Arora (2022) derive SDEs whose invariance gives the square-root scaling rule, which also rescales the averaging horizons and :
Where the picture breaks. Both rules are small-learning-rate statements: the theorem holds as over a fixed horizon, while practical runs use nearly the largest stable rates for many epochs. Li, Malladi & Arora (2021) built an efficient way to simulate the SDE (stochastic variance amplified gradient, SVAG) and proved a testable necessary condition for the approximation, whose best-known consequence is the linear scaling rule itself. Read backwards: where linear scaling fails, as it does beyond about 8,000 images per batch for ResNet-50 on ImageNet (Goyal et al., 2017), the SDE has stopped describing SGD. The SDE also keeps only the first two moments of the noise. Simsekli, Sagun & Gürbüzbalaban (2019) measured heavy-tailed gradient noise and argued for Lévy-driven dynamics instead; how Gaussian the noise is at practical batch sizes is still debated.
The stationary spread in a basin
Near a minimum, treat the loss as quadratic and the noise as constant. In one dimension, take with the minimum at , and let the per-example gradients have variance . The SDE becomes an Ornstein–Uhlenbeck process, and the actual algorithm can be solved too.
The SDE is linear. Itô's formula applied to gives an ordinary differential equation for the second moment :
Its fixed point is the stationary variance. The excess loss then does not depend on the curvature at all:
Now the real algorithm: with , so , whose fixed point is
The SDE is right to leading order in and wrong near the stability threshold: as the true variance blows up while the SDE's stays finite, and beyond it the SDE still predicts a stationary state where SGD diverges. In dimensions, with Hessian and noise covariance , the stationary covariance of the SDE solves a Lyapunov equation, and taking its trace gives the excess loss without solving for :
To leading order, a constant-step run hovers at an excess loss of : set by the total gradient noise at the minimum, not by the curvature. Curvature decides only where the spread goes; when and commute, , so sharp directions fluctuate less. Halve or double and the floor halves. Mandt, Hoffman & Blei (2017) used this picture to tune constant-step SGD so that its stationary distribution approximates a Bayesian posterior.
Both sides of the relation are cheap to measure during training, so it doubles as an equilibrium detector. Yaida proposed tracking running averages of and and cutting by 10% whenever they agree to within 1%: a schedule that decays exactly when the run has reached its noise floor. The relation extends to momentum with a modified right-hand side.
A constant-rate run has settled on its noise floor. You double the batch size and keep . By what factor does the excess loss at stationarity change?
Show the answer
0.5
The excess loss is to leading order, so it halves. In the noisy quadratic model the exact floor, , is proportional to as well. Doubling instead would roughly double it, and slightly more, since the factor grows with .
How much does a bigger batch buy?
The SDE says what stays the same when and scale together, not how far the scaling can go. McCandlish, Kaplan, Amodei and the OpenAI Dota Team (2018) asked a sharper question: how much can one step achieve with batch if its size is chosen optimally? Expand the loss to second order around the current point, with gradient , Hessian and per-example covariance .
Average over the batch, using and . A step lowers the expected loss by
This is a concave quadratic in . Its maximizer and maximum are the infinite-batch values and , both discounted by the same factor:
For the best step grows linearly with , the linear scaling rule again but now with a known slope, and so does the progress per step. For both saturate and extra examples are wasted. If is close to a multiple of the identity, the noise scale becomes a ratio that can be measured:
For a fixed amount of progress the number of steps scales like , so and the number of examples is , with . Eliminating leaves a hyperbola:
A training run is allowed only 1.5 times the minimum number of examples, . How many times the minimum number of steps does it take?
Show the answer
3
gives . At the run would sit at the critical batch size, the knee where time and computation are both twice their minimum. Toward small example budgets the curve steepens fast: examples need steps, and as approaches the number of steps grows without bound.
In a real run the noise scale changes, so McCandlish et al. fit and to whole training runs; their model predicts "appropriately averaged over training". The critical batch size varies enormously across tasks, from about 20 for an SVHN autoencoder to millions for the Dota game-playing agents, and within a run it grows severalfold to more than a hundredfold, because shrinks as the loss falls while does not:
| Task | early in training | averaged over training |
|---|---|---|
| MNIST | 20 | 200 |
| CIFAR-10 | 300 | 900 |
| ImageNet | 1,000 | 15,000 |
| Dota 1v1 (reinforcement learning) | 50,000 | 3,000,000 |
Measuring it. Data-parallel training gives two batch sizes for free: each device's local batch and the averaged global batch . Since , two measurements yield unbiased estimates of both pieces. Their ratio is biased, so McCandlish et al. smooth each piece with a moving average before dividing.
On each device, batches of 16 give an average squared gradient norm of ; the averaged batch of 256 gives . What is the estimate of ?
Show the answer
C.
and , so . Check: and . Batches well below 64 are noise-dominated, so growing them still buys nearly linear speed-ups.
Language models and optimizers. Kaplan et al. (2020) found that for language models the critical batch size depends on the loss alone and not on model size, with tokens, and the loss in nats. Later work separated the effects of data and model size. Training language models of 85 million to 1.2 billion parameters, Zhang et al. (2025) found that the critical batch size grows mainly with the amount of training data rather than with model size. Measuring it directly with a small amount of extra training, Merrill, Arora, Groeneveld & Hajishirzi (2025) found that it starts near zero, rises quickly and then plateaus; growing the batch size to match trained a 1-billion-parameter OLMo model with 43% fewer gradient steps at slightly better loss. The optimizer matters as well: in the noisy quadratic model, momentum leaves small-batch training unchanged but extends perfect scaling to larger batches, and preconditioners such as Adam and K-FAC raise the critical batch size further, in line with experiments on real networks (Zhang et al., 2019; Shallue et al., 2019).
The regularizer hidden in a finite step
Even without noise, a finite step does not follow the gradient flow. Backward error analysis, a tool from numerical integration, asks which modified flow the discrete iterates follow exactly, up to higher-order terms.
Look for a flow whose solution after time matches one gradient step up to . Since , a Taylor expansion of the flow gives
Gradient descent lands exactly at , so the terms must cancel. The correction turns out to be a gradient itself:
So gradient descent with step follows, to this order, the gradient flow of a modified loss that penalizes steep regions. It is the same correction that turns the first-order stochastic modified equation into the second-order one.
For SGD with random reshuffling, Smith, Dherin, Barrett & De (2021) showed that over one epoch the mean iterate, averaged over batch orders, follows a modified loss built from the batch losses :
Both results assume small but finite steps and describe average behavior. They also suggest experiments, which have been run. Smith et al. found that adding the regularizer to the loss explicitly improves test accuracy when the learning rate is small, and Geiping, Goldblum, Pope, Moeller & Goldstein (2022) matched SGD's accuracy on CIFAR-10 with non-stochastic, full-batch training by adding an explicit gradient-norm penalty, together with more steps and aggressive gradient clipping. Over longer times, noise also acts along the valley of minimizers. Once SGD reaches a manifold of zero-loss solutions, its noise drives a slow drift along the manifold on a timescale of steps; for SGD with label noise, that drift lowers the trace of the Hessian, a measure of sharpness (Blanc et al., 2020; Li, Wang & Arora, 2022).
Key takeaways
- To first order in , SGD is weakly approximated over a fixed horizon by . Learning rate and batch size act through , so linear scaling keeps the SDE fixed; Adam's analogue is with . Both rules fail as nears the stability threshold.
- In a quadratic basin the stationary excess loss is , independent of curvature; the exact discrete variance is larger by . The fluctuation–dissipation relation holds exactly at stationarity and can trigger learning-rate decay.
- One step with batch makes progress with . Steps and examples trade off as ; the critical batch size grows severalfold or more during training and is larger for preconditioned optimizers.
- A finite step adds the implicit regularizer ; SGD adds a penalty on batch-gradient disagreement with strength proportional to .
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A run uses SGD with batch size 256 and learning rate . According to the SDE approximation, which run follows the same dynamics in time ?
- Batch size 1,024 and learning rate
- Batch size 1,024 and learning rate
- Batch size 64 and learning rate
- Batch size 1,024 and learning rate
Show the answer
D. Batch size 1,024 and learning rate
The SDE depends on and only through ; . The new run needs four times fewer steps to reach the same time, with the same number of examples, as long as stays small enough for the approximation to hold.
In the Ornstein–Uhlenbeck approximation of constant-step SGD on with per-example gradient variance , how does the stationary excess loss depend on the curvature ?
- It does not: it is for every
- It grows in proportion to : sharper minima are noisier
- It is inversely proportional to , like the variance
- It grows like
Show the answer
A. It does not: it is for every
The variance falls like and the loss multiplies it by , so the curvature cancels. The exact discrete result multiplies this by , which does depend on and blows up at the stability threshold.
By backward error analysis, gradient descent with step follows, up to higher-order terms, the gradient flow of which modified loss?
- itself: gradient descent is an exact discretization
Show the answer
B.
Matching one step with the flow over time forces the correction into the drift. The extra term penalizes regions where the gradient is large; the same correction appears in the second-order stochastic modified equation.
Early in training you use a batch size far below the gradient noise scale, . What does doubling , with the step size re-optimized, do?
- It halves the number of examples needed and leaves the steps unchanged
- Nothing: below the noise scale the batch size does not matter
- It nearly halves the number of steps needed, at nearly the same number of examples
- It doubles the progress per example
Show the answer
C. It nearly halves the number of steps needed, at nearly the same number of examples
With for small , steps fall like , while hardly moves. That is perfect scaling; it ends around .
Further reading
- Q. Li, C. Tai & W. E, "Stochastic modified equations and dynamics of stochastic gradient algorithms I: Mathematical foundations," Journal of Machine Learning Research 20 (2019).
- S. McCandlish, J. Kaplan, D. Amodei & the OpenAI Dota Team, "An empirical model of large-batch training," arXiv:1812.06162 (2018).
- S. Malladi, K. Lyu, A. Panigrahi & S. Arora, "On the SDEs and scaling rules for adaptive gradient algorithms," NeurIPS (2022).
- S. Yaida, "Fluctuation-dissipation relations for stochastic gradient descent," ICLR (2019).
- S. L. Smith, B. Dherin, D. G. T. Barrett & S. De, "On the origin of implicit regularization in stochastic gradient descent," ICLR (2021).