ATOMO: Communication-efficient Learning via Atomic Sparsification
Hongyi Wang, Scott Sievert, Zachary Charles, Shengchao Liu, Stephen Wright, Dimitris Papailiopoulos
Introduction
Distributed computing systems have become vital to the success of modern machine learning systems. Work in parallel and distributed optimization has shown that these systems can obtain massive speed up gains in both convex and non-convex settings . Several machine learning frameworks such as TensorFlow , MXNet , and Caffe2 , come with distributed implementations of popular training algorithms, such as mini-batch SGD. However, the empirical speed-up gains offered by distributed training, often fall short of the optimal linear scaling one would hope for. It is now widely acknowledged that communication overheads are the main source of this speedup saturation phenomenon .
Communication bottlenecks are largely attributed to frequent gradient updates transmitted between compute nodes. As the number of parameters in state-of-the-art models scales to hundreds of millions , the size of gradients scales proportionally. These bottlenecks become even more pronounced in the context of federated learning , where edge devices (e.g., mobile phones, sensors, etc) perform decentralized training, but suffer from low-bandwidth during up-link.
To reduce the cost of of communication during distributed model training, a series of recent studies propose communicating low-precision or sparsified versions of the computed gradients during model updates. Partially initiated by a 1-bit implementation of SGD by Microsoft in , a large number of recent studies revisited the idea of low-precision training as a means to reduce communication . Other approaches for low-communication training focus on sparsification of gradients, either by thresholding small entries or by random sampling . Several approaches, including QSGD and TernGrad, implicitly combine quantization and sparsification to maximize performance gains , while providing provable guarantees for convergence and performance. We note that quantization methods in the context of gradient based updates have a rich history, dating back to at least as early as the 1970s .
An atomic decomposition represents a vector as a linear combination of simple building blocks in an inner product space. In this work, we show that stochastic gradient sparsification and quantization are facets of a general approach that sparsifies a gradient in any possible atomic decomposition, including its entry-wise or singular value decomposition, its Fourier decomposition, and more. With this in mind, we develop Atomo, a general framework for atomic sparsification of stochastic gradients. Atomo sets up and optimally solves a meta-optimization that minimizes the variance of the sparsified gradient, subject to the constraints that it is sparse on the atomic basis, and also is an unbiased estimator of the input.
We show that 1-bit QSGD and TernGrad are in fact special cases of Atomo, and each is optimal (in terms of variance and sparsity), in different parameter regimes. Then, we argue that for some neural network applications, viewing the gradient as a concatenation of matrices (each corresponding to a layer), and applying atomic sparsification to their SVD is meaningful and well-motivated by the fact that these matrices are “nearly” low-rank, e.g., see Fig. 1. We show that Atomo on the SVD of each layer’s gradient, can lead to less variance, and faster training, for the same communication budget as that of QSGD or TernGrad. We present extensive experiments showing that using Atomo with SVD sparsification, can lead to up to faster training time (including the time to compute the SVD) compared to QSGD, on VGG and ResNet-18, and SVHN and CIFAR-10.
Relation to Prior Work
Atomo is closely related to work on communication-efficient distributed mean estimation in and . These works both note, as we do, that variance (or equivalently the mean squared error) controls important quantities such as convergence, and they seek to find a low-communication vector averaging scheme that minimizes it. Our work differs in two key aspects. First, we derive a closed-form solution to the variance minimization problem for all input gradients. Second, Atomo applies to any atomic decomposition, which allows us to compare entry-wise against singular value sparsification for matrices. Using this, we derive explicit conditions for which SVD sparsification leads to lower variance for the same sparsity budget.
The idea of viewing gradient sparsification through a meta-optimization lens was also used in . Our work differs in two key ways. First, consider the problem of minimizing the sparsity of a gradient for a fixed variance, while we consider the reverse problem, that is, minimizing the variance subject to a sparsity budget. The second more important difference is that while focuses on entry-wise sparsification, we consider a general problem where we sparsify according to any atomic decomposition. For instance, our approach directly applies to sparsifying the singular values of a matrix, which gives rise to faster training algorithms.
Finally, low-rank factorizations and sketches of the gradients when viewed as matrices were proposed in ; arguably most of these methods (with the exception of ) aimed to address the high flops required during inference by using low-rank models. Though they did not directly aim to reduce communication, this arises as a useful side effect.
Problem Setup
In machine learning, we often wish to find a model minimizing the empirical risk
where is the -th data point. One way to approximately minimize is by using stochastic gradient methods that operate as follows:
where is some initial model, is the step size, and is a stochastic gradient of , i.e.it is an unbiased estimate of the true gradient . Mini-batch SGD, one of the most common algorithms for distributed training, computes as an average of gradients, each evaluated on randomly sampled data from the training set. Mini-batch SGD is easily parallelized in the parameter server (PS) setup, where a PS stores the global model, and compute nodes split the effort of computing the gradients. Once the PS receives these gradients, it applies them to the model, and sends it back to the compute nodes.
Since variance is a proxy for speed of convergence, in the context of communication-efficient stochastic gradient methods, one can ask: What is the smallest possible variance of an unbiased stochastic gradient that can be represented with bits? Note that under the unbiased assumption, minimizing variance is equivalent to minimizing the second moment of the random vector. This meta-optimization can be cast as the following meta-optimization:
Here, the expectation is taken over the randomness of . We are interested in designing a stochastic approximation that “solves” this optimization. However, it seems difficult to design a formal, tractable version of the last constraint. In the next section, we replace this with a simpler constraint that instead requires that is sparse with respect to a given atomic decomposition.
Atomo: Atomic Decomposition and Sparsification
Let be an inner product space over and let denote the induced norm on . In what follows, you may think of as a stochastic gradient of the function we wish to optimize. An atomic decomposition of is any decomposition of the form for some set of atoms . Intuitively, consists of simple building blocks. We will assume that for all , , as this can be achieved by a positive rescaling of the .
An example of an atomic decomposition is the entry-wise decomposition where is the standard basis. More generally, any orthonormal basis of gives rise to a unique atomic decomposition of any . While we focus on finite-dimensional vectors, one could use Fourier and wavelet decompositions in this framework for infinite-dimensional spaces. When considering matrices, the singular value decomposition gives an atomic decomposition in the set of rank-1 matrices. More general atomic decompositions have found uses in a variety of situations, including solving linear inverse problems .
We are interested in finding an approximation to with fewer atoms. Our primary motivation is that this reduces communication costs, as we only need to send atoms with non-zero weights. We can use whichever decomposition is most amenable for sparsification. For instance, if is a low rank matrix, then its singular value decomposition is naturally sparse, so we can save communication costs by sparsifying its singular value decomposition instead of its entries.
where , for . We refer to this sparsification scheme as atomic sparsification. Note that the ’s are independent. Recall that we assumed above that for all . We have the following lemma about .
An equivalent form of this optimization problem was previously presented in (Section 6.1). The authors considered this problem for entry-wise sparsification and found a closed-form solution for . We give a version of their result but extend this to a closed-form solution for all . A similar optimization problem was given in , which instead minimizes sparsity subject to a variance constraint.
We will show that the Algorithm 1 produces a probability vector solving (3) for . While we show in Appendix B that this result can be derived using the KKT conditions, we use an alternative method that focuses on a relaxation of (3) in order to better understand the structure of the problem. This approach has the added benefit of shedding light on what variance is achieved by solving (3).
Note that (3) has a non-empty feasible set only for . Define . To understand how to solve (3), we first consider the following relaxation:
We have the following lemma about the solutions to (4), first shown in .
Any feasible vector to (4) satisfies . This is achieved iff
Lemma 2 implies that if we ignore the constraint that , then the optimal is achieved by setting . If the quantity in the right-hand side is greater than 1, this does not give us an actual probability. This leads to the following definition.
An atomic decomposition is -unbalanced at entry if .
Fix the atomic decomposition of . If there are no -unbalanced entries then we say that the is -balanced. We have the following lemma which guarantees that is -balanced for not too large.
An atomic decomposition is -balanced iff .
Lemma 2 gives us the optimal way to sparsify -balanced vectors, since the that is optimal for (4) is feasible for (3). Moreover, the iff condition in Lemma 2 implies that the optimal assignment of the are between 0 and 1 iff is -balanced. Suppose now that is -unbalanced at entry . We cannot assign as in (5). We will show that setting is optimal in this setting. This comes from the following lemma.
Suppose that is -unbalanced at entry and that is feasible in (3). Then that is feasible in (3) such that and .
Lemmas 2 and 4 imply the following theorem about solutions to (3).
Suppose we sparsify as in (2) with sparsity budget .
with equality if and only if .
and is minimized by with where .
This theorem implies that Algorithm 1 produces a vector solving (3). Note that due to the sorting requirement in the input, the algorithm requires operations. As we discuss in Appendix B, we could instead do this in operations by, instead of sorting and iterating through the values in order, simply selecting the next unvisited index maximizing and performing the same test/updates. As we show in Appendix B, we need to select at most indices before the if statement in Algorithm 1 holds. Whether to sort or do selection depends on the size of relative to .
Relation to QSGD and TernGrad
In this section, we will discuss how Atomo is related to two recent quantization schemes, 1-bit QSGD and TernGrad . We will show that in certain cases, these schemes are versions of the Atomo for a specific sparsity budget . Both schemes use the entry-wise atomic decomposition.
QSGD takes as input and . This governs the number of quantization buckets. When , this is referred to as 1-bit QSGD. 1-bit QSGD produces a random vector defined by
Here, the are independent random variables. A straightforward computation shows that can be defined equivalently by
where . Therefore, 1-bit QSGD exactly uses the atomic sparsification framework in (2) with . The total sparsity budget is therefore given by
By Lemma 3 any is -balanced for this . Therefore, Theorem 5 implies that the optimal way to assign with this given is . Since this agrees with (6), this implies that 1-bit QSGD performs variance-optimal entry-wise sparsification for sparsity budget .
2 TernGrad
Similarly, TernGrad takes as input , and produces a sparsified version given by
where . A straightforward computation shows that can be defined equivalently by
where . Therefore, TernGrad exactly uses the atomic sparsification framework in (2) with . The total sparsity budget is given by
By Lemma 3, any is -balanced for this . Therefore, Theorem 5 implies that the optimal way to assign with this given is . This agrees with (7). Therefore, TernGrad performs variance-optimal entry-wise sparsification for sparsity budget .
where . Note that for all , , so this does give us a valid probability. We can define equivalently by
By Lemma 3, the optimal way to assign with this given is . Since this agrees with (8), Theorem 5 implies the following theorem.
Spectral-Atomo: Sparsifying the Singular Value Decomposition
In this section we compare different methods for matrix sparsification. The first uses Atomo on the entry-wise decomposition of a matrix, and the second uses Atomo on the singular value decomposition (SVD) of a matrix. We refer to this second approach as Spectral-Atomo. We show that under concrete conditions, Spectral-Atomo incurs less variance than sparsifying entry-wise. We present these conditions and connect them to the equivalence of certain matrix norms.
For a rank matrix , denote its singular value decomposition by
When , we define this to be where .
Comparing matrix sparsification methods:
Suppose that is the vector space of real matrices. Given , there are two standard atomic decompositions of . The first is the entry-wise decomposition
The second is the singular value decomposition
If is small, it may be more efficient to communicate the entries of the SVD, rather than the entries of the matrix. Let and denote the random variables in (2) corresponding to the entry-wise decomposition and singular value decomposition of , respectively. We wish to compare these two sparsifications.
In Table 1, we compare the communication cost and second moment of these two methods. The communication cost is the expected number of non-zero elements (real numbers) that need to be communicated. For , a sparsity budget of corresponds to non-zero entries we need to communicate. For , a sparsity budget of gives a communication cost of due to the singular vectors. We compare the optimal second moment from Theorem 5.
To compare the second moment of these two methods under the same communication cost, we and suppose is -balanced entry-wise. By Theorem 5 and Lemma 3, the second moment in Table 1 is achieved iff
To achieve the same communication cost with , we take a sparsity budget of . By Theorem 5 and Lemma 3, the second moment in Table 1 is achieved iff
For any matrix over .
Experiments
We present an empirical study of Spectral-Atomo and compare it to the recently proposed QSGD , and TernGrad , on a different neural network models and data sets, under real distributed environments. Our main findings are as follows:
We observe that spectral-Atomo provides a useful alternative to entry-wise sparsification methods, it reduces communication compared to vanilla mini-batch SGD, and can reduce training time compared to QSGD and TernGrad by up to a factor of and respectively. For instance, on VGG11-BN trained on CIFAR-10, spectral-Atomo with sparsity budget 3 achieves speedup over vanilla SGD, while 4-bit QSGD achieves on a cluster of 16, g2.2xlarge instances. Both Atomo and QSGD greatly outperform TernGrad as well.
We observe that spectral-Atomo in distributed settings leads to models with negligible accuracy loss when combined with parameter tuning.
We compare spectral-Atomocode available at: https://github.com/hwang595/ATOMO with different sparsity budgets to -bit QSGD across a distributed cluster with a parameter server (PS), implemented in mpi4py and PyTorch and deployed on multiple types of instances in Amazon EC2 (e.g.m5.4xlarge, m5.2xlarge, and g2.2xlarge), both PS and compute nodes are of the same type of instance. The PS implementation is standard, with a few important modifications. At the most basic level, it receives gradients from the compute nodes and broadcasts the updated model once a batch has been received.
In our experiments, we use data augmentation (random crops, and flips), and tuned the step-size for every different setup as shown in Table 5 in Appendix D. Momentum and regularization terms are switched off to make the hyperparamter search tractable and the results more legible. Tuning the step sizes for this distributed network for three different datasets and eight different coding schemes can be computationally intensive. As such, we only used small networks so that multiple networks could fit into GPU memory. To emulate the effect of larger networks, we use synchronous message communication, instead of asynchronous.
Each compute node evaluates gradients sampled from its partition of data. Gradients are then sparsified through QSGD or spectral-Atomo, and then are sent back to the PS. Note that spectral-Atomo transmits the weighted singular vectors sampled from the true gradient of a layer. The PS then combines these, and updates the model with the average gradient. Our entire experimental pipeline is implemented in PyTorch with mpi4py , and deployed on either g2.2xlarge, m5.2xlarge and m5.4xlarge instances in Amazon AWS EC2. We conducted our experiments on various models, datasets, learning tasks, and neural network models as detailed in Table 2.
Scalability
We study the scalability of these sparsification methods on clusters of different sizes. We used clusters with one PS and compute nodes. We ran ResNet-34 on CIFAR-10 using mini-batch SGD with batch size split among compute nodes. The experiment was run on m5.4xlarge instances of AWS EC2 and the results are shown in Figure 2.
While increasing the size of the cluster, decreases the computational cost per worker, it causes the communication overhead to grow. We denote as computational cost, the time cost required by each worker for gradient computations, while the communication overhead is represented by the amount time the PS waits to receive the gradients by the slowest worker. This increase in communication cost is non-negligible, even for moderately-sized networks with sparsified gradients. We observed a trade-off in both sparsification approaches between the information retained in the messages after sparsification and the communication overhead.
End-to-end convergence performance
We evaluate the end-to-end convergence performance on different datasets and neural networks, training with spectral-Atomo(with sparsity budget ), QSGD (with bits), and ordinary mini-batch SGD. The datasets and models are summarized in Table 2. We use ResNet-18 and VGG11-BN for CIFAR-10 and SVHN . Again, for each of these methods we tune the step size. The experiments were run on a cluster of 16 compute nodes instantiated on g2.2xlarge instances.
The gradients of convolutional layers are 4 dimensional tensors with shape of where are two spatial dimensions and is the size of the convolutional kernel. However, matrices are required to compute the SVD for spectral-Atomo, and we choose to reshape each layer into a matrix of size . This provides more flexibility on the sparsity budget for the SVD sparsification. For QSGD, we use the bucketing and Elias recursive coding methods proposed in , with bucket size equal to the number of parameters in each layer of the neural network.
Figure 3 shows how the testing accuracy varies with wall clock time. Tables 3 and 4 give a detailed account of speedups of singular value sparsification compared to QSGD. In these tables, each method is run until a specified accuracy.
We observe that QSGD and Atomo speed up model training significantly and achieve similar accuracy to vanilla mini-batch SGD. We also observe that the best performance is not achieve with the most sparsified, or quantized method, but the optimal method lies somewhere in the middle where enough information is preserved during the sparsification. For instance, 8-bit QSGD converges faster than 4-bit QSGD, and spectral-Atomo with sparsity budget 3, or 4 seems to be the fastest. Higher sparsity can lead to a faster running time, but extreme sparsification can adversely affect convergence. For example, for a fixed number of iterations, 1-bit QSGD has the smallest time cost, but may converge much more slowly to an accurate model.
Conclusion
In this paper, we present and analyze Atomo, a general sparsification method for distributed stochastic gradient based methods. Atomo applies to any atomic decomposition, including the entry-wise and the SVD of a matrix. Atomo generalizes 1-bit QSGD and TernGrad, and provably minimizes the variance of the sparsified gradient subject to a sparsity constraint on the atomic decomposition. We focus on the use Atomo for sparsifying matrices, especially the gradients in neural network training. We show that applying Atomo to the singular values of these matrices can lead to faster training than both vanilla SGD or QSGD, for the same communication budget. We present extensive experiments showing that Atomo can lead to up to a speed-up in training time over QSGD and up to speed-up in training time over TernGrad.
In the future, we plan to explore the use of Atomo with Fourier decompositions, due to its utility and prevalence in signal processing. More generally, we wish to investigate which atomic sets lead to reduced communication costs. We also plan to examine how we can sparsify and compress gradients in a joint fashion to further reduce communication costs. Finally, when sparsifying the SVD of a matrix, we only sparsify the singular values. We also note that it would be interesting to explore jointly sparsification of the SVD and and its singular vectors, which we leave for future work.
Acknowledgement
This work was supported in part by AWS Cloud Credits for Research from Amazon.
References
Appendix A Proof of results
Suppose we have some satisfying the conditions in (4). We define two auxiliary vectors by
Then note that using the fact that , we have
By the Cauchy-Schwarz inequality, this implies
This proves the first part of Lemma 2. In order to have , (9) implies that we need
By the Cauchy-Schwarz inequality, this occurs iff and are linearly dependent. Therefore, for some constant . Solving, this implies . Since , we have
Therefore, , which implies the second part of the theorem. ∎
A.2 Proof of Lemma 4
Fix that is feasible in (3). To prove Lemma 4 we will require a lemma. Given the atomic decomposition , we say that is -unbalanced at if , which is equivalent to being unbalanced in this atomic decomposition at . For notational simplicity, we will assume that is -unbalanced at . Let . We define the following notation:
Note that under this notation, Lemma 2 implies that for all ,
Suppose that is feasible and that there is some set such that
is -balanced.
.
Then there is a vector that is feasible satisfying and .
Suppose that such a set exists. Let . Note that we have
Note that by Assumption 1 and Lemma 2, we have
Since for , we have . Therefore,
Combining this with Assumption 2, we have
To show that the RHS of (13) is at most , it suffices to show
However, note that since , the RHS of (14) satisfies
Therefore, (14) holds, completing the proof. ∎
We can now prove Lemma 4. In the following, we will refer to Conditions 1 and 2, relative to some set , as the conditions required by Lemma 9.
We first show this in the case that . Here we have the atomic decomposition
The condition that is -unbalanced at implies
In particular, this implies . For , Condition 1 is equivalent to
Note that and that by assumption. Since , we know that and so Condition 1 holds. Similarly, Condition 2 becomes
which holds by assumption. Therefore, Lemma 4 holds for .
Now suppose that , is some feasible probability vector, and that is -unbalanced at index . We wish to find an satisfying Conditions 1 and 2. Consider . Note that for such , . By our unbalanced assumption, we know that Condition 2 holds for . If is -balanced, then Lemma 9 implies that we are done.
Assume that is not -balanced. After relabeling, we can assume it is unbalanced at . Let . Therefore,
Combining this with the -unbalanced assumption at , we find
Let . Then note that (16) implies that is -unbalanced at . Inductively applying this theorem, this means that we can find a vector such that and . Moreover, . Therefore, if we let be the vector that equals on and with , we have
Appendix B Analysis of Atomo via the KKT Condtions
In this section we show how to derive Algorithm 1 using the KKT conditions. Recall that we wish to solve the following optimization problem:
We first note a few immediate consequences.
If then the problem is infeasible. Note that when , the optimal thing to do is to set all , in which case no sparsification takes place.
If , then . This follows from the fact that this does not change the value of , and the objective could be decreased by allocating more to the associated to non-zero . Therefore we can assume that all .
If , then we can assume . Otherwise, suppose but . Let denote the vector with switched. We then have
We therefore assume and . As above we define . While the formulation of (17) does not allow direct application of the KKT conditions, since we have a strict inequality of , this is fixed with the following lemma.
The minimum of (17) is achieved by some satisfying
Define by . This vector is clearly feasible in (17). Let be any feasible vector. If then for any we have
Therefore, . A straightforward computations shows that . Note that this implies that we can restrict to the feasbile set
This defines a compact region . Since is continuous on this set, its maximum value is obtained at some .∎
The KKT conditions then imply that at any point solving (17), we must have
for some . Since for all , we actually must have . We therefore have two conditions for all .
.
Note that in either case, to have feasible we must have . Combining this with the fact that we can always select , we obtain the following partial characterization of the solution to (17). For some , we have while for . Combining this with the constraint that , we have
Thus, we need to select such that the in (21) are bounded above by 1. Let denote the first element of for which this holds. Then the condition that for is exactly the condition that is -balanced (see Definition 1. In particular, Lemma 2 implies that, fixing for , the optimal way to assign the remaining is by
This agrees with (21) for . In particular, the minimal value of occurs at the first value of such that the in (21) are bounded above by 1.
Algorithm 1 scans through the sorted and finds the first value of for which the probabilities in (21) are in $pO(n\log n)O(sn)\lambda_{i}|\lambda_{i}|sO(sn)$ complexity algorithm.
Appendix C Equivalence of norms
We are often interested in comparing norms on vectors spaces. This naturally leads to the following definition.
As it turns out, norms on finite-dimensional vector spaces are always equivalent.
In order to compare norms, we often wish to determine the tightest constants which give equivalence between them. In Section 5, we are particularly interested in comparing the and on the space of matrices. We have the following lemma.
Suppose that has the singular value decomposition
We will first show the left inequality. First, note that for any matrix , . This follows directly from the fact that for a -dimensional vector , . We will also use the fact that for any vectors , . We then have
For the right inequality, note that we have
where is the -th standard basis vector, while is the -th standard basis vector. We then have
In fact, these are the best constants possible. To see this, first consider the matrix with a 1 in the upper-left entry and 0 elsewhere. Clearly, , so the right-hand inequality is tight. For the left-hand inequality, consider the all-ones matrix . This has one singular value, , so . On the other hand, . Therefore, in this case.
Appendix D Hyperparameter optimization
We firstly provide results of step size tunning, as shows in Table 5 we reported stepsize tunning results for all of our experiments. We tuned these step sizes by evaluating many logarithmically spaced step sizes (e.g., ) and evaluated on validation loss.
This step sizes tuning, for 8 gradient coding methods and 3 datasets was only possible because fairly small networks were used.
Appendix E Additional Experiments
Runtime analysis: We empirically study runtime costs of spectral-Atomo with sparsity budget set at 1, 2, 3, 6 and made comparisons among -bit QSGD and TernGrad. We deployed distributed training on ResNet-18 with batch size on the CIFAR-10 dataset run with m5.2xlarge instances. As shown in Figure 4, there is a trade-off between the amount of communication per iteration and the running time for both singular value sparsification and QSGD. In some scenarios, spectral-Atomo attains a higher compression ratio than QSGD and TernGrad. For example, singular value sparsification with sparsity budget 1 may communicate smaller messages than -bit QSGD and Terngrad.