Title: ANALYSIS OF QUANTIZED MODELS

Abstract: Deep neural networks are usually huge, which significantly limits the deployment on low-end devices. In recent years, many weight-quantized models have been proposed. They have small storage and fast inference, but training can still be time-consuming. This can be improved with distributed learning. To reduce the high communication cost due to worker-server synchronization, recently gradient quantization has also been proposed to train deep networks with full-precision weights. In this paper, we theoretically study how the combination of both weight and gradient quantization affects convergence. We show that (i) weight-quantized models converge to an error related to the weight quantization resolution and weight dimension; (ii) quantizing gradients slows convergence by a factor related to the gradient quantization resolution and dimension; and (iii) clipping the gradient before quantization renders this factor dimension-free, thus allowing the use of fewer bits for gradient quantization. Empirical experiments confirm the theoretical convergence results, and demonstrate that quantized networks can speed up training and have comparable performance as full-precision networks.

1. INTRODUCTION:

Deep neural networks are usually huge. The high demand in time and space can significantly limit deployment on low-end devices. To alleviate this problem, many approaches have been recently proposed to compress deep networks. One direction is network quantization, which represents each network weight with a small number of bits. Besides significantly reducing the model size, it also accelerates network training and inference. Many weight quantization methods aim at approximating the full-precision weights in each iteration (Courbariaux et al., 2015; Lin et al., 2016; Rastegari et al., 2016; Li & Liu, 2016; Lin et al., 2017; Guo et al., 2017) . Recently, loss-aware quantization minimizes the loss directly w.r.t. the quantized weights (Hou et al., 2017; Hou & Kwok, 2018; Leng et al., 2018) , and often achieves better performance than approximation-based methods.

Distributed learning can further speed up training of weight-quantized networks (Dean et al., 2012) .

A key challenge is on reducing the expensive communication cost incurred during synchronization of the gradients and model parameters (Li et al., 2014a; b) . Recently, algorithms that sparsify (Aji & Heafield, 2017; Wangni et al., 2017) or quantize the gradients (Seide et al., 2014; Wen et al., 2017; Alistarh et al., 2017; Bernstein et al., 2018) have been proposed.

In this paper, we consider quantization of both the weights and gradients in a distributed environment. Quantizing both weights and gradients has been explored in the DoReFa-Net (Zhou et al., 2016) , QNN (Hubara et al., 2017) , WAGE (Wu et al., 2018) and ZipML (Zhang et al., 2017) . We differ from them in two aspects. First, existing methods mainly consider learning on a single machine, and gradient quantization is used to reduce the computations in backpropagation. On the other hand, we consider a distributed environment, and use gradient quantization to reduce communication cost and accelerate distributed learning of weight-quantized networks. Second, while DoReFa-Net, QNN and WAGE show impressive empirical results on the quantized network, theoretical guarantees are not provided. ZipML provides convergence analysis, but is limited to stochastic weight quantization, square loss with the linear model, and requires the stochastic gradients to be unbiased. This can be restrictive as most state-of-the-art weight quantization methods (Rastegari et al., 2016; Lin et al., 2016; Li & Liu, 2016; Guo et al., 2017; Hou et al., 2017; Hou & Kwok, 2018) are deterministic, and the resultant stochastic gradients are biased.

In this paper, we relax the restrictions on the loss function, and study in an online learning setting how the gradient precision affects convergence of weight-quantized networks in a distributed environment. The main findings are:

1. With either full-precision or quantized gradients, the average regret of loss-aware weight quantization does not converge to zero, but to an error related to the weight quantization resolution ∆ w and dimension d. The smaller the ∆ w or d, the smaller is the error (Theorems 1 and 2). 2. With either full-precision or quantized gradients, the average regret converges with a O(1/ √ T ) rate to the error, where T is the number of iterations. However, gradient quantization slows convergence (relative to using full-precision gradients) by a factor related to gradient quantization resolution ∆ g and d. The larger the ∆ g or d, the slower is the convergence (Theorems 1 and 2). This can be problematic when (i) the weight quantized model has a large d (e.g., deep networks); and (ii) the communication cost is a bottleneck in the distributed setting, which favors a small number of bits for the gradients, and thus a large ∆ g . 3. For gradients following the normal distribution, gradient clipping renders the speed degradation mentioned above dimension-free. However, an additional error is incurred. The convergence speedup and error are related to how aggressive clipping is performed. More aggressive clipping results in faster convergence, but a larger error (Theorem 3). 4. Empirical results show that quantizing gradients significantly reduce communication cost, and gradient clipping makes speed degradation caused by gradient quantization negligible. With quantized clipped gradients, distributed training of weight-quantized networks is much faster, while comparable accuracy with the use of full-precision gradients is maintained (Section 4).

Notations. For a vector x, √ x is the element-wise square root, x 2 is the element-wise square, Diag(x) returns a diagonal matrix with x on the diagonal, and x y is the element-wise multiplication of vectors x and y. For a matrix Q, x 2 Q = x Qx. For a matrix X, √ X is the element-wise square root, and diag(X) returns a vector extracted from the diagonal elements of X.

2. PRELIMINARIES:



2.1. ONLINE LEARNING:

Online learning continually adapts the model with a sequence of observations. It has been commonly used in the analysis of deep learning optimizers (Duchi et al., 2011; Kingma & Ba, 2015; Reddi et al., 2018) . At time t, the algorithm picks a model with parameter w t ∈ S, where S is a convex compact set. The algorithm then incurs a loss f t (w t ). After T rounds, the performance is usually evaluated by the regret R(T ) = T t=1 f t (w t ) -f t (w * ) and average regret R(T )/T , where w * = arg min w∈S T t=1 f t (w) is the best model parameter in hindsight.

2.2. WEIGHT QUANTIZATION:

In BinaryConnect (Courbariaux et al., 2015) , each weight is binarized using the sign function either deterministically or stochastically. In ternary-connect (Lin et al., 2016) , each weight is stochastically quantized to {-1, 0, 1}. Stochastic weight quantization often suffers severe accuracy degradation, while deterministic weight quantization (as in the binary-weight-network (BWN) (Rastegari et al., 2016) and ternary weight network (TWN) (Li & Liu, 2016) ) achieves much better performance.

