← Explainer Library

Interactive Explainer

Beyond Gradient Descent

SGD and Adam aren't the only optimisers. Race five non-SGD methods on the same 2D loss surface and watch where each leaps and stalls.

Prelude

Why bother going beyond SGD?

SGD with momentum is the workhorse of deep learning because (a) it scales — one gradient evaluation per step is cheap, (b) noise is a feature, not a bug, on a single-pass training run, and (c) the implicit regularisation of small batches gives free generalisation. Adam and its cousins (AdamW, Lion, Sophia) inherit those advantages and add adaptive per-parameter learning rates.

But: SGD throws away two things.

When are these worth paying for? When (i) you can afford full-batch or large-batch gradients, (ii) the dimensionality is small enough to store/invert curvature, or (iii) you have no gradient at all and must fall back to function-value methods like CMA-ES and SPSA.

Step 1

The five contenders

Step 1½

Newton's method, in two lines

Taylor-expand the loss around the current iterate $w_t$:

Minimise this quadratic in $\Delta w$ by setting its gradient to zero. Solving gives $\Delta w = -H^{-1}\nabla f$, which is the Newton step. On a perfect quadratic, one step reaches the optimum; on a smooth function, the rate is quadratic — the error squares each iteration. In practice you must damp: $w_{t+1} = w_t - \alpha_t H^{-1}\nabla f$ with $\alpha_t$ from a line search, and stabilise the Hessian with $H + \lambda I$ when it's not positive-definite (Levenberg–Marquardt).

Step 1¾

BFGS — the rank-2 secret to L-BFGS

BFGS maintains a Hessian-inverse approximation $B$ that gets better every step. After observing the step $s_t = w_{t+1} - w_t$ and gradient change $y_t = \nabla f_{t+1} - \nabla f_t$, it updates $B$ by a rank-2 perturbation:

Two properties make this magical:

L-BFGS stores only the last $m$ pairs $(s_t, y_t)$ (typically $m=10$) instead of the full matrix, applying $B \nabla f$ via a two-loop recursion in $O(md)$ time. That's why it scales to millions of parameters when full Newton can't.

Step 1⅞

Natural gradient — geometry of probability

For a probabilistic model $p_\theta(x)$, the natural gradient preconditions the ordinary gradient with the inverse Fisher information matrix:

The Fisher $F$ is the Hessian of the KL divergence to the current model. Stepping along $-F^{-1}\nabla L$ keeps the KL change between consecutive iterates bounded — the step becomes geometry-aware in the manifold of distributions. Concrete consequences:

Step 2

Race them on a 2-D loss

step 0
Loss surface contour + each optimiser's trajectory. Final loss values shown in the legend.
Step 2½

Gradient-free: CMA-ES and SPSA

Suppose you can compute $f(w)$ but not $\nabla f(w)$. This is the regime for RL hyperparameter search, simulator-based design, hardware-in-the-loop tuning, and certain quantum experiments. Two algorithms dominate.

CMA-ES (Covariance Matrix Adaptation Evolution Strategy). Maintain a Gaussian search distribution $\mathcal{N}(m_t, \sigma_t^2 C_t)$. At each generation:

The adaptive covariance is what makes CMA-ES competitive — it learns the local conditioning from successes and failures without computing a Hessian.

SPSA (Simultaneous Perturbation Stochastic Approximation). Pick a random $\pm 1$ vector $\Delta_t$ (Rademacher); evaluate $f$ at $w_t \pm c_t \Delta_t$; estimate the gradient with a single 2-point finite difference:

Two function evaluations per step, regardless of dimension. That's the magic: where ordinary finite differences cost $2d$ evaluations, SPSA pays a fixed 2. The trade-off is variance: you need many steps and shrinking $a_t, c_t$ to converge, but the per-step cost is dimension-independent.

Step 3

When to use what

Final takeaway. The right optimiser depends on the cost of each piece of information. SGD throws away curvature (cheap forward+ backward, no Hessian). L-BFGS / Newton spend more per step but converge faster. Gradient-free methods spend more per step and ignore gradients but win when there aren't any to use.
Step 4

Comparison table

MethodInfo usedPer-step costConvergenceSweet spot
SGD + momentum$\nabla f$$O(d)$$O(\kappa \log \tfrac{1}{\varepsilon})$DL pretraining, mini-batch
Adam / AdamW$\nabla f$, $|\nabla f|^2$ (diag)$O(d)$$O(\kappa \log \tfrac{1}{\varepsilon})$ (diag-precond)Transformers, mixed scales
L-BFGS$\nabla f$, history $m$ pairs$O(md)$SuperlinearSmooth full-batch losses
Newton$\nabla f$, $H$$O(d^3)$Quadratic$d \lesssim 10^4$, smooth
K-FAC / Shampoo$\nabla f$, Fisher block-diag$O(\text{block}^3)$Faster than Adam in practiceLarge nets where stability matters
CMA-ES$f$ only (population)$O(\lambda d^2)$ per genLinear, robust$d \lesssim 10^3$, noisy black box
SPSA$f$ only (2 evals)$O(d)$ per stepSlow but dimension-independent per stepHardware / simulator loops
Step 5

Practical recipes

Step 6

Reading list