A NALYSIS OF Q UANTIZED M ODELS
A BSTRACT
Deep neural networks are usually huge, which signiﬁcantly 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 conﬁrm the theoretical convergence results, and demonstrate that quantized networks can speed up training and have comparable performance as full-precision networks.
I NTRODUCTION
Deep neural networks are usually huge.
The high demand in time and space can signiﬁcantly 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 signiﬁcantly 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 &
Heaﬁeld, 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 ﬁndings are:
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).
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).
Empirical results show that quantizing gradients signiﬁcantly 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 (cid:12) y is the element-wise multiplication of vectors x and y .
For a matrix Q , (cid:107) x (cid:107) 2 Q = x (cid:62) 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 .
P RELIMINARIES 2. O NLINE L EARNING
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 ) =
(cid:80) T t =1 f t ( w t ) − f t ( w ∗ ) and average regret R ( T ) /T , where w ∗ = arg min w ∈S (cid:80) Tt =1 f t ( w ) is the best model parameter in hindsight.
2. W EIGHT Q UANTIZATION
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 ) =
ˆ w , where Q w ( · ) is the weight quantization function.
At the ( t + 1) th iteration, the second-order Taylor expansion of f t ( ˆ w ) , i.e., f t ( ˆ w t ) + ∇ f t ( ˆ w t ) (cid:62) ( ˆ w − ˆ w t ) + 12 ( ˆ w − ˆ w t ) (cid:62) H t ( ˆ w − ˆ w t ) is minimized w.r.t.
ˆ w , where H t is the Hessian at ˆ w t .
A direct computation of H t is expensive.
In practice, this is approximated by Diag ( √ ˆ v t ) , where ˆ v t is the moving average:
[Equation]
with g t the stochastic gradient, β (cid:39) 1 , and is readily available in popular deep network optimizers such as RMSProp and Adam.
Diag ( √ ˆ v t ) is also an estimate of Diag ( (cid:112) diag ( H 2 t ))
(Dauphin et al., 2015).
Computationally, the quantized weight is obtained by ﬁrst performing a preconditioned gradient descent w t
{++
 =+}
