Sparsified SGD with Memory
Sebastian U. Stich, Jean-Baptiste Cordonnier, Martin Jaggi
Introduction
Stochastic Gradient Descent (SGD) and variants thereof (e.g. ) are among the most popular optimization algorithms in machine- and deep-learning . SGD consists of iterations of the form
In this paper we give a concise convergence rate analysis for SGD with memory and -compression operatorsSee Definition 2.1., such as (but not limited to) top- sparsification. Our analysis also supports ultra-sparsification operators for which , i.e. where less than one coordinate of the stochastic gradient is applied on average in (1). We not only provide the first convergence result of this method, but the result also shows that the method converges at the same rate as vanilla SGD.
There are several ways to reduce the communication in SGD. For instance by simply increasing the amount of computation before communication, i.e. by using large mini-batches (see e.g. ), or by designing communication-efficient schemes . These approaches are a bit orthogonal to the methods we consider in this paper, which focus on quantization or sparsification of the gradient.
Several papers consider approaches that limit the number of bits to represent floating point numbers . Recent work proposes adaptive tuning of the compression ratio . Unbiased quantization operators not only limit the number of bits, but quantize the stochastic gradients in such a way that they are still unbiased estimators of the gradient . The ZipML framework also applies this technique to the data . Sparsification methods reduce the number of non-zero entries in the stochastic gradient .
A very aggressive sparsification method is to keep only very few coordinates of the stochastic gradient by considering only the coordinates with the largest magnitudes . In contrast to the unbiased schemes it is clear that such methods can only work by using some kind of error accumulation or feedback procedure, similar to the one the we have already discussed , as otherwise certain coordinates could simply never be updated. However, in certain applications no feedback mechanism is needed . Also more elaborate sparsification schemes have been introduced .
Asynchronous updates provide an alternative solution to disguise the communication overhead to a certain amount . However, those methods usually rely on a sparsity assumption on the updates , which is not realistic e.g. in deep learning. We like to advocate that combining gradient sparsification with those asynchronous schemes seems to be a promising approach, as it combines the best of both worlds. Other scenarios that could profit from sparsification are heterogeneous systems or specialized hardware, e.g. accelerators .
Convergence proofs for SGD typically rely on averaging the iterates , though convergence of the last iterate can also be proven . For our convergence proof we rely on averaging techniques that give more weight to more recent iterates , as well as the perturbed iterate framework from Mania et al. and techniques from .
Simultaneous to our work, at NIPS 2018 propose related schemes. Whilst Tang et al. only consider unbiased stochastic compression schemes, Alistarh et al. study biased top- sparsification. Their scheme also uses a memory vector to compensate for the errors, but their analysis suffers from a slowdown proportional to , which we can avoid here. Another simultaneous analysis of Wu et al. at ICML 2018 is restricted to unbiased gradient compression. This scheme also critically relies on an error compensation technique, but in contrast to our work the analysis is restricted to quadratic functions and the scheme introduces two additional hyperparameters that control the feedback mechanism.
2 Contributions
We introduce the method formally in Section 2 and show a sketch of the convergence proof in Section 3. In Section 4 we include a few numerical experiments for illustrative purposes. The experiments highlight that top- sparsification yields a very effective compression method and does not hurt convergence. We also report results for a parallel multi-core implementation of SGD with memory that show that the algorithm scales as well as asynchronous SGD and drastically decreases the communication cost without sacrificing the rate of convergence. We like to stress that the effectiveness of SGD variants with sparsification techniques has already been demonstrated in practice .
Although we do not yet provide convergence guarantees for parallel and asynchronous variants of the scheme, this is the main application of this method. For instance, we like to highlight that asynchronous SGD schemes could profit from the gradient sparsification. To demonstrate this use-case, we include in Section 4 a set of experiments for a multi-core implementation.
SGD with Memory
In this section we present the sparsified SGD algorithm with memory. First we introduce sparsification and quantization operators which allow us to drastically reduce the communication cost in comparison with vanilla SGD.
We consider compression operators that satisfy the following contraction property:
The contraction property is sufficient to obtain all mathematical results that are derived in this paper. However, note that (4) does not imply that is a necessarily sparse vector. Also dense vectors can satisfy (4). One of the main goals of this work is to derive communication efficient schemes, thus we are particularly interested in operators that also ensure that can be encoded much more efficiently than the original .
The following two operators are examples of -contraction operators with the additional property of being -sparse vectors:
where is a permutation of such that for . We abbreviate whenever the second argument is chosen uniformly at random, .
It is easy to see that both operators satisfy Definition 2.1 of being a -contraction. For completeness the proof is included in Appendix A.1.
We like to highlight that many other operators do satisfy Definition 2.1, not only the two examples given in Definition 2.2. As a notable variant is to pick a random coordinate of a vector with probability , for , property (4) holds even if . I.e. it suffices to transmit on average less than one coordinate per iteration (this would then correspond to a mini-batch update).
2 Variance Blow-up for Unbiased Updates
Before introducing SGD with memory we first discuss a motivating example. Consider the following variant of SGD, where random coordinates of the stochastic gradient are dropped:
It is well known that by using mini-batches the variance of the gradient estimator can be reduced. If we consider in (6) the estimator \mathbf{g}_{t}:=\frac{d}{k}\cdot\operatorname{rand}_{k}\bigl{(}\frac{1}{\tau}\sum_{i\in\mathcal{I}_{\tau}}\nabla f_{i}(\mathbf{x}_{t})\bigr{)} for , and instead, we have
This shows that, when using mini-batches of appropriate size, the sparsification of the gradient does not hurt convergence. However, by increasing the mini-batch size, we increase the computation by a factor of .
3 SGD with Memory: Algorithm and Convergence Results
where , and denotes a sequence of stepsizes. The pseudocode is given in Algorithm 1. Note that the gradients get multiplied with the stepsize at the timestep when they put into memory, and not when they are (partially) retrieved from the memory.
We state the precise convergence result for Algorithm 1 in Theorem 2.4 below. In Remark 2.6 we give a simplified statement in big- notation for a specific choice of the stepsizes .
where , for , and .
Theorem 2.4 says that for any shift there is a parameter such that (9) holds. However, for the choice one has to set such that and the last term in (9) will be of order , thus requiring steps to yield convergence. For we have and the last term is only of order instead. However, this requires typically a large shift. Observe , i.e. setting is enough. We like to stress that in general it is not advisable to set as the first two terms in (9) depend on . In practice, it often suffices to set , as we will discuss in Section 4.
As discussed in Remark 2.5 above, setting and is feasible. With this choice, equation (9) simplifies to
Proof Outline
We now give an outline of the proof. The proofs of the lemmas are given in Appendix A.2.
where the sequences and are the same as in (8). Notice that
Bounding the memory.
Optimal averaging.
Similar as discussed in we have to define a suitable averaging scheme for the iterates to get the optimal convergence rate. In contrast to that use linearly increasing weights, we use quadratically increasing weights, as for instance .
Let , , , , be sequences satisfying
for and constants , , . Then
for and .
Proof of Theorem 2.4.
Experiments
We present numerical experiments to illustrate the excellent convergence properties and communication efficiency of Mem-SGD. As the usefulness of SGD with sparsification techniques has already been shown in practical applications we focus here on a few particular aspects. First, we verify the impact of the initial learning rate that did come up in the statement of Theorem 2.4. We then compare our method with QSGD which decreases the communication cost in SGD by using random quantization operators, but without memory. Finally, we show the performance of the parallel SGD depicted in Algorithm 2 in a multi-core setting with shared memory and compare the speed-up to asynchronous SGD.
Datasets.
We consider a dense dataset, epsilon , as well as a sparse dataset, RCV1 where we train on the larger test set. Statistics on the datasets are listed in Table 1 below:
Implementation.
We use Python3 and the numpy library . Our code is open-source and publicly available at github.com/epfml/sparsifiedSGD. We emphasize that our high level implementation is not optimized for speed per iteration but for readability and simplicity. We only report convergence per iteration and relative speedups, but not wall-clock time because unequal efforts have been made to speed up the different implementations. Plots additionally show the baseline computed with the standard optimizer LogisticSGD of scikit-learn . Experiments were run on an Ubuntu 18.04 machine with a 24 cores processor Intel® Xeon® CPU E5-2680 v3 @ 2.50GHz.
2 Verifying the Theory
We study the convergence of the method using the stepsizes and hyperparameters and set as in Table 2. We compute the final estimate as a weighted average of all iterates with weights as indicated by Theorem 2.4. The results are depicted in Figure 2. We use for epsilon and for RCV1 to increase the difference with large number of features. The variant consistently outperforms and sometimes outperforms vanilla SGD, which is surprising and might come from feature characteristics of the datasets. We also evaluate the impact of the delay in the learning rate: setting it to instead of order dramatically hurts the memory and requires time to recover from the high initial learning rate (labeled “without delay” in Figure 2).
We experimentally verified the convergence properties of Mem-SGD for different sparsification operators and stepsizes but we want to further evaluate its fundamental benefits in terms of sparsity enforcement and reduction of the communication bottleneck. The gain in communication cost of SGD with memory is very high for dense datasets—using the strategy on epsilon dataset improves the amount of communication by compared to SGD. For the sparse dataset, SGD can readily use the given sparsity of the gradients. Nevertheless, the improvement for on RCV1 is of approximately an order of magnitude.
3 Comparison with QSGD
Now we compare Mem-SGD with the QSGD compression scheme which reduces communication cost by random quantization. The accuracy (and the compression ratio) in QSGD is controlled by a parameter , corresponding to the number of quantization levels. Ideally, we would like to set the quantization precision in QSGD such that the number of bits transmitted by QSGD and Mem-SGD are identical and compare their convergence properties. However, even for the lowest precision, QSGD needs to send the sign and index of coordinates. It is therefore not possible to reach the compression level of sparsification operators such as top- or random-, that only transmit a constant number of bits per iteration (up to logarithmic factors).Encoding the indices of the top- or random- elements can be done with additional bits. Note that for both our examples. Hence, we did not enforce this condition and resorted to pick reasonable levels of quantization in QSGD ( with ). Note that -bits stands for the number of bits used to encode levels but the number of bits transmitted in QSGD can be reduced using Elias coding. As a fair comparison in practice, we chose a standard learning rate , tuned the hyperparameter on a subset of each dataset (see Appendix B). Figure 3 shows that Mem-SGD with on epsilon and RCV1 converges as fast as QSGD in term of iterations for 8 and 4-bits. As shown in the bottom of Figure 3, we are transmitting two orders of magnitude fewer bits with the sparsifier concluding that sparsification offers a much more aggressive and performant strategy than quantization.
4 Multicore experiment
We implement a parallelized version of Mem-SGD, as depicted in Algorithm 2. The enforced sparsity allows us to do the update in shared memory using a lock-free mechanism as in . For this experiment we evaluate the final iterate instead of the weighted average above, and use the learning rate .
Figure 4 shows the speed-up obtained when increasing the number of cores. We see that both sparsified SGD and vanilla SGD have a linear speed-up, the slopes are dependent of the implementation details. But we observe that Parallel-Mem-SGD with a reasonable sparsification parameter does not suffer of having multiple independent memories. The experiment is run on a single machine with a 24 core processor, hence no inter-node communication is used. The main advantage of our method—overcoming the communication bottleneck— would be even more visible in a multi-node setup. In this asynchronous setup, SGD with memory computes gradients on stale iterates that differ only by a few coordinates. It encounters fewer inconsistent read/write operations than lock free asynchronous SGD and exhibits better scaling properties on the RCV1 dataset. The operator performs better than in the sequential setup, but this is not the case in the parallel setup.
Conclusion
We provide the first concise convergence analysis of sparsified SGD . This extremely communication-efficient variant of SGD enforces sparsity of the applied updates by only updating a constant number of coordinates in every iteration. This way, the method overcomes the communication bottleneck of SGD, while still enjoying the same convergence rate in terms of stochastic gradient computations.
Our experiments verify the drastic reduction in communication cost by demonstrating that Mem-SGD requires one to two orders of magnitude less bits to be communicated than QSGD while converging to the same accuracy. The experiments show an advantage for the top- sparsification over random sparsification in the serial setting, but not in the multi-core shared memory implementation. There, both schemes are on par, and show better scaling than a simple shared memory implementation that just writes the unquantized updates in a lock-free asynchronous fashion (like Hogwild! ).
The theoretical insights to Mem-SGD that were developed here should facilitate the analysis of the same scheme in the parallel (as developped in ) and the distributed setting. It has already been shown in practice that gradient sparsification can be efficiently applied to bandwidth memory limited systems such as multi-GPU training for neural networks . By delivering sparsity no matter if the original gradients were sparse or not, our scheme is not only communication efficient, but becomes more eligible for asynchronous implementations as well. While those were so far limited by strict sparsity assumptions (as e.g. in ), our approach might make such methods much more widely applicable.
Acknowledgments
We would like to thank Dan Alistarh for insightful discussions in the early stages of this project and Frederik Künstner for his useful comments on the various drafts of this manuscript. We acknowledge funding from SNSF grant 200021_175796, Microsoft Research JRC project ‘Coltrain’, as well as a Google Focused Research Award.
References
Appendix A Proofs
Let , for . Then .
A.2 Proof of the Main Theorem
and with we further have
Putting these two estimates together, we can bound (23) as follows:
First, observe that by Lemma A.1 and for we have
On the other hand, from we also have
Now the claim follows from Lemma A.3 just below with . ∎
Let , , , be a sequence satisfying
for a sequence with , for , . Then
Let , i.e. . (Note that for any it holds .) Suppose the claim holds for . Observe,
for . This follows from Lemma A.2 with . By induction,
where we used (and the observation just above) for the last inequality.
Small t𝑡t.
Assume , otherwise the claim follows from the part above. We have
using . Observe . For we have
by the condition on . Hence, by combining these observations,
We now multiply equation (15) with , which yields
and by recursively substituting we get
We will now derive upper bounds for the terms on the right hand side. We have
Let . Observe
Appendix B Experiments
To produce a fair comparison between Mem-SGD and QSGD , we fix the learning rate to and run a grid search on the hyperparameter (individually for each method). The results are displayed in Figure 5.
QSGD communicated bits.
The number of bits needed by QSGD with quantization levels to communicate the gradient at each iteration is \min\bigl{\{}(\lceil\log_{2}(s)\rceil+1)\cdot d,\,3s(s+\sqrt{d})+32\bigr{\}} where is the size of the gradient. The first expression corresponds to the naïve encoding (i.e. index/value pairs), the second expression corresponds to the estimates of the more evolved Elias encoding (see e.g. [3, Theorem 3.2]). For the sparse dataset RCV1-test, we additionally assume that QSGD is aware of the sparsity of the gradients () and send only the quantized non zero coordinates with their indexes. In a nutshell, we chose the best communication pattern for QSGD to conduct a fair comparison with Mem-SGD.