On Variance Reduction in Stochastic Gradient Descent and its Asynchronous Variants
Sashank J. Reddi, Ahmed Hefny, Suvrit Sra, Barnabás Póczos, Alex Smola
Introduction
There has been a steep rise in recent work on “variance reduced” stochastic gradient algorithms for convex problems of the finite-sum form:
Although these advances have great value in general, for large-scale problems we still require parallel or distributed processing. And in this setting, asynchronous variants of SGD remain indispensable . Therefore, a key question is how to extend the synchronous finite-sum VR algorithms to asynchronous parallel and distributed settings.
We answer one part of this question by developing new asynchronous parallel stochastic gradient methods that provably converge at a linear rate for smooth strongly convex finite-sum problems. Our methods are inspired by the influential Svrg , S2gd , Sag and Saga family of algorithms. We list our contributions more precisely below.
Contributions. Our paper makes two core contributions: (i) a formal general framework for variance reduced stochastic methods based on discussions in ; and (ii) asynchronous parallel VR algorithms within this framework. Our general framework presents a formal unifying view of several VR methods (e.g., it includes SAGA and SVRG as special cases) while expressing key algorithmic and practical tradeoffs concisely. Thus, it yields a broader understanding of VR methods, which helps us obtain asynchronous parallel variants of VR methods. Under sparse-data settings common to machine learning problems, our parallel algorithms attain speedups that scale near linearly with the number of processors.
As a concrete illustration, we present a specialization to an asynchronous Svrg-like method. We compare this specialization with non-variance reduced asynchronous SGD methods, and observe strong empirical speedups that agree with the theory.
Related work. As already mentioned, our work is closest to (and generalizes) Sag , Saga , Svrg and S2gd , which are primal methods. Also closely related are dual methods such as sdca and Finito , and in its convex incarnation Miso ; a more precise relation between these dual methods and VR stochastic methods is described in Defazio’s thesis . By their algorithmic structure, these VR methods trace back to classical non-stochastic incremental gradient algorithms , but by now it is well-recognized that randomization helps obtain much sharper convergence results (in expectation). Proximal and accelerated VR methods have also been proposed ; we leave a study of such variants of our framework as future work. Finally, there is recent work on lower-bounds for finite-sum problems .
Within asynchronous SGD algorithms, both parallel and distributed variants are known. In this paper, we focus our attention on the parallel setting. A different line of methods is that of (primal) coordinate descent methods, and their parallel and distributed variants . Our asynchronous methods share some structural assumptions with these methods. Finally, the recent work generalizes S2GD to the mini-batch setting, thereby also permitting parallel processing, albeit with more synchronization and allowing only small mini-batches.
A General Framework for VR Stochastic Methods
While our analysis focuses on strongly convex functions, we can extend it to just smooth convex functions along the lines of .
Next, we provide different instantiations of the framework and construct a new algorithm derived from it. In particular, we consider incremental methods Sag , Svrg and Saga , and classic gradient descent GradientDescent for demonstrating our framework.
Figure 1 shows the schedules for the aforementioned algorithms. In case of Svrg, ScheduleUpdate is triggered every iterations (here denotes precisely the number of inner iterations used in ); so remains unchanged for the iterations and all are updated to the current iterate at the iteration. For Saga, unlike Svrg, changes at the iteration for all . This change is only to a single element of , and is determined by the index (the function chosen at iteration ). The update of Sag is similar to Saga insofar that only one of the is updated at each iteration. However, the update for is based on rather than . This results in a biased estimate of the gradient, unlike Svrg and Saga. Finally, the schedule for gradient descent is similar to Sag, except that all the ’s are updated at each iteration. Due to the full update we end up with the exact gradient at each iteration. This discussion highlights how the scheduler determines the resulting gradient method.
To motivate the design of another schedule, let us consider the computational and storage costs of each of these algorithms. For Svrg, since we update after every iterations, it is enough to store a full gradient, and hence, the storage cost is . However, the running time is at each iteration and at the end of each epoch (for calculating the full gradient at the end of each epoch). In contrast, both Sag and Saga have high storage costs of and running time of per iteration. Finally, GradientDescent has low storage cost since it needs to store the gradient at cost, but very high computational costs of at each iteration.
Svrg has an additional computation overhead at the end of each epoch due to calculation of the whole gradient. This is avoided in Sag and Saga at the cost of additional storage. When is very large, the additional computational overhead of Svrg amortized over all the iterations is small. However, as we will later see, this comes at the expense of slower convergence to the optimal solution. The tradeoffs between the epoch size , additional storage, frequency of updates, and the convergence to the optimal solution are still not completely resolved.
A straightforward approach to design a new scheduler is to combine the schedules of the above algorithms. This allows us to tradeoff between the various aforementioned parameters of our interest. We call this schedule hybrid stochastic average gradient (Hsag). Here, we use the schedules of Svrg and Saga to develop Hsag. However, in general, schedules of any of these algorithms can be combined to obtain a hybrid algorithm. Consider some , the indices that follow Saga schedule. We assume that the rest of the indices follow an Svrg-like schedule with schedule frequency for all . Figure 2 shows the corresponding update schedule of Hsag. If then Hsag is equivalent to Saga, while at the other extreme, for and for all , it corresponds to Svrg. Hsag exhibits interesting storage, computational and convergence trade-offs that depend on . In general, while large cardinality of likely incurs high storage costs, the computational cost per iteration is relatively low. On the other hand, when cardinality of is small and ’s are large, storage costs are low but the convergence typically slows down.
Before concluding our discussion on the general framework, we would like to draw the reader’s attention to the advantages of studying Algorithm 1. First, note that Algorithm 1 provides a unifying framework for many incremental/stochastic gradient methods proposed in the literature. Second, and more importantly, it provides a generic platform for analyzing this class of algorithms. As we will see in Section 3, this helps us develop and analyze asynchronous versions for different finite-sum algorithms under a common umbrella. Finally, it provides a mechanism to derive new algorithms by designing more sophisticated schedules; as noted above, one such construction gives rise to Hsag.
For any positive parameters , step size and epoch size , we define the following quantities:
Suppose the probabilities , and that , step size and epoch size are chosen such that the following conditions are satisfied:
Then, for iterates of Algorithm 1 under the Hsag schedule, we have
As a corollary, we immediately obtain an expected linear rate of convergence for Hsag.
We emphasize that there exist values of the parameters for which the conditions in Theorem 1 and Corollary 1 are easily satisfied. For instance, setting , , and , the conditions in Theorem 1 are satisfied for sufficiently large . Additionally, in the high condition number regime of , we can obtain constant (say ) with epoch size (similar to ). This leads to a computational complexity of for Hsag to achieve accuracy in the objective function as opposed to for batch gradient descent method. Please refer to the appendix for more details on the parameters in Theorem 1.
Asynchronous Stochastic Variance Reduction
We are now ready to present asynchronous versions of the algorithms captured by our general framework. We first describe our setup before delving into the details of these algorithms. Our model of computation is similar to the ones used in Hogwild! and AsySCD . We assume a multicore architecture where each core makes stochastic gradient updates to a centrally stored vector in an asynchronous manner. There are four key components in our asynchronous algorithm; these are briefly described below.
Read: Read the iterate and compute the gradient for a randomly chosen .
Read schedule iterate: Read the schedule iterate and compute the gradients required for update in Algorithm 1.
Update: Update the iterate with the computed incremental update in Algorithm 1.
Schedule Update: Run a scheduler update for updating .
Each processor repeatedly runs these procedures concurrently, without any synchronization. Hence, may change in between Step 1 and Step 3. Similarly, may change in between Steps 2 and 4. In fact, the states of iterates and can correspond to different time-stamps. We maintain a global counter to track the number of updates successfully executed. We use and to denote the particular -iterate and -iterate used for evaluating the update at the iteration. We assume that the delay in between the time of evaluation and updating is bounded by a non-negative integer , i.e., and . The bound on the staleness captures the degree of parallelism in the method: such parameters are typical in asynchronous systems (see e.g., ). Furthermore, we also assume that the system is synchronized after every epoch i.e., for . We would like to emphasize that the assumption is not strong since such a synchronization needs to be done only once per epoch.
For the purpose of our analysis, we assume a consistent read model. In particular, our analysis assumes that the vector used for evaluation of gradients is a valid iterate that existed at some point in time. Such an assumption typically amounts to using locks in practice. This problem can be avoided by using random coordinate updates as in (see Section 4 of ) but such a procedure is computationally wasteful in practice. We leave the analysis of inconsistent read model as future work. Nonetheless, we report results for both locked and lock-free implementations (see Section 4).
Suppose step size , epoch size are chosen such that the following condition holds:
Then, for the iterates of an asynchronous variant of Algorithm 1 with Svrg schedule and probabilities for all , we have
The bound obtained in Theorem 2 is useful when is small. To see this, as earlier, consider the indicative case where . The synchronous version of Svrg obtains a convergence rate of for step size and epoch size . For the asynchronous variant of Svrg, by setting , we obtain a similar rate with . To obtain this, set where and . Then, a simple calculation gives the following:
where is some constant. This follows from the fact that . Suppose . Then we can achieve nearly the same guarantees as the synchronous version, but times faster since we are running the algorithm asynchronously. For example, consider the sparse setting where ; then it is possible to get near linear speedup when . On the other hand, when , we can obtain a theoretical speedup of .
We finally provide the convergence result for the asynchronous algorithm in the general case. The proof is complicated by the fact that set , unlike in Svrg, changes during the epoch. The key idea is that only a single element of changes at each iteration. Furthermore, it can only change to one of the iterates in the epoch. This control provides a handle on the error obtained due to the staleness. Due to space constraints, the proof is relegated to the appendix.
For any positive parameters , step size and epoch size , we define the following quantities:
Suppose probabilities , parameters , step-size , and epoch size are chosen such that the following conditions are satisfied:
Then, for the iterates of asynchronous variant of Algorithm 1 with Hsag schedule we have
By using step size normalized by (similar to Theorem 2) and parameters similar to the ones specified after Theorem 1 we can show speedups similar to the ones obtained in Theorem 2. Please refer to the appendix for more details on the parameters in Theorem 3.
Before ending our discussion on the theoretical analysis, we would like to highlight an important point. Our emphasis throughout the paper was on generality. While the results are presented here in full generality, one can obtain stronger results in specific cases. For example, in the case of Saga, one can obtain per iteration convergence guarantees (see ) rather than those corresponding to per epoch presented in the paper. Also, Saga can be analyzed without any additional synchronization per epoch. However, there is no qualitative difference in these guarantees accumulated over the epoch. Furthermore, in this case, our analysis for both synchronous and asynchronous cases can be easily modified to obtain convergence properties similar to those in .
Experiments
We present our empirical results in this section. For our experiments, we study the problem of binary classification via -regularized logistic regression. More formally, we are interested in the following optimization problem:
A careful implementation of Svrg is required for sparse gradients since the implementation as stated in Algorithm 1 will lead to dense updates at each iteration. For an efficient implementation, a scheme like the ‘just-in-time’ update scheme, as suggested in , is required. Due to lack of space, we provide the implementation details in the appendix.
We evaluate the following algorithms for our experiments:
Lock-Free Svrg: This is the lock-free asynchronous variant of Algorithm 1 using Svrg schedule; all threads can read and update the parameters with any synchronization. Parameter updates are performed through atomic compare-and-swap instruction . A constant step size that gives the best convergence is chosen for the dataset.
Locked Svrg: This is the locked version of the asynchronous variant of Algorithm 1 using Svrg schedule. In particular, we use a concurrent read exclusive write locking model, where all threads can read the parameters but only one threads can update the parameters at a given time. The step size is chosen similar to Lock-Free Svrg.
Lock-Free Sgd: This is the lock-free asynchronous variant of the Sgd algorithm (see ). We compare two different versions of this algorithm: (i) Sgd with constant step size (referred to as CSgd). (ii) Sgd with decaying step size (referred to as DSgd), where constants and specify the scale and speed of decay. For each of these versions, step size is tuned for each dataset to give the best convergence progress.
All the algorithms were implemented in C++ All experiments were conducted on a Google Compute Engine n1-highcpu-32 machine with 32 processors and 28.8 GB RAM.. We run our experiments on datasets from LIBSVM websitehttp://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html. Similar to , we normalize each example in the dataset so that for all . Such a normalization leads to an upper bound of on the Lipschitz constant of the gradient of . The epoch size is chosen as (as recommended in ) in all our experiments. In the first experiment, we compare the speedup achieved by our asynchronous algorithm. To this end, for each dataset we first measure the time required for the algorithm to each an accuracy of (i.e., ). The speedup with threads is defined as the ratio of the runtime with a single thread to the runtime with threads. Results in Figure 3 show the speedup on various datasets. As seen in the figure, we achieve significant speedups for all the datasets. Not surprisingly, the speedup achieved by Lock-free Svrg is much higher than ones obtained by locking. Furthermore, the lowest speedup is achieved for rcv1 dataset. Similar speedup behavior was reported for this dataset in . It should be noted that this dataset is not sparse and hence, is a bad case for the algorithm (similar to ).
For the second set of experiments we compare the performance of Lock-Free Svrg with stochastic gradient descent. In particular, we compare with the variants of stochastic gradient descent, DSgd and CSgd, described earlier in this section. It is well established that the performance of variance reduced stochastic methods is better than that of Sgd. We would like to empirically verify that such benefits carry over to the asynchronous variants of these algorithms. Figure 4 shows the performance of Lock-Free Svrg, DSgd and CSgd. Since the computation complexity of each epoch of these algorithms is different, we directly plot the objective value versus the runtime for each of these algorithms. We use 10 cores for comparing the algorithms in this experiment. As seen in the figure, Lock-Free Svrg outperforms both DSgd and CSgd. The performance gains are qualitatively similar to those reported in for the synchronous versions of these algorithms. It can also be seen that the DSgd, not surprisingly, outperforms CSgd in all the cases. In our experiments, we observed that Lock-Free Svrg, in comparison to Sgd, is relatively much less sensitive to the step size and more robust to increasing threads.
Discussion & Future Work
In this paper, we presented a unifying framework based on , that captures many popular variance reduction techniques for stochastic gradient descent. We use this framework to develop a simple hybrid variance reduction method. The primary purpose of the framework, however, was to provide a common platform to analyze various variance reduction techniques. To this end, we provided convergence analysis for the framework under certain conditions. More importantly, we propose an asynchronous algorithm for the framework with provable convergence guarantees. The key consequence of our approach is that we obtain asynchronous variants of several algorithms like Svrg, Saga and S2gd. Our asynchronous algorithms exploits sparsity in the data to obtain near linear speedup in settings that are typically encountered in machine learning.
For future work, it would be interesting to perform an empirical comparison of various schedules. In particular, it would be worth exploring the space-time-accuracy tradeoffs of these schedules. We would also like to analyze the effect of these tradeoffs on the asynchronous variants.
References
Appendix A Appendix
Notation: We use to denote the Bregman divergence (defined below) for function .
We would like to clarify the definition of here. As noted in the main text, we assume that is replaced with an element chosen randomly from with probability at the end of the epoch. However, whenever appears in the analysis (proofs), it represents the iterate before this replacement.
Implementation Details
Since we are interested in sparse datasets, simply taking is not efficient as it requires updating the whole vector at each iteration. This is due to the regularization term in each of the ’s. Instead, similar to , we rewrite problem in (4.1) as follows:
Proof of Theorem 1
We expand function as where and . Let the present epoch be . We define the following:
The last step follows from convexity of and the unbiasedness of . We have the following relationship between and .
This follows from the definition of the schedule of Hsag for indices in . Substituting the above relationship in Equation (A.1) we get the following.
We describe the bounds for (defined below).
The terms and can be bounded in the following fashion:
Substituting these bounds and in , we get
The second inequality follows from Lemma 2. In particular, we use the fact that and . The third inequality follows from the following for the choice of our parameters:
Applying the recursive relationship on for m iterations, we get
Substituting the bound on from Equation (A.3) in the above equation we get the following inequality:
For obtaining the above inequality, we used the strongly convex nature of function . Again, using the Bregman divergence based inequality (see Lemma 2)
Using the above notation, we have the following inequality from Equation (A.4).
where is a constant that depends on the parameters used in the algorithm. ∎
Proof of Theorem 2
Let the present epoch be . Recall that denotes the iterate used in the iteration of the algorithm. We define the following:
We first bound the last term of the above inequality. We expand the term in the following manner:
The first equality directly follows from the definition of and its property of unbiasedness. The second step follows from simple algebraic calculations. Terms and can be bounded in the following way:
This bound directly follows from convexity of function .
The first inequality follows from lipschitz continuous nature of the gradient of function . The second inequality follows from the definition of . The last term can be bounded in the following manner.
The first inequality follows from Cauchy-Schwartz inequality. The second inequality follows from repeated application of triangle inequality. The third step is a simple application of AM-GM inequality and the fact that gradient of the function is lipschitz continuous. Finally, the last step can be obtained by using a simple counting argument, the fact that the staleness in gradient is at most and the definition of .
By combining the bounds on and in Equations (A.7), (A.8) and (A.9) respectively and substituting the sum in Equation (A.6), we get
By substituting the above inequality in Equation (A.5), we get
The first step follows from Lemma 3 for . The third inequality follows from the lipschitz continuous nature of the gradient and simple application of Lemma 3. Adding the above inequalities from to , we get
Here we again used a simple counting argument and the fact that the delay in the gradients is at most . From the above inequality, we get
Adding Equation (A.11) from to and substituting Equation (A.12) in the resultant, we get
Substituting this in the inequality above, we get the following bound:
Proof of Theorem 3
Let the present epoch be . For simplicity, we assume that the iterates and used in the each iteration are from the same time step (index) i.e., for all . Recall that and denote the index used in the iteration of the algorithm. Our analysis can be extended to the case of in a straightforward manner. We expand function as where and . We define the following:
We use the same Lyapunov function used in Theorem 1. We recall the following definitions:
We bound term in the following manner:
The first term can be bounded in the following manner:
The second step follows from Lemma 3 for r = 3. The last step follows from simple application of Jensen’s inequality. The first term can be bounded easily in the following manner:
The second and third terms need more delicate analysis. The key insight for our analysis is that at most ’s differ from time step to . This is due to the fact that the delay is bounded by and at most one changes at each iteration. Furthermore, whenever there is a change in , it changes to one of the iterates for some . With this intuition we bound the second term in the following fashion.
The first inequality follows from the fact that if and differ, then (a) should have been chosen in one of the iteration and (b) is changed to in that iteration. The second inequality follows from Lemma 3 for r = 2. The third inequality follows from the fact that the probability . The last step directly follows from Lemma 1. Note that sum is over indices in since ’s for do not change during the epoch.
The third term in Equation (A.15) can be bounded by exactly the same technique we used for the second term. The bound, in fact, turns out to identical to second term since is chosen uniformly random. Combining all the terms we have
The term can be bounded in a manner similar to one in Theorem 2 to obtain the following (see proof of Theorem 2 for details):
We need the following bound for our analysis:
The above inequality follows directly from the bound on by adding over all in the epoch. Under the condition
The above inequality follows from the fact that
The above relationship is due to the condition on and the fact that any for at most values of . We have the following:
We bound in the following manner:
The second equality follows from the definition of (see Equation (A.2)).
Applying the recurrence relationship in Equation (A.18) with the derived bound on , we have
where is defined as follows
The last inequality follows from that fact that the delay is at most . In particular, each index occurs at most times. We use the following notation for ease of exposition:
Substituting the bound in Equation (A.17), we get the following:
We now use the following previously used bound on (see bound in the proof of Theorem 1):
Substituting the above bound on in Equation (A.19), we get the following:
where is a constant that depends on the parameters used in the algorithm. ∎
In this section, we briefly remark about the parameters in Theorems 1 & 3. For Theorem 1, suppose we use the following instantiation of the parameters:
In the interesting case of (high condition number regime), since , one can obtain a constant (say ) with . This leads to accuracy in the objective function after epochs of Hsag. When , the computational complexity of each epoch of Hsag is . Hence, the total computational complexity of Hsag is . On the other hand, because , batch gradient descent method requires iterations to achieve accuracy in the objective value. Since the complexity of each iteration of gradient descent is (as it passes through the whole dataset for calculating the gradient), the overall computational complexity of batch gradient descent is . In general, for high condition number regimes (which is typically the case in machine learning applications), Hsag (like Svrg, Saga) will be significantly faster than the batch gradient methods. Furthermore, the convergence rate is strictly better than the sublinear rate obtained for Sgd.
The parameter instantiations for Theorem 3 are much more involved. Suppose (this is the sparse regime that is typically of interest to the machine learning community) and . The other case ( ) can be analyzed in a similar fashion. We set the following parameters:
Again, in the case of , we can obtain constant (say ) with and . The constants in the parameters are not optimized and can be improved by a more careful analysis. Furthermore, sharper constants can be obtained in specific cases. For example, see and Theorem 2 for synchronous and asynchronous convergence rates of Svrg respectively. Similarly, sharper constants for Saga can also be derived by simple modifications of the analysis.
Other Lemmatta
The proof follows trivially from the fact that is the optimal solution and linearity and non-negative properties of Bregman divergence. ∎
For random variables , we have