Mini-Batch Gradient Descent

Mini-Batch Gradient Descent is an optimization algorithm that updates model parameters using the gradient of a loss function estimated on small, randomly selected subsets ("mini-batches") of the training data. Key result: it combines the low-variance updates of full-batch gradient descent with the computational efficiency and noise-driven exploration of stochastic gradient descent, making it the de facto training method for deep neural networks. Applies to large-scale machine learning, deep learning, and any empirical-risk-minimization problem. Who/when: crystallized in the 2000s–2010s deep learning era, building on Robbins–Monro stochastic approximation (1951).

Mini-batch gradient descent minimizes an objective (an average over training examples) by repeatedly stepping in the direction of the negative gradient — but estimating that gradient from a random subset of examples rather than all . It matters because computing the exact gradient over millions of examples per step is prohibitively expensive, while using a single example yields gradients too noisy to converge smoothly. The surprising fact: the noise introduced by mini-batching is not merely a tolerated cost but a feature — it helps escape saddle points and shallow local minima, and acts as an implicit regularizer. Mini-batching also maps perfectly onto the parallel arithmetic of GPUs, where a batch of examples is processed as one matrix multiplication. It is the workhorse beneath nearly every modern trained neural network.

The Core Insight

The true gradient is an average over all training examples. Any unbiased random subset gives an unbiased estimate of that average whose variance shrinks like . Mini-batch gradient descent exploits this: pick a batch size large enough to tame variance and saturate hardware parallelism, but small enough that you take many cheap, frequent steps per pass through the data. You trade a little gradient accuracy for vastly more updates — and the leftover noise often helps.

Formal Statement

Empirical Risk and Mini-Batch Estimate

Let the training set be with per-example loss . The empirical risk (full objective) is

1
⟳this is the sample average of per-example losses; it estimates the true risk .

A mini-batch of size is drawn (usually without replacement) from the training indices. The mini-batch gradient estimate is

2
⟳replace the average over all examples in with an average over the sampled examples.

The update rule at iteration , with learning rate , is

3
⟳standard gradient-descent step but with the noisy estimate substituted for the exact gradient .
Symbols: parameters; total examples; batch size; the batch at step ; learning rate (step size); mini-batch gradient. Special cases: is full-batch gradient descent; is stochastic gradient descent (SGD).

Unbiasedness and Variance Reduction

If the batch indices are drawn uniformly at random, then the mini-batch gradient is an unbiased estimator of the full gradient:

4
⟳linearity of expectation; each index has equal probability of inclusion, so its average loss-gradient equals the population average.

Moreover, for sampling with replacement (or large- approximation), the per-coordinate variance scales as

5

where is the variance of a single example's gradient.

⟳variance of the mean of i.i.d. samples is the single-sample variance divided by .

Why It Holds / Derivation

Unbiasedness (Eq. 4) and Variance (Eq. 5)

Step 1 — Setup. Let contain indices each drawn uniformly from (with replacement for simplicity). For a single draw , the probability . Step 2 — Expectation of one term. For any single sampled index ,
Step 3 — Expectation of the average. By linearity,
establishing Eq. [4]. Step 4 — Variance. Since the draws are i.i.d. with single-draw variance ,
giving Eq. [5]. Step 5 — Without-replacement correction. When sampling without replacement from a finite set of size , multiply by the finite-population correction factor . For this is , recovering the law.

Herbert Robbins & Sutton Monro | 1951

Although mini-batch GD is a 21st-century computational staple, its theoretical bedrock is the Robbins–Monro stochastic approximation scheme. Robbins (a statistician and topologist) and Monro showed that you can find the root of an unknown function using only noisy measurements, provided the step sizes satisfy and . This established that noisy gradient updates can converge — the licence under which all of SGD and mini-batch GD operate.

Building Intuition

Imagine you want the average opinion of a city of people, but polling everyone takes a day. Polling one person (SGD) is instant but wildly unrepresentative; polling everyone (full-batch) is accurate but glacial. Polling a random people (mini-batch) gives an answer that's almost as accurate as the full poll — its error shrinks like — but costs almost nothing. You can re-poll every few minutes and steadily refine your estimate of where to move.

Now picture the loss landscape as a foggy mountain. Full-batch descent walks downhill perfectly but pauses forever at every flat ledge (saddle point) and small dip (local minimum). Mini-batch's gradient jitter is like an occasional gust of wind: it knocks you off ledges and out of shallow dips, helping you find deeper valleys — while still trending downhill on average.

Loss vs. iterations: full-batch (smooth), SGD (very noisy), mini-batch (a balanced compromise).

Iterations → Loss L(θ) full-batch (smooth, slow/expensive) SGD (m=1, very noisy) mini-batch (m=256) — fast + stable

Worked Examples

Linear regression, one mini-batch step

Given: Model (single weight, no bias). Squared loss , so . Current , learning rate . A mini-batch of :
Steps:
  1. Per-example gradients at :
- -
  1. Mini-batch gradient (Eq. 2):
  2. Update (Eq. 3):
Answer:
The weight increased because both predictions were too low (residuals negative), so the negative gradient pushes up.

Variance reduction by batch size