In this paper, we will focus on loss-aware weight quantization, which further improves performance by considering the effect of weight quantization on the loss. Examples include loss-aware binarization (LAB) (Hou et al., 2017) and loss-aware quantization (LAQ) (Hou & Kwok, 2018) . Let the full-precision weights from all L layers in the deep network be w. The corresponding quantized weight is denoted Q w (w) = ŵ, where Q w (•) is the weight quantization function. At the (t + 1)th iteration, the second-order Taylor expansion of f t ( ŵ), i.e., f t ( ŵt ) + ∇f t ( ŵt ) ( ŵŵt ) + 1 2 ( ŵŵt ) H t ( ŵŵt ) is minimized w.r.t. ŵ, where H t is the Hessian at ŵt . A direct computation of H t is expensive. In practice, this is approximated by Diag( √ vt ), where vt is the moving average:

EQUATION

with g t the stochastic gradient, β 1, and is readily available in popular deep network optimizers such as RMSProp and Adam. Diag( √ vt ) is also an estimate of Diag( diag(H 2 t )) (Dauphin et al., 2015) . Computationally, the quantized weight is obtained by first performing a preconditioned gradient descent w t+1 = w t -η t Diag( √ vt ) -1 ĝt , followed by quantization via solving the following problem:

ŵt+1 = Q w (w t+1 ) = arg min ŵ w t+1 -ŵ 2 Diag( √ vt) s.t. ŵ = αb, α > 0, b ∈ (S w ) d . (2)

For simplicity of notations, we assume that the same scaling parameter α is used for all layers. Extension to layer-wise scaling is straightforward. For binarization, S w = {-1, +1}, the weight quantization resolution is ∆ w = 1, and a simple closed-form solution is obtained in (Hou et al., 2017) .

For m-bit linear quantization,

S w = {-M k , . . . , -M 1 , M 0 , M 1 , . . . , M k }, where k = 2 m-1 -1, 0 = M 0 < • • • < M k are uniformly spaced, with weight quantization resolution ∆ w = M r+1 -M r .

An efficient approximate solution of ( 2) is obtained in (Hou & Kwok, 2018) .

2.3. GRADIENT QUANTIZATION:

In a distributed learning environment with data parallelism, the main bottleneck is often on the communication cost due to gradient synchronization. By quantizing the gradients before synchronization (Seide et al., 2014; Wen et al., 2017; Alistarh et al., 2017) , this cost can be significantly reduced. For example, assuming that the full-precision gradient is 32-bit, the communication cost can be reduced 32/m times when gradients are quantized to m bits.

Most recent gradient quantization methods (Wen et al., 2017; Alistarh et al., 2017; Zhang et al., 2017) require the quantized gradient to be unbiased, and thus use stochastically quantized gradients. On the other hand, deterministic gradient quantization makes the quantized gradient biased, and the resultant analysis more complex. In this paper, we consider the more general m-bit stochastic linear quantization (Alistarh et al., 2017) :

EQUATION

where s t = g t ∞ , q t ∈ (S g ) d , and

S g = {-B k , . . . , -B 1 , B 0 , B 1 , . . . , B k }, with k = 2 m-1 -1, 0 = B 0 < B 1 < • • • < B k are uniformly spaced.

The gradient quantization resolution is defined as ∆ g = B r+1 -B r . The ith element q t,i in q t is equal to B r+1 with probability (|g t,i |/s t -B r ) /(B r+1 -B r ), and B r otherwise. Here, r is an index satisfying B r ≤ |g t,i |/s t < B r+1 . Note that Q g (g t ) is an unbiased estimator of g t .

3. PROPERTIES OF A QUANTIZED MODEL:

In this section, we consider quantization of both weights and gradients in a distributed environment with N workers using data parallelism. For easy illustration, we use the parameter server model (Li et al., 2014b) in Figure 1 , though it also holds for other configurations such as the AllReduce model (Rabenseifner, 2004) . At the tth iteration, worker n ∈ {1, 2, . . . , N } computes the full-precision gradient ĝ(n) t w.r.t. the quantized weight and quantizes ĝ(n)

t to g(n) t = Q g (ĝ (n) t )

. The quantized gradients are then synchronized and averaged at the parameter server as: gt =

1 N N n=1 g(n)

t . The server updates the second moment ṽt based on gt , and also the full-precision weight as w t+1 = w t -η t Diag( √ ṽt ) -1 gt . The weight is quantized using loss-aware weight quantization to produce ŵt+1 = Q w (w t+1 ), which is then sent back to all the workers.

3.1. ASSUMPTIONS:

Analysis on quantized deep networks has only been performed on models with (i) full-precision gradients and weights quantized by stochastic weight quantization (Li et al., 2017; De Sa et al., 2018) , or simple deterministic weight quantization using the sign (Li et al., 2017) ; (ii) full-precision weights and quantized gradients (Alistarh et al., 2017; Wen et al., 2017; Bernstein et al., 2018) ;

Parameter server 1. Gradient descent: 𝑤 𝑡+1 = 𝑤 𝑡 -𝜂 𝑡 𝐷𝑖𝑎𝑔( 𝑣 𝑡 ) -1 𝑔 𝑡 2. Weight quantization: ෝ 𝑤 𝑡+1 = 𝑄 𝑤 𝑤 𝑡+1 Worker 1 Gradient quantization: 𝑔 t (1) = Q g ( ො 𝑔 t (1) ) 𝑔 t (2) 𝑔 t (1) 𝑔 t (N)

Worker 2

Gradient quantization:

𝑔 t (2) = Q g ( ො 𝑔 t (2) )

Worker N

Gradient quantization: (iii) quantized weights and quantized gradients (Zhang et al., 2017) , but limited to stochastic weight quantization, square loss on linear model (i.e., f t (w t ) = (x t w t -y t ) 2 ) in Section 2.1), and unbiased gradient.

𝑔 t (N) = Q g ( ො 𝑔 t (N) ) ෝ 𝑤 𝑡+1 ෝ 𝑤 𝑡+1 ෝ 𝑤 𝑡+1

In this paper, we study the more advanced loss-aware weight quantization, with both full-precision and quantized gradients. As it is deterministic and has biased gradients, the above analysis do not apply here. Moreover, we do not assume a linear model, and relax the assumptions on f t as:

