ML & Deep Learning Foundations·Question 8 of 55Basic

What's the difference between batch, mini-batch, and stochastic gradient descent? What does batch size actually change?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Batch GD computes the exact gradient over the full dataset per step - accurate but one slow step per epoch and infeasible at scale. SGD (strictly, single-example) updates on one sample - very noisy, poor hardware utilisation. Mini-batch GD - what everyone actually runs - averages the gradient over a batch (dozens to millions of tokens), balancing gradient quality against throughput. Confusingly, practitioners call mini-batch training "SGD" too.

Full worked answer

Batch GD computes the exact gradient over the full dataset per step - accurate but one slow step per epoch and infeasible at scale. SGD (strictly, single-example) updates on one sample - very noisy, poor hardware utilisation. Mini-batch GD - what everyone actually runs - averages the gradient over a batch (dozens to millions of tokens), balancing gradient quality against throughput. Confusingly, practitioners call mini-batch training "SGD" too.

What batch size changes:

  • Gradient noise: variance of the gradient estimate scales ~1/batch size. Some noise is useful - it acts as implicit regularization and helps escape sharp minima; very large batches can generalize slightly worse without recipe adjustments.
  • LR coupling: bigger batches support (and need) larger learning rates. The linear scaling rule (multiply LR by k when multiplying batch by k, plus warmup) comes from Goyal et al.'s "ImageNet in 1 hour" work. Beyond a problem-dependent critical batch size (McCandlish et al., gradient-noise-scale analysis), extra batch parallelism stops buying faster convergence - you're just averaging already-clean gradients.
  • Hardware: larger batches improve accelerator utilisation; LLM pretraining uses enormous global batches (order of millions of tokens) via data parallelism, and gradient accumulation simulates large batches when memory is tight.

The interview trap: "bigger batch is always better." It isn't - per-step cost grows, per-step progress saturates past the critical batch size, and memory is finite. Batch size is a systems-and-optimization tradeoff, not a free knob.

What a good answer covers

  • Batch GD computes the exact gradient over the full dataset per step - accurate but one slow step per…
  • SGD (strictly, single-example) updates on one sample - very noisy, poor hardware utilisation
  • Mini-batch GD - what everyone actually runs - averages the gradient over a batch (dozens to millions of…
  • Confusingly, practitioners call mini-batch training "SGD" too
  • Gradient noise: variance of the gradient estimate scales ~1/batch size

Key terms: Batch GD · SGD · Mini-batch GD · Gradient noise · LR coupling · linear scaling rule · critical batch size · Hardware · gradient accumulation

Interviewer follow-ups to expect

  1. You double the batch size - what do you do to the learning rate and why?

  2. What is gradient accumulation actually equivalent to, and where does the equivalence break (hint: BatchNorm)?

  3. Why might a huge batch hurt generalization?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep