Simple Algorithm
Machine Learning · Convergence · 30 min

Convergence of SGD

Robbins–Monro conditions, step-size schedules and averaging.

Stochastic approximation is older than machine learning, and its theory is sharp: we know which step sizes converge, at what rates, and that no method using noisy gradients can do better. This lesson proves almost-sure convergence under the Robbins–Monro conditions, the optimal rates for convex and strongly convex problems, why the right average of the iterates matters, the rate for nonconvex problems, and the lower bounds that make all of these rates optimal.

What you’ll learn

  • Prove almost-sure convergence of SGD on strongly convex problems under the Robbins–Monro conditions, using the Robbins–Siegmund lemma.
  • Prove the RG/TRG/\sqrt T rate of averaged SGD on convex problems, and explain how step sizes and averaging interact.
  • Prove E∥xT−x⋆∥2≤4G2/(μ2T)\E\norm{\mathbf x_T-\mathbf x^\star}^2\le4G^2/(\mu^2T) for the step 1/(μt)1/(\mu t), and explain why uniform averaging loses a log⁡T\log T factor and how suffix or weighted averaging recovers O(1/T)\order{1/T}.
  • State Polyak–Ruppert averaging, the O(ε−4)\order{\varepsilon^{-4}} guarantee for smooth nonconvex problems, and the lower bounds that match them.

Stochastic approximation and almost-sure convergence

The model. Minimize F(x)=Eξ[f(x,ξ)]F(\mathbf x)=\E_\xi[f(\mathbf x,\xi)] over a closed convex set X\mathcal X (possibly all of Rd\R^d). At step tt an oracle returns a random gt\mathbf g_t with E[gt∣Ft]∈∂F(xt)\E[\mathbf g_t\mid\mathcal F_t]\in\partial F(\mathbf x_t), an unbiased (sub)gradient given the past Ft\mathcal F_t, and SGD moves to xt+1=ΠX(xt−ηtgt)\mathbf x_{t+1}=\Pi_{\mathcal X}(\mathbf x_t-\eta_t\mathbf g_t), where ΠX\Pi_{\mathcal X} is the Euclidean projection. Empirical risk with uniform sampling and single-pass learning on fresh data are both instances.

Robbins & Monro (1951) introduced the method to find a root of a function observed only through noise, under the step conditions ∑tηt=∞\sum_t\eta_t=\infty and ∑tηt2<∞\sum_t\eta_t^2<\infty, and proved that the iterates converge in probability. Almost-sure convergence followed soon after (Blum, 1954), and Robbins & Siegmund (1971) distilled the supermartingale argument behind such proofs into a lemma.

DerivationProof
  1. E[Vt+1∣Ft]=Vt−2ηt ∇F(xt)⊤(xt−x⋆)+ηt2 E[∥gt∥2∣Ft]\E[V_{t+1}\mid\mathcal F_t]=V_t-2\eta_t\,\nabla F(\mathbf x_t)^\top(\mathbf x_t-\mathbf x^\star)+\eta_t^2\,\E\big[\norm{\mathbf g_t}^2\mid\mathcal F_t\big]

    Expand the squared distance Vt=∥xt−x⋆∥2V_t=\norm{\mathbf x_t-\mathbf x^\star}^2 after one step and take the conditional expectation:

  2. E[Vt+1∣Ft]≤(1+Bηt2)Vt+Aηt2−2μηtVt\E[V_{t+1}\mid\mathcal F_t]\le\big(1+B\eta_t^2\big)V_t+A\eta_t^2-2\mu\eta_tV_t

    Strong convexity and ∇F(x⋆)=0\nabla F(\mathbf x^\star)=\mathbf 0 give ∇F(x)⊤(x−x⋆)≥μ∥x−x⋆∥2\nabla F(\mathbf x)^\top(\mathbf x-\mathbf x^\star)\ge\mu\norm{\mathbf x-\mathbf x^\star}^2; insert the moment bound:

  3. ∑tηt Vt<∞almost surely\sum_t\eta_t\,V_t<\infty\quad\text{almost surely}

    This is the Robbins–Siegmund form with at=Bηt2a_t=B\eta_t^2, bt=Aηt2b_t=A\eta_t^2, ct=2μηtVtc_t=2\mu\eta_tV_t; the condition ∑ηt2<∞\sum\eta_t^2<\infty makes ∑at\sum a_t and ∑bt\sum b_t finite. So Vt→V∞V_t\to V_\infty almost surely, and:

  4. V∞=lim⁡tVt=lim inf⁡tVt=0V_\infty=\lim_tV_t=\liminf_tV_t=0

    Because ∑tηt=∞\sum_t\eta_t=\infty, a convergent ∑tηtVt\sum_t\eta_tV_t forces lim inf⁡tVt=0\liminf_tV_t=0. A convergent sequence with lim inf⁡\liminf zero has limit zero. ■\blacksquare