(A1) f t is convex; (A2) f t is twice differentiable with Lipschitz-continuous gradient; and (A3) f t has bounded gradient, i.e., ∇f t (w) ≤ G and ∇f t (w) ∞ ≤ G ∞ for all w ∈ S.

These assumptions have been commonly used in convex online learning (Hazan, 2016; Duchi et al., 2011; Kingma & Ba, 2015) and quantized networks (Alistarh et al., 2017; Li et al., 2017) . Obviously, the convexity assumption A1 does not hold for deep networks. However, this facilitates analysis of deep learning models, and has been used in (Kingma & Ba, 2015; Reddi et al., 2018; Li et al., 2017; De Sa et al., 2018) . Moreover, as will be seen, it helps to explain the empirical behavior in Section 4.

As in (Duchi et al., 2011; Kingma & Ba, 2015; Li et al., 2017) , we assume that w m -w n ≤ D and w m -w n ∞ ≤ D ∞ for all w m , w n ∈ S. Moreover, the learning rate η t decays as η/ √ t, where η is a constant (Hazan, 2016; Duchi et al., 2011; Kingma & Ba, 2015; Li et al., 2017) .

For simplicity of notations, we denote the full-precision gradient ∇f t (w t ) w.r.t. the full-precision weight by g t , and the full-precision gradient ∇f t (Q w (w t )) w.r.t. the quantized weight by ĝt . As f t is twice differentiable (Assumption A2), using the mean value theorem, there exists p ∈ (0, 1)

such that g t -ĝt = ∇f t (w t ) -∇f t ( ŵt ) = ∇ 2 f t ( ŵt + p(w t -ŵt )) (w t -ŵt ). Let H t = ∇ 2 f t ( ŵt + p(w t -ŵt ))

be the Hessian at ŵt + p(w t -ŵt ). Moreover, let α = max{α 1 , . . . , α T }, where α t is the scaling parameter in (2) at the tth iteration.

3.2. WEIGHT QUANTIZATION WITH FULL-PRECISION GRADIENT:

When only weights are quantized, the update for loss-aware weight quantization is

w t+1 = w t -η t Diag( vt ) -1 ĝt ,

where vt is the moving average of the (squared) gradients ĝ2 t in (1). Theorem 1. For loss-aware weight quantization with full-precision gradients and

EQUATION

EQUATION

For standard online gradient descent with the same learning rate scheme, R(T )/T converges to zero at the rate of O(1/ √ T ) (Hazan, 2016) . From Theorem 1, the average regret converges at the same rate, but only to a nonzero error LD D 2 + dα 2 ∆ 2 w 4 related to the weight quantization resolution ∆ w and dimension d.

3.3. WEIGHT QUANTIZATION WITH QUANTIZED GRADIENT:

When both weights and gradients are quantized, the update for loss-aware weight quantization is

w t+1 = w t -η t Diag( ṽt ) -1 gt ,

where gt is the stochastically quantized gradient Q g (∇f t (Q w (w t ))). The second moment ṽt is the moving average of the (squared) quantized gradients g2

t . The following Proposition shows that gradient quantization significantly blows up the norm of the quantized gradient relative to its fullprecision counterparts. Moreover, the difference increases with the gradient quantization resolution ∆ g and dimension d.

Proposition 1. E( gt 2 ) ≤ ( 1+ √ 2d-1 2 ∆ g + 1) ĝt 2 .

Theorem 2. For loss-aware weight quantization with quantized gradients and

EQUATION

EQUATION

The regrets in ( 4) and ( 6) are of the same form and differ only in the gradient used. Similarly, for the average regrets in ( 5) and ( 7), quantizing gradients slows convergence by a factor

of 1+ √ 2d-1 2 ∆ g + 1,

which is a direct consequence of the blowup in Proposition 1. These observations can be problematic as (i) deep networks typically have a large d; and (ii) distributed learning prefers using a small number of bits for the gradients, and thus a large ∆ g .

3.4. WEIGHT QUANTIZATION WITH QUANTIZED CLIPPED GRADIENTS:

To reduce convergence speed degradation caused by gradient quantization, gradient clipping has been proposed as an empirical solution (Wen et al., 2017) . The gradient ĝt is clipped to Clip(ĝ t ), where

Clip(ĝ t,i ) = ĝt,i |ĝ t,i | ≤ cσ, sign(ĝ t,i ) • cσ otherwise.

Here, c is a constant clipping factor, and σ is the standard deviation of elements in ĝt . The update then becomes

w t+1 = w t -η t Diag( √ vt ) -1 ǧt , where ǧt ≡ Q g (Clip(ĝ t )) ≡ Q g (Clip(∇f t (Q w (w t )))

) is the quantized clipped gradient. The second moment vt is computed using the (squared) quantized clipped gradient ǧ2 t . As shown in Figure 2 (a) of (Wen et al., 2017) , the distribution of gradients before quantization is close to the normal distribution. Recall from Section 3.3 that the difference between E( gt 2 ) of the quantized gradient gt and the full-precision gradient ĝt 2 is related to the dimension d. The following Proposition shows that E( ǧt 2 )/E( ĝt 2 ) becomes independent of d if ĝt follows the normal distribution and clipping is used.

Proposition 2. Assume that ĝt follows N (0, σ 2 I), we have E( ǧt 2 ) ≤ ((2/π) 1 2 c∆ g +1)E( ĝt 2 ).

However, the quantized clipped gradient may now be biased (i.e., E(ǧ t ) = Clip(ĝ t ) = ĝt ). The following Proposition shows that the bias is related to the clipping factor c. A larger c (i.e., less severe gradient clipping) leads to smaller bias.

Proposition 3. Assume that ĝt follows N (0, σ 2 I), we have

E( Clip(ĝ t ) -ĝt 2 ) ≤ dσ 2 (2/π) 1 2 F (c), where F (c) = -ce -c 2 2 + π 2 (1 + c 2 )(1 -erf( c √ 2

)), and erf(z) = 2 √ π z 0 e -t 2 dt is the error function.

Theorem 3. Assume that ĝt follows N (0, σ 2 I). For loss-aware weight quantization with quantized clipped gradients and

EQUATION

) E R(T ) T ≤ O (2/π) 1 2 c∆g + 1 d √ T + LD D 2 + dα 2 ∆ 2 w 4 + √ dDσ(2/π) 1 4 F (c). (9)

