Implicit Gradient Regularization

David G. T. Barrett, Benoit Dherin

Introduction

The loss surface of a deep neural network is a mountainous terrain - highly non-convex with a multitude of peaks, plateaus and valleys (Li et al., 2018; Liu et al., 2020). Gradient descent provides a path through this landscape, taking discrete steps in the direction of steepest descent toward a sub-manifold of minima. However, this simple strategy can be just as hazardous as it sounds. For small learning rates, our model is likely to get stuck at the local minima closest to the starting point, which is unlikely to be the most desirable destination. For large learning rates, we run the risk of ricocheting between peaks and diverging. However, for moderate learning rates, gradient descent seems to move away from the closest local minima and move toward flatter regions where test data errors are often smaller (Keskar et al., 2017; Lewkowycz et al., 2020; Li et al., 2019). This phenomenon becomes stronger for larger networks, which also tend to have a smaller test error (Arora et al., 2019a; Belkin et al., 2019; Geiger et al., 2020; Liang & Rakhlin, 2018; Soudry et al., 2018). In addition, models with low test errors are more robust to parameter perturbations (Morcos et al., 2018). Overall, these observations contribute to an emerging view that there is some form of implicit regularization in gradient descent and several sources of implicit regularization have been identified.

We have found a surprising form of implicit regularization hidden within the discrete numerical flow of gradient descent. Gradient descent iterates in discrete steps along the gradient of the loss, so after each step it actually steps off the exact continuous path that minimizes the loss at each point. Instead of following a trajectory down the steepest local gradient, gradient descent follows a shallower path. We show that this trajectory is closer to an exact path along a modified loss surface, which can be calculated using backward error analysis from numerical integration theory (Hairer et al., 2006). Our core idea is that the discrepancy between the original loss surface and this modified loss surface is a form of implicit regularization (Theorem 3.1, Section 3).

We begin by calculating the discrepancy between the modified loss and the original loss using backward error analysis and find that it is proportional to the second moment of the loss gradients, which we call Implicit Gradient Regularization (IGR). Using differential geometry, we show that IGR is also proportional to the square of the loss surface slope, indicating that it encourages optimization paths with shallower slopes and optima discovery in flatter regions of the loss surface. Next, we explore the properties of this regularization in deep neural networks such as MLP’s trained to classify MNIST digits and ResNets trained to classify CIFAR-10 images and in a tractable two-parameter model. In these cases, we verify that IGR effectively encourages models toward minima in the vicinity of small gradient values, in flatter regions with shallower slopes, and that these minima have low test error, consistent with previous observations. We find that IGR can account for the observation that learning rate size is correlated with test accuracy and model robustness. Finally, we demonstrate that IGR can be used as an explicit regularizer, allowing us to directly strengthen this regularization beyond the maximum possible implicit gradient regularization strength.

The modified loss landscape induced by gradient descent

Now, even though gradient descent takes steps in the direction of the steepest loss gradient, it does not stay on the exact continuous path of the steepest loss gradient, because each iteration steps off the exact continuous path. Instead, we show that gradient descent follows a path that is closer to the exact continuous path given by θ˙=−∇θE~(θ)\dot{\theta}=-\nabla_{\theta}\widetilde{E}(\theta), along a modified loss E~(θ)\widetilde{E}(\theta), which can be calculated analytically using backward error analysis (see Theorem 3.1 and Section 3), yielding:

Immediately, we see that this modified loss is composed of the original training loss E(θ)E(\theta) and an additional term, which we interpret as a regularizer RIG(θ)R_{IG}(\theta) with regularization rate λ\lambda. We call RIG(θ)R_{IG}(\theta) the implicit gradient regularizer because it penalizes regions of the loss landscape that have large gradient values, and because it is implicit in gradient descent, rather than being explicitly added to our loss.

Definition. Implicit gradient regularization is the implicit regularisation behaviour originating from the use of discrete update steps in gradient descent, as characterized by Equation 2.

We can now make several predictions about IGR which we will explore in experiments:

IGR encourages smaller values of RIG(θ)R_{IG}(\theta) relative to the loss E(θ)E(\theta).

Given Equation 2 and Theorem 3.1, we expect gradient descent to follow trajectories that have relatively small values of RIG(θ)R_{IG}(\theta). It is already well known that gradient descent converges by reducing the loss gradient so it is important to note that this prediction describes the relative size of RIG(θ)R_{IG}(\theta) along the trajectory of gradient descent. To expose this phenomena in experiments, great care must be taken when comparing different gradient descent trajectories. For instance, in our deep learning experiments, we compare models at the iteration time of maximum test accuracy (and we consider other controls in the appendix), which is an important time point for practical applications and is not trivially determined by the speed of learning (Figures 1, 2). Also, related to this, since the regularization rate λ\lambda is proportional to the learning rate hh and network size mm (Equation 3), we expect that larger models and larger learning rates will encourage smaller values of RIG(θ)R_{IG}(\theta) (Figure 2).

IGR encourages the discovery of flatter optima.

In section 3 we will show that RIG(θ)R_{IG}(\theta) is proportional to the square of the loss surface slope. Given this and Prediction 2.1, we expect that IGR will guide gradient descent along paths with shallower loss surface slopes, thereby encouraging the discovery of flatter, broader optima. Of course, it is possible to construct loss surfaces at odds with this (such as a Mexican-hat loss surface, where all minima are equally flat). However, we will provide experimental support for this using loss surfaces that are of widespread interest in deep learning, such as MLPs trained on MNIST (Figure 1, 2, 3).

Given Prediction 2.2, we predict that IGR encourages higher test accuracy since flatter minima are known empirically to coincide with higher test accuracy (Figure 2).

IGR encourages the discovery of optima that are more robust to parameter perturbations.

There are several important observations to make about the properties of IGR: 1) It does not originate in any specific model architecture or initialization, although our analysis does provide a formula to explain the influence of these model properties through IGR; 2) Other sources of implicit regularization also have an impact on learning, alongside IGR, and the relative importance of these contributions will likely depend on model architecture and initialization; 3) In defining λ\lambda and RIGR_{IG} we chose to set λ\lambda proportional to the number of parameters mm. To support this choice, we demonstrate in experiments that the test accuracy is controlled by the IGR rate λ\lambda. 4) The modified loss and the original loss share the same global minima, so IGR vanishes when the gradient vanishes. Despite this, the presence of IGR has an impact on learning since it changes the trajectory of gradient descent, and in over-parameterized models this can cause the final parameters to reach different solutions. 5) Our theoretical results are derived for full-batch gradient descent, which allows us to isolate the source of implicit regularisation from the stochasticity of stochastic gradient descent (SGD). Extending our theoretical results to SGD is considerably more complicated, and as such, is beyond the scope of this paper. However, in some of our experiments, we will demonstrate that IGR persists in SGD, which is especially important for deep learning. Next, we will provide a proof for Theorem 3.1, and we will provide experimental support for our predictions.

Backward error analysis of gradient descent

In this section, we show that gradient descent follows the gradient flow of the modified loss E~\widetilde{E} (Equation 2) more closely than that of the original loss EE. The argument is a standard argument from the backward error analysis of Runge-Kutta methods (Hairer et al., 2006). We begin by observing that gradient descent (Equation 1) can be interpreted as a Runge-Kutta method numerically integrating the following ODE:

In the language of numerical analysis, gradient descent is the explicit Euler method numerically integrating the vector field f(θ)=−∇E(θ)f(\theta)=-\nabla E(\theta). The explicit Euler method is of order 1, which means that after one gradient descent step θn=θn−1−h∇E(θn−1)\theta_{n}=\theta_{n-1}-h\nabla E(\theta_{n-1}), the deviation from the gradient flow ∥θn−θ(h)∥\|\theta_{n}-\theta(h)\| is of order O(h2)\mathcal{O}(h^{2}), where θ(h)\theta(h) is the solution of Equation 5 starting at θn−1\theta_{n-1} and evaluated at time hh. Backward error analysis was developed to deal with this discrepancy between the discrete steps of a Runge-Kutta method and the continuous exact solutions (or flow) of a differential equation. The main idea is to modify the ODE vector field θ˙=f(θ)\dot{\theta}=f(\theta) with corrections in powers of the step size

yielding f1(θ)=−f′(θ)f(θ)/2f_{1}(\theta)=-f^{\prime}(\theta)f(\theta)/2. Now, when ff is a gradient vector field with f=−∇Ef=-\nabla E, we find:

where Dθ2ED_{\theta}^{2}E is the Hessian of E(θ)E(\theta). Putting this together, we obtain the first order modified equation:

which is a gradient system with modified loss

A direct application of a standard result in backward error analysis (Hairer & Lubich (1997), Thm. 1) indicates that the learning rate range where the gradient flow of the modified loss provides a good approximation of gradient descent lies below h0=CR/Mh_{0}=CR/M, where ∇E\nabla E is analytic and bounded by M in a ball of radius RR around the initialization point and where CC depends on the Runge-Kutta method only, which can be estimated for gradient descent. We call this the moderate learning rate regime. For each learning rate below h0h_{0}, we can provably find an optimal truncation of the modified equation whose gradient flow is exponentially close to the steps of gradient descent, so the higher term corrections are likely to contribute to the dynamics. Given this, we see that the exact value of the upper bound for the moderate regime will correspond to a setting where the optimal truncation is the first order correction only. Calculating this in general is difficult and beyond the scope of this paper. Nonetheless, our experiments strongly suggest that this moderate learning rate regime overlaps substantially with the learning rate range typically used in deep learning.

This proposition is an immediate consequence of Theorem 3.1 and Corollary A.6.1 in Appendix A.2. It tells us that gradient descent with higher amounts of implicit regularization (higher learning rate) will implicitly minimize the loss surface slope locally along with the original training loss. Prediction 2.2 claims that this local effect of implicit slope regularization accumulates into the global effect of directing gradient descent trajectories toward global minima in regions surrounded by shallower slopes - toward flatter (or broader) minima.

It is important to note that IGR does not help gradient descent to escape from local minima. In the learning rate regime where the truncated modified equation gives a good approximation for gradient descent, the steps of gradient descent follow the gradient flow of the modified loss closely. As Proposition A.10 shows, the local minima of the original loss are still local minima of the modified loss so gradient descent within this learning rate regime remains trapped within the basin of attraction of these minima. IGR does not lead to an escape from local minima, but instead, encourages a shallower path toward flatter solutions close to the submanifold of global interpolating minima, which the modified loss shares with the original loss (Proposition A.10).

Explicit Gradient Regularization

For overparameterized models, we predict that the strength of IGR relative to the original loss can be controlled by increasing the learning rate hh (Prediction 2.1). However, gradient descent becomes unstable when the learning rate becomes too large. For applications where we wish to increase the strength of IGR beyond this point, we can take inspiration from implicit gradient regularization to motivate Explicit Gradient Regularization (EGR), which we define as:

where, μ\mu is the explicit regularization rate, which is a hyper-parameter that we are free to choose, unlike the implicit regularization rate λ\lambda (Equation 3) which can only by controlled indirectly. Now, we can do gradient descent on EμE_{\mu} with small learning rates and large μ\mu.

Although EGR is not the primary focus of our work, we will demonstrate the effectiveness of EGR for a simple two parameter model in the next section (Section 5) and for a ResNet trained on Cifar-10 (Figure 3c). Our EGR experiments act as control study in this work, to demonstrate that the RIGR_{IG} term arising implicitly in gradient descent can indeed improve test accuracy independent of confounding effects that may arise when we control IGR implicitly through the learning rate. Namely, if we had not observed a significant boost in model test accuracy by adding the RIGR_{IG} term explicitly, our prediction that implicit regularization helps to boost test accuracy would have been in doubt.

