Module contents
Lesson 15 of 20Advanced 100 min

Implicit regularization: what gradient descent chooses

Study how optimization selects among infinitely many empirical-risk minimizers: minimum-norm least-squares GD, early stopping as ridge, maximum-margin logistic regression, and stability of SGD with few passes.

After this lesson you can

  • Prove that GD initialized in the row space of X converges to the minimum-norm solution X⁺y.
  • Relate early stopping to ridge by comparing filters 1 - (1 - ημ_i)^t and μ_i/(μ_i + λ).
  • State and numerically verify Soudry et al.’s directional maximum-margin convergence at rate 1/log t.
  • Prove the SGD stability bound for convex, Lipschitz and smooth losses (Hardt, Recht and Singer).
  • Explain with diagonal linear networks how implicit bias depends on parameterization and initialization scale.

Before you start

Motivation: train without a regularizer and still generalize

All theory in this topic so far controls risk by restricting the hypothesis class: a bounded-norm ball, an explicit penalty as in regularized loss minimization, or finite VC dimension. Modern practice does something else. A network with tens of millions of parameters trains with SGD on a loss without a regularization term until training error reaches zero, yet generalizes. In that regime empirical risk has infinitely many global minimizers, many poor out of sample, and the optimization problem alone does not say which is obtained.

The algorithm decides. Starting point, update geometry, parameterization and number of steps select a particular minimizer, and that minimizer is often the solution to a regularization problem nobody wrote down.

The lesson studies four cases where this rule can be stated precisely, three with complete proofs and classification with its essential argument, and a fifth where the rule has a different form:

  1. In least squares with more parameters than data, GD from zero converges to the minimum ℓ2\ell_2-norm interpolator, the same as ridge with λ→0+\lambda \to 0^+.
  2. Stopping GD at iteration tt applies a filter to each data eigendirection nearly identical to ridge with λ=1/(ηt)\lambda = 1/(\eta t).
  3. For classification with separable data, weight norm diverges and direction converges very slowly to the maximum-margin SVM.
  4. With parameterization w=u⊙u−v⊙v\vb{w} = \vb{u}\odot\vb{u} - \vb{v}\odot\vb{v}, initialization scale shifts bias from ℓ2\ell_2 to ℓ1\ell_1 without changing the function class or loss.
  5. SGD with few passes is uniformly stable, so it generalizes for a reason independent of any norm.

Overparameterized least squares: GD stays in the row space

Take X∈Rn×d\mat{X} \in \R^{n\times d} and y∈Rn\vb{y} \in \R^n and squared empirical risk

R^(w)=12n∥Xw−y∥22,∇R^(w)=1nX⊤(Xw−y)=Σ^w−1nX⊤y,\hat{R}(\vb{w}) = \frac{1}{2n}\norm{\mat{X}\vb{w} - \vb{y}}_2^2, \qquad \grad\hat{R}(\vb{w}) = \frac{1}{n}\mat{X}\T(\mat{X}\vb{w} - \vb{y}) = \hat{\mat{\Sigma}}\vb{w} - \frac{1}{n}\mat{X}\T\vb{y},

with Σ^=X⊤X/n\hat{\mat{\Sigma}} = \mat{X}\T\mat{X}/n and eigenvalues μ1≥⋯≥μd≥0\mu_1 \ge \dots \ge \mu_d \ge 0. If d>nd > n, Σ^\hat{\mat{\Sigma}} has at least d−nd - n zero eigenvalues, R^\hat{R} is not strictly convex and its minimizers form an affine subspace: w†+null⁡(X)\vb{w}^\dagger + \nullsp(\mat{X}), where w†=X+y\vb{w}^\dagger = \mat{X}\pinv\vb{y} is the pseudoinverse applied to y\vb{y}. If also rank⁡X=n\rank\mat{X} = n, all interpolate: Xw=y\mat{X}\vb{w} = \vb{y}.

The smallest case containing the whole idea has one equation and two unknowns: x⊤w=y\vb{x}\T\vb{w} = y with x=(2,1)\vb{x} = (2, 1) and y=2y = 2. Solutions form a line. The gradient of 12(x⊤w−y)2\frac12(\vb{x}\T\vb{w} - y)^2 is (x⊤w−y) x(\vb{x}\T\vb{w} - y)\,\vb{x}: it always points in direction x\vb{x}, perpendicular to the solution line. GD cannot move in any other direction.

InteractiveGD chooses the closest point
  • solutions {w:x⊤w=y}\{\vb{w} : \vb{x}\T\vb{w} = y\}
  • row space span⁡{x}\spn\{\vb{x}\}
  • path and ball of ∥⋅∥2\|\cdot\|_2 centered at w0\vb{w}_0
  • minimum norm X+y\mat{X}^{+}y
Algorithm
0.60
Limit w∞\vb{w}_\infty(−0.080, 2.160)
∥w∞∥2\|\vb{w}_\infty\|_2 (minimum possible: 0.894)2.161
∥w∞−w0∥\|\vb{w}_\infty - \vb{w}_0\| in the norm ∥⋅∥2\|\cdot\|_21.252
Null-space component: w0\vb{w}_0 → w40\vb{w}_{40}−1.968 → −1.968
Residual ∣x⊤w40−y∣|\vb{x}\T\vb{w}_{40} - y|4.4e−16
The aqua line shows infinitely many solutions of 2w1+w2=22w_1 + w_2 = 2. Drag initialization w0\vb{w}_0: GD moves straight, always parallel to x\vb{x} (the arrow), ending at the orthogonal projection of w0\vb{w}_0 onto the line, where the circle centered on w0\vb{w}_0 touches it. Press ‘Start at the origin’: the limit is X+y=(0.8,0.4)\mat{X}^{+}y = (0.8, 0.4), the line’s closest point to 0\vb{0}. Slider qq is step size in curvature units: at each iteration residual x⊤w−y\vb{x}\T\vb{w} - y is multiplied by 1−q1 - q. Raise it above 1 to see iterates bounce back and forth without changing the limit. Then try preconditioned GD and sign descent: each ends elsewhere on the line, minimizing distance to w0\vb{w}_0 in its own norm (ellipse and square).

The figure shows three facts formalized by the next theorem: the component of w\vb{w} in the null space of X\mat{X} never changes (the “null component” readout is the same initially and finally); the limit does not depend on step size while the algorithm is stable; and update geometry does change it.

Proof

Let w†=X+y\vb{w}^\dagger = \mat{X}\pinv\vb{y}. It satisfies the normal equations X⊤Xw†=X⊤y\mat{X}\T\mat{X}\vb{w}^\dagger = \mat{X}\T\vb{y} because X⊤XX+=X⊤\mat{X}\T\mat{X}\mat{X}\pinv = \mat{X}\T (one Moore-Penrose identity). Then ∇R^(w)=Σ^(w−w†)\grad\hat{R}(\vb{w}) = \hat{\mat{\Sigma}}(\vb{w} - \vb{w}^\dagger) and error et=wt−w†\vb{e}_t = \vb{w}_t - \vb{w}^\dagger obeys

et+1=(I−ηΣ^) et,et=(I−ηΣ^)t e0.\vb{e}_{t+1} = (\mat{I} - \eta\hat{\mat{\Sigma}})\,\vb{e}_t, \qquad \vb{e}_t = (\mat{I} - \eta\hat{\mat{\Sigma}})^t\,\vb{e}_0.

Diagonalize Σ^=∑iμivivi⊤\hat{\mat{\Sigma}} = \sum_i \mu_i\vb{v}_i\vb{v}_i\T with orthonormal {vi}\{\vb{v}_i\}. The vi\vb{v}_i with μi>0\mu_i > 0 span row⁡(X)\row(\mat{X}) and those with μi=0\mu_i = 0 span null⁡(X)\nullsp(\mat{X}). In the eigenbasis, vi⊤et=(1−ημi)t vi⊤e0\vb{v}_i\T\vb{e}_t = (1 - \eta\mu_i)^t\,\vb{v}_i\T\vb{e}_0:

  • if μi>0\mu_i > 0, ∣1−ημi∣<1\abs{1 - \eta\mu_i} < 1 because 0<ημi≤ημ1<20 < \eta\mu_i \le \eta\mu_1 < 2, and the component tends geometrically to zero;
  • if μi=0\mu_i = 0, the component does not change: vi⊤et=vi⊤e0=vi⊤w0\vb{v}_i\T\vb{e}_t = \vb{v}_i\T\vb{e}_0 = \vb{v}_i\T\vb{w}_0, because w†=X⊤(XX⊤)+y∈row⁡(X)\vb{w}^\dagger = \mat{X}\T(\mat{X}\mat{X}\T)\pinv\vb{y} \in \row(\mat{X}) has no null-space component.

Therefore et→(I−P)w0\vb{e}_t \to (\mat{I} - \mat{P})\vb{w}_0 and wt→w†+(I−P)w0\vb{w}_t \to \vb{w}^\dagger + (\mat{I} - \mat{P})\vb{w}_0 with the stated convergence factor. This limit lies in M=w†+null⁡(X)\mathcal{M} = \vb{w}^\dagger + \nullsp(\mat{X}). For any other w=w†+z\vb{w} = \vb{w}^\dagger + \vb{z} with z∈null⁡(X)\vb{z} \in \nullsp(\mat{X}), since w†−Pw0∈row⁡(X)⊥null⁡(X)\vb{w}^\dagger - \mat{P}\vb{w}_0 \in \row(\mat{X}) \perp \nullsp(\mat{X}), Pythagoras gives

