The asymptotic spectrum of the Hessian of DNN throughout training
Arthur Jacot, Franck Gabriel, Clément Hongler
Introduction
The advent of deep learning has sparked a lot of interest in the loss surface of deep neural networks (DNN), and in particular its Hessian. However to our knowledge, there is still no theoretical description of the spectrum of the Hessian. Nevertheless a number of phenomena have been observed numerically.
The loss surface of neural networks has been compared to the energy landscape of different physical models (Choromanska et al., 2015; Geiger et al., 2018; Mei et al., 2018). It appears that the loss surface of DNNs may change significantly depending on the width of the network (the number of neurons in the hidden layer), motivating the distinction between the under- and over-parametrized regimes (Baity-Jesi et al., 2018; Geiger et al., 2018; 2019).
The non-convexity of the loss function implies the existence of a very large number of saddle points, which could slow down training. In particular, in (Pascanu et al., 2014; Dauphin et al., 2014), a relation between the rank of saddle points (the number of negative eigenvalues of the Hessian) and their loss has been observed.
For overparametrized DNNs, a possibly more important phenomenon is the large number of flat directions (Baity-Jesi et al., 2018). The existence of these flat minima is conjectured to be related to the generalization of DNNs and may depend on the training procedure (Hochreiter & Schmidhuber, 1997; Chaudhari et al., 2016; Wu et al., 2017).
In (Jacot et al., 2018) it has been shown, using a functional approach, that in the infinite-width limit, DNNs behave like kernel methods with respect to the so-called Neural Tangent Kernel, which is determined by the architecture of the network. This leads to convergence guarantees for DNNs (Jacot et al., 2018; Du et al., 2019; Allen-Zhu et al., 2018; Huang & Yau, 2019) and strengthens the connections between neural networks and kernel methods (Neal, 1996; Cho & Saul, 2009; Lee et al., 2018).
Our approach also allows one to probe the so-called mean-field/active limit (studied in (Rotskoff & Vanden-Eijnden, 2018; Chizat & Bach, 2018a; Mei et al., 2018) for shallow networks), where the NTK varies during training.
This raises the question: can we use these new results to gain insight into the behavior of the Hessian of the loss of DNNs, at least in the small region explored by the parameters during training?
The first matrix is positive semi-definite and its eigenvalues are given by the (weighted) kernel PCA of the dataset with respect to the NTK. The dominating eigenvalues are the principal components of the data followed by a high number of small eigenvalues. The “flat directions” are spanned by the small eigenvalues and the null-space (of dimension at least when there is a single output). Because the NTK is asymptotically constant (Jacot et al., 2018), these results apply at initialization, during training and at convergence.
Regarding the sum , we show that the matrices and are asymptotically orthogonal to each other at initialization and during training. In particular, the moments of the matrices and add up: .
These results give, for any depth and a fairly general non-linearity, a complete description of the spectrum of the Hessian in terms of the NTK at initialization and throughout training. Our theoretical results are consistent with a number of observations about the Hessian (Hochreiter & Schmidhuber, 1997; Pascanu et al., 2014; Dauphin et al., 2014; Chaudhari et al., 2016; Wu et al., 2017; Pennington & Bahri, 2017; Geiger et al., 2018), and sheds a new light on them.
2 Related works
The Hessian of the loss has been studied through the decomposition in a number of previous works (Sagun et al., 2017; Pennington & Bahri, 2017; Geiger et al., 2018).
For least-squares and cross-entropy costs, the first matrix is equal to the Fisher matrix (Wagenaar, 1998; Pascanu & Bengio, 2013), whose moments have been described for shallow networks in (Pennington & Worah, 2018). For deep networks, the first two moments and the operator norm of the Fisher matrix for a least squares loss were computed at initialization in (Karakida et al., 2018) conditionally on a certain independence assumption; our method does not require such assumptions. Note that their approach implicitly uses the NTK.
The second matrix has been studied in (Pennington & Bahri, 2017; Geiger et al., 2018) for shallow networks, conditionally on a number of assumptions. Note that in the setting of (Pennington & Bahri, 2017), the matrices and are assumed to be freely independent, which allows them to study the spectrum of the Hessian; in our setting, we show that the two matrices and are asymptotically orthogonal to each other.
Setup
The parameter is added to tune the influence of the bias on trainingIn our experiments, we take .. All parameters are initialized as iid Gaussians.
We will in particular study the network function, which maps inputs to the activation of the output layer (before the last non-linearity):
In this paper, we will study the limit of various objects as sequentially, i.e. we first take then , etc. This greatly simplifies the proofs, but they could in principle be extended to the simultaneous limit, i.e. when . All our numerical experiments are done with ‘rectangular’ networks (with ) and match closely the predictions for the sequential limit.
In the limit we study in this paper, the NTK is asymptotically fixed, as in (Jacot et al., 2018; Allen-Zhu et al., 2018; Du et al., 2019; Arora et al., 2019; Huang & Yau, 2019). By rescaling the outputs of DNNs as the width increases, one can reach another limit where the NTK is not fixed (Chizat & Bach, 2018a; b; Rotskoff & Vanden-Eijnden, 2018; Mei et al., 2019). Some of our results can be extended to this setting, but only at initialization (see Section 3.3). The behavior during training becomes however much more complex.
The network is trained with respect to the cost functional:
For our analysis, we require that the gradient norm does not explode during training. The following condition is sufficient:
2 Neural Tangent Kernel
The behavior during training of the network function in the function space is described by a (multi-dimensional) kernel, the Neural Tangent Kernel (NTK)
During training, the function follows the so-called kernel gradient descent with respect to the NTK, which is defined as
In the infinite-width limit (letting sequentially) and for losses with BGOSS, the NTK converges to a deterministic limit , which is constant during training, uniformly on finite time intervals (Jacot et al., 2018). For the MSE loss, the uniform convergence of the NTK was proven for in (Arora et al., 2019).
The NTK leads to convergence guarantees for DNNs in the infinite-width limit, and connect their generalization to that of kernel methods (Jacot et al., 2018; Arora et al., 2019).
3 Gram Matrices
It is block diagonal because different outputs are asymptotically uncorrelated.
Main Theorems
𝐼𝑆I+S Using the above setup, the Hessian of the loss is the sum of two terms, with the entry given by
For a finite dataset, the Hessian matrix is equal to the sum of two matrices
where is a matrix, is a matrix and is a tensor to which we apply a scalar product (denoted by ) in its last dimension with the vector to obtain a matrix.
The moments of and can be studied separately because the moments of their sum is asymptotically equal to the sum of their moments by Proposition 5 below. The limiting moments of and are respectively described by Propositions 1 and 4 below. ∎
In the case of a MSE loss , the first and second derivatives take simple forms and and the differential equations can be solved to obtain more explicit formulae:
The moments of are constant because is constant. For the moments of , we first solve the differential equation for :
The expectation of the first moment of then follows. ∎
2 Mutual Orthogonality of I𝐼I and S𝑆S
A first key ingredient to prove Theorem 1 is the asymptotic mutual orthogonality of the matrices and
Note that both matrices and have large nullspaces: indeed assuming a constant width , we have and (see Appendix C), while the number of parameters scales as (when ).
Figure 3 illustrates the mutual orthogonality of and . All numerical experiments are done for rectangular networks (when the width of the hidden layers are equal) and agree well with our predictions obtained in the sequential limit.
3 Mean-field Limit
For a rectangular network with width , if the output of the network is divided by and the learning rate is multiplied by (to keep similar dynamics at initialization), the training dynamics changes and the NTK varies during training when goes to infinity. The new parametrization of the output changes the scaling of the two matrices:
The scaling of the learning rate essentially multiplies the whole Hessian by . In this setting, the matrix is left unchanged while the matrix is multiplied by (the -th moment of is hence multiplied by ). In particular, the two moments of the Hessian are dominated by the moments of , and the higher moments of (and the operator norm of ) should not vanish. This suggests that the active regime may be characterised by the fact that . Under the conjecture that Theorem 1 holds for the infinite-width limit of rectangular networks, the asymptotic of the two first moments of is given by:
where for the MSE loss we have .
4 The matrix S𝑆S
The matrix is best understood as a perturbation to , which vanishes as the network converges because . To calculate its moments, we note that
The following proposition desribes the limit of the function and the kernel and the vanishing of the higher moments:
- At initialization, and converge to a (centered) Gaussian pair with covariances
and during training evolves according to
- Uniformly over any interval , the kernel has a deterministic and fixed limit with limiting kernel:
This result has a number of consequences for infinitely wide networks:
When it comes to the first moment of , Proposition 4 shows that the spectrum of is in general not symmetric. For the MSE loss the expectation of the first moment at initialization is
These observations suggest that has little influence on the shape of the surface, especially towards the end of training, the matrix however has an interesting structure.
5 The matrix I𝐼I
At a global minimizer , the spectrum of describes how the loss behaves around . Along the eigenvectors of the biggest eigenvalues of , the loss increases rapidely, while small eigenvalues correspond to flat directions. Numerically, it has been observed that the matrix features a few dominating eigenvalues and a bulk of small eigenvalues (Sagun et al., 2016; 2017; Gur-Ari et al., 2018; Papyan, 2019). This leads to a narrow valley structure of the loss around a minimum: the biggest eigenvalues are the ‘cliffs’ of the valley, i.e. the directions along which the loss grows fastest, while the small eigenvalues form the ‘flat directions’or the bottom of the valley.
Note that the rank of is bounded by and in the overparametrized regime, when , the matrix will have a large nullspace, these are directions along which the value of the function on the training set does not change. Note that in the overparametrized regime, global minima are not isolated: they lie in a manifold of dimension at least and the nullspace of is tangent to this solution manifold.
The matrix is closely related to the NTK Gram matrix:
As a result, the limiting spectrum of the matrix can be directly obtained from the NTKThis result was already obtained in (Karakida et al., 2018), but without identifying the NTK explicitely and only at initialization.
The eigenvectors of the NTK Gram matrix are the kernel principal components of the data. The biggest principal components are the directions in function space which are most favorised by the NTK. This gives a functional interpretation of the narrow valley structure in DNNs: the cliffs of the valley are the biggest principal components, while the flat directions are the smallest components.
As the depth of the network increases, one can observe two regimes (Poole et al., 2016; Jacot et al., 2019): Order/Freeze where the NTK converges to a constant and Chaos where the NTK converges to a Kronecker delta. In the Order/Freeze the Gram matrix approaches a block diagonal matrix with constant blocks, and as a result eigenvalues of dominate the other ones, corresponding to constant directions along each outputs (this is in line with the observations of (Papyan, 2019)). This leads to a narrow valley for the loss and slows down training. In contrast, in the Chaos regime, the NTK Gram matrix approaches a scaled identity matrix, and the spectrum of should hence concentrate around a positive value, hence speeding up training. Figure 3 illustrates this phenomenon: with the smooth ReLU we observe a narrow valley, while with the normalized smooth ReLU (which lies in the Chaos according to (Jacot et al., 2019)) the narrowness of the loss is reduced. A similar phenomenon may explain why normalization helps smoothing the loss surface and speed up training (Santurkar et al., 2018; Ghorbani et al., 2019).
5.2 Cross-Entropy Loss
For a binary cross-entropy loss with labels
is a diagonal matrix whose entries depend on (but not on ):
The eigenvectors of then correspond to the weighted kernel principal component of the data. The positive weights approach as goes to , i.e. when it is close to the decision boundary from one class to the other, and as the weight go to zero. The weights evolve in time through , the spectrum of is therefore not asymptotically fixed as in the MSE case, but the functional interpretation of the spectrum in terms of the kernel principal components remains.
Conclusion
We have given an explicit formula for the limiting moments of the Hessian of DNNs throughout training. We have used the common decomposition of the Hessian in two terms and and have shown that the two terms are asymptotically mutually orthogonal, such that they can be studied separately.
The matrix vanishes in Frobenius norm as the network converges and has vanishing operator norm throughout training. The matrix is arguably the most important as it describes the narrow valley structure of the loss around a global minimum. The eigendecomposition of is related to the (weighted) kernel principal components of the data w.r.t. the NTK.
Acknowledgements
Clément Hongler acknowledges support from the ERC SG CONSTAMIS grant, the NCCR SwissMAP grant, the NSF DMS-1106588 grant, the Minerva Foundation, the Blavatnik Family Foundation, and the Latsis foundation.
References
Appendix A Proofs
Under the condition that is stochastically bounded as the width of the network goes to infinity, the NTK converges to its fixed limit uniformly over .
When a network is trained with gradient descent on a loss with BGOSS, the integral is stochastically bounded. Because the loss is decreasing during training, the outputs lie in the sublevel set for all times . The norm of the gradient is hence bounded for all times . Because the distribution of converges to a multivariate Gaussian, is stochastically bounded as the width grows, where is a bound on the norm of the gradient on . We then have the bound which is itself stochastically bounded.
For the binary and softmax cross-entropy losses the gradient is uniformly bounded:
The binary cross-entropy loss with labels is
which is bounded in absolute value by for both such that .
The softmax cross-entropy loss over classes with labels is defined by
The gradient is at an input and output class is
which is bounded in absolute value by such that . ∎
Appendix B Preliminaries
To study the moments of the matrix , we first have to show that two tensors vanish as :
for parameters which belong to the lower layers the derivatives can be defined recursively by
Using these recursive definitions, the tensors and are given in terms of , and , in the same manner that the NTK is defined recursively in terms of in (Jacot et al., 2018).
The proof is done by induction. When the second derivatives and .
The proof is done by induction. When the hessian , such that .
Appendix C The Matrix S𝑆S
We now have the theoretical tools to describe the moments of the matrix . We first give a bound for the rank of :
We first observe that is given by a sum of matrices:
It is therefore sufficiant to show that the rank of each matrices is bounded by .
and the matrix is equal to the Jacobian of this map. By the chain rule, is the matrix multiplication of the Jacobians of the two submaps, whose rank are bounded by , hence bounding the rank of . And because is a sum of matrices of rank smaller than , the rank of is bounded by . ∎
- At initialization, and converge to a (centered) Gaussian pair with covariances
and during training evolves according to
- Uniformly over any interval where is stochastically bounded, the kernel has a deterministic and fixed limit with limiting kernel:
where is the restriction to the training set of the function . This process is random at initialization and varies during training. Lemma 3 below shows that, in the infinite width limit, it is a Gaussian process at initialization which then evolves according to a simple differential equation, hence describing the evolution of the first moment during training.
which vanishes in the infinite width limit by Lemma 5 below. ∎
and during training evolves according to
When , is for any and .
For the inductive step, the trace is defined recursively as
with and
where is a Gaussian quadruple of covariance
During training, the parameters follow the gradient . By the induction hypothesis, the traces then evolve according to the differential equation
As , the kernels and converge to their limit and vanishes:
By the law of large numbers, as , at initialization where
The next lemma describes the asymptotic limit of the kernel :
The proof is by induction on the depth . The case is trivially true because for all . For the induction step we observe that
if we now let the width of the lower layers grow to infinity , the tensor vanishes and and the NTK converge to limits which are non-zero only when . As a result, the term above converges to
At initialization, we can apply the law of large numbers as such that it converges to , for the kernel defined recursively by
and .
Finally, the next lemma shows the vanishing of the tensor to prove that the higher moments of vanish.
When the Hessian is zero and .
For the induction step, we write recursively, because it contains many terms, we change the notation, writing \left[\begin{array}[]{cc}x_{0}&x_{1}\\ m_{0}&m_{1}\end{array}\right] for , \left[\begin{array}[]{ccc}x_{0}&x_{1}&x_{2}\\ m_{0}&m_{1}&m_{2}\end{array}\right] for and \left[\begin{array}[]{cccc}x_{0}&x_{1}&x_{2}&x_{3}\\ m_{0}&m_{1}&m_{2}&m_{3}\end{array}\right] for . The value is then equal to
Even though this is a very large formula one can notice that most terms are “rotation of each other”. Moreover, as , all terms containing either an , an or a vanish. For the remaining terms, we may replace the NTKs by their limit and as a result converges to
And all these sums vanish as thanks to the prefactor , proving the vanishing of in the infinite width limit.
Appendix D Orthogonality of I𝐼I and S𝑆S
From Lemma 2 and the vanishing of the tensor as proven in Lemma 2, we can easily prove the orthogonality of and of Proposition 5:
and vanishes as by Lemma 2.
which vanishes in the infinite width limit because and are bounded and vanishes. ∎