Related work: Explicit regularization using gradient penalties has a long history. In early work, Drucker & Le Cun (1992) used a gradient penalty (using input gradients instead of parameter gradients). Hochreiter & Schmidhuber (1997) introduced a regularization penalty to guide gradient descent toward flat minima. EGR is also reminiscent of other regularizers such as dropout, which similarly encourages robust parameterizations (Morcos et al., 2018; Srivastava et al., 2014; Tartaglione et al., 2018). More recently, loss gradient penalties have been used to stabilize GAN training (Nagarajan & Kolter, 2017; Balduzzi et al., 2018; Mescheder et al., 2017; Qin et al., 2020). The success of these explicit regularizers demonstrates the importance of this type of regularization in deep learning.

IGR and EGR in a 2-d linear model

We can understand these observations using Theorem 3.1, which predicts that gradient descent is closer to the modified flow given by a˙=−∇aE~(a,b)\dot{a}=-\nabla_{a}\widetilde{E}(a,b) and b˙=−∇bE~(a,b)\dot{b}=-\nabla_{b}\widetilde{E}(a,b) where E~(a,b)=E(a,b)+λRIG(a,b)\widetilde{E}(a,b)=E(a,b)+\lambda R_{IG}(a,b) is the modified loss from Equation 2, RIG(a,b)=(∣a∣2+∣b∣2)x2E(a,b)R_{IG}(a,b)=\left(|a|^{2}+|b|^{2}\right)x^{2}E(a,b) is the implicit regularization term from Equation 4 and λ=h/2\lambda=h/2 is the implicit regularization rate from Equation 3, with learning rate hh. Although the modified loss and the original loss have the same global minima, they generate different flows. Solving the modified flow equations numerically starting from the same initial point (a0,b0)(a_{0},b_{0}) as before, we find that the gradient descent trajectory is closer to the modified flow than the exact flow, consistent with Theorem 3.1 (Figure 1a).

Next, we investigate Prediction 2.1, that the strength of the implicit gradient regularization RIG(a,b)R_{IG}(a,b) relative to the original loss E(a,b)E(a,b) can be controlled by increasing the regularization rate λ\lambda. In this case, this means that larger learning rates should produce gradient descent trajectories that lead to minima with a smaller value of RIG(a,b)/E(a,b)=x2(∣a∣2+∣b∣2)R_{IG}(a,b)/E(a,b)=x^{2}\left(|a|^{2}+|b|^{2}\right). It is interesting to note that this is proportional to the parameter norm, and also, to the square of the loss surface slope. In our numerical experiments, we find that larger learning rates lead to minima with smaller L2 norm (Figure 1b), closer to the flatter region in the parameter plane, consistent with Prediction 2.1 and 2.2. The extent to which we can strengthen IGR in this way is restricted by the learning rate. For excessively large learning rates, gradient descent ricochets from peak to peak, until it either diverges or lands in the direct vicinity of a minimum, which is sensitively dependent on initialization (Figure A.1).

To go beyond the limits of implicit gradient regularization, we can explicitly regularize this model using Equation 8 to obtain a regularized loss Eμ(a,b)=E(a,b)+μ(∣a∣2+∣b∣2)x2E(a,b)E_{\mu}(a,b)=E(a,b)+\mu\left(|a|^{2}+|b|^{2}\right)x^{2}E(a,b). Now, if we numerically integrate a˙=−∇aEμ(a,b)\dot{a}=-\nabla_{a}E_{\mu}(a,b) and b˙=−∇bEμ(a,b)\dot{b}=-\nabla_{b}E_{\mu}(a,b) starting from the same initial point (a0,b0)(a_{0},b_{0}), using a very large explicit regularization rate μ\mu (and using gradient descent with a very small learning rate hh for numerical integration, see Appendix A.4) we find that this flow leads to global minima with a small L2 norm (Figure 1a) in the flattest region of the loss surface. This is not possible with IGR, since it would require learning rates so large that gradient descent would diverge.

IGR and EGR in deep neural networks

Next, we empirically investigate implicit gradient regularization and explicit gradient regularization in deep neural networks. We consider a selection of MLPs trained to classify MNIST digits and we also investigate Resnet-18 trained to classify CIFAR-10 images. All our models are implemented using Haiku (Hennigan et al., 2020).

To begin, we measure the size of implicit regularization in MLPs trained to classify MNIST digits with a variety of different learning rates and network sizes (Figure 2). Specifically, we train 5-layer MLPs with nln_{l} units per layer, where nl∈{50,100,200,400,800,1600}n_{l}\in\{50,100,200,400,800,1600\}, h∈{0.5,0.1,0.05,0.01,0.005,0.001,0.0005}h\in\{0.5,0.1,0.05,0.01,0.005,0.001,0.0005\}, using ReLu activation functions and a cross entropy loss (see Appendix A.5 for further details and see Figures A.3, A.4 and A.5 for training and test data curves). We report RIGR_{IG} and test accuracy at the time of maximum test accuracy for each network that fits the training data exactly. We choose this time point for comparison because it is important for practical applications. We find that RIGR_{IG} is smaller for larger learning rates and larger networks (Figure 2a), consistent with Theorem 3.1 and Prediction 2.1. Next, we measure the loss surface slope in 5-layer MLPs, with 400 units per layer, trained to classify MNIST digits with a range of different learning rates. We find that neural networks with larger learning rates, and hence, with stronger IGR have smaller slopes at the time of maximum test accuracy (Figure 3a). We also measure the loss surface slope in the vicinity of these optima. To do this, we add multiplicative Gaussian noise to every parameter according to θp=θ(1+η)\theta_{p}=\theta(1+\eta), where θ\theta are the parameters of a fully trained model and θp\theta_{p} are the parameters after the addition of noise, where η∼N(0,σ)\eta\sim\mathcal{N}(0,\sigma). We find that neural networks trained with larger learning rates have flatter slopes and these slopes remain small following larger perturbations (Figure 3a). These numerical results are consistent with our prediction that IGR encourages the discovery of flatter optima (Prediction 2.2)

