TExcelTAD
Home › Optimization › Step Sizes and Convergence of SGD

Step Sizes and Convergence of SGD

Gradient noise forces a trade-off: large steps make fast early progress but leave a large noise ball; small steps are accurate but slow. Step-size schedules get both: start large, then decay. This lesson gives the theory behind the schedules and the averaging trick that makes SGD provably optimal on convex problems.

The two regimes

For a μ\mu-strongly convex, LL-smooth ff with gradient variance bounded by σ2\sigma^2, SGD with a constant step t≤1/Lt \le 1/L satisfies roughly

E∥wk−w∗∥2≤(1−tμ)k∥w0−w∗∥2+tσ2μ\mathbb{E}\lVert \mathbf{w}_k - \mathbf{w}^* \rVert^2 \le (1 - t\mu)^k\lVert \mathbf{w}_0 - \mathbf{w}^* \rVert^2 + \frac{t\sigma^2}{\mu}

The first term decays geometrically (like gradient descent); the second is the noise floor, proportional to tt. Halving the step halves the floor but doubles the time to reach it.

Classical decreasing steps

To converge exactly, the steps must shrink, but not too fast. The Robbins-Monro conditions are

∑ktk=∞,∑ktk2<∞\sum_k t_k = \infty, \qquad \sum_k t_k^2 < \infty

The first lets the iterates travel any distance; the second kills the noise. tk=ckt_k = \frac{c}{k} satisfies both; for strongly convex ff with cc large enough it gives E∥wk−w∗∥2=O(1/k)\mathbb{E}\lVert \mathbf{w}_k - \mathbf{w}^* \rVert^2 = O(1/k), the best possible rate for stochastic first-order methods. For general convex ff, tk=ckt_k = \frac{c}{\sqrt{k}} with averaging gives O(1/k)O(1/\sqrt{k}) in the objective.

python · try it yourself
import numpy as np

rng = np.random.default_rng(0)
n = 5000
X = rng.normal(size=(n, 5)); w_true = rng.normal(size=5); y = X @ w_true + rng.normal(size=n)
w_star = np.linalg.lstsq(X, y, rcond=None)[0]
def run(schedule, iters=50000):
    w = np.zeros(5)
    for k in range(1, iters + 1):
        i = rng.integers(n)
        w -= schedule(k) * X[i] * (X[i] @ w - y[i])
    return np.linalg.norm(w - w_star)
schedules = {"constant 0.05": lambda k: 0.05, "constant 0.005": lambda k: 0.005,
             "1/k (c = 1)": lambda k: 1.0 / (k + 20), "step decay": lambda k: 0.05 * 0.1 ** (k // 15000)}
for name, s in schedules.items():
    print(f"{name:15s}: distance to w* after 50,000 steps {run(s):.4f}")
constant 0.05  : distance to w* after 50,000 steps 0.3242
constant 0.005 : distance to w* after 50,000 steps 0.0471
1/k (c = 1)    : distance to w* after 50,000 steps 0.0076
step decay     : distance to w* after 50,000 steps 0.0218

Iterate averaging

Polyak-Ruppert averaging returns the average wˉk=1k∑j≤kwj\bar{\mathbf{w}}_k = \frac{1}{k}\sum_{j \le k}\mathbf{w}_j instead of the last iterate. With a larger, slowly decaying step (tk∝k−1/2t_k \propto k^{-1/2} or even constant on least squares), the average achieves the optimal O(1/k)O(1/k) rate and is robust to the choice of constant. The noise in individual iterates averages out.

python · try it yourself
import numpy as np

rng = np.random.default_rng(1)
n = 5000
X = rng.normal(size=(n, 5)); w_true = rng.normal(size=5); y = X @ w_true + rng.normal(size=n)
w_star = np.linalg.lstsq(X, y, rcond=None)[0]
w = np.zeros(5); w_avg = np.zeros(5)
for k in range(1, 50001):
    i = rng.integers(n)
    w -= 0.02 * X[i] * (X[i] @ w - y[i])
    if k > 5000:                                   # average after a burn-in
        w_avg += (w - w_avg) / (k - 5000)
print("last iterate distance:    ", round(float(np.linalg.norm(w - w_star)), 4))
print("averaged iterate distance:", round(float(np.linalg.norm(w_avg - w_star)), 4))
last iterate distance:     0.2375
averaged iterate distance: 0.0046

Schedules used in practice

Schedule Formula Used in
step decay multiply by 0.1 every few epochs classic ImageNet training
1/k1/k or 1/k1/\sqrt{k} t0/(1+k/k0)t_0/(1 + k/k_0) scikit-learn SGDClassifier(learning_rate="optimal")
cosine tmin⁡+12(t0−tmin⁡)(1+cos⁡(πk/K))t_{\min} + \frac{1}{2}(t_0 - t_{\min})(1 + \cos(\pi k/K)) modern deep learning
warm-up then decay linear increase for a few thousand steps transformers

Warm-up and cosine schedules are discussed in Learning-Rate Schedules and Clipping.

In software

  • torch.optim.lr_scheduler (StepLR, CosineAnnealingLR, OneCycleLR), optax schedules in JAX; torch.optim.swa_utils.AveragedModel implements iterate (weight) averaging, also known as SWA or EMA of weights.
  • scikit-learn's SGDRegressor(average=True) turns on Polyak-Ruppert averaging.

Exercises

Exercise 1: Robbins-Monro

Which schedules satisfy both Robbins-Monro conditions? (a) tk=0.1t_k = 0.1; (b) tk=1/kt_k = 1/k; (c) tk=1/k2t_k = 1/k^2; (d) tk=1/kt_k = 1/\sqrt{k}.

Answer

Only (b).

Solution

(a) has ∑tk2=∞\sum t_k^2 = \infty. (c) has ∑tk<∞\sum t_k < \infty: the iterates can only travel a bounded distance. (d) has ∑tk2=∑1/k=∞\sum t_k^2 = \sum 1/k = \infty (it still works with averaging, but not for the last iterate in the classical theorem).

Exercise 2: Noise floor

With a constant step, the noise floor is proportional to tt. If t=0.01t = 0.01 gives an error floor of 0.04, estimate the floor for t=0.0025t = 0.0025.

Answer

About 0.01.

Solution

The floor term tσ2/μt\sigma^2/\mu is linear in tt; dividing tt by 4 divides the floor by 4.

Exercise 3: Cosine schedule (code)

Print the cosine schedule with t0=0.1t_0 = 0.1, tmin⁡=0t_{\min} = 0, K=100K = 100 at k=0,25,50,75,100k = 0, 25, 50, 75, 100.

Answer

0.1, about 0.0854, 0.05, about 0.0146, 0.

Solution
python · try it yourself
import numpy as np
print([round(float(0.5 * 0.1 * (1 + np.cos(np.pi * k / 100))), 4) for k in (0, 25, 50, 75, 100)])
[0.1, 0.0854, 0.05, 0.0146, 0.0]

Test yourself

The Robbins-Monro conditions on step sizes are…

  1. ∑tk=∞\sum t_k = \infty and ∑tk2<∞\sum t_k^2 < \infty
  2. ∑tk<∞\sum t_k < \infty
  3. tkt_k constant
  4. tk=1t_k = 1

Polyak-Ruppert averaging returns…

  1. the last iterate
  2. the average of the iterates
  3. the best iterate
  4. the median gradient

With a constant step, halving tt in SGD…

  1. halves the noise floor but slows the initial convergence
  2. doubles the noise floor
  3. has no effect
  4. guarantees exact convergence