Note that terms involving gt in Theorem 2 are replaced by ǧt . Moreover, the regret has an additional term D

T t=1 E( Clip(ĝ t ) -ĝt 2 ) over that in Theorem 2. Comparing the average regrets in Theorems 1 and 3, gradient clipping before quantization slows convergence by a factor of (2/π) 1 2 c∆ g + 1, as compared to using full-precision gradients. This is independent of d as the increase in E( ǧt 2 ) is independent of d (Proposition 2). Hence, a ∆ g larger than the one in Theorem 2 can be used, and this reduces the communication cost in distributed learning. F (c) in ( 9) is thus smaller, but convergence is also slower. Hence, there is a trade-off between the two. Remark 1. There are two scaling schemes in distributed training with data parallelism: strong scaling and weak scaling (Snavely et al., 2002) . In this work, we consider weak scaling, which is more popular in deep network training. In weak scaling, the same data set size is used for each worker. The gradients are averaged over the N workers as

1 g t = 1 N N n=1 g (n)

t . If the gradients before averaging are independent random variables with zero mean, and g

(n) t 2 is bounded by G 2 , then E( g t 2 ) = E( 1 N N n=1 g (n) t 2 ) = 1 N 2 E( N n=1 g (n) t 2 ) ≤ G 2 /N . From Theorems 1-3,

the convergence speed with one worker is determined by

D 2 ∞ √ dT 2η T t=1 (1 -β)β T -t E( g t 2 ) + ηG∞ √ d √ 1-β T t=1 E( g t 2 ) ≤ D 2 ∞ √ d 2η √ T G 2 + ηG∞ √ d √ 1-β √ T G 2 ≤ ( D 2 ∞ √ d 2η + ηG∞ √ d √ 1-β ) √ T G 2 , while

with N workers by (

D 2 ∞ √ d 2η + ηG∞ √ d √ 1-β ) T G 2 /N = ( D 2 ∞ √ d 2η + ηG∞ √ d √ 1-β ) (T /N )G 2 .

Thus, with N workers, the number of iterations for convergence is subsequently reduced by a factor of 1/N as compared to using a single worker.

4. EXPERIMENTS:



4.1. SYNTHETIC DATA:

In this section, we first study the effect of dimension d on the convergence speed and final error of a simple linear model with square loss as in (Zhang et al., 2017) . Each entry of the model parameter is generated by uniform sampling from [-0.5, 0.5]. Samples x i 's are generated such that each entry of x i is drawn uniformly from [-0.5, 0.5], and the corresponding output y i from N (x i w * , (0.2)2 ). At the tth iteration, a mini-batch of B = 64 samples are drawn to form X t = [x 1 , . . . , x B ] and y t = [y 1 , . . . , y B ] . The corresponding loss is f t (w t ) = X t w t -y t 2 /2B. The weights are quantized to 1 bit using LAB. The gradients are either full-precision (denoted FP) or stochastically quantized to 2 bits (denoted SQ2). The optimizer is RMSProp, and the learning rate is η t = η/ √ t, where η = 0.03. Training is terminated when the average training loss does not decrease for 5000 iterations. 

4.2. CIFAR-10:

In this experiment, we follow (Wen et al., 2017) and use the same train/test split, data preprocessing, augmentation and distributed Tensorflow setup.

4.2.1. VARYING d:

We first study the effect of d on deep networks. Experiments are performed on two neural network models. The first one is a multi-layer perceptron with one layer of d hidden units (Reddi et al., 2016) .

The weights are quantized to 3 bits using LAQ3. The gradients are either full-precision (denoted FP) or stochastically quantized to 3 bits (denoted SQ3). The optimizer is RMSProp, and the learning rate is η t = η/ √ t, where η = 0.1. The second network is the Cifarnet (Wen et al., 2017) . We set d to be the number of filters in each convolutional layer. The gradients are either full-precision or stochastically quantized to 2 bits (denoted SQ2). Adam is used as the optimizer. The learning rate is decayed from 0.0002 by a factor of 0.1 every 200 epochs as in (Wen et al., 2017) .

Figures 3(b ) and 3(c) show convergence of the average training loss for both networks. As can be seen, similar to that in Section 4.1, a larger d leads to larger convergence degradation of the quantized gradients as compared to using full-precision gradients. However, unlike the linear model, a larger d does not necessarily lead to a larger loss upon convergence.

4.2.2. WEIGHT QUANTIZATION RESOLUTION ∆ w:

We use the same Cifarnet model as in (Wen et al., 2017) , with d = 64. Weights are quantized to 1 bit (LAB), 2 bits (LAQ2), or m bits (LAQm). The gradients are full-precision (FP) or stochastically quantized to m = {2, 3, 4} bits (SQm) without gradient clipping. Adam is used as the optimizer. The learning rate is decayed from 0.0002 by a factor of 0.1 every 200 epochs. Two workers are used in this experiment. Figure 4 shows convergence of the average training loss with different numbers of bits for the quantized weight. With full-precision or quantized gradients, weight-quantized networks have larger training losses than full-precision networks upon convergence. The more bits are used, the smaller is the final loss. This agrees with the results in Theorems 1 and 2. Table 1 shows the test set accuracies. Weight-quantized networks are less accurate than their full-precision counterparts, but the degradation is small when 3 or 4 bits are used. We use the same Cifarnet model as in (Wen et al., 2017) . Adam is used as the optimizer. The learning rate is decayed from 0.0002 by a factor of 0.1 every 200 epochs. Figure 5 shows convergence of the average training loss with different numbers of bits for the quantized gradients, again without gradient clipping. Using fewer bits yields a larger final error, and using 2-or 3-bit gradients yields larger training loss and worse accuracy than full-precision gradients (Figure 5 and Table 1 ). The fewer bits for the gradients, the larger the gap. The degradation is negligible when 4 bits are used. Indeed, 4-bit gradient sometimes has even better accuracy than full-precision gradient, as its inherent randomness encourages escape from poor sharp minima (Wen et al., 2017) . Moreover, using a larger m results in faster convergence, which agrees with Theorem 2. 

4.2.4. GRADIENT CLIPPING:

In this section, we perform experiments on gradient clipping, with clipping factor c in {1, 2, 3}, using the Cifarnet (Wen et al., 2017) . LAQ2 is used for weight quantization and SQ2 for gradient quantization. Adam is used as the optimizer. The learning rate is decayed from 0.0002 by a factor of 0.1 every 200 epochs. Figure 6 (a) shows histograms of the full-precision gradients before clipping.

As can be seen, the gradients at each layer before clipping roughly follow the normal distribution, which verifies the assumption in Section 3.4. Figure 6 (b) shows the average gt 2 / ĝt 2 (for nonclipped gradients) and ǧt 2 / ĝt 2 (for clipped gradients) over all iterations. The dimensionalities (d) of the various Cifarnet layers are "conv1": 1600, "conv2": 1600, "fc3": 884736, "fc4": 73728, Figure 7 shows convergence of the average training loss with different numbers of bits for the quantized clipped gradient, with c = 3. By comparing3 with Figure 5 , gradient clipping achieves faster convergence, especially when the number of gradient bits is small. For example, 2-bit clipped gradient has comparable speed (Figure 7 ) and accuracy (Table 1 ) as full-precision gradient. 

4.2.5. VARYING THE NUMBER OF WORKERS:

In Remark 1, we showed that using multiple workers can reduce the number of training iterations required. In this section, we vary the number of workers in a distributed learning setting with weak scaling, using the Cifarnet (Wen et al., 2017) . We fix the mini-batch size for each worker to 64, and set a smaller number of iterations when more workers are used.

We use 3-bit quantized weight (LAQ3), and gradients are full-precision or stochastically quantized to m = {2, 3, 4} bits (SQm). Table 2 shows the testing accuracies with varying number of workers N .

Observations are similar to those in Section 4.2.4. 2-bit quantized clipped gradient has comparable performance as full-precision gradient, while the non-clipped counterpart requires 3 to 4 bits for comparable performance. In this section, we train the AlexNet on ImageNet. We follow (Wen et al., 2017) and use the same data preprocessing, augmentation, learning rate, and mini-batch size. Quantization is not performed in the first and last layers, as is common in the literature (Zhou et al., 2016; Zhu et al., 2017; Polino et al., 2018; Wen et al., 2017) . We use Adam as the optimizer. We experiment with 4-bit loss-aware weight quantization (LAQ4), and the gradients are either full-precision or quantized to 3 bits (SQ3).

Table 3 shows the accuracies with different numbers of workers. Weight-quantized networks have slightly worse accuracies than full-precision networks. Quantized clipped gradient outperforms the non-clipped counterpart, and achieves comparable accuracy as full-precision gradient. Figure 8 shows the speedup in distributed training of a weight-quantized network with quantized/full-precision gradient compared to training with one worker using full-precision gradient. We use the performance model in (Wen et al., 2017) , which combines lightweight profiling on a single node with analytical communication modeling. We use the AllReduce communication model (Rabenseifner, 2004) , in which each GPU communicates with its neighbor until all gradients are accumulated to a single GPU. We do not include the server's computation effort on weight quantization and the worker's effort on gradient clipping, which are negligible compared to the forward and backward propagations in the worker. As can be seen from the 

5. CONCLUSION:

In this paper, we studied loss-aware weight-quantized networks with quantized gradient for efficient communication in a distributed environment. Convergence analysis is provided for weight-quantized models with full-precision, quantized and quantized clipped gradients. Empirical experiments confirm the theoretical results, and demonstrate that quantized networks can speed up training and have comparable performance as full-precision networks.

A PROOFS:

A.1 PROOF OF THEOREM 1

First, we introduce the following two lemmas.

Lemma 1. Let v t = t j=1 (1 -β)β t-j g 2 j , where β ∈ [0, 1). Assume that g j ∞ < G ∞ for j ∈ {1, 2 . . . , t}. Then,

EQUATION

EQUATION

√ v t = t j=1

(1 -β)β t-j g j 2 .

(12)

EQUATION

√ v t = d i=1 v t,i = d i=1 t j=1 (1 -β)β t-j g 2 j,i = t j=1

(1 -β)β t-j g j 2 .

Lemma 2. [Lemma 10.3 in (Kingma & Ba, 2015) ] Let g 1:T,i = [g 1,i , g 2,i , . . . , g T,i ] be the vector containing the ith element of the gradients for all iterations up to T , and g t be bounded as in Assumption A3. Then,

T t=1 g 2 t,i t ≤ 2G ∞ g 1:T,i .

Proof. (of Theorem 1) When only weights are quantized, the update for loss-aware weight quantization is

EQUATION

)

The update for the ith entry of w t is w t+1,i = w t,i -η t ĝt,i √ vt,i

. This implies

(w t+1,i -w * i ) 2 = (w t,i -w * i ) 2 -2η t (w t,i -w * i ) g t,i vt,i +2η t (w t,i -w * i ) (g t,i -ĝt,i ) vt,i + η 2 t ( ĝt,i vt,i ) 2 .

After rearranging,

EQUATION

)

Since f t is convex, we have

EQUATION

As f t is convex (Assumption A1) and twice differentiable (Assumption A2), ∇ 2 f t LI, where I is the identity matrix. Combining with the assumption in Section 3.1 that w m -w n ≤ D, we have

EQUATION

)

Let x, y = x y be the dot product between two vectors x and y. Combining ( 14) and ( 15), sum over all the dimensions i ∈ {1, 2 . . . , d} and over all iterations t ∈ {1, 2, . . . , T }, we have

EQUATION

)

The first inequality comes from (10) in Lemma 1. In the second inequality, the first term comes from

d i=1 √ v1,i 2η1 (w 1,i -w * i ) 2 + d i=1 T t=2 √ vt,i 2ηt - √ vt-1,i 2ηt-1 (w t,i -w * i ) 2 = d i=1 √ vT,i 2η T (w T,i - w * i ) 2

and the domain bound assumption in Section 3.1 (i.e., (w T,i -

w * i ) ≤ w T -w * ∞ ≤ D ∞ ).

The second term comes from the definition of H t (i.e., H

-1 2 t (g t -ĝt ) = H 1 2

t (w t -ŵt )), and Lemma 2. The third inequality comes from Cauchy's inequality. The fourth inequality comes from (16). The last inequality comes from (12) in Lemma 1.