∥w−w0∥2=∥w†−Pw0∥2+∥z−(I−P)w0∥2,\norm{\vb{w} - \vb{w}_0}^2 = \norm{\vb{w}^\dagger - \mat{P}\vb{w}_0}^2 + \norm{\vb{z} - (\mat{I} - \mat{P})\vb{w}_0}^2,

which is minimized exactly at z=(I−P)w0\vb{z} = (\mat{I} - \mat{P})\vb{w}_0.

∎

The proof uses nothing specific to GD beyond each update being a linear combination of gradients, all in row⁡(X)\row(\mat{X}). The same argument holds for Polyak or Nesterov momentum, SGD with any batch size and any step sequence: all preserve the null component, so if they converge to a minimizer it is the same one. A fixed preconditioner P\mat{P} instead moves iterates through P row⁡(X)\mat{P}\,\row(\mat{X}), generally not orthogonal to the null space, and the limit becomes the minimizer closest to w0\vb{w}_0 in norm ∥⋅∥P−1\norm{\cdot}_{\mat{P}\inv} (the ellipse in the figure).

GD choosing X+y\mat{X}\pinv\vb{y} does not yet show X+y\mat{X}\pinv\vb{y} generalizes. It does show the trained model is not an arbitrary minimizer but the minimum-norm one, and norm is exactly what Rademacher complexity bounds control for balls {∥w∥≤B}\{\norm{\vb{w}} \le B\}. When that control suffices is the question of benign interpolation.

Early stopping as spectral regularization

Now do not wait for convergence. From w0=0\vb{w}_0 = \vb{0}, the proof gives wt=w†+(I−ηΣ^)t(−w†)\vb{w}_t = \vb{w}^\dagger + (\mat{I} - \eta\hat{\mat{\Sigma}})^t(-\vb{w}^\dagger), namely,

wt=∑i: μi>0(1−(1−ημi)t)⏟gtGD(μi) (vi⊤w†) vi.\vb{w}_t = \sum_{i:\,\mu_i > 0} \underbrace{\big(1 - (1 - \eta\mu_i)^t\big)}_{g^{\mathrm{GD}}_t(\mu_i)}\,(\vb{v}_i\T\vb{w}^\dagger)\,\vb{v}_i .

Compare with ridge, wλ=arg⁡min⁡R^(w)+λ2∥w∥2=(Σ^+λI)−1X⊤y/n\vb{w}_\lambda = \arg\min\hat{R}(\vb{w}) + \frac{\lambda}{2}\norm{\vb{w}}^2 = (\hat{\mat{\Sigma}} + \lambda\mat{I})\inv\mat{X}\T\vb{y}/n. Since X⊤y/n=Σ^w†\mat{X}\T\vb{y}/n = \hat{\mat{\Sigma}}\vb{w}^\dagger,

wλ=∑i: μi>0μiμi+λ⏟gλR(μi) (vi⊤w†) vi,\vb{w}_\lambda = \sum_{i:\,\mu_i > 0} \underbrace{\frac{\mu_i}{\mu_i + \lambda}}_{g^{\mathrm{R}}_\lambda(\mu_i)}\,(\vb{v}_i\T\vb{w}^\dagger)\,\vb{v}_i ,

the spectral shrinkage of ridge. Both estimators have the same form: take w†\vb{w}^\dagger and multiply its component in each eigendirection by filter g(μ)∈[0,1]g(\mu) \in [0, 1], which passes high-eigenvalue directions and suppresses low-eigenvalue directions that amplify noise most. This is what early stopping is regularization means: iteration count plays the role of 1/λ1/\lambda.

Calibration comes from where each filter is half. For small ημ\eta\mu, (1−ημ)t≈e−ημt(1 - \eta\mu)^t \approx e^{-\eta\mu t}, so GD’s filter approximates gradient flow at time τ=ηt\tau = \eta t, g(μ)=1−e−μτg(\mu) = 1 - e^{-\mu\tau}. With x=μτx = \mu\tau, the filters are 1−e−x1 - e^{-x} and x/(1+x)x/(1 + x) if λ=1/τ=1/(ηt)\lambda = 1/\tau = 1/(\eta t): they are ≈x\approx x for small xx, tend to 1 for large xx and transition near x≈1x \approx 1, i.e. μ≈λ\mu \approx \lambda. The effective parameter count ∑ig(μi)\sum_i g(\mu_i), which for ridge is effective dimension, grows with tt just as it grows as λ\lambda falls.

InteractiveEarly stopping versus ridge
  • GD: 1−(1−ημ)t1 - (1 - \eta\mu)^{t}
  • ridge: μ/(μ+λ)\mu/(\mu + \lambda)
  • flujo: 1−e−ημt1 - e^{-\eta\mu t}
  • GD path and wt\vb{w}_t
  • ridge path and wλ\vb{w}_{\lambda}, λ=1/(ηt)\lambda = 1/(\eta t)
  • level curves of R^\hat{R}
32
0.50
λ=1/(ηt)\lambda = 1/(\eta t)0.063
Filter at μ1=1\mu_1 = 1: GD / ridge1.000 / 0.941
Filter at μ2=0.02\mu_2 = 0.02: GD / ridge0.275 / 0.242
∥wt−wλ∥\|\vb{w}_t - \vb{w}_\lambda\| (with ∥w^MC∥=2\|\hat{\vb{w}}_{\mathrm{MC}}\| = 2)0.116
max⁡μ\max_\mu GD filter / ridge filter1.312
Explicit problem in R2\R^2: Σ^\hat{\mat{\Sigma}} with eigenvalues μ1=1\mu_1 = 1 and μ2=0.02\mu_2 = 0.02 (eigenvectors rotated 25°) and least-squares solution w^MC=(1.6,1.2)\hat{\vb{w}}_{\mathrm{MC}} = (1.6, 1.2). The filter plot shows GD after tt steps (blue), ridge with λ=1/(ηt)\lambda = 1/(\eta t) (orange), and continuous flow (gray) as functions of μ\mu on a log scale. In weight space, with R^\hat{R} contours, see the GD path from 0\vb{0} and ridge path as λ\lambda falls from ∞\infty to 0, marking each current-tt point. Move tt: both paths first traverse the high-curvature direction and only much later the low-curvature direction, with points nearly together. Inspect maximum filter ratio. Then raise η\eta above 1: GD’s filter at μ1\mu_1 exceeds 1 and its path zigzags, unlike ridge.

The similarity is quantitative. Ali, Kolter and Tibshirani compared estimation risk of the two estimators calibrated at λ=1/τ\lambda = 1/\tau and obtained a uniform bound in τ\tau without assumptions on X\mat{X} (Ali, Kolter and Tibshirani, 2019, Theorem 1). The proof fits in a few lines.

Proof

For spectral estimator β^g=∑μi>0(g(μi)/μi) vivi⊤X⊤y/n\hat{\beta}_g = \sum_{\mu_i > 0}(g(\mu_i)/\mu_i)\,\vb{v}_i\vb{v}_i\T\mat{X}\T\vb{y}/n, Eβ^g=∑μi>0g(μi) vivi⊤β0\E\hat{\beta}_g = \sum_{\mu_i > 0} g(\mu_i)\,\vb{v}_i\vb{v}_i\T\beta_0, and since Cov⁡(X⊤ε/n)=σ2Σ^/n\Cov(\mat{X}\T\vb{\varepsilon}/n) = \sigma^2\hat{\mat{\Sigma}}/n,

E∥β^g−β0∥2=∑μi>0[(1−g(μi))2(vi⊤β0)2+σ2ng(μi)2μi]+∑μi=0(vi⊤β0)2.\E\norm{\hat{\beta}_g - \beta_0}^2 = \sum_{\mu_i > 0}\Big[(1 - g(\mu_i))^2(\vb{v}_i\T\beta_0)^2 + \frac{\sigma^2}{n}\frac{g(\mu_i)^2}{\mu_i}\Big] + \sum_{\mu_i = 0}(\vb{v}_i\T\beta_0)^2 .

The last term is the same for both estimators. With xi=μiτx_i = \mu_i\tau, flow uses g=1−e−xg = 1 - e^{-x} and ridge with λ=1/τ\lambda = 1/\tau uses g=x/(1+x)g = x/(1 + x). Two scalar inequalities for x>0x > 0 suffice:

  • e−x≤1/(1+x)e^{-x} \le 1/(1 + x) because ex≥1+xe^x \ge 1 + x. Thus each flow bias term is no larger than ridge’s.
  • 1−e−x≤c x/(1+x)1 - e^{-x} \le c\,x/(1 + x) with c=sup⁡x>0(1−e−x)(1+x)/x≈1.2984c = \sup_{x > 0}(1 - e^{-x})(1 + x)/x \approx 1.2984, attained at x≈1.79x \approx 1.79 (calculated by the lab cell). Thus each flow variance term is at most c2≈1.6859c^2 \approx 1.6859 times ridge’s.

Summing, flow risk is at most c2c^2 times ridge risk. The paper rounds upward: c≤1.2985c \le 1.2985 and c2≤1.6862c^2 \le 1.6862.

∎

