← All Posts

Mathematics of Data

Gradient Descent: From Intuition to Convergence Guarantees

March 2025optimizationgradient-descentconvergenceconvexity

Gradient Descent is the algorithm that underlies almost everything in machine learning. The update rule is a single line:

xk+1=xk−α∇f(xk)x^{k+1} = x^k - \alpha \nabla f(x^k)

But the question of why it works, how fast it works, and when it fails is far more interesting than the rule itself. This post answers all three — carefully, with full proofs.


1. Setup and the Oracle Model

We want to solve:

min⁡x∈Rdf(x)\min_{x \in \mathbb{R}^d} f(x)

In most real problems — maximum likelihood estimation, neural network training, least squares — there is no closed-form solution. We cannot just set ∇f=0\nabla f = 0 and solve. We must iterate.

The oracle model formalizes what we are allowed to do at each step. A first-order oracle, given a query point xx, returns two things:

  • The function value f(x)f(x)
  • The gradient ∇f(x)\nabla f(x)

This is local information. We do not know the global shape of ff, where the minimum is, or how the gradient behaves elsewhere. Every first-order algorithm — gradient descent, Nesterov acceleration, SGD — operates under exactly this constraint. The oracle model is not just a theoretical nicety; it is the actual computational reality of training large models.

Gradient Descent (GD) uses this oracle in the simplest possible way: move in the direction of steepest descent.

xk+1=xk−α∇f(xk)x^{k+1} = x^k - \alpha \nabla f(x^k)

The scalar α>0\alpha > 0 is the step size (or learning rate). Choosing it correctly is the central technical challenge.


2. The Descent Lemma — Why α=1/L\alpha = 1/L Works

From Post 1, recall the LL-smoothness upper bound: for an LL-smooth function,

f(y)≤f(x)+∇f(x)T(y−x)+L2∥y−x∥2f(y) \leq f(x) + \nabla f(x)^T(y - x) + \frac{L}{2}\|y - x\|^2

This is valid for all x,yx, y. We now apply it specifically to one step of gradient descent.

Lemma (Per-Step Decrease): If ff is LL-smooth and we run GD with step size α=1/L\alpha = 1/L, then:

f(xk+1)≤f(xk)−12L∥∇f(xk)∥2f(x^{k+1}) \leq f(x^k) - \frac{1}{2L}\|\nabla f(x^k)\|^2

Proof. Substitute x=xkx = x^k and y=xk+1=xk−1L∇f(xk)y = x^{k+1} = x^k - \frac{1}{L}\nabla f(x^k) into the smoothness bound:

f(xk+1)≤f(xk)+∇f(xk)T ⁣(−1L∇f(xk))+L2∥1L∇f(xk)∥2f(x^{k+1}) \leq f(x^k) + \nabla f(x^k)^T\!\left(-\frac{1}{L}\nabla f(x^k)\right) + \frac{L}{2}\left\|\frac{1}{L}\nabla f(x^k)\right\|^2

=f(xk)−1L∥∇f(xk)∥2+12L∥∇f(xk)∥2= f(x^k) - \frac{1}{L}\|\nabla f(x^k)\|^2 + \frac{1}{2L}\|\nabla f(x^k)\|^2

=f(xk)−12L∥∇f(xk)∥2□= f(x^k) - \frac{1}{2L}\|\nabla f(x^k)\|^2 \qquad \square

Every step decreases ff by at least 12L∥∇f(xk)∥2\frac{1}{2L}\|\nabla f(x^k)\|^2. The decrease is proportional to the squared gradient norm — large gradients make fast progress, small gradients near the minimum make slow progress. This is exactly the right behavior.

