Error Compensated Quantized SGD and its Applications to Large-scale Distributed Optimization

Large-scale distributed optimization is of great importance in various applications. For data-parallel based distributed learning, the inter-node gradient communication often becomes the performance bottleneck. In this paper, we propose the error compensated quantized stochastic gradient descent algorithm to improve the training efficiency. Local gradients are quantized to reduce the communication overhead, and accumulated quantization error is utilized to speed up the convergence. Furthermore, we present theoretical analysis on the convergence behaviour, and demonstrate its advantage over competitors. Extensive experiments indicate that our algorithm can compress gradients by a factor of up to two magnitudes without performance degradation.


Introduction
Due to the explosive growth of data in recent years, largescale machine learning has attracted increasing attention in various domains, such as computer vision and speech recognition. Distributed optimization is one of the core building blocks in these applications, where the training data is often too massive to be efficiently handled by a single computation node.
A commonly used distributed learning framework is data parallelism, in which the whole data set is split and stored on multiple nodes within a cluster. Each node computes its local gradients and communicates gradients with other nodes to update model parameters. For such learning systems, the time consumption can be roughly categorized as either computation or communication. The communication often becomes the performance bottleneck, especially for large clusters and/or models with tons of parameters. There have been several works attempting to improve the efficiency of distributed learning by reducing the communication cost. Some methods focused on quantizing gradients into the fixed-point numbers (Zhou et al., 2016;Alistarh et al., 2017), so that much fewer bits are needed to be transimitted. More aggressive quantization, such as the binary or ternary representation, has also been investigated in (Seide et al., 2014;Strom, 2015;Wen et al., 2017). Other methods imposed sparsity onto gradients during communication, where only a small fraction of gradients get exchanged across nodes in each iteration (Wangni et al., 2017;Lin et al., 2018).
The underlying ideas of these methods are basically to compress gradients into some special form, in which each entry can be represented by much fewer bits than the original 32-bit floating-point number. Such compression introduces extra stochastic noises, i.e. quantization error, into the optimization process, and will slow down the convergence or even leads to divergence. 1Bit-SGD (Seide et al., 2014) adopted the error feedback scheme, which was to compensate the current local gradients with quantization error from the last iteration, before feeding it into the quantization function. Although authors stated that this improved the convergence behaviour, no theoretical analysis was given to evidence its effectiveness.
In this paper, we propose the error compensated quantized stochastic gradient descent method, namely ECQ-SGD. Our algorithm also utilizes the error feedback scheme, but here we accumulate all the previous quantization errors, rather than only from the last iteration as in 1Bit-SGD. Although empirical evaluation shows that this modification leads to faster and more stable convergence than many baseline methods, it is non-trivial to establish the theoretical guarantee for this phenomenon.
In , authors proved that for their proposed QSGD algorithm, the number of iterations required to reach a certain sub-optimality gap is proportional to the variance bound of stochastic quantized gradients. However, this cannot explain our method's convergence behaviour, since our quantized gradients are biased estimations, unlike in QSGD. Actually, the variance bound of quantized gradients is even larger than that in QSGD, due to the accumu-lated quantization error. In order to address this issue, we present the convergence analysis from another perspective, and prove that our algorithm has a tighter worst-case error bound than QSGD with properly chosen hyper-parameters. It can be shown that our proposed error feedback scheme can well suppress the quantization error's contribution to the error bound, leading to a smaller sub-optimality gap than QSGD, as we observed in experiments.
The remaining part of this paper will be organized as follows. We briefly review related works in Section 2, and present preliminaries in Section 3. In Section 4 and 5, we propose the ECQ-SGD algorithm and its theoretical analysis. Extensive experiments are carried out in Section 6, followed by the final conclusions.

