A training run makes many small updates before its loss settles, so a method that needs fewer steps sounds appealing. The cost of a step matters too, especially as the network grows. Our earlier backpropagation and SGD examples use the gradient to choose an update. Methods that also use curvature have more information, but must obtain and work with it.
Counting steps alone favours curvature. Gauss-Newton reaches the noise floor in 30 iterations, L-BFGS in 40 and SGD in 20,000. L-BFGS is faster in elapsed time, taking 0.12 seconds against Gauss-Newton's 0.37. We trace gradients, Jacobians and Hessians on this 25-parameter network to explain the cost.
By the end, you will be able to estimate the memory and computation needed for full Newton on a 70-billion-parameter transformer.
Quick Win: Three Optimisers on One Loss Surface
Fit a two-layer GELU net with 8 hidden units (25 weights and biases) to 40 noisy observations of . Train it three ways from the same initialisation, log loss per iteration and per wall-clock second.

import torch
import torch.nn.functional as F
torch.manual_seed(0)
N = 40
x = torch.linspace(0.05, 0.95, N, dtype=torch.float64).unsqueeze(1)
y = torch.sin(2 * torch.pi * x) + 0.08 * torch.randn_like(x)
HIDDEN = 8 # 25 parameters total
def predict(theta, x):
W1 = theta[:HIDDEN].view(HIDDEN, 1)
b1 = theta[HIDDEN:2 * HIDDEN]
W2 = theta[2 * HIDDEN:3 * HIDDEN].view(1, HIDDEN)
b2 = theta[3 * HIDDEN:]
return F.gelu(x @ W1.T + b1) @ W2.T + b2
def loss(theta):
return 0.5 * ((predict(theta, x) - y) ** 2).mean()
The three trainers differ only in how they use loss(theta):
- SGD + momentum computes via
loss(theta).backward(), multiplies by a learning rate, and subtracts. - L-BFGS keeps the last 20 gradients and implicitly reconstructs an approximation to from them. One backward pass per iteration.
- Gauss-Newton (Levenberg-Marquardt) evaluates the full Jacobian of residuals with respect to parameters, forms as a positive-semidefinite approximation to the Hessian, and solves a linear system at every step.
# Gauss-Newton: outer-product (J^T J) approximation to the Hessian
from torch.autograd.functional import jacobian
J = jacobian(lambda t: (predict(t, x) - y).squeeze(-1), theta) # (N, W)
r = (predict(theta, x) - y).squeeze(-1).detach()
step = torch.linalg.solve(J.T @ J / N + damping * I, J.T @ r / N)
theta = theta - step
Here is the convergence per outer iteration (log scale on both axes so all three fit).

Gauss-Newton wins on iterations. L-BFGS is a hair behind. SGD needs roughly a thousand times more updates to reach the same loss. That is the textbook result: more curvature information, fewer steps.
Now the plot the iteration-count story leaves out.

On wall-clock time, L-BFGS wins: 0.12 seconds versus 0.37 for Gauss-Newton, and that is on a 25-parameter toy. Each Gauss-Newton step solves a linear system; each L-BFGS step does two inner products of length . At 25 parameters the gap is 3x. At 25 million, it is billions.
All three recover the true from the noisy samples. The difference is entirely in how they got there.

What Just Happened?
1. Backpropagation is the cheap way to get the gradient
Forget the cartoon with arrows flowing backwards through a network for a moment. Backpropagation is, mathematically, the chain rule applied to a computation graph. For a two-layer network with weights and and a sum-of-squares loss , the backpropagation equations write the gradient as
where is the output error and propagates it back through the hidden layer. The practical consequence: one forward pass, one backward pass, and every one of the network's weight derivatives is computed. Total cost: .
The naive alternative is finite differences. Perturb each weight individually, re-run the forward pass, measure the change in loss. That costs forward passes instead of one. For a 70-billion-parameter language model it would be 70 billion forward passes per gradient step. Backpropagation is the difference between a feasible training loop and a computationally impossible one.
One observation is worth sitting with. The only reason deep learning exists is that one backward pass gives you numbers at cost. Every autograd framework on the planet is an industrial-strength version of that chain rule.
2. The Jacobian is a sideways backward pass
The Hessian and Jacobian names get shuffled around the literature, so it's worth pinning them down. For a network mapping inputs to outputs , the Jacobian is
This measures how much each output changes for a small wiggle in each input. It is the linear approximation of the network at a point. In a trained net, if the Jacobian is large along some input direction, the network is highly sensitive to that feature; if it is near zero, the model ignores it. For our trained network fitting , the one-input Jacobian should look like the derivative of the target function, .