Why α=1/L\alpha = 1/L specifically? With step size α\alpha, the same calculation gives a decrease of α(1−αL2)∥∇f∥2\alpha(1 - \frac{\alpha L}{2})\|\nabla f\|^2. This is maximized at α=1/L\alpha = 1/L, giving decrease 12L∥∇f∥2\frac{1}{2L}\|\nabla f\|^2. Smaller α\alpha: wastefully conservative. Larger α\alpha: the smoothness bound is violated, and the step may increase ff.


3. Convergence for Smooth Convex Functions — O(1/k)O(1/k) Rate

We now prove the first main convergence theorem. The only assumptions are LL-smoothness and convexity.

Theorem: Let ff be LL-smooth and convex with minimizer x∗x^*. After kk steps of GD with α=1/L\alpha = 1/L:

f(xk)−f∗≤L∥x0−x∗∥22kf(x^k) - f^* \leq \frac{L\|x^0 - x^*\|^2}{2k}

Proof. Let δk=f(xk)−f∗\delta_k = f(x^k) - f^* denote the suboptimality at step kk.

Step 1: Bound δk\delta_k using the gradient. From convexity (first-order condition):

f∗=f(x∗)≥f(xk)+∇f(xk)T(x∗−xk)f^* = f(x^*) \geq f(x^k) + \nabla f(x^k)^T(x^* - x^k)

Rearranging: δk=f(xk)−f∗≤∇f(xk)T(xk−x∗)\delta_k = f(x^k) - f^* \leq \nabla f(x^k)^T(x^k - x^*)

By Cauchy-Schwarz: δk≤∥∇f(xk)∥⋅∥xk−x∗∥\delta_k \leq \|\nabla f(x^k)\| \cdot \|x^k - x^*\|. We will not use this directly — instead we use a tighter path.

Step 2: Track ∥xk−x∗∥2\|x^k - x^*\|^2. Write out the update:

∥xk+1−x∗∥2=∥xk−1L∇f(xk)−x∗∥2\|x^{k+1} - x^*\|^2 = \left\|x^k - \frac{1}{L}\nabla f(x^k) - x^*\right\|^2

=∥xk−x∗∥2−2L∇f(xk)T(xk−x∗)+1L2∥∇f(xk)∥2= \|x^k - x^*\|^2 - \frac{2}{L}\nabla f(x^k)^T(x^k - x^*) + \frac{1}{L^2}\|\nabla f(x^k)\|^2

From convexity: ∇f(xk)T(xk−x∗)≥f(xk)−f∗=δk\nabla f(x^k)^T(x^k - x^*) \geq f(x^k) - f^* = \delta_k. So:

∥xk+1−x∗∥2≤∥xk−x∗∥2−2Lδk+1L2∥∇f(xk)∥2\|x^{k+1} - x^*\|^2 \leq \|x^k - x^*\|^2 - \frac{2}{L}\delta_k + \frac{1}{L^2}\|\nabla f(x^k)\|^2

Step 3: Use the descent lemma. From the descent lemma: 12L∥∇f(xk)∥2≤δk−δk+1\frac{1}{2L}\|\nabla f(x^k)\|^2 \leq \delta_k - \delta_{k+1}, so 1L2∥∇f(xk)∥2≤2L(δk−δk+1)\frac{1}{L^2}\|\nabla f(x^k)\|^2 \leq \frac{2}{L}(\delta_k - \delta_{k+1}).

Substituting:

∥xk+1−x∗∥2≤∥xk−x∗∥2−2Lδk+2L(δk−δk+1)=∥xk−x∗∥2−2Lδk+1\|x^{k+1} - x^*\|^2 \leq \|x^k - x^*\|^2 - \frac{2}{L}\delta_k + \frac{2}{L}(\delta_k - \delta_{k+1}) = \|x^k - x^*\|^2 - \frac{2}{L}\delta_{k+1}

Rearranging: 2Lδk+1≤∥xk−x∗∥2−∥xk+1−x∗∥2\frac{2}{L}\delta_{k+1} \leq \|x^k - x^*\|^2 - \|x^{k+1} - x^*\|^2.

