Suppose we want to minimize some loss L(θ):RdR\mathcal{L}(\boldsymbol{\theta}): \mathbb{R}^d \to \mathbb{R} via gradient descent. At each step, we receive the true gradient L(θt)\nabla \mathcal{L}(\boldsymbol{\theta}_t) plus some randomly sampled noise εt\boldsymbol{\varepsilon}_t. We run this noisy gradient descent with a constant learning rate.

What happens? Do we converge to the true minimum of L\mathcal{L}? Or do we hover within some range of it?

Turns out we hover within some range (a sort of “cloud”) around the minimum. The size of this cloud depends on the step size, the magnitude of the noise, and the local curvature of the loss.

The 1D quadratic case

Consider a simple 1D quadratic loss function

L(θ)=λ2θ2,\mathcal{L}(\theta)=\frac{\lambda}{2}\theta^2,

where θR\theta \in \mathbb{R} is the parameter to be learned, and λR+\lambda \in \mathbb{R}^{+} is a constant that controls the curvature of the quadratic. The minimum is at θ=0\theta=0, and the true gradient is L(θ)=λθ\nabla\mathcal{L}(\theta)=\lambda\theta.

Now suppose noisy gradient descent sees

gt=λθt+εt,g_t=\lambda\theta_t+\varepsilon_t,

where each noise term εt\varepsilon_t is an independently drawn random variable with E[εt]=0\mathbb{E}[\varepsilon_t]=0 and Var(εt)=σ2\text{Var}(\varepsilon_t)=\sigma^2.

We can write one step of noisy gradient descent as

θt+1=θtηgt=θtη(λθt+εt)=(1ηλ)θtηεt.\begin{aligned} \theta_{t+1} &= \theta_t-\eta g_t \\ &= \theta_t-\eta(\lambda\theta_t+\varepsilon_t) \\ &= (1-\eta\lambda)\theta_t-\eta\varepsilon_t. \end{aligned}

Letting a:=1ηλa:=1-\eta\lambda, we can write

θt+1=aθtηεt.\theta_{t+1}=a\theta_t-\eta\varepsilon_t.

Note that we’ll assume a<1\lvert a \rvert < 1 (or equivalently 0<ηλ<20 < \eta\lambda < 2). If this were not the case, then learning would be unstable, with the iterate blowing up to infinity.1

Analysis of parameter iterates

The expectation of an iterate

Note that we can think of each iterate θt\theta_t as a random variable – each θt\theta_t depends on all the random noise terms sampled up to that point: ε0,ε1,,εt1\varepsilon_0,\varepsilon_1,\ldots,\varepsilon_{t-1}.

Let mt:=E[θt].m_t:=\mathbb{E}[\theta_t]. We write the expectation of the next iterate as a simple recursion:

mt+1=E[aθtηεt]=aE[θt]ηE[εt]=amt.\begin{aligned} m_{t+1} &= \mathbb{E}[a\theta_t-\eta\varepsilon_t] \\ &= a\mathbb{E}[\theta_t]-\eta\mathbb{E}[\varepsilon_t] \\ &= am_t. \end{aligned}

Thus, the expectation of iterates evolves as

m1=am0,m2=am1=a2m0,mt=atm0.m_1=am_0,\qquad m_2=am_1=a^2m_0,\qquad m_t=a^tm_0.

If a<1\lvert a \rvert < 1, then at0a^t \to 0, so E[θt]0.\mathbb{E}[\theta_t]\to 0.

From this, we see that the expectation of iterates goes to the minimum. However, we will see that actual iterates do not stay there – they have non-zero variance, driven by the fact that new noise is injected at every step.

The variance of an iterate

Let vt:=Var(θt).v_t:=\text{Var}(\theta_t). Then

vt+1=Var(aθtηεt)=a2Var(θt)+η2Var(εt)=a2vt+η2σ2.\begin{aligned} v_{t+1} &= \text{Var}(a\theta_t-\eta\varepsilon_t) \\ &= a^2\text{Var}(\theta_t)+\eta^2\text{Var}(\varepsilon_t) \\ &= a^2v_t+\eta^2\sigma^2. \end{aligned}

Note that there is no cross term because the noise εt\varepsilon_t is independent of the iterate θt\theta_t.

At stationarity (i.e., when we’re in the final “cloud”), the variance stops changing, so vt+1=vt=vv_{t+1}=v_t=v. Therefore

