NeuroGenesys.
Optimization & GeneralizationAcademy • Foundations • Lesson 1 of 4

Gradient descent and the shape of a loss surface

7 min read • By Will Schulz • NeuroGenesys AI Academy

Every modern neural network is trained by some variant of one idea: compute which way the loss decreases fastest and take a small step that way. This lesson covers why that works, how the step size and the curvature of the loss interact, and what the loss surfaces of large networks look like in practice.

The update

Given a differentiable loss L(θ)L(\theta) over parameters θ∈Rd\theta\in\mathbb{R}^d, gradient descent repeats

θk+1=θk−η ∇L(θk),\theta_{k+1} = \theta_k - \eta\,\nabla L(\theta_k),

where η>0\eta>0 is the learning rate. Textbooks usually credit the method to Augustin-Louis Cauchy, who described it in a note to the Paris Académie des Sciences in 1847. Historians point out that his note is less clear-cut than the textbook version.[1]

Why the negative gradient? A first-order Taylor expansion gives L(θ+Δ)≈L(θ)+∇L⊤ΔL(\theta + \Delta) \approx L(\theta) + \nabla L^\top \Delta. Among all steps of a fixed small length, ∇L⊤Δ\nabla L^\top\Delta is most negative when Δ\Delta points along −∇L-\nabla L (by the Cauchy–Schwarz inequality). The gradient is the direction of steepest local increase, and we go the other way.

Curvature sets the speed limit

The first-order picture says nothing about how large a step can be. Adding the second-order term shows what goes wrong:

L(θ−ηg)≈L(θ)−η ∥g∥2+η22 g⊤Hg,L(\theta - \eta g) \approx L(\theta) - \eta\,\|g\|^2 + \frac{\eta^2}{2}\, g^\top H g ,

where g=∇Lg = \nabla L and HH is the Hessian, the matrix of second derivatives. The linear term always helps. The quadratic term hurts in proportion to the curvature along the step direction. If the step is too large, the curvature term wins and the loss goes up.

One dimension

Take L(x)=λ2x2L(x) = \tfrac{\lambda}{2}x^2, with curvature λ>0\lambda>0. Then ∇L=λx\nabla L = \lambda x and the update is

xk+1=(1−ηλ) xk.x_{k+1} = (1-\eta\lambda)\,x_k .

The iterate shrinks geometrically when ∣1−ηλ∣<1|1-\eta\lambda|<1, that is, when 0<η<2/λ0<\eta<2/\lambda. For η<1/λ\eta<1/\lambda it approaches the minimum smoothly. For 1/λ<η<2/λ1/\lambda<\eta<2/\lambda it overshoots and oscillates while still converging. For η>2/λ\eta>2/\lambda it diverges. The highest curvature you encounter sets the largest stable learning rate.

Many dimensions and the condition number

Near a minimum, any smooth loss looks like a quadratic 12θ⊤Hθ\tfrac12\theta^\top H\theta. In the eigenbasis of HH, gradient descent splits into independent one-dimensional problems, one per eigenvalue λi\lambda_i, each contracting by ∣1−ηλi∣|1-\eta\lambda_i| per step. The learning rate must satisfy η<2/λmax⁡\eta < 2/\lambda_{\max} for stability, but progress along the flattest direction is governed by λmin⁡\lambda_{\min}. The ratio κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min} is the condition number. With the best fixed step, η=2/(λmax⁡+λmin⁡)\eta = 2/(\lambda_{\max}+\lambda_{\min}), the error contracts by a factor of (κ−1)/(κ+1)(\kappa-1)/(\kappa+1) per step.

Worked example: a long, narrow valley

Let L(x,y)=12(x2+100 y2)L(x,y) = \tfrac12(x^2 + 100\,y^2). The curvatures are 1 and 100, so κ=100\kappa = 100.

  • Stability requires η<2/100=0.02\eta < 2/100 = 0.02.
  • The best fixed step is η=2/101≈0.0198\eta = 2/101 \approx 0.0198, and the contraction factor is 99/101≈0.98099/101 \approx 0.980.
  • Reducing the error by a factor of 100 then takes about ln⁡100/(−ln⁡0.980)≈4.6/0.020≈230\ln 100 / (-\ln 0.980) \approx 4.6/0.020 \approx 230 steps.

The steep yy direction forces a small step size, and the shallow xx direction then takes hundreds of steps to make progress. The iterates zig-zag across the valley while creeping along it. A perfectly round bowl (κ=1\kappa=1) would be solved in one step. Poor conditioning, not distance from the minimum, is what makes plain gradient descent slow. It is the main motivation for momentum and adaptive methods, covered in Stochastic optimization.

Check your understanding

For L(x,y)=12(x2+100y2)L(x,y)=\tfrac12(x^2+100y^2), you choose η=0.025\eta = 0.025. What happens?

Show answer +

Along yy, the contraction factor is 1−0.025×100=−1.51 - 0.025\times100 = -1.5, which has magnitude greater than 1. The yy coordinate flips sign and grows by 50% each step, so the iteration diverges, even though the xx direction alone would be perfectly happy with this step size.