The two conditions play exactly the roles the proof shows: ∑ηt2<∞\sum\eta_t^2<\infty caps the total injected noise, and ∑ηt=∞\sum\eta_t=\infty keeps enough "drift" to reach the optimum from anywhere. The moment condition A+B∥x−x⋆∥2A+B\norm{\mathbf x-\mathbf x^\star}^2 matters in practice: for least squares the gradient grows linearly with x\mathbf x, so a uniform bound E∥g∥2≤G2\E\norm{\mathbf g}^2\le G^2 cannot hold on all of Rd\R^d, and analyses that assume one implicitly project onto a bounded set.

Convex problems: the 1/√T rate

DerivationProof
  1. 2η E[F(xt)−F⋆]≤E∥xt−x⋆∥2−E∥xt+1−x⋆∥2+η2G22\eta\,\E\big[F(\mathbf x_t)-F^\star\big]\le\E\norm{\mathbf x_t-\mathbf x^\star}^2-\E\norm{\mathbf x_{t+1}-\mathbf x^\star}^2+\eta^2G^2

    Expand the distance as before, take expectations, and use convexity, F(xt)−F⋆≤∇F(xt)⊤(xt−x⋆)F(\mathbf x_t)-F^\star\le\nabla F(\mathbf x_t)^\top(\mathbf x_t-\mathbf x^\star) (any subgradient works):

  2. 1T∑t<TE[F(xt)−F⋆]≤R22ηT+ηG22\frac1T\sum_{t<T}\E\big[F(\mathbf x_t)-F^\star\big]\le\frac{R^2}{2\eta T}+\frac{\eta G^2}2

    Sum over t=0,…,T−1t=0,\dots,T-1; the distances telescope and the last one is dropped:

  3. EF(xˉT)−F⋆≤R22ηT+ηG22=RG2T+RG2T=RGT■\E F(\bar{\mathbf x}_T)-F^\star\le\frac{R^2}{2\eta T}+\frac{\eta G^2}2=\frac{RG}{2\sqrt T}+\frac{RG}{2\sqrt T}=\frac{RG}{\sqrt T}\qquad\blacksquare

    Jensen's inequality moves the average inside FF. Balancing the two terms gives η=R/(GT)\eta=R/(G\sqrt T):

Three things to notice. First, the rate does not depend on the dimension, nor on whether the gradients are exact: noisy SGD matches the deterministic subgradient method, and no method can do better in the worst case. Agarwal, Bartlett, Ravikumar & Wainwright (2012) proved information-theoretic lower bounds of order 1/T1/\sqrt T for stochastic convex Lipschitz problems, matching the classical Ω(RG/T)\Omega(RG/\sqrt T) of Nemirovski & Yudin for this class (Lower Bounds & Oracle Complexity).

Second, the step must know TT, or must decay like 1/t1/\sqrt t; with decaying steps the same telescoping needs a bounded domain (projection onto a set of diameter DD) and gives O(DG/T)\order{DG/\sqrt T}. Third, the average is what is guaranteed. Shamir & Zhang (2013) showed the last iterate is within O(log⁡T/T)\order{\log T/\sqrt T}, a logarithm worse.

Check your understanding