w t − η t Diag ( √ ˆ v t ) − 1 ˆ g t , followed by quantization via solving the following problem:
[Equation]
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 efﬁcient approximate solution of (2) is obtained in (Hou & Kwok, 2018).
2. G RADIENT Q UANTIZATION
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 signiﬁcantly 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., 
 ; 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 = (cid:107) g t (cid:107) ∞ , q t ∈ ( S g ) d , and S g = {− B k , . .
. , − B 1 , B 0 , B 1 , . .
B k } , with k = 2 m − 1 − 1 ,
= B 0 < B 1 < · · · < B k are uniformly spaced. The gradient quantization resolution is deﬁned as ∆ g = B r +1 − B r .
The i th 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 .
P ROPERTIES OF A Q UANTIZED M ODEL
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 conﬁgurations such as the AllReduce model (Rabenseifner, 2004).
At the t th iteration, worker n ∈ { 1 , 2 , . . .
, N } computes the full-precision gradient
ˆ g ( n ) t w.r.t.
the quantized weight and quantizes ˆ g ( n ) t to ˜ g ( n ) t = Q g (ˆ g ( n ) t ) .
The quantized gradients are then synchronized and averaged at the parameter server as: ˜ g t = 1 N (cid:80)
Nn =1 ˜ g ( n ) t .
The server updates the second moment ˜ v t based on ˜ g t , and also the full-precision weight as w t +1 =
w t − η t Diag ( √ ˜ v t ) − 1 ˜ g t .
The weight is quantized using loss-aware weight quantization to produce ˆ w t
+1 =
Q w ( w t +1 ) , which is then sent back to all the workers.
3. A SSUMPTIONS
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);
[Figure]
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., (cid:107)∇ f t ( w ) (cid:107) ≤ G and (cid:107)∇ f t ( w ) (cid:107) ∞
≤ 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 (cid:107) w m − w n (cid:107) ≤ D and (cid:107) w m − w n (cid:107) ∞ ≤ 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 ˆ g t .
As f t is twice differentiable (Assumption A2 ), using the mean value theorem, there exists p ∈ (0 , 1) such that g t [Equation] p [Equation]
w t [Equation] ˆ [Equation]
t ))
( w t − ˆ w t ) .
Let H (cid:48) t = ∇ 2 f t ( ˆ w t + p ( w t − ˆ w t )) be the Hessian at ˆ w t + p ( w t − ˆ w t ) .
Moreover, let α = max { α 1 , . .
. , α T } , where α t is the scaling parameter in (2) at the t th iteration.
3. W EIGHT Q UANTIZATION WITH F ULL -P RECISION G RADIENT
When only weights are quantized, the update for loss-aware weight quantization is
[Equation]
where ˆ v t is the moving average of the (squared) gradients ˆ g 2 t in (1).
Theorem 1.
For loss-aware weight quantization with full-precision gradients and η t = η/ √ t ,
[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 (cid:113) D 2 + dα 2 ∆ 2 wrelated to the weight quantization resolution ∆ w and dimension d .
3. W EIGHT Q UANTIZATION W ITH Q UANTIZED G RADIENT
When both weights and gradients are quantized, the update for loss-aware weight quantization is
[Equation]
where ˜ g t is the stochastically quantized gradient Q g ( ∇ f t ( Q w ( w t ))) .
The second moment ˜ v t is the moving average of the (squared) quantized gradients ˜
g 2 t .
The following Proposition shows that gradient quantization signiﬁcantly 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.
[Equation]
Theorem 2.
For loss-aware weight quantization with quantized gradients and η t = η/ √ t ,
[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 (cid:113) 1+ √ 2 d − 1∆ 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. W EIGHT Q UANTIZATION WITH Q UANTIZED C LIPPED G RADIENTS
To reduce convergence speed degradation caused by gradient quantization, gradient clipping has been proposed as an empirical solution (Wen et al., 2017).
The gradient ˆ g t is clipped to Clip (ˆ g t ) , where
[Equation]
Here, c is a constant clipping factor, and σ is the standard deviation of elements in ˆ g t .
The update then becomes
[Equation]
where ˇ g t ≡ Q g ( Clip (ˆ g t ))
≡ Q g ( Clip ( ∇ f t ( Q w ( w t )))) is the quantized clipped gradient.
The second moment ˇ v t is computed using the (squared) quantized clipped gradient ˇ g 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 ( (cid:107) ˜
g t (cid:107) 2 ) of the quantized gradient ˜ g t and the full-precision gradient (cid:107) ˆ g t (cid:107) 2 is related to the dimension d .
The following Proposition shows that E ( (cid:107)
ˇ g t (cid:107) 2 ) /
E ( (cid:107) ˆ g t (cid:107) 2 ) becomes independent of d if ˆ g t follows the normal distribution and clipping is used.
Proposition 2.
Assume that ˆ g t follows N ( 0 , σ 2 I ) , we have E ( (cid:107)
ˇ g t (cid:107) 2 ) ≤ ((2 /π )
12 c ∆ g +1) E ( (cid:107) ˆ g t (cid:107) 2 ) .
However, the quantized clipped gradient may now be biased (i.e., E (ˇ g t ) =
Clip (ˆ g t ) (cid:54) =
ˆ g 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 ˆ g t follows N ( 0 , σ 2 I ) , we have E ( (cid:107) Clip (ˆ g t ) − ˆ g t (cid:107) 2 ) ≤ dσ 2 (2 /π )
12 F ( c ) , where F ( c )
= − ce − c 2 2 + (cid:112)
π 2 (1 + c 2 )(1 − erf ( c √ 2 )) , and erf ( z ) = 2 √ π (cid:82) z
e − t 2 dt is the error function.
Theorem 3.
Assume that ˆ g t follows N ( 0 , σ 2 I ) .
For loss-aware weight quantization with quantized clipped gradients and η t = η/ √ t ,
[Equation]
Note that terms involving ˜ g t in Theorem 2 are replaced by ˇ g t .
Moreover, the regret has an additional term D (cid:80)
Tt =1 E ( (cid:112) (cid:107) Clip
(ˆ g t ) − ˆ g t (cid:107) 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 (cid:113) (2 /π ) 12 c ∆ g + 1 , as compared to using full-precision gradients.
This is independent of d as the increase in E ( (cid:107) ˇ g t (cid:107) 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.
A larger c (i.e., less severe gradient clipping) makes F ( c ) smaller (Figure 2).
Compared with (6) in Theorem 2, the extra error √ dDσ (2 /π ) 14 (cid:112) 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 (cid:80)
Nn =1 g ( n ) t .
If the gradients before averaging are independent random variables with zero mean, and (cid:107) g ( n ) t (cid:107) 2 is bounded by G 2 , then E ( (cid:107) g t (cid:107) 2 )
=
E ( (cid:107) 1 N (cid:80) N n =1 g ( n ) t (cid:107) 2 ) =
1 N 2 E ( (cid:80) N n =1 (cid:107) g ( n ) t (cid:107) 2 ) ≤ G 2 /N .
From Theorems 1-3, the convergence speed with one worker is determined by D 2 ∞ √ dT 2 η
[Equation]
+
[Equation]
, while with N workers by ( D 2 ∞ √ d
[Equation]
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.
E XPERIMENTS 4. S YNTHETIC D ATA
In this section, we ﬁrst study the effect of dimension d on the convergence speed and ﬁnal 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 (cid:62) i w ∗ , (0 . 2) 2 ) .
At the t th 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 ] (cid:62) .
The corresponding loss is f t ( w t ) =
(cid:107) X
(cid:62) t w t − y t (cid:107) 2 / 2 B .
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 .
Training is terminated when the average training loss does not decrease foriterations.
Figure 3(a) shows 2 convergence of the average training loss (cid:80)
Tt =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 Theoremsand 2.
[Figure]
4. CIFAR-
In this experiment, we follow (Wen et al., 2017) and use the same train/test split, data preprocessing, augmentation and distributed Tensorﬂow setup.
4.2. V ARYING d
We ﬁrst study the effect of d on deep networks.
Experiments are performed on two neural network models.
The ﬁrst 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 .
The second network is the Cifarnet (Wen et al., 2017).
We set d to be the number of ﬁlters 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. W EIGHT Q UANTIZATION R ESOLUTION ∆ w
We use the same Cifarnet model as in (Wen et al., 2017), with d = 64 .
Weights are quantized tobit (LAB), 2 bits (LAQ2), or m bits (LAQ m ).
The gradients are full-precision (FP) or stochastically quantized to m = { 2 , 3 , 4 } bits (SQ m ) 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 ﬁnal 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.
[Figure]
[Table]
4.2. G RADIENT Q UANTIZATION R ESOLUTION ∆ g
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 ﬁnal 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.
[Figure]
4.2. G RADIENT C LIPPING
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 veriﬁes the assumption in Section 3.4.
Figure 6(b) shows the average (cid:107) ˜
g t (cid:107) 2 / (cid:107) ˆ g t (cid:107) 2 (for nonclipped gradients) and (cid:107) ˇ g t (cid:107) 2 / (cid:107) ˆ g t (cid:107) 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] “softmax”: 1920.
Layers with large d have large (cid:107) ˜
g t (cid:107) 2 / (cid:107) ˆ g t (cid:107) 2 values, which agrees with Proposition 1.
With clipped gradients, (cid:107) ˇ g t (cid:107) 2 / (cid:107) ˆ g t (cid:107) 2 is much smaller and does not depend on d , agreeing with Proposition 3.
Figure 6(c) shows convergence of the average training loss.
Using a smaller c (more aggressive clipping) leads to faster training (at the early stage of training) but larger ﬁnal training loss, agreeing with Theorem 3.
Figure 7 shows convergence of the average training loss with different numbers of bits for the quantized clipped gradient, with c = 3 .
By comparing 3 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.
[Equation]
4.2. V ARYING THE N UMBER OF W ORKERS
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 ﬁx 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 (SQ m ).
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. [Table]
4. I MAGE N ET
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 ﬁrst 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.
[Table]
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 proﬁling 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 signiﬁcantly reduces network communication and speeds up training.
When the bandwidth is small (Figure 8(a)), communication is the bottleneck, and using quantizing gradients is signiﬁcantly faster than the use of full-precision gradients.
With a larger bandwidth (Figure 8(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]
C ONCLUSION
In this paper, we studied loss-aware weight-quantized networks with quantized gradient for efﬁcient communication in a distributed environment.
Convergence analysis is provided for weight-quantized models with full-precision, quantized and quantized clipped gradients.
Empirical experiments conﬁrm the theoretical results, and demonstrate that quantized networks can speed up training and have comparable performance as full-precision networks.
A CKNOWLEDGMENTS
We thank NVIDIA for the gift of GPU card.
A P ROOFS A. P ROOF OF T HEOREM
First, we introduce the following two lemmas.
[-+1 ,i with B r,i ≤ | g t,i | /s t < B r +
 ,i , its expectation satisﬁes:-]Lemma 1.
Let v t = (cid:80) tj =1 (1 − β ) β t − j g 2 j , where β ∈ [0 , 1) .
Assume that (cid:107) g j (cid:107) ∞ <
G ∞ for j ∈ { 1 , 2 . . . , t } .
Then, v t,i ≥ (1 − β ) g 2 t,i , (10) √ v t,i
[Equation]
G ∞ , (11) (cid:107)√ v
[Equation]
(cid:107) =
[Equation]
t (cid:88) j
= (1 − β ) β t − j (cid:107) g j (cid:107) 2 .
Proof.
v t,i = (cid:80) tj =1 (1 − β ) β t − j g 2 j,i ≥ (1 − β ) g 2 t,i .
Moreover, √ v t,i = (cid:118)(cid:117)(cid:117)(cid:116) t (cid:88)
j = (1 − β ) β t − j g 2 j,i ≤ (cid:118)(cid:117)(cid:117)(cid:116) t (cid:88)
j = (1 − β ) β t − j G 2 ∞ ≤ G ∞ , and (cid:107)√ v t (cid:107) = (cid:118)(cid:117)(cid:117)(cid:116)
d (cid:88) i = v t,i = (cid:118)(cid:117)(cid:117)(cid:116)
d (cid:88) i
= t (cid:88)
j = (1 − β ) β t − j g 2 j,i = (cid:118)(cid:117)(cid:117)(cid:116) t (cid:88)
[Equation]
Lemma 2.
[Lemma 10.3 in (Kingma & Ba, 2015)] Let g 1: T,i =
[ g 1 ,i , g 2 ,i , . .
. , g T,i ] (cid:62) be the vector containing the i th element of the gradients for all iterations up to T , and g t be bounded as in
Assumption A3 .
Then,
[Equation]
Proof.
(of Theorem 1) When only weights are quantized, the update for loss-aware weight quantization is
[Equation]
The update for the i th entry of w t is w t +1 ,i = [Equation] −
[Equation]
ˆ g t
[Equation]
i √ ˆ v t,i . This implies
[Equation]
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 (cid:22) L I , where I is the identity matrix.
Combining with the assumption in Section 3.1 that (cid:107) w m − w n (cid:107) ≤ D , we have
[Equation]
Let (cid:104) x , y (cid:105) =
x (cid:62) 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] [Table]
[Equation]
The ﬁrst inequality comes from (10) in Lemma 1.
In the second inequality, the ﬁrst term comes from (cid:80) di
[Equation]
w ∗ i ) 2 and the domain bound assumption in Section 3.1 (i.e., ( w T
[Equation]
i − [Equation] i ) ≤
[Equation]
w
[Equation]
−
[Equation]
(cid:107) ∞ ≤ D
[Equation]
The second term comes from the deﬁnition of H (cid:48) t (i.e., H (cid:48) − 12 t ( g
[Equation]
12 t
[Equation]
w
[Equation]
− ˆ w
[Equation]
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[-ˆ w t = arg min w (cid:107) w − w t (cid:107) 
-]
[Equation]
If − α t M k ≤ w t,i ≤ α t M k , as (cid:112) ˆ v t − 1 ,i > 0 , the optimal ˆ w t,i satisﬁes ˆ w t,i ∈ { α t M r,i ,
α t M r +1 ,i } , where r is the index that satisﬁes α t M r,i ≤ w t,i ≤
α t M r +1 ,i .
Since α = max { α 1 , . . . , α T } , we have
[Equation]
[Equation]
Otherwise (i.e., w t,i is exterior of the representable range), the optimal ˆ w 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]
[Equation]
From (16) and (20),
[Equation]
[Equation]
From (21) and Assumption A3 , we have from (17)
[Equation]
Thus, the average regret is
[Equation]
A. P ROOF OF P ROPOSITION
Lemma 3.
For stochastic gradient quantization in (3), E (˜ g t )
=
ˆ g t , and E ( (cid:107) ˜ g t − ˆ g t (cid:107) 2 ) ≤ ∆ g (cid:107) ˆ g t (cid:107) ∞ (cid:107) ˆ g t (cid:107) 1 . Proof.
Denote the i th element of the quantized gradient ˜ g t by ˜ g t,i .
For two adjacent quantized values B r,i , B r +1 ,i with B r,i ≤ | g t,i | /s
t < B r
{++
+}
,i ,
E (˜ g t,i ) =
E ( s t · sign (ˆ g t,i ) · q t,i ) =
s t · sign (ˆ g t,i ) · E ( q t,i )
[Equation]
Thus, E (˜ g t ) =
ˆ g t , and the variance of the quantized gradients satisfy
[Equation]
Proof.
From Lemma 3,
[Equation]
Denote { x 1 , x 2 , . . .
, x d } as the absolute values of the elements in ˆ g t sorted in ascending order.
From
Cauchy’s inequality, we have [Equation] d [Equation]
i = x
[Equation]
[Equation]
The equality holds iff x 1 = x 2 = · · · = [Equation] x d .
Thus, we have
[Equation]
A. P ROOF OF T HEOREM
Proof.
When both weights and gradients are quantized [Equation] the update is
[Equation]
Similar to the proof of Theorem
[Equation]
and using that E (˜ g t )
=
ˆ g t (Lemma 3)
[Equation]
we have
[Equation]
As (21) in the proof of Theorem 1 still holds, using Proposition 1 and Assumption A [Equation] we have
[Equation] E ( R ( T ) /T ) ≤
[Equation]
A. P ROOF OF P ROPOSITION
Proof.
From Lemma 3,
E ( Q g ( Clip (ˆ g t ))) =
Clip (ˆ g t ) , and
E ( (cid:107) Q g ( Clip (ˆ g t ))
(cid:107) 2 ) ≤ E (∆ g (cid:107) Clip
(ˆ g t ) (cid:107) ∞ (cid:107) Clip
(ˆ g t ) (cid:107)
+ (cid:107) Clip (ˆ g t ) (cid:107) 2 ) .
As [ˆ g t ] i ∼ N (0 , σ 2 ) , its pdf is f ( x ) = 1 √ 2 πσ 2 e − x 2 2 σ 2 . Thus,
E ( (cid:107) Clip (ˆ g t ) (cid:107) 1 ) ≤ E ( (cid:107) ˆ g t (cid:107) 1 ) =
d (cid:88)
[Equation]
( | [ˆ g
[Equation]
| ) =
d (cid:90)
[Equation]
∞
[Equation]
|
[Equation]
x )
[Equation]
x
[Equation]
x )
[Equation]
= d (cid:90) +
[Equation]
d
[Equation]
2 πσ 2 e
[Equation]
∞= (2 /π ) 12 dσ.
As E ( (cid:107) Clip (ˆ g t ) (cid:107) 2 ) ≤ E ( (cid:107) ˆ g t (cid:107) 2 ) , and that E ( (cid:107) ˆ g t (cid:107) 2 ) = dσ 2 , we have
E ( (cid:107) Q g ( Clip (ˆ g t ))
(cid:107) 2 ) ≤ E (∆ g (cid:107) Clip
(ˆ g t ) (cid:107) ∞ (cid:107) Clip
(ˆ g t ) (cid:107)
+ (cid:107) Clip (ˆ g t ) (cid:107) 2 ) ≤ ∆ g cσ (2 /π )
12 dσ + E ( (cid:107) Clip (ˆ g t ) (cid:107) 2 ) ≤ ((2 /π )
12 c ∆ g + 1) E ( (cid:107) ˆ g t (cid:107) 2 ) .
A. P ROOF OF P ROPOSITION
Proof.
[Equation]
A. P ROOF OF T HEOREM
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 (ˆ g t ))) =
Clip (ˆ g t ) , we have
E ( R ( T )) ≤
d (cid:88)
[Equation]
i =
T (cid:88) t =
E (cid:32) ( (cid:112) ˇ v t,i 2 η t − (cid:112) ˇ v t − 1 ,i 2 η t − 1 )( w t,i − w ∗ i )(cid:33) +
T (cid:88) t =
E ( (cid:104) w t − w ∗ , g t − ˇ g t (cid:105) )
+ d (cid:88) i =
T (cid:88) t =
η t 2 E   ˇ g 2 t,i (cid:113) (1 − β )ˇ g 2 t,i 

[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[-, M k } , with k = 2 m − 1 − 1 , 
-]
[-As f t is twice differentiable (Assumption A2 ), using the mean value theorem, there exists p ∈ (0 , 1) such that (cid:107) g t − ˆ g t (cid:107) 
-]
(21) 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., (cid:107) w m − w n (cid:107) ≤ D and (cid:107) w m − w n (cid:107) ∞ ≤ D ∞ for any w m , w n ∈ S ), and Proposition 3, we have
[Equation]