Next, we observe that improvements in test set accuracy are correlated with increases in regularization rate (Figure 2b), and also with increases in learning rate and network size (Figure A.6). This is consistent with Prediction 2.3. Furthermore, the correlation between test set accuracy and network size mm supports our use of network size scaling in Equation 3 and 4.

Next, we explore the robustness of deep neural networks in response to parameter perturbations. In previous work, it has been reported that deep neural networks are robust to a substantial amount of parameter noise, and that this robustness is stronger in networks with higher test accuracy (Morcos et al., 2018). We measure the degradation in classification accuracy as we increase the amount of multiplicative Gaussian noise and find that neural networks with larger learning rates, and hence, with stronger IGR, are more robust to parameter perturbations after training (Figure 3c), consistent with Prediction 2.4. This may explain the origin, in part, of deep neural network robustness.

We also explore IGR in several other settings. For ResNet-18 models trained on CIFAR-10, we find that RIGR_{IG} is smaller and test accuracy is higher for larger learning rates (at the time of maximum test accuracy) (Figure A.7, A.8), consistent again with Theorem 3.1 and Predictions 2.1 and 2.3. We also explore IGR using different stopping time criteria (other than the time of maximum test accuracy), such as fixed iteration time (Figures A.3, A.4), and fixed physical time (Figure A.5) (where iteration time is rescaled by the learning rate, see Appendix A.5 for further information). We explore IGR for full batch gradient descent and for stochastic gradient descent (SGD) with a variety of different batch sizes (Figure A.6) and in all these cases, our numerical experiments are consistent with Theorem 3.1. These supplementary experiments are designed to control for the presence, and absence, of other sources of implicit regularisation - such as model architecture choice, SGD stochasticity and the choice of stopping time criteria.

Finally, we provide an initial demonstration of explicit gradient regularization (EGR). Specifically, we train a ResNet-18 using our explicit gradient regularizer (Equation 8) and we observe that EGR produces a boost of more than 12% in test accuracy (see Figure 3c). This initial experiment indicates that EGR may be a useful tool for training of neural networks, in some situations, especially where IGR cannot be increased with larger learning rates, which happens, for instance, when learning rates are so large that gradient descent diverges. However, EGR is not the primary focus of our work here, but for IGR, which is our primary focus, this experiment provides further evidence that IGR may play an important role as a regularizer in deep learning.

Related work

Implicit regularization: Many different sources of implicit regularization have been identified, including early-stopping (Hardt et al., 2016), model initialization (Glorot & Bengio, 2010; Li & Liang, 2018; Nagarajan & Kolter, 2018; Gunasekar et al., 2018; Zhang et al., 2019; Zou et al., 2019), model architecture (Li et al., 2018; Lin & Tegmark, 2016; Ma et al., 2020), stochasticity (Keskar et al., 2017; Soudry et al., 2018; Roberts, 2018; Ali et al., 2020; Chaudhari & Soatto, 2018; De & Smith, 2020; Mandt et al., 2017; Park et al., 2019; Sagun et al., 2017; Smith & Le, 2018; Wilson et al., 2017; Jastrzebski et al., 2021), implicit L2 regularity (Soudry et al., 2018; Neyshabur et al., 2015; Ali et al., 2019; Ji & Telgarsky, 2019; Nacson et al., 2019; Poggio et al., 2019; Suggala et al., 2018), low rank biases (Arora et al., 2019a; Gunasekar et al., 2017; Razin & Cohen, 2020) among other possibilities. A number of studies have investigated implicit regularization in the discrete steps of gradient descent for specific datasets, losses, or architectures (Soudry et al., 2018; Neyshabur et al., 2015; Gidel et al., 2019). IGR might also be useful for understanding implicit regularization in deep matrix factorization with gradient descent (Arora et al., 2019a; Gunasekar et al., 2017; Razin & Cohen, 2020), where gradient descent seems to have a low-rank bias. Our work may also provide a useful perspective on the break-even point in deep learning (Jastrzebski et al., 2021). At a break-even point our backward analysis suggests that gradient descent with large learning rates will move toward flatter regions, consistent with this work. Stochastic effects are also likely to contribute to the trajectory at break-even points.

Learning rate schedules and regimes: Implicit gradient regularization can be used to understand the role of learning schedules, since learning rate controls the relative strength of implicit regularization and loss optimization. For example, for a cyclical learning rate schedule (Smith, 2017), cyclically varying learning rates between large and small learning rates can be interpreted as a cyclical variation between large and small amounts of IGR (i.e., alternate phases of optimization and regularization). A number of studies have identified various learning rates regimes characterized by different convergence and generalization properties. For instance Li et al. (2019) identifies a small learning rate regime where a network tends to memorize and a large learning rate regime characterized by increased generalization power. This is consistent with IGR which we believe is most useful at the start of training, orienting the search toward flatter regions, and less important in later stages of the training, when a flatter region has been reached, and where convergence to any of the flatter minima is more important. This is also consistent with Jastrzebski et al. (2021) who showed the importance of large learning rates at the beginning of training in encouraging more favourable optimization trajectories. Also Lewkowycz et al. (2020) identifies a lazy phase, a catapult phase, and a divergent phase, which may be related to the range of backward error analysis applicability.

