Simple Algorithm
Machine Learning · Convergence · 28 min

Variance Reduction: SVRG & SAGA

Linear convergence for finite sums by correcting the noise.

On a fixed training set, SGD's noise floor is self-inflicted: the full gradient is computable, just expensive. Variance-reduced methods correct each cheap stochastic gradient with stored or periodically refreshed information, so that the noise vanishes at the optimum. The payoff is linear convergence at nearly the per-step cost of SGD, O((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)} gradient evaluations instead of O(nκlog⁡(1/ε))\order{n\kappa\log(1/\varepsilon)}. This lesson derives SVRG and SAGA, proves SVRG's rate, and asks why methods so effective on convex problems rarely help deep learning.

What you’ll learn

  • Explain why constant-step SGD stalls on finite sums, and compare the gradient-evaluation complexity of gradient descent, SGD and variance-reduced methods.
  • Derive the SVRG and SAGA estimators as control variates, and prove the bound E∥g∥2≤4L(F(x)−F⋆+F(x~)−F⋆)\E\norm{\mathbf g}^2\le4L\big(F(\mathbf x)-F^\star+F(\tilde{\mathbf x})-F^\star\big).
  • Prove the linear convergence of SVRG and read off its O((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)} complexity.
  • Compare SAG, SAGA, SDCA and accelerated variants with the lower bounds, and weigh the evidence on deep learning.

The noise floor of a finite sum

Take F(x)=1n∑i=1nfi(x)F(\mathbf x)=\frac1n\sum_{i=1}^nf_i(\mathbf x) with every fif_i convex and LL-smooth, FF μ\mu-strongly convex, and κ=L/μ\kappa=L/\mu. At the minimizer ∇F(x⋆)=0\nabla F(\mathbf x^\star)=\mathbf 0, but the individual gradients do not vanish: their spread σ⋆2=1n∑i∥∇fi(x⋆)∥2\sigma_\star^2=\frac1n\sum_i\norm{\nabla f_i(\mathbf x^\star)}^2 is positive unless every example is fitted perfectly. That is the variance that keeps constant-step SGD in its noise ball, and that forces decaying steps and sublinear rates.

Gradient descent has no noise but pays nn gradient evaluations per step. Variance reduction gets the best of both: one or two component gradients per step, and an estimator whose variance goes to zero as the iterates approach x⋆\mathbf x^\star.

MethodGradient evaluations of the fif_i to reach accuracy ε\varepsilonRate type
Gradient descentO(nκlog⁡(1/ε))\order{n\kappa\log(1/\varepsilon)}linear, nn per step
Nesterov's accelerated gradientO(nκlog⁡(1/ε))\order{n\sqrt\kappa\log(1/\varepsilon)}linear, nn per step
SGD, decaying steps and averagingO(σ⋆2/(με))\order{\sigma_\star^2/(\mu\varepsilon)} plus lower-order termssublinear, independent of nn
SAG, SAGA, SVRGO((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)}linear, O(1)\order{1} per step
Accelerated variance reduction (e.g. Katyusha)O((n+nκ)log⁡(1/ε))\order{(n+\sqrt{n\kappa})\log(1/\varepsilon)}linear, optimal
For the full-gradient methods κ\kappa could use the smoothness of FF, which can be smaller than the worst component's LL; with importance sampling, variance-reduced methods can use the average smoothness instead. Ignoring those refinements, the key comparison is nκn\kappa against n+κn+\kappa.
Predict before you look

n=106n=10^6 examples and κ=103\kappa=10^3. Ignoring constants and the shared log⁡(1/ε)\log(1/\varepsilon) factor, how many times fewer component gradients does a variance-reduced method need than gradient descent?

Show the answer

1000 ×

nκ/(n+κ)=109/(1.001×106)≈999n\kappa/(n+\kappa)=10^9/(1.001\times10^6)\approx999. When n≫κn\gg\kappa the ratio is about κ\kappa: variance reduction pays roughly one pass over the data per "condition number's worth" of progress, instead of κ\kappa passes.

Control variates

Monte Carlo has an old trick for estimating EX\E X with less noise: find a YY that is strongly correlated with XX and whose mean is known, and use X−Y+EYX-Y+\E Y. It has the same mean, and variance Var⁡X+Var⁡Y−2Cov⁡(X,Y)\Var X+\Var Y-2\Cov(X,Y), small when Y≈XY\approx X.

For SGD, X=∇fi(x)X=\nabla f_i(\mathbf x) with ii uniform. SVRG (Johnson & Zhang, 2013) takes Y=∇fi(x~)Y=\nabla f_i(\tilde{\mathbf x}) at a snapshot x~\tilde{\mathbf x} where the full gradient ∇F(x~)\nabla F(\tilde{\mathbf x}) was computed once. SAGA (Defazio, Bach & Lacoste-Julien, 2014) keeps a table with the last gradient computed for each example, ∇fj(ϕj)\nabla f_j(\boldsymbol\phi_j), and takes Y=∇fi(ϕi)Y=\nabla f_i(\boldsymbol\phi_i), whose mean is the table's average:

gSVRG=∇fi(x)−∇fi(x~)+∇F(x~),gSAGA=∇fi(x)−∇fi(ϕi)+1n∑j=1n∇fj(ϕj)\mathbf g^{\text{SVRG}}=\nabla f_i(\mathbf x)-\nabla f_i(\tilde{\mathbf x})+\nabla F(\tilde{\mathbf x}),\qquad\mathbf g^{\text{SAGA}}=\nabla f_i(\mathbf x)-\nabla f_i(\boldsymbol\phi_i)+\frac1n\sum_{j=1}^n\nabla f_j(\boldsymbol\phi_j)
Both are unbiased: averaging over ii, the last two terms cancel in expectation and leave ∇F(x)\nabla F(\mathbf x). As x\mathbf x, x~\tilde{\mathbf x} and the ϕj\boldsymbol\phi_j approach x⋆\mathbf x^\star, the first two terms nearly cancel and so does the noise.
DerivationThe variance bound behind every proof
  1. 1n∑i=1n∥∇fi(x)−∇fi(x⋆)∥2≤2L(F(x)−F⋆)\frac1n\sum_{i=1}^n\norm{\nabla f_i(\mathbf x)-\nabla f_i(\mathbf x^\star)}^2\le2L\big(F(\mathbf x)-F^\star\big)

    Lemma. For convex LL-smooth fif_i, fi(x)≥fi(x⋆)+∇fi(x⋆)⊤(x−x⋆)+12L∥∇fi(x)−∇fi(x⋆)∥2f_i(\mathbf x)\ge f_i(\mathbf x^\star)+\nabla f_i(\mathbf x^\star)^\top(\mathbf x-\mathbf x^\star)+\frac1{2L}\norm{\nabla f_i(\mathbf x)-\nabla f_i(\mathbf x^\star)}^2. Average over ii; the linear terms cancel because ∑i∇fi(x⋆)=n∇F(x⋆)=0\sum_i\nabla f_i(\mathbf x^\star)=n\nabla F(\mathbf x^\star)=\mathbf 0:

  2. E∥g∥2≤2 E∥∇fi(x)−∇fi(x⋆)∥2+2 E∥(∇fi(x~)−∇fi(x⋆))−∇F(x~)∥2\E\norm{\mathbf g}^2\le2\,\E\norm{\nabla f_i(\mathbf x)-\nabla f_i(\mathbf x^\star)}^2+2\,\E\norm{\big(\nabla f_i(\tilde{\mathbf x})-\nabla f_i(\mathbf x^\star)\big)-\nabla F(\tilde{\mathbf x})}^2

    Split the SVRG estimator around x⋆\mathbf x^\star and use ∥a+b∥2≤2∥a∥2+2∥b∥2\norm{\mathbf a+\mathbf b}^2\le2\norm{\mathbf a}^2+2\norm{\mathbf b}^2:

  3. E∥g∥2≤4L((F(x)−F⋆)+(F(x~)−F⋆))\E\norm{\mathbf g}^2\le4L\Big(\big(F(\mathbf x)-F^\star\big)+\big(F(\tilde{\mathbf x})-F^\star\big)\Big)

    The second bracket is a random vector minus its mean (∇F(x~)=Ei[∇fi(x~)−∇fi(x⋆)]\nabla F(\tilde{\mathbf x})=\E_i[\nabla f_i(\tilde{\mathbf x})-\nabla f_i(\mathbf x^\star)]), and a variance is at most the second moment. Apply the lemma twice:

  4. Compare SGD, whose second moment at the optimum is σ⋆2>0\sigma_\star^2>0. Here it is bounded by suboptimality gaps that shrink to zero: the noise dies out exactly where it used to hurt.

SVRG and its linear rate

text
SVRG(x̃_0, step η, inner length m)
  for s = 1, 2, ...:
      x̃ ← x̃_{s-1};  μ̃ ← ∇F(x̃) = (1/n) Σ_i ∇f_i(x̃)        # one full pass: n gradients
      x_0 ← x̃
      for t = 0, ..., m-1:
          pick i uniformly from {1..n}
          x_{t+1} ← x_t - η (∇f_i(x_t) - ∇f_i(x̃) + μ̃)      # 2 gradients
      x̃_s ← x_τ for τ uniform in {0, ..., m-1}            # "option II"; practice uses x_m

No table of gradients is stored: only the snapshot and its full gradient. The cost of an outer loop is n+2mn+2m component gradients.

DerivationProof
  1. E∥xt+1−x⋆∥2≤∥xt−x⋆∥2−2η(F(xt)−F⋆)+4Lη2(F(xt)−F⋆+F(x~)−F⋆)\E\norm{\mathbf x_{t+1}-\mathbf x^\star}^2\le\norm{\mathbf x_t-\mathbf x^\star}^2-2\eta\big(F(\mathbf x_t)-F^\star\big)+4L\eta^2\big(F(\mathbf x_t)-F^\star+F(\tilde{\mathbf x})-F^\star\big)

    One inner step. Expand the distance, use unbiasedness, convexity (∇F(xt)⊤(xt−x⋆)≥F(xt)−F⋆\nabla F(\mathbf x_t)^\top(\mathbf x_t-\mathbf x^\star)\ge F(\mathbf x_t)-F^\star) and the variance bound:

  2. 2η(1−2Lη)∑t=0m−1E[F(xt)−F⋆]≤∥x~−x⋆∥2+4Lmη2(F(x~)−F⋆)2\eta(1-2L\eta)\sum_{t=0}^{m-1}\E\big[F(\mathbf x_t)-F^\star\big]\le\norm{\tilde{\mathbf x}-\mathbf x^\star}^2+4Lm\eta^2\big(F(\tilde{\mathbf x})-F^\star\big)

    Sum over t=0,…,m−1t=0,\dots,m-1 (the distances telescope, and x0=x~\mathbf x_0=\tilde{\mathbf x}), dropping the final distance:

  3. 2η(1−2Lη) m E[F(x~s)−F⋆]≤(2μ+4Lmη2)(F(x~)−F⋆)2\eta(1-2L\eta)\,m\,\E\big[F(\tilde{\mathbf x}_s)-F^\star\big]\le\Big(\frac2\mu+4Lm\eta^2\Big)\big(F(\tilde{\mathbf x})-F^\star\big)

    Option II makes the sum m E[F(x~s)−F⋆]m\,\E[F(\tilde{\mathbf x}_s)-F^\star], and strong convexity gives ∥x~−x⋆∥2≤2μ(F(x~)−F⋆)\norm{\tilde{\mathbf x}-\mathbf x^\star}^2\le\frac2\mu\big(F(\tilde{\mathbf x})-F^\star\big):

  4. E[F(x~s)−F⋆]≤(1μη(1−2Lη)m+2Lη1−2Lη)(F(x~s−1)−F⋆)\E\big[F(\tilde{\mathbf x}_s)-F^\star\big]\le\Big(\frac1{\mu\eta(1-2L\eta)m}+\frac{2L\eta}{1-2L\eta}\Big)\big(F(\tilde{\mathbf x}_{s-1})-F^\star\big)

    Divide by 2η(1−2Lη)m2\eta(1-2L\eta)m: the factor is exactly α\alpha. Iterate over outer loops. ■\blacksquare

Predict before you look

Take η=110L\eta=\frac1{10L} and m=50κm=50\kappa inner steps. What is the contraction factor α\alpha per outer loop?

Show the answer

0.5

1−2Lη=0.81-2L\eta=0.8. First term: 1/(μ⋅110L⋅0.8⋅50κ)=1/(0.08⋅50)=141/(\mu\cdot\frac1{10L}\cdot0.8\cdot50\kappa)=1/(0.08\cdot50)=\frac14, using μκ/L=1\mu\kappa/L=1. Second term: 0.2/0.8=140.2/0.8=\frac14. So α=12\alpha=\frac12: each outer loop, costing n+100κn+100\kappa component gradients, halves the gap. Reaching ε\varepsilon takes log⁡2(1/ε)\log_2(1/\varepsilon) loops, hence O((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)} in total.

SAG, SAGA and dual methods

SAG (Le Roux, Schmidt & Bach, 2012; journal version Schmidt, Le Roux & Bach, 2017) was the first stochastic method with a linear rate on strongly convex finite sums at SGD's per-step cost. It steps along the average of the stored gradients, refreshing one entry per step, which amounts to using 1n(∇fi(x)−∇fi(ϕi))+1n∑j∇fj(ϕj)\frac1n\big(\nabla f_i(\mathbf x)-\nabla f_i(\boldsymbol\phi_i)\big)+\frac1n\sum_j\nabla f_j(\boldsymbol\phi_j): the correction is damped by 1n\frac1n. Defazio, Bach & Lacoste-Julien note that, for the same table, SAG's update has 1/n21/n^2 the variance of SAGA's, but it is biased. SAGA's unbiased version gives a short proof and better constants.