Averaged SGD on a convex Lipschitz problem reaches EF(xˉT)−F⋆≤0.01\E F(\bar{\mathbf x}_T)-F^\star\le0.01 after T=104T=10^4 steps, with the optimally tuned constant step. Roughly how many steps does the bound need for 0.0010.001?

  1. 10510^5
  2. 10610^6
  3. 2×1042\times10^4
  4. 10810^8
Show the answer

B. 10610^6

The bound scales like RG/TRG/\sqrt T, so each tenfold improvement in accuracy costs a hundredfold more steps: ε−2\varepsilon^{-2} complexity. That is the price of noise (and of nonsmoothness), and it cannot be avoided in the worst case.

Strongly convex problems: 1/T, and which average

DerivationProof by induction
  1. at+1≤(1−2μηt) at+ηt2G2=(1−2t)at+G2μ2t2a_{t+1}\le(1-2\mu\eta_t)\,a_t+\eta_t^2G^2=\Big(1-\frac2t\Big)a_t+\frac{G^2}{\mu^2t^2}

    Projection onto X∋x⋆\mathcal X\ni\mathbf x^\star does not increase distances. With at=E∥xt−x⋆∥2a_t=\E\norm{\mathbf x_t-\mathbf x^\star}^2 and strong convexity, E[∇F(xt)⊤(xt−x⋆)]≥μat\E[\nabla F(\mathbf x_t)^\top(\mathbf x_t-\mathbf x^\star)]\ge\mu a_t, the usual expansion gives

  2. a1≤G2μ2≤4G2μ2,a2≤−a1+G2μ2≤4G22μ2a_1\le\frac{G^2}{\mu^2}\le\frac{4G^2}{\mu^2},\qquad a_2\le-a_1+\frac{G^2}{\mu^2}\le\frac{4G^2}{2\mu^2}

    Base. Strong convexity and optimality of x⋆\mathbf x^\star give ∥∇F(x)∥≥μ∥x−x⋆∥\norm{\nabla F(\mathbf x)}\ge\mu\norm{\mathbf x-\mathbf x^\star}, and ∥∇F(x)∥2=∥Eg∥2≤G2\norm{\nabla F(\mathbf x)}^2=\norm{\E\mathbf g}^2\le G^2, so every point has ∥x−x⋆∥≤G/μ\norm{\mathbf x-\mathbf x^\star}\le G/\mu:

  3. at+1≤G2μ2[(1−2t)4t+1t2]=G2μ2(4t−7t2)≤4G2μ2(t+1)a_{t+1}\le\frac{G^2}{\mu^2}\Big[\Big(1-\frac2t\Big)\frac4t+\frac1{t^2}\Big]=\frac{G^2}{\mu^2}\Big(\frac4t-\frac7{t^2}\Big)\le\frac{4G^2}{\mu^2(t+1)}

    Step (t≥2t\ge2). If at≤4G2/(μ2t)a_t\le4G^2/(\mu^2t), the recursion gives the bound below, and 4t−7t2≤4t+1\frac4t-\frac7{t^2}\le\frac4{t+1} is equivalent to 4t≤7(t+1)4t\le7(t+1), which always holds:

  4. EF(xT)−F⋆≤L2⋅4G2μ2T=2LG2μ2T\E F(\mathbf x_T)-F^\star\le\frac L2\cdot\frac{4G^2}{\mu^2T}=\frac{2LG^2}{\mu^2T}

    For LL-smooth FF (with ∇F(x⋆)=0\nabla F(\mathbf x^\star)=\mathbf 0), F(x)−F⋆≤L2∥x−x⋆∥2F(\mathbf x)-F^\star\le\frac L2\norm{\mathbf x-\mathbf x^\star}^2 turns the distance bound into the value bound. ■\blacksquare

