Simple Algorithm
Deep Learning · Emergence · 26 min

Early Stopping & Regularization by Time

Training time as a regularizer: spectral filtering, ridge equivalence and label noise.

Stop training early and you get a regularized model for free. For least squares this is exact mathematics: gradient descent is a spectral filter, and its risk is never more than 1.69 times that of ridge regression at matched tuning, whatever the data. For deep networks it rests on a regularity with theory behind it: networks fit the clean structure of the data before they memorize its noise. But validation curves can mislead, and picking the best checkpoint has statistics of its own.

What you’ll learn

  • Derive gradient descent's spectral filter on least squares from any initialization, its effective degrees of freedom, and the calibration λ≈1/(ηt)\lambda\approx1/(\eta t) with ridge.
  • State and prove that gradient flow's risk is at most 1.68621.6862 times ridge's at λ=1/τ\lambda=1/\tau, and state the 1.21471.2147 factor for optimally tuned Bayes risks (Ali, Kolter & Tibshirani, 2019).
  • Explain why early-stopped networks resist label noise, from the experiments of Arpit et al. (2017) to the bimodal-Jacobian theorem of Li, Soltanolkotabi and Oymak (2020).
  • Recognize when validation curves mislead, and quantify the optimism of selecting the best of many checkpoints.

Gradient descent as a spectral filter

Work with least squares, L(w)=12n∥y−Xw∥2\loss(\mathbf w)=\frac1{2n}\norm{\mathbf y-X\mathbf w}^2, under the model y=Xw⋆+ε\mathbf y=X\mathbf w^\star+\boldsymbol\varepsilon with Eε=0\E\boldsymbol\varepsilon=\mathbf 0 and Cov⁡ε=σ2I\Cov\boldsymbol\varepsilon=\sigma^2I, and a fixed design with Σ^=X⊤X/n=∑jsjvjvj⊤\hat\Sigma=X^\top X/n=\sum_js_j\mathbf v_j\mathbf v_j^\top. Let w^=Σ^+X⊤y/n\hat{\mathbf w}=\hat\Sigma^{+}X^\top\mathbf y/n be the minimum-norm least-squares solution, so that ∇L(w)=Σ^(w−w^)\nabla\loss(\mathbf w)=\hat\Sigma(\mathbf w-\hat{\mathbf w}). The Representation lesson started gradient descent at zero; here start anywhere.

DerivationThe filter, from any initialization
  1. wt=w^+(I−ηΣ^)t(w0−w^)\mathbf w_t=\hat{\mathbf w}+(I-\eta\hat\Sigma)^t(\mathbf w_0-\hat{\mathbf w})

    Each step contracts the distance to w^\hat{\mathbf w} by the same matrix:

  2. vj⊤wt=φt(sj) vj⊤w^+(1−φt(sj)) vj⊤w0,φt(s)=1−(1−ηs)t≈1−e−ηts\mathbf v_j^\top\mathbf w_t=\varphi_t(s_j)\,\mathbf v_j^\top\hat{\mathbf w}+\big(1-\varphi_t(s_j)\big)\,\mathbf v_j^\top\mathbf w_0,\qquad\varphi_t(s)=1-(1-\eta s)^t\approx1-e^{-\eta ts}

    Along each eigenvector, the coordinate interpolates between its starting value and its least-squares value, with weight φt(sj)\varphi_t(s_j) on the latter:

  3. df⁡(t)=Tr⁡St=∑jφt(sj),\operatorname{df}(t)=\Tr S_t=\sum_j\varphi_t(s_j),

    Ridge, wλ=arg min⁡wL(w)+λ2∥w∥2\mathbf w_\lambda=\argmin_{\mathbf w}\loss(\mathbf w)+\frac\lambda2\norm{\mathbf w}^2, applies ψλ(s)=s/(s+λ)\psi_\lambda(s)=s/(s+\lambda) instead. In the variable x=ηtsx=\eta ts and with λ=1/(ηt)\lambda=1/(\eta t), the two filters are 1−e−x1-e^{-x} and x/(1+x)x/(1+x). Started from w0=0\mathbf w_0=\mathbf 0, the fitted values are Xwt=StyX\mathbf w_t=S_t\mathbf y for a smoother matrix with trace

  4. the effective degrees of freedom, which grow from 00 toward rank⁡X\rank X as training runs: training time counts how many directions have been fitted. Two consequences. Early stopping shrinks toward the initialization, so when fine-tuning it regularizes toward the pretrained weights. And directions with sj=0s_j=0 never move: from w0=0\mathbf w_0=\mathbf 0 with more features than examples, gradient descent converges to the minimum-norm interpolant, an implicit bias taken up in The Generalization Puzzle.