Observe the breakdown: early stopping always has less bias than ridge calibrated at λ=1/τ\lambda = 1/\tau and at most 69% more variance. For discrete GD with ημ1≤1\eta\mu_1 \le 1 bias remains smaller because (1−ημ)t≤e−ημt(1 - \eta\mu)^t \le e^{-\eta\mu t}, and a crude variance bound follows from 1−(1−a)t≤min⁡(1,at)≤2at/(1+at)1 - (1 - a)^t \le \min(1, at) \le 2at/(1 + at): constant 44 instead of 1.691.69. With ημ1>1\eta\mu_1 > 1 the GD filter exceeds 1 in high-curvature directions, as the figure shows, and the ridge analogy breaks precisely there.

Separable classification: norm diverges and direction converges to maximum margin

Classification is more extreme: separable data have no minimizer. Take examples (xn,yn)(\vb{x}_n, y_n) with yn∈{±1}y_n \in \{\pm 1\}, define zn=ynxn\vb{z}_n = y_n\vb{x}_n and minimize logistic regression loss without intercept or regularization,

L(w)=∑n=1Nℓ(zn⊤w),ℓ(u)=log⁡(1+e−u).L(\vb{w}) = \sum_{n=1}^N \ell(\vb{z}_n\T\vb{w}), \qquad \ell(u) = \log(1 + e^{-u}).

Data are separable if some ws\vb{w}_s satisfies zn⊤ws>0\vb{z}_n\T\vb{w}_s > 0 for all nn. Then L(c ws)→0L(c\,\vb{w}_s) \to 0 as c→∞c \to \infty; the infimum is 0 and unattained. Since ℓ′′(u)=σ(u)σ(−u)≤1/4\ell''(u) = \sigmoid(u)\sigmoid(-u) \le 1/4, ℓ\ell is β\beta-smooth with β=1/4\beta = 1/4 and ∇2L=∑nℓ′′(zn⊤w) znzn⊤⪯β Z⊤Z\grad^2 L = \sum_n\ell''(\vb{z}_n\T\vb{w})\,\vb{z}_n\vb{z}_n\T \preceq \beta\,\mat{Z}\T\mat{Z}, so LL is βσmax⁡2(Z)\beta\sigma_{\max}^2(\mat{Z})-smooth, where Z\mat{Z} has rows zn⊤\vb{z}_n\T.

Proof

Let M=βσmax⁡2(Z)=σmax⁡2(Z)/4M = \beta\sigma_{\max}^2(\mat{Z}) = \sigma_{\max}^2(\mat{Z})/4 be the smoothness constant of LL, so ηM<2\eta M < 2. By the descent lemma, L(wt+1)≤L(wt)−η(1−ηM/2)∥∇L(wt)∥2L(\vb{w}_{t+1}) \le L(\vb{w}_t) - \eta(1 - \eta M/2)\norm{\grad L(\vb{w}_t)}^2 with 1−ηM/2>01 - \eta M/2 > 0. Summing gives ∑t∥∇L(wt)∥2≤L(w0)/(η(1−ηM/2))<∞\sum_t\norm{\grad L(\vb{w}_t)}^2 \le L(\vb{w}_0)/(\eta(1 - \eta M/2)) < \infty, hence ∇L(wt)→0\grad L(\vb{w}_t) \to \vb{0}. Now use the separator: since −ℓ′>0-\ell' > 0,

∥∇L(wt)∥ ∥ws∥≥⟨−∇L(wt),ws⟩=∑n−ℓ′(zn⊤wt) zn⊤ws≥(min⁡nzn⊤ws)∑n−ℓ′(zn⊤wt).\norm{\grad L(\vb{w}_t)}\,\norm{\vb{w}_s} \ge \inner{-\grad L(\vb{w}_t)}{\vb{w}_s} = \sum_n -\ell'(\vb{z}_n\T\vb{w}_t)\,\vb{z}_n\T\vb{w}_s \ge \Big(\min_n\vb{z}_n\T\vb{w}_s\Big)\sum_n -\ell'(\vb{z}_n\T\vb{w}_t).

The left side tends to zero and min⁡nzn⊤ws>0\min_n\vb{z}_n\T\vb{w}_s > 0, so each −ℓ′(zn⊤wt)=1/(1+ezn⊤wt)-\ell'(\vb{z}_n\T\vb{w}_t) = 1/(1 + e^{\vb{z}_n\T\vb{w}_t}) tends to zero, i.e. zn⊤wt→∞\vb{z}_n\T\vb{w}_t \to \infty. Hence L(wt)→0L(\vb{w}_t) \to 0, all margins eventually become positive, and since zn⊤wt≤∥zn∥∥wt∥\vb{z}_n\T\vb{w}_t \le \norm{\vb{z}_n}\norm{\vb{w}_t}, norm diverges.

∎

The interesting question is the direction of divergence. Recall the maximum-margin classifier: hard-margin SVM without intercept,

w^=arg⁡min⁡w∥w∥2s.a.zn⊤w≥1  ∀n,\hat{\vb{w}} = \arg\min_{\vb{w}}\norm{\vb{w}}^2 \quad\text{s.a.}\quad \vb{z}_n\T\vb{w} \ge 1 \ \ \forall n,

whose geometric margin is γ=1/∥w^∥\gamma = 1/\norm{\hat{\vb{w}}}. By KKT conditions, w^=∑nαnzn\hat{\vb{w}} = \sum_n\alpha_n\vb{z}_n with αn≥0\alpha_n \ge 0 and αn=0\alpha_n = 0 except on support vectors, examples satisfying zn⊤w^=1\vb{z}_n\T\hat{\vb{w}} = 1.

This is the result of Soudry et al. (2018), Theorems 3, 4 and 5. It is the implicit bias toward maximum margin: without mentioning margin in the loss, GD eventually produces the geometric maximum-margin classifier, the same margin controlled by the margin bound.

The reason appears in a self-consistent argument, the proof sketch given in the paper. For large uu, −ℓ′(u)=1/(1+eu)≈e−u-\ell'(u) = 1/(1 + e^u) \approx e^{-u}. Suppose wt=w^log⁡t+ρt\vb{w}_t = \hat{\vb{w}}\log t + \vb{\rho}_t with bounded ρt\vb{\rho}_t. Each example then contributes to the gradient with weight

−ℓ′(zn⊤wt)≈e−zn⊤ρt t−zn⊤w^.-\ell'(\vb{z}_n\T\vb{w}_t) \approx e^{-\vb{z}_n\T\vb{\rho}_t}\,t^{-\vb{z}_n\T\hat{\vb{w}}}.

Examples with zn⊤w^>1\vb{z}_n\T\hat{\vb{w}} > 1 weigh o(1/t)o(1/t); those with margin exactly 1 weigh Θ(1/t)\Theta(1/t). But the one-step increment of w^log⁡t\hat{\vb{w}}\log t is w^log⁡t+1t≈w^/t\hat{\vb{w}}\log\frac{t+1}{t} \approx \hat{\vb{w}}/t. For both to agree, at order 1/t1/t,

w^=∑n: zn⊤w^=1η e−zn⊤ρ zn,\hat{\vb{w}} = \sum_{n:\,\vb{z}_n\T\hat{\vb{w}} = 1}\eta\,e^{-\vb{z}_n\T\vb{\rho}}\,\vb{z}_n ,

a positive-coefficient combination of margin-1 examples is needed. (The minimum margin of w^\hat{\vb{w}} must also equal exactly 1 by the 1/t1/t order: with smaller margin γ′≠1\gamma' \ne 1, dominant terms would be order t−γ′t^{-\gamma'} and could not equal increment w^/t\hat{\vb{w}}/t.) No example can have zn⊤w^<1\vb{z}_n\T\hat{\vb{w}} < 1 either: its weight t−zn⊤w^t^{-\vb{z}_n\T\hat{\vb{w}}} would dominate 1/t1/t and push wt\vb{w}_t toward it faster than log⁡t\log t. Margin at least 1 for all, with w^\hat{\vb{w}} a nonnegative combination of those with margin exactly 1, gives the hard-margin SVM KKT conditions, which characterize its solution by convexity. Coefficients are αn=ηe−zn⊤w~\alpha_n = \eta e^{-\vb{z}_n\T\tilde{\vb{w}}}, giving the theorem’s w~\tilde{\vb{w}} equation, and loss behaves as L(wt)≈∑nαn/(ηt)=∥w^∥2/(ηt)L(\vb{w}_t) \approx \sum_n\alpha_n/(\eta t) = \norm{\hat{\vb{w}}}^2/(\eta t) because ∑nαn=∑nαnzn⊤w^=∥w^∥2\sum_n\alpha_n = \sum_n\alpha_n\vb{z}_n\T\hat{\vb{w}} = \norm{\hat{\vb{w}}}^2.

InteractiveThe slow march toward maximum margin
  • measured GD
  • asymptote ∠(w^log⁡t+w~,w^)\angle(\hat{\vb{w}}\log t + \tilde{\vb{w}}, \hat{\vb{w}})
  • class +1+1
  • class −1-1
  • boundary of wt\vb{w}_t
  • Maximum-margin SVM, its margins and support vectors (rings)
