Better Mini-Batch Algorithms via Accelerated Gradient Methods
Andrew Cotter, Ohad Shamir, Nathan Srebro, Karthik Sridharan
Introduction
We consider a stochastic convex optimization problem of the form
A parallel development has been the popularization of accelerated gradient descent methods . In a deterministic optimization setting and for general smooth convex functions, these methods enjoy a rate of (where is the number of iterations) as opposed to using standard methods. However, in a stochastic setting (which is the relevant one for learning problems), the rate of both approaches have an dominant term in general, so the benefit of using accelerated methods for learning problems is not obvious.
In this paper, we study the application of accelerated methods for mini-batch algorithms, and provide theoretical results, a novel algorithm, and empirical experiments. The main resulting message is that by using an appropriate accelerated method, we obtain significantly better stochastic optimization algorithms in terms of convergence speed. Moreover, in certain regimes acceleration is actually necessary in order to allow a significant speedups. The potential benefit of acceleration to mini-batching has been briefly noted in , but here we study this issue in much more depth. In particular, we make the following contributions:
We develop novel convergence bounds for the standard gradient method, which refines the result of by being dependent on , the expected loss of the best predictor in our class. For example, we show that in the regime where the desired suboptimality is comparable or larger than , including in the separable case , mini-batching does not lead to significant speed-ups with standard gradient methods.
We develop a novel variant of the stochastic accelerated gradient method , which is optimized for a mini-batch framework and implicitly adaptive to .
We provide an analysis of our accelerated algorithm, refining the analysis of by being dependent on , and show how it always allows for significant speed-ups via mini-batching, in contrast to standard gradient methods. Moreover, its performance is uniformly superior, at least in terms of theoretical upper bounds.
We provide an empirical study, validating our theoretical observations and the efficacy of our new method.
Preliminaries
We consider stochastic convex optimization problems over some convex domain . Here, we take to be a convex subset of a Euclidean space, and use to denote the standard Euclidean norm. In the Appendix, we state and prove the result in a more general setting, where is a convex subset of a Banach space, and can be an arbitrary norm.(subset of Euclidean case, see Appendix for the more general Banach space case), using an i.i.d. sample drawn from some fixed distribution.
(for more general Banach space case, the norm on the left hand side is the dual norm). Let us denote
We wish to minimize over convex domain . We will provide guarantees on relative to at some , where the guarantees also depend on . We could choose , though our results hold for any , and in some cases we might choose to compete with a low-norm that is not optimal in .
The behavior of the accelerated gradient method also depends on the radius of , defined as:
We discuss two stochastic optimization approaches to deal with this problem: stochastic gradient descent (SGD), and accelerated gradient methods (AG). In a mini-batch setting, both approaches iteratively average sub-gradients with respect to several instances, and use this average to update the predictor. However, the update is done in different ways. In the Appendix, we also provide the form of the update in the more general mirror descent setting, where is an arbitrary norm.
The stochastic gradient descent algorithm is summarized as Algorithm 1. In the pseudocode, refers to the projection on to the ball (under the Euclidean distance). The accelerated gradient method (e.g., ) is summarized as Algorithm 2.
In terms of existing results, for the SGD algorithm we have [4, Section 5.1]
whereas for an accelerated gradient algorithm, we have
where in both cases the dependence on and is suppressed. The above bounds suggest that, as long as , both methods allow us to use a large mini-batch size without significantly degrading the performance of either method. This allows the number of iterations to be smaller, potentially resulting in faster convergence speed. However, these bounds do not show that accelerated methods have a significant advantage over the SGD algorithm, at least when , since both have the same first-order term . To understand the differences between these two methods better, we will need a more refined analysis, to which we now turn.
Convergence Guarantees
The following theorems provide a refined convergence guarantee for the SGD algorithm and the AG algorithm, which improves on the analysis of by being explicitly dependent on , the expected loss of the best predictor in .
For any , using Stochastic Gradient Descent with a step size of , we have:
Note that the radius does not appear in the above bound, which depends only on . This means that could be unbounded, perhaps even the entire space, and a projection step for SGD is not really crucial. The step size, of course, still depends on .
For any , using Accelerated Gradient with step size parameters , where
Unlike for SGD, notice that the bound for the AG method above does depend on , and a projection step is necessary for our analysis. However it is worth noting that only appears in terms of order at least , and appears only mildly in the term, suggesting some robustness to the radius .
We emphasize that Theorem 2 gives more than a theoretical bound: it actually specifies a novel accelerated gradient strategy, where the step size scales polynomially in , in a way dependent on the minibatch size and . While may not be known in advance, it does have the practical implication that choosing for some , as opposed to just choosing as in ), might yield superior results.
We now provide a proof sketch of Theorems 1 and 2. A more general statement of the Theorems as well as a complete proof can be found in the Appendix.
The proof for the stochastic gradient descent bound is mainly based on the proof techniques in and its extension to the mini-batch case in . Following the line of analysis in , one can show that
rearranging and setting appropriately gives the final bound. ∎
The proof of the accelerated method starts in a similar way as in . For the ’a and ’s mentioned in the theorem, following similar lines of analysis as in we get the preliminary bound
Using smoothness, the self bounding property some manipulations, we can further get the bound
Using the as given in the theorem statement, and few simple manipulations, gives the final bound. ∎
Optimizing with Mini-Batches
To compare our two theorems and understand their implications, it will be convenient to treat and as constants, and focus on the more interesting parameters of sample size , minibatch size , and optimal expected loss . Also, we will ignore the logarithmic factor in Theorem 2, since we will mostly be interested in significant (i.e. polynomial) differences between the two algorithms, and it is quite possible that this logarithmic factor is merely an artifact of our analysis. Using , we get that the bound for the SGD algorithm is
and the bound for the accelerated gradient method we propose is
To understand the implication these bounds, we follow the approach described in to analyze large-scale learning algorithms. First, we fix a desired suboptimality parameter , which measures how close to we want to get. Then, we assume that both algorithms are ran till the suboptimality of their outputs is at most . Our goal would be to understand the runtime each algorithm needs, till attaining suboptimality , as a function of .
To measure this runtime, we need to discern two settings here: a parallel setting, where we assume that the mini-batch gradient computations are performed in parallel, and a serial setting, where the gradient computations are performed one after the other. In a parallel setting, we can take the number of iterations as a rough measure of the runtime (note that in both algorithms, the runtime of a single iteration is comparable). In a serial setting, the relevant parameter is , the number of data accesses.
To analyze the dependence on and , we upper bound (5) and (6) by , and invert them to get the bounds on and . Ignoring logarithmic factors, for the SGD algorithm we get
First, let us compare the performance of these two algorithms in the parallel setting, where the relevant parameter to measure runtime is . Analyzing which of the terms in each bound dominates, we get that for the SGD algorithm, there are 2 regimes, while for the AG algorithm, there are 2-3 regimes depending on the relationship between and . The following two tables summarize the situation (again, ignoring constants):
SGD Algorithm Regime n
AG Algorithm Regime n
From the tables, we see that for both methods, there is an initial linear speedup as a function of the minibatch size . However, in the AG algorithm, this linear speedup regime holds for much larger minibatch sizesSince it is easily verified that is generally smaller than both and . Even beyond the linear speedup regime, the AG algorithm still maintains a speedup, for the reasonable case where . Finally, in all regimes, the runtime bound of the AG algorithm is equal or significantly smaller than that of the SGD algorithm.
We now turn to discuss the serial setting, where the runtime is measured in terms of . Inspecting (7) and (8), we see that a larger size of actually requires to increase for both algorithms. This is to be expected, since mini-batching does not lead to large gains in a serial setting. However, using mini-batching in a serial setting might still be beneficial for implementation reasons, resulting in constant-factor improvements in runtime (e.g. saving overhead and loop control, and via pipelining, concurrent memory accesses etc.). In that case, we can at least ask what is the largest mini-batch size that won’t degrade the runtime guarantee by more than a constant. Using our bounds, the mini-batch size for the SGD algorithm can scale as much as , vs. a larger value of for the AG algorithm.
Finally, an interesting point is that the AG algorithm is sometimes actually necessary to obtain significant speed-ups via a mini-batch framework (according to our bounds). Based on the table above, this happens when the desired suboptimality is not much bigger then , i.e. . This includes the “separable” case, , and in general a regime where the “estimation error” and “approximation error” are roughly the same—an arguably very relevant one in machine learning. For the SGD algorithm, the critical mini-batch value can be shown to equal , which is in our case. So with SGD we get no non-constant parallel speedup. However, with AG, we still enjoy a speedup of at least , all the way up to mini-batch size .
Experiments
While both datasets are relatively easy to classify, we also wished to understand the algorithms’ performance in the “separable” case , to see if the theory in Section 4 holds in practice. To this end, we created an additional version of each dataset, where , by training a classifier on the entire dataset and removing margin violations.
In all of our experiments, we used up to half of the data for training, and one-quarter each for validation and testing. The validation set was used to determine the step sizes and . We justify this by noting that our goal is to compare the performance of the SGD and AG algorithms, independently of the difficulties in choosing their stepsizes. In the implementation, we neglected the projection step, as we found it does not significantly affect performance when the stepsizes are properly selected.
In our first set of experiments, we attempted to determine the relationship between the performance of the AG algorithm and the parameter, which determines the rate of increase of the step sizes . Our experiments are summarized in Figure 1. Perhaps the most important conclusion to draw from these plots is that neither the “traditional” choice , nor the constant-step-size choice , give the best performance in all circumstances. Instead, there is a complicated data-dependent relationship between , and the final classifier’s performance. Furthermore, there appears to be a weak trend towards higher performing better for larger minibatch sizes , which corresponds neatly with our theoretical predictions.
In our next experiment, we directly compared the performance of the SGD and AG methods. To do so, we varied the minibatch size while holding the total amount of data used for training, , fixed. When (top row of Figure 2), the total sample size is high and the suboptimality is low (red and black plots), we see that for small minibatch size, both methods do not degrade as we increase , corresponding to a linear parallel speedup. In fact, SGD is actually overall better, but as increases, its performance degrades more quickly, eventually performing worse than AG. That is, even in the least favorable scenario for AG (high and small , see the tables in Section 4), it does give benefits with large enough minibatch sizes. Also, we see that even here, once the suboptimality is roughly equal to , AG significantly outperforms SGD, even with small minibatches, agreeing with our the theory.
Turning to the case (bottom two rows of Figure 2), which is theoretically more favorable to AG, we see it is indeed mostly better, in terms of retaining linear parallel speedups for larger minibatch sizes, even for large data set sizes corresponding to small suboptimality values, and might even be advantageous with small minibatch sizes.
Summary
In this paper, we presented novel contributions to the theory of first order stochastic convex optimization (Theorems 1 and 2, generalizing results of and to be sensitive to ), developed a novel step size strategy for the accelerated method that we used in order to obtain our results and we saw works well in practice, and provided a more refined analysis of the effects of minibatching which paints a different picture then previous analyses and highlights the benefit of accelerated methods.
A remaining open practical and theoretical question is whether the bound of Theorem 2 is tight. Following , the bound is tight for and , i.e. the first and third terms are tight, but it is not clear whether the dependence is indeed necessary. It would be interesting to understand whether with a more refined analysis, or perhaps different step-sizes, we can avoid this term, whether an altogether different algorithm is needed, or whether this term does represent the optimal behavior for any method based on -aggregated stochastic gradient estimates.
References
Appendix A Generalizing to Different Norms
We now turn to general norms and discuss the generic Mirror Descent and Accelerated Mirror Descent algorithms. In this more general case we let domain be some closed convex set of a Banach space equipped with norm . We will use to represent the dual norm of . Further the -smoothness of the loss function in this general case is takes the form that for any and any ,
The generalizations of the SGD and AG methods are summarized in Algorithms 3 and 4 respectively. The key difference between these and the Euclidean case is that the gradient descent step is replaced by a descent step involving gradient mappings of and its conjugate and the projection step is replaced by Bregman projection (projection to set minimizing the Bregman divergence to the point).
as long as , we have that :
Appendix B Complete Proofs
We provide complete proofs of Theorems 3 and 4, noting how Theorems 1 and 2 are specializations to the Euclidean case.
Due to -smoothness of convex function we have that,
We now note that the update step can be written equivalently as
It can be shown that (see for instance Lemma 1 of )
Adding on both sides and removing on the left we conclude that
Writing , so that we get,
Now we shall always pick so that and so
or equivalently we get,
Using Jensen’s inequality concludes the proof. ∎
For Euclidean case and . Plugging these in the previous theorem concludes the proof. ∎
B.2 Accelerated Mirror Descent
For the accelerated update rule, if the step sizes and are chosen such that and for all
We now note that the update step 2 of accelerated gradient can be written equivalently as
It can be shown that (see for instance Lemma 1 of )
Multiplying throughout by we get
Owing to the condition that we have that
Using the above inequality repeatedly we conclude that
Plugging these back in Equation 10 we get :
Dividing throughout by concludes the proof.
Thus we have verified that the step sizes satisfy the conditions required by previous lemma. From the previous lemma we have that
Note that for any by smoothness, Also notice that
. We shall ensure that the we choose will satisfy the above condition. Now applying lemma B.3 we get that for any ,
Plugging this back in Equation 12 we conclude that
We now optimize over the choice of above by using
Ofcourse for the choice of to be valid we need that which gives our second condition on which is
We shall try to now optimize the above bound w.r.t. , To this end set
We first need to verify that this choice of satisfies the conditions in Equation 11 and 13. To this end, note that as for the condition in Equation 11,
and hence it can be easily verified that for , . On the other hand to verify the condition in Equation 13, we need to show that
It can be verified that this condition is satisfied as long as,
So in effect as long as and sample size the conditions are satisfied. Now plugging in this choice of into the bound in Equation 14, we get
Recall that . Now note that if then , on the other hand if then . Hence we can conclude that,
Since and we can conclude that
For Euclidean case and . Plugging these in the previous theorem (along with appropriate step size) we get
The second inequality is a direct consequence of the fact that . ∎
B.3 Some Technical Lemmas
Denote , then for any mean zero vectors drawn iid from any fixed distribution,
where the step before last was due to Fenchel-Young inequality and is simply the convex conjugate of . Now For any define . We claim that
To see this note that since is -strongly convex w.r.t. , by duality is -strongly smooth w.r.t. and so for any ,
Taking expectation we get as claimed that :
Now using this above recursively (and noting that ) we conclude that
Consider a sequence of non-negative number that satisfy
where is decreasing in . For such a sequence, for any , as long as for any and then
We shall unroll this recursion. Note that
We would now like to bound in general the term . To this extant note that,
Now assume for all so that . We get
Now if then we can conclude that
Now if for each , then we see that
Hence we conclude that as long as