The Surprising Simplicity of the Early-Time Learning Dynamics of Neural Networks
Wei Hu, Lechao Xiao, Ben Adlam, Jeffrey Pennington
Introduction
Modern deep learning models are enormously complex function approximators, with many state-of-the-art architectures employing millions or even billions of trainable parameters (Radford et al., 2019; Adiwardana et al., 2020). While the raw parameter count provides only a crude approximation of a model’s capacity, more sophisticated metrics such as those based on PAC-Bayes (McAllester, 1999; Dziugaite and Roy, 2017; Neyshabur et al., 2017b), VC dimension (Vapnik and Chervonenkis, 1971), and parameter norms (Bartlett et al., 2017; Neyshabur et al., 2017a) also suggest that modern architectures have very large capacity. Moreover, from the empirical perspective, practical models are flexible enough to perfectly fit the training data, even if the labels are pure noise (Zhang et al., 2017). Surprisingly, these same high-capacity models generalize well when trained on real data, even without any explicit control of capacity.
These observations are in conflict with classical generalization theory, which contends that models of intermediate complexity should generalize best, striking a balance between the bias and the variance of their predictive functions. To reconcile theory with observation, it has been suggested that deep neural networks may enjoy some form of implicit regularization induced by gradient-based training algorithms that biases the trained models towards simpler functions. However, the exact notion of simplicity and the mechanism by which it might be achieved remain poorly understood except in certain simplistic settings.
One concrete mechanism by which such induced simplicity can emerge is the hypothesis that neural networks learn simple functions early in training, and increasingly build up their complexity in later time. In particular, recent empirical work Nakkiran et al. (2019) found that, intriguingly, in some natural settings the simple function being learned in the early phase may just be a linear function of the data.
Key to our technical analysis is a bound on the spectral norm of the difference between the Neural Tangent Kernel (NTK) (Jacot et al., 2018) of the neural network at initialization and that of the linear model; indeed, a weaker result, like a bound on the Frobenius norm, would be insufficient to establish our result. Although the NTK is usually associated with the study of ultra-wide networks, our result only has a mild requirement on the width and allows the network to leave the kernel regime later in training. While our formal result focuses on two-layer fully-connected networks and data with benign concentration properties (specified in Assumption 3.1), we argue with theory and provide empirical evidence that the same linear learning phenomenon persists for more complex architectures and real-world datasets.
The early phase of neural network training has been the focus of considerable recent research. Frankle and Carbin (2019) found that sparse, trainable subnetworks – “lottery tickets" – emerge early in training. Achille et al. (2017) showed the importance of early learning from the perspective of creating strong connections that are robust to corruption. Gur-Ari et al. (2018) observed that after a short period of training, subsequent gradient updates span a low-dimensional subspace. Li et al. (2019a); Lewkowycz et al. (2020) showed that an initial large learning rate can benefit late-time generalization performance.
Implicit regularization of (stochastic) gradient descent has also been studied in various settings, suggesting a bias towards large-margin, low-norm, or low-rank solutions (Gunasekar et al., 2017, 2018; Soudry et al., 2018; Li et al., 2018; Ji and Telgarsky, 2019a, b; Arora et al., 2019a; Lyu and Li, 2019; Chizat and Bach, 2020; Razin and Cohen, 2020). These results mostly aim to characterize the final solutions at convergence, while our focus is on the early-time learning dynamics. Another line of work has identified that deep linear networks gradually increase the rank during training (Arora et al., 2019a; Saxe et al., 2014; Lampinen and Ganguli, 2018; Gidel et al., 2019).
A line of work adopted the Fourier perspective and demonstrated that low-frequency functions are often learned first (Rahaman et al., 2018; Xu, 2018; Xu et al., 2019a, b). Based on the NTK theory, Arora et al. (2019c) showed that for very wide networks, components lying in the top eigenspace of the NTK are learned faster than others. Using this principle, Su and Yang (2019); Cao et al. (2019) analyzed the spectrum of the infinite-width NTK. However, in order to obtain precise characterization of the spectrum these papers require special data distributions such as uniform distribution on the sphere.
Most relevant to our work is the finding of Nakkiran et al. (2019) that a neural network learned in the early phase of training can be almost fully explained by a linear function of the data. They supported this claim empirically by examining an information theoretic measure between the predictions of the neural network and the linear model. Our result formally proves that neural network and a corresponding linear model make similar predictions in early time, thus providing a theoretical explanation of their empirical finding.
In Section 2, we introduce notation and briefly recap the Neural Tangent Kernel. In Section 3, we present our main theoretical results on two-layer neural networks as well as empirical verification. In Section 4, we discuss extensions to more complicated architecture from both theoretical and empirical aspects. We conclude in Section 5, and defer additional experimental results and all the proofs to the appendices.
Preliminaries
We use the standard , and notation to only hide universal constant factors. For , we also use or to mean , and use or to mean for a sufficiently large universal constant . Throughout the paper, “high probability” means a large constant probability arbitrarily close to (such as ).
Consider a single-output neural network where is the input and is the collection of parameters in the network. Around a reference network with parameters , we can do a local first-order approximation:
Thus when is close to , for a given input the network can be viewed as linear in . This gradient feature map induces a kernel which is called the NTK at . Gradient descent training of the neural network can be viewed as kernel gradient descent on the function space with respect to the NTK. We use NTK matrix to refer to an matrix that is the NTK evaluated on datapoints.
While in general the NTK is random at initialization and can vary significantly during training, it was shown that, for a suitable network parameterization (known as the “NTK parameterization”), when the width goes to infinity or is sufficiently large, the NTK converges to a deterministic limit at initialization and barely changes during training (Jacot et al., 2018; Lee et al., 2019; Arora et al., 2019b; Yang, 2019), so that the neural network trained by gradient descent is equivalent to a kernel method with respect to a fixed kernel. However, for networks with practical widths, the NTK does usually stray far from its initialization.
Two-Layer Neural Networks
We consider a two-layer fully-connected neural network with hidden neurons defined as:
and run vanilla gradient descent (GD) on the objective (2) starting from random initialization. Specifically, we use the following symmetric initialization for the weights :
Let be a set of initial weights drawn from the symmetric initialization (3). Then the weights are updated according to GD:
where and are the learning rates. Here we allow potentially different learning rates for flexibility.
Now we state the assumption on the input distribution used in our theoretical results.
Note that a special case that satisfies Assumption 3.1 is the Gaussian distribution , but we allow a much larger class of distributions here. The subgaussian assumption is made due to the probabilistic tail bounds used in the analysis, and it can be replaced with a weaker bounded moment condition. The independence between ’s entries may also be dropped if its density is strongly log-concave. We choose to use Assumption 3.1 as the most convenient way to present our results.
We allow to be any of the commonly used activation functions, including ReLU, Leaky ReLU, Erf, Tanh, Sigmoid, Softplus, etc. Formally, our requirement on is the following:
The activation function satisfies either of the followings:
We will consider the regime where the data dimension is sufficiently large (i.e., larger than any constant) and the number of datapoints is at most some polynomial in (i.e., ). These imply for any constant .
Under Assumption 3.1, the datapoints satisfy the following concentration properties:
Suppose . Then under Assumption 3.1, with high probability we have \frac{\left\|{\bm{x}}_{i}\right\|^{2}}{d}=1\pm O\Big{(}\sqrt{\tfrac{\log n}{d}}\Big{)} (), \frac{|\langle{\bm{x}}_{i},{\bm{x}}_{j}\rangle|}{d}=O\Big{(}\sqrt{\tfrac{\log n}{d}}\Big{)} (), and .
The main result in this section is to formally prove that the neural network trained by GD is approximately a linear function in the early phase of training. As we will see, there are distinct contributions coming from the two layers. Therefore, it is helpful to divide the discussion into the cases of training the first layer only, the second layer only, and both layers together. All the omitted proofs in this section are given in Appendix D.
The width requirement in Theorem 3.2 is very mild as it only requires the width to be larger than for some small constant . Note that the width is allowed to be much smaller than the number of samples , which is usually the case in practice.
The agreement guaranteed in Theorem 3.2 is up to iteration (for some constant ). It turns out that for well-conditioned data, after iterations, a near optimal linear model will have been reached. This means that the neural network in the early phase approximates a linear model all the way until the linear model converges to the optimum. See Corollary 3.3 below.
2 Training the Second Layer
As usual, this linear model is trained with GD starting from zero:
Similar to Theorem 3.2, our main theorem for training the second layer is the following:
We remark that if the data distribution is well-conditioned, we can also have a guarantee similar to Corollary 3.3.
3 Training Both Layers
Finally we consider the case where both layers are trained, in which in (4). Since the NTK for training both layers is simply the sum of the first-layer NTK and the second-layer NTK, the corresponding linear model should have its kernel being the sum of the kernels for linear models (5) and (9), which can be derived easily:
where the constants are from (9). Note that .
Again, we can show that the neural network is close to the linear model (11) in early time. The guarantee is very similar to Theorems 3.2 and 3.5, so we defer the formal theorem to Appendix D; see Theorem D.1. Note that our result can be directly generalized to the case where , for which we just need to redefine the linear model using a weighted combination of the kernels for (5) and (9).
4 Empirical Verification
Extensions to Multi-Layer and Convolutional Neural Networks
In this section, we provide theoretical and empirical evidence supporting that the agreement between neural networks and linear models in the early phase of training may continue to hold for more complicated network architectures and datasets than what we analyzed in Section 3.
We consider a simple 1-dimensional CNN with one convolutional layer and without pooling (generalization to the commonly used 2-dimensional CNNs is straightforward):
We have the following result concerning the NTK of this CNN:
The proof is given in Appendix E. The above result shows that the NTK of a CNN can also be close to the (scaled) data kernel, which implies the linear learning behavior in the early time of training the CNN. Our empirical results will show that this behavior can even persist to multi-layer CNNs and real data beyond our analysis.
2 Empirical Results
Conclusion
This work gave a novel theoretical result rigorously showing that gradient descent on a neural network learns a simple linear function in the early phase. While we mainly focused on two-layer fully-connected neural networks, we further provided theoretical and empirical evidence suggesting that this phenomenon continues to exist in more complicated models. Formally extending our result to those settings is a direction of future work. Another interesting direction is to study the dynamics of neural networks after the initial linear learning phase.
References
Appendices
In Appendix A, we describe additional experiment details and provide additional plots. In Appendix B, we introduce additional notation and some lemmas that will be used in the proofs. In Appendix C, we present a general result that shows how the GD trajectory of a non-linear least squares problem can be approximated by a linear one, which will be used in the proofs. Finally, in Appendices D and E we provide omitted details and proofs in Sections 3 and 4, respectively.
Appendix A Experiment Setup and Additional Plots
We provide additional plots and describe additional experiment details in this section.
In Figure 4, we repeat the same experiments in Figure 3 on the full-size () CIFAR-10 as well as MNIST datasets, using the same -hidden-layer FC and CNN architectures. For both datasets we take two classes and perform binary classification. We see very good early-time agreement except for CNN on CIFAR-10, where the agreement only lasts for a shorter time.
We use the Neural Tangents Library [Novak et al., 2019] and JAX [Bradbury et al., 2018] for our experiments.
Appendix B Additional Notation and Lemmas
We introduce some additional notation and lemmas that will be used in the proofs.
For any matrix and a submatrix of , we have .
For simplicity we assume that is in the top-left corner of , i.e. . The same proof works when is any other submatrix of .
By the definition of spectral norm, we have
From Lemma B.1 we know that for all since can be viewed as a submatrix of . Thus we have
For any two positive semidefinite matrices , we have
Appendix C General Result on the Closeness between Two Dynamics
We present a general result that shows how the GD trajectory for a non-linear least squares problem can be simulated by a linear one. Later we will specialize this result to the settings considered in the paper.
We consider an objective function of the form:
Consider another linear least squares problem:
Let , and let
which stand for the predictions of these two models at iteration .
The linear dynamics admit a very simple analytical form, summarized below.
We make the following assumption that connects these two problems:
(boundedness of parameter movement) .
We first prove the first two properties, and will prove the last property at the end.
We first prove . If , this is trivially true. Now we assume . For each , by the fundamental theorem for line integrals we have
Let . Since and , from Assumption C.1 we know that . We can write
Combining the above two inequalities, we obtain
Taking sum over , we get
Then by the Cauchy-Schwartz inequality we have
Choosing sufficiently small, we can ensure .
Now that we have proved , to prove it suffices to bound the one-step deviation by . Using the exact same method in (14), we have
where we have used and . Choosing sufficiently small, we can ensure . Therefore we conclude that .
where . Since and , we know from Assumption C.1 that . Moreover, from Claim C.1 we know
Finally, we prove the last statement in the theorem, i.e., . In fact we have already proved this – notice that we have proved and that a special instance of this problem is when , i.e., the two dynamics are the same. Applying our result on that problem instance, we obtain . ∎
Appendix D Omitted Details in Section 3
In Section D.1, we present the formal theoretical guarantee (Theorem D.1) for the case of training both layers.
In Section D.2, we calculate the formulae of various Jacobians and NTKs that will be used in the analysis.
In Section D.3, we prove Theorem 3.2 (training the first layer).
In Section D.4, we prove Corollary 3.3 (training the first layer with well-conditioned data).
In Section D.5, we prove Theorem 3.5 (training the second layer).
In Section D.6, we prove Theorem D.1 (training both layers).
In Section D.7, we prove Claim 3.1 (data concentration properties).
We remark that if the data distribution is well-conditioned, we can also have a guarantee similar to Corollary 3.3.
D.2 Formulae of Jacobians and NTKs
We first calculate the Jacobian of the network outputs at the training data with respect to the weights in the network. The Jacobian for the first layer is:
After calculating the Jacobians, we can calculate the NTK matrices for the first layer, the second layer, and both layers as follows:
We also denote the expected NTK matrices at random initialization as:
These are also the NTK matrices at infinite width ().
Next, for the three linear models (5), (9) and (11) defined in Section 3, denote their feature/Jacobian matrices by:
Consequently, their corresponding kernel matrices are:
D.3 Proof of Theorem 3.2 (Training the First Layer)
For convenience we let which is the fixed second layer. Since we have (), we can write the first-layer NTK matrix as
Because it does not depend on , we denote for convenience.
Now we prove Proposition 3.4, restated below:
With high probability over the random initialization and the training data , we have
With high probability over the random initialization and the training data , we have
For convenience we denote and in this proof.
From Claim 3.1 we know with high probability. For the rest of the proof we will be conditioned on and on Claim 3.1, and only consider the randomness in .
Next we will apply the matrix Bernstein inequality (Theorem 1.6.2 in Tropp ) to bound . We will first consider the first half of independent neurons, i.e. . For each we have
Therefore, from the the matrix Bernstein inequality, for any we have:
Letting , we obtain
where we have used and . Therefore with high probability we have
Similarly, for the second half of the neurons we also have with high probability
Finally, by the triangle inequality we have
with high probability, completing the proof. ∎
With high probability over the training data , we have
We will be conditioned on the high probability events stated in Claim 3.1.
By the definition of , we know
We consider the diagonal and off-diagonal entries of separately.
Now we treat the terms in (21) separately. First, we have
For the final term in (21), we have
For the diagonal entries of , we have . We denote (). When is a smooth activation as in Assumption 3.2, we know that has bounded derivative, and thus we get
Combining the off-diagonal and diagonal approximations (23) and (25), we obtain
Finally, when (), we have . Hence we can discard the identity component above and get
Combining Propositions D.3 and D.4 directly gives Proposition D.2.
D.3.2 Agreement on Training Data
If is a smooth activation as in Assumption 3.2, then with high probability over the training data , we have
If is a piece-wise linear activation as in Assumption 3.2, then with high probability over the random initialization and the training data , we have
Throughout the proof we will be conditioned on and on the high-probability events in Claim 3.1.
By the definition of in (15), we have
Then if is a smooth activation, we have with high probability,
Next we consider the case where is a piece-wise linear activation. From (28) and Lemma B.3 we have
Since is a step function that only depends on the sign of the input, we have
Therefore we need to bound , i.e. how many coordinates in and differ in sign for each .
Let be a parameter whose value will be determined later. For each , define
Taking a union bound over all , we know that with high probability,
By definition, if but , we must have . This leads to
Letting , we get
Finally, we combine (29), (30) and (33) to obtain
The next lemma verifies Assumption C.1 for the case of training the first layer.
This proof is conditioned on all the high-probability events we have shown.
where we have used . If is a piece-wise linear activation, from Lemma D.5 we have
Hence we always have . Similarly, we have .
Note that from Proposition D.2 and Claim 3.1 we know
which implies . It follows that and . Then we have
Combining the above inequality with Proposition D.2, we obtain
Finally, we can instantiate Theorem C.2 to conclude the proof of (7):
There exists a universal constant such that with high probability, for all simultaneously, we have:
, .
Furthermore, Theorem C.2 also tells us and . ∎
D.3.3 Agreement on Distribution
where . Since according to Proposition D.7, we can use Lemma D.5 in the same way as in the proof of Lemma D.6 and obtain
Since is bounded and (), we can bound
Now using the standard generalization bound via Rademacher complexity (see e.g. Mohri et al. ), and noticing that the function is -Lipschitz and bounded in $t\leq T$ simultaneously,
Then letting and taking a union bound over , we obtain that with high probability, for all simultaneously,
D.4 Proof of Corollary 3.3 (Training the First Layer, Well-Conditioned Data)
According to the linear dynamics (6), we have the following relation (see Claim C.1):
Therefore we can apply the standard Rademacher complexity argument and conclude the proof of (41). ∎
D.5 Proof of Theorem 3.5 (Training the Second Layer)
Since the first layer is kept fixed in this case, we let for notational convenience. Similar to the proof of Theorem 3.2 in Section D.3, we still divide the proof into 3 parts: analyzing the NTK at initialization (which is also the NTK throughout training in this case), proving the agreement on training data, and proving the agreement on the distribution.
With high probability over the random initialization and the training data , we have
With high probability over the training data , we have
We will be conditioned on the high probability events stated in Claim 3.1.
By the definition of , we know
Denote and . Below we consider the diagonal and off-diagonal entries of separately.
For , we do a Taylor expansion of around :
Here are defined in (9), and is the -th entry in the Hessian whose specific value is not important to us. Recall that .
On the other hand, by the definition (20) we have
since (). ∎
With high probability over the random initialization and the training data , we have
Since is a random variable with degrees of freedom, it has sub-exponential norm , which implies that the random variable has sub-exponential norm .
Next we bound the variance. Let be a threshold to be determined. We have:
Thus, letting for a sufficiently large universal constant , we know that with probability at least over ,
Hence we pick the threshold which is the upper bound above, where is a universal constant.
Recall that in this case Theorem 3.5 assumes .
Applying Proposition 4.1 in Klochkov and Zhivotovskiy , we know that for any ,
Let . We can verify since . Then we have
Similarly, for the second half of the neurons we also have with high probability. Therefore we have with high probability,
Recall that in this case Theorem 3.5 assumes .
Applying Proposition 4.1 in Klochkov and Zhivotovskiy , we know that for any ,
Let . We can verify since . Then we have
Similarly, for the second half of the neurons we also have with high probability. Therefore we have with high probability,
Combining Propositions D.9 and D.10 directly gives Proposition D.8.
D.5.2 Agreement on Training Data
This proves the first part in Theorem 3.5.
Note that Theorem C.2 also tells us and , which will be useful for proving the guarantee on the distribution .
D.5.3 Agreement on Distribution
Next we bound the above two traces. First, we have
with high probability for all together. Here we have used the standard tail bound for random variables and a union bound over . Hence we have . For the second trace, we have
with high probability. Therefore we can bound the Rademacher complexity by . Then we can conclude the agreement guarantee on the distribution , i.e., for all simultaneously,
D.6 Proof of Theorem D.1 (Training Both Layers)
The proof for training both layers follows the same ideas in the proofs for training the first layer only and the second layer only. In fact, most technical components needed in the proof were already developed in the previous proofs. The only new component is a Jacobian perturbation bound for the case of training both layers, Lemma D.12 (analog of Lemma D.5 for training the first layer).
With high probability over the random initialization and the training data , we have
D.6.2 Agreement on Training Data
The proof for the agreement on training data is similar to the case of training the first layer only (Section D.3.2). We will again apply Theorem C.2. For this we need a new Jacobian perturbation lemma to replace Lemma D.5, since both layers are allowed to move now.
If is a smooth activation as in Assumption 3.2, then with high probability over the training data , we have
If is a piece-wise linear activation as in Assumption 3.2, then with high probability over the random initialization and the training data , we have
Furthermore, with high probability over the training data , we have
We will be conditioned on and on the high-probability events in Claim 3.1.
We first consider the first-layer Jacobian. By the definition of in (15), we have
Then if is a smooth activation, we have with high probability,
If is a piece-wise linear activation, then with high probability,
For the second-layer Jacobian, we have with high probability,
Based on Lemma D.12, we can now verify Assumption C.1 for the case of training both layers:
Let . With high probability over the random initialization and the training data, for all and such that , , and , we have
This proof is conditioned on all the high-probability events we have shown.
Now consider and which satisfy the conditions stated in the lemma.
If is a smooth activation, from Lemma D.12 we know
where we have used . If is a piece-wise linear activation, from Lemma D.12 we have
Hence in either case have . Similarly, we have .
Also, we know from Proposition D.2 that . It follows that and . Then we have
Next we look at the second-layer Jacobian. From Lemma D.12 we know . Similarly we have . Also, from Proposition D.8 we know , which implies and . It follows that
Combining the above auguments for two layers, we obtain
Combining the above inequality with Proposition D.11, the proof is finished. ∎
Finally, we can apply Theorem C.2 with and , and obtain that for all :
This proves the first part in Theorem D.1.
Note that Theorem C.2 also tells us , and , which will be useful for proving the guarantee on the distribution .
D.6.3 Agreement on Distribution
The proof for the second part of Theorem D.1 is basically identical to the case of training the first layer (Section D.3.3), so we will only sketch the differences here to avoid repetition.
Recall that in Section D.3.3 we define an auxiliary model which is the first-order approximation of the network around initialization. Here since we are training both layers, we need to modify the definition of the auxiliary model to incorporate deviation from initialization in both layers:
There are two more minor changes to Section D.3.3:
In Sections D.3.3 and D.5.3, we have shown that the above 4 traces are all with high probability. Hence we get the same Rademacher complexity bound as before.
Modulo these differences, the proof proceeds the same as Section D.3.3. Therefore we conclude the proof of Theorem D.1.
D.7 Proof of Claim 3.1
By Hanson-Wright inequality (specifically, Theorem 2.1 in Rudelson and Vershynin ), we have for any ,
Let for a sufficiently large constant . Taking a union bound over all , we obtain that with high probability, for all simultaneously. This proves the first property in Claim 3.1.
For , we have . Conditioned on , we know that is zero-mean and -subgaussian, which means for any ,
Since we have shown that with probability at least , we have
Then we can take and apply a union bound over , which gives for all with high probability. This completes the proof of the second statement in Claim 3.1.
Finally, for , we can use standard covariance concentration (see, e.g., Lemma A.6 in Du et al. ) to obtain with high probability. This implies . ∎
Appendix E Omitted Details in Section 4
For two datapoints and () and a location , we define
which is a local correlation between and .
Now we calculate the infinite-width NTK matrix , which is also the expectation of a finite-width NTK matrix with respect to the randomly initialized weights . We divide the NTK matrix into two components corresponding to two layers: , and consider the two layers separately.
Since the CNN model (12) is linear in the second layer weights, it is easy to derive the formula for the second-layer NTK:
Note that we have used the property since the data are from the hypercube .
Therefore we have shown that with high probability, for all ,
For the diagonal entries, we can easily see
Combining the above two equations, we obtain
We calculate the derivative of the output of the CNN with respect to the first-layer weights as:
Therefore, the entries in the first-layer NTK matrix are
Then, using the exact same analysis for the second-layer NTK, we know that with high probability,
Finally, combining the results for two layers, we conclude the proof of Proposition 4.1. ∎