Abstract
In deep learning, overparameterized models often generalize remarkably well despite having the capacity to memorize training data. A persistent mystery in optimization is why Stochastic Gradient Descent (SGD) consistently outperforms full-batch Gradient Descent (GD) in terms of test-set performance. This paper provides a theoretical explanation for this phenomenon by analyzing the discrete update dynamics of these algorithms. We demonstrate that SGD introduces a systematic "drift" that acts as an implicit regularizer, effectively pushing the model away from configurations that overfit the training data. By deriving a relationship between the gradient covariance and the generalization gap, we show that SGD effectively optimizes a modified loss function that penalizes the divergence between training and test performance.
Introduction
The success of modern deep learning relies on the ability of models to generalize to unseen data, even when the number of parameters far exceeds the number of training examples. Theoretically, such models should be prone to overfitting, yet the optimization process—specifically the use of Stochastic Gradient Descent (SGD)—appears to provide an inherent regularizing effect.
While previous theories have suggested that SGD's stochasticity helps it escape "sharp" minima in favor of "flat" ones, this paper seeks a more fundamental, model-independent mathematical reason for this phenomenon. By shifting the focus from the static geometry of the loss landscape to the discrete update dynamics of the learning process, we can quantify how individual updates change the "generalization gap"—the difference between training and test error.
Theoretical Framework
To understand the difference between GD and SGD, we treat both algorithms within a unified stochastic framework, considering averages over all possible realizations of the training set. Unlike many previous works that treat training as a continuous flow (the "continuum limit"), this analysis focuses on discrete steps. This is crucial because the relationship between batch size and learning rate is often lost in continuous approximations.
Our methodology relies on several key assumptions:
- Central Limit Theorem (CLT): For sufficiently large batch sizes, the distribution of the gradient estimator is assumed to be Gaussian.
- Taylor Expansion: We expand the loss function in terms of the learning rate ($\eta$) to calculate the expected change in loss after a single update.
- Discrete Dynamics: We analyze the step-by-step evolution of the model parameters to identify systematic biases that emerge over time.
The Overfitting Bias of Gradient Descent
A primary finding of this research is that full-batch Gradient Descent possesses an inherent "overfitting bias." In GD, every update is calculated using the entire training set. Over time, these updates become increasingly correlated with the specific noise and quirks of that training set. This correlation systematically increases the generalization gap, as the model parameters are driven toward configurations that minimize the training loss at the expense of test performance.
SGD as Implicit Regularization
In contrast to GD, SGD uses small "mini-batches" to estimate gradients. While this is often described as adding "noise" or "diffusion" to the learning process, we argue that the primary benefit is actually a systematic "drift."
The Generalization Formula
We derive a simple formula for the average change in the generalization gap ($\delta\epsilon$) per update: $$\langle \delta\epsilon \rangle = \eta \frac{\text{tr } \Sigma}{N} + O(\eta^2)$$
This formula reveals that the gap grows proportionally to the learning rate ($\eta$) and the trace of the gradient covariance matrix ($\text{tr } \Sigma$), while shrinking as the training set size ($N$) increases. The gradient covariance ($\Sigma$) represents the fluctuations in the gradient across different mini-batches. This suggests that the "noise" in SGD is not merely a nuisance; its mathematical structure directly determines the rate of regularization.
Decorrelation and Drift
SGD works by "decorrelating" nearby updates. Because each mini-batch provides a different sample of the data, the model cannot easily develop the same systematic bias toward the specific quirks of the full training set that GD does. Our main result shows that the difference between an SGD update and a GD update is equivalent to the derivative of the generalization error: $$\langle \delta g_i \rangle = -\frac{1}{2} \partial_i \langle \delta\epsilon \rangle$$
This implies that SGD is effectively performing gradient descent on a modified loss function that explicitly penalizes the generalization gap. In essence, the stochasticity of the mini-batches forces the model to stay in regions where the training and test gradients are aligned.
Discussion and Future Work
This work suggests that the gap between training and test performance is not just a byproduct of the model architecture, but a controllable variable influenced by the optimization algorithm. By understanding the "drift" inherent in SGD, we can potentially design new optimization algorithms. For instance, one could use the inverse of the gradient covariance matrix as a "preconditioner" to slow down learning in directions where the gradient is highly unstable, further enhancing generalization.
However, there are limitations to this leading-order approximation. At very high learning rates, higher-order terms in the Taylor expansion may become significant. Additionally, as a model begins to overfit severely, the gradient distributions on the test and training sets will diverge, adding complexity that the current linear model may not fully capture. Future empirical work is needed to verify these theoretical predictions across various architectures and datasets.
Summary updated