Related Works
There have been several works proposed to speed up stochastic gradient descent in the context of distributed learning. Some adopt asynchronous update to decouple computation from communication, while others focus on reducing the communication overhead with gradient quantization or sparsification.
Asynchronous SGD. Hogwild! (Recht et al., 2011) is a lock-free implementation of paralleled SGD that can achieve a nearly optimal rate of convergence for certain problems. (Dean et al., 2012) proposes the DistBelief framework, which adopts asynchronous SGD to train deep networks under a distributed setting. The convergence behaviour of asynchronous SGD have been extensively analysed in many works (Chaturapruek et al., 2015;Zhao & Li, 2016;Zheng et al., 2017;De Sa et al., 2017). Gradient Quantization. In (Seide et al., 2014), 1Bit-SGD is proposed to quantize each gradient component to either 1 or -1 with zero-thresholding. An error feedback scheme is introduced during quantization, to compensate the quantization error from the last iteration. Similar ideas are adopted in (Strom, 2015), which accumulates local gradients across iterations, and only transmits gradient components exceeding a pre-selected threshold. Wen et al. further extend this idea and compress gradients into ternary values with a stochastic quantization function to ensure the unbiasness (Wen et al., 2017). Quantized SGD  randomly quantizes gradients using uniformly distributed quantization points, and detailed analysis is presented to address its convergence. ZipML  introduces an optimal quantization strategy via dynamically choosing quantization points based on the distribution. Zhou et al. propose the DoReFa-Net to train convolutional networks with inputs, weights, and gradients all quantized into fixed-point numbers (Zhou et al., 2016).
Gradient Sparsification. The gradient dropping method is proposed in (Aji & Heafield, 2017) to introduce sparsity into gradients to reduce the communication cost. In (Wangni et al., 2017), gradient sparsification is modelled as a linear programming problem, aiming to minimize the variance increase of quantized gradients. Lin et al. propose the deep gradient compression algorithm, utilizing momentum correction, gradient clipping, momentum factor masking, and warm-up training to achieve higher sparsity without losing the accuracy (Lin et al., 2018).

Preliminaries
We consider the following unconstrained optimization: where w ∈ R d and f : R d → R is a convex and differentiable function we wish to minimize. Often, the objective function f is defined on a set of training samples D = {x i }, and the need for distributed optimization arises when the training set is too large to fit into a single node.
Assume we are solving this distributed optimization problem in a data-parallel manner. The full set D is evenly distributed across P nodes, and the data subset located at the p-th node is denoted as D p . Formally, we wish to optimize: Figure 1 depicts how model parameters w are updated via distributed SGD. Every node initializes its local model replica using the same random seed, to ensure the consistency of all model replicas. In the t-th iteration, each node randomly selects a mini-batch of training samples, computes local gradients, and then broadcasts to all the other nodes. When one node gathers all the local gradients sent by other nodes, global gradients can be computed and used to update model parameters.

Error Compensated Quantized SGD
For distributed optimization under the data-parallel setting, it is required to exchange local gradients between every two nodes in each iteration. For large-scale distributed optimization with massive number of model parameters, e.g. training a convolutional neural network, gradient communication may become the performance bottleneck.
One possible solution is to quantize local gradients before transmission, so as to reduce the communication cost. In this section, we propose the ECQ-SGD (Error Compensated Quantized SGD) algorithm, which updates model parameters with quantized local gradients. In each iteration, current local gradients are compensated with accumulated quantization error from all the previous iterations, and then fed into a stochastic quantization function for compression.
Let Q : R d → C d be an unbiased stochastic quantization function, which maps each component in a d-dimensional vector into some element from the quantization codebook C.
The codebook usually only contains limited number of elements, so the quantized vector can be efficiently encoded.
In each iteration, each node quantizes its local gradients before broadcasting:g p is the local gradients of the p-th node at the t-th iteration, andg (t) p is its quantized counterpart. When a node receives all the local gradients sent by other nodes, it computes the global gradients and updates its local model replica via: where η > 0 is the learning rate.
The core idea of ECQ-SGD is that when quantizing local gradients, both the current gradients and previously accumulated quantization error should be taken into consideration. Specifically, we use h (t) p to denote the accumulated quantization error of the p-th node at the t-th iteration: where β is the time decaying factor (0 ≤ β ≤ 1). Note that the accumulated quantization error can be incrementally updated: where h (0) p = 0. The quantized local gradients are now computed by applying the quantization function to the compensated gradients: where α is the compensation coefficient (α ≥ 0).
Here, we adopt a stochastic quantization function with uniformly distributed quantization points, similar to QSGD , where the i-th component is quantized as:g where g acts as the scaling factor (possible choices include l 2 -norm and l ∞ -norm), and ξ (·) is a stochastic function which maps a scalar to some element in 0, 1 s , . . . , 1 : s , otherwise (9) when |g i | / g falls in the interval l s , l+1 s . The hyperparameter s defines the number of non-zero quantization levels: a larger s leads to more fine-grained quantization, at the cost of increased communication cost. From now on, we use Q s (·) to denote the quantization function with s non-zero quantization levels.
After quantization, we only need r = ⌈log 2 (2s + 1)⌉ bits to encode each quantizedg i , and one floating-point number to represent the scaling factor g . The overall communication cost is 32 + dr bits (r ≪ 32), which is much smaller than 32d bits needed by the original 32-bit full-precision gradients. More efficient entropy encoding schemes, e.g. Huffman encoding (Huffman, 1952), can further reduce the communication cost. Let d k denote the number of dimensions assigned to the k-th quantization level, then the overall encoding length is at most We summarize the overall workflow in Algorithm 1. Since all the local gradients are quantized before transmission, the communication overhead can be greatly reduced. This is crucial to the learning efficiency, especially when the inter-node communication is the performance bottleneck.

