Chapter 17Second-order optimization
We review in this chapter methods whose iterations take the form wt+1:=wt−γtBt∇L(wt), where γt is a stepsize and Bt is a pre-conditioning matrix involving second-order derivatives.
17.1 Newton’s method
17.1.1 Variational perspective
We saw in Eq. (16.2) that gradient descent can be motivated from a variational perspective, in which we use a linear approximation of the objective around the current iterate, obtained from the current gradient. Similarly, if we have access not only to the gradient but also to the Hessian of the objective, we can use a quadratic approximation of the objective around the current iterate. More precisely, given a function L(w), we may consider minimizing the second-order Taylor approximation of L(w) around the current iterate wt, L(w)≈L(wt)+⟨∇L(wt),w−wt⟩+21⟨w−wt,∇2L(wt)(w−wt)⟩. Newton’s method simply iteratively minimizes this quadratic approximation around the current iteration wt, namely, wt+1=w∈WargminL(wt)+⟨∇L(wt),w−wt⟩+21⟨w−wt,∇2L(wt)(w−wt)⟩.(17.1) If the Hessian is positive definite at wt, which we denote by ∇2L(wt)≻0, then the minimum is well-defined and unique (this is for example the case if L is strictly convex). The iterates can then be written analytically as wt+1=wt−∇2L(wt)−1∇L(wt). If the Hessian is not positive definite, the minimum may not be defined. Ignoring this issue and taking the analytical formulation could be dangerous, as it could amount to computing the maximum of the quadratic instead if, for example, the quadratic was strictly concave (i.e., ∇2L(w)≺0).
17.1.2 Regularized Newton method
A simple technique to circumvent this issue consists in adding a regularization term to the Hessian. Namely, from a variational viewpoint, we can add a proximity term 21∥w−wt∥22, encouraging it to stay close to the current wt. The iterates of this regularized Newton method then take the form wt+1=w∈Wargmin L(wt)+⟨∇L(wt),w−wt⟩+21⟨w−wt,∇2L(wt)(w−wt)⟩+2ηt∥w−wt∥22, where ηt controls the regularization strength. Assuming ηt>0 is strong enough to make ∇2L(wt)+ηtI positive-definite, we have wt+1=wt−dt, where we defined the direction dt:=(∇2L(wt)+ηtI)−1∇L(wt).(17.2) Other techniques to circumvent this issue include using cubic regularization and modifying the spectral decomposition of the Hessian, by thresholding the eigenvalues or taking their absolute values. We refer the interested reader to, e.g., (Nesterov, 2018; Wright and Nocedal, 1999) for more details.
17.1.3 Approximate direction
We observe a main impediment for implementing such a second-order optimization algorithm: even if we had access to the Hessian of the objective for free and this Hessian was positive definite, computing the exact direction dt in Eq. (17.2) requires computing an inverse-Hessian vector product (IHVP) with the gradient ∇L(wt). Doing so exactly requires solving a linear system (∇2L(wt)+ηtI)dt=∇L(wt), which a priori takes O(P3) time. In practice, however, we can compute IHVPs approximately, as explained in Section 9.4.
17.1.4 Convergence guarantees
While implementing Newton’s method comes at a higher computational cost, it can also benefit from faster convergence rates. Briefly, if Newton’s method is initialized at a point w0∈W close enough to the minimizer w⋆ of a μ-strongly convex function with M-Lipschitz continuous Hessian (namely ∥w0−w∗∥2≤3M2μ), then Newton’s method converges at a quadratic rate (Nesterov, 2018), that is, R(t)≤O(exp(−2t)) (see Section 15.5 for a brief introduction to performance guarantees). This is far superior to gradient descent. Such an efficiency motivated the development of interior point methods, that have been a breakthrough in constrained optimization, thanks to the use of log-barrier penalties (Nesterov, 2018).
17.1.5 Linesearch
In practice, we may not have access to an initial point close enough to the minimizer. In that case, even for strictly convex functions for which Newton’s steps are well-defined, taking wt+1=wt−dt may not ensure a decrease of the objective values. Nevertheless, the direction dt may define a descent direction as defined below.
Definition 17.1 (Descent direction)
A point d∈W defines a descent direction −d for an objective L at w, if there exists a positive stepsize γ>0 such that L(w−γd)≤L(w). If L is differentiable, −d is a descent direction if ⟨−d,∇L(w)⟩<0.
For Newton’s method without regularization, dt=∇2L(wt)−1∇L(wt) is then a descent direction at wt, as long as ∇L(wt)=0 and ∇2L(wt)≻0. If ∇2L(wt)≻0, choosing ηt>0 such that ∇2L(wt)+ηtI≻0, also ensures that dt=−(∇2L(wt)+ηtI)−1∇L(wt) is a descent direction (as long as ∇L(wt)=0). Newton’s method is then generally equipped with a linesearch method that attempts to take steps of the form wt+1=wt−γtdt with γt chosen as the largest stepsize among {ρτ,τ∈N} for ρ∈(0,1) until a sufficient decrease of the objective is satisfied such as, for c∈(0,1), L(wt−γtdt)≤L(wt)−cγt⟨∇L(wt),∇2L(wt)−1∇L(wt)⟩. For strongly convex functions, such an implementation exhibits two phases: a first phase during which Newton’s steps are “damped” by using a stepsize γt<1 and a second phase of super-fast convergence during which stepsizes γt=1 are taken, and the objective decreases very fast. Even far from the optimum, Newton directions can advantageously adapt to the local geometry of the objective to speed up convergence compared to a regular gradient descent as explained below.
17.1.6 Geometric interpretation
To understand the efficiency of Newton’s method compared to gradient descent, consider the minimization of a simple quadratic L(w)=21aw12+21bw22 for a≫b≥0, as illustrated in Fig. 17.1. A gradient descent moves along the directions ∇L(w)=(aw1,bw2)⊤ and its stepsize is limited by the variations in the first coordinate leading to some oscillations. If we were simply rescaling the gradient by (a,b), i.e., taking steps of the form wt+1=wt−γdiag(a−1,b−1)∇L(wt), the variations in both coordinates would be normalized to one and the stepsize could simply be chosen to γ=1 to directly get w⋆. In other words, by adapting the geometry of the directions with the geometry induced by the objective, we can circumvent the oscillations.
That’s exactly what Newton’s method does by modifying the gradient direction using the inverse of the Hessian. Formally, at iteration t, consider the modified objective L~(v)=L(Av) for A=∇2L(wt)−1/2, with L strictly convex and A the inverse matrix square root of the Hessian. One easily verifies that a Newton step is equivalent to a gradient step on L~, that is, vt+1=vt−∇L~(vt) ⟺ wt+1=wt−(∇2L(wt))−1∇L(wt) where wt=Avt=∇2L(wt)−1/2vt. In the geometry induced by A, the objective is generally better conditioned as illustrated in Fig. 17.1. This explains the efficiency of Newton’s method. In particular for any strongly convex quadratic, a Newton step reaches the optimum in one iteration, while a gradient step can take many more iterations.