It does, to within the same noise budget that sets the fit itself. Computing this costs one backward pass per input point, which is the same trick that makes backprop tractable. The useful mental model: the gradient is (how loss changes when you wiggle weights), and the Jacobian is (how outputs change when you wiggle inputs). Both are first-order objects; both are one backward pass.
3. The Hessian is expensive because it is big
The Hessian is the matrix of second derivatives of the loss with respect to the weights:
For parameters, this is a matrix. Storing it is . Solving for the Newton step is . The gradient costs . That gap is the whole story.

At (a small MLP), the Newton solve is roughly seven orders of magnitude more expensive than the gradient step. At (GPT-3 scale), the Hessian does not fit on Earth's hard drives, let alone on a single GPU. That is why you never see full Newton in a modern training loop.
The theorists' comeback is that Newton converges in far fewer iterations, so maybe the per-step cost is worth it. Sometimes, for small convex problems, yes. For neural networks, no: the loss surface is non-convex, and that breaks Newton in ways the textbook classical-optimisation view does not prepare you for.
4. Non-convex loss breaks plain Newton
Evaluate the full Hessian of our 25-parameter net at the initial weights. Check its eigenvalues.

Thirteen of twenty-five eigenvalues are negative at initialisation. Newton's direction assumes is positive definite; along any direction where has a negative eigenvalue, the step points uphill. Dauphin et al. (2014, Identifying and attacking the saddle point problem in high-dimensional non-convex optimisation) showed that in high-dimensional neural networks this is the rule, not the exception. The loss surface is riddled with saddle points, and plain Newton is attracted to them rather than repelled.
That is why, in the experiment above, we used Gauss-Newton rather than full Newton. Gauss-Newton approximates the Hessian as , where is the Jacobian of residuals with respect to parameters. Because is positive semi-definite by construction, the update direction is always a descent direction. This is the outer-product approximation, also known as the Levenberg-Marquardt method, and it is the second-order method you will see in regression packages like scipy.optimize.least_squares. Naive Newton with the full Hessian on the same net gets stuck at a loss of 0.27 (well above the noise floor of 0.003) and refuses to move.
The broader lesson: even if you could afford the Hessian, you would not want to use it on a non-convex loss. You would want or some other positive-definite modification. And at that point you might as well skip the expensive matrix and use a quasi-Newton method that approximates from gradient history at cost.
Going Deeper
Why modern activations quietly killed second-order
The classical derivations assume smooth activations: , sigmoid, logistic. All have continuous second derivatives. The Hessian of a two-layer tanh network is a well-defined object you can differentiate through. ReLU broke this.