Which iterate to return matters when FF is not smooth. Averaging all iterates is natural, but Rakhlin, Shamir & Sridharan showed that for nonsmooth strongly convex problems it can be stuck at Ω(log⁡T/T)\Omega(\log T/T), and that averaging only the last αT\alpha T iterates (α\alpha-suffix averaging) restores O(G2/(μT))\order{G^2/(\mu T)}. Lacoste-Julien, Schmidt & Bach (2012) gave a simpler fix: steps 2μ(t+1)\frac2{\mu(t+1)} and weights proportional to t+1t+1 yield EF(xˉ)−F⋆≤2G2μ(T+1)\E F(\bar{\mathbf x})-F^\star\le\frac{2G^2}{\mu(T+1)}, computable on the fly. The last iterate itself is within O(log⁡T/T)\order{\log T/T} (Shamir & Zhang, 2013), and Harvey, Liaw, Plan & Randhawa (2019) showed that for nonsmooth strongly convex functions this logarithm is genuinely there with these steps, even for gradient descent without noise. The rate G2/(μT)G^2/(\mu T) is optimal: no stochastic first-order method beats it in the worst case (Agarwal et al., 2012).

Predict before you look

On f(x)=c2x2f(x)=\frac c2x^2 without noise, the steps ηt=θ/t\eta_t=\theta/t give xt+1=(1−cθt)xtx_{t+1}=(1-\frac{c\theta}t)x_t, so ∣xt∣\abs{x_t} decays like t−at^{-a} when cθ<1c\theta<1. In the example above (c=0.2c=0.2, θ=1\theta=1), what is the exponent aa?

Show the answer

0.2

∏s(1−cθ/s)≈exp⁡(−cθln⁡t)=t−cθ\prod_s(1-c\theta/s)\approx\exp(-c\theta\ln t)=t^{-c\theta}, so a=cθ=0.2a=c\theta=0.2. The rate is tied to the product of the curvature and the step constant: the "optimal" 1/t1/t schedule is only optimal if its constant is at least about 1/μ1/\mu.

Averaging, smooth problems and nonconvexity

H−1SH−1H^{-1}SH^{-1} is the best asymptotic covariance any estimator built from TT samples can have here: it is the "sandwich" covariance of the empirical risk minimizer on TT samples, which for a well-specified likelihood is the inverse Fisher information (Cramér–Rao). Without averaging, SGD reaches it only with the matrix step H−1/tH^{-1}/t, which requires knowing HH. Averaging long, noisy steps gets it for free, with no tuning of μ\mu: the theoretical justification for robust stochastic approximation. Bach & Moulines (2013) pushed this further: for least squares, averaged SGD with a constant step achieves an O(1/n)\order{1/n} rate after nn samples without any strong convexity.

Smooth nonconvex problems. Without convexity the target is a point with a small gradient. Repeating the noise-ball argument of the Descent lesson without the Polyak–Łojasiewicz step gives the following guarantee, in the spirit of Ghadimi & Lan (2013), who analyzed SGD that returns a randomly chosen iterate.

DerivationSGD finds approximate stationary points
  1. EF(xt+1)≤EF(xt)−η2 E∥∇F(xt)∥2+Lη2σ22\E F(\mathbf x_{t+1})\le\E F(\mathbf x_t)-\frac\eta2\,\E\norm{\nabla F(\mathbf x_t)}^2+\frac{L\eta^2\sigma^2}2

    Let FF be LL-smooth with Δ=F(x0)−inf⁡F\Delta=F(\mathbf x_0)-\inf F, and the gradients unbiased with variance at most σ2\sigma^2. For a constant η≤1/L\eta\le1/L, the smoothness expansion gives, in expectation,

  2. E∥∇F(xτ)∥2=1T∑t<TE∥∇F(xt)∥2≤2ΔηT+Lησ2\E\norm{\nabla F(\mathbf x_\tau)}^2=\frac1T\sum_{t<T}\E\norm{\nabla F(\mathbf x_t)}^2\le\frac{2\Delta}{\eta T}+L\eta\sigma^2

    Sum over t<Tt<T and divide by ηT/2\eta T/2. Returning a uniformly random iterate xτ\mathbf x_\tau turns the average into an expectation:

  3. E∥∇F(xτ)∥2≤2LΔT+2σ2LΔT\E\norm{\nabla F(\mathbf x_\tau)}^2\le\frac{2L\Delta}T+2\sigma\sqrt{\frac{2L\Delta}T}

    Choose η=min⁡{1/L,2Δ/(Lσ2T)}\eta=\min\{1/L,\sqrt{2\Delta/(L\sigma^2T)}\} to balance the terms:

  4. T=O(LΔε2+LΔσ2ε4)T=\order{\frac{L\Delta}{\varepsilon^2}+\frac{L\Delta\sigma^2}{\varepsilon^4}}

    To make E∥∇F∥2≤ε2\E\norm{\nabla F}^2\le\varepsilon^2, the noise term needs T≳LΔσ2/ε4T\gtrsim L\Delta\sigma^2/\varepsilon^4: the price of noise is ε−4\varepsilon^{-4}, against ε−2\varepsilon^{-2} for exact gradients.