SAGA's guarantees: with step γ=12(μn+L)\gamma=\frac1{2(\mu n+L)}, E∥xk−x⋆∥2\E\norm{\mathbf x^k-\mathbf x^\star}^2 contracts by 1−μ2(μn+L)1-\frac{\mu}{2(\mu n+L)} per step (times a constant depending on the start). With the step 13L\frac1{3L}, which does not need μ\mu, the factor is 1−min⁡{14n,μ3L}1-\min\{\frac1{4n},\frac\mu{3L}\}: the method adapts to whatever strong convexity is present, and without any it converges at rate O(n/k)\order{n/k} for the averaged iterate. A proximal step after each update handles nonsmooth regularizers such as the lasso penalty.

MethodExtra memoryGradients per stepNotes
SGDnone1sublinear on finite sums; simplest
SVRGsnapshot and its full gradient, O(d)\order{d}2, plus nn per outer loopneeds mm and η\eta; loopless variants refresh the snapshot at random
SAGAone gradient per example, O(nd)\order{nd}1unbiased; proximal; adapts to μ\mu
SAGas SAGA1biased, lower variance
SDCAone dual variable per example1dual coordinate ascent for regularized ERM (Shalev-Shwartz & Zhang, 2013)
For generalized linear models fi(w)=ℓ(w⊤xi,yi)f_i(\mathbf w)=\ell(\mathbf w^\top\mathbf x_i,y_i), the gradient is ℓ′(w⊤xi,yi) xi\ell'(\mathbf w^\top\mathbf x_i,y_i)\,\mathbf x_i, so SAG and SAGA need to store only one scalar per example: O(n)\order{n} memory.
python
from sklearn.linear_model import LogisticRegression

# L1-regularized logistic regression solved by SAGA (proximal steps handle the L1 term).
clf = LogisticRegression(penalty="l1", solver="saga", C=1.0, max_iter=1000)
clf.fit(X_train, y_train)

Variance-reduced solvers are standard tools for convex empirical risk minimization; scikit-learn offers sag and saga solvers for its linear models.

Check your understanding

What distinguishes SAGA's update from SAG's, for the same table of stored gradients?

  1. SAGA stores fewer gradients
  2. SAGA's estimator is unbiased; SAG's damps the correction by 1/n1/n, which lowers its variance but biases it
  3. SAG converges linearly and SAGA only sublinearly
  4. SAGA needs a full gradient at every step
Show the answer

B. SAGA's estimator is unbiased; SAG's damps the correction by 1/n1/n, which lowers its variance but biases it

SAGA uses ∇fi(x)−∇fi(ϕi)\nabla f_i(\mathbf x)-\nabla f_i(\boldsymbol\phi_i) undamped, so its mean is exactly ∇F(x)\nabla F(\mathbf x). That makes its analysis short and lets it take proximal steps; SAG trades bias for variance.

Optimality, nonconvexity and deep learning

Acceleration and lower bounds. Katyusha (Allen-Zhu, 2018) combines variance reduction with a Nesterov-type momentum and attains the optimal accelerated rate, O((n+nκ)log⁡(1/ε))\order{(n+\sqrt{n\kappa})\log(1/\varepsilon)}. Woodworth & Srebro (2016) proved matching lower bounds for randomized methods that access the components' gradients: for smooth finite sums, an accelerated variant of SVRG is optimal. When n≥κn\ge\kappa, the nn term dominates: about log⁡(1/ε)\log(1/\varepsilon) passes over the data suffice, close to the least one could hope for.

Nonconvex finite sums. Variance reduction also helps without convexity. SPIDER (Fang, Li, Lin & Zhang, 2018) finds an ε\varepsilon-stationary point with O(min⁡(n ε−2,ε−3))\order{\min(\sqrt n\,\varepsilon^{-2},\varepsilon^{-3})} stochastic gradient evaluations, nearly matching the lower bound under averaged smoothness, against ε−4\varepsilon^{-4} for SGD (Convergence of SGD).