For m-bit (m > 1) loss-aware weight quantization in (13), as

ŵt = arg min w ŵ -w t 2 Diag( √ vt-1) = d i=1 vt-1,i ( ŵi -w t,i ) 2 s.t. ŵ = α t b t , α > 0, b ∈ (S w ) d . If -α t M k ≤ w t,i ≤ α t M k , as vt-1,i > 0, the optimal ŵt,i satisfies ŵt,i ∈ {α t M r,i , α t M r+1,i },

where r is the index that satisfies α t M r,i ≤ w t,i ≤ α t M r+1,i . Since α = max{α 1 , . . . , α T }, we have

EQUATION

Otherwise (i.e., w t,i is exterior of the representable range), the optimal ŵt,i is just the nearest representable value of w t,i . Thus,

EQUATION

From ( 18) and ( 19), and sum over all the dimensions, we have

EQUATION

From ( 16) and ( 20),

EQUATION

From ( 21) and Assumption A3, we have from ( 17)

R(T ) ≤ D 2 ∞ dG ∞ √ T 2η + ηdG 2 ∞ √ T √ 1 -β + LD D 2 + dα 2 ∆ 2 w 4 T.

Thus, the average regret is

EQUATION

A.2 PROOF OF PROPOSITION 1 Lemma 3. For stochastic gradient quantization in (3), E(g t ) = ĝt , and

E( gt -ĝt 2 ) ≤ ∆ g ĝt ∞ ĝt 1 .

Proof. Denote the ith element of the quantized gradient gt by gt,i . For two adjacent quantized values

B r,i , B r+1,i with B r,i ≤ |g t,i |/s t < B r+1,i , E(g t,i ) = E(s t • sign(ĝ t,i ) • q t,i ) = s t • sign(ĝ t,i ) • E(q t,i ) = s t • sign(ĝ t,i ) • (pB r+1,i + (1 -p)B r,i ) = s t • sign(ĝ t,i ) • (p(B r+1,i -B r,i ) + B r,i ) = s t • sign(ĝ t,i ) • |ĝ t,i | s t = ĝt,i .

Thus, E(g t ) = ĝt , and the variance of the quantized gradients satisfy

E( gt -ĝt 2 ) = d i=1 (s t B r+1,i -|ĝ t,i |)(|ĝ t,i | -s t B r,i ) = s 2 t d i=1 (B r+1,i - |ĝ t,i | s t )( |ĝ t,i | s t -B r,i ) ≤ s 2 t d i=1 (B r+1,i -B r,i ) |ĝ t,i | s t = ∆ g ĝt ∞ ĝt 1 . Proof. From Lemma 3, E( gt 2 ) = E( gt -ĝt 2 ) + ĝt 2 ≤ ∆ g ĝt ∞ ĝt 1 + ĝt 2 .

Denote {x 1 , x 2 , . . . , x d } as the absolute values of the elements in ĝt sorted in ascending order. From Cauchy's inequality, we have

ĝt ∞ ĝ 1 = x d d i=1 x i = d i=1 x d x i ≤ d-1 i=1 ( 1 + √ 2d -1 2 x 2 i + 1 1 + √ 2d -1 x 2 d ) + x 2 d = 1 + √ 2d -1 2 d i=1 x 2 i = 1 + √ 2d -1 2 ĝt 2 .

The equality holds iff

x 1 = x 2 = • • • = √ 2 1+ √ 2d-1 x d . Thus, we have E( gt 2 ) ≤ ( 1 + √ 2d -1 2 ∆ g + 1) ĝt 2 .

A.3 PROOF OF THEOREM 2

Proof. When both weights and gradients are quantized, the update is

EQUATION

)

Similar to the proof of Theorem 1, and using that E(g t ) = ĝt (Lemma 3), we have

E(R(T )) ≤ d i=1 E( ṽ1,i 2η 1 (w 1,i -w * i ) 2 ) + d i=1 T t=2 E ( ṽt,i 2η t - ṽt-1,i 2η t-1 )(w t,i -w * i ) 2 + T t=1 E( w t -w * , g t -gt ) + d i=1 T t=1 η t 2 E(   g2 t,i (1 -β)g 2 t,i )   ≤ D 2 ∞ 2η d i=1 E( T ṽT,i ) + T t=1 E H 1 2 t (w t -w * ), H -1 2 t (g t -ĝt ) + ηG ∞ √ 1 -β d i=1 E( g1:T,i ) ≤ D 2 ∞ 2η d i=1 E( T ṽT,i ) + T t=1 E( w t -w * 2 H t w t -ŵt 2 H t ) + ηG ∞ √ 1 -β d i=1 E( g1:T,i ) ≤ D 2 ∞ 2η √ dT E( √ ṽT ) + ηG ∞ √ 1 -β d i=1 E( g1:T,i ) + √ LD T t=1 E( w t -ŵt 2 H t ) ≤ D 2 ∞ 2η √ dT T t=1 (1 -β)β T -t E( gt 2 ) + ηG ∞ √ 1 -β √ d T t=1 E( gt 2 ) + √ LD T t=1 E( w t -ŵt 2 H t

).

As (21) in the proof of Theorem 1 still holds, using Proposition 1 and Assumption A3, we have

E(R(T )) ≤   D 2 ∞ 2η √ dT T t=1 (1 -β)β T -t ĝt 2 + ηG ∞ √ 1 -β √ d T t=1 ĝt 2   • 1 + √ 2d -1 2 ∆ g + 1 + LD D 2 + dα 2 ∆ 2 w 4 ≤ D 2 ∞ G ∞ 2η + ηG 2 ∞ √ 1 -β d √ T 1 + √ 2d -1 2 ∆ g + 1 + LD D 2 + dα 2 ∆ 2 w 4 . E(R(T )/T ) ≤ D 2 ∞ G ∞ 2η + ηG 2 ∞ √ 1 -β 1 + √ 2d -1 2 ∆ g + 1 d √ T + LD D 2 + dα 2 ∆ 2 w 4 .

A.4 PROOF OF PROPOSITION 2

Proof. From Lemma 3, E(Q g (Clip(ĝ t ))) = Clip(ĝ t ), and E( Q g (Clip(ĝ t )) 2 ) ≤ E(∆ g Clip(ĝ t ) ∞ Clip(ĝ t ) 1 + Clip(ĝ t ) 2 ).

