Analyzing Finite Neural Networks: Can We Trust Neural Tangent Kernel Theory?
Mariia Seleznova, Gitta Kutyniok
Introduction
Deep neural networks (DNNs) have gained a lot of popularity in the last decades due to their success in a variety of domains, such as image classification (Krizhevsky et al., 2012), speech recognition (Hannun et al., 2014), playing games (Mnih et al., 2013), etc. Consequently, there has been a tremendous interest in the theoretical properties of DNNs: expressivity (Montufar et al., 2014), optimization (Goodfellow et al., 2014) and generalization (Hardt et al., 2016). However, many aspects of DNNs, in particular their surprising generalization properties, still remain unclear to the community (Zhang et al., 2016).
To study theoretical properties of DNNs, numerous recent papers have considered them in the infinite-width limit. In particular, there is a line of research which shows that untrained fully-connected networks of depth and widths with weights and biases initialized randomly as
behave as Gaussian processes (GP) in the infinite-width limit (for any ) (Lee et al., 2017; Matthews et al., 2018; Novak et al., 2018). These GPs are then fully described by a so-called Neural Network Gaussian Process (NNGP) kernel, and a number of publications have studied properties of this kernel depending on the network’s depth and initialization hyperparameters (Poole et al., 2016; Schoenholz et al., 2016). These works developed a mean field theory formalism for NNs and identified that there exist two situations – depending on hyperparameters – in which signal propagation through the network differs substantially: ordered and chaotic phases, which correspond to vanishing and exploding gradients. However, these results only concern untrained randomly initialized networks.
There have also been recent successes in the theory of trained infinitely wide DNNs. In particular, it has been shown that the evolution of NN’s output during gradient flow training can be captured by a so-called Neural Tangent Kernel (NTK) (Jacot et al., 2018; Arora et al., 2019; Yang, 2020):
where is the network’s output on at time and is the training set. In general, the NTK changes during training time and the dynamics in (2) is complex. However, as layers’ widths tend to infinity with fixed depth, it can be shown that the NTK stays constant during training and equal to its initial value:
Moreover, the NTK at initialization converges to a deterministic kernel in the same limit:
These two results allow to dramatically simplify the analysis of DNNs behavior, as the dynamics in (2) becomes identical to kernel regression and the ODE has a closed-formed solution.
However, some recent papers argue that the success of DNNs cannot be explained by their behavior in the infinite-width limit (Chizat et al., 2019; Hanin and Nica, 2019). One justification for this view is that no feature learning occurs when (3) and (4) hold, as the NTK stays constant during training and depends only on the parameters at initialization. Moreover, the NTK becomes completely data-independent in the infinite-depth limit, which suggests poor generalization performance (Xiao et al., 2019). That is why, to study properties of real DNNs, it is important to understand when and if NTK theory can be applied to finite-width NNs.
Our aim in this work is to understand when the inferences of NTK theory (3) and (4) hold for real NNs depending on hyperparameters and what this implies for the existing theoretical results about DNNs based on NTK theory. The contributions of our work are as follows:
NTK variance at initialization. We study empirically when the NTK is approximately deterministic at initialization for finite-width fully-connected ReLU and tanh networks with different hyperparameters . Our results suggest that, depending on the initialization hyperparameters (, there is a phase in the hyperparameter space where the NTK is close to deterministic for any depth , so (4) holds. However, there is also a phase where the NTK variance grows with , so (4) does not hold for deep networks. Following the terminology from Poole et al. (2016), we will call these phases ordered and chaotic, respectively.
NTK change during training. We also empirically study changes in the NTK matrix during gradient descent training for ReLU and tanh networks. Our results show that, in the ordered phase, the relative change in the NTK matrix norm caused by training is small and does not increase with , so (3) holds. However, in the chaotic phase the NTK matrix change during training is large and grows with depth . This implies that (3) does not hold, i.e. DNNs initialized in the chaotic phase do not behave as NTK theory suggests.
NTK theory approach for generalization. Some recent publications analyze properties of the NTK and draw conclusions about DNNs’ generalization thereof (Xiao et al., 2019; Geiger et al., 2020). Other authors argue that the behavior of networks in the NTK regime is trivial and does not yield good generalization properties, that are however observed for DNNs in practice (Chizat et al., 2019). We show how to compute data-independent variance of the network’s output when it evolves according to NTK theory. However, given our empirical results for when NTK theory is applicable, we discover that these findings do not explain the behavior of finite-width networks in most of the hyperparameters space .
2 Related work
This work adds to the line of research that studies the correspondence between finite- and infinite-width DNNs. In particular, the difference between theoretical (infinite-width) and empirical (finite-width) NTK. In this section, we survey the prior results in this direction and position our contribution within them.
A number of papers have studied the convergence of the empirical NTK at initialization to the theoretical NTK. The first fundamental result of NTK theory is that the NTK converges to a deterministic limit as goes to infinity (Jacot et al., 2018). The following work proved a non-asymptotic bound on minimal required to guarantee this convergence in case of ReLU networks (Arora et al., 2019). This bound on depends on the depth as , therefore is always small for deep networks when the bound holds. Then, a recent theoretical work improved this result in a special case of ReLU networks with initialization () by showing the precise exponential dependence of the NTK variance at initialization on (Hanin and Nica, 2019). That is, (4) does not hold for such networks when is bounded away from zero. However, the proofs given in the paper are not immediately generalizable for different activation functions and different initialization parameters. Thus, there is still no solid understanding of the NTK randomness depending on the choice of a network. Therefore, in Section 3, we empirically study the randomness of the NTK at initialization for ReLU and tanh networks with a variety of hyperparameters () and observe the precise dependence on 1) the position of initialization () in either ordered or chaotic phase, 2) depth-to-width ratio in the chaotic phase.
Changes of the NTK matrix during gradient descent training have also been analyzed in the literature mostly as a function of . In particular, it has been proven (Huang and Yau, 2020) and shown experimentally (Lee et al., 2019) that the change of the NTK matrix during gradient descent training is bounded by when the depth is fixed. For ReLU networks with initialization () it has also been proven that the change of the NTK in a gradient descent step depends exponentially on (Hanin and Nica, 2019). We add to these results in Section 4 by investigating the NTK changes during training for two activation functions and hyperparameters .
A different line of research has also studied the theoretical (infinite-width) NTK as a function of depth and initialization parameters (Xiao et al., 2019; Hayou et al., 2019). These contributions found that the spectrum of infinite-width NTK behaves differently in ordered and chaotic phases. The authors also showed that the infinite-depth limit of the theoretical NTK (when first the limit is taken with fixed and then ) yields trivial performance and cannot explain properties of finite DNNs. These papers showed that both in ordered and chaotic phases the NTK approaches its trivial limit exponentially in , and only in the border between phases (EOC) this convergence is sub-exponential. However, the setting of these contributions requires values to be small, therefore they do not explain how the randomness of NTK and its changes during training impact the results. Our work shows that in the chaotic phase and at the EOC the NTK does not behave as its theoretical limit when is bounded away from zero, therefore we cannot draw conclusions about such DNNs based on the theoretical NTK.
In generalization research, the recent trend is double descent – the phenomenon that highly overparametrized models, including DNNs, tend to generalize surprisingly well (Belkin et al., 2018; Nakkiran et al., 2019; Belkin et al., 2019; Hastie et al., 2019). The recent developments in the theory of double descent showed that overparametrized linear models reach low generalization error because, counterintuitively, their variance decreases when the number of parameters increases beyond the number of samples (Hastie et al., 2019). However, there is still no double descent theory for DNNs, which are significantly more theoretically complex than linear models. In Section 5, we studied the variance of DNNs’ output with the simplifications of NTK theory, which can be seen as the first step into this direction.
Mean field approach for wide neural networks
A number of recent papers used the mean field formalism to study forward- and backpropagation of signal through randomly initialized DNNs (Poole et al., 2016; Schoenholz et al., 2016; Karakida et al., 2018; Yang and Schoenholz, 2017). We first describe this approach and show how ordered and chaotic phases, which correspond to vanishing and exploding gradients, arise from it.
Suppose there is a fully-connected feed-forward neural network initialized randomly as in (1) with hidden layers’ widths . Forward propagation through the network is given by
where is the activation function, are activations, are pre-activations in each layer , and is a dataset.
The gradients of the network are given by the backpropagation chain:
Note that for certain activation functions, e.g. ReLU and erf, the integrals in (5), (6), (7), (8) and (9) can be taken analytically. One can refer to Appendix E for these analytical expressions.
We can now introduce, following the notation from Poole et al. (2016) and Schoenholz et al. (2016), a quantity that controls the backpropagation of variance :
where we assumed that the network’s width is constant, i.e. . Then also controls the propagation of the gradients at initialization:
In particular, when the initialization parameters are such that in all the layers, the gradients vanish, and when the gradients explode. These two situations are referred to as ordered and chaotic phases correspondingly, and the border between these phases defined by is called edge of chaos (EOC) initialization. Several authors suggest that networks should be initialized near EOC to allow deeper signal propagation (Hayou et al., 2018; Schoenholz et al., 2016).
In the next two sections of the paper, we test empirically how different parameters of random initialization , as well as network’s architecture , impact the behavior of the empirical NTK . Our observation is that for finite-width networks chaotic and ordered phases give rise to very different behavior of the empirical NTK as compared to the theoretical NTK, which has not been considered in the community before to the best of our knowledge.
NTK variance at initialization
One can see the results of our experiments for fully-connected ReLU and tanh networks with constant width in Figure 1. We observe that when is small enough (ordered phase), the NTK variance is small and does not increase with depth , implying that (4) holds for any depth and NTK theory can be used to study NNs initialized in this way. However, for large (chaotic phase) the variance grows significantly with , hence for very deep networks in this phase (4) does not hold. At the EOC, the variance of the NTK is a fraction of its mean even for very deep networks, so NTK theory can approximate the average behavior of networks initialized near EOC, but the random effects may still be significant. One can also see that as grows, the vertical red region gets narrower, i.e. the transition becomes sharper. This is consistent with the fact that the theoretical border between vanishing and exploding gradients is sharp and computed in mean field theory (Section 2) by taking the limit . These results are similar for ReLU and tanh networks, taking into account that the theoretical boundary between phases — given by and indicated by the dashed line in the figures — is located at larger values for sigmoid networks. One also observes that the NTK variance is small for sufficiently shallow NNs with any value. Such shallow networks were mostly considered in recent empirical studies on behavior of wide NNs under gradient descent (Lee et al., 2019). It is thus important to note, that such empirical results may be invalid for much deeper networks, depending on the initialization parameters.
We also checked if the value of impacts the NTK variance behavior at initialization significantly. In Appendix D, we provide figures showing the NTK variance with different values. We observed that lower values yield narrower boundary between the two phases identified in Figure 1, but the general picture stays similar.
NTK change during training
In this section we present the numerical experiments that we conducted to check whether the second result of NTK theory (3) holds, i.e. whether the empirical NTK of finite-width ReLU and tanh networks stays approximately constant during training with gradient descent. We trained networks with a variety of hyperparameters and measured the relative change of NTK’s Frobenious norm that occurs during training. The results for tanh and ReLU networks are in Figures 3a and 4a. In Figures 3b and 4b, we also plotted the minimal losses that the networks reached in the experiments.
We draw the following conclusions from the experiments’ results:
Phase transition for empirical NTK. For both ReLU and tanh networks, the NTK behavior during training changes significantly around the theoretical border between chaotic and ordered phases.
Chaotic phase. In the chaotic phase, the relative change in the NTK matrix norm is significant and increases with depth , so one cannot assume that the kernel stays constant during training for deep networks. However, for very shallow networks the NTK at initialization may still be a good approximation for the NTK after training. In the previous section we also saw that the NTK matrix of shallow networks in the chaotic phase is close to deterministic at initialization, which shows that NTK theory approximates only shallow networks in the chaotic phase.
Ordered phase. In the ordered phase, the relative change in the NTK matrix norm is small throughout training for any depth. We saw in the previous section that the NTK is also close to deterministic at initialization in this phase. It follows that in the ordered phase finite-width DNNs behave as NTK theory suggests even when depth is large.
EOC. There is a region close to the border between phases where the change in the NTK norm is larger than in the ordered phase but still remains way below 1 for deep networks. We also saw in the previous section that in this region the standard deviation of the NTK is lower than its mean value for deep networks. Thus, NTK theory can approximate behavior of deeper networks in case of EOC initialization in comparison to the chaotic phase, but the effects of randomness and change during training may still play a significant role.
Trainability. Networks become untrainable with depth much faster in the ordered phase than in the chaotic phase. In our experiments, networks in the ordered phase with already mostly cannot reach low training loss values. This is consistent with the results on trainability provided in Xiao et al. (2019).
We thus have discovered two regions in the hyperparameters space where both statements of NTK theory (3) and (4) hold: the ordered phase with any depth and the chaotic phase where the ratio is low. For other choices of architecture and initialization, our experiments suggest that finite-width networks do not behave according to NTK theory.
Note that the networks in Figures 3a and 4a take different number of training steps to reach their final loss values. Somewhat counterintuitively, we observe that the networks which take more iterations to train show mostly small changes in the NTK matrix norm. To provide more insight about the NTK dynamics during different stages of training, we also include figures that show changes in the NTK matrix norm as a function of the number of training steps, as well as figures with changes of the NTK for different values, in Appendix D.
NTK theory approach for generalization
If the NTK stays constant during training (3), then the dynamics in (2) are identical to kernel regression with kernel . In such dynamics, the output function of a network that is trained until convergence () by gradient flow with MSE loss is given by:
where is the kernel matrix of all the pairs of inputs in , i.e. , and and . One can refer to Arora et al. (2019) or Lee et al. (2019) for the derivation of this equation. If the NTK is also deterministic at initialization (4), then the only variables in (10) that are random with respect to the network’s parameters at initialization are and , which greatly simplifies the analysis of the generalization properties of .
The variance of the output function of a randomly initialized network and the covariance of outputs on two different input vectors are given by:
Recall that the NTK is composed of gradients as and its expected values are therefore proportional to the variances of gradients, considered in Section 2. Then, assuming that the the NTK matrix at initialization is deterministic and equal to its expected value, we can express it through quantities by the following lemma.
For a fully-connected network with widths (where is the input dimension), deterministic the NTK matrix on a sample at initialization is given by:
where .
We give a proof for this lemma in Appendix A. We note that the same statement is also proven in Karakida et al. (2018) as a part of Theorem 3.
We can also notice that and depend only on the norm of input , so for normalized inputs they become data-independent. On the other hand, and depend on covariances of points in the dataset and therefore are data-dependent. However, it has also been observed in Poole et al. (2016) that both and converge to their data-independent limits with depth. Let us denote their data-independent means by and respectively. Then we can also write data-independent means and for the backpropagated errors, as well as and for the activations. This leads to data-independent and . We also notice that the changes in that come from the changes in covariance are small with respect to its mean value for ReLU and erf networksWe expect tanh-networks that we studied empirically in other sections to behave similar to erf-networks.. Note that for these two activation functions, we can take the integrals in (5), (7), (8) and (9) analytically (see Appendix E) and calculate for different values of the inputs’ covariance, which is shown in Figure 5 for ordered and chaotic phases and at the border between them. Therefore, we can write the NTK as a sum of its data-independent part and a data-dependent perturbation:
We note that this result about the structure of the NTK is consistent with the analysis of Xiao et al. (2019), where the authors study the NTK at large depths.
From the structure of , one can see that its condition number depends on the ratio : when its value is high, the NTK matrix is well-conditioned, and when the ratio approaches 1 the matrix becomes close to degenerate. Figure 6 shows ratio as a function of depth for erf and ReLU networks in ordered and chaotic phases and at the border between them. One can see from the graphs that the NTK matrix is well-conditioned in the chaotic phase and ill-conditioned in the ordered phase. Ill-conditioned NTK also implies that the maximum learning rate which allows to train the network is small (Xiao et al., 2019; Karakida et al., 2018). Therefore networks in the ordered phase rapidly become untrainable with depth, which is consistent with our observations in Section 4.
The following theorem characterizes the dependence of the variance of the output function on the data-independent part of the NTK.
Suppose a network evolves according to NTK theory under gradient flow and is fully trained () on a dataset of size . Suppose also that the NTK matrix is well-conditioned. Then the variance of its output is characterized by:
where .
We give a proof for this result in the Appendix B. In the next paragraphs, we analyze the behavior of the given variance expression and the applicability of the theorem in different situations:
Ordered phase. One can notice that in the ordered phase converges to rapidly with depth, as . This implies , i.e. the variance is small and decreases with depth. However, the NTK is also ill-conditioned, therefore small data-dependent changes can cause significant changes in the output function. Thus, the data-independent estimate for variance given by NTK theory does not explain the behavior of DNNs in the ordered phase and it is important to take into account data-dependent effects.
Chaotic phase. In the chaotic phase, the NTK is well-conditioned for any depth. However, only networks with depth to width ratio behave as NTK theory suggests under gradient flow in the chaotic phase according to our experiments. As we saw in the previous sections, the NTK changes significantly during training and is random at initialization for deep networks, therefore the expression for the output function after training (10) does not hold. The ratio increases with depth in the chaotic phase, so decreases, and is much larger than (Poole et al., 2016). Therefore the data-independent variance is high and proportional to the variance of outputs of a randomly initialized network. This is consistent with observations in Chizat et al. (2019) and Xiao et al. (2019). Thus, NTK theory can explain poor generalization, which shallow wide networks in the chaotic phase display. However, deeper networks may have very different behavior due to randomness at initialization and changes during gradient descent training, so they require more investigation.
EOC. At EOC, the conditioning of the NTK at as a function of depth is similar to the chaotic phase: grows with depth, hence the kernel is well-conditioned. However, at EOC is smaller than in the chaotic phase (Poole et al., 2016). This implies that networks initialized close to EOC generalize better than networks in the chaotic phase and at the same time remain trainable at large depths. We observed in the previous sections that at the border between phases NTK theory gives an approximation of network’s average behavior even for deep networks, but the finite-width effects can still be significant and should be considered.
Conclusions and future work
In this work, we have shown that NTK theory does not generally describe the training dynamics of finite-width DNNs accurately. Only relatively shallow networks and deep networks in the ordered phase, i.e. initialized with small , behave as NTK theory suggests under gradient descent. The analysis of the data-independent variance of the output function based on NTK theory shows that it is proportional to the output variance at initialization in the chaotic phase and at EOC. This result is not surprising, in a sense that it does not explain how training effects NNs’ performance. It would provide more insight into networks’ behavior if we could understand the data-dependent changes in the NTK that are significant for deep networks at EOC and shallow networks in the chaotic phase and study how these changes impact the output function. To study deep networks in the chaotic phase and at EOC, it is also essential to account for randomness in the NTK matrix at initialization and its changes during training, which cannot be done within NTK theory. Thus, an entirely new conceptual viewpoint is required to provide a full theoretical analysis of DNNs behavior under gradient descent.
References
Appendix A Lemma 5.2
By definition, each component of the NTK matrix is a scalar product of network’s gradient vectors:
In Section 2 we show for the network’s gradients that
Thus, we get the following expression for non-diagonal elements of the NTK:
Similarly, we get the expression for diagonal elements of the NTK matrix:
Appendix B Theorem 5.3
Recall the formula of the output function after training:
As initialization of the network’s parameters is centered Gaussian, the expectation of the output at initialization is equal to zero:
Then if the NTK is deterministic at initialization we can write the expectation as follows:
because neither nor are random with respect to the initialization parameters.
To obtain the variance of output, we also need to write the expected values of all the terms of squared . First, by Lemma 5.1:
is the NNGP matrix, which characterizes the Gaussian process of a randomly initialized network. Finally:
where . The other terms are equal to zero. Moreover, we can see that terms of variance with cancel each other.
Taking expectation of the above expressions over a random dataset , which is independent to random initialization , we get
Denoting , we can rewrite the above expression as
Appendix C Effects of biases initialization on the NTK variance at initialization
Figure 7 shows the dependence of the NTK variance at initialization on . One can see that lower values yield narrower boundary between the two phases, but the general picture stays similar to the one in Figure 1.
Appendix D Additional experiments on the NTK change during training
Here we provide additional figures on changes of the NTK during gradient descent training.
Figures 8 and 9 show changes in the NTK matrix norm as a function of the number of training steps for tanh and ReLU networks, respectively. One can see how the NTK changes after and training steps. The findings from these figures are similar to the analysis we provided in Section 4: the NTK behaviour changes significantly around the border between ordered and chaotic phases. One can also see that for deep networks in the chaotic phase the NTK changes significantly already in the early stages of training, while networks in the ordered phase display very low changes in the NTK norm for a long time.
Figures 10 and 11 show the effects of the network width on the changes of the NTK matrix during training. We provide experiments for . One can see that, as expected in NTK theory, higher values overall result in smaller changes of the NTK. However, with all the width values, one can see the transition from ordered to chaotic phase, which gets more pronounced with the network’s depth.
Appendix E Analytical relations for integrals in Section 2
Then to obtain analytical expressions for and we can take the following integrals, which appear in (5) and (8):
Similarly, to get analytical expressions for and , we can take the integrals in (7) and (9):
where , to obtain the following expressions:
Then, to compute the values of and in all the layers, we only need to set the following initial conditions: when data is normalized, is the covariance between two inputs, as the output depends linearly on the activations in the last layer.
E.2 Erf networks
Error function, which is a kind of sigmoid functions, is defined by
Then, same as for ReLU activation, we analytically take the integrals from (5) and (8):
to obtain expressions for and :
And similarly we take the integrals in (7) and (9):
to obtain the analytical expressions for and :
And the initial conditions can be specified in the same way as for the ReLU networks in the previous subsection.