Neural Tangent Kernel: The Neural Tangent Kernel (NTK) is especially interesting (Arora et al., 2019b; c; Chizat & Bach, 2019; Jacot et al., 2018; Lee et al., 2019; Oymak & Soltanolkotabi, 2019; Woodworth et al., 2020; Cao & Gu, 2019) since, in the case of the least square loss, the IGR term RIGR_{IG} can be related to the NTK (see Appendix A.3). This is particularly interesting because it suggests that the NTK may play a role beyond the kernel regime, into the rich regime. In this context, IGR is also related to the trace of the Fisher Information Matrix (Karakida et al., 2019).

Runge-Kutta methods: To the best of our knowledge, backward analysis has not been used previously to investigate implicit regularization in gradient based optimizers. However, Runge-Kutta methods have been used to understand old (and devise new) gradient-based optimization methods (Betancourt et al., 2018; Scieur et al., 2017; Zhang et al., 2018; França et al., 2020). A stochastic version of the modified equation was used (Li et al., 2017; Feng et al., 2020) to study stochastic gradient descent in the context of stochastic differential equations and diffusion equations with a focus on convergence and adaptive learning, and very recently França et al. (2020) used backward analysis to devise new optimizers to control convergence and stability.

Discussion

Following our backward error analysis, we now understand gradient descent as an algorithm that effectively optimizes a modified loss with an implicit regularization term arising through the discrete nature of gradient descent. This leads to several predictions that we confirm experimentally: (i) IGR penalizes the second moment of the loss gradients (Prediction 2.1), and consequently, (ii) it penalizes minima in the vicinity of large gradients and encourages flat broad minima in the vicinity of small gradients (Prediction 2.2); (iii) these broad minima are known to have low test errors, and consistent with this, we find that IGR produces minima with low test error (Prediction 2.3); (iv) the strength of regularization is proportional to the learning rate and network size (Equation 3), (v) consequently, networks with small learning rates or fewer parameters or both will have less IGR and worse test error, and (vi) solutions with high IGR are more robust to parameter perturbations (Prediction 2.4).

It can be difficult to study implicit regularization experimentally because it is not always possible to control the impact of various alternative sources of implicit regularization. Our analytic approach to the study of implicit regularization in gradient descent allows us to identify the properties of implicit gradient regularization independent of other sources of implicit regularization. In our experimental work, we take great care to choose models and datasets that were sufficiently simple to allow us to clearly expose implicit gradient regularization, yet, sufficiently expressive to provide insight into larger, less tractable settings. For many state-of-the-art deep neural networks trained on large real-world datasets, IGR is likely to be just one component of a more complex recipe of implicit and explicit regularization. However, given that many of the favourable properties of deep neural networks such as low test error capabilities and parameter robustness are consistent with IGR, it is possible that IGR is an important piece of the regularization recipe.

There are many worthwhile directions for further work. In particular, it would be interesting to use backward error analysis to calculate the modified loss and implicit regularization for other widely used optimizers such as momentum, Adam and RMSprop. It would also be interesting to explore the properties of higher order modified loss corrections. Although this is outside the scope of our work here, we have provided formulae for several higher order terms in the appendix. More generally, we hope that our work demonstrates the utility of combining ideas and methods from backward analysis, geometric numerical integration theory and machine learning and we hope that our contribution supports future work in this direction.

We would like to thank Ernst Hairer, Samuel Smith, Soham De, Mihaela Rosca, Yan Wu, Chongli Qin, Mélanie Rey, Yee Whye Teh, Sébastien Racaniere, Razvan Pascanu, Daan Wierstra, Ethan Dyer, Aitor Lewkowycz, Guy Gur-Ari, Michael Munn, David Cohen, Alejandro Cabrera and Shakir Mohamed for helpful discussion and feedback. We would like to thank Alex Goldin, Guy Scully, Elspeth White and Patrick Cole for their support. We would also like to thank our families, especially Wendy; Susie, Colm and Fiona for their support, especially during these coronavirus times.

References

Appendix A Appendix

In this section, we provide formulae for higher order backward analysis correction terms for the explicit Euler method, including the first order correction which is required to complete the proof of Theorem 3.1.

We start by restating the general problem addressed by backward error analysis. To begin, consider a first order differential equation

so that the numeric method steps now exactly follow the (formal) solution of the modified equation:

In other words, if θ(t)\theta(t) is the solution of the modified equation (A.4) and θn\theta_{n} is the nthn^{th} discrete step of the numerical method, now one has:

To derive the corrections fif_{i}’s for the explicit Euler method, it is enough to consider a single step of gradient descent θ+hf(θ)\theta+hf(\theta) and identify the corresponding powers of hh in

by expanding the solution θ(h)\theta(h) of the modified equation (A.4) starting at θ\theta into its Taylor series at zero:

For a gradient flow f(θ)=−∇E(θ)f(\theta)=-\nabla E(\theta) its Jacobian f′(θ)f^{\prime}(\theta) is symmetric. In this case, it is natural to look for a modified vector field whose Jacobian is still symmetric (i.e., the higher order corrections can be expressed as gradients). If we assume this, we have the following expression for the higher derivatives of the modified flow solution:

where dn−2dtn−2ddθg(θ)\frac{d^{n-2}}{dt^{n-2}}\frac{d}{d\theta}g(\theta) is shorthand to denote the operator \frac{d^{n-2}}{dt^{n-2}}_{\big{|}t=0}\frac{d}{d\theta}_{\big{|}\theta=\theta(t)}g(\theta) and θ(t)\theta(t) is the solution of the modified equation A.4. We will will use this shorthand notation throughout this section.

The previous lemma gives a formula for the derivatives θ(n)(0)\theta^{(n)}(0). However in order to compare the powers of hh we need to expand these derivatives into power of hh, which is what the next lemma does:

with f0(θ)f_{0}(\theta) being the original vector field f(θ)f(\theta), and ⟨ , ⟩\langle\,,\,\rangle denoting the inner product of two vectors.

Putting everything together, we now obtain a Taylor series for the solution of the modified equation as a formal power series in hh:

where f0f_{0} is the original vector field ff, H0=0H_{0}=0 and we define recursively

