Search

Search papers and lessons

Critical Batch Size

Level 4 · 10 min read

The batch size beyond which a bigger gradient batch mostly wastes examples: it stops cutting the number of training steps by much.

On this page

  • Colour = topic mix
  • Calculus
  • Optimizers
  • Probability
  • Linear algebra
  • Losses & regularization
  • Discrete math
  • Sign in to see your progress

TL;DR

The critical batch size is the number of examples per gradient step above which making the batch bigger stops paying off. Below it, doubling the batch roughly halves the number of steps you need. Above it, doubling the batch barely reduces the steps, so you pay for twice the examples and get almost nothing back.

It is set by the noise in the gradient. When the gradient from a batch is very noisy, a bigger batch averages that noise away and helps; once the noise is already small compared with the true signal, more examples add cost without adding information.

Where you'll see it: in deciding how large a batch to use when training a large language model on many GPUs, where the choice trades wall-clock time against total compute.

Intuition

Tasting soup

Imagine checking whether a large pot of soup needs salt. One spoonful tells you a little, but it could come from a salty corner. Take a few spoonfuls from different places and your estimate gets much better. Take a hundred more and you have learned almost nothing new, because the soup is already well mixed and your estimate was good enough several spoonfuls ago.

Training a model with stochastic gradient descent works the same way. Each step needs an estimate of the direction to move, and that estimate is the average gradient over a batch of examples. A small batch gives a noisy direction, so the model needs many steps. A large batch gives a clean direction, so each step is more reliable, but each step also reads more examples and costs more time and memory.

The question is where to stop. The critical batch size is the point where the extra cleanliness of the direction stops being worth the extra examples.

Why the answer depends on the training run

The right batch size is not a fixed property of a model architecture. It changes as training proceeds. Early on, when the model is far from good, the gradient points the same way for most examples and is relatively clean, so the critical batch is small. Later, when the loss is low, the remaining useful signal is small compared with the noise, and the critical batch grows. This is why a batch size that was sensible at the start of a run can become wasteful near the end.

The math

Gradient noise

Take a batch of BB examples and let gBg_B be the average of their per-example gradients. Let G=E[gB]G = \mathbb{E}[g_B] be the true gradient over the whole data distribution, the thing every batch is trying to estimate. Write gB=G+nBg_B = G + n_B, where nBn_B is the noise, with E[nB]=0\mathbb{E}[n_B] = 0.

Let Σ\Sigma be the covariance matrix of a single example's gradient. Averaging BB independent examples divides the covariance by BB, so the noise has covariance Σ/B\Sigma / B. The expected squared length of the batch gradient is then

E[ ∣gB∣2 ]=∣G∣2+E[∣nB∣2]=∣G∣2+tr⁡(Σ)B.\mathbb{E}\big[\,|g_B|^2\,\big] = |G|^2 + \mathbb{E}\big[|n_B|^2\big] = |G|^2 + \frac{\operatorname{tr}(\Sigma)}{B}.

Here ∣⋅∣|\cdot| is the Euclidean length, tr⁡\operatorname{tr} is the trace (the sum of the diagonal entries, which is the total variance across all parameters), and the cross term between GG and nBn_B vanishes because the noise has zero mean. The formula says that the squared size of a batch gradient is a constant signal part plus a noise part that shrinks like 1/B1/B.

Define the gradient noise scale

Bnoise=tr⁡(Σ)∣G∣2.\mathcal{B}_{\text{noise}} = \frac{\operatorname{tr}(\Sigma)}{|G|^2}.

It is the ratio of noise to signal, measured in examples. When B≪BnoiseB \ll \mathcal{B}_{\text{noise}} the noise dominates. When B≫BnoiseB \gg \mathcal{B}_{\text{noise}} the signal dominates and extra examples do little.

Steps against examples

Let SS be the number of steps and E=SBE = SB the number of examples processed. McCandlish and colleagues found, empirically, that across many training runs the trade between steps and examples is described well by

(SSmin⁡−1)(EEmin⁡−1)=1,\left(\frac{S}{S_{\min}} - 1\right)\left(\frac{E}{E_{\min}} - 1\right) = 1,