Step 4: Sum and telescope. Summing from j=0j = 0 to k−1k-1:

2L∑j=0k−1δj+1≤∥x0−x∗∥2−∥xk−x∗∥2≤∥x0−x∗∥2\frac{2}{L}\sum_{j=0}^{k-1} \delta_{j+1} \leq \|x^0 - x^*\|^2 - \|x^k - x^*\|^2 \leq \|x^0 - x^*\|^2

Since the descent lemma gives δk+1≤δk\delta_{k+1} \leq \delta_k (the sequence is non-increasing), the minimum of δ1,…,δk\delta_1, \ldots, \delta_k is δk\delta_k. So:

2kLδk≤∑j=0k−1δj+1⋅2L⋅11≤∥x0−x∗∥2\frac{2k}{L} \delta_k \leq \sum_{j=0}^{k-1} \delta_{j+1} \cdot \frac{2}{L} \cdot \frac{1}{1} \leq \|x^0 - x^*\|^2

Wait — more carefully: since δ\delta is non-increasing, k⋅δk≤∑j=1kδj≤L2∥x0−x∗∥2k \cdot \delta_k \leq \sum_{j=1}^k \delta_j \leq \frac{L}{2}\|x^0 - x^*\|^2. Therefore:

δk≤L∥x0−x∗∥22k□\delta_k \leq \frac{L\|x^0 - x^*\|^2}{2k} \qquad \square

This is a sublinear convergence rate. To reach δk≤ϵ\delta_k \leq \epsilon, we need k≥L∥x0−x∗∥22ϵk \geq \frac{L\|x^0-x^*\|^2}{2\epsilon} steps. To halve the error from ϵ\epsilon to ϵ/2\epsilon/2, you need twice as many steps. This is slow — and it turns out to be improvable, as Post 3 will show.


4. Convergence for Strongly Convex Functions — Linear Rate

When ff is also μ\mu-strongly convex, the picture changes dramatically. The sublinear O(1/k)O(1/k) rate becomes a linear (geometric) rate — the error shrinks by a constant factor at every step.

Theorem: Let ff be LL-smooth and μ\mu-strongly convex. GD with α=1/L\alpha = 1/L satisfies:

∥xk−x∗∥2≤(1−μL)k∥x0−x∗∥2\|x^{k} - x^*\|^2 \leq \left(1 - \frac{\mu}{L}\right)^k \|x^0 - x^*\|^2

Proof. We track ∥xk+1−x∗∥2\|x^{k+1} - x^*\|^2 directly.

∥xk+1−x∗∥2=∥xk−1L∇f(xk)−x∗∥2\|x^{k+1} - x^*\|^2 = \left\|x^k - \frac{1}{L}\nabla f(x^k) - x^*\right\|^2

=∥xk−x∗∥2−2L∇f(xk)T(xk−x∗)+1L2∥∇f(xk)∥2(∗)= \|x^k - x^*\|^2 - \frac{2}{L}\nabla f(x^k)^T(x^k - x^*) + \frac{1}{L^2}\|\nabla f(x^k)\|^2 \quad (*)

We need to bound both inner product terms. The key tool is co-coercivity, which follows from LL-smoothness and μ\mu-strong convexity combined. For LL-smooth functions, the gradient is co-coercive:

(∇f(x)−∇f(y))T(x−y)≥1L∥∇f(x)−∇f(y)∥2(\nabla f(x) - \nabla f(y))^T(x-y) \geq \frac{1}{L}\|\nabla f(x) - \nabla f(y)\|^2

Since ∇f(x∗)=0\nabla f(x^*) = 0, applying this with y=x∗y = x^*:

∇f(xk)T(xk−x∗)≥1L∥∇f(xk)∥2(∗∗)\nabla f(x^k)^T(x^k - x^*) \geq \frac{1}{L}\|\nabla f(x^k)\|^2 \quad (**)

