On the Validity of Modeling SGD with Stochastic Differential Equations (SDEs)
Zhiyuan Li, Sadhika Malladi, Sanjeev Arora
Introduction
Training with Stochastic Gradient Gescent (SGD) (1) and finite learning rate (LR) is largely considered essential for getting best performance out of deep nets: using infinitesimal LR (which turns the process into Gradient Flow (GF)) or finite LR with full gradients results in noticeably worse test error despite sometimes giving better training error [Wu et al., 2020, Smith et al., 2020, Bjorck et al., 2018].
Mathematical explorations of the implicit bias of finite-LR SGD toward good generalization have focused on the noise arising from gradients being estimated from small batches. This has motivated modeling SGD as a stochastic process and, in particular, studying Stochastic Differential Equations (SDEs) to understand the evolution of net parameters.
Early attempts to analyze the effect of noise try to model it as as a fixed Gaussian [Jastrzebski et al., 2017, Mandt et al., 2017]. Current approaches approximate SGD using a parameter-dependent noise distribution that match the first and second order moments of of the SGD (Equation 2). It is important to realize that this approximation is heuristic for finite LR, meaning it is not known whether the two trajectories actually track each other closely. Experimental verification seems difficult because simulating the (continuous) SDE requires full gradient/noise computation over suitably fine time intervals. Recently, Li et al. [2017, 2019a] provided a rigorous proof that the trajectories are arbitrarily close in a natural sense, but the proof needs the LR of SGD to be an unrealistically small (unspecified) constant so the approximation remains heuristic.
Setting aside the issue of correctness of the SDE approximation, there is no doubt it has yielded important insights of practical importance, especially the linear scaling rule (LSR; see Definition 2.1) relating batch size and optimal LR, which allows much faster training using high parallelism [Krizhevsky, 2014, Goyal et al., 2017]. However, since the scaling rule depends upon the validity of the SDE approximation, it is not mathematically understood when the rule fails. (Empirical investigation, with some intuition based upon analysis of simpler models, appears in [Smith et al., 2020, Goyal et al., 2017].)
This paper casts new light on the SDE approximation via the following contributions:
A new and efficient numerical method, Stochastic Variance Amplified Gradient (SVAG), to test if the trajectories of SGD and its corresponding SDE are close for a given model, dataset, and hyperparameter configuration. In Theorem 4.3, we prove (using ideas similar to Li et al. [2019a]) that SVAG provides an order-1 weak approximation to the corresponding SDE. (Section 4)
Empirical testing showing that the trajectory under SVAG converges and closely follows SGD, suggesting (in combination with the previous result) that the SDE approximation can be a meaningful approach to understanding the implicit bias of SGD in deep learning.
New theoretical insight into the observation in [Goyal et al., 2017, Smith et al., 2020] that linear scaling rule fails at large LR/batch sizes (Section 5). It applies to networks that use normalization layers (scale-invariant nets in Arora et al. [2019b]), which includes most popular architectures. We give a necessary condition for the SDE approximation to hold: at equilibrium, the gradient norm must be smaller than its variance.
Preliminaries and Overview
where each is an i.i.d. random variable with the same distribution as . Taking learning rate (LR) toward turns SGD into (deterministic) Gradient Descent (GD) with infinitesimal LR, also called Gradient Flow. Infinitesimal LR is more compatible with traditional calculus-based analyses, but SGD with finite LR yields the best generalization properties in practice. Stochastic processes give a way to (heuristically) model SGD as a continuous-time evolution (i.e., stochastic differential equation or SDE) without ignoring the crucial role of noise. Driven by the intuition that the benefit SGD depends primarily on the covariance of noise in gradient estimation (and not, say, the higher moments), researchers arrived at following SDE for parameter vector :
The SDE view—specifically, the belief in key role played by noise covariance—motivated the famous Linear Scaling Rule, a rule of thumb to train models with large minibatch sizes (e.g., in highly parallel architectures) by changing LR proportionately, thereby preserving the scale of the gradient noise.
[Krizhevsky, 2014, Goyal et al., 2017] When multiplying the minibatch size by , multiply the learning rate (LR) also by .
If the SDE approximation accurately captures the SGD dynamics for a specific training setting, then LSR should work; however, LSR can work even when the SDE approximation fails. We hope to (1) understand when and why the SDE approximation can fail and (2) provide provable and practically applicable guidance on when LSR can fail. Experimentally verifying if the SDE approximation is valid is computationally challenging, because it requires repeatedly computing the full gradient and the noise covariance at each iteration, e.g. the Euler-Maruyama method (3), which is called Noisy Gradient Descent in the rest of the paper. We are not aware of any empirical verification using conventional techniques, which we discuss in more detail in Section A.1. Section 4 gives a new, tractable simulation algorithm, SVAG, and presents theory and experiments suggesting it is a reasonably good approximation to both the SDE and SGD.
Two stochastic processes (e.g., SGD and SDE) track each other closely if they lead to similar distributions on outcomes (e.g., trained nets). Mathematics formulates closeness of distributions in terms of expectations of suitable classes of test functions The discriminator net in GANs is an example of test function in machine learning.; see Section 4.2. The test functions of greatest interest for ML are of course train and test error. These do not satisfy formal conditions such as differentiability assumed in classical theory but can be still used in experiments (see Figure 4). Section 5 uses test functions such as weight norm , gradient norm and trace of noise covariance and proves a sufficient condition for the failure of SDE approximation.
Mathematical analyses of closeness of SGD and SDE will often consider the discrete process
where . A basic step in analysis will be the following Error Decomposition:
Understanding the failure caused by discretization error: In Section 5, a testable condition of SDE approximation is derived for scale-invariant nets (i.e. nets using normalization layers). This condition only involves the Noise-Signal-Ratio, but not the shape of the noise. We further extend this condition to LSR and develops a method predicting the largest batch size at which LSR succeeds, which only takes a single run with small batch size.
1 Understanding the Role of Non-Gaussian Noise
Some works have challenged the traditional assumption that SGD noise is Gaussian. Simsekli et al. , Nguyen et al. suggested that SGD noise is heavy-tailed, which Zhou et al. claimed causes adaptive gradient methods to generalize better than SGD. Xie et al. argued that the experimental evidence in [Simsekli et al., 2019] made strong assumptions on the nature of the gradient noise, and we furthermore prove in Section B.3 that their measurement method could flag Gaussian distributions as non-Gaussian. Below, we clarify how the Gaussian noise assumption interacts with our findings.
Non-Gaussian noise is not essential to SGD performance. We provide experimental evidence in Figure 3 and Section F.3 that SGD (1) and NGD (3) with matching covariances achieve similar test performance on CIFAR10 ( ), suggesting that even if the gradient noise in SGD is non-Gaussian, modeling it by a Gaussian estimation is sufficient to understand generalization properties. Similar experiments were conducted in [Wu et al., 2020] but used SGD with momentum and BatchNorm, which prevents the covariance of NGD noise from being equal to that of SGD. These findings confirm the conclusion in [Cheng et al., 2020] that differences in the third-and-higher moments in SGD noise don’t affect the test accuracy significantly, though differences in the second moments do.
LSR can work when SDE approximation fails. We note that [Smith et al., 2020] derives LSR (Definition 2.1) by assuming the Itô SDE approximation (2) holds, but in fact the validity of the SDE approximation is a sufficient but not necessary condition for LSR to work. In Section B.1, we provide a concrete example where LSR holds for all LRs and batch sizes, but the dynamics are constantly away from the Itô SDE limit. This example also illustrates that the failure of the SDE approximation can be caused solely by non-Gaussian noise, even when there is no discretization error (i.e., the loss landscape and noise distribution are parameter-independent).
SVAG does not require Gaussian gradient noise. In Section 4, we present an efficient algorithm SVAG to simulate the Itô SDE corresponding to a given training setting. In particular, Theorem 4.3 reveals that SVAG simultaneously causes the discretization error and the gap by non-Gaussian noise to disappear as it converges to the SDE approximation. From Figure 4 and Section F.1, we can observe that for vision tasks, the test accuracy of deep nets trained by SGD in standard settings stays the same when interpolating towards SDE via SVAG, suggesting that neither the potentially non-Gaussian nature of SGD noise nor the discrete nature of SGD dynamics is an essential ingredient of the generalization mystery of deep learning.
Related Work
Applications of the SDE approximation in deep learning. One component of the SDE approximation is the gradient noise distribution. When the noise is an isotropic Gaussian distribution (i.e., ), then the equilibrium of the SDE is the Gibbs distribution. Shi et al. used an isotropic Gaussian noise assumption to derive a convergence rate on SGD that clarifies the role of the LR during training. Several works have relaxed the isotropic assumption but assume the noise is constant. Mandt et al. assumed the covariance is locally constant to show that SGD can be used to perform Bayesian posterior inference. Zhu et al. argued that when constant but anisotropic SGD noise aligns with the Hessian of the loss, SGD is able to more effectively escape sharp minima.
Recently, many works have used the most common form of the SDE approximation (2) with parameter-dependent noise covariance. Li et al. and Kunin et al. used the symmetry of loss (scale invariance) to derive properties of dynamics (i.e., ). Li et al. further used this property to explain the phenomenon of sudden rising error after LR decay in training. Smith et al. used the SDE to derive the linear scaling rule (Goyal et al. and Definition 2.1) for infinitesimally small LR. Xie et al. constructed a SDE-motivated diffusion model to propose why SGD favors flat minima during optimization. Cheng et al. analyzed MCMC-like continuous dynamics and construct an algorithm that provably converges to this limit, although their dynamics do not model SGD.
Theoretical Foundations of the SDE approximation for SGD. Despite the popularity of using SDEs to study SGD, theoretical justification for this approximation has generally relied upon tiny LR [Li et al., 2019a, Hu et al., 2019]. Cheng et al. proved a strong approximation result for an SDE and MCMC-like dynamics, but not SGD. Wu et al. argued that gradient descent with Gaussian noise can generalize as well as SGD, but their convergence proof also relied on an infinitesimally small LR.
LR and Batch Size. It is well known that using large batch size or small LR will lead to worse generalization [Bengio, 2012, LeCun et al., 2012]. According to [Keskar et al., 2017], generalization is harmed by the tendency for large-batch training to converge to sharp minima, but Dinh et al. argued that the invariance in ReLU networks can permit sharp minima to generalize well too. Li et al. [2019b] argued that the LR can change the order in which patterns are learned in a non-homogeneous synthetic dataset. Several works [Hoffer et al., 2017, Smith and Le, 2018, Chaudhari and Soatto, 2018, Smith et al., 2018] have had success using a larger LR to preserve the scale of the gradient noise and hence maintain the generalization properties of small-batch training. The relationship between LR and generalization remains hazy, as [Shallue et al., 2019] empirically demonstrated that the generalization error can depend on many other training hyperparameters.
Stochastic Variance Amplified Gradient (SVAG)
Experimental verification of the SDE approximation appears computationally intractable by traditional methods. We provide an algorithm, Stochastic Variance Amplified Gradient (SVAG), that efficiently simulates and provably converges to the Itô SDE (2) for a given training setting (Theorem 4.3). Moreover, we use SVAG to experimentally verify that the SDE approximation closely tracks SGD for many common settings (Figure 4; additional settings in Appendix F).
where with sampled independently and
2 SVAG Approximates the SDE
Let and be families of continuous and discrete stochastic processes parametrized by . We say and are order- weak approximations of each other if for every , there is a constant independent of such that
We now show that SVAG converges weakly to the Itô SDE approximation in (2) when , i.e., and have the roughly same distribution. Figure 1 highlights the differences between our result and [Li et al., 2019a]. Figure 4 provide verification of the below theorem, and additional settings are studied in Appendix F.
Suppose the following conditionsThe smoothness assumptions can be relaxed by using the mollification technique in Li et al. [2019a]. are met:
is -smooth in .
Let be a constant and be the SVAG hyperparameter (5). Define as the stochastic process (independent of ) satisfying the Itô SDE (2) and as the trajectory of SVAG (5) where . Then, SVAG is an order- weak approximation of the SDE , i.e. for each , there exists a constant independent of such that
Lipschitz conditions like (ii) are often not met by deep learning objectives. For instance using normalization schemes can make derivatives unbounded, but if the trajectory stays bounded away from the origin and infinity, then (ii) holds.
3 Proof Overview
Let denote the stochastic process obeying the Itô SDE (2) starting from time and with the initial condition and denote the stochastic process (depending on ) satisfying SVAG (5) with initial condition . For convenience, we define and write . Alternatively, we write and .
Now for any , we interpolate between a SVAG solution and SDE solution through a series of hybrid trajectories , i.e., the weight achieved by running SVAG for the first steps and then SDE from time to . The two limits of the interpolation are (i.e., SVAG solution after steps) and (i.e., SDE solution after time). This yields the following error decomposition for a test function (see Definition 4.1).
Note that each pair of adjacent hybrid trajectories only differ by a single step of SVAG or SDE. We show that the one-step increments of SVAG and SDE are close in distribution along the entire trajectory by computing their moments (Lemmas 4.5 and 4.6). Then, using the Taylor expansion of , we can show that the single-step approximation error from switching from SVAG to SDE is uniformly upper bounded by . Hence, the total error is .
Define the one-step increment of the Itô SDE as . Then we have
Define the one-step increment of SVAG as . Then we have
Though (i) and (ii) in Lemma 4.6 hold for any discrete update with LR that matches the first and second order moments of SDE (2), (iii) and (iv) could fail. For example, when decreasing LR according to LSR (Definition 2.1), even if we can use a fractional batch size and sample an infinitely divisible noise distribution, we may arrive at a different continuous limit if (iii) and (iv) are not satisfied. (See a more detailed discussion in Section B.2) SVAG is not the unique way to ensure (iii) and (iv), and any other design (e.g. using three copies per step and with different weights) satisfying Lemma 4.6 are also first order approximations of SDE (2), by the same proof.
Understanding the Failure of SDE Approximation and LSR
To quantify differences in training algorithms, we would ideally work with statistics like the train/test loss and accuracy achieved, but characterizing optimization and generalization properties of deep networks beyond the NTK regime [Jacot et al., 2018, Allen-Zhu et al., 2019b, Du et al., 2019, Arora et al., 2019a, Allen-Zhu et al., 2019a] is in general an open problem.
Therefore, we rely on other natural test functions (Definition 5.1).
In Theorem 5.2, we show that the SDE-approximation of SGD is bound to fail for these scale-invariant nets when LR gets too large. Specifically, using above-mentioned results we show that then equilibrium distributions of SGD and SDE are quite far from each other with respect to expectations of these natural test functions (Definition 5.1).
We will measure the closeness of two distributions by three test functions: squared weight norm , squared gradient norm , and trace of noise covariance . We say two equilibrium distributions are close to each other if expectations of these test functions are within a multiplicative constant.
We call and the noise-to-signal ratio (NSR), and below we show that it plays an important role. When the LR of SGD significantly exceeds the NSR of the corresponding SDE, the approximation fails. Of course, we lack a practical way to calculate NSR of the SDE so this result is existential rather than effective. Therefore we give a condition in terms of NSR of the SGD that suffices to imply failure of the approximation.
Experiments later in the paper show this condition is effective at showing divergence from SDE behavior.
If either (i). or (ii)., then the equilibria of SDE (6) and SGD (7) are not -close.
Since the order-1 approximation fails for large LR, it’s natural to ask if higher-order SDE approximation works. In Theorem E.4 we give a partial answer, that the same gap happens already between order-1 and order-2 SDE approximation, when . This suggests failure of SDE approximation may be due to missing some second order term, and thus higher-order approximation in principle could avoid such failure. On the other hand, when approximation fails in such ways, e.g., increasing batch size along LSR, the performance of SGD degrades while SDE remains good. This suggests the higher-order correction term may not be very helpful for generalization.
2 Failure of Linear Scaling Rule
In this section we derive a similar necessary condition for LSR to hold.
Similar to Definition 5.1, we will use as test functions for equilibrium achieved by SGD (7) when training with LR and mini-batches of size . We first introduce the concept of Linear Scaling Invariance (LSI). Note here we care about the scaled ratio because the covariance scales inversely to batch size, .
We say SGD (7) with batch size and LR exhibits -LSI if, for a constant such that ,
We show below that -LSI fails if the NSR is too small, thereby giving a certificate for failure of -LSI even without a baseline run.
For any , , , and such that
SGD with batch size and LR does not exhibit -LSI.
We now present a simple and efficient procedure to find the largest for which -LSI will hold, providing useful guidance to make hyper-parameter tuning more efficient. Before doing so, one must choose an appropriate value for , which controls how close the test functions must be for us to consider LSR to have “worked.” It is an open question what value of will ensure that the two settings achieve similar test performance, but throughout our experiments across various datasets and architectures in Figure 2 and Appendix F, we find that works well. One can estimate and from a baseline run. Then, one can straightforwardly compute the value for the threshold given in the theorem below. We conduct this process in Figure 2 and Appendix F to test our theory.
SGD with batch size and LR does not exhibit -LSI.
Experiments
Figure 2 provides experimental evidence that measurements from a single baseline run can be used to predict when LSR will break, thereby providing verification for Theorem 5.6. Surprisingly, it turns out the condition in Theorem 5.6 is not only sufficient but also close to necessary.
Figure 4 and Section F.1 test SVAG on common architectures and datasets and report the results. Theorem 4.3 shows that SVAG converges to the SDE as , but we note that SVAG needs times as many steps as SGD to match the SDE. Therefore, in order for SVAG to be a computationally efficient simulation of the SDE, we hope to observe convergence for small values of . This is confirmed in Figure 4 and Section F.1. The success of SVAG in matching SGD in many cases indicates that studying the Itô SDE can yield insights about the behavior of SGD. Moreover, in the case where we expect the SDE approximation to fail (e.g., when LSR fails), SVAG does indeed converge to a different limiting trajectory from the SGD trajectory.
Conclusion
We present a computationally efficient simulation SVAG (Section 4) that provably converges to the canonical order-1 SDE (2), which we use to verify that the SDE is a meaningful approximation for SGD in common deep learning settings (Section 6). We relate the discretization error to LSR (Definition 2.1): in Section 5 we derive a testable necessary condition for the SDE approximation and LSR to hold, and in Figure 2 we demonstrate its applicability to standard settings.
Acknowledgement
The authors acknowledge support from NSF, ONR, Simons Foundation, Schmidt Foundation, Mozilla Research, Amazon Research, DARPA and SRC. ZL is also supported by Microsoft Research PhD Fellowship.
References
Appendix A Preliminaries on SDE
Here, we review the common approximation schemes for SDEs and discuss why they are not efficient enough to be applied to the Itô SDE approximation for SGD. We adapt the information in Chapters 13 and 14 of . In general, an Itô SDE can be written as
where and are called the drift and diffusion coefficients respectively. The standard Itô SDE (2) used to approximate SGD sets and .
Suppose we want to solve the SDE on a time interval . First, we discretize the time interval into equal steps of size . We will construct a Markov chain that is a weak approximation in (Definition 4.2) to the true solution, and let where is the initialization for the SGD trajectory.
where . In the ML setting, computing a single step in this Markov chain requires computing the full gradient (for ) and the covariance of the gradient (for ). As such, modeling a single step in the recurrence requires making one pass over the entire dataset. The error of the approximation scheme scales with , so making larger (thereby requiring more recurrence steps) will improve the quality of the approximate solution. We furthermore note that storing the gradient covariance matrix requires a large amount of memory. Each weight parameter in the network must be modeled by its own recurrence equation, so for modern day deep networks, this approximation seems computationally intractable.
The Euler-Maruyama scheme is considered the simplest approximation scheme for an Itô SDE. A variety of other schemes, such as the Milstein and stochastic Runge-Kutta schemes, have been derived by adding a higher order corrective term, taken from the stochastic Taylor expansion, to the recurrence computation. In particular, these schemes all still require the computation of and at each step of the recurrence, so they remain computationally intractable for the Itô SDE used to approximate SGD.
A.2 Preliminary on Stochastic Process
We call a -dimensional stochastic process a Lévy process if it satisfies the following properties:
Independence of increments: For any are independent;
Stationary increments: For any is equal in distribution to
Continuity in probability: For any and it holds that
We call a counting process a Poisson process with rate if it satisfies the following properties:
the number of events (or points) in any interval of length is a Poisson random variable with parameter (or mean) .
Appendix B Discussion on Non-Gaussian Noise
In Section B.1 we give an example where LSR holds while SDE approximation breaks. In Section B.2, we show this example to a more general setting – infinitely divisible noise. We also explain why decreasing LR along LSR will not get a better approximation for SDE, while decreasing LR along SVAG will, since both operation preserves the same SDE approximation. In Section B.3, we discuss the possibility where the noise is heavy-tailed and with unbounded covariance.
Let be a -dimensional Poisson process (Definition Definition A.2), where follows Poisson distribution with parameter . We assume the distribution of the gradient on single sampled data , is the same as for any parameter . For a batch of size B (with replacement), since Poisson process has independent increments, .
Thus for any constant and initialization , performing SGD starting from for steps with LR and batch size , the distribution of is independent of , i.e.,
Thus LSR holds for all batch size . Below we consider the corresponding NGD (3), , where
and .
Thus it holds that , where is a Wiener process with , meaning the NGD final iterate is also independent of , and constant away form the final iterate . Indeed we can show the same result for Itô SDE (2), :
Thus we conclude that LSR holds but SDE approximation fails. Since NGD achieves the same distribution as Itô SDE, the gap is solely caused by non-gaussian noise.
However, the reader might still wonder, since batch size is always at least , there’s always a lower bound for LR when going down along the ladder of LSR, and thus a discrete process with a finite step size of course cannot be approximated by a continuous one arbitrarily well. So isn’t this example trivial? In Section B.2, we will see even if we are allowed to use fractional batch size, and thus allow , LSR can still hold without Itô SDE approximation.
B.2 Infinitely Divisible Noise and Lévy SDE
To understand why decreasing LR along LSR will not get a better approximation for SDE, and how LSR can hold without Itô SDE approximation when , we assume the noise is infinitely divisible below for simplicity, which allows us to define SGD with fractional batch sizes and thus we can take the limit of along the ladder of LSR.
For SGD with batch size , such a random loss function can be found when is a factor of , where it suffices to define as times the same loss with a smaller batch size .Batch loss of nets with BatchNorm is not necessarily divisble, because (13) doesn’t hold, as the individual loss depends on the entire batch of data with the presence of BN. Still, it holds for ghost BatchNorm with equal to the number of mini-ghost batches. In other words, we can phrase LSR in a more general form, which only involves the distribution of the noise, but not the generating process of the noise (e.g. noise from sampling a batch with replacement).
Keep LR the same. Replace by and multiply the total number of steps by .
Formally, is the solution of the following SDE driven by a Lévy process.
Why decreasing LR along LSR will not get a better approximation for SDE: The Lévy SDE is equal to the Itô SDE only when the noise is strictly Gaussian. Thus the gap induced by non-Gaussian noise will not vanish even if both SGD and NGD decrease the LR along LSR, as it will converge to the gap between Itô SDE and Lévy SDE. See Figure 5 for a summary of the relationships among SGD, NGD, Itô SDE, and Lévy SDE.
Since decreasing LR along LSR converges to a different limit than SVAG does, it’s natural to ask which part of the approximation in Lemma 4.6 fails for the former. By scrutinizing the proof of Lemma 4.6, we can see (i) and (ii) still hold for any stochastic discrete process with LR and matching first and second order moments, while the term now becomes for SGD along LSR, which is larger by an order of . Therefore, the single-step approximation error becomes and the total error after steps remains constant.Such error does not only occur in the third order moment. It also appears in the higher moments. Therefore simply assuming the noise distribution is symmetric (thus ) won’t fix this gap.
SDE approximation is not necessary for LSR, even for LR : We also note that though derives LSR by assuming the Itô SDE approximation holds, this is only a sufficient but not necessary condition for LSR. In Section B.1, we provide a concrete example where LSR holds for all LRs and batch sizes, but the dynamics are constantly away from Itô SDE limit. The loss landscape and noise distribution are constant, i.e., parameter-independent. This is also an example where the gap between SGD and Itô SDE is solely caused by non-gaussian noise, but not the discretization error.
B.3 Heavy-tailed Noise and Unbounded Covariance
experimentally found that the distribution of the SGD noise appears to be heavy-tailed and proposed to model it with an -stable process. In detail, in Figure 1 of , they show that the histogram of the gradient noise computed with AlexNet on CIFAR-10 is more close to that of -stable random variables, instead of that of Gaussian random variables. However, a more recent paper pointed out a fundamental limitation of methodology in : made a hidden but very restrictive assumption that the noise of each parameter in the model is distributed identically. Moreover, their test (Theorem B.3) of the tail-index works only under this assumption. Thus the empirical measurement in () doesn’t exclude the possibility that that stochastic gradient noise follows a joint multivariate Gaussian.
Let be a collection of i.i.d. random variables with and . Define for . Then the estimator
We provide the following theoretical and experimental evidence on vision tasks to support the argument in that it is reasonable to model the stochastic gradient noise by joint Gaussian random variables instead of -stable random variables even for finite learning rate. (Note SVAG (e.g., Figure 4) only shows that when LR becomes infinitesimally small, replacing the noise by Gaussian noise gets similar performance.)
In Figure 2, we find that the trace of covariance of noise is bounded and the empirical average doesn’t grow with the number of samples/batches (this is not plotted in the current paper). However, an -stable random variable has unbounded variance for .
In Figures 3, 19, 18, and 20, we show directly that replacing the stochastic gradient noise by Gaussian noise with the same covariance gets almost the train/test curve and the final performance.
Applying the test in Theorem B.3 on joint multivariate Gaussian random variables can yield an estimate ranged from to for the tail-index , but for Gaussian variables, . (Theorem B.4)
Another recent work also confirmed that the noise in stochastic gradient in ResNet50 on vision tasks is finite. However, they also found the noise for BERT on Wikipedia+Books dataset could be heavy-tailed: the empirical variance is not converging even with samples. We left it as a future work to investigate how does SDE approximate SGD on those tasks or models with heavy-tailed noise.
Specifically, when and , taking , we have
Appendix C Omitted Derivation in Section 4
We prove Theorem 4.3 in this section. The derivation is based on the following two-step process, following the agenda of :
Showing that the approximation error on a finite interval ( steps) can be upper bounded by the sum of expected one-step errors. (Theorem C.1, which is Theorem 3 in )
Showing the one-step approximation error of SVAG is of order , and so the approximation on a finite interval is of order . (Lemmas 4.5 and 4.6)
Let us consider generally the question of the relationship between one-step approximations and approximations on a finite interval. Let and . Let us also denote for convenience . Further, let denote the stochastic process obeying the same Equation 2, but with the initial condition . We similarly write and denote by the stochastic process (depending on ) satisfying Equation 5 but with .
The following result is adapted from to our setting, which relates one-step approximations with approximations on a finite time interval. To prove it, we will construct hybrid trajectories interpolating between SVAG (5) and the SDE (2), as shown in Figure 6.
Then, for each , there exists a constant , independent of , such that
Let , and for convenience we also define . Further, let denote the stochastic process obeying the same Equation 2, but with the initial condition . We similarly write and denote by the stochastic process (depending on ) satisfying Equation 5 but with . Alternatively, we write and . By definition, and .
Thus we have for any , we can decompose the error as illustrated in Figure 6,
By assumption (ii), we know the there is some ,
Suppose uniformly, that is, and there’s a single such that , for and . Let assumption (i),(ii) in Thm. C.1 hold and be such functions. Then, there exists some , independent of , such that
Using Taylor’s theorem with the Lagrange form of the remainder, we have for any ,
Taking expectations over the first term, using assumption (i) of Thm. C.1, we get
Taking expectations over the second term, using assumption (i) of Section C.1 and Lemma D.1, we get
Note that by assumption (ii) of Section C.1, we have
We can deal with the third term similarly to the second term and thus we conclude
C.2 One-step approximation
To obtain (i)-(iii), we simply apply Lem. D.2 with for and respectively. (iv) is due to Lemma D.1. ∎
Next, we estimate the moments of the SVAG iterations below. See 4.6
Recall , where . Taking expectations, (i) and (ii) are immediate. Note , (iv) also holds.
Below we show (iii). For convenience, we denote by , , , for and . We have
Appendix D Auxiliary results for the proof of Thm. 4.3
Let , there exists a , independent of , such that
where and is independent of .
Using Cauchy-Schwarz inequality, Itô’s isometry, we get
where depends only on . Now, using the linear growth condition (4.3 (ii)) and the moment estimates in Theorem 19 in , we obtain the result. ∎
We prove the following Itô-Taylor expansion, which is slightly different from Lemma 28 in .
Suppose that , and is the solution of the following SDE, with .
That is, there exists some function such that
We also prove a general moment estimate for the SVAG iterations Equation 5.
Let be the generalized SVAG iterations defined in Equation 5. Suppose
where are independent of and , which immediately implies, for all ,
Appendix E Omitted proofs in Section 5
In this section, we provide the missing proofs in Section 5, including Theorem 5.5, Theorem 5.6 and the counterpart of Theorem E.4 between st order SDE (2) and nd order SDE (32), which is Theorem E.1. We also provide the derivation of properties for scale invariant functions in Section E.5.
We will prove the theorem by showing the contrapositive statement: if the equilibriums of (7) and (6) are -close, then and . Following the derivation in , by Itô’s lemma and scale invariance of :
It can be shown that for SGD (7), it holds that
If both and have reached their equilibriums, both LHS of (23) and (24) are , and therefore
Applying (8) again, we have ∎
E.2 Proof of Theorem 5.6
Suppose -LSI hold, similar to Equation 25, we have
Thus combining (27) ,(28) and (8), we have
Therefore we conclude that .
E.3 Proof of Theorem 5.5
Suppose -LSI hold, by (8), we have
E.4 Necessary condition for C𝐶C-closeness between 111st order and 222nd order SDE approximation
In this section we will present a necessary condition for -closeness between st order and nd order SDE approximation, similar to that betweeen st order approximation and SGD. The key observation is that the missing second order term in st order SDE, also appears in the nd order SDE, as it does for SGD. Thus we can basically apply the same analysis and show the similar conclusion (Theorem E.4).
Below we recap the st and nd order SDE approximation:
st order SDE approximation (with ):
(32) is an order-2 weak approximation of SGD (1):
The following theorem is an analog of Theorem 5.2.
If the equilibriums of (31) and (32) exist and are -close for some , then
where is usually of scale in practice and thus can be omitted when calculating upper bound.
Since is scale-invariant, so , which implies . Plug in , we have
If we compare Equation 37 to Equations 25 and 26 (we recap them below), it’s quite clear nd order is much closer to SGD in terms of the relationship between , and . Thus st and nd order SDE approximation won’t be -close if is larger than some constant for the exact same reason that st SDE is not -close to SGD.
In detail, by combining (37), (26) and (33), we have
which imples \eta\leq\big{(}C^{2}(1+\frac{\eta\lambda}{2})-1\big{)}\min\{\frac{\overline{N}_{\infty}}{\overline{G}_{\infty}},\frac{\overline{N}_{\infty}^{\prime}}{\overline{G}_{\infty}^{\prime}}\}. ∎
derived a similar equation to Equation 35 in Appendix F of their paper.
E.5 Properties of Scale Invariance Function
These properties are proved in . We include them here for self-containedness.
.
, .
For (1), by chain rule, we have .
, .
Appendix F Experiments
We use the models from Github Repository: https://github.com/bearpaw/pytorch-classification. For VGG and PreResNet, unless noted otherwise, we modified the model following Appendix C of so that the network is scale invariant, e.g., fixing the last layer. Such modification doesn’t lead to change in performance, as shown in . We use Weights & Biases to manage our experiments .
We verify that SVAG converges for different architectures (including ones without normalization), learning rate schedules, and datasets. We further conclude that for most the standard settings we consider (excluding the use of large batch size in Figures 4 and 14 and GroupNorm on CIFAR-100 in Figure 13), SVAG with large achieves similar performance to SGD, i.e. SVAG with .
Theorem 4.3 only holds if each step of SGD is a Markov process, which is in part determined by how each example is sampled from the dataset. We describe three common ways that examples can be sampled from the dataset during training.
Random shuffling (RS): RS is standard practice in experiments and is the default implementation in PyTorch. A random shuffled order of datapoints is fixed at the start of each epoch, and each sample is drawn in this order. SGD with this sampling scheme can be viewed as a Markov process per epoch, although not per step. We use this method in our experiments, but our theory for SVAG (Section 4) does not cover this sampling method.
Without replacement (WOR): WOR requires drawing each sample i.i.d. from the dataset without replacing previously drawn ones. SGD with this sampling scheme can be viewed as a Markov process per step, so our theory for SVAG (Section 4) does cover this case.
With replacement (WR): WR requires drawing each sample i.i.d. from the dataset with replacement. SGD with this sampling scheme can be viewed as a Markov process per step, so our theory for SVAG (Section 4) does cover this case.
In Figure 7, we observe that SVAG (including SGD) behaves similarly when using all three of these sampling methods. Therefore, although our theory does not directly apply to the commonly used RS scheme, we can heuristically apply Theorem 4.3 to understand its behavior.
We furthermore note that our findings do not match the conclusion in that SGD with RS has a different implicit bias compared to WOR and WR. We suggest two possible reasons for this discrepancy: (1) Their result holds when is smaller than an unmeasurable constant, so it may be the case that their results do not apply to the constant LR regime we use SVAG in. (2) Their result concerns behavior after a single epoch and our experiments run for hundreds of epochs.
F.1.2 Further Verification of SVAG on more architectures on CIFAR-10
In Figure 8, we demonstrate that SVAG converges and closely follows SGD for PreResNet32 with BatchNorm (left), PreResNet32 (4x) with BatchNorm (middle) and PreResNet32 with GroupNorm (right).
In Figure 9, we demonstrate that SVAG converges and closely follows SGD for VGG16 without Normalization (left), VGG16 with BatchNorm (middle) and VGG16 with GroupNorm (right).
F.1.3 Further Verification of SVAG on more complex LR schedules
We verify that SVAG converges and closely follows the SGD trajectory for networks trained with more complex learning rate schedules. In Figure 11, we use the triangle (i.e., cyclical) learning rate schedule proposed in , visualized in Figure 10. We implement the schedule over 320 epochs of training: we increase the initial learning rate linearly to over epochs, decay the LR to over the next epochs, increase the LR to over epochs, and decay the LR to over the remaining 80 epochs. As seen in Figure 11, SVAG converges to the SGD trajectory in this setting.
We further test SVAG on the cosine learning rate schedule proposed in with and with total training budgets of epochs. We visualize the schedule in Figure 10. In Figure 12, we see that SVAG converges and closely follows the SGD trajectory, suggesting the SDE (2) can model SGD trajectories with complex learning rate schedules as well.
F.1.4 Further Verification of SVAG on more datasets (CIFAR-100 and SVHN)
F.2 Further Verification of Necessary Condition for LSR
We further verify the necessary condition for LSR (Theorem 5.6) using different architectures and datasets. Figure 15 tests the condition for ResNet-32 and wider PreResNets trained on CIFAR-10. Although our theory requires strict scale-invariance, we find the condition to still be applicable to the standard ResNet architecture , ResNet32, likely because most of the network parameters are scale-invariant. Figure 16 tests the condition for wider PreResNets and VGG-19 trained on CIFAR-100. We require the wider PreResNet to achieve reasonable test error, but we note that the larger model made it difficult to straightforwardly train with a larger batch size.
In Figure 15 and Figure 2, and are the empirical estimations of and taken after reaching equilibrium in the second to last phase (before the final LR decay), where the number of samples (batches) is equal to , and is the batch size.
Per the approximated version of Theorem 5.6, i.e., , we use baseline runs with different batch sizes to report the maximal and minimal predicted critical batch size, defined as the x-coordinate of the intersection of the threshold () with the green and blue lines, respectively. Both the green and blue line have slope , and thus the x-coordinate of intersection, , is the solution of the following equation,
For all settings, we choose a threshold of , and consider LSR to fail if the final test error exceeds the lowest achieved test error by more than 20% of its value, marked by the red region on the plot. Surprisingly, it turns out the condition in Theorem 5.6 is not only necessary, but also close to sufficient.
F.3 Additional Experiments for NGD (Noisy Gradient Descent)
We provide further evidence that SGD (1) and noisy gradient descent (NGD) (3) have similar train and test curves in Figures 18, 19, and 20. To perform NGD, we replace the SGD noise by Gaussian noise with the same covariance as was done in . In , the authors trained a network using BatchNorm, which prevents the covariance of NGD from being exactly equal to that of SGD. Hence, we use GroupNorm in our experiments, which improves NGD accuracy. We note that each step of NGD requires computing the full-batch gradient over the entire dataset (in this case, done through gradient accumulation), which is much more costly than a single SGD step. Each figure took roughly days on a single RTX 2080 GPU.