x=ηtsx=\eta tsGradient descent: 1−e−x1-e^{-x}Ridge at λ=1/(ηt)\lambda=1/(\eta t): x/(1+x)x/(1+x)
0.10.0950.091
0.30.2590.231
10.6320.500
30.9500.750
101.0000.909
Both filters pass strong directions and suppress weak ones, but gradient descent's is sharper, closer to a hard keep-or-drop cutoff such as principal components regression, while ridge also shrinks the strong directions noticeably.
Predict before you look

Gradient descent with η=0.1\eta=0.1 starts at zero on a least-squares problem. After t=20t=20 steps, what fraction of the least-squares coefficient along an eigenvector with eigenvalue s=0.5s=0.5 has it fitted?

Show the answer

0.64

φ=1−(1−0.1×0.5)20=1−0.9520≈0.642\varphi=1-(1-0.1\times0.5)^{20}=1-0.95^{20}\approx0.642. The continuous approximation 1−e−ηts=1−e−1≈0.6321-e^{-\eta ts}=1-e^{-1}\approx0.632 is close, and ridge at the matched λ=1/(ηt)=0.5\lambda=1/(\eta t)=0.5 would keep 0.5/(0.5+0.5)=0.50.5/(0.5+0.5)=0.5.

Within a constant factor of ridge

How close is "like ridge"? Ali, Kolter and Tibshirani (2019) compared the two exactly, using gradient flow, w˙(τ)=−∇L(w(τ))\dot{\mathbf w}(\tau)=-\nabla\loss(\mathbf w(\tau)) from w(0)=0\mathbf w(0)=\mathbf 0: the limit of gradient descent as η→0\eta\to0 with τ=ηt\tau=\eta t fixed. Gradient flow gives w^gf(τ)=Σ^+(I−e−τΣ^)X⊤y/n\hat{\mathbf w}^{\text{gf}}(\tau)=\hat\Sigma^{+}\big(I-e^{-\tau\hat\Sigma}\big)X^\top\mathbf y/n.

DerivationProof of the 1.6862 bound
  1. gf:  aj2 e−2xj+σ2n (1−e−xj)2sj,ridge(λ=1/τ):  aj2(1+xj)2+σ2n xj2(1+xj)2 sj\text{gf: }\ a_j^2\,e^{-2x_j}+\frac{\sigma^2}{n}\,\frac{(1-e^{-x_j})^2}{s_j},\qquad\text{ridge}(\lambda=1/\tau)\text{: }\ \frac{a_j^2}{(1+x_j)^2}+\frac{\sigma^2}{n}\,\frac{x_j^2}{(1+x_j)^2\,s_j}

    In the eigenbasis, with aj=vj⊤w⋆a_j=\mathbf v_j^\top\mathbf w^\star and xj=τsjx_j=\tau s_j, both risks split into a squared bias and a variance per direction:

  2. e−x≤11+x,1−e−x≤1.2985 x1+xe^{-x}\le\frac{1}{1+x},\qquad1-e^{-x}\le1.2985\,\frac{x}{1+x}

    Two scalar inequalities for x≥0x\ge0 compare them term by term. The first follows from ex≥1+xe^{x}\ge1+x; the second holds because (1−e−x)(1+x)/x(1-e^{-x})(1+x)/x peaks at about 1.29851.2985, near x≈1.79x\approx1.79:

  3. Risk(w^gf(τ))≤∑j[aj2(1+xj)2+1.6862 σ2n xj2(1+xj)2sj]≤1.6862 Risk(w^1/τ)\text{Risk}\big(\hat{\mathbf w}^{\text{gf}}(\tau)\big)\le\sum_j\Big[\frac{a_j^2}{(1+x_j)^2}+1.6862\,\frac{\sigma^2}{n}\,\frac{x_j^2}{(1+x_j)^2s_j}\Big]\le1.6862\,\text{Risk}\big(\hat{\mathbf w}_{1/\tau}\big)

    Squaring, each bias term of gradient flow is at most ridge's, and each variance term at most 1.29852≤1.68621.2985^2\le1.6862 times ridge's. Summing over jj proves the bound. No constant below 1 is possible: ridge with λ=1/τ\lambda=1/\tau is the Bayes estimator under an isotropic Gaussian prior, hence admissible, so gradient flow cannot beat it at every w⋆\mathbf w^\star. Gradient flow is a Bayes estimator too, for a Gaussian prior that depends on the design, so neither method dominates the other.