Theoretical Analysis
In this section, we analyse the convergence behaviour of the proposed ECQ-SGD algorithm. We start with the discussion on the variance bound of quantization error. After that, we build up the error bound for quadratic optimization problems, and demonstrate ECQ-SGD's advantage over QSGD.

Variance Bound of Quantization Error
We define the quantization error as the difference between the compensated local gradients and its quantization results: If the quantization function uses l 2 -norm as the scaling factor, then it is identical to the one used in QSGD. In this case, we can directly borrow their conclusions on the following two properties of quantization error: Lemma 1.  For any vector v ∈ R d , let ε = Q s (v) − v denote the quantization error, then we have: Here, we assume that the second moment of local gradients are bounded, i.e. g (t) p 2 2 ≤ B, ∀(p, t). Under this assumption, the quantization error in QSGD satisfies: where γ = min(d/s 2 , √ d/s).
In ECQ-SGD, however, the vector to be quantized is a linear combination of current local gradients and accumulated quantization error. Still, we can derive a slightly relaxed bound for the quantization error's second moment: Lemma 2. For the p-th node, its quantization error at the t-th iteration satisfies: where λ = α 2 γ + (β − α) 2 .
Proof. Please refer to the supplementary material.
In ECQ-SGD, we usually select hyper-parameters (α, β) to satisfy λ < 1 (i.e. let 0 < α < 2 γ+1 and β = 1), ensuring that the following variance bound of quantization error holds for any iteration t: Therefore, as long as α 2 γ 1−λ is small, the variance bound of quantization error in the ECQ-SGD algorithm is still very close to that of QSGD. Also, it is worth noting that this upper bound does not depend on t, indicating that the variance bound will not diverge during the optimization.
Based on the above results, one can derive that the quantized local gradients' variance bound in ECQ-SGD is also larger than that in QSGD. According to the convergence analysis in QSGD, the number of iterations required to reach certain sub-optimality is proportional to the stochastic gradients' variance bound. This implies that following the convergence analysis in QSGD, one would conclude that ECQ-SGD should converge slower than QSGD, which actually conflicts with experimental results (as shown later). Therefore, we need to analyse ECQ-SGD's convergence behaviour from another perspective to explain its advantage over QSGD as observed in practice.