What neural-network loss surfaces look like

A quadratic bowl is a local picture. The full loss of a deep network is non-convex, high-dimensional and shaped by symmetries; for example, permuting the hidden units of a layer leaves the function unchanged. A few facts hold up across the literature:

  • Saddle points outnumber bad local minima. At a critical point in very high dimension, it is unlikely that the curvature is positive in every one of millions of directions. Dauphin et al. argued, drawing on random-matrix theory and experiments, that the main obstacle is saddle points and the flat plateaus around them, which can look like local minima. High-error local minima are less of a problem.[2] Gradient descent slows near saddles but is not trapped by them, and the noise of stochastic gradients helps it leave.
  • Many minima, connected. Overparameterised networks have large sets of parameters that fit the training data equally well. Which one the optimiser lands in depends on initialisation, learning rate and batch size. This matters for generalization (see Generalization).
  • Training runs at the edge of stability. The quadratic analysis predicts divergence once the sharpness λmax⁡\lambda_{\max} exceeds 2/η2/\eta. Cohen et al. found that full-batch gradient descent on neural networks typically pushes sharpness up until it hovers just above 2/η2/\eta. The loss then decreases non-monotonically over short timescales while still falling over long ones.[3] The network adapts its curvature to the learning rate rather than the other way round. The classical stability bound is still the right reference point, but it does not describe what happens next.
Check your understanding

Edge-of-stability training sits at sharpness λmax⁡≈2/η\lambda_{\max}\approx 2/\eta. If you halve the learning rate partway through training, what does the classical analysis predict, and what would you expect to happen to sharpness afterwards?

Show answer +

At the new step size the stability threshold doubles to 4/ηold4/\eta_{\text{old}}, so the current curvature is comfortably stable and the loss should drop smoothly at first. If the edge-of-stability pattern holds, sharpness will then rise again toward the new threshold 2/ηnew2/\eta_{\text{new}}. The temporary room below the stability threshold is one plausible account of the quick fall in loss often seen right after a learning-rate decay.

Practical consequences

Several standard training practices follow from the curvature picture:

  • Learning-rate warmup. Early in training, before the parameters have settled into well-scaled values, a large step is more likely to diverge. Starting with a small step and raising it over the first few thousand updates avoids early divergence. Large-batch training relies on warmup explicitly,[4] and large language models routinely use it. Llama 2, for instance, used 2,000 warmup steps followed by cosine decay.[5]
  • Decay. Lowering the step later lets the iterate settle into regions of higher curvature that a large step would bounce out of.
  • Gradient clipping. Capping the gradient norm limits the damage from a single step taken where the local curvature or gradient spikes.
  • Normalisation and residual connections improve conditioning, so a single learning rate suits more directions at once.

Key takeaways

  • Gradient descent steps along −∇L-\nabla L, the direction of steepest local decrease. Its use for optimisation goes back to Cauchy in 1847.
  • On a quadratic, stability requires η<2/λmax⁡\eta < 2/\lambda_{\max}, and the convergence rate is governed by the condition number κ=λmax⁡/λmin⁡\kappa=\lambda_{\max}/\lambda_{\min}. With κ=100\kappa=100, a 100-fold reduction takes about 230 steps.
  • Deep-network losses are non-convex, with saddle points and plateaus as the main obstacles and many equally good minima.
  • In practice sharpness tends to settle near 2/η2/\eta (the edge of stability). Warmup, decay and clipping are ways of managing curvature.

Sources

  1. C. Lemaréchal (2012). "Cauchy and the Gradient Method." Documenta Mathematica, Extra Volume: Optimization Stories, 251–254. https://doi.org/10.4171/DMS/6/27 ↩

  2. Y. Dauphin, R. Pascanu, C. Gulcehre, K. Cho, S. Ganguli and Y. Bengio (2014). "Identifying and attacking the saddle point problem in high-dimensional non-convex optimization." arXiv:1406.2572. https://arxiv.org/abs/1406.2572 ↩

  3. J. M. Cohen, S. Kaur, Y. Li, J. Z. Kolter and A. Talwalkar (2021). "Gradient Descent on Neural Networks Typically Occurs at the Edge of Stability." ICLR 2021. arXiv:2103.00065. https://arxiv.org/abs/2103.00065 ↩

  4. P. Goyal, P. Dollár, R. Girshick et al. (2017). "Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour." arXiv:1706.02677. https://arxiv.org/abs/1706.02677 ↩

  5. H. Touvron et al. (2023). "Llama 2: Open Foundation and Fine-Tuned Chat Models." arXiv:2307.09288. https://arxiv.org/abs/2307.09288 ↩

Leadership

A word from the founder — on why the brain is the blueprint, and why the next decade of intelligence will be built here.

"The brain is the universe's only proof that general intelligence is possible. We treat it as the blueprint."

From cortical interfaces to photonic silicon, every program at NeuroGenesys exists to answer one question: how does intelligence arise — and how do we build it safely.

Will Schulz

Will Schulz

Founder, NeuroGenesys • AW3 Technology