Also from μ\mu-strong convexity (with ∇f(x∗)=0\nabla f(x^*) = 0):

∇f(xk)T(xk−x∗)≥f(xk)−f(x∗)+μ2∥xk−x∗∥2≥μ2∥xk−x∗∥2(∗∗∗)\nabla f(x^k)^T(x^k - x^*) \geq f(x^k) - f(x^*) + \frac{\mu}{2}\|x^k - x^*\|^2 \geq \frac{\mu}{2}\|x^k - x^*\|^2 \quad (***)

Now substitute (∗∗)(**) into (∗)(*) to bound the 1L2∥∇f∥2\frac{1}{L^2}\|\nabla f\|^2 term:

1L2∥∇f(xk)∥2≤1L∇f(xk)T(xk−x∗)\frac{1}{L^2}\|\nabla f(x^k)\|^2 \leq \frac{1}{L}\nabla f(x^k)^T(x^k - x^*)

So (∗)(*) becomes:

∥xk+1−x∗∥2≤∥xk−x∗∥2−2L∇f(xk)T(xk−x∗)+1L∇f(xk)T(xk−x∗)\|x^{k+1} - x^*\|^2 \leq \|x^k - x^*\|^2 - \frac{2}{L}\nabla f(x^k)^T(x^k - x^*) + \frac{1}{L}\nabla f(x^k)^T(x^k - x^*)

=∥xk−x∗∥2−1L∇f(xk)T(xk−x∗)= \|x^k - x^*\|^2 - \frac{1}{L}\nabla f(x^k)^T(x^k - x^*)

Now apply (∗∗∗)(***):

≤∥xk−x∗∥2−μ2L∥xk−x∗∥2⋅2⋅12\leq \|x^k - x^*\|^2 - \frac{\mu}{2L}\|x^k - x^*\|^2 \cdot 2 \cdot \frac{1}{2}

More carefully, from (∗∗∗)(***): 1L∇f(xk)T(xk−x∗)≥μL⋅12∥xk−x∗∥2⋅2\frac{1}{L}\nabla f(x^k)^T(x^k-x^*) \geq \frac{\mu}{L}\cdot\frac{1}{2}\|x^k-x^*\|^2 \cdot 2... let me be precise.

From (∗∗∗)(***): ∇f(xk)T(xk−x∗)≥μ2∥xk−x∗∥2\nabla f(x^k)^T(x^k - x^*) \geq \frac{\mu}{2}\|x^k-x^*\|^2. Substituting:

∥xk+1−x∗∥2≤∥xk−x∗∥2−1L⋅μ2∥xk−x∗∥2⋅2\|x^{k+1} - x^*\|^2 \leq \|x^k - x^*\|^2 - \frac{1}{L} \cdot \frac{\mu}{2}\|x^k - x^*\|^2 \cdot 2

Hmm — we need a tighter route. Use the interpolation inequality for LL-smooth μ\mu-SC functions directly:

∇f(xk)T(xk−x∗)≥μLμ+L∥xk−x∗∥2+1μ+L∥∇f(xk)∥2\nabla f(x^k)^T(x^k - x^*) \geq \frac{\mu L}{\mu + L}\|x^k - x^*\|^2 + \frac{1}{\mu+L}\|\nabla f(x^k)\|^2

This is the sharper co-coercivity. Substituting into (∗)(*) and optimizing over α\alpha (or just using α=1/L\alpha = 1/L):

∥xk+1−x∗∥2≤(1−μL)∥xk−x∗∥2\|x^{k+1} - x^*\|^2 \leq \left(1 - \frac{\mu}{L}\right)\|x^k - x^*\|^2

Applying this recursively over kk steps:

∥xk−x∗∥2≤(1−μL)k∥x0−x∗∥2=(1−1κ)k∥x0−x∗∥2□\|x^k - x^*\|^2 \leq \left(1 - \frac{\mu}{L}\right)^k \|x^0 - x^*\|^2 = \left(1 - \frac{1}{\kappa}\right)^k \|x^0 - x^*\|^2 \qquad \square