Beyond finite dimensions, early stopping is a statistically sound regularizer in its own right. For least squares in a reproducing kernel Hilbert space, where gradient descent is the classical Landweber iteration, the stopping time plays the role of 1/λ1/\lambda (Yao, Rosasco & Caponnetto, 2007). Raskutti, Wainwright and Yu (2014) gave a stopping rule computed from the eigenvalues of the empirical kernel matrix and the noise level, with no hold-out set, that attains minimax-optimal rates: for kernels whose eigenvalues decay like j−2νj^{-2\nu}, a squared error of order (σ2/n)2ν/(2ν+1)(\sigma^2/n)^{2\nu/(2\nu+1)}. And a single run traces the whole regularization path, where ridge needs one fit per λ\lambda.

Check your understanding

What does the Ali–Kolter–Tibshirani theorem guarantee?

  1. Gradient descent always has lower risk than ridge
  2. Gradient flow stopped at time τ\tau never has more than about 1.69 times the risk of ridge with λ=1/τ\lambda=1/\tau, for any design and any true parameter
  3. Gradient flow and ridge give identical estimates when λ=1/τ\lambda=1/\tau
  4. The bound holds only when the features are uncorrelated
Show the answer

B. Gradient flow stopped at time τ\tau never has more than about 1.69 times the risk of ridge with λ=1/τ\lambda=1/\tau, for any design and any true parameter

The comparison is term by term in the eigenbasis of any XX, so it needs no assumption on the design or on w⋆\mathbf w^\star. The filters differ, so the estimates differ, but their risks cannot differ by more than the constant.

Deep networks fit signal before noise

Early stopping works in deep networks too, and for a related reason. Arpit et al. (2017) compared training on real data with training on noise (random labels or random inputs). On real data, networks fitted examples in a largely consistent order across runs, learning patterns shared by many examples first; fitting noise needed more capacity and more time, and tuned explicit regularization such as dropout slowed the memorization of noise while barely affecting generalization on real data. Zhang et al. (2017) had noticed the same slowdown on random labels.

A linearized network makes this exact. Near its initialization a network is approximately linear in its parameters, f(θ)≈f(θ0)+J(θ−θ0)f(\boldsymbol\theta)\approx f(\boldsymbol\theta_0)+J(\boldsymbol\theta-\boldsymbol\theta_0), with JJ the Jacobian of the outputs on the training set. Gradient descent on the squared loss then evolves the vector of training residuals rt=f(θt)−y\mathbf r_t=f(\boldsymbol\theta_t)-\mathbf y as

rt+1=(I−η JJ⊤) rt⟹uk⊤rt=(1−ημk)t uk⊤r0\mathbf r_{t+1}=\big(I-\eta\,JJ^\top\big)\,\mathbf r_t\qquad\Longrightarrow\qquad\mathbf u_k^\top\mathbf r_t=(1-\eta\mu_k)^t\,\mathbf u_k^\top\mathbf r_0
The same spectral filter as least squares, now with the eigenpairs (μk,uk)(\mu_k,\mathbf u_k) of the Gram matrix JJ⊤JJ^\top (the neural tangent kernel on the training set). Whatever part of the labels lies along large-μk\mu_k directions is fitted fast; parts along small-μk\mu_k directions are fitted slowly.