where Smin⁡S_{\min} is the number of steps needed with a very large batch, and Emin⁡E_{\min} is the number of examples needed with a very small batch. The critical batch size BcritB_{\text{crit}} is the batch at which the two terms are equal, and it is approximately Bnoise\mathcal{B}_{\text{noise}}. Solving the relation for SS and EE gives

SSmin⁡=1+BcritB,EEmin⁡=1+BBcrit.\frac{S}{S_{\min}} = 1 + \frac{B_{\text{crit}}}{B}, \qquad \frac{E}{E_{\min}} = 1 + \frac{B}{B_{\text{crit}}}.

Both formulas show the trade in one place. Make BB small and steps go up. Make BB large and examples go up. At B=BcritB = B_{\text{crit}} both the step count and the example count are exactly twice their minimums.

123450123456batch size B / critical batch size B_critrelative cost
  • steps needed (relative to minimum)
  • examples used (relative to minimum)
Left of 1, steps are the bottleneck; right of 1, examples are. Both curves equal 2 at the critical batch size.

Worked examples

Example
A hand-computable run

Take a run where the best possible step count is Smin⁡=1000S_{\min} = 1000 and the critical batch size is Bcrit=100B_{\text{crit}} = 100 examples. Then Emin⁡=Smin⁡Bcrit=100,000E_{\min} = S_{\min} B_{\text{crit}} = 100{,}000 examples.

  1. Batch B=10B = 10. Steps: S=1000×(1+100/10)=11,000S = 1000 \times (1 + 100/10) = 11{,}000. Examples: E=11,000×10=110,000E = 11{,}000 \times 10 = 110{,}000.
  2. Batch B=100B = 100. Steps: S=1000×(1+1)=2,000S = 1000 \times (1 + 1) = 2{,}000. Examples: E=2,000×100=200,000E = 2{,}000 \times 100 = 200{,}000.
  3. Batch B=1000B = 1000. Steps: S=1000×(1+0.1)=1,100S = 1000 \times (1 + 0.1) = 1{,}100. Examples: E=1,100×1000=1,100,000E = 1{,}100 \times 1000 = 1{,}100{,}000.

Interpretation: going from batch 10 to batch 100 is a tenfold larger batch that cuts steps by 5.5 times, for only 1.8 times the examples. Going from 100 to 1000 is another tenfold batch, but steps fall only from 2000 to 1100 while examples grow 5.5 times (from 200,000 to 1,100,000). The sweet spot is near 100.

Example
Estimating the noise scale from two batch sizes

You can estimate ∣G∣2|G|^2 and tr⁡(Σ)\operatorname{tr}(\Sigma) without knowing them in advance. Measure the squared gradient length for two batch sizes. Suppose B1=10B_1 = 10 gives ∣g10∣2=44|g_{10}|^2 = 44 and B2=100B_2 = 100 gives ∣g100∣2=8|g_{100}|^2 = 8.

  1. From the formula, E∣gB∣2=∣G∣2+tr⁡(Σ)/B\mathbb{E}|g_B|^2 = |G|^2 + \operatorname{tr}(\Sigma)/B, so we have two equations: 44=∣G∣2+tr⁡(Σ)/1044 = |G|^2 + \operatorname{tr}(\Sigma)/10 and 8=∣G∣2+tr⁡(Σ)/1008 = |G|^2 + \operatorname{tr}(\Sigma)/100.
  2. Subtract the second from the first: 36=tr⁡(Σ) (1/10−1/100)=0.09 tr⁡(Σ)36 = \operatorname{tr}(\Sigma)\,(1/10 - 1/100) = 0.09\,\operatorname{tr}(\Sigma), so tr⁡(Σ)=400\operatorname{tr}(\Sigma) = 400.
  3. Substitute back: 8=∣G∣2+400/1008 = |G|^2 + 400/100, so ∣G∣2=4|G|^2 = 4.
  4. The noise scale is Bnoise=400/4=100\mathcal{B}_{\text{noise}} = 400 / 4 = 100.

