Three flavors of gradient descent
Batch (full) gradient descent — compute the gradient on the entire dataset, take one step, repeat. Smooth, but expensive (one gradient per epoch) and impossible for datasets that do not fit in memory.
Stochastic gradient descent (SGD) — compute the gradient on one example at a time, take a step, repeat. Noisy, fast, hard to use the GPU efficiently.
Mini-batch SGD — compute the gradient on a small batch (16, 32, 256, ...), take a step. Noisy enough to escape some local minima, smooth enough to be stable, batched enough to use the GPU. This is what everyone actually does.
Why noise helps generalization
The randomness in mini-batch sampling acts as an implicit regularizer. The optimizer follows a noisy estimate of the true gradient, which keeps it from settling too aggressively into sharp local minima — and sharp minima generalize worse than flat ones. This is why mini-batch SGD often generalizes better than the smoother full-batch update, even when it converges to a higher training loss.
Modern optimizer-aware mini-batches
Modern optimizers (Adam, AdamW) maintain per-parameter running estimates of the gradient mean and variance, which makes the choice of batch size less critical for stable training. You still tune it for hardware (memory, throughput) and for generalization (smaller batches often regularize better), but you no longer have to baby-sit the optimizer through wild gradient noise.