Replacing θ(n)(0)\theta^{(n)}(0) by their expression in (A.10) in the Taylor series (A.6), we obtain

Now comparing the Taylor series for the modified equation solution in its last form in (A.12) with one step of the Euler method

for each order of hh. Observe that this formula is yet not fully developped in hh since the terms Hl(θ)H_{l}(\theta) contain a dependency in hh through the fif_{i}’s. Therefore we can not readily identify flf_{l} with −Hl-H_{l}, but rather we obtain the following proposition:

The corrections fif_{i}’s for the Euler method modified equation in (A.3) are given by the general recursive formula:

Let us use (A.14) to compute the first order correction in the modified equation for the Euler explicit method:

Suppose f=−∇Ef=-\nabla E, then the first order correction is

which is the only correction we use in Theorem 3.1. The remarkable thing is that now the first two terms of (A.3) can be understood as the gradient of a modified function, yielding the following form for the modified equation (A.4):

A.2 Geometry of implicit gradient regularization

In this section, we provide all the details for a proof of Proposition 3.3 and for our claim concerning the relationship between the loss surface slope and the implicit gradient regularizer, which we package in Corollary A.6.1. The geometry underlying implicit gradient regularization makes it apparent that gradient descent has a bias toward flat minima .

for i=1,…,mi=1,\dots,m and where the 11 is at the ithi^{th} position. Now that we have the tangent vectors, we can verify that the following vector is the normal vector, since its inner product with all the tangent vectors is zero and its norm is one:

We can compute the cosine of the angle between the normal vector N(θ)N(\theta) at (θ,E(θ))(\theta,E(\theta)) and the vector z^=(0,…,0,1)\hat{z}=(0,\dots,0,1) that is perpendicular to the parameter plane by taking the inner product between these two vectors, immediately yielding the following Proposition:

Consider a loss EE and its loss surface SS as above. The cosine of the angle between the normal vector N(θ)N(\theta) to the loss surface at (θ,E(θ))(\theta,E(\theta)) and the vector z^=(0,…,0,1)\hat{z}=(0,\dots,0,1) perpendicular to the parameter plane can be expressed in terms of the implicit gradient regularizer as follows:

Now observe that if ⟨N(θ),z^⟩\langle N(\theta),\hat{z}\rangle is zero this means that the tangent plane to SS at (θ,E(θ))(\theta,E(\theta)) is orthogonal to the parameter space, in which case the loss surface slope is maximal and infinite at this point! On the contrary, when ⟨N(θ),z^⟩\langle N(\theta),\hat{z}\rangle is equal to 1, the tangent plane at (θ,E(θ))(\theta,E(\theta)) is parallel to the parameter plane, making SS look like a plateau in a neighborhood of this point.

Let us make precise what we mean by loss surface slope. First notice that the angle between z^\hat{z} (which is the unit vector normal to the parameter plane) and N(θ)N(\theta) (which is the vector normal to the tangent plane to SS) coincides with the angle between this two planes. We denote by α(θ)\alpha(\theta) this angle:

Now, we define the loss surface slope at (θ,E(θ))(\theta,E(\theta)) by the usual formula

As we expect, when the loss surface slope is zero this means that the tangent plane to the loss surface is parallel to the parameter plane (i.e., α(θ)=0\alpha(\theta)=0), while when the slope goes to infinity it means the tangent plane is orthogonal to the parameter plane (i.e., α(θ)=π/2\alpha(\theta)=\pi/2).

The following corollary makes it clear that implicit gradient regularization in gradient descent orients the parameter search for minima toward flatter regions of the parameter space, or flat minima, which have been found to be more robust and to possess more generalization power (see Keskar et al. , Hochreiter & Schmidhuber ):

The slope of the loss surface SS at (θ,E(θ))(\theta,E(\theta)) can be expressed in terms of the implicit gradient regularizer as follows:

From (A.15) and the fact that cos⁡α(θ)=⟨N(θ), z^⟩\cos\alpha(\theta)=\langle N(\theta),\,\hat{z}\rangle, we have that

Now basic trigonometry tells us that in general 1/cos⁡2α=1+tan⁡2α1/\cos^{2}\alpha=1+\tan^{2}\alpha, which implies here that tan⁡2α(θ)=mRIG(θ)\tan^{2}\alpha(\theta)=mR_{IG}(\theta). Taking the square root of this last expression finishes the proof. ∎

This makes it clear that this explicit regularization drives the model toward flat minima (with zero slope).

There is another connection between IGR and the underlying geometry of the loss surface through the metric tensor. It is a well-known fact from Riemannian geometry that the metric tensor g(θ)g(\theta) for surfaces in the Monge parameterization θ→(θ,E(θ))\theta\rightarrow(\theta,E(\theta)) has the following form:

where δij\delta_{ij} is the Kronecker delta. Now the determinant ∣g∣|g|, which defines the local infinitesimal volume element on the loss surface, can also be expressed in terms of the implicit gradient regularizer: Namely, ∣g(θ)∣=1+∥∇E(θ)∥2=1+mRIG(θ).|g(\theta)|=1+\|\nabla E(\theta)\|^{2}=1+mR_{IG}(\theta). Solving this equation above for RIGR_{IG}, we obtain a geometric definition for the implicit gradient regularizer:

which incidentally is zero when the surface looks like an Euclidean space.

We conclude this section by showing that the increase in parameter norm can be bounded by the loss surface slope at each gradient descent step.

Let θn\theta_{n} be the parameter vector after nn gradient descent updates. Then the increase in parameter norm is controlled by the loss surface slope as follows:

The triangle inequality applied to one step of gradient descent ∥θn+1∥=∥θn−h∇E(θn)∥\|\theta_{n+1}\|=\|\theta_{n}-h\nabla E(\theta_{n})\| yields (∥θn+1∥−∥θn∥)≤h∥∇E(θn)∥(\|\theta_{n+1}\|-\|\theta_{n}\|)\leq h\|\nabla E(\theta_{n})\|, which concludes the proof, since the gradient norm coincides with the loss surface slope. ∎