Key takeaways

  • On a finite sum, SGD's gradient noise does not vanish at the optimum (σ⋆2>0\sigma_\star^2>0), so constant steps stall and decaying steps are sublinear.
  • SVRG and SAGA are control variates: ∇fi(x)−∇fi(reference)+mean\nabla f_i(\mathbf x)-\nabla f_i(\text{reference})+\text{mean}. They are unbiased, with E∥g∥2≤4L(F(x)−F⋆+F(x~)−F⋆)\E\norm{\mathbf g}^2\le4L(F(\mathbf x)-F^\star+F(\tilde{\mathbf x})-F^\star) for SVRG.
  • SVRG contracts the gap by α=1μη(1−2Lη)m+2Lη1−2Lη\alpha=\frac1{\mu\eta(1-2L\eta)m}+\frac{2L\eta}{1-2L\eta} per outer loop; η=1/(10L)\eta=1/(10L), m=50κm=50\kappa give α=12\alpha=\tfrac12 and O((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)} gradient evaluations, versus O(nκlog⁡(1/ε))\order{n\kappa\log(1/\varepsilon)} for gradient descent.
  • SAGA is unbiased, proximal and adaptive to μ\mu; SAG is biased with lower variance; accelerated variants reach the optimal O((n+nκ)log⁡(1/ε))\order{(n+\sqrt{n\kappa})\log(1/\varepsilon)}.
  • On large deep networks, variance reduction has so far not helped: iterates decorrelate from the snapshot, augmentation breaks the finite-sum structure, and statistical accuracy is reached first.

Check yourself

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

Question 1

On a strongly convex finite sum, why does SVRG with a constant step converge linearly, while constant-step SGD stalls in a noise ball?

  1. SVRG uses a larger step size
  2. SVRG computes the full gradient at every step
  3. The variance of SVRG's estimator is bounded by suboptimality gaps that shrink to zero, whereas SGD's variance at the optimum is σ⋆2>0\sigma_\star^2>0
  4. SVRG is a second-order method
Show the answer

C. The variance of SVRG's estimator is bounded by suboptimality gaps that shrink to zero, whereas SGD's variance at the optimum is σ⋆2>0\sigma_\star^2>0

E∥g∥2≤4L(F(x)−F⋆+F(x~)−F⋆)\E\norm{\mathbf g}^2\le4L(F(\mathbf x)-F^\star+F(\tilde{\mathbf x})-F^\star), which vanishes at the optimum. With no persistent noise, a constant step gives a geometric contraction, as for gradient descent.

Question 2

One outer loop of SVRG with mm inner steps costs how many component-gradient evaluations?

  1. nn
  2. mm
  3. n+2mn+2m
  4. nmnm
Show the answer

C. n+2mn+2m

nn for the snapshot's full gradient, then two per inner step (∇fi(xt)\nabla f_i(\mathbf x_t) and ∇fi(x~)\nabla f_i(\tilde{\mathbf x}), unless the latter are stored). With m=Θ(κ)m=\Theta(\kappa) and a constant contraction per loop, the total is O((n+κ)log⁡(1/ε))\order{(n+\kappa)\log(1/\varepsilon)}.

Question 3

According to Defazio & Bottou (2019), what is the main reason SVRG fails to reduce gradient variance when training large modern networks?

  1. Deep networks are nonconvex, so the variance bound is false
  2. Within an epoch the iterates move far from the snapshot, so the stored and current gradients decorrelate
  3. The full gradient is too expensive to compute even once per epoch
  4. Batch normalization makes the gradients exactly zero
Show the answer

B. Within an epoch the iterates move far from the snapshot, so the stored and current gradients decorrelate

A control variate helps only while ∇fi(x)\nabla f_i(\mathbf x) and ∇fi(x~)\nabla f_i(\tilde{\mathbf x}) are strongly correlated. In large networks trained with practical step sizes they decorrelate quickly, and even more frequent snapshots did not rescue the large models.

Further reading

  • M. Schmidt, N. Le Roux & F. Bach, "Minimizing finite sums with the stochastic average gradient," Mathematical Programming 162(1–2), 83–112 (2017).
  • R. Johnson & T. Zhang, "Accelerating stochastic gradient descent using predictive variance reduction," Advances in Neural Information Processing Systems 26 (2013).
  • A. Defazio, F. Bach & S. Lacoste-Julien, "SAGA: a fast incremental gradient method with support for non-strongly convex composite objectives," Advances in Neural Information Processing Systems 27 (2014).
  • A. Defazio & L. Bottou, "On the ineffectiveness of variance reduced optimization for deep learning," Advances in Neural Information Processing Systems 32 (2019).
  • R. M. Gower, M. Schmidt, F. Bach & P. Richtárik, "Variance-reduced methods for machine learning," Proceedings of the IEEE 108(11), 1968–1983 (2020).