An Improved Analysis of Stochastic Gradient Descent with Momentum
Yanli Liu, Yuan Gao, Wotao Yin
Introduction
Stochastic gradient methods have been a widespread practice in machine learning. They aim to minimize the following empirical risk:
In general, stochastic gradient methods can be written as
The idea behind SGDM originates from Polyak’s heavy-ball method for deterministic optimization. For strongly convex and smooth objectives, heavy-ball method enjoys an accelerated linear convergence rate over gradient descent . However, the theoretical understanding of its stochastic counterpart is far from being complete.
In the case of fixed stepsize and momentum weight, most of the current results only apply to restrictive settings. In and , the behavior of SGDM on least square regression is analyzed and linear convergence is established. analyzes the local convergence rate of SGDM for strongly convex and smooth functions, where the initial point is assumed to be close enough to the minimizer . provides global convergence of SGDM, but only for objectives with uniformly bounded gradients, thus excluding many machine learning models such as Ridge regression. Very recently, presents a convergence bound of for general smooth nonconvex objectivesHere is the number of iterations. Note that in , a different but equivalent formulation of SGDM is analyzed; their stepsize is effectively in our setting.. When , this recovers the classical convergence bound of of SGD . However, the size of stationary distribution is times larger than that of SGD. This factor is not negligible, especially when large values such as and is applied . Therefore, their result does not explain the competitiveness of SGDM compared to SGD. Concurrent to this work, shows that SGDM converges as fast as SGD under convexity and strong convexity, and that it is asymptotically faster than SGD for overparameterized models. Remarkably, their analysis considers a different stepsize and momentum weight schedule from this work, and applies to arbitrary sampling without assuming the bounded variance of the gradient noise.
In deep learning, SGDM is often applied with various parameter tuning rules to achieve efficient training. One of the most widely adopted rules is called “constant and drop", where a constant stepsize is applied for a long period and is dropped by some constant factor to allow for refined training, while the momentum weight is either kept unchanged (usually ) or gradually increasing. We call this strategy Multistage SGDM and summarize it in Algorithm 1. Practically, (multistage) SGDM was successfully applied to training large-scale neural networks , and it was found that appropriate parameter tuning leads to superior performance . Since then, (multistage) SGDM has become increasingly popular .
At each stage, Multistage SGDM (Algorithm 1) requires three parameters: stepsize, momentum weight, and stage length. In and , doubling argument based rules are analyzed for SGD on strongly convex objectives, where the stage length is doubled whenever the stepsize is halved. Recently, certain stepsize schedules are shown to yield faster convergence for SGD on nonconvex objectives satisfying growth conditions , and a nearly optimal stepsize schedule is provided for SGD on least square regression . These results consider only the momentum-free case. Another recent work focuses on the asymptotic convergence of SGDM (i.e., without convergence rate) , which requires the momentum weights to approach either or , and therefore contradicts the common practice in neural network training. In summary, the convergence rate of Multistage SGDM (Algorithm 1) has not been established except for the momentum-free case, and the role of parameters in different stages is unclear.
In this work, we provide new convergence analysis for SGDM and Multistage SGDM that resolve the aforementioned issues. A comparison of our results with prior work can be found in Table 1.
We show that for both strongly convex and nonconvex objectives, SGDM (2) enjoys the same convergence bound as SGD. This helps explain the empirical observations that SGDM is at least as fast as SGD . Our analysis relies on a new observation that, the update direction of SGDM (2) has a controllable deviation from the current full gradient , and enjoys a smaller variance. Inspired by this, we construct a new Lyapunov function that properly handles this deviation and exploits an auxiliary sequence to take advantage of the reduced variance.
Compared to aforementioned previous work, our analysis applies to not only least squares, does not assume uniformly bounded gradient, and improves the convergence bound.
For the more popular SGDM in the multistage setting (Algorithm 1), we establish its convergence and demonstrate that the multistage strategy are faster at initial stages. Specifically, we allow larger stepsizes in the first few stages to boost initial performance, and smaller stepsizes in the final stages decrease the size of stationary distribution. Theoretically, we properly redefine the aforementioned auxiliary sequence and Lyapunov function to incorporate the stagewise parameters.
To the best of our knowledge, this is the first convergence guarantee for SGDM in the multistage setting.
2 Other related work
Nesterov’s momentum achieves optimal convergence rate in deterministic optimization , and has also been combined with SGD for neural network training . Recently, its multistage version has been analyzed for convex or strongly convex objectives . Other forms of momentum for stochastic optimization include PID Control-based methods , Accelerated SGD , and Quasi-Hyperbolic Momentum . In this work, we restrict ourselves to heavy-ball momentum, which is arguably the most popular form of momentum in current deep learning practice.
Notation and Preliminaries
The following assumption is effective throughout, which is standard in stochastic optimization.
Smoothness: The objective in (1) is smooth.
Independent samples: the random samples are independent.
Unless otherwise noted, all the proof in the paper are deferred to the appendix.
Key Ingredients of Convergence Theory
In this section, we present some key insights for the analysis of stochastic momentum methods. For simplicity, we first focus on the case of fixed stepsize and momentum weight, and make proper generalizations for Multistage SGDM in App. C.
In this section, we make the following observation on the role of momentum:
With a momentum weight , the update vector enjoys a reduced “variance" of , while having a controllable deviation from the full gradient in expectation.
First, without loss of generality, we can take , and express as
is a moving average of the past stochastic gradients, with smaller weights for older onesNote the sum of weights as ..
we have the following result regarding the “variance" of , which is measured between and its deterministic version .
Under Assumption 1, the update vector in SGDM (2) satisfies
Lemma 1 follows directly from the property of the moving average.
On the other hand, is a moving average of all past gradients, which is in contrast to SGD. It seems unclear how far is from the ideal descent direction , which could be unbounded unless stronger assumptions are imposed. Previous analysis such as and make the blanket assumption of bounded to circumvent this difficulty.
In this work, we provide a different perspective to resolve this issue.
From Lemma 2, we know the deviation of from is controllable sum of past successive iterate differences, in the sense that the coefficients decays linearly for older ones. This inspires the construction of a new Lyapunov function to handle the deviation brought by the momentum, as we shall see next.
2 A new Lyapunov function
Let us construct the following Lyapunov function for SGDM:
In the Lyapunov function (5), are positive constants to be specified later corresponding to the deviation described in Lemma 2. Since the coefficients in (4) converges linearly to as , we can choose in a diminishing fashion, such that this deviation can be controlled, and defined in (5) is indeed a Lyapunov function under strongly convex and nonconvex settings (see Propositions 1 and 2).
In (5), is an auxiliary sequence defined as
This auxiliary sequence first appeared in the analysis of deterministic heavy ball methods in , and later applied in the analysis of SGDM . It enjoys the following property.
Since the coefficients of the deviation in Lemma 2 converges linearly to as , we can choose in a diminishing fashion, such that this deviation can be controlled. Remarkably, we shall see in Sec. 4 that with , defined in (5) is indeed a Lyapunov function under strongly convex and nonconvex settings, and that SGDM converges as fast as SGD.
Now, let us turn to the Multistage SGDM (Algorithm 1), which has been very successful in neural network training. However, its convergence still remains unclear except for the momentum-free case. To establish convergence, we require the parameters of Multistage SGDM to satisfy
where and are the stepsize, momentum weight, and stage length of th stage, respectively, and are properly chosen constants. In principle, one applies larger stepsizes at the initial stages, which will accelerate initial convergence, and smaller stepsizes for the final stages, which will shrink the size of final stationary distribution. As a result, (7) stipulates that less iterations are required for stages with large stepsizes and more iterations for stages with small stepsizes. Finally, (7) requires the momentum weights to be monotonically increasing, which is consistent with what’s done in practice . often, using constant momentum weight also works.
Under the parameter choices in (7), let us define the auxiliary sequence by
This sequence reduces to (6) when a constant stepsize and momentum weight are applied. Furthermore, the observations made in Lemmas 1, 2, and 3 can also be generalized (see Lemmas 4, 5, 6, and 7 in App. C). In Sec. 5. we shall see that with (7) and appropriately chosen , in (5) also defines a Lyapunov function in the multistage setting, which in turn leads to the convergence of Multistage SGDM.
Convergence of SGDM
In this section, we proceed to establish the convergence of SGDM described in (2). First, by following the idea presented in Sec. 3, we can show that defined in (5) is a Lyapunov function.
Let Assumption 1 hold. In (2), let . Let in (5) be defined by
By telescoping (9), we obtain the stationary convergence of SGDM under nonconvex settings.
Let Assumption 1 hold. In (2), let . Then,
Now let us turn to the strongly convex setting, for which we have
Let Assumption 1 hold. Assume in addition that is strongly convex. In (2), let . Then, there exists positive constants for (5) such that for all , we have
The choices of is similar to those of Proposition 1 and can be found in App. B.4. With Proposition 2, we immediately have
Let Assumption 1 hold and assume in addition that is strongly convex. Under the same settings as in Proposition 2, for all we have
Let Assumption 1 hold and assume in addition that is strongly convex. Under the same settings as in Proposition 2, for all we have
Under nonconvex settings, the classical convergence bound of SGD is with (see, e.g., Theorem 4.8 of ). Therefore, Theorem 1 tells us that with , SGDM achieves the same convergence bound as SGD.
In contrast, the radius of the stationary distribution for SGDM in and is , and the latter one also assumes that is uniformly bounded.
In Theorem 2 and Corollary 1, the convergence bounds hold for , where is a mild constantFor example, we have for the popular choice ..
The convergence bound of SGD under strong convexity is (see, e.g, Theorem 4.6 of ), our result for SGDM in Corollary 1 recovers this when .
Convergence of Multistage SGDM
In this section, we switch to the Multistage SGDM (Algorithm 1).
Let us first show that when the (7) is applied, we can define the constants properly so that (5) still produces a Lyapunov function.
Let Assumption 1 hold. In Algorithm 1, let the parameters satisfy (7) with . In addition, let
Then, we have for any . Furthermore, with defined in (8), for any , we have
where are the stepsize and momentum weight applied at th iteration, respectively.
Let Assumption 1 hold. Under the same settings as in Proposition 3, let and let be large enough such that
On the left hand side of (11), we have the average of the averaged squared gradient norm of stages.
On the right hand side of (11), the first term dominates at initial stages, we can apply large for these stages to accelerate initial convergence, and use smaller for later stages so that the size of stationary distribution is small. In contrast, (static) SGDM need to use a small stepsize to make the size of stationary distribution with small.
It is unclear whether the overall iteration complexity of Multistage SGDM is better than SGDM or not. Numerically, we do observe that Multistage SGDM is faster. We leave the possible improved analysis of Multistage SGDM to future work.
Experiments
In this section, we verify our theoretical claims by numerical experiments. For each combination of algorithm and training task, training is performed with random seeds . Unless otherwise stated, we report the average of losses of the past batches, where is the number of batches for the whole dataset. Additional implementation details can be found in App. E.
Setup. The MNIST dataset consists of labeled examples of gray-scale images of handwritten digits in classes . For all algorithms, we use batch size (and hence number batches per epoch is ), number of epochs . The regularization parameter is .
The effect of in (static) SGDM. By Theorem 2 we know that, with a fixed , a larger leads to faster loss decrease to the stationary distribution. However, the size of the stationary distribution is also larger. This is well illustrated in Figure 1. For example, and make losses decrease more rapidly than . During later iterations, leads to a lower final loss.
Multistage SGDM. We take stages for Multistage SGDM. The parameters are chosen according to (7): , , , where and .Here, is not set by its theoretical value , since the dataset is very large and the gradient Lipschitz constant cannot be computed easily. We compare Multistage SGDM with SGDM with and , where , are the stepsizes of the first and last stage of Multistage SGDM, respectively. The training losses of initial and later iterations are shown in Figure 2.
We can see that SGDM with converges faster initially, but has a higher final loss; while SGDM with behaves the other way. Multistage SGDM takes the advantage of both, as predicted by Theorem 3. The performances of SGDM and Vanilla SGD with the same stepsize are similar.
2 Image classification
For the task of training ResNet18 on the CIFAR-10 dataset, we compare Multistage SGDM, a baseline SGDM, and YellowFin , an automatic momentum tuner based on heuristics from optimizing strongly convex quadratics. The initial learning rate of YellowFin is set to ,We have experimented with initial learning rates (default), , and , each repeated times; we found that the choice is the best in terms of the final training loss. and other parameters are set as their default values. All algorithms are run for epochs and the batch size is fixed as .
For Multistage SGDM, the parameters choices are governed by (7): the stage lengths are , , and . Take , , set the per-stage stepsizes and momentum weights as and , for stages . For the baseline SGDM, the stepsize schedule of Multistage SGDM is applied, but with a fixed momentum .
In Figure 3, we present training losses and end-of-epoch validation accuracy of the tested algorithms. We can see that Multistage SGDM performs the best. Baseline SGDM is slightly worse, possibly because of its fixed momentum weight.
Summary and Future Directions
In this work, we provide new theoretical insights into the convergence behavior of SGDM and Multistage SGDM. For SGDM, we show that it is as fast as plain SGD in both nonconvex and strongly convex settings. For the widely adopted multistage SGDM, we establish its convergence and show the advantage of stagewise training.
There are still open problems to be addressed. For example, (a) Is it possible to show that SGDM converges faster than SGD for special objectives such as quadratic ones? (b) Are there more efficient parameter choices than (7) that guarantee even faster convergence?
References
Appendix A Proof of Preliminary Lemmas
It is straightforward to see that the same conclusion holds for .
Finally, we know from the item 4 in Assumption 1 that
A.2 Proof of Lemma 2
where we have applied Cauchy-Schwarz in the first inequality.
By applying triangle inequality and the smoothness of (item 1 in Assumption 1), we further have
Therefore, by defining , we get
Furthermore, can be calculated as
Combining this with (12), we finally arrive at
A.3 Proof of Lemma 3
Let us consider the cases of and separately.
Appendix B Main Theory for SGDM
In order to prove Proposition 1, let us first show an auxiliary result.
Take Assumption 1. Then, for defined in (6), we have
where we have applied Lemma 3 in the second step.
where can be any positive constant (to be determined later).
Combining (16) and the last inequality, we arrive at
Since when and when , it can be verified that . Consequently,
On the other hand, from Lemma 1 we know that
Finally, using and gives
B.2 Proof of Proposition 1
where .
In the rest of the proof, let us show that the sum of the last three terms in (22) is non-positive.
Therefore, in order to make the sum of the last three terms of (22) to be non-positive, we need to have
Since , it suffices to enforce the following for all :
And in order for for all , we can determine by
we have and
Notice that ensures .
With the choices of in (23) and (24), the sum of the last three terms of (22) is non-positive. Therefore,
B.3 Proof of Theorem 1
In the rest the proof, we will bound and appropriately.
First, let us show that when as in (26) and .
Since , we have
Therefore, in order to ensure where is defined in (28), it suffices to have
Applying yields
where we have applied in the last step.
Now let us turn to . By (32) we know that
Since , we have
By applying , we further have
By putting (34) and (35) into (30), we finally obtain
B.4 Proof of Proposition 2
In order to prove Proposition 2, we will set
Take in (22), we have
Let us first derive a lower bound of the first term on the right hand side of (36).
where , are to be determined later.
On the other hand, we have from (18) that
Putting these two inequalities into (38) and rearranging gives
Taking and gives
Since , we have that
Therefore, by we have
By combining (44) with (41), we further obtain
In the rest of the proof, we will show that if the constants are chosen such that
Then, we have for all and
And therefore, we will have the desired result:
First of all. by , we know that , and (47) gives
Therefore, in order for (51) to hold, it suffices to set
On the other hand, (50) is also equivalent to
Therefore, in order to have for all , we can set
Since and
for any , (52) is equivalent to
Since , we further have
Since and , it can be verified that for all and . Therefore,
As a result, in order to have (53), it suffices to set
Since , we have
which is exactly our choice of as in (49).
B.5 Proof of Theorem 2
From Proposition 2 we know that for all ,
where we have applied in the last step. Therefore,
By for all and (42), we conclude that
B.6 Proof of Corollary 1
In fact, by (6) we can express as a convex combination of :
The desired result follows directly from the convexity of and Theorem 2.
Appendix C Generalizations of Lemmas 1, 2, and 3 for Multistage SGDM
In order to establish the convergence of Multistage SGDM(Algorithm 1), we need to generalize the Lemmas 1 and 2 , which play a key role in the convergence of SGDM in (2).
Under the assumptions of Theorem 3, the variance of update vector in Algorithm 1 satisfies
where b_{k,i}=\big{(}1-\beta(i)\big{)}\prod_{j=i+1}^{k}\beta(j).
To begin with, let us express by the past stochastic gradients:
where we have applied and defined
It can be verified that the sum of weights is
As a result, by applying Assumption 1 we have
Note that by setting , we have
Under the assumptions of Theorem 3, the update vector in Algorithm 1 satisfies
By setting , we have
C.2 Generalization of Lemma 3 for Multistage SGDM
where is the stepsize applied at the th step.
Recall that the auxiliary sequence is defined by
where and are the stepsize and momentum weight at the th stage, respectively. Therefore, we also have
where are the stepsize and momentum weight applied at the th step. Using this, we obtain
C.3 Generalization of Lemma 2 for Multistage SGDM
In Multistage SGDM(Algorithm 1), assume that the momentum weights at stages satisfy . Then, we have
where b_{k,i}=\big{(}1-\beta(i)\big{)}\prod_{j=i+1}^{k}\beta(j) and is the momentum weight applied at the th iteration, and
By By (55), (56) and (57), we can compute that
where we have used (57) in the first and third equality, and Cauchy-Schwarz in the first inequality. In the last inequality, we have applied the triangle inequality and the smoothness of .
In the Proposition 5 below, we shall see that for all , where is defined in (58). Therefore,
defined in (59) and defined in (58) satisfy
We aim to show that for all . Or equivalently, for all .
In order to show , we just need to show that
Let , where . If , then . If , then .
Since , we have , where .
Now, let us compute the left hand side of (60) explicitly.
where we have applied if and if in the last term. Since
By applying these equalities on (61), we have
On the right hand side, the first terms are non-positive since . Therefore,
By applying and (since ), we arrive at
Now let us consider two cases: and .
In this case, we apply to get
Since , iteration is at the th stage, we have , and the above inequality is exactly what we want to show in (60).
In this case, we apply to get
Since , we have and by we deduce that (Otherwise ). Therefore, we have
which is exactly what we want to show in (60).
Appendix D Main Theory for Multistage SGDM
In this section, we prove the main convergence theory of Multistage SGDM.
Proposition 3 is a generalization of Propositions 4 and 1 to the multistage case. Therefore, its proof is similar to those of Propositions 4 and 1.
First of all, by the smoothness of we have
where we have applied Lemma 6 in the second step. Note that is the stepsize applied at the th iteration.
where can be any positive constant.
By (8) we know that , which leads to
Plugging (65) and (67) into (64) gives us
In the rest of the proof, we will show that the sum of the last three terms in (68) is non-positive.
Therefore, in order to make the sum of the last three terms of (68) to be non-positive, we need to enforce that
Since , , and , we need to enforce the following for all :
Recall that for all stages . This gives us
Since , it suffices to enforce that
Note that the equalities in (70) does not depend on . In order for for all , we can determine by
we have and
Notice that and ensures
With the choices of in (70) and (71), the sum of the last three terms of (68) is non-positive. Therefore,
Taking in (73) gives
Finally, by applying Lemma 4 and Lemma 5, we arrive at
D.2 Proof of Theorem 3
In the rest the proof, we will bound and appropriately.
First, let us show that under as in (69) and .
Therefore, in order for , it suffices to have
By we know that
Therefore, . Furthermore, yields
where in the inequality above, we have applied
Now let us turn to . By (76) and (72) we know that
Since and , we have
By applying Lemmas 4 and 5, we further have
By putting (79) and (80) into (77) with , we obtain
Dividing both sides by gives
Appendix E Details of computational infrastructure
All experiments were performed on a computing server with Intel(R) Core(TM) i9-9940X CPU @ 3.30GHz and NVidia GeForce RTX 2080 P8. The weights of the neural networks are initialized by the default, random initialization routines.