Let EE be a non-negative loss. Then local minima of EE are local minima of the modified loss E~\widetilde{E}. Moreover, the two losses have the same interpolating solutions (i.e., locus of zeros).

Since ∇E~=∇E+h2D2E∇E\nabla\widetilde{E}=\nabla E+\frac{h}{2}D^{2}E\nabla E, where D2ED^{2}E is the Hessian of EE, it is clear that a critical point of EE is a critical point of E~\widetilde{E}. Suppose now that θ∗\theta^{*} is a local minimum of EE. This means that there is a neighbourhood of θ∗\theta^{*} where E(θ)≥E(θ∗)E(\theta)\geq E(\theta^{*}). We can add h4∥∇E(θ)∥2\frac{h}{4}\|\nabla E(\theta)\|^{2} on the left of this inequality, since it is a positive quantity, and we can also add h4∥∇E(θ∗)∥2\frac{h}{4}\|\nabla E(\theta^{*})\|^{2} on the right of the inequality, since it is zero. This shows that in a neighborhood of θ∗\theta^{*}, we also have that E~(θ)≥E~(θ∗)\widetilde{E}(\theta)\geq\widetilde{E}(\theta^{*}). This means that θ∗\theta^{*} is also a local minimum of E~\widetilde{E}. Finally, let us see that EE and E~\widetilde{E} share the same locus of zeros. Let θ\theta be a zero of EE. Since EE is non-negative and E(θ)=0E(\theta)=0 then θ\theta is a global minima, which implies that ∇E(θ)=0\nabla E(\theta)=0 also, and hence E~(θ)=0\widetilde{E}(\theta)=0. Now for positive EE, E~(θ)=0\widetilde{E}(\theta)=0 trivially implies E(θ)=0.E(\theta)=0. ∎

A.3 The NTK connection

In the case of the least square loss, the modified equation as well as the implicit gradient regularizer take a very particular form, involving the Neural Tangent Kernel (NTK) introduced in Jacot et al. .

where KθK_{\theta} is the Neural Tangent Kernel defined by

since ∇ϵi(θ)=∇θfθ(xi)\nabla\epsilon_{i}(\theta)=\nabla_{\theta}f_{\theta}(x_{i}) is a matrix. Using that result, we can compute the implicit gradient regularizer in this case:

For the least square loss, we see that the IGR is expressed in terms of the NTK. Therefore the NTK entries will tend to be minimized during gradient descent. In particular, the cross terms Kθ(xi,xj)K_{\theta}(x_{i},x_{j}) will be pushed to zero. This means that gradient descent will push the maximum error direction ∇ϵk(θ)\nabla\epsilon_{k}(\theta) at different data points to be orthogonal to each other (i.e., ∇ϵk(θ)T∇ϵl(θ)≃0\nabla\epsilon_{k}(\theta)^{T}\nabla\epsilon_{l}(\theta)\simeq 0). This is good, since a gradient update is nothing other than a weighted sum of these error directions. If they are orthogonal, this means that the gradient update contribution at point xkx_{k} will not affect the gradient update contribution at point xlx_{l}, so the individual data point corrections are less likely to nullifying each other as gradient descent progresses.

A.4 Experiment details for the 2-d linear model

In this section, we provide supplementary results (Figure A.1), hyper-parameter values (Table A.1) and modified loss derivations for the two parameter model described in Section 5. This model has a loss given by:

The implicit regularization term for this model can be calculated using Equation 4, yielding:

The implicit regularization rate can be calculated using Equation 3, yielding:

The modified loss can be calculated using Equation 2, yielding:

Here, we can see that the global minima for E(a,b)E(a,b) (i.e. the zeros) are the same as the global minima for E~(a,b)\widetilde{E}(a,b) since 1+λ(a2+b2)x21+\lambda\left(a^{2}+b^{2}\right)x^{2} is positive. However, as we will see, the corresponding gradient flows are different.

The exact modified gradient flow for the modified loss is given by:

The exact gradient flow for the original loss is given by

The exact numerical flow of gradient descent is given by

where (an,bn)(a_{n},b_{n}) are the parameters at iteration step nn. For this model, we have ∇aE=−bx(y−abx)\nabla_{a}E=-bx(y-abx) and ∇bE=−ax(y−abx)\nabla_{b}E=-ax(y-abx).

In vector notation, we see that the modified gradient flow equation is

with θ=(a,b)\theta=(a,b). The last term −(2λx2E)θ-(2\lambda x^{2}E)\theta is a central vector field re-orienting the original vector field ∇E\nabla E away from the steepest slopes and toward the origin which coincides in this example with flatter regions where the minimal norm global minima are located. This phenomenon becomes stronger for parameters further away from the origin, where, coincidentally the slopes are the steepest. Specifically, slope⁡(θ)=∥θ∥∣x∣2E\operatorname{slope}(\theta)=\|\theta\||x|\sqrt{2E}.

In Figure 1a, we plot the trajectories of four different flows starting from the same initial point (a0,b0)(a_{0},b_{0}), to illustrate the impact of IGR. We look at two initial points, chosen to illustrate the behaviour of gradient descent in different settings. The full set of hyper-parameters used for this experiment is given in Table A.1. First, we calculate the numerical flow of gradient descent with a small learning rate hSh_{S} using Equation A.4. Next, we plot the numerical flow of gradient descent with a moderate learning rate hMh_{M} using Equation A.4. We then calculate the modified gradient flow by solving Equation A.4 numerically using the Euler method, starting from initial point (a0,b0)(a_{0},b_{0}) and using λ=hM/2\lambda=h_{M}/2. For this numerical calculation, we use a very small Euler method step size hEulerh_{Euler} so that the Euler method follows the gradient flow of the modified loss accurately. We observe that this modified flow is close to the numerical flow of gradient descent, consistent with Theorem 3.1.

