Systems / Training
verifiedGradient Accumulation
Sometimes the batch size a run needs does not fit in memory. Gradient accumulation runs several smaller batches, adds their gradients together, and only then takes a step — the same update as one large batch, spread over several forward passes.
Skip the optimizer step for k micro-batches and divide the accumulated gradient by k. It buys effective batch size at the cost of wall-clock. The usual caveat — that a normalization layer computing statistics per micro-batch sees a smaller batch than intended — is about batch normalization, and does not apply to a transformer: layer norm and RMSNorm normalize across features within one position, so they never look at the batch at all.
g = (1/k)Σ sub i=1..k ∇L sub B sub i , then one step. Mathematically identical to a batch of size k|B| for the gradient, and for a transformer identical outright, since nothing in the forward pass computes a statistic over the batch.
microbatches holds 50% of the budget; rest holds the remaining 50%.
Share of memory the activations take against everything else held during a step. Drag the micro-batch count to watch peak memory fall while the step takes longer.
Reviewed by opendroid · 2026-08-04
- arXiv:1706.02677 — Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour