179 questions
No questions match those filters.
What is gradient accumulation, and what problem does it...
This is one of the questions in the full AI/ML interview bank. Pro unlocks all 1789 questions; Premium includes the same bank plus the highest daily Practice limit.
See plansLarge-batch training is often desirable for stable gradient estimates and to keep hardware busy, but memory is a hard constraint — activations and gradients for a large batch simply may not fit on a single GPU, especially with a big model. Gradient accumulation solves this without touching model size or requiring more hardware: run the forward and backward pass on a small mini-batch that does fit, but instead of calling the optimizer step immediately, add (“accumulate”) the resulting gradients into a running total across several mini-batches. Only after enough mini-batches have accumulated to match the desired effective batch size do you call the optimizer step and zero the gradients.
Mathematically this is nearly equivalent to having processed one large batch directly, because gradients are additive across data points — the main practical caveat is that batch-dependent operations like batch normalization statistics don’t benefit the same way, since they only see the small mini-batch at a time. The trade-off is time, not correctness: you get the training dynamics of a large batch, but each effective optimizer step now takes several sequential forward-backward passes instead of one, so wall-clock training time doesn’t shrink the way it would with genuinely more memory or more GPUs.