We also plot the trajectory of gradient descent for a large learning rate hLh_{L}, where backward analysis is no longer applicable (Fig. A.1) and observe that gradient descent ricochets across the loss surface, stepping over line attractors until it lands in a low gradient region of the loss surface where it converges toward a global minima. This large learning rate regime can be unstable. For larger learning rates, or for different initial positions, we observe that gradient descent can diverge in this regime.

In Figure 1b, we explore the asymptotic behaviour of gradient descent by measuring R/ER/E after convergence for a range of models, all initialized at a0=2.8a_{0}=2.8 and b0=3.5b_{0}=3.5, with a range of learning rates.

We also explore the impact of explicit gradient regularization, using Equation 8 to define the explicitly regularized modified loss for our two-parameter model:

We use this modified loss for gradient descent:

Here, we have used a very small learning rate, hEulerh_{Euler} (Table A.1) and a very large value of μ\mu (Table A.1). This allows us to achieve stronger regularization, since μ\mu can be increased to a large value where gradient descent with h=2μh=2\mu would diverge. We observe that EGR can decrease the size of RIGR_{IG} after training (Figure 1a) and can increase test accuracy (Figure A.2).

A.5 Deep neural network experiment details

In this section, we provide further details for the calculation of RIG(θ)R_{IG}(\theta) in a deep neural network (Figure 2, 3, A.3, A.4, A.5, A.6, A.7, A.8). For all these experiments, we use JAX and Haiku to automatically differentiate and train deep neural networks for classification. Conveniently, the loss gradients that we compute with automatic differentiation are the same loss gradients that we need for the calculation of RIG(θ)R_{IG}(\theta).

We calculate the size of implicit gradient regularization RIG(θ)R_{IG}(\theta), during model training, using Equation 4. We observe that RIG(θ)R_{IG}(\theta), the loss E(θ)E(\theta) and the ratio RIG/E(θ)R_{IG}/E(\theta) all decrease as training progresses, for all learning rates considered (Figure A.3). We also observe that the parameter magnitudes grow during training, and this growth slows as RIG(θ)R_{IG}(\theta) becomes small, in agreement with Proposition A.9. After a sufficiently large fixed number of training steps, we see that models with larger learning rates have much smaller values of RIG(θ)R_{IG}(\theta) relative to E(θ)E(\theta), which appears to be consistent with Prediction 2.1. However, the speed of learning clearly depends on the learning rate hh so it may not be reasonable to compare models after a fixed number of training iterations. Instead of stopping after a fixed number of iterations, we could stop training after n=T/hn=T/h iterations, where TT is the fixed physical time that naturally occurs in our backward analysis (Equation A.5). Again, we find that models with larger learning rates have lower values of RIG(θ)R_{IG}(\theta) and E(θ)E(\theta) after a sufficiently large amount of physical training time TT (Figure A.5). However, even for fixed physical time comparisons, we still need to choose an arbitrary physical time point TT for making comparisons between models. The choice of stopping time is effectively an unavoidable form of implicit regularization. Instead of fixed iteration time or fixed physical time, we use the time of maximum test accuracy as the stopping time for model comparison in Figure 2, 3 and A.6. We choose this option because it is the most useful time point for most real-world applications. For each model, we calculate E(θ)E(\theta), RIG(θ)R_{IG}(\theta) and the test accuracy at the time of maximum test accuracy (which will be a different iteration time for each model) (Figure A.4). The observation that (i) fixed iteration stopping time, (ii) fixed physical stopping time, and (iii) maximum test accuracy stopping time all have smaller values of RIG(θ)/E(θ)R_{IG}(\theta)/E(\theta) for larger values of λ\lambda, consistent with Prediction 2.1, indicates that the relationships between these quantities cannot be trivially explained to be a consequence of a particular choice stopping time regularization. In these examples, we use nl=400n_{l}=400 (corresponding to ∼9.6×106\sim 9.6\times 10^{6} parameters) with batch size 32.

In Figure 2 and Figure A.6 we report RIG(θ)R_{IG}(\theta) and test accuracy at the time of maximum test accuracy for a selection of networks of different size, trained with different learning rates. For models with sufficient capacity to solve the training task and simultaneously minimize RIG(θ)R_{IG}(\theta), we expect RIG(θ)/ER_{IG}(\theta)/E and test error to decrease as λ\lambda increases (Prediction 2.1 and 2.3). To expose this behaviour, we exclude models that fail to reach 100%100\% MNIST training accuracy, such as models that diverge (in the large learning rate regime), and models with excessively small learning rates, which fail to solve the task, even after long training periods. We observe that test error is strongly correlated with the size of RIGR_{IG} after training (Figure A.6). We also confirm this for a range of batch sizes, including full batch gradient descent (Figure A.6, top right) with nl=400n_{l}=400, and for SGD with batch size 32 across a range of learning rates and network sizes (Figure A.6, bottom right).

Finally, to explore IGR and EGR for a larger model we trained a ResNet-18 to classify CIFAR-10 images using Haiku . We used stochastic gradient descent for the training with a batch size of 512 for a range of learning rates l∈{0.005,0.01,0.05,0.1,0.2}l\in\{0.005,0.01,0.05,0.1,0.2\}. We observe the same behaviour as in the MNIST experiments: as the learning rate increases, the values of RIGR_{IG} decrease (Prediction 2.1), the test accuracy increases (Prediction 2.3) and the optimization paths follow shallower slopes leading to broader minima (Prediction 2.2). The experimental results are summarized by the training curves displayed in Figure A.7 and in Figure A.8, where we plot the relation between learning rate, RIGR_{IG}, and test accuracy taken at the time of maximum test accuracy for each training curve.