t = 1 000 000
Plot
0.50
Angle between wt\vb{w}_t and w^\hat{\vb{w}}0.94°
∥wt∥\|\vb{w}_t\| versus ∥w^∥log⁡t\|\hat{\vb{w}}\|\log t15.69 / 20.58
Normalized margin min⁡nynxn⊤wt/∥wt∥\min_n y_n\vb{x}_n\T\vb{w}_t/\|\vb{w}_t\|0.6533 (max. 0.6712)
Loss L(wt)L(\vb{w}_t)4.55e−5
Margin of the next non-support example1.556
Twelve fixed points in R2\R^2 separable by a line through the origin; logistic GD from 0\vb{0}, with η=0.9⋅8/σmax⁡2(Z)\eta = 0.9\cdot 8/\sigma^2_{\max}(\mat{Z}), through t=106t = 10^6. In data space, the boundary of wt\vb{w}_t (magenta) and maximum-margin SVM with margin lines and two support vectors (rings). The plot uses log scale tt and shows the angle between wt\vb{w}_t and w^\hat{\vb{w}}, norm or loss, alongside theorem asymptote w^log⁡t+w~\hat{\vb{w}}\log t + \tilde{\vb{w}}. Play the animation: angle falls quickly at first when distant groups dominate the gradient, then each decade of tt cuts it only slightly. Norm grows as ∥w^∥log⁡t\norm{\hat{\vb{w}}}\log t and loss as ∥w^∥2/(ηt)\norm{\hat{\vb{w}}}^2/(\eta t). Enable the new point: at margin 0.5 it becomes a support vector and w^\hat{\vb{w}} rotates about 15°; watch how long wt\vb{w}_t takes to follow. Then move its margin to 0.98: another example is nearly support and the asymptote no longer describes the path.

Figure values come from running GD on that explicit model, and the lab cell reproduces the first 2⋅1042\cdot 10^4 Python iterations. Angle goes from 63.4° at t=1t = 1 to 10.1° at t=100t = 100, 3.2° at t=103t = 10^3 and 1.7° at t=104t = 10^4; the figure continues to 1.2° at t=105t = 10^5 and 0.94° at t=106t = 10^6, where the theorem asymptote also gives 0.94°. Each decade divides angle by a smaller factor: 1.8, 1.4 and 1.3 in the final three.

Practical consequences. Rate 1/log⁡t1/\log t is extremely slow: asymptotically, halving the angle requires squaring tt. The paper notes three consequences:

  • Continuing to train after zero error changes the model: margin keeps growing slowly even when training loss is tiny.
  • Validation logistic loss can rise while validation classification error falls. If one validation example x\vb{x} satisfies y x⊤w^<0y\,\vb{x}\T\hat{\vb{w}} < 0, its loss grows as Θ(log⁡t)\Theta(\log t) because wt\vb{w}_t norm diverges (Corollary 6). Stopping on validation loss can stop too early.
  • The limiting direction does not depend on w0\vb{w}_0 or η\eta within the stable range; speed does.

Parameterization matters

The previous two results concern GD directly on linear-model weights. A multilayer linear network represents the same function class, x↦w⊤x\vb{x} \mapsto \vb{w}\T\vb{x}, but writes w\vb{w} as a product of matrices and applies GD to factors. By the chain rule, if w=ϕ(θ)\vb{w} = \phi(\theta) with Jacobian J(θ)\mat{J}(\theta), gradient flow θ˙=−J⊤∇wR^\dot\theta = -\mat{J}\T\grad_{\vb{w}}\hat{R} induces in function space

w˙=−J(θ)J(θ)⊤ ∇wR^(w),\dot{\vb{w}} = -\mat{J}(\theta)\mat{J}(\theta)\T\,\grad_{\vb{w}}\hat{R}(\vb{w}),

a flow preconditioned by state-dependent matrix JJ⊤\mat{J}\mat{J}\T. The first figure showed that a fixed preconditioner changes the limit; a state-dependent one can change it much more.

Diagonal linear networks

The simplest model fully calculable is Woodworth et al. (2020): w=u⊙u−v⊙v\vb{w} = \vb{u}\odot\vb{u} - \vb{v}\odot\vb{v}, with u,v∈Rd\vb{u}, \vb{v} \in \R^d and elementwise product. It is a two-layer linear network with diagonal connections, and the difference of squares permits weights of both signs. Initialize at u0=v0=α1\vb{u}_0 = \vb{v}_0 = \alpha\vb{1}, so w0=0\vb{w}_0 = \vb{0} for any scale α>0\alpha > 0, and minimize 12∥Xw−y∥2\frac12\norm{\mat{X}\vb{w} - \vb{y}}^2 by gradient flow in (u,v)(\vb{u}, \vb{v}).

u˙=−2 u⊙g,v˙=2 v⊙g\dot{\vb{u}} = -2\,\vb{u}\odot\vb{g},\qquad \dot{\vb{v}} = 2\,\vb{v}\odot\vb{g}
With r=Xw−y\vb{r} = \mat{X}\vb{w} - \vb{y} and g=X⊤r\vb{g} = \mat{X}\T\vb{r}, the gradient with respect to u\vb{u} is 2u⊙g2\vb{u}\odot\vb{g} and with respect to v\vb{v} is −2v⊙g-2\vb{v}\odot\vb{g}.
1/6

Since q′′(z)=1/4+z2>0q''(z) = 1/\sqrt{4 + z^2} > 0, QαQ_\alpha is strictly convex; KKT conditions characterize it and give the result.

Both limits follow from qq. For small zz, q(z)=z2/4+O(z4)q(z) = z^2/4 + \bigO(z^4), so with large α\alpha (all wi/α2w_i/\alpha^2 small), Qα(w)≈∥w∥22/(4α2)Q_\alpha(\vb{w}) \approx \norm{\vb{w}}_2^2/(4\alpha^2): a multiple of squared ℓ2\ell_2 norm. For large ∣z∣\abs{z}, q(z)≈∣z∣log⁡∣z∣q(z) \approx \abs{z}\log\abs{z}, so with small α\alpha

Qα(w)≈∑i∣wi∣log⁡∣wi∣α2=log⁡1α2 ∥w∥1+∑i∣wi∣log⁡∣wi∣,Q_\alpha(\vb{w}) \approx \sum_i\abs{w_i}\log\frac{\abs{w_i}}{\alpha^2} = \log\frac{1}{\alpha^2}\,\norm{\vb{w}}_1 + \sum_i\abs{w_i}\log\abs{w_i},

and the first term dominates: minimizing QαQ_\alpha is, to first order, minimizing ∥w∥1\norm{\vb{w}}_1. Woodworth et al. call the first extreme the kernel regime: with large α\alpha weights barely move relatively, the model behaves like its linearization at initialization, and bias is minimum tangent-kernel norm (here ℓ2\ell_2), the kernel regime studied in lesson 18. The second is the rich regime: weights grow orders of magnitude from near zero and bias is no longer that of a fixed kernel.

InteractiveInitialization scale determines the norm
  • GD on w=u⊙u−v⊙v\vb{w} = \vb{u}\odot\vb{u} - \vb{v}\odot\vb{v}
  • minimum ℓ1\ell_1 norm (lasso, λ→0+\lambda \to 0^+)
  • w⋆\vb{w}^\star (3 coefficients)
  • flow limit, arg⁡min⁡Qα\arg\min Q_\alpha
  • minimum ℓ1\ell_1
  • minimum ℓ2\ell_2
0.010
Compare with
Curve
GD recovery error ∥wGD−w⋆∥2\|\vb{w}_{\mathrm{GD}} - \vb{w}^\star\|_20.264
Minimum ℓ1\ell_1 / minimum ℓ2\ell_20.000 / 2.209
∥wGD∥1\|\vb{w}_{\mathrm{GD}}\|_1 and ∥wGD∥2\|\vb{w}_{\mathrm{GD}}\|_25.095 y 2.676
Coefficients with ∣wj∣>0.05|w_j| > 0.055 of 50 (truth: 3)
∥wGD−arg⁡min⁡Qα∥2\|\vb{w}_{\mathrm{GD}} - \arg\min Q_\alpha\|_20.0123
GD steps and residual ∥Xw−y∥\|\mat{X}\vb{w} - \vb{y}\|45068 y 1.0e−6
Noiseless sparse regression: n=20n = 20 equations, d=50d = 50 unknowns and w⋆\vb{w}^\star with 3 nonzero coefficients (gray rings). Above, blue shows 50 coefficients from actual GD on (u,v)(\vb{u}, \vb{v}) from α1\alpha\vb{1}; orange shows your reference: minimum ℓ1\ell_1-norm interpolator (lasso limit as λ→0+\lambda \to 0^+) or minimum ℓ2\ell_2-norm interpolator (ridgeless). Below, recovery error or ℓ1\ell_1 norm of the QαQ_\alpha minimizer versus α\alpha between the two references. Start at α=0.01\alpha = 0.01: GD finds the 3 coefficients nearly exactly. Raise α\alpha to 1 and see the solution spread across coordinates until it matches minimum ℓ2\ell_2 norm. Readout ∥wGD−arg⁡min⁡Qα∥\|\vb{w}_{\mathrm{GD}} - \arg\min Q_\alpha\| checks the theorem for every α\alpha.

With the same data and loss, the sole change between figure extremes is initialization scale, and recovery error differs as between solving the problem (near-zero error, like lasso with λ→0+\lambda \to 0^+) and not solving it (ridgeless error near 2). The rich regime costs time: flow needs order log⁡(1/α)\log(1/\alpha) time for coefficients to leave scale α2\alpha^2, and discrete GD feels it; in the figure with α=10−3\alpha = 10^{-3}, GD does not fully interpolate in 60,000 steps.