This is unimprovable. Arjevani, Carmon, Duchi, Foster, Srebro & Woodworth (2023) proved that any algorithm with access to unbiased, bounded-variance stochastic gradients of smooth functions needs order ε−4\varepsilon^{-4} queries to find an ε\varepsilon-stationary point in the worst case, so SGD is minimax optimal in this model. Under the stronger assumption that each stochastic gradient is itself Lipschitz on average (mean-squared smoothness), ε−3\varepsilon^{-3} is achievable and optimal, by the variance-reduction methods of Variance Reduction: SVRG & SAGA.

The complete picture and the frontier

Setting (stochastic first-order oracle)Achieved byRate or complexityLower bound
convex, E∥g∥2≤G2\E\norm{\mathbf g}^2\le G^2, ∥x0−x⋆∥≤R\norm{\mathbf x_0-\mathbf x^\star}\le Raveraged SGD, η∝1/T\eta\propto1/\sqrt TRG/TRG/\sqrt TΩ(RG/T)\Omega(RG/\sqrt T)
μ\mu-strongly convex, E∥g∥2≤G2\E\norm{\mathbf g}^2\le G^2SGD with ηt∝1/(μt)\eta_t\propto1/(\mu t) and suffix or weighted averagingO(G2/(μT))\order{G^2/(\mu T)}Ω(G2/(μT))\Omega(G^2/(\mu T))
smooth, strongly convex, local asymptoticsPolyak–Ruppert averagingcovariance H−1SH−1/TH^{-1}SH^{-1}/Tstatistical (Cramér–Rao)
smooth nonconvex, variance σ2\sigma^2SGD, random iterateO(ε−4)\order{\varepsilon^{-4}} for ∥∇F∥≤ε\norm{\nabla F}\le\varepsilonΩ(ε−4)\Omega(\varepsilon^{-4})
nonconvex, mean-squared smoothrecursive variance reductionO(ε−3)\order{\varepsilon^{-3}}Ω(ε−3)\Omega(\varepsilon^{-3})
Up to constants (and logarithms for some last-iterate statements), the classical theory of SGD is complete: every row is optimal.

Key takeaways

  • Robbins–Monro: ∑ηt=∞\sum\eta_t=\infty and ∑ηt2<∞\sum\eta_t^2<\infty, with the Robbins–Siegmund lemma, give almost-sure convergence on strongly convex problems; the first condition supplies drift, the second caps the noise.
  • Convex problems with E∥g∥2≤G2\E\norm{\mathbf g}^2\le G^2: averaged SGD with η=R/(GT)\eta=R/(G\sqrt T) gets RG/TRG/\sqrt T, which is optimal; the last iterate pays an extra log⁡T\log T.
  • Strongly convex problems: ηt=1/(μt)\eta_t=1/(\mu t) gives E∥xT−x⋆∥2≤4G2/(μ2T)\E\norm{\mathbf x_T-\mathbf x^\star}^2\le4G^2/(\mu^2T); with nonsmooth FF, use suffix or tt-weighted averaging to get O(G2/(μT))\order{G^2/(\mu T)}. Underestimating the step constant can make it collapse to t−cθt^{-c\theta}.
  • Polyak–Ruppert averaging of slowly decaying steps attains the optimal asymptotic covariance H−1SH−1/TH^{-1}SH^{-1}/T without knowing HH or μ\mu.
  • For smooth nonconvex FF, SGD finds E∥∇F∥≤ε\E\norm{\nabla F}\le\varepsilon in O(ε−4)\order{\varepsilon^{-4}} steps, and that is optimal for bounded-variance oracles.