Convergence for Quadratic Optimization
Now we analyse how model parameters converge to the optimal solution in ECQ-SGD. Consider the following convex quadratic optimization: where the whole data set D = D 1 ∪ · · · ∪ D P is evenly split and stored at P nodes. By summing up all A i s and b i s, the above optimization is equivalent to: where A = (Ai,bi)∈D A i and b = (Ai,bi)∈D b i . The smallest and largest singular values of A are denoted as a 1 and a 2 , respectively, i.e. a 1 I A a 2 I. Here, we assume a 1 > 0 to ensure the strong convexity, which leads to the closed-form optimal solution w * = −A −1 b.
In each iteration, every node constructs a mini-batch of training samples {(A i , b i )}, uniformly sampled from its local data subset. The resulting local gradients can be represented as the underlying true gradients plus a stochastic noise term, which is: where {ξ (t) p } are i.i.d. random noises with zero mean. The quantized local gradients are given by: Recall the update rule of ECQ-SGD, we have: where auxiliary variables are defined as follows: From Lemma 2, we can derive the variance bound for the pseudo quantization error: Below, we present the worst-case upper bound on the expected distance between w (t+1) , solution obtained in the (t + 1)-th iteration, and w * , the optimal solution.
Theorem 1. Let f (w) = 1 2 w T Aw + b T w be the objective function to be minimized, whose optimal solution is denoted as w * , and R 2 = sup w∈R d w − w * 2 2 . Assume the stochastic noise in the mini-batch's gradients satisfies E ξ (t) 2 2 ≤ σ 2 , then the error bound in the ECQ-SGD algorithm satisfies: where H = I − ηA and: Proof. Please refer to the supplementary material.
It is worth mentioning that our algorithm only differs from QSGD in the last two terms of error bound given above; the other two terms are identical in both algorithms. Now we analyse Θ (t ′ ) 's value to reveal the difference between ECQ-SGD and QSGD. Firstly, we can prove that: Lemma 3. If the learning rate satisfies ηa 1 < 1, then: where ν = (β − α)/(1 − ηa 1 ).
To simplify further discussions, we introduce the auxiliary variable τ (t ′ ) , defined as: which stands for the upper bound of quantization error ε (t ′ ) 's contribution to the final error bound (21). Similarly, the upper bound of quantization error's contribution in QSGD is given by: which is actually a special case of ECQ-SGD when α = 0.
Recall that in (13), by ensuring λ < 1, the variance bound of quantization error in ECQ-SGD is relatively close to that of QSGD. Therefore, with properly chosen hyperparameters, ECQ-SGD's reduction ratio in τ (t ′ ) (comparing against QSGD) approaches to zero as the time gap (t − t ′ ) grows to infinity: Lemma 4. If β = 1 − ηa 1 and α > 0 satisfies that λ = α 2 γ + (β − α) 2 < 1, then we have: The detailed proof for Lemma 3 and 4 can be found in the supplementary material. In practice, since the learning rate η ≪ 1 a1 , we can simply set β = 1 and α to some small positive number to approximately satisfy the requirements in Lemma 4.
Lemma 4 implies that as the iteration goes on, ECQ-SGD can better suppress all the previous quantization errors' contribution to the error bound (21) than QSGD. An intrinsic understanding is that with the error feedback scheme, quantization errors from different iterations are cancelled out when evaluating the final error bound, leading to a tighter worst-case upper bound than that of QSGD.

Experiments
In this section, we demonstrate the effectiveness of our proposed ECQ-SGD algorithm with extensive experiments. We start with linear models for convex optimization, and then extend to non-convex optimization with deep convolutional neural networks. We further analyse the scalability for large-scale scenarios, and finish the discussion with a detailed study on choices of hyper-parameters.

Linear Models
In the previous convergence analysis, we claim that for convex quadratic optimization, ECQ-SGD can reduce the quantization error's contribution to the error bound, which leads to better solution after convergence. Now we verify this by comparing the convergence behaviour of ECQ-SGD and QSGD for training linear regression models.
Here we start with three synthetic datasets: Syn-256, Syn-512, and Syn-1024. Each dataset consists of 10k training samples, and the suffix denotes the feature dimension d. The training sample is generated as y i = w * T x i +ǫ i , where w * ∈ R d is the underlying model parameters we wish to obtain, and {ǫ i } are i.i.d. random noises. The learning rate is set to 0.02, and both QSGD and ECQ-SGD use l 2 -norm as the scaling factor and 4 non-zero quantization levels, i.e. s = 4. For ECQ-SGD, we let α = 0.2 and β = 0.9.
In Figure 2, we compare the loss function's value (top) and distance to the optimal solution (bottom) in each iteration. For all three datasets, the convergence of loss function's value of ECQ-SGD is more close to the 32-bit fullprecision SGD, and significantly faster than QSGD. On the other hand, the gap between QSGD (or ECQ-SGD) and 32Bit-FP in the distance to the optimal solution measures the quantization error's contribution to the error bound as defined in (21). The distance gap of ECQ-SGD is clearly smaller than QSGD, indicating that the quantization error's contribution to the error bound is well suppressed. Now we compare the run-time speed between QSGD and ECQ-SGD on a larger dataset, Syn-20k, which consists of 50k training samples and the feature dimension is 20k. In Figure 3, we report the decomposed time consumption and test loss (in brackets) of various methods after 1k iterations. We discover that ECQ-SGD achieves similar test loss with 32Bit-FP in a shorter time than both 32Bit-FP and QSGD.
Although ECQ-SGD requires extra encoding and decoding time, the overall training speed is still improved due to the reduction in the gradient communication time. Furthermore, we extend the evaluation to two publicly available datasets, YearPredictionMSD for regression and gisette for classification (Chang & Lin, 2011). Linear regression and logistic regression models are trained with different gradient quantization methods on these two datasets respectively. The comparison on the loss function's value and communication cost, averaged from five random runs, is as depicted in Figure 4 and Table 1. Here we use squared l 2 -loss for regression and log-loss for classification. The communication cost is measured by the total number of bits to encode gradients after 1k iterations. We use entropy encoding to fully exploit the sparsity after gradient quantization for all methods.  From Figure 4, we observe that all methods except 1Bit-SGD converge at similar speed, and the final performance is also almost identical to each other. This may due to the relatively small number of feature dimensions (90) of the YearPredictionMSD dataset, so that different gradient quantization methods do not have significant performance gap.
For the gisette dataset, whose feature dimension is 5000, both TernGrad and ECQ-SGD can still match the performance of the 32-bit full-precision SGD, while 1Bit-SGD and QSGD suffer more severe performance degradation. On the other hand, ECQ-SGD achieves much higher compression ratio (281.88×) than TernGrad (34.67×).

