Curvature, the Hessian and Saddle Points
The gradient says which way is downhill; the Hessian says how the slope itself changes. Curvature explains why learning rates have a maximum, why some directions train slowly, and why high-dimensional loss surfaces are full of saddle points rather than bad local minima. The calculus is in Hessians and Second-Order Taylor; here we look at what it means for training networks.
The second-order picture
Near a point , the loss is approximately
For a gradient step the predicted change is . If the curvature along is large, the second term wins and the step increases the loss. Along an eigenvector with eigenvalue , gradient descent multiplies the error by , which diverges once :
Critical points
Where , the eigenvalues of classify the point: all positive is a local minimum, all negative a local maximum, mixed signs a saddle point. In a network with millions of parameters, having every one of millions of eigenvalues positive is a strong condition; most critical points with high loss turn out to be saddles. Gradient noise and momentum help escape them, because any small push along a negative-curvature direction grows.
import numpy as np
f = lambda w: w[0]**2 - w[1]**2 # a saddle at the origin
grad = lambda w: np.array([2 * w[0], -2 * w[1]])
H = np.array([[2.0, 0.0], [0.0, -2.0]])
print("eigenvalues of H:", np.linalg.eigvalsh(H), "-> saddle")
for start in ([1.0, 0.0], [1.0, 1e-6]):
w = np.array(start)
for _ in range(80):
w = w - 0.1 * grad(w)
print(f"start {start}: after 80 steps w = {np.round(w, 4)}, f = {f(w):.4f}")eigenvalues of H: [-2. 2.] -> saddle
start [1.0, 0.0]: after 80 steps w = [0. 0.], f = 0.0000
start [1.0, 1e-06]: after 80 steps w = [0. 2.1602], f = -4.6666
Started exactly on the ridge, gradient descent converges to the saddle; a perturbation of is enough to escape.
The edge of stability
The largest Hessian eigenvalue (the sharpness) can be estimated without forming by power iteration on Hessian-vector products, which autodiff computes for the cost of about two gradients. Observed in practice: during full-batch training the sharpness rises until it hovers around , the "edge of stability".
import numpy as np
rng = np.random.default_rng(0)
A = rng.normal(size=(50, 50)); H = A @ A.T / 50 # a positive semidefinite "Hessian"
hvp = lambda v: H @ v # in practice computed by autodiff
v = rng.normal(size=50)
for _ in range(1000):
v = hvp(v); v /= np.linalg.norm(v)
lam = v @ hvp(v)
print(f"power iteration: {lam:.4f}, exact: {np.linalg.eigvalsh(H).max():.4f}")
print(f"largest stable learning rate: {2 / lam:.4f}")power iteration: 3.5069, exact: 3.5069
largest stable learning rate: 0.5703
Flat and sharp minima
Minima with small Hessian eigenvalues are flat: the loss changes little if the weights are perturbed. Flat minima tend to generalize better, an observation behind the success of small-batch SGD and methods such as sharpness-aware minimization (SAM), which minimizes the worst loss in a small ball around the weights.
In software
torch.autograd.functional.hvpandjax.jvp(jax.grad(f), …)give Hessian-vector products.- Learning-rate warmup (Schedules) keeps early steps below while the sharpness is high.
- Newton's method uses ; it is too expensive for networks, but Adam's per-coordinate scaling is a cheap diagonal stand-in.
Exercises
Exercise 1: Maximum learning rate
The Hessian at a minimum has eigenvalues 0.5, 4 and 20. What is the largest stable step size?
Answer
.
Solution
Stability requires for every eigenvalue, so .
Exercise 2: Classify the point
has a critical point at the origin. What kind?
Answer
A saddle point.
Solution
has eigenvalues and : mixed signs.
Exercise 3: Divergence (code)
Run gradient descent on from with and for 20 steps.
Answer
converges (factor per step); diverges (factor ).
Solution
, so the threshold is ; each step multiplies by .
for lr in (0.19, 0.21):
w = 1.0
for _ in range(20):
w -= lr * 10 * w
print(lr, round(w, 4))0.19 0.1216
0.21 6.7275
Test yourself
Gradient descent on a quadratic is stable only if the step size is below…
- 1
A critical point whose Hessian has both positive and negative eigenvalues is…
- a minimum
- a maximum
- a saddle point
- impossible
How is the largest Hessian eigenvalue of a big network usually estimated?
- Form the full Hessian and call eig
- Power iteration with Hessian-vector products
- It cannot be estimated
- From the learning rate alone