As [ĝ t ] i ∼ N (0, σ 2 ), its pdf is f (x) = 1 √ 2πσ 2 e -x 2 2σ 2 . Thus, As E( Clip(ĝ t ) 2 ) ≤ E( ĝt 2 ), and that E( ĝt 2 ) = dσ 2 , we have

E( Clip(ĝ t ) 1 ) ≤ E( ĝt 1 ) = d i=1 E(|[ĝ t ] i |) = d

E( Q g (Clip(ĝ t )) 2 ) ≤ E(∆ g Clip(ĝ t ) ∞ Clip(ĝ t ) 1 + Clip(ĝ t ) 2 ) ≤ ∆ g cσ(2/π) 1 2 dσ + E( Clip(ĝ t ) 2 )

≤ ((2/π) 1 2 c∆ g + 1)E( ĝt 2 ).

A.5 PROOF OF PROPOSITION 3

Proof.

EQUATION

)))

= (2/π) 1 2 dσ 2 F (c).

A.6 PROOF OF THEOREM 3

Proof. When both weights and gradients are quantized, and gradient clipping is applied before gradient quantization, the update then becomes

EQUATION

)

Similar to the proof of Theorem 1, and using that E(Q g (Clip(ĝ t ))) = Clip(ĝ t ), we have F (c).

E(R(T )) ≤ d i=1

:

With a slight abuse of notation, gt here can be the full-precision gradient or quantized gradient with/without clipping.

Legend "W(LAB)-G(FP)" means that weights are quantized using LAB and gradients are full-precision.

The curves for full-precision gradient are the same in Figures5 and 7, and can be used as a common baseline.

Figures and Tables:

Figure 1: Distributed weight and gradient quantization with data parallelism.

Figure 2: F (c) vs clipping factor c.

Figure 3(a) shows 2 convergence of the average training loss T t=1 f t (w t )/T , which differs from the average regret only by only a constant. As can be seen, for both full-precision and quantized gradients, a larger d leads to a larger loss upon convergence. Moreover, convergence is slower for larger d, particularly when the gradients are quantized. These agree with the results in Theorems 1 and 2.

Figure 3: Convergence of the weight-quantized models with different d's.

Figure 4: Convergence with different numbers of bits for the weights on CIFAR-10. The gradient is full-precision (denoted G(FP)) or m-bit quantized (denoted G(SQm)) without gradient clipping.

Figure 5: Convergence with different numbers of bits for the gradients on CIFAR-10. The weight is binarized (denoted W(LAB)) or m-bit quantized (denoted W(LAQm)). Gradients are not clipped.

(a) Histograms of gradients before clipping. (b) gt 2 ĝt 2 or ǧt 2 ĝt 2 . (c) Training curve.

Figure 6: Results for LAQ2 with SQ2 on CIFAR-10 with two workers. (a) Histograms of gradients at different Cifarnet layers before clipping (visualized by Tensorboard); (b) Average gt 2 / ĝt 2

Figure 7: Convergence with different numbers of bits for gradients (with c = 3) on CIFAR-10.

Figure8shows the speedup in distributed training of a weight-quantized network with quantized/full-precision gradient compared to training with one worker using full-precision gradient. We use the performance model in(Wen et al., 2017), which combines lightweight profiling on a single node with analytical communication modeling. We use the AllReduce communication model(Rabenseifner, 2004), in which each GPU communicates with its neighbor until all gradients are accumulated to a single GPU. We do not include the server's computation effort on weight quantization and the worker's effort on gradient clipping, which are negligible compared to the forward and backward propagations in the worker. As can be seen from the Figure, even though the number of bits used for gradients increases by one at every aggregation step in the AllReduce model, the proposed method still significantly reduces network communication and speeds up training. When the bandwidth is small (Figure8(a)), communication is the bottleneck, and using quantizing gradients is significantly faster than the use of full-precision gradients. With a larger bandwidth (Figure8(b)), the difference in speedups is smaller. Moreover, note that on the 1Gbps Ethernet with quantized gradients, its speedup is similar to those on the 10Gbps Ethernet with full-precision gradients.

Figure 8: Speedup of ImageNet training on a 16-node GPU cluster. Each node has 4 1080ti GPUs with one PCI switch.

in the proof of Theorem 1 still holds. Similar to the proof of Theorem 2, using the domain bound assumption in Section 3.1 (i.e., w m -w n ≤ D and w m -w n ∞ ≤ D ∞ for any w m , w n ∈ S), and Proposition 3, we have

Testing accuracy (%) on CIFAR-10 with two workers.

Table content: <table><tr><td>gradient</td><td>weight</td><td>FP</td><td>LAB LAQ2 LAQ3 LAQ4</td></tr><tr><td>FP</td><td/><td colspan="2">83.74 80.37 82.11 83.14 83.35</td></tr><tr><td colspan="2">SQ2 (no clipping)</td><td colspan="2">81.40 78.67 80.27 81.27 81.38</td></tr><tr><td colspan="2">SQ2 (clip,c = 3)</td><td colspan="2">82.99 80.25 81.59 83.14 83.40</td></tr><tr><td colspan="2">SQ3 (no clipping)</td><td colspan="2">83.24 80.18 81.63 82.75 83.17</td></tr><tr><td colspan="2">SQ3 (clip, c = 3)</td><td colspan="2">83.89 80.13 81.77 82.97 83.43</td></tr><tr><td colspan="2">SQ4 (no clipping)</td><td colspan="2">83.64 80.44 81.88 83.13 83.47</td></tr><tr><td colspan="2">SQ4 (clip, c = 3)</td><td colspan="2">83.80 79.27 81.42 82.77 83.43</td></tr><tr><td colspan="4">4.2.3 GRADIENT QUANTIZATION RESOLUTION ∆ g</td></tr></table>

Testing accuracy (%) on CIFAR-10 with varying number of workers (N ).