Given: Suppose the single-example gradient (a scalar) has standard deviation at the current . Compare the standard deviation of the gradient estimate for , , (sampling with replacement, large). Steps:
  1. From Eq. [5], , so .
Answer:
Note the diminishing return: going from cuts noise 8×; going (4× the compute) only halves it. This law motivates moderate batch sizes.

Common Misconceptions

Bigger batches are not always better

A common belief is "larger → better, since the gradient is more accurate." But:

  • Variance only falls like , so doubling doubles compute for a noise reduction — diminishing returns.
  • Very large batches lose the beneficial noise that helps escape saddle points and shallow minima, often converging to sharper minima that generalize worse (the "large-batch generalization gap").
  • The learning rate must usually be rescaled with batch size (e.g., the linear scaling rule: ). Forgetting this makes large-batch training diverge or stall.
There is no universally optimal ; common choices are 32–512, tuned empirically.

Mini-batch gradient ≠ exact gradient direction

It is tempting to treat each mini-batch step as "downhill on ." It is only downhill in expectation. Consider with gradients and at some point. The true gradient is — pointing in . But a mini-batch of just gives , moving the parameters in the direction, completely orthogonal to (and uncorrelated with) the true descent direction. Individual mini-batch steps can temporarily increase the full loss; only their average trends downward.

Connections

Mini-batch GD sits at the center of a family of methods. It generalizes Stochastic Gradient Descent () and Gradient Descent|Full-Batch Gradient Descent (). Its noisy updates are analyzed through Stochastic Approximation (Robbins–Monro) and modeled as a Stochastic Differential Equation|continuous-time SGD diffusion. Practically, it is the base on which Momentum (Optimization), Adam Optimizer, and RMSProp build adaptive or accelerated variants. Its computation relies on Backpropagation to obtain efficiently, and its objective is the Empirical Risk Minimization framework. The implicit regularization it provides connects to Generalization (Machine Learning) and the flat-vs-sharp-minima debate.

Real-World Applications

  1. Deep neural network training (vision): Convolutional networks like ResNet are trained on ImageNet with mini-batches (commonly ) distributed across GPUs.
  2. Large language models: Transformers (GPT, BERT) are trained with massive effective batch sizes (thousands to millions of tokens) assembled by gradient accumulation across many devices.
  3. Recommender systems: Matrix-factorization and deep recommenders (e.g., YouTube, Netflix) use mini-batch updates over user–item interaction logs that are far too large to fit in memory at once.
  4. Reinforcement learning: Deep Q-Networks (DQN) sample mini-batches from an experience replay buffer to stabilize and decorrelate updates.
  5. Speech recognition: End-to-end acoustic models (e.g., DeepSpeech) train on mini-batches of variable-length audio utterances.
  6. Generative models: GANs and diffusion models alternate mini-batch updates for generator/discriminator or denoiser networks.
  7. On-device / federated learning: Mobile keyboards train local mini-batch updates on user data, aggregating gradients centrally.

Historical Development

  • 1847 — Cauchy proposes the method of steepest (gradient) descent for solving systems of equations.
  • 1951 — Robbins & Monro publish A Stochastic Approximation Method, proving convergence of root-finding with noisy measurements; the theoretical foundation for SGD.
  • 1952 — Kiefer & Wolfowitz extend stochastic approximation to gradient-free optimization of noisy objectives.
  • 1960s–1980s — Stochastic gradient methods used in adaptive filtering (Widrow–Hoff LMS) and early neural network learning.
  • 1986 — Rumelhart, Hinton & Williams popularize Backpropagation, enabling efficient per-example gradients in multilayer networks.
  • 1998 — LeCun et al.'s Efficient BackProp gives practical advice on stochastic/mini-batch training and learning-rate schedules.
  • 2010 — Bottou's work on large-scale learning argues SGD/mini-batch methods are optimal for big data given fixed compute budgets.
  • 2012 — AlexNet trains on GPUs with mini-batches, igniting the deep learning era and cementing mini-batch GD as standard practice.
  • 2017 — Goyal et al. demonstrate the linear scaling rule, training ImageNet in 1 hour with batch size 8192, clarifying how to scale with .

Subtleties & Limits

Several questions about mini-batch GD remain active research:

  • Optimal batch size theory: Why moderate batches generalize better than huge ones — the precise mechanism linking gradient noise to flat minima and generalization — is not fully understood.
  • SGD as approximate inference: Whether mini-batch noise can be rigorously characterized as sampling from a Bayesian posterior (the "SGD-as-MCMC" view) is only partially resolved.
  • Adaptive batch sizing: Principled, automatic schedules that grow during training (to reduce noise as you approach a minimum) lack a complete theory.
  • Non-convex convergence rates: Tight, instance-dependent bounds for mini-batch GD on the highly non-convex, over-parameterized landscapes of deep nets remain open.
  • Heavy-tailed gradient noise: Empirically, mini-batch gradient noise is often heavy-tailed (non-Gaussian), challenging the standard finite-variance assumption behind Eq. [5] and its diffusion approximations.

See Also

Stochastic Gradient Descent · Gradient Descent · Stochastic Approximation · Adam Optimizer · Backpropagation · Empirical Risk Minimization · Generalization (Machine Learning) · Learning Rate Scheduling

Before this

Where this leads