Figure 17.1: Left: Minimization of a quadratic L(w):=21aw12+21bw22 by gradient descent. For a≫b≥0, gradient descent typically oscillates. Right: minimization by Newton’s method amounts to changing the geometry of the problem to avoid oscillations.
17.1.7 Stochastic Newton’s method
Consider now an expected loss w∈Wmin L(w):=ES∼ρ[L(w;S)]. In that case, an estimate of the Hessian can be constructed just like for the gradient using that ES∼ρ[∇2L(w;S)]=∇2L(w). Les us then denote g(w;S)≈∇L(w),H(w;S′)≈∇2L(w) some stochastic estimates of the gradient and the Hessian, respectively, with S,S′ independently drawn from ρ or from mini-batch approximations with varying mini-batch sizes. One implementation of a stochastic Newton method can then be wt+1=wt−γt(H(wt;S′)+ηtI)−1g(wt;S), for ηt≥0 such that (H(wt;S′)+ηtI)−1≻0 and γt fixed or chosen to satisfy some sufficient decrease condition. We refer the interested reader to, e.g., (Xu et al., 2020), for more details and variants.
17.2 Gauss-Newton method
Newton’s method (17.1) is usually not properly defined for non-convex objective functions, since the Hessian may not be positive definite at the current iterate. We saw in Section 9.2 that the Gauss-Newton matrix can be used to define a positive-semidefinite approximation of the Hessian. Here, we revisit the Gauss-Newton method from a variational and partial linearization perspective. While the original Gauss-Newton method originates from nonlinear least-squares, we will first describe an extension to arbitrary convex loss functions, since it is both more general and easier to explain.
17.2.1 With exact outer function
Consider a composite objective of the form L(w):=ℓ(f(w)), where ℓ:M→R is a convex function, such as a convex loss function applied on a given sample, and f:W→M is a nonlinear function, such as a neural network with parameters w∈W, evaluated on the same sample. We saw that gradient descent and Newton’s method amount to using linear and quadratic approximations of L(w) around the current iterate wt, respectively. As a middle ground between the two, the Gauss-Newton method uses the linearization of f around wt f(w)≈f(wt)+∂f(wt)(w−wt) but keeps ℓ as is to obtain the objective wt+1:=w∈Wargminℓ(f(wt)+∂f(wt)(w−wt))=w∈Wargminℓ(∂f(wt)w+f(wt)−∂f(wt)wt)=w∈Wargminℓ(Jtw+δt), where we defined the shorthands Jt:=∂f(wt) and δt:=f(wt)−∂f(wt)wt. We call ℓ(Jtw+δt) the partial linearization of L=ℓ∘f at wt, as opposed to the full linearization of L used in gradient descent.
Since the composition of a convex function and of linear function is convex, this objective is convex even if L(w) is nonconvex. In practice, we often add a proximity term as regularization to define wt+1:=w∈Wargminℓ(Jtw+δt)+2ηt∥w−wt∥22.(17.3) We can see this update as an approximation of the proximal point update w∈WargminL(w)+2ηt∥w−wt∥22, where L(w) has been replaced by its partial linearization. Solving Eq. (17.3) using gradient-based solvers requires computing the gradient of w↦ℓ(Jtw+δt), which is w↦(Jt)∗∇ℓ(Jtw+δt). Computing this gradient by autodiff therefore requires performing a forward pass to compute the JVP Jtw and a backward pass to compute the VJP (Jt)∗∇ℓ(z). See Section 2.3 for an introduction to these operators and Chapter 8 for an introduction to autodiff.
The Gauss-Newton method with arbitrary convex outer loss is often called modified Gauss-Newton (Nesterov, 2007) or prox-linear (Drusvyatskiy and Paquette, 2019). The classical Gauss-Newton and Levenberg-Marquardt (Levenberg, 1944; Marquardt, 1963) methods originate from nonlinear least-squares and are recovered when ℓ(z) is quadratic (Kelley, 1995), such as ℓ(z):=21∥z−y∥22, for y some reference target. The Gauss-Newton method corresponds classically to not using regularization (i.e., ηt=0) and the Levenberg-Marquardt method uses regularization (usually called damping, potentially changing ηt across iterations). See e.g., (Messerer et al., 2021), for a survey of different variants.
17.2.2 With approximate outer function
Another variant of the Gauss-Newton method consists in replacing the convex loss ℓ with its quadratic approximation around zt:=f(wt), qt(z):=ℓ(zt)+⟨∇ℓ(zt),z−zt⟩+21⟨z−zt,∇2ℓ(zt)(z−zt)⟩≈ℓ(z) to define the update wt+1:=w∈Wargminqt(Jtw+δt)+2ηt∥w−wt∥22. Notice that ℓ has been replaced by its quadratic approximation qt. This objective is always a convex quadratic, unlike the objective of the Newton method in Eq. (17.1), which is a priori a nonconvex quadratic, if f is nonlinear. Simple calculations show that wt+1=w∈Wargmin L(wt)+⟨qt,Jt(w−wt)⟩+21⟨w−wt,(Jt)∗QtJt(w−wt)⟩+2ηt∥w−wt∥22 where qt:=∇ℓ(f(wt))∈M=RZ,Qt:=∇2ℓ(f(wt))∈RZ×Z. The closed form solution is wt+1=wt−((Jt)∗QtJt+ηtI)−1(Jt)∗qt=wt−(∇GN2(ℓ∘f)(wt)+ηtI)−1∇L(wt), where we used the (generalized) Gauss-Newton matrix of L=ℓ∘f, defined in Section 9.2.
17.2.3 Linesearch
Similarly to Newton’s method, the iterates of a Gauss-Newton method may diverge when used alone. However, the direction −(∇GN2(ℓ∘f)(wt)+ηtI)−1∇L(wt) defines a descent direction for any ηt>0 and can be combined with a stepsize γt (typically chosen using a linesearch) to obtain iterates of the form wt+1=wt−γt(∇GN2(ℓ∘f)(wt)+ηtI)−1∇L(wt).
17.2.4 Stochastic Gauss-Newton
In deep learning, the objective generally consists in an expectation over samples of the composition between a loss function and a network function: L(w)=ES∼ρ[L(w;S)]=E(X,Y)∼ρ[ℓ(f(w;X);Y)] where S=(X,Y) denotes a sample pair of input X with associated label Y. In that case, as already studied in Section 9.2, the Gauss-Newton matrix ∇GN2L is the expectation of the individual Gauss-Newton matrices ∇GN2L(w;x,y)∇GN2L(w):=∂f(w;x)⊤∇2ℓ(f(w;x))∂f(w;x),:=E(X,Y)∼ρ[∇GN2L(w;x,y)]. We can estimate the gradient and the Gauss-Newton matrix by, respectively, g(w;S)≈∇L(w), and G(w;S′)≈∇GN2L(w) for S,S′∼ρ or using mini-batch approximations. A stochastic Gauss-Newton method therefore performs iterates wt+1:=wt−γt(G(wt;S′)+ηtI)−1g(wt;S), for ηt≥0 and γt fixed or selected to satisfy some criterion.
17.3 Natural gradient descent
Natural gradient descent (Amari, 1998) follows a similar principle as gradient descent: linearize the objective around the current iterate and minimize this approximation together with a proximity term. It differs from gradient descent in the choice of the proximity term: rather than using a squared Euclidean distance between the parameters, it uses a Kullback-Leibler divergence between the probability distributions these parameters define.
Negative log-likelihood
We consider objectives of the form w∈WminL(w)=ES∼ρ[L(w;S)]=ES∼ρ[−logqw(S)], where ρ is an unknown data distribution (but from which we can sample) and where qw is a probability distribution parameterized by w. As reviewed in Chapter 3, the negative log-likelihood can be used as a loss function (many loss functions can be seen from this perspective, including the squared and logistic loss functions). In the unsupervised setting, where S=Y, we simply use qw(Y) as is. In the supervised setting, where S=(X,Y), we use the product rule P(X,Y)=P(X)P(Y∣X) to parameterize qw(S) as qw(x,y):=ρX(x)pθ(y), where ρX is the marginal distribution for X, pθ(y) is the PMF/PDF of a probability distribution and θ=f(w;x) is for instance a neural network with parameters w∈W and input x∈X.
17.3.1 Variational perspective
Natural gradient descent is motivated by updates of the form wt+1=w∈WargminL(wt)+⟨∇L(wt),w−wt⟩+KL(qwt,qw), where KL(p,q):=∫p(z)logq(z)p(z)dz is the Kullback-Leibler (KL) divergence. Unlike gradient descent, the proximity term is therefore between the current distribution qwt and a candidate probability distribution qw. The above problem is intractable in general, as the KL may not have a closed form. Nevertheless, its quadratic approximation can be shown (Amari, 1998) to admit a simple form, KL(qwt,qw)≈21⟨w−wt,∇F2L(wt)(w−wt)⟩ where we used the Fisher information matrix ∇F2L(w), studied in Section 9.3. Equipped with this quadratic approximation of the KL divergence, natural gradient descent amounts to computing iterates as wt+1:=w∈Wargmin L(wt)+⟨∇L(wt),w−wt⟩+21⟨w−wt,∇F2L(wt)(w−wt)⟩+2ηt∥w−wt∥22, where a quadratic proximity term was added to ensure a unique solution. This is a strictly convex problem as ∇F2L(wt) is positive semi-definite. The closed-form solution is wt+1=wt−(∇F2L(wt)+ηtI)−1∇L(wt). Because the Gauss-Newton and Fisher information matrices are equivalent when pθ is an exponential family distribution (Proposition 9.6), the Gauss-Newton and natural gradient methods coincide in this case.
17.3.2 Stochastic natural gradient descent
In practice, we may not have access to ∇L(wt) in closed form as it is an expectation over ρ. Moreover, ∇F2L(wt) may not be computable in closed form either. To estimate the Fisher information matrix, we can use that (see Section 9.3) using the shorthand θ:=f(w,X), ∇F2L(w)=EX∼ρXEY∼pθ[∇L(w;X,Y)⊗∇L(w;X,Y)]. We can then build estimates g(wt;S)≈∇L(wt,S) and F(wt;S′)≈∇F2L(wt) for S sampled from ρ and S′ sampled from qwt(x,y)=pX(x)ρθ(y). A stochastic natural gradient descent can then be implemented as wt+1=wt−γt(F(wt;S′)+ηtI)−1g(wt;S), where γt is a stepsize, possibly chosen by linesearch.
In deep learning, the product with the inverse Fisher or Gauss-Newton matrices can remain costly to compute. Several approximations have been proposed, such as KFAC (Botev et al., 2017; Martens and Grosse, 2015), which uses a computationally efficient structural approximation to these matrices.
17.4 Quasi-Newton methods
17.4.1 BFGS
A celebrated example of quasi-Newton method is the BFGS method (Broyden, 1970; Fletcher, 1970; Goldfarb, 1970; Shanno, 1970), whose acronym follows from its authors’ names. The rationale of the BFGS update stems once again from a variational viewpoint. We wish to build a simple quadratic model of the objective ht(w)=L(wt)+⟨∇L(wt),w−wt⟩+21⟨w−wt,Qt(w−wt)⟩ for some Qt built along the iterations rather than taken as ∇2L(wt). One desirable property of such a quadratic model would be that its gradients at consecutive iterates match the gradients of the original function, i.e., ∇ht(wt)=∇L(wt) and ∇ht(wt−1)=∇L(wt−1). A simpler condition, called the secant condition consists in considering the differences of these vectors, that is, ensuring that ⟺⟺∇ht(wt)−∇ht(wt−1)=∇L(wt)−∇L(wt−1)Qt(wt−wt−1)=∇L(wt)−∇L(wt−1)wt−wt−1=Bt(∇L(wt)−∇L(wt−1)), for Bt=(Qt)−1. Building Bt, a surrogate of the inverse of the Hessian satisfying the secant equation, can then be done as Bt+1:=(I−ρtst(yt)⊤)Bt(I−ρtst(yt)⊤)+ρtst(st)⊤ where stytρt:=wt+1−wt:=∇L(wt+1)−∇L(wt):=⟨st,yt⟩1. A typical implementation of BFGS stores Bt∈RP×P in memory, which is prohibitive when P is large.
17.4.2 Limited-memory BFGS
In practice, the limited-memory counterpart of BFGS, called LBFGS (Liu and Nocedal, 1989), is often preferred. The key observation of LBFGS is that we do not need to materialize Bt in memory: we only need to multiply it with the gradient ∇L(wt). That is, we can see Bt as a linear map. Fortunately, the product between Bt and any vector v can be computed efficiently if we store (s1,y1,ρ1),…,(st,yt,ρt) in memory. In practice, a small history of past values is used to reduce memory and computational cost. Because LBFGS has the benefits of second-order-like methods with much reduced cost, it has become a de-facto algorithm, outperforming most other algorithms for medium-scale problems without particular structure (Liu and Nocedal, 1989).
17.5 Approximate Hessian diagonal inverse preconditioners
One application of the approximations of the Hessian diagonal developed in Section 9.7 is to obtain cheap approximations of the Hessian diagonal inverse, Bt:=diag(∣H11t∣−1,…,∣HPPt∣−1). Such a scaling would for instance be sufficient to make the quadratic example presented in Fig. 17.1 work. Many optimization algorithms, including the popular ADAM, can be viewed as using a preconditioner that approximates the inverse of the Hessian’s diagonal.
17.6 Summary
We reviewed Newton’s method, the Gauss-Newton method, natural gradient descent, quasi-Newton methods and preconditioning methods.
We adopted a variational viewpoint, where the method’s next iterate is computed as the solution of a trade-off between minimizing an approximation of the function (linear, partially linear, quadratic) and a proximity term (squared Euclidean, KL).
All methods were shown to use iterates of the form wt+1:=wt−γtBt∇L(wt) but have different trade-offs between the cost it takes to evaluate Bt∇L(wt) and the richness of the information used about L.