Matrix factorization and limits of norms

In matrix factorization the model is W=UU⊤\mat{W} = \mat{U}\mat{U}\T and observations are linear measurements ⟨Ai,W⟩=yi\langle\mat{A}_i, \mat{W}\rangle = y_i. Gunasekar et al. (2017) observed that GD with small steps and near-zero initialization finds low nuclear-norm solutions even with full-dimensional factorization, where nothing restricts rank, and conjectured its limit is the minimum nuclear-norm solution; they proved it when matrices Ai\mat{A}_i commute. This is the matrix version of the diagonal network: commuting measurements diagonalize simultaneously, returning to the earlier case with nuclear norm playing the role of ℓ1\ell_1 on eigenvalues.

The general case is not resolved this way. Razin and Cohen (2020) constructed matrix-completion problems where GD on deep factorization drives every norm and even every quasinorm to infinity while effective rank falls. They conclude implicit bias is better described as a low-rank tendency than norm minimization. General lesson: not every implicit bias minimizes a norm, and always seeking one may seek something nonexistent.

Other algorithms, other geometries

Parameterization is not the only geometry changer. Gunasekar, Lee, Soudry and Srebro (2018) generalized the prior result to steepest descent with respect to an arbitrary norm: with exponential loss and separable data, normalized margin converges to maximum margin in that norm (Theorem 5). With ℓ∞\ell_\infty norm, whose descent direction is gradient sign, the limit is maximum ℓ∞\ell_\infty-margin classifier, distinct from SVM. For AdaGrad the same work finds bias depends on initialization and step size, even for strictly monotonic losses. Adaptive methods like Adam are close relatives of both, so do not assume they inherit GD bias.

SGD stability: few passes generalize

So far implicit bias described which solution is selected. An algorithm can also regularize without an explicit term by staying close to what it would do on another sample. This is lesson 11’s uniform stability. Recall the randomized-algorithm version of Hardt, Recht and Singer (2016): AA is ε\varepsilon-uniformly stable if for every pair of size-nn samples S,S′S, S' differing in one example,