Convolutional Neural Networks
Now we evaluate the ECQ-SGD algorithm for training convolutional neural networks, which is a highly non-convex optimization problem.
The experiments are carried out on the CIFAR-10 dataset (Krizhevsky, 2009), which consists of 60k images from 10 categories. We follow the common protocol, using 50k images for training and the remaining 10k images for evaluation. We train the ResNet-20 model (He et al., 2016) with different gradient quantization methods, and the results are as reported in Figure 5. For all methods, the batch size is set to 128, and the learning rate starts from 0.1, divided by 10 at 40k and 60k iterations. The training process is terminated at the end of the 200-th epoch (∼78k iterations).
In the first column of Figure 5, we compare the loss function's value and overall communication overhead of various methods. The hyper-parameters of each method 1 are selected to achieve negligible accuracy loss, comparing with the 32-bit full-precision baseline. We discover that all methods converge at a similar speed, but ECQ-SGD offers over 80× reduction in the communication cost and significantly outperforms other gradient quantization methods.
In the second and third column of Figure 5, we present more detailed comparison against QSGD, since it is the most relevant one with our method. Different scaling factors are used: l 2 -norm for the second column, and l ∞ -norm for the third column. Both methods use a bucket size of 4096 for fair comparison. We observe that ECQ-SGD is consistently superior to QSGD in both convergence speed and classification accuracy, while the reduction in the communication cost of these two methods are similar under the same hyper-parameter settings.

Performance Model
We adopt the performance model proposed in (Yan et al., 2015) to evaluate the scalability of our ECQ-SGD algorithm. Lightweight profiling on the computation and communication time is carried out to estimate the learning efficiency for larger clusters. Major hardware specifications are as follows: Intel Xeon E5-2680 CPU, Nvidia Tesla P40 GPU (8 units per node), and Mellanox ConnectX-3 Pro network card (40Gb/s connectivity).
In Figure 6, we report the throughput for training a ResNet-50 model on the ILSVRC-12 dataset (Russakovsky et al., 2015). For training with 512 GPUs, ECQ-SGD achieves 143.5% speed-up over the vanilla SGD (66.42k vs. 27.28k images per second). In our experiments, the connection bandwidth is relatively large and thus for clusters with a smaller bandwidth, it is expected that our method can achieve even higher speed-up.

Parameter Study
In Lemma 4, we present a guideline for choosing hyperparameters α and β in ECQ-SGD. A simple practice is to set β = 1 and α to some small positive number satisfying α 2 γ + (β − α) 2 < 1. Now we verify whether this is indeed optimal for training models to higher accuracy.
For quantitative evaluation, we train ResNet-20 models on the CIFAR-10 dataset with various hyper-parameters combinations, and the results are as reported in Table 2. When fixing α to 0.01, we discover that the lowest error rate is achieved when β is set to 1. On the other hand, when β = 1 is fixed, similar error rate is achieved by setting α to any value between 0.01 and 0.1. If α is too small, then the error feedback effect is greatly weaken, leading to similar performance with QSGD. If α is too large, then the constraint λ = α 2 γ +(β −α) 2 < 1 might be violated, and the training process becomes less stable (e.g. when α = 0.15, the optimization does not converge at all). The above observations are consistent with our previous analysis in Lemma 4.

Conclusion
In this paper, we present the error compensated quantized SGD algorithm to improve the learning efficiency for largescale distributed optimization. By introducing the error feedback scheme, the ECQ-SGD algorithm can effectively suppress the quantization error's contribution to the error bound. We analyse its convergence behaviour from the theoretical perspective, add demonstrate its advantage over the state-of-the-art QSGD algorithm. Experiments on convex linear models and non-convex convolutional neural networks demonstrate the efficacy of the proposed algorithm.