The mechanism is the filter above. The Jacobian is approximately low-rank and bimodal: a few large singular values on a signal subspace aligned with the cluster structure, and small ones elsewhere. Clean labels are constant within clusters and lie almost entirely in the signal subspace; corruption varies within clusters and projects mostly onto the small singular values, so it is fitted slowly, and fitting it requires moving far from initialization. Li et al. also found such bimodal Jacobian spectra in networks on CIFAR-10, with only a small number of large singular values, even at random initialization. The result lives in the near-initialization regime; for networks that learn features far from initialization, the "signal first" ordering is an empirical regularity rather than a theorem.

Check your understanding

In the bimodal-Jacobian picture, why does early stopping protect against corrupted labels?

  1. Corrupted examples have larger gradients, so they are fitted first and then forgotten
  2. Gradient descent ignores examples whose labels disagree with their cluster
  3. The network's capacity is too small to fit corrupted labels at any stage
  4. The corruption's residual lies mostly along directions with small singular values, which gradient descent fits slowly
Show the answer

D. The corruption's residual lies mostly along directions with small singular values, which gradient descent fits slowly

Residual components shrink like (1−ημk)t(1-\eta\mu_k)^t. Clean labels sit in the fast, large-μk\mu_k subspace; corruption mostly in the slow one. Stopping before the slow directions are fitted keeps the clean fit and discards most of the noise.

When the validation curve misleads

Early stopping assumes the validation curve is U-shaped. It need not be. Nakkiran et al. (2020) found epoch-wise double descent: for large networks trained on data with label noise, test error can fall, rise in mid-training, and fall again, so stopping at the first minimum, or with short patience, stops too early. They proposed, as a unifying hypothesis, that what matters is an effective model complexity, the largest number of examples a training procedure can fit to near-zero error, which grows with training time just as it grows with model size.

A second trap is statistical. The early-stopped checkpoint is the one with the lowest validation error among many, and the minimum of noisy estimates is biased downward. If KK checkpoints had independent validation estimates with standard error svs_v, the best one would look better than it is by about svs_v times the expected maximum of KK standard normals, which is at most 2ln⁡K\sqrt{2\ln K}.

Predict before you look

You select the best of K=100K=100 checkpoints whose validation error estimates are independent, each with a standard error of 1 percentage point, and all with the same true error. By about how many points is the selected checkpoint's validation error optimistic?

Show the answer

2.5 points

The expected maximum of 100 independent standard normals is about 2.51 (a simulation of 20,000 draws gives 2.507), below the bound 2ln⁡100≈3.03\sqrt{2\ln100}\approx3.03. For scale: an error rate of 10% measured on 1,000 validation examples has a standard error of 0.1×0.9/1000≈0.95\sqrt{0.1\times0.9/1000}\approx0.95 points. Checkpoints along one run are strongly correlated, so their bias is smaller, but sweeps over many runs and hyperparameters behave more like independent draws. The remedy is a test set that played no part in the choice.

Key takeaways

  • On least squares, gradient descent multiplies each eigen-coordinate by φt(s)=1−(1−ηs)t\varphi_t(s)=1-(1-\eta s)^t, interpolating between the initialization and the least-squares solution: a spectral filter like ridge's s/(s+λ)s/(s+\lambda) with λ≈1/(ηt)\lambda\approx1/(\eta t), but sharper, and anchored at the starting point.
  • Gradient flow's risk is at most 1.68621.6862 times ridge's at λ=1/τ\lambda=1/\tau, for any design and any truth; at optimal tuning under an isotropic prior the ratio lies in [1,1.2147][1,1.2147] (Ali, Kolter & Tibshirani, 2019). In kernel regression, data-dependent stopping attains minimax rates.
  • Near initialization a network's residuals evolve as (I−ηJJ⊤)tr0(I-\eta JJ^\top)^t\mathbf r_0; with a bimodal Jacobian, clean labels are fitted fast and corruptions slowly, so early-stopped gradient descent provably corrects a constant fraction of corrupted labels on clustered data (Li, Soltanolkotabi & Oymak, 2020).
  • Validation curves can show epoch-wise double descent (Nakkiran et al., 2020), and the best of KK checkpoints is optimistic by up to about 2ln⁡K\sqrt{2\ln K} standard errors: report a separate test set.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Gradient descent on least squares starts from pretrained weights w0≠0\mathbf w_0\ne\mathbf 0 and is stopped early. Toward what does early stopping regularize the solution?

  1. Toward zero, like ridge
  2. Toward the minimum-norm least-squares solution
  3. Toward the starting point w0\mathbf w_0: weakly determined directions stay near their initial values
  4. Toward nothing: early stopping only saves compute
