Training and optimization
Large-Batch Training, Gradient Accumulation, and Scaling Limits
Evaluate linear and square-root scaling heuristics, warmup, critical-batch behavior, update count, accumulation semantics, and generalization at scale.
By the end you can
- Explain why increasing global batch size reduces update frequency for a fixed data budget
- Interpret learning-rate scaling rules as empirical heuristics rather than guarantees
- Distinguish hardware throughput gains from optimization-efficiency gains
- Design a scaling study that tracks quality, compute, communication, and state semantics
A larger batch buys a better estimate but fewer decisions
For a fixed number of examples, doubling batch size roughly halves optimizer updates. Each update uses a smoother gradient estimate, yet the model receives fewer opportunities to change.
Useful scaling occurs when parallel throughput outweighs the lost update frequency. Beyond a regime-dependent point, more examples per step add little new directional information.
Where that point sits has been measured, at a scale that leaves little room for argument. Six families of neural network. Three training algorithms. Seven data sets, with the learning rate, momentum and schedule retuned independently at every batch size. Shallue and colleagues published the result in the Journal of Machine Learning Research in 2019, and it rests on “a database of 71,638,836 loss measurements taken over the course of training for 168,160 individual models across 35 workloads”. Two findings came out of it. The first is that the batch ceiling does not transfer: they report “extremely large variation between workloads”. The second is that the ceiling is not a quality cliff — they found “no evidence that larger batch sizes degrade out-of-sample performance”. The trade is real. The number at which it turns belongs to one system.
Large-batch training exchanges update frequency for parallel evidence.
Visual
Two efficiencies determine whether scale helps
A system can win one and lose the other, and both halves have been measured on named runs rather than imagined.
Start with the hardware. ResNet-50 on ImageNet, a minibatch of 8192 spread across 256 GPUs, one hour of wall clock, roughly 90% scaling efficiency going from 8 to 256 GPUs. That run belongs to Goyal and eight Facebook co-authors, and it sits close to the top of what parallel work can pay.
On the statistical side the same axis moved the other way. Keskar and colleagues, at ICLR 2017, used 10% of the training set as the large batch against 256 points as the small batch under ADAM. Testing accuracy on their C4 network was 63.08% small batch against 57.81% large. On C1 it was 80.04% against 77.26%. Same knob, opposite sign of result, and neither run tells you what the other did.
- 01
Hardware efficiency
Examples or tokens processed per second improve with parallel work.
- 02
Communication efficiency
Workers spend an acceptable fraction of time computing rather than synchronizing.
- 03
Optimization efficiency
The number of examples or steps needed to reach a target remains favorable.
- 04
Statistical efficiency
Final validation behavior and robustness remain acceptable.
- 05
Economic efficiency
Wall-clock, energy, and infrastructure cost justify the result.
Example
Why accumulated and physical large batches can diverge
The gradient sum is only one part of training state, and the gap between accumulation and a physical batch is not a theoretical worry. In October 2024 gradient accumulation was found to be mathematically non-equivalent to full-batch training in Hugging Face Transformers and other trainers. For token-level losses the cross-entropy mean was taken per micro-batch. Micro-batches holding different numbers of non-padding tokens were therefore weighted wrongly.
The clearest statement of the defect came from the library's own maintainers. “Gradient accumulation is supposed to be mathematically equivalent to full batch training; however, losses did not match between training runs where the setting was toggled on and off.” — Hugging Face, on its own blog, 16 October 2024.
An independent researcher, Benjamin Marie, reported it publicly, and Daniel Han of Unsloth replicated it. Marie measured loss gaps of 0.2–0.3 at 2048-token sequences, 0.1–0.2 at 512 tokens and 0.45–0.70 with highly diverse sequence lengths. After the fix the gap fell to about 0.0004. The fix was pull request #34191, opened on 16 October 2024 and merged on 17 October 2024: reduction="mean" became reduction="sum" divided by the true token count, so the denominator is the total loss over all micro-batches divided by the total non-padding tokens. A widely used trainer carried this for as long as nobody diffed the two runs.
- BatchNorm: Each micro-batch computes separate activation statistics unless synchronization is used — and those statistics are worth points. At NIPS 2017, Hoffer and two Technion colleagues raised CIFAR-100 C3 large-batch (4096) validation accuracy from 51.50% to 63.20%, with the square-root-scaled learning rate, Ghost Batch Normalization and regime adaptation applied cumulatively — above the 61.25% small-batch baseline.
- Dropout and augmentation: Random draws differ across accumulation passes and one physical pass.
- Gradient clipping: Clipping per micro-batch differs from clipping the accumulated vector.
- Learning-rate schedules: Stepping per micro-batch instead of per optimizer update changes the rate path.
- EMA and optimizer moments: State should advance on actual updates, not every backward pass.
- Variable valid counts: Unequal masks require weighted accumulation rather than averaging micro-batch means — precisely the defect corrected in pull request #34191, where the mean-per-micro-batch reduction was replaced by a sum divided by the true non-padding token count.
A council making fewer decisions with larger surveys
A council doubles the size of its survey and halves how often it meets. Each survey is steadier, yet delayed decisions may slow adaptation.
The trade is the whole story. More evidence behind each decision, fewer decisions for a fixed amount of data, and a crossover point that has to be measured rather than assumed. The sections that follow are the measurements: where the crossover was found, how far it moved inside a single run, and what the two standard learning-rate rules were actually shown to do.
A larger batch improves one update estimate while reducing how often the model can respond.
Key idea
Critical batch size depends on the task and training recipe
The point of diminishing returns depends on model, objective, data diversity, optimizer, schedule, precision, and training phase. It can also change during a run. That caveat comes from the paper that gave the quantity its name, not from this lesson.
The critical batch size was defined in December 2018 as Bcrit = Emin/Smin, an empirical fit published by OpenAI. The abstract claims that “a simple and easy-to-measure statistic called the gradient noise scale predicts the largest useful batch size across many domains and applications”, and then bounds the claim in the next breath: “the noise scale increases as the loss decreases over a training run”. Anyone hoping to write down one number is warned off explicitly. “Note that the noise scale can vary significantly over the course of a training run, so the critical batch size also depends on the level of performance to which we train the model.” — McCandlish and Kaplan with the OpenAI Dota Team, 2018.
The proxy was adopted. Will Merrill of Ai2 records that “McCandlish et al. (2018) propose that the CBS can be measured before launching a large training run by using a quantity called the gradient noise scale as a proxy”, and that this “inspired some practical adoption of the gradient noise scale, e.g., in pretraining GPT-3”.
Seven years later the same group measured the thing directly instead. Ai2 tracked critical batch size through OLMo 1B and 7B pretraining and reported it at NeurIPS 2025 as a spotlight paper. “the CBS starts near 0, increases rapidly and then diminishingly, and plateaus around a batch size of 4096.” — Will Merrill, Ai2, 3 June 2025. Their gradient-noise-scale estimates did not match those measurements, and the write-up concludes that the “gradient noise scale cannot be reliably trusted as a proxy for CBS”. Reading the curve paid. A batch-size warmup that doubles the batch and scales the learning rate by √2 at each step reached slightly better loss than the original OLMo 1B run, with 43% fewer gradient steps.
Statistical efficiency is where the literature openly disagrees, and the disagreement is instructive. Keskar's group attributed the large-batch penalty to convergence toward sharp minimizers, and put a size on it: “In our experiments, we have found the drop in generalization (also called generalization gap) to be as high as 5% even for smaller networks.” Hoffer and two Technion colleagues then ran the same networks and reproduced the gap — 87.80% against 83.95% on C1/CIFAR-10, 61.25% against 51.50% on C3/CIFAR-100 — before closing it by training longer with adapted normalization. Shallue and colleagues object to the design rather than the numbers, in a footnote: those experiments “only compare two absolute batch sizes per data set, rather than charting out a curve to its apparent extremes”. Three teams, one phenomenon, and a two-point comparison that could not settle it.
Estimate scaling through actual time-to-quality curves rather than borrowing one number from another architecture. Critical-batch language is a diagnostic model, not a constant of nature.
Report global batch, workers, hardware, precision, examples processed, tuning compute, validation target, and final quality. Excluding failed scaling trials can make the recipe appear cheaper than it was. Operationally useful speedups include setup, data input, synchronization, checkpointing, and recovery; kernel-only benchmarks do not describe an end-to-end run.
The useful batch ceiling belongs to a specific training system and budget.
Comparison
Two familiar learning-rate scaling heuristics
Both need warmup and empirical validation under the target optimizer. They are also not two rival theories. They are a theory and the heuristic that beat it, and both were written down in the same note.
The two rules were set side by side in April 2014, in a note called One weird trick for parallelizing convolutional neural networks. The theory is the square root: “Theory suggests that when multiplying the batch size by k, one should multiply the learning rate ε by √k to keep the variance in the gradient expectation constant”. What Alex Krizhevsky measured was something else. “Theory aside, for the batch sizes considered in this note, the heuristic that I found to work the best was to multiply the learning rate by k when multiplying the batch size by k. I can’t explain this discrepancy between theory and practice.” He held momentum at 0.9 and weight decay at 0.0005 across all batch sizes. He also marked the limit himself, in a footnote: the linear heuristic “does eventually break down for batch sizes larger than the ones considered in this note”.
The linear rule then acquired a measured envelope. Goyal and eight Facebook co-authors adopted “a hyper-parameter-free linear scaling rule for adjusting learning rates as a function of minibatch size” together with “a new warmup scheme that overcomes optimization challenges early in training”, and reported “no loss of accuracy when training with large minibatch sizes up to 8192 images”. ResNet-50 on ImageNet, minibatch 8192 across 256 GPUs, one hour, roughly 90% scaling efficiency from 8 to 256 GPUs, five-epoch gradual warmup. The warmup is there because the rule fails, and they say so: “As we discussed, for large minibatches (e.g., 8k) the linear scaling rule breaks down when the network is changing rapidly, which commonly occurs in early stages of training.” — Priya Goyal and eight Facebook co-authors, Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour, 2017.
The result was reproduced independently, in a section titled “Reproduce and Extend Facebook's result”: You and colleagues report batch-8192 peak test accuracy 0.727 against a batch-256 baseline of 0.730 at 90 epochs. The outer bound was fixed later by Shallue and colleagues, who record that Goyal et al. “increased the batch size from 64 to 8,192 with no loss in accuracy. However, their learning rate heuristic broke down for even larger batch sizes.” Inside 8192 the rule has evidence. Outside it, the paper claims nothing and neither should you.
The square-root rule has a derivation rather than an anecdote. At NIPS 2017, Hoffer and two Technion colleagues required the covariance of the update step to stay constant across mini-batch sizes and concluded that “we should increase the learning rate by the square root of the mini-batch size.” (η ∝ √M.) They also moved the blame for the large-batch generalization gap onto the number of weight updates rather than the batch size. With the square-root-scaled learning rate, Ghost Batch Normalization and regime adaptation applied cumulatively, their ResNet44/CIFAR-10 large batch rose from 86.10% to 93.07%, against a 92.83% small-batch baseline. Shallue and colleagues summarise the position from the outside: “Hoffer et al. (2017) argue that increasing the batch size need not degrade out-of-sample error at all, assuming training has gone on long enough.” The rule is still in production use. Ai2's OLMo batch-size warmup reports that “We also scale the learning rate by a factor of √2 when we increase the batch size, following the square-root scaling rule”.
Linear scaling
Multiply learning rate approximately with batch-size ratio.
- Intuition: preserve change per processed example
- Use: selected SGD recipes
- Risk: unstable early steps
- Status: empirical heuristic
Square-root scaling
Increase learning rate with the square root of the batch ratio.
- Intuition: reflect variance reduction
- Use: selected noisy regimes
- Risk: overly conservative or aggressive
- Status: empirical heuristic
No fixed rule
Retune rate and schedule directly for the new regime.
- Intuition: interactions are task-specific
- Use: expensive high-stakes runs
- Risk: search cost
- Status: strongest evidence
Steps
Run a disciplined scaling experiment
Separate system speed from learning behavior. The shape you are looking for has already been characterized, which means the last step has a target instead of a hunch.
That shape was mapped with the learning rate, momentum and schedule retuned independently at every batch size — the tuning that makes a scaling curve mean anything. Shallue and colleagues describe what came out: “In all cases, as the batch size grows, there is an initial period of perfect scaling (b-fold benefit, indicated with a dashed line on the plots) where the steps needed to achieve the error goal halves for each doubling of the batch size. However, for all problems, this is followed by a region of diminishing returns that eventually leads to a regime of maximal data parallelism where additional parallelism provides no benefit whatsoever.”
So there are three regions, and the first one has a test you can run: does the step count to your error goal halve when the batch doubles? While it does, buy more parallelism. When it stops halving you are in the second region and paying partial rates. When the curve flattens you are in the third and paying for nothing. Where the boundaries fall is workload-specific. OpenAI puts it this way: “the limits of this massive data parallelism seem to differ from domain to domain, ranging from batches of tens of thousands in ImageNet to batches of millions in RL agents that play the game Dota 2”. Six model families, three training algorithms and seven data sets produced the same three-region shape and no shared number. The curve is the deliverable. The crossover is not.
1. Choose batch regimes
Vary global batch through workers, micro-batch, and accumulation deliberately.
2. Define matched budgets
Compare equal examples or tokens and a fixed validation protocol.
3. Retune rate and warmup
Test scaling heuristics against direct local search.
4. Preserve state semantics
Align schedules, clipping, EMA, normalization, and optimizer steps.
5. Measure several axes
Report throughput, utilization, communication, time to quality, and final metrics.
6. Locate diminishing returns
Identify where extra batch no longer reduces useful training time.
Key takeaways
- Larger batches reduce gradient sampling variance and reduce optimizer-step frequency at the same time, and the resulting curve has one reproducible shape: perfect scaling, then diminishing returns, then a regime where extra parallelism buys nothing. Shallue and colleagues found it in every workload they measured.
- Linear and square-root scaling are not competing theories but a theory and the heuristic that outperformed it, in Krizhevsky's April 2014 note, where he wrote “I can’t explain this discrepancy between theory and practice.”
- The linear rule carries a measured envelope, not a guarantee: ResNet-50 on ImageNet at minibatch 8192 across 256 GPUs in one hour, with a five-epoch warmup that exists because the rule breaks down early in training, and a documented breakdown beyond 8192.
- Gradient accumulation matches a physical batch only when reductions, randomness, normalization, clipping and step-linked state align — Hugging Face Transformers did not until pull request #34191 was merged on 17 October 2024, with loss gaps measured at 0.45–0.70 in the worst case.
- The point of diminishing batch returns belongs to the run and moves inside it: OpenAI defined Bcrit = Emin/Smin and warned that the noise scale drifts, and Ai2 later measured OLMo's critical batch size plateauing near 4096 while the noise-scale proxy failed to track it.
- Scaling reports should include tuning cost, hardware, precision, global batch, evidence processed, time to quality and final validation behavior — 71,638,836 loss measurements over 168,160 models and 35 workloads is what that discipline cost the one team that did it exhaustively.