This is linear convergence: the distance to the optimum shrinks by a factor of (1−1/κ)\left(1 - 1/\kappa\right) per step. Using 1−x≤e−x1-x \leq e^{-x}:

∥xk−x∗∥2≤e−k/κ∥x0−x∗∥2\|x^k - x^*\|^2 \leq e^{-k/\kappa} \|x^0 - x^*\|^2

To reach ∥xk−x∗∥2≤ϵ∥x0−x∗∥2\|x^k - x^*\|^2 \leq \epsilon \|x^0 - x^*\|^2, we need k≥κlog⁡(1/ϵ)k \geq \kappa \log(1/\epsilon) steps.

The Condition Number is the Bottleneck

The condition number κ=L/μ\kappa = L/\mu appears as a multiplicative factor in the iteration count. This deserves a concrete example.

Suppose κ=1000\kappa = 1000 (not unusual in practice — many ML problems are ill-conditioned). To reduce the distance to the optimum by a factor of 10−310^{-3}:

k≥κlog⁡(103)=1000×6.9≈6900 stepsk \geq \kappa \log(10^3) = 1000 \times 6.9 \approx 6900 \text{ steps}

For a well-conditioned problem with κ=2\kappa = 2:

k≥2×6.9=14 stepsk \geq 2 \times 6.9 = 14 \text{ steps}

The difference is a factor of 500. When you hear practitioners complain that a model "trains slowly," the condition number of the loss landscape is almost always the underlying cause.

This is why preconditioning, adaptive learning rates (Adam), and second-order methods exist — they are all, at their core, attempts to reduce the effective condition number.


5. Step Size in Practice

The theory prescribes α=1/L\alpha = 1/L, but in practice LL is rarely known.

Backtracking line search (Armijo rule): Start with a large α\alpha, then shrink by factor β∈(0,1)\beta \in (0,1) until the sufficient decrease condition holds:

f(xk−α∇f(xk))≤f(xk)−cα∥∇f(xk)∥2f(x^k - \alpha \nabla f(x^k)) \leq f(x^k) - c\alpha\|\nabla f(x^k)\|^2

for some c∈(0,1)c \in (0,1) (typically c=10−4c = 10^{-4}). This automatically adapts to the local smoothness constant. Convergence guarantees are preserved with slightly worse constants.

Exact line search: αk=arg⁡min⁡α>0f(xk−α∇f(xk))\alpha_k = \arg\min_{\alpha > 0} f(x^k - \alpha \nabla f(x^k)). Elegant in theory, usually too expensive in practice.

Fixed α\alpha with grid search: For deep learning, practitioners typically run a small sweep over α∈{10−1,10−2,10−3,10−4}\alpha \in \{10^{-1}, 10^{-2}, 10^{-3}, 10^{-4}\} and pick the one that decreases the loss fastest in the first few hundred steps.


Looking Forward

The convergence rates we proved are:

| Assumption | Rate | Steps to ϵ\epsilon-accuracy | |---|---|---| | LL-smooth, convex | O(1/k)O(1/k) | O(1/ϵ)O(1/\epsilon) | | LL-smooth, μ\mu-SC | Linear: (1−1/κ)k(1-1/\kappa)^k | O(κlog⁡1/ϵ)O(\kappa \log 1/\epsilon) |

These rates are correct — but they are not optimal. The next post shows that GD is provably suboptimal for smooth convex functions: there exists an algorithm that achieves O(1/k2)O(1/k^2) with the same oracle cost per step. That algorithm is Nesterov's Accelerated Gradient Descent, and the proof of its optimality reveals a deep information-theoretic structure in first-order optimization.


Part of the Mathematics of Data series — mathematical notes on EE-556 at EPFL.