Check yourself

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

Question 1

In the almost-sure convergence proof, what does the condition ∑tηt2<∞\sum_t\eta_t^2<\infty guarantee?

  1. That the iterates move far enough to reach the optimum from any start
  2. That the total noise injected, the bt=Aηt2b_t=A\eta_t^2 terms, is finite, so the Robbins–Siegmund lemma applies
  3. That the gradient is bounded
  4. That the function is strongly convex
Show the answer

B. That the total noise injected, the bt=Aηt2b_t=A\eta_t^2 terms, is finite, so the Robbins–Siegmund lemma applies

Both perturbation terms in E[Vt+1∣Ft]≤(1+Bηt2)Vt+Aηt2−2μηtVt\E[V_{t+1}\mid\mathcal F_t]\le(1+B\eta_t^2)V_t+A\eta_t^2-2\mu\eta_tV_t are proportional to ηt2\eta_t^2; summability makes VtV_t converge. The other condition, ∑ηt=∞\sum\eta_t=\infty, then forces the limit to be zero.

Question 2

SGD with ηt=1/(μt)\eta_t=1/(\mu t) runs on a nonsmooth, μ\mu-strongly convex problem. Which output has an O(1/T)\order{1/T} guarantee in expectation?

  1. The uniform average of all iterates
  2. The average of the last half of the iterates
  3. The first iterate
  4. Only the last iterate
Show the answer

B. The average of the last half of the iterates

α\alpha-suffix averaging (here α=12\alpha=\tfrac12) gives O(G2/(μT))\order{G^2/(\mu T)} (Rakhlin, Shamir & Sridharan, 2012). The uniform average is dragged down by the early, poor iterates and can be stuck at Ω(log⁡T/T)\Omega(\log T/T); the last iterate carries a log⁡T\log T factor too.

Question 3

With unbiased, bounded-variance stochastic gradients of a smooth nonconvex function, how many stochastic gradients does SGD need, in the worst case, to find a point with E∥∇F∥≤ε\E\norm{\nabla F}\le\varepsilon, and can another algorithm do better in that model?

  1. O(ε−2)\order{\varepsilon^{-2}}, and no one can do better
  2. O(ε−4)\order{\varepsilon^{-4}}, and acceleration improves it to ε−2\varepsilon^{-2}
  3. O(ε−4)\order{\varepsilon^{-4}}, and Ω(ε−4)\Omega(\varepsilon^{-4}) is a lower bound for every algorithm in that model
  4. It cannot find such a point in finite time
Show the answer

C. O(ε−4)\order{\varepsilon^{-4}}, and Ω(ε−4)\Omega(\varepsilon^{-4}) is a lower bound for every algorithm in that model

The bound 2LΔ/T+2σ2LΔ/T2L\Delta/T+2\sigma\sqrt{2L\Delta/T} needs T∼LΔσ2/ε4T\sim L\Delta\sigma^2/\varepsilon^4, and Arjevani et al. (2023) showed a matching Ω(ε−4)\Omega(\varepsilon^{-4}) lower bound. Only stronger assumptions (mean-squared smoothness) allow ε−3\varepsilon^{-3}.

Further reading

  • H. Robbins & S. Monro, "A stochastic approximation method," Annals of Mathematical Statistics 22(3), 400–407 (1951).
  • B. T. Polyak & A. B. Juditsky, "Acceleration of stochastic approximation by averaging," SIAM Journal on Control and Optimization 30(4), 838–855 (1992).
  • A. Nemirovski, A. Juditsky, G. Lan & A. Shapiro, "Robust stochastic approximation approach to stochastic programming," SIAM Journal on Optimization 19(4), 1574–1609 (2009).
  • A. Rakhlin, O. Shamir & K. Sridharan, "Making gradient descent optimal for strongly convex stochastic optimization," Proceedings of the 29th ICML (2012); corrected version arXiv:1109.5647.
  • S. Ghadimi & G. Lan, "Stochastic first- and zeroth-order methods for nonconvex stochastic programming," SIAM Journal on Optimization 23(4), 2341–2368 (2013).