sup⁡z EA[f(A(S);z)−f(A(S′);z)]≤ε,\sup_{z}\ \E_A\big[f(A(S); z) - f(A(S'); z)\big] \le \varepsilon,

with expectation over internal algorithm randomness. And the stability-generalization relationship: if AA is ε\varepsilon-uniformly stable, ∣ES,A[R^S(A(S))−R(A(S))]∣≤ε\abs{\E_{S,A}[\hat{R}_S(A(S)) - R(A(S))]} \le \varepsilon.

Here SGD is iteration wt+1=wt−αt∇f(wt;zit)\vb{w}_{t+1} = \vb{w}_t - \alpha_t\grad f(\vb{w}_t; z_{i_t}) with iti_t uniform in {1,…,n}\{1, \dots, n\} and independent at each step, the stochastic version of GD. Write Gt(w)=w−αt∇f(w;zit)G_t(\vb{w}) = \vb{w} - \alpha_t\grad f(\vb{w}; z_{i_t}). Two update properties suffice for the analysis:

  • GG is σ\sigma-bounded if sup⁡w∥w−G(w)∥≤σ\sup_{\vb{w}}\norm{\vb{w} - G(\vb{w})} \le \sigma. If ff is LL-Lipschitz, ∥∇f∥≤L\norm{\grad f} \le L and the gradient update is αL\alpha L-bounded.
  • GG is ρ\rho-expansive if ∥G(v)−G(w)∥≤ρ∥v−w∥\norm{G(\vb{v}) - G(\vb{w})} \le \rho\norm{\vb{v} - \vb{w}} for every v,w\vb{v}, \vb{w}.
Proof

For convex, β\beta-smooth ff the gradient is cocoercive: ⟨∇f(v)−∇f(w),v−w⟩≥1β∥∇f(v)−∇f(w)∥2\inner{\grad f(\vb{v}) - \grad f(\vb{w})}{\vb{v} - \vb{w}} \ge \frac{1}{\beta}\norm{\grad f(\vb{v}) - \grad f(\vb{w})}^2. With Δ=v−w\vb{\Delta} = \vb{v} - \vb{w} and δ=∇f(v)−∇f(w)\vb{\delta} = \grad f(\vb{v}) - \grad f(\vb{w}),

∥G(v)−G(w)∥2=∥Δ∥2−2α⟨δ,Δ⟩+α2∥δ∥2≤∥Δ∥2−(2αβ−α2)∥δ∥2≤∥Δ∥2,\norm{G(\vb{v}) - G(\vb{w})}^2 = \norm{\vb{\Delta}}^2 - 2\alpha\inner{\vb{\delta}}{\vb{\Delta}} + \alpha^2\norm{\vb{\delta}}^2 \le \norm{\vb{\Delta}}^2 - \Big(\frac{2\alpha}{\beta} - \alpha^2\Big)\norm{\vb{\delta}}^2 \le \norm{\vb{\Delta}}^2,

because 2α/β−α2=α(2/β−α)≥02\alpha/\beta - \alpha^2 = \alpha(2/\beta - \alpha) \ge 0.

∎
Proof

Run SGD on SS and S′S' (differing at example jj) from the same w0\vb{w}_0 with the same index sequence i1,i2,…i_1, i_2, \dots, and write δt=∥wt−wt′∥\delta_t = \norm{\vb{w}_t - \vb{w}'_t}, with δ0=0\delta_0 = 0. At step tt:

  • with probability 1−1/n1 - 1/n, choose it≠ji_t \ne j; both runs apply the same update and by the lemma δt+1≤δt\delta_{t+1} \le \delta_t;
  • with probability 1/n1/n, choose jj; updates differ but both are αtL\alpha_t L-bounded, and the triangle inequality gives δt+1≤∥G(wt)−wt∥+δt+∥wt′−G′(wt′)∥≤δt+2αtL\delta_{t+1} \le \norm{G(\vb{w}_t) - \vb{w}_t} + \delta_t + \norm{\vb{w}'_t - G'(\vb{w}'_t)} \le \delta_t + 2\alpha_t L.

Taking expectations, Eδt+1≤(1−1n)Eδt+1n(Eδt+2αtL)=Eδt+2αtL/n\E\delta_{t+1} \le (1 - \frac1n)\E\delta_t + \frac1n(\E\delta_t + 2\alpha_t L) = \E\delta_t + 2\alpha_t L/n, so EδT≤2Ln∑tαt\E\delta_T \le \frac{2L}{n}\sum_t\alpha_t. For any zz, because f(⋅;z)f(\cdot; z) is LL-Lipschitz, ∣E[f(wT;z)−f(wT′;z)]∣≤L EδT\abs{\E[f(\vb{w}_T; z) - f(\vb{w}'_T; z)]} \le L\,\E\delta_T.

∎

This is SGD stability. With constant step α\alpha and EE data passes, T=EnT = En and the bound becomes 2L2αE2L^2\alpha E: it does not depend on nn alone but on step times passes. Few passes at moderate step give a stable algorithm and therefore a small expected generalization gap regardless of class complexity. This is the idea in the paper’s title Train faster, generalize better: fewer training steps also regularize. Together with optimization error, which falls with TT, this yields the fit-stability tradeoff, with early stopping at the balance.

InteractiveTwo SGD twins
  • one run: δt=∥wt−wt′∥\delta_t = \|\vb{w}_t - \vb{w}'_t\|
  • mean over 96 runs
  • bound 2Lαt/n2L\alpha t/n
1.00
5
Sample size nn
Steps TT = passes × nn500
Bound 2LαT/n2L\alpha T/n for E[δT]\mathbb{E}[\delta_T]10.000
Estimated E[δT]\mathbb{E}[\delta_T] (96 runs)0.3407
Measured / bound0.034
Steps with the same example in which δ\delta increased0.00 %
α≤2/β=8\alpha \le 2/\beta = 8: with the same example, the update is nonexpansive. δt\delta_t increases only when the differing example is selected (the jumps in the green curve).
Logistic regression in R5\R^5 with ∥xi∥≤1\|\vb{x}_i\| \le 1, so L=1L = 1 and β=1/4\beta = 1/4. Both SGD runs use the same index sequence on samples differing in one example. The green curve is one δt=∥wt−wt′∥\delta_t = \|\vb{w}_t - \vb{w}'_t\| run: it jumps only when the differing example is chosen and never grows between jumps. Blue averages 96 index sequences and dashed gray shows theorem bound 2Lαt/n2L\alpha t/n (log scale). Increase passes: the bound grows without limit while the mean barely moves. Double nn: the bound halves and the mean also falls, though less. Raise step above 2/β=82/\beta = 8 and inspect expansive steps: it is no longer zero because the lemma assumption fails.

The figure also shows the bound is worst-case. With α=1\alpha = 1, n=100n = 100 and 5 passes, the bound is 10 and measured mean distance 0.34; from 5 to 10 passes the bound doubles while the mean barely changes. In practice the update not only fails to expand but contracts: near the optimum, logistic regression with nonseparable data has positive curvature along wt−wt′\vb{w}_t - \vb{w}'_t, and each same-example step brings the twins closer (the green curve falls between jumps). The paper gives two useful variants. If ff is also γ\gamma-strongly convex and projected SGD uses constant step α≤1/β\alpha \le 1/\beta, the update contracts and the bound stops growing with TT: εstab≤2L2/(γn)\varepsilon_{\mathrm{stab}} \le 2L^2/(\gamma n) (Theorem 3.9). Without convexity, for f∈[0,1]f \in [0, 1], LL-Lipschitz and β\beta-smooth with steps αt≤c/t\alpha_t \le c/t, updates can expand by factor 1+αtβ1 + \alpha_t\beta and the bound becomes order T1−1/(βc+1)/nT^{1 - 1/(\beta c + 1)}/n (Theorem 3.12): still useful for few iterations but degrading with long training.

[ ]Two SGD twins: nonexpansiveness and the Hardt, Recht and Singer boundBrowser
import numpy as np

rng = np.random.default_rng(3)
n, d = 100, 5
X = rng.normal(size=(n, d))
X /= np.maximum(1, np.linalg.norm(X, axis=1))[:, None]        # ||x|| <= 1: L = 1, beta = 1/4
y = np.where(rng.uniform(size=n) < 1 / (1 + np.exp(-2 * X @ np.array([1.5, -1, 0.5, 0, 0]))), 1.0, -1.0)
Xp = X.copy()
Xp[0] = -X[0]                                                 # S': solo cambia el ejemplo 0

def twin_sgd(alpha, T, runs=40):
    """SGD sobre S y S' con la misma sucesión de índices; devuelve E[delta_T] y la fracción de pasos expansivos."""
    deltas, expans, same = np.zeros(runs), 0, 0
    for r in range(runs):
        w, wp, prev = np.zeros(d), np.zeros(d), 0.0
        for i in rng.integers(0, n, T):
            w += alpha * y[i] * X[i] / (1 + np.exp(y[i] * X[i] @ w))
            wp += alpha * y[i] * Xp[i] / (1 + np.exp(y[i] * Xp[i] @ wp))
            delta = np.linalg.norm(w - wp)
            if i != 0:
                same += 1
                expans += delta > prev * (1 + 1e-9) + 1e-12
            prev = delta
        deltas[r] = delta
    return deltas.mean(), expans / same

T = 3 * n                                                     # tres pasadas
print(" alpha   E[delta_T]   cota 2*alpha*T/n   pasos expansivos")
for alpha in [1.0, 4.0, 8.0, 12.0, 16.0]:
    m, frac = twin_sgd(alpha, T)
    print(f"{alpha:5.1f}   {m:9.4f}   {2 * alpha * T / n:10.1f}        {100 * frac:5.2f} %")

Through α=8=2/β\alpha = 8 = 2/\beta there is not one expansive step; above it, slightly more than 6% of same-example steps separate the twins. The mean of δT\delta_T remains far below the bound in every case.

What these results do and do not explain for deep networks

This lesson’s theorems are exact for linear models, specially structured linear networks and convex losses. For nonlinear deep networks there are partial results, which should be distinguished from conjecture.

What is known.

  • In the kernel regime (very wide networks with suitable initialization and step scales), training behaves like GD on a model linear in parameters, and implicit bias is minimum norm in the tangent-kernel RKHS: the first theorem applied to linearization. Lesson 18 studies the kernel regime.
  • For parameter-homogeneous networks (such as fully connected or convolutional ReLU or Leaky ReLU networks without biases) trained with logistic or cross-entropy loss, Lyu and Li (2020) proved that once training loss drops below a threshold, a smoothed normalized margin grows and normalized margin converges to the value of a KKT point of margin maximization. This generalizes Soudry et al. to a KKT point, not necessarily the global maximum.
  • The SGD stability bound applies without convexity (Hardt et al., Theorem 3.12), although it degrades with iteration count.

What they do not explain.

  • A real network’s rich regime has no formula like QαQ_\alpha. Razin and Cohen’s examples show that even in deep linear factorizations bias is not always norm minimization.
  • Bounds derived from norms or stability are often vacuous for real networks. Standard networks can fit random labels (Zhang et al., 2017), and lesson 17’s random-label memorization examines implications for uniform bounds. Many passes with large steps make the stability bound useless.
  • Bias depends on learning rate (large steps change which minima are stable), batch size, optimizer, normalization and weight decay, and these effects interact. “SGD generalizes because of implicit bias” is a research program, not a theorem.

Lab: implicit bias in least squares and logistic regression

Start with the first theorem. With n=20n = 20 equations and d=50d = 50 unknowns, GD from zero should end at the pseudoinverse, and from random w0\vb{w}_0 at X+y\mat{X}\pinv\vb{y} plus the projection of w0\vb{w}_0 onto the null space.

[ ]Least-squares GD from zeroBrowser
import numpy as np

rng = np.random.default_rng(0)
n, d = 20, 50                                  # más incógnitas que ecuaciones
X = rng.normal(size=(n, d))
y = rng.normal(size=n)

def gd_least_squares(X, y, w0, eta, T):
    """T pasos de GD sobre R(w) = ||Xw - y||^2 / (2n) desde w0."""
    n = X.shape[0]
    w = np.array(w0, dtype=float).copy()
    for _ in range(T):
        w -= eta * X.T @ (X @ w - y) / n
    return w

mu = np.linalg.eigvalsh(X.T @ X / n)           # autovalores de Sigma = X^T X / n
mu_pos = mu[mu > 1e-10]
eta = 1.0 / mu.max()
print(f"autovalores no nulos: {mu_pos.size} de {d};  mu_max = {mu.max():.3f}, mu_min+ = {mu_pos.min():.4f}")
print(f"factor de contracción en el espacio de filas: {1 - eta * mu_pos.min():.4f}")

w_dag = np.linalg.pinv(X) @ y                  # interpolador de mínima norma
w_gd = gd_least_squares(X, y, np.zeros(d), eta, 1000)
print(f"desde 0:   ||w_GD - X^+ y|| = {np.linalg.norm(w_gd - w_dag):.1e},  residuo = {np.linalg.norm(X @ w_gd - y):.1e}")

w0 = rng.normal(size=d)
P_row = np.linalg.pinv(X) @ X                  # proyector sobre el espacio de filas
w_pred = w_dag + (np.eye(d) - P_row) @ w0
w_gd0 = gd_least_squares(X, y, w0, eta, 1000)
print(f"desde w0:  ||w_GD - (X^+ y + (I - P) w0)|| = {np.linalg.norm(w_gd0 - w_pred):.1e}")
print(f"normas: ||X^+ y|| = {np.linalg.norm(w_dag):.3f},  ||w_GD desde w0|| = {np.linalg.norm(w_gd0):.3f}")
print(f"componente en el núcleo: al principio {np.linalg.norm((np.eye(d) - P_row) @ w0):.4f}, al final {np.linalg.norm((np.eye(d) - P_row) @ w_gd0):.4f}")

The 20 nonzero eigenvalues of Σ^\hat{\mat{\Sigma}} range from 0.36 to 6.61, so with η=1/μ1\eta = 1/\mu_1 error is multiplied by 0.9456 each step, reaching rounding scale in 1000 steps. Both solutions interpolate, but the one from w0\vb{w}_0 has norm 5.566 versus 0.598: it retains the entire null-space component of w0\vb{w}_0, unchanged even at the fourth digit.

The second cell checks the Ali, Kolter and Tibshirani theorem: it calculates proof constant cc and exact risks of both paths for an unequal spectrum, and validates ridge risk against scikit-learn Ridge. Watch the scale: scikit-learn minimizes ∥y−Xb∥2+a∥b∥2\norm{\vb{y} - \mat{X}\vb{b}}^2 + a\norm{\vb{b}}^2, so this lesson’s λ\lambda corresponds to a=nλa = n\lambda.

[ ]Early stopping versus ridge: exact risksBrowser
import numpy as np
from scipy.optimize import minimize_scalar
from sklearn.linear_model import Ridge

c = lambda x: (1 - np.exp(-x)) * (1 + x) / x
opt = minimize_scalar(lambda x: -c(x), bounds=(1e-6, 20), method="bounded")
print(f"c = sup (1 - e^-x)(1 + x)/x = {c(opt.x):.5f} en x = {opt.x:.3f};  c^2 = {c(opt.x)**2:.5f}")

rng = np.random.default_rng(1)
n, d, sigma = 100, 60, 1.0
X = rng.normal(size=(n, d)) @ np.diag(np.linspace(0.2, 2.0, d))   # espectro desigual
beta0 = rng.normal(size=d) / np.sqrt(d)
mu, V = np.linalg.eigh(X.T @ X / n)
b2 = (V.T @ beta0) ** 2

def risk(g):
    """E||b - beta0||^2 de un estimador espectral con filtro g(mu)."""
    return np.sum((1 - g) ** 2 * b2) + sigma**2 / n * np.sum(g**2 / mu)

taus = np.logspace(-1, 3, 400)
r_gf = np.array([risk(1 - np.exp(-mu * t)) for t in taus])
r_rd = np.array([risk(mu / (mu + 1 / t)) for t in taus])
print(f"máx riesgo(flujo, tau) / riesgo(ridge, 1/tau) = {np.max(r_gf / r_rd):.4f}  (cota: 1.6862)")
print(f"riesgo óptimo: flujo {r_gf.min():.4f}, ridge {r_rd.min():.4f}")

# la fórmula frente a scikit-learn, con lambda = 1/tau = 0.2
tau = 5.0
y = X @ beta0 + sigma * rng.normal(size=n)
b_sk = Ridge(alpha=n / tau, fit_intercept=False).fit(X, y).coef_
b_np = np.linalg.solve(X.T @ X / n + np.eye(d) / tau, X.T @ y / n)
print(f"Ridge de sklearn frente a la fórmula: diferencia {np.linalg.norm(b_sk - b_np):.1e}")
A = np.linalg.solve(X.T @ X / n + np.eye(d) / tau, X.T / n)      # b = A y
E = sigma * rng.normal(size=(n, 4000))
errs = np.sum((A @ (X @ beta0[:, None] + E) - beta0[:, None]) ** 2, axis=0)
print(f"riesgo de ridge con tau = 5: fórmula {risk(mu / (mu + 1 / tau)):.4f}, Monte Carlo {errs.mean():.4f}")

The maximum of cc is 1.2984 at x≈1.79x \approx 1.79, and its square is 1.6859. In this problem the risk ratio across the path never exceeds 1.38 and optimal risks nearly coincide.

Now logistic regression. The cell uses the same twelve points as the figure, calculates hard-margin SVM without intercept by its dual, and compares with LinearSVC (without intercept and with large CC, approaching hard margin on separable data) and SVC. It then runs GD and compares angle with theorem asymptote w^log⁡t+w~\hat{\vb{w}}\log t + \tilde{\vb{w}}.

[ ]Logistic regression: GD versus maximum-margin SVMBrowser
import numpy as np
from scipy.optimize import minimize
from sklearn.svm import LinearSVC, SVC

pos = np.array([[3.6, 1.1], [4.1, 0.6], [3.3, 0.3], [4.4, 1.4], [3.8, -0.2], [0.2, 1.3]])
neg = np.array([[-3.7, -0.9], [-4.2, -0.4], [-3.4, -1.3], [-4.0, -0.3], [-3.1, -0.5], [0.9, -0.9]])
Xc = np.vstack([pos, neg])
yc = np.r_[np.ones(6), -np.ones(6)]
Z = yc[:, None] * Xc

# SVM de margen duro homogéneo por su dual: max sum(a) - ||Z^T a||^2 / 2, a >= 0
dual = minimize(lambda a: 0.5 * np.sum((Z.T @ a) ** 2) - a.sum(), np.zeros(12),
                jac=lambda a: Z @ (Z.T @ a) - 1, bounds=[(0, None)] * 12, method="L-BFGS-B",
                options={"ftol": 1e-15, "gtol": 1e-12})
w_hat = Z.T @ dual.x
print("w_hat =", np.round(w_hat, 4), " márgenes:", np.round(np.sort(Z @ w_hat), 3))

def ang(a, b):
    return np.degrees(np.arccos(np.clip(a @ b / np.linalg.norm(a) / np.linalg.norm(b), -1, 1)))

lsvc = LinearSVC(loss="hinge", fit_intercept=False, C=1e3, tol=1e-10, max_iter=1_000_000).fit(Xc, yc)
svc = SVC(kernel="linear", C=1e6).fit(Xc, yc)
print(f"LinearSVC sin intercepto: ángulo con w_hat = {ang(lsvc.coef_[0], w_hat):.4f}°")
print(f"SVC con intercepto (b = {svc.intercept_[0]:.3f}): ángulo con w_hat = {ang(svc.coef_[0], w_hat):.2f}°")

eta = 0.9 * 8 / np.linalg.norm(Z, 2) ** 2       # eta < 2 / (beta sigma_max^2) con beta = 1/4
S = np.where(Z @ w_hat < 1 + 1e-6)[0]
alpha_sv = dual.x[S]
w_tilde = np.linalg.solve(Z[S], -np.log(alpha_sv / eta))   # eta exp(-z_n^T w~) = alpha_n
print(f"eta = {eta:.4f}, vectores soporte {S}, alpha = {np.round(alpha_sv, 4)}")
print("     t   ángulo(w_t, w_hat)   asíntota   ||w_t||   ||w_hat|| log t")
w = np.zeros(2)
for t in range(1, 20_001):
    w += eta * Z.T @ (1 / (1 + np.exp(Z @ w)))
    if t in (1, 10, 100, 1000, 10_000, 20_000):
        th = w_hat * np.log(t) + w_tilde
        asin = f"{ang(th, w_hat):8.3f}°" if t >= 100 else "       -  "
        print(f"{t:6d}   {ang(w, w_hat):8.3f}°   {asin}   {np.linalg.norm(w):7.3f}   {np.linalg.norm(w_hat) * np.log(t):7.3f}")

LinearSVC without intercept matches the dual. SVC does not, and not due to inaccuracy: its intercept bb is unpenalized, so it solves another problem and its weight vector makes about 9° with w^\hat{\vb{w}}. GD treats any intercept as another weight (if a column of ones is added to X\mat{X}), so it converges to the SVM that also penalizes bb, solved by LinearSVC. The final table shows the logarithmic march: from 63.4° to 1.7° in 10410^4 steps and only 1.5° after doubling iterations, with asymptote increasingly close (1.67° at t=104t = 10^4, 1.50° at t=2⋅104t = 2\cdot 10^4). Norm lies below ∥w^∥log⁡t\norm{\hat{\vb{w}}}\log t because w~\tilde{\vb{w}} has a negative component along w^\hat{\vb{w}}.

Lab: diagonal linear networks and initialization scale

The second lab reproduces the transition from ℓ2\ell_2 to ℓ1\ell_1. References are minimum ℓ1\ell_1 norm, a linear program (w=w+−w−\vb{w} = \vb{w}^+ - \vb{w}^- with w±≥0\vb{w}^\pm \ge 0), and minimum ℓ2\ell_2 norm, the pseudoinverse.

[ ]GD on w = u⊙u − v⊙v at different scalesBrowser
import numpy as np
from scipy.optimize import linprog

rng = np.random.default_rng(0)
n, d, k = 20, 50, 3
X = rng.normal(size=(n, d)) / np.sqrt(n)
w_star = np.zeros(d)
supp = rng.choice(d, k, replace=False)
w_star[supp] = rng.choice([-1, 1], k) * rng.uniform(1, 2, k)
y = X @ w_star

# referencias: mínima norma l1 (programa lineal) y mínima norma l2 (pseudoinversa)
lp = linprog(np.ones(2 * d), A_eq=np.hstack([X, -X]), b_eq=y, bounds=(0, None))
w_l1 = lp.x[:d] - lp.x[d:]
w_l2 = np.linalg.pinv(X) @ y
print(f"mínima l1: error {np.linalg.norm(w_l1 - w_star):.1e}, ||w||_1 = {np.abs(w_l1).sum():.3f}")
print(f"mínima l2: error {np.linalg.norm(w_l2 - w_star):.3f}, ||w||_1 = {np.abs(w_l2).sum():.3f}")

def gd_diagonal(X, y, alpha, T=60_000, tol=1e-6):
    """GD sobre ||X(u*u - v*v) - y||^2 / 2 desde u = v = alpha * 1."""
    L = np.linalg.norm(X, 2) ** 2
    eta = 0.2 / (L * max(1.0, alpha**2))
    u = np.full(X.shape[1], float(alpha))
    v = u.copy()
    for t in range(T):
        r = X @ (u * u - v * v) - y
        if t % 50 == 0 and np.linalg.norm(r) < tol:
            break
        g = X.T @ r
        u *= 1 - 2 * eta * g
        v *= 1 + 2 * eta * g
    return u * u - v * v, t

print(" alpha    pasos   error   ||w||_1   coef. > 0.05")
res_gd = {}
for alpha in [0.03, 0.1, 0.3, 1.0]:
    w, steps = gd_diagonal(X, y, alpha)
    res_gd[alpha] = w
    print(f"{alpha:6.2f}  {steps:6d}   {np.linalg.norm(w - w_star):.3f}   {np.abs(w).sum():.3f}     {np.sum(np.abs(w) > 0.05)}")

With α=1\alpha = 1 GD reproduces minimum ℓ2\ell_2-norm solution (error 1.945 versus 1.948 for the pseudoinverse) and distributes weight over 41 coordinates. As α\alpha falls, error and ℓ1\ell_1 norm fall and the solution concentrates: with α=0.03\alpha = 0.03, 8 coordinates remain above 0.05 and error is 0.333. Notice the steps column: each threefold scale reduction costs several times more iterations.

For smaller scales GD needs too many steps for a browser cell, but the theorem gives the limit without training: the QαQ_\alpha minimizer with Xw=y\mat{X}\vb{w} = \vb{y}. By the derivation, w=2α2sinh⁡(X⊤ν)\vb{w} = 2\alpha^2\sinh(\mat{X}\T\vb{\nu}) with ν\vb{\nu} the critical point of convex dual φ(ν)=∑i2α2cosh⁡((X⊤ν)i)−y⊤ν\varphi(\vb{\nu}) = \sum_i 2\alpha^2\cosh((\mat{X}\T\vb{\nu})_i) - \vb{y}\T\vb{\nu}, found in a few Newton iterations.

[ ]The exact limit: minimizing Q_αBrowser
def q_alpha_min(X, y, alpha, iters=100):
    """argmin Q_alpha(w) s.a. Xw = y por Newton sobre el dual: w = 2 alpha^2 sinh(X^T nu)."""
    a2 = alpha**2
    nu = np.zeros(X.shape[0])
    def phi(v):
        with np.errstate(over="ignore"):
            return np.sum(2 * a2 * np.cosh(X.T @ v)) - y @ v
    for _ in range(iters):
        z = X.T @ nu
        grad = X @ (2 * a2 * np.sinh(z)) - y
        if np.linalg.norm(grad) < 1e-12:
            break
        H = (X * (2 * a2 * np.cosh(z))) @ X.T
        step = np.linalg.solve(H, -grad)
        s = 1.0
        while phi(nu + s * step) > phi(nu) + 0.25 * s * grad @ step:
            s /= 2
        nu = nu + s * step
    return 2 * a2 * np.sinh(X.T @ nu)

for alpha in [0.03, 0.1, 1.0]:
    print(f"alpha = {alpha:4.2f}: ||w_GD - argmin Q_alpha|| = {np.linalg.norm(res_gd[alpha] - q_alpha_min(X, y, alpha)):.4f}")
print("  alpha    error de argmin Q_alpha   ||w||_1")
for alpha in [1e-4, 1e-3, 1e-2, 1e-1, 1.0, 10.0]:
    wq = q_alpha_min(X, y, alpha)
    print(f"{alpha:7.0e}   {np.linalg.norm(wq - w_star):.4f}                  {np.abs(wq).sum():.3f}")
print(f"alpha = 10:   ||argmin Q - X^+ y|| = {np.linalg.norm(q_alpha_min(X, y, 10.0) - w_l2):.1e}")
print(f"alpha = 1e-4: ||argmin Q - w_l1||  = {np.linalg.norm(q_alpha_min(X, y, 1e-4) - w_l1):.1e}")

GD and the QαQ_\alpha minimizer are within 0.02 of each other, compared with distances of order 1 between solutions with different α\alpha; remaining difference is finite step size, since the theorem concerns continuous flow. The table completes the transition: recovery error falls from 1.94 at α=1\alpha = 1 to 0.12 at α=10−2\alpha = 10^{-2} and 0.0017 at α=10−4\alpha = 10^{-4}, and ℓ1\ell_1 norm approaches the minimum ℓ1\ell_1-norm solution’s value. The limit is slow: α=10−4\alpha = 10^{-4} is needed to approach minimum ℓ1\ell_1 within 10−210^{-2} because correction to log⁡(1/α2)∥w∥1\log(1/\alpha^2)\norm{\vb{w}}_1 is relative order 1/log⁡(1/α2)1/\log(1/\alpha^2). Woodworth et al. quantify this slowness in Theorem 2.

Common mistakes

Exercises

NumericThe GD filter at an eigenvalue
GD from 0\vb{0} with step η=0.1\eta = 0.1 has run t=20t = 20 iterations. Calculate filter gtGD(μ)=1−(1−ημ)tg^{\mathrm{GD}}_t(\mu) = 1 - (1 - \eta\mu)^t at eigenvalue μ=0.5\mu = 0.5. (Then compare with ridge at λ=1/(ηt)\lambda = 1/(\eta t).)
QuizHow fast does direction arrive?
According to Soudry et al., for separable data and logistic loss, at what rate does distance between wt/∥wt∥\vb{w}_t/\|\vb{w}_t\| and w^/∥w^∥\hat{\vb{w}}/\|\hat{\vb{w}}\| converge for almost every dataset?
NumericThe cost of halving the angle
Suppose the angle between wt\vb{w}_t and w^\hat{\vb{w}} behaves exactly as c/log⁡tc/\log t and is 0.10.1 radians at t=103t = 10^3. At what iteration tt is it 0.050.05 radians?
QuizWhat changes the least-squares limit?
Least squares with d>nd > n and rank⁡X=n\rank\mat{X} = n. Starting from w0=0\vb{w}_0 = \vb{0} with stable-step GD reaches X+y\mat{X}^{+}\vb{y}. Which changes generally yield a different limiting interpolator? (Assume the method still converges.)

More than one answer may be correct.

QuizWhat the Ali, Kolter and Tibshirani theorem says
With calibration λ=1/τ\lambda = 1/\tau, which claim follows from the proof of bound 1.68621.6862?
QuizSmall or large
In diagonal network w=u⊙u−v⊙v\vb{w} = \vb{u}\odot\vb{u} - \vb{v}\odot\vb{v} initialized at α1\alpha\vb{1}, you want to recover sparse w⋆\vb{w}^\star from few noiseless measurements. Which scale and why?
NumericHow many passes?
You train logistic regression with ∥x∥≤1\|\vb{x}\| \le 1 (so L=1L = 1 and β=1/4\beta = 1/4) on n=104n = 10^4 examples using constant-step SGD α=0.01\alpha = 0.01. You want the Hardt, Recht and Singer bound to guarantee εstab≤0.05\varepsilon_{\mathrm{stab}} \le 0.05. How many complete data passes can you make at most?
ProofGD from zero converges to the pseudoinverse
Prove: Let X∈Rn×d\mat{X} \in \R^{n\times d} with invertible XX⊤\mat{X}\mat{X}\T and R^(w)=∥Xw−y∥2/(2n)\hat{R}(\vb{w}) = \|\mat{X}\vb{w} - \vb{y}\|^2/(2n). GD with 0<η<2/μ10 < \eta < 2/\mu_1 from w0=0\vb{w}_0 = \vb{0} converges to X+y=X⊤(XX⊤)−1y\mat{X}^{+}\vb{y} = \mat{X}\T(\mat{X}\mat{X}\T)^{-1}\vb{y}, the minimum-norm interpolator.
0
Let Σ^=X⊤X/n\hat{\mat{\Sigma}} = \mat{X}\T\mat{X}/n and w†=X⊤(XX⊤)−1y\vb{w}^\dagger = \mat{X}\T(\mat{X}\mat{X}\T)^{-1}\vb{y}.

Step 1 of 4. Which property of iterates do you use first?

ProofThe Hardt, Recht and Singer stability bound
Prove: If f(⋅;z)f(\cdot; z) is convex, β\beta-smooth and LL-Lipschitz for every zz, SGD with steps αt≤2/β\alpha_t \le 2/\beta for TT steps is uniformly stable with εstab≤2L2n∑t=1Tαt\varepsilon_{\mathrm{stab}} \le \frac{2L^2}{n}\sum_{t=1}^T\alpha_t.
0
Let SS and S′S' be size-nn samples differing only at example jj.

Step 1 of 5. How do you compare runs on SS and S′S'?

CodeLeast-squares GD and its limit
Implement gd_least_squares(X, y, w0, eta, T) returning weights after T GD steps on R^(w)=∥Xw−y∥2/(2n)\hat{R}(\vb{w}) = \|\mat{X}\vb{w} - \vb{y}\|^2/(2n) from w0 with step eta. Do not modify w0. Tests check one exact step, convergence from zero to the pseudoinverse and convergence from w0 to X+y\mat{X}^{+}\vb{y} plus the projection of w0 onto the null space of X\mat{X}.
import numpy as np

def gd_least_squares(X, y, w0, eta, T):
  """Pesos tras T pasos de GD sobre ||Xw - y||^2 / (2n) desde w0."""
  w = np.array(w0, dtype=float)
  # tu código: T actualizaciones w <- w - eta * gradiente
  return w
Shift+Enter to run

Summary

Key idea
When empirical risk has many minimizers, the algorithm decides which is obtained, and that choice is an unwritten regularizer: minimum ℓ2\ell_2 norm for least-squares GD, ridge for early-stopped GD, maximum margin for separable-classification GD, a norm between ℓ1\ell_1 and ℓ2\ell_2 fixed by initialization scale for a diagonal network, and stability for SGD with few passes.
  • Least-squares GD stays in w0+row⁡(X)\vb{w}_0 + \row(\mat{X}) and converges to the minimizer closest to w0\vb{w}_0; from zero, to X+y\mat{X}\pinv\vb{y}. Step and momentum do not change the limit; initialization, preconditioning and parameterization do.
  • Stopping at iteration tt applies filter 1−(1−ημ)t1 - (1 - \eta\mu)^t to each eigendirection, almost ridge’s μ/(μ+λ)\mu/(\mu + \lambda) with λ=1/(ηt)\lambda = 1/(\eta t). Gradient flow has less bias than ridge and at most 1.69 times its variance.
  • With separable data, logistic regression drives norm to infinity as ∥w^∥log⁡t\norm{\hat{\vb{w}}}\log t and direction to maximum-margin SVM at rate 1/log⁡t1/\log t: halving angular error requires squaring tt.
  • Implicit bias depends on parameterization: in w=u⊙u−v⊙v\vb{w} = \vb{u}\odot\vb{u} - \vb{v}\odot\vb{v}, the limit minimizes QαQ_\alpha, ranging from ℓ2\ell_2 (kernel regime, large α\alpha) to ℓ1\ell_1 (rich regime, small α\alpha). Not every implicit bias minimizes a norm.
  • SGD with steps αt≤2/β\alpha_t \le 2/\beta on convex losses is 2L2n∑tαt\frac{2L^2}{n}\sum_t\alpha_t-uniformly stable: with constant step the bound is 2L2α2L^2\alpha per pass, independent of hypothesis class.
  • For deep networks these results explain the kernel regime and partly homogeneous-network margins, but not the general rich regime: actual bias depends on architecture, initialization, step, optimizer and normalization.