Interpretation: a batch of about 100 examples is where the noise and signal balance. In practice, a team would run a few batch sizes around this and pick the one that gives the best trade. These noisy measurements are usually averaged over many batches, because a single pair of norms is a poor estimate.

Tradeoffs and failure modes

Batch size is a choice with three costs. The first is wasted hardware or wasted time when the batch is far below the critical size, because the run is limited by the number of sequential steps. The second is wasted compute when the batch is far above it, because extra examples add cost without shortening the run much. The third is a training-dynamics problem: a larger batch usually needs a learning rate change to stay stable, and it is easy to forget that step.

SituationWhat goes wrongBetter choice
Batch well below the critical sizeSteps are the bottleneck; many more sequential steps are needed, and parallel hardware sits idleIncrease the batch toward the critical size, scaling the learning rate with it
Batch well above the critical sizeExamples and compute are wasted; step count barely dropsKeep the batch near the critical size and spend spare hardware on other work
Fixed batch for a whole runCritical size rises as loss falls, so the batch that was right early becomes wasteful lateRamp the batch size up during training
Larger batch without retuning the learning rateTraining becomes unstable or converges to a worse resultUse warmup and a learning rate that scales with batch size, as in Goyal et al.
Tiny model on one deviceMemory or the dataset limits the batch long before the critical size is reachedIgnore the critical batch size; it matters only when batch size can really be chosen

A recurring caveat is generalization. Several studies have reported that very large batches can reach a higher training score yet generalize worse on held-out data. The effect depends on the setup, so treat the critical batch size as a guide for optimization speed, and check the final quality separately.

History

The idea of a gradient noise scale grew out of a 2017 observation by Samuel Smith, Quoc Le and colleagues that increasing the batch size can play the role of decaying the learning rate. In 2017, Priya Goyal and colleagues at Facebook trained ImageNet with very large batches in about an hour, using a linear learning rate scaling rule and a warmup period. That work made large batches a practical tool.

In 2018 Sam McCandlish, Jared Kaplan, Dario Amodei and colleagues at OpenAI wrote down the gradient noise scale and the steps-against-examples relation above, and showed it predicted the best batch size across many tasks. In the same year, Christopher Shallue and colleagues at Google ran a large, systematic study of data parallelism across several neural networks and reported that the best batch size depends strongly on the training setup and the target loss. Both lines of work shaped how large language models are trained today.

Check yourself

QuestionRecall: in one sentence, what does the critical batch size mean?Show answer

It is the batch size at which making the batch bigger stops cutting the number of steps much. Below it, doubling the batch roughly halves the steps. Above it, doubling the batch mainly doubles the examples used for little gain in steps.

QuestionComputation: with Smin⁡=1000S_{\min} = 1000 and Bcrit=100B_{\text{crit}} = 100, how many steps and how many examples does a batch of 50 need?Show answer

Steps: S=1000×(1+100/50)=3,000S = 1000 \times (1 + 100/50) = 3{,}000. Examples: E=Emin⁡(1+B/Bcrit)=100,000×1.5=150,000E = E_{\min}(1 + B/B_{\text{crit}}) = 100{,}000 \times 1.5 = 150{,}000. Check: 3000×50=150,0003000 \times 50 = 150{,}000. The batch of 50 is below the critical size, so steps are the cost.

QuestionWhy: why does doubling the batch above the critical size barely reduce the number of steps?Show answer

Above the critical size the gradient estimate is already dominated by signal. Extra examples in a batch reduce the remaining noise only a little, and the step direction was already close to the true gradient. Each step is more accurate, but the run needs roughly the same number of steps, so the extra examples are mostly spent for no benefit in step count.

QuestionApplied: a team doubles their GPUs and doubles the batch from 512 to 1024, but training takes the same number of steps as before. What probably happened, and what should they do?Show answer

The batch is probably now above the critical size, so the extra examples are not shortening the run. They should measure the gradient noise scale or check how the step count changes at a few batch sizes. If the batch is past the critical size, they should keep it near that size and use the extra GPUs for something else, such as a larger model or more experiments, rather than for a bigger batch.

Sources