Table content: <table><tr><td>weight</td><td>gradient</td><td colspan="3">N = 4 N = 8 N = 16</td></tr><tr><td>FP</td><td>FP</td><td>83.28</td><td>83.38</td><td>83.76</td></tr><tr><td/><td>FP</td><td>82.92</td><td>82.93</td><td>83.12</td></tr><tr><td/><td colspan="2">SQ2 (no clipping) 81.53</td><td>81.08</td><td>81.30</td></tr><tr><td/><td>SQ2 (clip, c = 3)</td><td>83.01</td><td>82.94</td><td>82.73</td></tr><tr><td colspan="3">LAQ3 SQ3 (no clipping) 82.64</td><td>82.42</td><td>82.27</td></tr><tr><td/><td>SQ3 (clip, c = 3)</td><td>82.93</td><td>83.16</td><td>82.54</td></tr><tr><td/><td colspan="2">SQ4 (no clipping) 83.03</td><td>82.53</td><td>82.61</td></tr><tr><td/><td>SQ4 (clip, c = 3)</td><td>82.51</td><td>83.07</td><td>82.52</td></tr></table>

Top-1 and top-5 accuracies (%) on ImageNet.

Table content: <table><tr><td>weight</td><td>gradient</td><td>N = 2 top-1 top-5 top-1 top-5 top-1 top-5 N = 4 N = 8</td></tr><tr><td>FP</td><td>FP</td><td>55.08 78.33 55.45 78.57 55.40 78.69</td></tr><tr><td/><td>FP</td><td>53.79 77.21 54.22 77.53 54.73 78.12</td></tr><tr><td colspan="3">LAQ4 SQ3 (no clipping) 52.48 75.97 52.87 76.40 53.18 76.62</td></tr><tr><td/><td colspan="2">SQ3 (clip, c = 3) 54.13 77.27 54.23 77.55 54.34 78.07</td></tr></table>

, ĝt -Clip(ĝ t )

Table content: <table><tr><td>≤</td><td colspan="10">d i=1 E w + T D 2 ∞ 2η E( T vT,i ) + t=1 d ηG ∞ √ i=1 1 -β E( ǧ1:T,i )</td></tr><tr><td>≤</td><td colspan="3">D 2 ∞ 2η</td><td colspan="4">i=1 d</td><td colspan="3">E( T vT,i ) +</td><td>t=1 T</td><td>E H</td><td>1 2</td><td>-1 2 t</td><td>(g t -ĝt )</td></tr><tr><td>≤</td><td colspan="10">+ D 2 t=1 T ∞ √ E w t -w  *  , ĝt -Clip(ĝ t ) + dT 2η E( √ vT ) + d ηG ∞ √ i=1 1 -β</td><td>d i=1 E( ǧ1:T,i ) ηG ∞ √ 1 -β</td><td>E( ǧ1:T,i )</td></tr><tr><td/><td>+</td><td>√</td><td colspan="4">LD</td><td/><td>T</td><td colspan="2">E( w t -ŵt 2 H t</td><td>) +</td><td>T</td><td>E( w t -w  *  2</td><td>(ĝ t -Clip(ĝ t )) 2 )</td></tr><tr><td/><td/><td/><td/><td/><td/><td/><td colspan="2">t=1</td><td/><td>t=1</td></tr><tr><td>≤</td><td colspan="5">D 2 ∞ 2η √</td><td colspan="3">dT</td><td colspan="2">T t=1</td><td>(1 -β)β T -t E( ǧt 2 ) +</td><td>ηG ∞ √ 1 -β √ d</td><td>T t=1</td><td>E( ǧt 2 )</td></tr><tr><td/><td>+</td><td>√</td><td colspan="4">LD</td><td/><td>T</td><td colspan="2">E( w t -ŵt 2 H t</td><td>) + D</td></tr><tr><td/><td/><td/><td/><td/><td/><td/><td colspan="2">t=1</td><td/></tr><tr><td/><td/><td/><td colspan="4">E(</td><td colspan="3">v1,i 2η 1</td><td>(w 1,i -w  *  i ) 2 ) +</td><td>d i=1</td><td>T t=2</td><td>E (</td><td>vt,i 2η t</td><td>-</td><td>vt-1,i 2η t-1</td><td>)(w t,i -w  *  i ) 2</td></tr><tr><td/><td>+</td><td colspan="3">T t=1</td><td colspan="6">E( w d i=1</td><td>T t=1</td><td>η t 2</td><td>E</td><td> </td><td>ǧ2 t,i (1 -β)ǧ 2 t,i</td><td> </td></tr></table>

Peer review (iclr2019):
 In a distributed learning system where a parameter server maintains a full resolution copy of the parameters, communication costs can be reduced by (a) discretizing the weights that the server broadcasts to the workers, and (b) discretizing the gradients that the workers return to the parameter server. Following existing literature, the authors propose to discretize the parameters in a manner that limits its impact on the loss function by means of a diagonal approximation of the Hessian. This also means that one can bound the difference between the gradient for the full precision parameter and the gradient for the discretized parameter. In contrast, they discretize the gradients stochastically so that the discretized version is an unbiased estimator of the full precision stochastic gradient. Since the stochastic gradient is itself an unbiased estimator of the gradient, this means we are dealing with an estimator whose variance has increased in a manner we can bound as well. The theoretical analysis consists in pushing these two bounds through classical analyses of the stochastic gradient algorithm, in this case, a regret-based version in the style of Zinkevich or Duchi. Although i did not check the minute details of the proof, the argument feels correct and familiar. They also give an interesting result in favor of clipping gradients, worth developing. Although the title promises an analysis that holds for deep networks, this analysis strictly applies only to convex models. The author argue that the predictions made by this analysis also apply to deep networks, and support this argument with extensive experiments (which certainly represent a fair amount of work). This result is believable but should not be construed as an analysis. Nevertheless, both results (the theoretical result for convex model and the empirical result for deep networks) are interesting and worth sharing. The main caveat comes from the style the parallel learning algorithm they are considering. In the data-parallel case (which they consider), parameter servers approaches have been displaced by setups where all workers update their copy of the weights using the allReduced gradients. One could also use discretized gradients to speedup the allReduce operation (this is less of a win because latencies dominate) but this would only result in an increased variance and a much simpler analysis. Finally I am not completely up-to-date with this line of work and cannot evaluate the novelty with confidence. This was not known to me, which is only a piece of evidence. -- bumping down my score because the misleading title was not addressed by the author response. -- bumping it up again because the authors have reacted.