v=a2v+η2σ2v(1a2)=η2σ2v=η2σ21a2.\begin{aligned} v &= a^2v+\eta^2\sigma^2 \\ v(1-a^2) &= \eta^2\sigma^2 \\ v &= \frac{\eta^2\sigma^2}{1-a^2}. \end{aligned}

Now substitute a=1ηλa=1-\eta\lambda:

1a2=1(1ηλ)2=ηλ(2ηλ).\begin{aligned} 1-a^2 &= 1-(1-\eta\lambda)^2 \\ &= \eta\lambda(2-\eta\lambda). \end{aligned}

So the stationary parameter variance is

Var(θ)=ησ2λ(2ηλ).\text{Var}(\theta) = \frac{\eta\sigma^2}{\lambda(2-\eta\lambda)}.

This is the noise floor in the toy model. Smaller learning rates and lower gradient noise shrink the cloud, while smaller curvature expands it.

Analysis of loss

So far, we have described the cloud in parameter space.

At stationarity, θ\theta is a random variable with

E[θ]=0,Var(θ)=ησ2λ(2ηλ).\mathbb{E}[\theta]=0, \qquad \text{Var}(\theta) = \frac{\eta\sigma^2}{\lambda(2-\eta\lambda)}.

We can compute statistics of the loss, since the loss is just a function of parameters θ\theta.

The expected loss is

E[L(θ)]=E[λ2θ2]=λ2E[θ2].\begin{aligned} \mathbb{E}[\mathcal{L}(\theta)] &= \mathbb{E}\left[\frac{\lambda}{2}\theta^2\right]\\ &= \frac{\lambda}{2} \mathbb{E}\left[\theta^2\right]. \end{aligned}

Since E[θ]=0\mathbb{E}[\theta] = 0, E[θ2]=Var(θ)\mathbb{E}[\theta^2] = \text{Var}(\theta). Therefore,

E[L(θ)]=λ2Var(θ)=λ2ησ2λ(2ηλ)=ησ22(2ηλ).\begin{aligned} \mathbb{E}[\mathcal{L}(\theta)] &= \frac{\lambda}{2}\text{Var}(\theta) \\ &= \frac{\lambda}{2} \cdot \frac{\eta\sigma^2}{\lambda(2-\eta\lambda)} \\ &= \frac{\eta\sigma^2}{2(2-\eta\lambda)}. \end{aligned}

Extending to general cases

We spent a bunch of time trying to understand a simple 1D quadratic. Why care about a 1D quadratic?

Near a nice local minimum, a smooth loss looks quadratic. The 1D quadratic is the simplest local model of what noisy gradient descent sees when it is close to a minimum.

In 1D, if the minimum is at θ\theta^\star, then for nearby θ\theta,

L(θ)L(θ)+12L(θ)(θθ)2.\mathcal{L}(\theta) \approx \mathcal{L}(\theta^\star) + \frac{1}{2}\mathcal{L}''(\theta^\star)(\theta-\theta^\star)^2.

So the same calculation applies locally, with curvature λ=L(θ).\lambda=\mathcal{L}''(\theta^\star).

In multiple dimensions, the same idea applies direction by direction. Near a minimum, the loss is approximately a quadratic bowl. The Hessian tells us the curvature in each local direction. Flatter directions have weaker force pulling the iterates back toward the minimum, so the noisy iterates spread out more along those directions; sharper directions have stronger force pulling the iterates back toward the minimum, so the cloud is narrower along those directions.

References

References are listed in alphabetical order.

  1. Gradient descent on neural networks typically occurs at the edge of stability [link]
    Jeremy Cohen, Simran Kaur, Yuanzhi Li, J Zico Kolter, and Ameet Talwalkar. International Conference on Learning Representations. 2021.
  2. Noise and fluctuation of finite learning rate stochastic gradient descent [link]
    Kangqiao Liu, Liu Ziyin, and Masahito Ueda. Proceedings of the 38th International Conference on Machine Learning. 2021.
  3. Acceleration of stochastic approximation by averaging [link]
    B. T. Polyak and A. B. Juditsky. SIAM Journal on Control and Optimization. 1992.

Footnotes

  1. This is the same basic stability threshold behind the “edge-of-stability” phenomenon: for a quadratic with curvature λ\lambda, gradient descent becomes unstable once the learning rate reaches η2/λ\eta \geq 2/\lambda