On Linear Stability of SGD and Input-Smoothness of Neural Networks
Chao Ma, Lexing Ying
Introduction
Stochastic gradient descent (SGD) is the most widely used optimization algorithm to train neural networks . By taking mini-batches of training data instead of all the data in each iteration, it was firstly designed as a substitute of the gradient descent (GD) algorithm to reduce its computational cost. Extensive researches are conducted on the convergence of SGD, both on convex and non-convex objective functions . In these studies, convergence is usually proven in the cases where the learning rate is sufficiently small, hence the gradient noise is small. In practice, however, SGD is preferred over GD not only for the low computational cost, but also for the implicit regularization effect that produces solutions with good generalization performance . Since a trajectory of SGD tends to that of GD when the learning rate goes to , this implicit regularization effect must come from the gradient noise induced by mini-batch and a moderate learning rate.
When studying the gradient noise of SGD, a majority of work treat SGD as an SDE, and studies the noise of the SDE . However, SGD is close to SDE only when the learning rate is small, and it is unclear that in practical setting whether the Gaussian noise of SDE can fully characterize the gradient noise of SGD. Some work resort to heavy-tailed noise like the Levy process . Another perspective to study the behavior of SGD is by its linear stability . This is relevant when the learning rate is not very small. The linear stability theory can explain the fast escape of SGD from sharp minima. The escape time derived from this theory depends on the logarithm of the barrier height, while the escape time derived from the diffusion theory based on SDE depends exponentially on the barrier height . The former is more consistent with empirical observations .
An important observation that connects the generalization performance of the solution with the landscape of the loss function is that flat minima tend to generalize better . SGD is shown to pick flat minima, especially when the learning rate is big and the batch size is small . Algorithms that prefer flat minima are designed to improve generalization . On the other hand, though, the reason why flat minima generalize better is still unclear. Intuitive explanations from description length or Bayesian perspective are provided in and . In , the authors show sharp minimum can also generalize by rescaling the parameters at a flat minimum. Hence, flatness is not a necessary condition of good generalization performance, but it is still possible to be a sufficient condition. In the study of linear stability in , besides the sharpness (a quantity inversely proportional to flatness), another quantity named non-uniformity is proposed which roughly characterizes the second order moment of the gradient noise. It is shown that SGD selects solutions with both low sharpness and low non-uniformity.
In this paper, we build a complete theoretical pipeline to analyze the implicit regularization effect and generalization performance of the solution found by SGD. Our starting points are the following two questions: (1) Why SGD finds flat minima? (2) Why flat minima generalize better? Our answers to these two questions go beyond the flatness and cover the non-uniformity and higher-order moments of the gradient noise. This distinguishes SGD from GD, and is out of the scope that can be explained by SDE. For the first question, we extend the linear stability theory of SGD from the second-order moments of the iterator of the linearized dynamics to the high-order moments. At the interpolation solutions found by SGD, by the linear stability theory, we derive a set of accurate upper bounds of the gradients’ moment. For the second question, using the multiplicative structure of the input layer of neural networks, we show that the upper bounds obtained in the first step regularize the Sobolev seminorms of the model function. Finally, bridging the two components, our main result is a bound of generalization error under some assumptions of the data distribution. The bound works well when the distribution is supported on a low-dimensional manifold (or a union of low-dimensional manifolds). An informal statement of our main result is
(Main result) Around an interpolation solution of the neural network model, assume that (1)the -th order moment of SGD’s iterator of the linearized dynamics is stable, (2)with probability at least the testing data is close to a training data with distance smaller than , and (3) both the model function and the target function are upper bounded by a constant . Then, at this interpolation solution we have
where is the number of data. The bound depends on the learning rate and the batch size of SGD as constant factors.
The formal description is stated in Theorem 6 of Section 5. Our analysis also provide bounds for adversarial robustness. As a byproduct, we theoretically show that flatness of the minimum controls the gradient norm of the model function at the training data. Therefore, searching for flat minima has the effect of Lipschitz regularization, which is shown to be able to improve generalization .
where is usually a long expression produced by back propagation from the output to the first layer. By (1) we have
Hence, from (2) we can obtain the following equation that gives bounds for the gradients of the model function with respect to the input data at the training data,
The left hand side of (4) is usually used to regularize the Lipschitz constant of the model function, and such regularization can improve the generalization performance and adversarial robustness of the model. Hence, (4) reveals the regularization effect of flat minima. Later in the paper, we extend the analysis to higher-order moments of the gradient and combine the results with the linear stability theory of SGD to explain the implicit regularization effect of SGD. We also extend the bound on from training data to all in a neighborhood of the training data, which implies the regularization of flatness is actually stronger than the left-hand-side of (4).
The strong correlation between and is justified by numerical experiments in practical settings. Specifically, in experiments we compare the following two quantities:
Figure 1 shows the results for a fully-connected network trained on FashionMNIST dataset and a VGG-11 network trained on CIFAR10 dataset. In each plot, and of different solutions found by SGD are shown by scatter plots. The plots show strong correlations between the two quantities. The colors of the points show that SGD with big learning rate and small batch size tends to converge to solutions with small and , which is consistent with our theoretical results on the Sobolev regularization effect of SGD. To summarize, the main contributions of this paper are:
We extend the linear stability analysis of SGD to high-order moments of the iterators. At the solutions selected by SGD, we find a class of conditions satisfied by the gradients of different training data. These conditions cover the flatness and non-uniformity, and also include higher order moments. They characterize the regularization effect of SGD beyond GD and SDE.
By exploring the multiplicative structure of the neural networks’ input layer, we build relations between the model function’s derivatives with respect to the parameters and with respect to the inputs. By these relations we turn the conditions obtained for SGD into bounds of different Sobolev (semi)norms of the model function. In particular, we show that flatness of the minimum regularizes the norm of the gradient of the model function. This explains how the flatness (as well as other stability conditions for SGD) benefits generalization and adversarial robustness.
Still using the multiplicative structure, the bounds for Sobolev seminorms can be extended from the training data to a neighborhood around the training data, based on certain smoothness assumption of the model function (with respect to parameters). Then, bounds for generalization error and adversarial robustness are provided under reasonable assumptions of the data distribution. The bounds work well when the data are distributed effectively in a set that consists of low dimensional manifolds.
Preliminaries
Problem settings
We remark that most neural networks have form (6), including convolutional networks, residual networks, recurrent networks, and even transformers. Note that since the in (6) can also be understood as fixed features calculated using input data, (6) also includes random feature models.
For any , let be the loss at . Then, the iteration scheme of the SGD with learning rate and batch size is
where is a -dimensional random variable uniformly distributed on the -tuples in and independent with . In the paper, we study interpolation solutions found by SGD, which satisfies for any . Obtaining interpolation solutions is possible in the over-parameterized setting , and is widely studied in existing work .
Some assumptions will be made when deriving the generalization error bounds. Firstly, we assume the model function with respect to the parameter to be smooth around .
Let , be positive numbers, and be a positive integer. We say the model satisfies the -local smoothness condition at data and parameter , if for any such that , there is
In the definition above, we consider the -norm of the gradients for the convenience of later analysis. When , the condition (8) becomes . This is weaker than local approximation by Taylor expansion, which usually yields results like . Here, we only require that the gradient with respect to the parameters does not get exceedingly large when is close to .
Next, we need the data distribution to support roughly on a low dimensional manifold (or a union of low dimensional manifolds), thus the neighborhoods of training data can well cover all test data.
i.e. with high probability a point sampled from lies close to a point in .
The uniform upper bound in the above definition can be weakened as an integral upper bound , where and is the Lebesgue volume of .
On the other hand, for positive integer and positive constants , and , we say satisfies the -scattered condition, if with probability at least over the choice of i.i.d. sampled data from , is -scattered.
Later in the analysis of the generalization error (Section 5), we will assume the model and the data distribution satisfy the conditions in Definition 1 and 4 with appropriately chosen constants.
Linear stability theory of SGD
Compared with full-batch GD, SGD adds in each iteration a random “noise” to the gradient of the loss function. Hence, it is harder for SGD to be stable around minima than GD. This is shown by the linear stability theory of SGD.
Recall that the iteration scheme of SGD with learning rate and batch size is given by (7). Let be an interpolation solution for the learning problem. When is close to , the behavior of (7), including its stability around the minimum, can be characterized by the linearized dynamics at :
Next, we define the stability of the above dynamics.
In , the following condition on the linear stability for is provided.
(Theorem 1 in ) The global minimum is -order linearly stable for SGD with learning rate and batch size if
where , and .
Shown by the proposition, the spectra of and influence the linear stability of SGD. Thus, in the biggest eigenvalue of and are named sharpness and non-uniformity, respectively. The condition (13) is then be relaxed into a condition of sharpness and non-uniformity. Similar analysis was also conducted in for linear least squares problems.
holds for any if is an even number, or for any is is an odd number.
All proofs are provided in the appendix. As a corollary, when , we can write down another sufficient condition for linear stability than Proposition 1. See Corollary 3 in the appendix.
Recall that we let and . The linear stability conditions in Theorem 1 imply the following bound on the moments of . Specifically, we have
If a global minimum is order linearly stable for SGD with learning rate and batch size , then, for any , we have
where means the entry of .
By Theorem 2, if a global minimum is stable for SGD with some order, then the gradient moment of this order is controlled. Summing from to , we have . For and , this gives control to the flatness and non-uniformity of the minimum, respectively. For general , applying the Hölder inequality on (18), we have the following corollary which bounds the mean -norm of the gradients at the training data.
If a global minimum is order linearly stable for SGD with learning rate and batch size , then
The Sobolev regularization effect
In this section, we build connection between and using the multiplication of and . For general parameterized model, it is hard to build connection between the two gradients. However, this is possible for neural network models, in which the input variable is multiplied with a set of parameters (the first-layer parameter) before any non-linear operation. By this connection, at an interpolation solution that is stable for SGD, we can turn the moments bounds derived in the previous section into the bounds on . For different , the moment bound on controls the Sobolev seminorms of at the training data with different index . When , this becomes a bound for the sum of gradient square at the training data, which is used in the literature as a regularization term to regularize the Lipschitz constant of the model function. This explains the favorable generalization performance of flat minima.
Combining Corollary 2 with the stability condition in Theorem 2, we have the following control for the Sobolev seminorm of the model function at interpolation solutions that are stable for SGD.
If a global minimum which interpolates the training data is order linearly stable for SGD with learning rate and batch size , and . Then,
By Corollary 2 and Theorem 3, as long as the data are not very small (in practical problems, the input data are usually normalized), and the input-layer parameters are not very large, the Sobolev seminorms of the model function (evaluated at the training data) is regularized by the linear stability of SGD. The regularization effect on Sobolev seminorm gets stronger for bigger learning rate and smaller batch size. When is big, the dependence of the bound with is negligible.
Proposition 3 turns the local smoothness condition in the parameter space into a local smoothness condition in the data space. This is made possible by the multiplicative structure of the network’s input layer. Specifically, since in the first layer and are multiplied together, a perturbation of can be turned to a perturbation of without changing the value of their product. See the proof of the proposition in Appendix B.2 for more detail.
By the results above, we can obtain the following theorem which estimates the Sobolev seminorm of the model function on a neighborhood of the training data.
Let be an interpolation solution that is order linearly stable for SGD with learning rate and batch size . Let be the training data. Suppose the model satisfies -local smoothness condition at and for any . Consider the set with . Assume satisfies -scattered condition as defined in Definition 3. Then, we have
where is the Lebesgue volume of .
By Theorem 4, the model function found by SGD is smooth in a neighborhood of the training data, given that the landscape of the model in the parameter space is smooth. When , the results implies that flatness regularizes , which is stronger than the gradient square at training data.
The bounds in this section depend on the norm of . This norm may be big, especially when homogeneous activation functions, such as ReLU, is used. In the ReLU case, for example, we can simply scale the first layer parameters to be arbitrarily large and second layer small while not changing the model function.
However, in practice SGD does not find these solutions with unbalanced layers because the homogeneity of ReLU induces an invariant in parameters. Specifically, let and be the parameter matrices in the and layers, then does not change significantly throughout the training (it is actually fixed in the zero learning rate limit). This invariant keeps layers balanced and prevents the first layer parameters from getting big alone.
On the other hand, we conduct numerical experiments to check the norm of during training. Table 1 shows the average -norm of for the same experiments in part (a) of Figure1. The model is a fully-connected neural network, and the dataset is FashionMNIST. Results show that the norm of increases at the beginning, but becomes stable afterwards. It will not keep increasing during the training.
Generalization error and adversarial robustness
Let be an interpolation solution that is order linearly stable for SGD with learning rate and batch size . Let be the training data. Suppose the model satisfies -local smoothness condition at and for any . Recall the definition of in Theorem 4. Then, for any , we have
With the result above, we can bound the generalization error if most test data are close to the training data, i.e. the data distribution satisfies a covered condition. This happens for machine learning problems with sufficient training data, especially for those where the training data lie approximately on a union of some low-dimensional surfaces. This is common in practical problems .
The bound (26) tends to as as long as decays faster than . From a geometric perspective, this happens when the dimension of the support of is less than . And the lower the dimension, the faster the decay. It is possible to get rid of the dependency in the bound when is sufficiently large. We may use the estimate of Sobolev functions with scattered zeros, e.g. Theorem 4.1 in . We leave the analysis to future work.
Neural network models suffer from adversarial examples , because the model function changes very fast in some directions so the function value becomes very different after a small perturbation. However, the results in Theorem 5 directly imply the adversarial robustness of the model at the training data. Hence, flatness, as well as high-order linear stability conditions, also imply adversarial robustness. Specifically, we have the following theorem.
Let be an interpolation solution that is order linearly stable for SGD with learning rate and batch size . Let be the training data. Suppose the model satisfies -local smoothness condition at and for any . Then, for any that satisfies for some and , we have
Conclusion
In this paper, we connect the linear stability theory of SGD with the generalization performance and adversarial robustness of the neural network model. As a corollary, we provide theoretical insights of why flat minimum generalizes better. To achieve the goal, we explore the multiplicative structure of the neural network’s input layer, and build connection between the model’s gradient with respect to the parameters and the gradient with respect to the input data. We show that as long as the landscape on the parameter space is mild, the landscape of the model function with respect to the input data is also mild, hence the flatness (as well as higher order linear stability conditions) has the effect of Sobolev regularization. Our study reveals the significance of the multiplication structure between data (or features in intermediate layers) and parameters. It is an important source of implicit regularization of neural networks and deserves further exploration.
References
Checklist
Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope? [Yes]
Did you describe the limitations of your work? [Yes] Our generalization bounds work on effectively low dimensional problems.
Did you discuss any potential negative societal impacts of your work? [N/A]
Have you read the ethics review guidelines and ensured that your paper conforms to them? [Yes]
If you are including theoretical results…
Did you state the full set of assumptions of all theoretical results? [Yes] In both Section 2 and the statement of theorems.
Did you include complete proofs of all theoretical results? [Yes]
Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)? [Yes] See Section F and the URL therein.
Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)? [Yes] Section F
Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)? [N/A]
Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)? [Yes] Section F
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets…
If your work uses existing assets, did you cite the creators? [N/A]
Did you mention the license of the assets? [N/A]
Did you include any new assets either in the supplemental material or as a URL? [N/A]
Did you discuss whether and how consent was obtained from people whose data you’re using/curating? [N/A]
Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content? [N/A]
If you used crowdsourcing or conducted research with human subjects…
Did you include the full text of instructions given to participants and screenshots, if applicable? [N/A]
Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable? [N/A]
Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation? [N/A]
Appendix A Proofs for Section 3
Next, we show the necessity. Let , then has the following decomposition
For any and , if , then .
Then, a similar construction as in the even case completes the proof.
A.2 Corollary 3 and the proof
The global minimum is -order linearly stable for SGD with learning rate and batch size if
For each , appears in batches, and for each , , and appears in batches simultaneously. Hence,
Then, the result is a direct application of Theorem 1.
A.3 Proof of Theorem 2
Next, we will use the following lemma, whose proof is also provided in the appendix.
For any batch , let , we obtain
Taking expectation over batches, by (34) we have
Appendix B Proofs for Section 4
In this proof, always means the vector or matrix -norm, not the function norm. Then, we have
Since is a subset of , obviously we have
B.2 Proof of Proposition 3
for . The linear system above is under-determined, hence solutions exist. We take the minimal norm solution
Let , then . Hence, by (8) we have
This together with (37) completes the proof of (23).
B.3 Proof of Theorem 4
where is the volume of , which does not depend on . Sum the above integral up for all training data, we have
Appendix C Proofs for Section 5
for any . Therefore, for any ,
Hence, for any , , which together with Proposition 3 finishes the proof.
C.2 Proof of Theorem 6
Let . Then, we have
In the last line, the term comes from
Inserting (44) to (41) yields the result.
Appendix D Additional proofs
We show the following more general result.
where are eigenvalues of . Hence, means
which means there exists such that and . Then,
D.2 Proof of Lemma 2
When , we have . Hence,
When , by the Hölder inequality,
Taking -th order on both sides, we have
Appendix E Additional Experiments
Except the and in (5), we also checked the gradient norms with higher in the same experiment settings. We consider
Figures 2 and 3 show the scatter plot for and , respectively. The figures shows that in most cases there is still a strong correlation between the gradient norm with respect to and the gradient norm with respect to .
The next figure (Figure 4) shows experiment results on more complicated dataset and network architectures, where we trained a -layer Resnet on a subset of the CIFAR100 dataset. The scattered plots show similar results as in Figrue 1, which further justifies our theoretical predictions.
Appendix F Experiment details
In the numerical experiments shown by Figure 1, 2 and 3, we train fully-connected deep neural networks and VGG-like networks on FashionMNIST and CIFAR10, respectively. As shown in the figures, for each network, different learning rates and bacth sizes are chosen. repetitions are conducted for each learning rate and batch size. In each experiment, SGD is used to optimize the network from a random initialization. The SGD is run for iterations to make sure finally the iterator is close to a global minimum. then, and in (5) are evaluated at the parameters given by the last iteration. In the experiments shown in Figure 4, we train a residual network on CIFAR100. Experiments are still repeated by times in each combination of learning rate and batch size. In each experiment, SGD is run for iterations. All experiments are conducted on a MacBook pro 13" only using CPU. See the code at https://github.com/ChaoMa93/Sobolev-Reg-of-SGD.
Dataset
For the FashionMNIST dataset, 5 out of the 10 classes are picked, and images are taken for each class. For the CIFAR10 dataset, the first 2 classes are picked with images per class. For the CIFAR100 dataset, the first 10 classes for picked with images in each class.
Network structures
The fully-connected network has hidden layers, with hidden neurons in each layer. The ReLU activation function is used. The VGG-like network consists of a series of convolution layers and max pooling layers. Each convolution layer has kernel size , and is followed by a ReLU activation function. The max poolings have stride . The order of the layers are
where each number means a convolutional layer with the number being the number of channels, and “M” means a max pooling layer. A fully-connected layer with width follows the last max pooling.
The residual network takes conventional architecture of Resnet. It consists of 6 residual blocks. The number of channels in the blocks are , from the input block to the output block.