A jamming transition from under- to over-parametrization affects loss landscape and generalization
Stefano Spigler, Mario Geiger, Stéphane d'Ascoli, Levent Sagun, Giulio Biroli, Matthieu Wyart
Introduction
Despite the remarkable progress in designing and training neural networks, there is still no general theory explaining their success, and their understanding remains mostly empirical. Central questions need to be clarified, such as what conditions need to be met in order to fit data properly, why the dynamics does not get stuck in spurious local minima, and how the depth of the network affects its loss landscape.
Complex physical systems with non-convex energy landscapes featuring an exponentially large number of local minima are called glasses . An analogy between deep networks and glasses has been proposed , in which the learning dynamics is expected to slow down and to get stuck in the highest minima of the loss. Yet, in the regime where the number of parameters is large (often considered in practice), several numerical and rigorous works suggest a different landscape geometry where the loss function is characterized by a connected level set. Furthermore, studies of the Hessian of the loss function and of the learning dynamics support that the landscape is characterized by an abundance of flat directions, even near its bottom, at odds with traditional glasses.
In a previous article we have introduced an analogy between supervised learning with deep neural networks and a class of glassy systems, namely random dense packings of repulsive particles. It generalized a previous seminal analogy established between the loss landscape of the perceptron (the simplest network without hidden neurons) and the energy landscape of spherical particles , and specified the universality class to which deep learning corresponds to. The critical behavior of these granular systems, although very general, is of easier understanding when we consider particles that interact only within a finite range: upon increasing their density, such systems undergo a critical jamming transition when there is no longer space to accommodate all the particles without them touching one another. Before the transition the energy is zero, and after it increases with the density. The inclusion of longer-range interactions blurs the transition but its effects are still affecting the energy landscape . Deep networks behave similarly when we look at the training loss, and, again, a clear criticality emerges when considering a “finite-range” loss function — the hinge loss: when the number of training points is small enough, the network is able to learn the whole training set and reaches zero training loss, and upon increasing the dataset size we find a critical “jamming” point where perfect training does not occur and learning gets stuck in a positive minimum of the the training loss.
For the full analogy we point to the aforementioned paper . In the present work we first review the arguments that show that the existence of the jamming transition, studied in the plane where is the number of degrees of freedom of the network (informally, its size) and is the size of the training set. As it turns out, there is a critical line (whose exact location can depend on the chosen dynamics) delimiting two phases, one where the learning reaches zero training loss, and one where it gets stuck in a minimum with finite loss — see Fig. 1. We present some numerical results that characterize the different phases, both for random data and for the MNIST dataset, using fully-connected networks with ReLU activation functions. Then, we show novel data that illustrate that this transition affects the most crucial aspect of learning, namely the generalization error. We observe that generalization properties are strongly affected by the proximity to the jamming transition: for a gradient descent dynamics, in the under-parameterized phase before jamming (large or small ) the generalization error is increasing; at the transition it displays a cusp; after jamming, in the over-parametrized phase, the error decreases monotonically. If early stopping is used, the cusp disappears, implying that the jamming transition is precisely the point where over-fitting is very strong.
2 Generalization versus over-fitting
The puzzle regarding the good generalization properties of neural networks despite their large size has been the topic of study for several other works. Some of them focus on the effects of various ways of regularizing the network, thereby effectively reducing the dimension . Yet another body of works focus on the effects of sheer size of a neural network .
Among previous studies, stands out as a natural predecessor of our work. In the authors present one of the first empirical observations of the cusp in test error of a non-linear model, a behaviour that is reminiscent of the perceptron. There, the training dynamics is run on a two-layer student network whose training data is provided by a teacher network with a similar architecture. The authors have observed (i) a cusp in generalization error, and (ii) monotonic decay in the test error when early stopping is used.
In this work, we show that the cusp in generalization corresponds to a phase transition where the number of unsatisfied constraints suddenly drops to zero as increases. We quantify how the location of the transition depends on for both random data and natural images, and find that the data structure significantly affects . Our analysis makes it clear that , an assumption sometimes made in previous studies. Overall, it relates the cusp in generalization to a well-known body of literature in physics associated with the “jamming” transition.
Since the initial preparation of the present work, the field has progressed quickly within a matter of months. The described cusp in the generalization error has been observed empirically in for random forest models and simple neural networks. Further theoretical studies on regression showed a precise mathematical description of the cusp behaviour in , albeit on models that are practically somewhat further away from modern neural networks. Finally, in , our subsequent work, we develop a quantitative theory for (i) the cusp which is associated to the divergence of the norm of the output function at the critical point of the phase transition and (ii) the asymptotic behaviour of the generalization error as which is associated with the reduced fluctuations of the output function. That work also shows that after ensemble averaging several networks, performance is optimal near the jamming the threshold, emphasizing the practical importance of this transition.
Theoretical framework
In this section we recall in detail the analogy between jamming and supervised learning for deep neural networks . This will set the stage for the following thorough analysis of the phase transition and its role on generalization.
We consider a binary classification problem, with a set of distinct training data denoted . The vector is the input, which lives in a -dimensional space, and is its label. We denote by the output of a fully-connected network corresponding to an input , parametrized by . We represent the network as in Fig. 2, and the output function is written recursively as
where are the preactivations. In our notation the set of parameters includes, with a slight abuse of notation, both the weights and the biases . is the non-linear activation function, e.g. the ReLU or the hyperbolic tangent . The parameters are learned by minimizing the quadratic hinge loss:
where and is the set of patterns with and contains elements. These patterns describe unsatisfied constraints: they are either incorrectly classified or classified with an insufficient margin (whereas patterns with are learned with margin 1). We adopt this loss function since it makes the jamming transition simpler to analyzeThe often used cross-entropy loss function also displays a transition where all data are well-fitted. However, in the over-parametrized regime the dynamic never stops, as the total loss vanishes only if the output and therefore the weights diverge. Imposing a time cut-off is done in practice, but it blurs the criticality near jamming, as exemplified below with the early stopping procedure., but this choice does not influence the performance of the network, as we have reported in .
We are interested in the transition between an over-parametrized phase where the network can satisfy all the constraints () and an under-parametrized phase where some constraints remain unsatisfied ().
2 A note on the effective number of parameters
Symmetries are present in the network, e.g. the scale symmetry in ReLU networks: since the ReLU function is homogeneous, multiplying the weights of a layer by some factor and dividing the weights in the next layer by the same factor leaves the output function invariant. It will reduce one degrees of freedom per node.
3 Constraints on the stability of minima
In this section we show that the existence of a minimum at a vanishingly small training loss (i.e. approaching jamming) is enough to derive an upper bound for the transition in the plane.
Let us suppose (and justify later) that, for a fixed number of data and with proper initialization of weights, if is large enough then gradient descent leads to , whereas if is small after training . Imagine increasing starting from a small value: at some the loss obtained after training approaches zero For finite , will present fluctuations induced by differences of initial conditions. The fluctuations of are however expected to vanish in the limit where and become large. This phenomenon is well-known for the jamming of particles, and is an instance of finite size effects. , i.e. . We refer to this point as the jamming transition. A vanishing training loss implies that for each pattern . As argued in , for each the constraint defines a manifold of dimension Related arguments were recently made for a quadratic loss . In that case, we expect the landscape to be related to that of floppy spring networks, whose spectra are predicted in .. Satisfying such equations thus generically leads to a manifold of solutions of dimension Note that this argument implicitly assumes that the constraints are independent. In disordered systems this assumption is generally correct, but it may break down if symmetries are present.. Imposing that a solution exists implies that at jamming:
Smooth activation function: An opposite bound can be obtained by considerations of stability (as was done for the jamming of repulsive spheres in ), by imposing that in a stable minimum the Hessian must be positive definite if the output function is smooth, as it must be the case if the activation function is smooth (see below for the situation where the function displays cusps, as occurs for ReLU neurons). The Hessian matrix, that is the matrix of second derivatives, is
(Here is the gradient operator and stands for tensor product). The first term is positive semi-definite: it is the sum of rank-one matrices, thus , implying that the kernel of is at least of dimension .
(The first inequality trivially follows from the fact that the patterns belong to the training set of size ). As reported in , we observe empirically that the spectrum of is statistically symmetric in the cases that we consider in the present work, i.e. for ReLU activation function, both for MNIST and random data, both at initialization and at the end of training. In A.2 we provide a non-rigorous argument supporting that in the case of ReLU activation functions and random data the spectrum of is indeed symmetric with independently of depth, where is the number of positive eigenvalue. We conjecture that in general the limiting spectrum of as (for any fixed ratio ) has a finite fraction of negative eigenvalues for generic architectures and datasets. In we observed for the ReLU activation function as expected, for tanh activation functions at jamming and at the end of training we found . Thus, is not universal.
Non-smooth activation functions: With ReLU activation functions, the output function is not smooth and presents cusps, so that the Hessian needs not be positive definite for stability. A minimum can lie on a point where the second derivative is not defined along some directions (because of the cusp), and we say that the cusp stabilizes those directions. Equation (7) needs to be modified accordingly: introducing the number of directions presenting cusps near jamming, stability implies and:
Numerically, we find that at jamming the fraction of directions along which there is a cusp is both for random data and images as reported in the A.3. Using for Relu, we obtain the bounds:
Main results: Overall, our analysis supports that for smooth activation functions there exists a constant such that:
there is a transition for below which the training loss converges to some non-zero value (under-parametrized phase) and above which it becomes null (over-parametrized phase).
At the transition, the fraction of unsatisfied constraints per degree of freedom jumps discontinuously to a finite value satisfying .
The complete list of results, including consequences of this analysis on the Hessian, is included in .
For activation function, but the analysis is complicated by the presence of cusps. The jamming transition is still sharp, i.e. characterized by a discontinuous jump in constraints as specified by Eq.11.
In the next sections, we confirm these predictions for in numerical experiments and observe the generalization properties at and beyond the transition point.
Location of the jamming transition
Here we present the numerical results on random data (uniformly distributed on a hypersphere and with random labels ) and on the MNIST dataset (partitioned into two groups according to the parity of the digits and with labels ). With MNIST, in order not to have most of the weights in the first layer, we reduce the actual input size by retaining only the first principal components that carry the most variance (this hardly diminishes the performance for such a task). Further description of the protocols is in B.
In Fig. 3A,C we show the location of boundary versus the number of samples . is estimated numerically for each by starting from a large value of and progressively decreasing it until at the end of training. Varying input dimension, depth and loss function (cross entropy or hinge) has little effect on the transition. This result indicates that in the present setup the ability of fully-connected networks to fit random data does not depend crucially on depth. Fig. 3C shows also a comparison of random data with MNIST. A difference between random data and images is that the minimum number of parameters needed to fit the real data is significantly smaller and grows less fast as increases — for , could be sub-linear or even tend to a finite asymptote: how the data structure affects is an important questions for future studies.
From the analysis of Section 2, the number of constraints per parameter is expected to jump discontinuously at the transition. This is shown in the insets of Fig. 3B,D. The scatter in these plots presumably reflects finite size effects known to occur near the jamming transition of particles . All this scatter is however gone when plotting as a function of the loss itself, as shown in the main panels of Fig. 3B,D.
Generalization at and beyond jamming
In Fig. 4A we show the evolution of the generalization error for networks at four different locations in the plane. The networks are trained on MNIST at fixed , and at different values , both above, at and below jamming. Training is run for a fixed number of steps of vanilla gradient descent (the simulation details are in B). The profile of these curves is typical of most learning problems (if one does not recur to early stopping): notice that the point of minimum generalization error happens before the end of training. The increase of test error at late times is referred to “over-fitting” in the field. Very interestingly, it is clear from this figure that at small and large , over-fitting is a weak effect, which however becomes very significant at intermediate .
To study this effect, we systematically vary at fixed . In Fig. 4B the solid curve shows the generalization error against the network size for three different values of (we sampled subsets of MNIST). The dashed curve represents the value of the smallest error obtained during training, at prior time-steps (extracted from the profiles shown in Fig. 4A). The former displays a cusp at the transition point, as one can see clearly after rescaling the -axis of each curve by the corresponding value of . Strong over-fitting, corresponding to the difference between the solid and dashed lines, takes place only in the vicinity of the critical jamming transition (Fig. 4B-C). We thus posit that at fixed , the benefit of early stopping should diminish in the large-size limit. Beyond the jamming point, the accuracy keeps steadily improving as the number of parameters increases , although it does so quite slowly. We have provided a quantitative explanation for this phenomenon in . In B.2 we have verified that the overall trends showed in Fig. 4 qualitatively hold also for other depths.
Notice that although the cusp has been found also in shallow networks (in particular the perceptron ), their behavior is at odds with what we observe: for the perceptron, test error asymptotically increases with .
Conclusions
Understanding the effect of over-parametrization on the behavior of deep neural networks is a central problem in machine learning. In this work, by focusing on the hinge loss, we recast the minimization of the loss function as a constraint-satisfaction problem with continuous degrees of freedom. A similar approach was used in the field of interacting particles, which display a sharp jamming transition affecting the landscape if the interaction is chosen to be finite range . Following the analogy we were able to predict a sharp transition as the number of network parameters is varied, separating a region in the plane where a global minimum can be found () from a region where the number of unsatisfied constraints is a fraction of the number of parameters, so . These results also shed light on several aspects of deep learning:
Not getting stuck in local minima: In the over-parametrized regime, the dynamics does not get stuck in local minima at finite loss value because the number of constraints to satisfy is too small to hamper minimization. It follows from our assumptions on the negative eigenspace of the matrix that in this regime the landscape is flat and local minima do not exist (assuming that the number of effective parameters that affect the output function is ). For a smooth activation function we predict that one cannot get stuck in a bad minimum for , implying in particular that where is a constant. We obtain a less demanding bound for ReLU activation functions due to the presence of cusps in the landscape, a situation for which we expect . In practice, for random data scale linearly with (in this sense, the bound is tight). By contrast, for structured data appears to scale sub-linearly with . Predicting the curve remains a challenge for the future.
Reference point for fitting and generalization: There exists a critical curve on the - plane above which the global minima of the landscape become accessible. The curve also appears to be linked to the generalization potential of the model. We show that in the cases that we considered, (i) the generalization error decreases when ; then (ii) it increases and culminates in a cusp at that is erased by early stopping, most useful in this region; finally, (iii) in the over-parametrized phase, it monotonically decreases, although very slowly.
We thank Marco Baity-Jesi, Carolina Brito, Chiara Cammarota, Taco S. Cohen, Silvio Franz, Yann LeCun, Florent Krzakala, Riccardo Ravasio, Andrew Saxe, Pierfrancesco Urbani and Lenka Zdeborova for helpful discussions. This work was partially supported by the grant from the Simons Foundation (#454935 Giulio Biroli, #454953 Matthieu Wyart). M.W. thanks the Swiss National Science Foundation for support under Grant No. 200021-165509. The manuscript , which appeared at the same time as ours, shows that the critical properties of the jamming transition found for the non-convex perceptron hold more generally in some shallow networks. This universality is an intriguing result. Understanding the connection with our findingsis certainly worth future studies.
References
Appendix A Network properties
In the following, we analyze numerically the networks properties that were used in the previous analysis. This provides a numerical confirmation of our arguments, and an in depth characterization of the networks.
Due to several effects discussed above, the function can effectively depend on less variables that the number of parameters, and thus reduce the dimension of the space spanned by the gradients that enters in the theory. For instance, there could be symmetries that reduce the number of effective degrees of freedom (e.g. each ReLU activation function has one of such symmetries, since one can rescale inputs and outputs in such a way that the post-activation is left invariant); another reason could be that a neuron might never activate for all the training data, thus effectively reducing the number of neurons in the network; furthermore, we expect that the network’s true dimension would also be reduced if its architecture presents some bottlenecks, is poorly designed or poorly initialized. For example if all biases are too negative on the neurons of one layer in the Relu case, the network does not transmit any signals, leading to and to the possible absence of unstable directions even if the number of parameters is very large.
It is tempting to define the effective dimension by considering the dimension of the space spanned by as varies. This definition is not practical for small number of samples however, because this dimension would be bounded by . We can overcome such a problem by considering a neighborhood of each point , where the network’s function and its gradient can be expanded in the pattern space:
Varying the pattern and the point in the neighborhood of , we can build a family of vectors:
where the elements of the matrix are defined as
with . The index ranges from to , and .
We consider , where is the Hessian of the network function and is the Relu function. We want to argue that the spectrum of is symmetric in the limit of large .
We do two main hypothesis: First, the trace of any finite power of is self-averaging (concentrates) with respect to the average over the random data:
The first hypothesis is natural since is a very large random matrix, for which the density of eigenvalues is expected to become a non-fluctuating quantity. The second hypothesis is more tricky: it is natural to assume that the trace concentrates, however one also need to show that the sub-leading corrections to the self-averaging of the trace can be neglected.
Using these two hypothesis and the result, showed below, that
for all odds, one can conclude that all odds traces of are zero. This implies that the spectrum of is symmetric, more precisely that the fractions of negative and positive eigenvalues are equal.
where the indices stand for synapses connecting a pair of neurons (i.e. each index is associated with a synaptic weight : we are not writing all the explicit indexes for the sake of clarity). The term of the hessian obtained when differentiating with respect to weights and reads
In fact, note that the sum in Equation (22) contains a weight per each layer in the network, with the exception of the two layers with respect to which we are deriving. This implies that any element of the hessian matrix where we have not differentiated with respect to the last layer () is an odd function of the last layer , meaning that if , then the sign of all these Hessian elements is inverted as well.
If in the argument of the sum in Equation (21) there is no index belonging to the last layer, then the whole term changes sign under the transformation . Suppose now that, on the contrary, there are terms with one index belonging to the last layer (we need not consider the case of two indices both belonging to the last layer because the corresponding term in the Hessian would be , as one can see in Equation (22)). For each index equal to (the last layer), there are exactly two terms: (for some indexes ). Since cannot be too, this implies that the number of terms with an index belonging to the last layer is always even. Consequently, when the sign of is reversed, the argument of the sum in Equation (21) is multiplied by (once for each term without an index belonging to the last layer), which is equal to if is odd. The same symmetry can be used to show that a matrix made of an odd product of matrices , such as , must also have a symmetric spectrum, concluding our argument.
A.3 Density of pre-activations for ReLU activation functions
The densities of pre-activation (i.e. the value of the neurons before applying the activation function) is shown in Fig. 6 for random data. It contains a delta distribution in zero. The number of pre-activations equal to zero when feeding a network all its random dataset is , corresponding to the number of directions in phase space where cusps are present in the loss function. For MNIST data we find . By taking and random data we find . In these directions, stability can be achieved even if the hessian would indicate an instability. For this reason, instead of in Equation (7) one should use .
Appendix B Parameters used in simulations
The dataset is composed of points taken to lie on the -dimensional hyper-sphere of radius , , with random label . The networks are fully connected, and have an input layer of size and layers with neurons each, culminating in a final layer of size . To find the transition we proceed as follows: we build a network with a number of parameters large enough for it to be able to fit the whole dataset without errors. Next, we decrease the width while keeping the depth fixed, until the network cannot correctly classify all the data anymore within the chosen learning time. We denote this transition point . As initial conditions for the dynamics we use the default initialization of pytorch: weights and biases are initialized with a uniform distribution on , where and is the number of incoming connections.
When using the cross entropy, the system evolves according to a stochastic gradient descent (SGD) with a learning rate of for steps and for steps ( steps in total); the batch size is set to , and batch normalization is used. We do not use any explicit regularization in training the networks. In Fig. 7 we check that is enough to converge.
When using the hinge loss, we use an orthogonal initialization , no batch normalization and steps of ADAM with batch size and a learning rate starting at . In the experiments of section 3 (not for the experiments of section 4), we progressively divided the learning rate by every 250k steps. Also in this case we do not use any explicit regularization in training the networks.
To observe the discontinuous jump in the number of unsatisfied constraints at the transition (Fig. 3B and inset), we consider three architectures, both with and but with different depths , and . The vicinity of the transition is studied by varying around the transition value and minimizing for steps (a better minimization is needed to improve the precision close to the transition).
We trained networks of depth 2,3,5 with 62, 51, 40 respectively for 10M steps. For (, ) we ran 128 training varying from 21991 to 25918. For the value of we take that correspond to the number of parameters minus the number of neurons, per neuron there is a degree of freedom lost in a symmetry induced by the homogeneity of the ReLU function. 37 of the runs have , 74 have . Among the 19 remaining ones, 14 of them have between 1 and 4, we think that these runs encounter numerical precision issues, we observed that using 32 bit precision accentuate this issue. We think that the 5 left with has been stoped too early. The same observation apply for the other depths.
B.2 Real data
The images in the MNIST dataset are gathered into two groups, with even and odd numbers and with labels . The architecture of the network is as in the previous sections: the inputs are fed to a cascade of fully-connected layers with neurons each, that in the end result in a single scalar output. The loss function used is always the hinge loss.
If we kept the original input size of (each picture is pixels) then the majority of the network’s weights would be necessarily concentrated in the first layer (the width cannot be too large in order to be able to compute the Hessian). To avoid this issue, we opt for a reduction of the input size. We perform a principal component analysis (PCA) on the whole dataset and we identify the 10 dimensions that carry the most variance on the whole dataset; then we use the components of each image along these directions as a new input of dimension . This projection hardly diminishes the performance of the network (which we find to be larger than when using all the data and large ).
We trained a network of , , for 3M steps. With varying from 31k to 68k (using trainset and testset of MNIST).