Tanh was the textbook default until the early 2010s. Reading basic tutorials today, you still see it; the activation has been over 10 years past its retirement date and nobody uses it in production networks any more. ReLU took over in 2012 (Krizhevsky et al., AlexNet) because it trains faster and avoids vanishing gradients. Its trade-off: ReLU is piecewise linear, so everywhere except at where it is undefined. A ReLU network's Hessian has zeros on most of its diagonal contributions and is uninformative as a curvature estimate. Second-order methods cannot extract the curvature they need because there is no curvature to extract.
GELU (Hendrycks & Gimpel, 2016), used in BERT, GPT-2, LLaMA, is smooth by construction: , where is the Gaussian CDF. Its second derivative is a well-behaved bump. We chose GELU for this post for the same reason the classical treatments chose tanh: the Hessian exists and can be probed. The pattern is larger than any one activation: the field moved toward first-order methods partly because the activations moved toward piecewise-linear. If your gradient is informative and your Hessian is zero, you build optimisers around gradients.
The Hessian approximations people use in practice
Full Newton is impossible at scale, but second-order information is useful. The Hessian (or a proxy) gets used in four practical ways.
Diagonal approximation. Keep only the diagonal of , ignore the off-diagonal terms. Storage drops to and the inverse is trivial. Adagrad, RMSProp, and Adam are exactly this idea applied to squared-gradient accumulators, which are a stochastic diagonal approximation to the Fisher information matrix (which itself approximates the Hessian for log-likelihood losses). Every time you use Adam, you are using a cheap diagonal Hessian preconditioner.
Outer-product / Gauss-Newton. Approximate as plus a damping term. Guaranteed positive semi-definite, cheap to assemble for regression losses, and the foundation of Levenberg-Marquardt. This is what our Quick Win used and what scientific computing packages still use for nonlinear least squares.
Quasi-Newton (L-BFGS). Never form the Hessian. Keep the last gradient differences and use the BFGS update formula to reconstruct a low-rank approximation to on the fly. Storage is ( around 10 to 20 in practice), per-step cost is . L-BFGS is the go-to method for smooth non-stochastic optimisation (fitting logistic regressions, hyperparameter optimisation of GPs, variational inference with small numbers of parameters). It is the second-fastest thing in our Quick Win plot and the fastest in wall-clock terms.
Hessian-vector products via the R-operator. For many uses you do not need , only for some vector . Pearlmutter (1994) showed this can be computed in time with a single forward-backward pass variant, no matrix ever assembled. Martens's 2010 Hessian-Free optimisation for deep networks is the most famous application: use conjugate gradient on products to approximately solve without ever materialising . It is how you can do Newton-ish steps at trillion-parameter scale.
The pattern repeats: the second you think a second-order method is out of reach, someone finds a way to extract just the part of it that is informative at first-order cost.
A brief Bayesian cameo
The Hessian also shows up in Bayesian inference. At the MAP weights, the Hessian of the negative log-posterior is the inverse covariance of the Laplace approximation to the posterior. The log determinant of that Hessian appears in the evidence framework as the Occam factor. A follow-up post extends this to Bayesian neural networks: predictions with uncertainty, and model evidence that balances fit against effective parameter count via the Hessian's eigenvalues. If the Hessian is expensive for optimisation, it is equally expensive for Bayesian inference, which is why modern Bayesian deep learning uses variational approximations or stochastic-gradient MCMC rather than Laplace. The problem is the same problem: matrices at neural-network scale.
The Foundations
The key references behind this post are worth reading at source.
Rumelhart, Hinton, Williams (1986), Learning representations by back-propagating errors. The original backpropagation paper. A three-page Nature letter showing how hidden layers of a feed-forward network can learn distributed representations via gradient descent on a sum-of-squares error. Free on the Stanford CS229 site.
Pearlmutter (1994), Fast exact multiplication by the Hessian. Shows how to compute for any vector in time. The key trick is the R-operator : apply the directional derivative along to the forward and backward propagation equations, introducing companion variables for the hidden units and for the outputs, so that falls out of a single forward-backward sweep with no matrix ever assembled.
Dauphin, Pascanu, Gulcehre, Cho, Ganguli, Bengio (2014), Identifying and attacking the saddle point problem in high-dimensional non-convex optimization. The saddle-point paper. Argues that in high-dimensional non-convex problems (neural networks), the difficulty is not local minima but saddle points, which trap Newton's method. Motivates saddle-free optimisation methods that flip the sign of negative Hessian eigenvalues. Free on arXiv:1406.2572.
Martens (2010), Deep learning via Hessian-free optimization. The paper that popularised products for deep learning. Combines Pearlmutter's trick with conjugate gradient and a positive-semidefinite Gauss-Newton surrogate. Briefly competitive with SGD for deep networks around 2010-2013 before Adam made the discussion moot. Free on the University of Toronto page.
Le Cun, Bottou, Orr, Müller (1998), Efficient BackProp. The practitioner's guide. Covers the diagonal Hessian approximation for learning-rate adaptation (precursor to Adam), the importance of input normalisation (precursor to batch normalisation), and why tanh is preferred to sigmoid in shallow nets (centred activations). A lot of what feels like modern deep-learning folk wisdom shows up in this 1998 chapter.
The clearest way to see backpropagation is as a disciplined application of the chain rule on a computation graph, rather than a mysterious "error signal" flowing backwards. A simple two-layer worked example plus the efficiency argument is the whole case for why gradient descent on neural networks works at all.
Interactive Tools
- Gradient Descent Visualizer: The curvature this post declines to compute, seen from the outside. The ravine and Rosenbrock presets are exactly the ill-conditioned cases where first-order methods struggle and momentum patches over the gap
- Overfitting Explorer: a polynomial-regression playground, the same dataset the evidence-framework post used. Shows how first-order gradient descent on a closed-form least-squares problem is unnecessary when the normal equations exist. The contrast is useful.
- Regression Playground: Fit linear and polynomial regressions interactively. For a quadratic loss, the Hessian is constant and Newton converges in a single step. Second-order methods win decisively here.
Related Posts
- Backpropagation Demystified: the chain-rule trick this post builds on, derived from first principles.
- Optimisers from Scratch: SGD, Momentum, Adam: first-order optimisers in code. Adam is the diagonal-Hessian preconditioner that quietly replaced second-order methods in deep learning.
- Learning Rate Scheduling: From Step Decay to One-Cycle: why first-order methods still need the learning rate tuned carefully. Second-order methods sidestep this; first-order methods compensate with schedules.
- Bayesian Model Comparison: The Evidence Framework: where the Hessian appears in the Laplace approximation for model evidence. Same matrix, different use.
- AIC and BIC: Information Criteria for Model Selection: BIC drops the Hessian log-determinant; AIC drops the prior. Both are cheap approximations to the Bayesian evidence that sidestep computing .
- The Universal Approximation Theorem in NumPy: The theorem says a fit exists; first-order methods are how a network with enough width actually finds it.