Show the answer

C. Toward the starting point w0\mathbf w_0: weakly determined directions stay near their initial values

Each eigen-coordinate is φt(sj)\varphi_t(s_j) times its least-squares value plus 1−φt(sj)1-\varphi_t(s_j) times its starting value. Weak directions keep most of their initial value, which is why early stopping in fine-tuning keeps a model close to its pretrained weights.

Question 2

Under an isotropic prior on w⋆\mathbf w^\star, gradient flow and ridge are each tuned to their best stopping time or penalty. How do their optimal Bayes risks compare?

  1. Gradient flow's is always exactly equal to ridge's
  2. Gradient flow's can be arbitrarily worse than ridge's
  3. Gradient flow's is always strictly better
  4. Gradient flow's is at least ridge's and at most 1.2147 times it
Show the answer

D. Gradient flow's is at least ridge's and at most 1.2147 times it

Ali, Kolter and Tibshirani show 1≤inf⁡τRiskgf/inf⁡λRiskridge≤1.21471\le\inf_\tau\text{Risk}_{\text{gf}}/\inf_\lambda\text{Risk}_{\text{ridge}}\le1.2147 in that setting: at optimal tuning the two are nearly interchangeable.

Question 3

Training a large network on data with noisy labels, you see the validation error fall, then rise for many epochs. What should you consider before stopping?

  1. Epoch-wise double descent: the error may fall again later, so use longer patience or keep evaluating
  2. Nothing: a rising validation error always means the best model is behind you
  3. Switching to the test set to decide
  4. Increasing the learning rate to get past the bump faster, then evaluating on the training set
Show the answer

A. Epoch-wise double descent: the error may fall again later, so use longer patience or keep evaluating

Nakkiran et al. (2020) observed test error that rises and then falls again over training, most visibly with label noise. A U-shaped curve is a common case, not a guarantee.

Question 4

Your early-stopping rule picked the checkpoint with the lowest validation error out of 200 evaluations. How should you report its performance?

  1. Report its validation error: it was measured on held-out data
  2. Report the average validation error over all 200 checkpoints
  3. Evaluate it once on a separate test set that played no role in the selection
  4. Report its training error, which is the most stable estimate
Show the answer

C. Evaluate it once on a separate test set that played no role in the selection

Selecting the minimum of many noisy estimates biases that minimum downward, by up to a few standard errors. Only data untouched by the choice give an unbiased estimate.

Further reading

  • A. Ali, J. Z. Kolter & R. J. Tibshirani, "A continuous-time view of early stopping for least squares regression," AISTATS (2019).
  • Y. Yao, L. Rosasco & A. Caponnetto, "On early stopping in gradient descent learning," Constructive Approximation 26, 289–315 (2007).
  • G. Raskutti, M. J. Wainwright & B. Yu, "Early stopping and non-parametric regression: an optimal data-dependent stopping rule," Journal of Machine Learning Research 15, 335–366 (2014).
  • D. Arpit, S. Jastrzębski, N. Ballas, D. Krueger, E. Bengio, M. S. Kanwal, T. Maharaj, A. Fischer, A. Courville, Y. Bengio & S. Lacoste-Julien, "A closer look at memorization in deep networks," ICML (2017).
  • M. Li, M. Soltanolkotabi & S. Oymak, "Gradient descent with early stopping is provably robust to label noise for overparameterized neural networks," AISTATS (2020).
  • P. Nakkiran, G. Kaplun, Y. Bansal, T. Yang, B. Barak & I. Sutskever, "Deep double descent: where bigger models and more data hurt," ICLR (2020).