Title: ALTERNATING MULTI-BIT QUANTIZATION FOR RECURRENT NEURAL NETWORKS

Abstract: Recurrent neural networks have achieved excellent performance in many applications. However, on portable devices with limited resources, the models are often too large to deploy. For applications on the server with large scale concurrent requests, the latency during inference can also be very critical for costly computing resources. In this work, we address these problems by quantizing the network, both weights and activations, into multiple binary codes {-1, +1}. We formulate the quantization as an optimization problem. Under the key observation that once the quantization coefficients are fixed the binary codes can be derived efficiently by binary search tree, alternating minimization is then applied. We test the quantization for two well-known RNNs, i.e., long short term memory (LSTM) and gated recurrent unit (GRU), on the language models. Compared with the full-precision counter part, by 2-bit quantization we can achieve ∼16× memory saving and ∼6× real inference acceleration on CPUs, with only a reasonable loss in the accuracy. By 3-bit quantization, we can achieve almost no loss in the accuracy or even surpass the original model, with ∼10.5× memory saving and ∼3× real inference acceleration. Both results beat the exiting quantization works with large margins. We extend our alternating quantization to image classification tasks. In both RNNs and feedforward neural networks, the method also achieves excellent performance.

1. INTRODUCTION:

Recurrent neural networks (RNNs) are specific type of neural networks which are designed to model the sequence data. In last decades, various RNN architectures have been proposed, such as Long-Short-Term Memory (LSTM) (Hochreiter & Schmidhuber, 1997) and Gated Recurrent Units Cho et al. (2014) . They have enabled the RNNs to achieve state-of-art performance in many applications, e.g., language models (Mikolov et al., 2010) , neural machine translation (Sutskever et al., 2014; Wu et al., 2016) , automatic speech recognition (Graves et al., 2013) , image captions (Vinyals et al., 2015) , etc. However, the models often build on high dimensional input/output,e.g., large vocabulary in language models, or very deep inner recurrent networks, making the models have too many parameters to deploy on portable devices with limited resources. In addition, RNNs can only be executed sequentially with dependence on current hidden states. This causes large latency during inference. For applications in the server with large scale concurrent requests, e.g., on-line machine translation and speech recognition, large latency leads to limited requests processed per machine to meet the stringent response time requirements. Thus much more costly computing resources are in demand for RNN based models.

To alleviate the above problems, several techniques can be employed, i.e., low rank approximation (Sainath et al., 2013; Jaderberg et al., 2014; Lebedev et al., 2014; Tai et al., 2016) , sparsity (Liu et al., 2015; Han et al., 2015; 2016; Wen et al., 2016) , and quantization. All of them are build on the redundancy of current networks and can be combined. In this work, we mainly focus on quantization based methods. More precisely, we are to quantize all parameters into multiple binary codes {-1, +1}.

The idea of quantizing both weights and activations is firstly proposed by (Hubara et al., 2016a) . It has shown that even 1-bit binarization can achieve reasonably good performance in some visual classification tasks. Compared with the full precision counterpart, binary weights reduce the memory by a factor of 32. And the costly arithmetic operations between weights and activations can then be replaced by cheap XNOR and bitcount operations (Hubara et al., 2016a) , which potentially leads to much acceleration. Rastegari et al. (2016) further incorporate a real coefficient to compensate for the binarization error. They apply the method to the challenging ImageNet dataset and achieve better performance than pure binarization in (Hubara et al., 2016a) . However, it is still of large gap compared with the full precision networks. To bridge this gap, some recent works (Hubara et al., 2016b; Zhou et al., 2016; 2017) further employ quantization with more bits and achieve plausible performance. Meanwhile, quite an amount of works, e.g., (Courbariaux et al., 2015; Li et al., 2016; Zhu et al., 2017; Guo et al., 2017) , quantize the weights only. Although much memory saving can be achieved, the acceleration is very limited in modern computing devices (Rastegari et al., 2016) . Among all existing quantization works, most of them focus on convolutional neural networks (CNNs) while pay less attention to RNNs. As mentioned earlier, the latter is also very demanding. Recently, (Hou et al., 2017) showed that binarized LSTM with preconditioned coefficients can achieve promising performance in some easy tasks such as predicting the next character. However, for RNNs with large input/output, e.g., large vocabulary in language models, it is still very challenging for quantization. Both works of Hubara et al. (2016b) and Zhou et al. (2017) test the effectiveness of their multi-bit quantized RNNs to predict the next word. Although using up to 4-bits, the results with quantization still have noticeable gap with those with full precision. This motivates us to find a better method to quantize RNNs. The main contribution of this work is as follows:

(a) We formulate the multi-bit quantization as an optimization problem. The binary codes {-1, +1} are learned instead of rule-based. For the first time, we observe that the codes can be optimally derived by the binary search tree once the coefficients are knowns in advance, see, e.g., Algorithm 1. Thus the whole optimization is eased by removing the discrete unknowns, which are very difficult to handle. (b) We propose to use alternating minimization to tackle the quantization problem. By separating the binary codes and real coefficients into two parts, we can solve the subproblem efficiently when one part is fixed. With proper initialization, we only need two alternating cycles to get high precision approximation, which is effective enough to even quantize the activations on-line. (c) We systematically evaluate the effectiveness of our alternating quantization on language models. Two well-known RNN structures, i.e., LSTM and GRU, are tested with different quantization bits. Compared with the full-precision counterpart, by 2-bit quantization we can achieve ∼16× memory saving and ∼6× real inference acceleration on CPUs, with a reasonable loss on the accuracy. By 3-bit quantization, we can achieve almost no loss in accuracy or even surpass the original model with ∼10.5× memory saving and ∼3× real inference acceleration. Both results beat the exiting quantization works with large margins. To illustrate that our alternating quantization is very general to extend, we apply it to image classification tasks. In both RNNs and feedforward neural networks, the technique still achieves very plausible performance.

2. EXISTING MULTI-BIT QUANTIZATION METHODS:

Before introducing our proposed multi-bit quantization, we first summarize existing works as follows:

(a) Uniform quantization method (Rastegari et al., 2016; Hubara et al., 2016b) firstly scales its value in the range x ∈ [-1, 1]. Then it adopts the following k-bit quantization:

EQUATION

after which the method scales back to the original range. Such quantization is rule based thus is very easy to implement. The intrinsic benefit is that when computing inner product Quantize to -α 1 α 1 0

Quantize to Quantize to Quantize to

α 1 -α 2 -α 1 +α 2 α 1 +α 2 -α 1 -α 2

Figure 1 : Illustration of the optimal 2-bit quantization when α 1 and α 2 (α 1 ≥ α 2 ) are known in advance. The values are quantized into -α 1 -α 2 , -α 1 + α 2 , α 1 -α 2 , and α 1 + α 2 , respectively. And the partition intervals are optimally separated by the middle points of adjacent quantization codes, i.e., -α 1 , 0, and α 1 , correspondingly. of two quantized vectors, it can employ cheap bit shift and count operations to replace costly multiplications and additions operations. However, the method can be far from optimum when quantizing non-uniform data, which is believed to be the trained weights and activations of deep neural network (Zhou et al., 2017) . (b) Balanced quantization (Zhou et al., 2017) alleviates the drawbacks of the uniform quantization by firstly equalizing the data. The method constructs 2 k intervals which contain roughly the same percentage of the data. Then it linearly maps the center of each interval to the corresponding quantization code in (1). Although sounding more reasonable than the uniform one, the affine transform on the centers can still be suboptimal. In addition, there is no guarantee that the evenly spaced partition is more suitable if compared with the non-evenly spaced partition for a specific data distribution. (c) Greedy approximation (Guo et al., 2017) instead tries to learn the quantization by tackling the following problem:

EQUATION

For k = 1, the above problem has a closed-form solution (Rastegari et al., 2016) . Greedy approximation extends to k-bit (k > 1) quantization by sequentially minimizing the residue. That is

EQUATION

Then the optimal solution is given as

EQUATION

)

Greedy approximation is very efficient to implement in modern computing devices. Although not able to reach a high precision solution, the formulation of minimizing quantization error is very promising. (d) Refined greedy approximation (Guo et al., 2017) extends to further decrease the quantization error. In the j-th iteration after minimizing problem (3), the method adds one extra step to refine all computed {α i } j i=1 with the least squares solution:

EQUATION

In experiments of quantizing the weights of CNN, the refined approximation is verified to be better than the original greedy one. However, as we will show later, the refined method is still far from satisfactory for quantization accuracy.

Besides the general multi-bit quantization as summarized above, Li et al. (2016) propose ternary quantization by extending 1-bit binarization with one more feasible state, 0. It does quantization by tackling min α,t w -αt 2 2 with t ∈ {-1, 0, +1} n . However, no efficient algorithm is proposed in (Li et al., 2016) . They instead empirically set the entries w with absolute scales less than 0.7/n w 1 to 0 and binarize the left entries as (4). In fact, ternary quantization is a special case of the 2-bit quantization in (2), with an additional constraint that α 1 = α 2 . When the binary codes are fixed, the optimal coefficient α 1 (or α 2 ) can be derived by least squares solution similar to (5).

-α 1 -α 2 -α 1 +α 2 α 1 -α 2 α 1 +α 2 -α 1 α 1 0 Figure 2:

Illustration of binary search tree to determine the optimal quantization.

Algorithm 1: Binary Search Tree (BST) to determine to optimal code BST(w, v) {w is the real value to be quantized} {v is the vector of quantization codes in ascending order}

m = length(v) if m == 1 then return v 1 end if w ≥ (v m/2 + v m/2+1 )/2 then BST(w, v m/2+1:m ) else BST( w, v 1:m/2 ) end

In parallel to the binarized quantization discussed here, vector quantization is applied to compress the weights for feedforward neural networks (Gong et al., 2014; Han et al., 2016) . Different from ours where all weights are directly constraint to {-1, +1}, vector quantization learns a small codebook by applying k-means clustering to the weights or conducting product quantization. The weights are then reconstructed by indexing the codebook. It has been shown that by such a technique, the number of parameters can be reduced by an order of magnitude with limited accuracy loss (Gong et al., 2014) . It is possible that the multi-bit quantized binary weight can be further compressed by using the product quantization.

3. OUR ALTERNATING MULTI-BIT QUANTIZATION:

Now we introduce our quantization method. We tackle the same minimization problem as (2). For simplicity, we firstly consider the problem with k = 2. Suppose that α 1 and α 2 are known in advance with

α 1 ≥ α 2 ≥ 0, then the quantization codes are restricted to v = {-α 1 -α 2 , -α 1 + α 2 , α 1 - α 2 , α 1 + α 2 }.

For any entry w of w in problem (2), its quantization code is determined by the least distance to all codes. Consequently, we can partition the number axis into 4 intervals. And each interval corresponds to one particular quantization code. The common point of two adjacent intervals then becomes the middle point of the two quantization codes, i.e., -α 1 , 0, and α 1 . Fig. 1 gives an illustration.

For the general k-bit quantization, suppose that {α i } k i=1 are known and we have all possible codes in ascending order, i.e., v = {-k i=1 α i , . . . , k i=1 α i }. Similarly, we can partition the number axis into 2 k intervals, in which the boundaries are determined by the centers of two adjacent codes in v, i.e., {(v i + v i+1 )/2} 2 k -1 i=1 . However, directly comparing per entry with all the boundaries needs 2 k comparisons, which is very inefficient. Instead, we can make use of the ascending property in v. Hierarchically, we partition the codes of v evenly into two ordered sub-sets, i.e., v 1:m/2 and v m/2+1:m with m defined as the length of v. If w < (v m/2 + v m/2+1 )/2, its feasible codes are then optimally restricted to v 1:m/2 . And if w ≥ (v m/2 +v m/2+1 )/2 , its feasible codes become v m/2+1:m . By recursively evenly partition the ordered feasible codes, we can then efficiently determine the Algorithm 2: Alternating Multi-bit Quantization Require :Full precision weight w ∈ R n , number of bits k, total iterations T Ensure :{α

i , b i } k i=1 Greedy Initialize {α i , b i } k i=1 as (4) for iter ← 1 to T do Update {α i } k i=1 as (5)

Construct v of all feasible codes in accending order Update {b i } k i=1 as Algorithm 1. end optimal code for per entry by only k comparisons. The whole procedure is in fact a binary search tree. We summarize it in Algorithm 1. Note that once getting the quantization code, it is straightforward to map to the binary code b. Also, by maintaining a mask vector with the same size as w to indicate the partitions, we could operate BST for all entries simultaneously. To give a better illustration, we give a binary tree example for k = 2 in Fig. 2 . Note that for k = 2, we can even derive the optimal codes by a closed form solution, i.e., b 1 = sign(w) and b 2 = sign(w -α 1 b 1 ) with α 1 ≥ α 2 ≥ 0.

Under the above observation, let us reconsider the refined greedy approximation (Guo et al., 2017) introduced in Section 2. After modification on the computed {α i } j i=1 as (5), {b i } j i=2 are no longer optimal while the method keeps all of them fixed. To improve the refined greedy approximation, alternating minimizing {α i } k i=1 and {b i } k i=1 becomes a natural choice. Once getting {b i } k i=1 as described above, we can optimize {α i } k i=1 as (5). In real experiments, we find that by greedy initialization as (4), only two alternating cycles is good enough to find high precision quantization. For better illustration, we summarize our alternating minimization in Algorithm 2. For updating {α i } k i=1 , we need 2k 2 n binary operations and kn non-binary operations. Combining kn non-binary operations to determine the binary code, for total T alternating cycles, we thus need 2T k 2 n binary operations and 2(T + 1)kn non-binary operations to quantize w ∈ R n into k-bit, with the extra 2kn corresponding to greedy initialization.

4. APPLY ALTERNATING MULTI-BIT QUANTIZATION TO RNNS:

Implementation. We firstly introduce the implementation details for quantizing RNN. For simplicity, we consider the one layer LSTM for language model. The goal is to predict the next word indexed by t in a sequence of one-hot word tokens (y * 1 , . . . , y * N ) as follows:

x t = W T e y * t-1 , i t , f t , o t , g t = σ(W i x t + b i + W h h t-1 + b h ), c t = f t c t-1 + i t g t , h t = o t tanh(c t ), y t = softmax(W s h t + b s ). (6)

where σ represents the activation function. In the above formulation, the multiplication between the weight matrices and the vectors x t and h t occupy most of the computation. This is also where we apply quantization to. For the weight matrices, We do not apply quantization on the full but rather row by row. During the matrix vector product, we can firstly execute the binary multiplication. Then element-wisely multiply the obtained binary vector with the high precision scaling coefficients. Thus little extra computation results while much more freedom is brought to better approximate the weights. We give an illustration on the left part of Fig. 3 . Due to one-hot word tokens, x t corresponds to one specific row in the quantized W e . It needs no more quantization. Different from the weight matrices, h t depends on the input, which needs to be quantized on-line during inference. For consistent notation with existing work, e.g., (Hubara et al., 2016b; Zhou et al., 2017) , we also call quantizing on h t as quantizing on activation.

For W ∈ R m×n and h t ∈ R n , the standard matrix-vector product needs 2mn operations. For the quantized product between k w -bit W and k h -bit h t , we have 2k w k h mn + 4k 2 h n binary operations and 6k h n + 2k w k h m non-binary operations, where 6k h n corresponds to the cost of alternating approximation (T = 2) and 2k w k h m corresponds to the final product with coefficients. As the binary 0.16 -0.21 … -0.05 -0.32 0.09 … 0.13 0.07 -0.17 … -0.02 … 0.03 -0.17 0.20

* … 1 -1 … -1 -1 1 … 1 1 -1 … -1 … 0.15 0.30 0.10 1 -1 … 1 -1 -1 … -1 -1 -1 … 1 0.08 0.12 0.06 -1 -1 1 * ( + ) … … 1 -1 1 … 0.13 0.05 ) ( + 0.15 0.30 0.10 1 -1 … -1 -1 1 … 1 1 -1 … -1 … 0.08 0.12 0.06 … 1 -1 … 1 -1 -1 … -1 -1 -1 … 1 -1 -1 1 … 0.05 1 -1 1 0.13 … * Standard Matrix Vector Product

Multi-bit Binary Product Modified Multi-bit Binary Product

Figure 3 : Illustration of quantized matrix vector multiplication (left part). The matrix is quantized row by row, which provides more freedom to approximate while adds little extra computation. By reformulating as the right part, we can make full use of the intrinsic parallel binary matrix vector multiplication for further acceleration.

multiplication operates in 1 bit, whereas the full precision multiplication operates in 32 bits, despite the feasible implementations, the acceleration can be 32× in theory. For alternating quantization here, the overall theoretical acceleration is thus computed as γ =

2mn 1 32 (2kwk h mn+4k 2 n n)+6k h n+2kwk h m .

Suppose that LSTM has hidden states n = 1024, then we have W h ∈ R 4096×1024 . The acceleration ratio becomes roughly 7.5× for (k h , k w ) = (2, 2) and 3.5× for (k h , k w ) = (3, 3). In addition to binary operations, the acceleration in real implementations can be largely affected by the size of the matrix, where much memory reduce can result in better utilizing in the limited faster cache. We implement the binary multiplication kernel in CPUs. Compared with the much optimized Intel Math Kernel Library (MKL) on full precision matrix vector multiplication, we can roughly achieve 6× for (k h , k w ) = (2, 2) and 3× for (k h , k w ) = (3, 3). For more details, please refer to Appendix A.

As indicated in the left part of Fig. 3 , the binary multiplication can be conducted sequentially by associativity. Although the operation is suitable for parallel computing by synchronously conducting the multiplication, this needs extra effort for parallelization. We instead concatenate the binary codes as shown in the right part of Fig. 3 . Under such modification, we are able to make full use of the much optimized inner parallel matrix multiplication, which gives the possibility for further acceleration. The final result is then obtained by adding all partitioned vectors together, which has little extra computation.

Training. As firstly proposed by Courbariaux et al. (2015) , during the training of quantized neural network, directly adding the moderately small gradients to quantized weights will result in no change on it. So they maintain a full precision weight to accumulate the gradients then apply quantization in every mini-batch. In fact, the whole procedure can be mathematically formulated as a bi-level optimization (Colson et al., 2007) problem:

EQUATION

)

Denote the quantized weight as ŵ = k i=1 α i b i . In the forward propagation, we derive ŵ from the full precision w in the lower-level problem and apply it to the upper-level function f (•), i.e., RNN in this paper. During the backward propagation, the derivative ∂f ∂ ŵ is propagated back to w through the lower-level function. Due to the discreteness of b i , it is very hard to model the implicit dependence of ŵ on w. So we also adopt the "straight-through estimate" as (Courbariaux et al., 2015) , i.e., ∂f ∂w = ∂f ∂ ŵ . To compute the derivative on the quantized hidden state h t , the same trick is applied. During the training, we find the same phenomenon as Hubara et al. (2016b) that some Table 1 : Measurement on the approximation of different quantization methods, e.g., Uniform (Hubara et al., 2016b) , Balanced (Zhou et al., 2017) , Greedy (Guo et al., 2017) , Refined (Guo et al., 2017) , and our Alternating method, see Section 2. We apply these methods to quantize the full precision pre-trained weight of LSTM on the PTB dataset. The best values are in bold. W-bits represents the number of weight bits and FP denotes full precision. 

5. EXPERIMENTS ON THE LANGUAGE MODELS:

In this section, we conduct quantization experiments on language models. The two most well-known recurrent neural networks, i.e., LSTM (Hochreiter & Schmidhuber, 1997) and GRU (Cho et al., 2014) , are evaluated. As they are to predict the next word, the performance is measured by perplexity per word (PPW) metric. For all experiments, we initialize with the pre-trained model and using vanilla SGD. The initial learning rate is set to 20. Every epoch we evaluate on the validation dataset and record the best value. When the validation error exceeds the best record, we decrease learning rate by a factor of 1.2. Training is terminated once the learning rate less than 0.001 or reaching the maximum epochs, i.e., 80. The gradient norm is clipped in the range [-0.25, 0.25]. We unroll the network for 30 time steps and regularize it with the standard dropout (probability of dropping out units equals to 0.5) (Zaremba et al., 2014) . For simplicity of notation, we denote the methods using uniform, balanced, greedy, refined greedy, and our alternating quantization as Uniform, Balanced, Greedy, Refined, and Alternating, respectively.

Peen Tree Bank. We first conduct experiments on the Peen Tree Bank (PTB) corpus (Marcus et al., 1993) , using the standard preprocessed splits with a 10K size vocabulary (Mikolov, 2012) . The PTB dataset contains 929K training tokens, 73K validation tokens, and 82K test tokens. For fair comparison with existing works, we also use LSTM and GRU with 1 hidden layer of size 300. To have a glance at the approximation ability of different quantization methods as detailed in Section 2, we firstly conduct experiments by directly quantizing the trained full precision weight (neither quantization on activation nor retraining). Results on LSTM and GRU are shown in Table 1 and Table  2 , respectively. The left parts record the relative mean squared error of quantized weight matrices with full precision one. We can see that our proposed Alternating can get much lower error across all varying bit. We also measure the testing PPW for the quantized weight as shown in the right parts of Table 1 and 2 . The results are in consistent with the left part, where less errors result in lower testing PPW. Note that Uniform and Balanced quantization are rule-based and not aim at minimizing the error. Thus they can have much worse result by direct approximation. We also repeat the experiment on other datasets. For both LSTM and GRU, the results are very similar to here.

We then conduct experiments by quantizing both weights and activations. We train with the batch size 20. The final result is shown in Table 3 . Besides comparing with the existing works, we also conduct experiment for Refined as a competitive baseline. We do not include Greedy as it is already shown to be much inferior to the refined one, see, e.g., Table 1 and 2. As Table 3 shows, our full precision model can attain lower PPW than the existing works. However, when considering the gap between quantized model with the full precision one, our alternating quantized neural network is still far better than existing works, i.e., Uniform (Hubara et al., 2016b) and Balanced (Zhou et al., 2017) . Compared with Refined, our Alternating quantization can achieve compatible performance using 1-bit less quantization on weights or activations. In other words, under the same tolerance of accuracy drop, Alternating executes faster and uses less memory than Refined. We can see that our 3/3 weights/activations quantized LSTM can achieve even better performance than full precision one. A possible explanation is due to the regularization introduced by quantization (Hubara et al., 2016b) .

WikiText-2 (Merity et al., 2017) Text8. In order to determine whether Alternating remains effective with a larger dataset, we perform experiments on the Text8 corpus (Mikolov et al., 2014) . Here we follow the same setting as (Xie et al., 2017) . The first 90M characters are used for training, the next 5M for validation, and the final 5M for testing, resulting in 15.3M training tokens, 848K validation tokens, and 855K test tokens. We also preprocess the data by mapping all words which appear 10 or fewer times to the unknown token, resulting in a 42K size vocabulary. We train LSTM and GRU with one hidden layer of size 1024 and set the batch size to 100. The result is shown in Table 5 . For LSTM on the left part, Alternating achieves excellent performance. By only 2-bit quantization on weights and activations, it exceeds Refined with 3-bit. The 2-bit result is even better than that reported in (Xie et al., 2017) , where LSTM adding noising schemes for regularization can only attain 110.6 testing PPW. For GRU on the right part, although Alternating is much better than Refined, the 3-bit quantization still has gap with full precision one. We attribute that to the unified setting of hyper-parameters across all experiments.

With specifically tuned hyper-parameters on this dataset, one may make up for that gap.

Note that our alternating quantization is a general technique. It is not only suitable for language models here. For a comprehensive verification, we apply it to image classification tasks. In both RNNs and feedforward neural networks, our alternating quantization also achieves the lowest testing error among all compared methods. Due to space limitation, we deter the results to Appendix B.

6. CONCLUSIONS:

In this work, we address the limitations of RNNs, i.e., large memory and high latency, by quantization. We formulate the quantization by minimizing the approximation error. Under the key observation that some parameters can be singled out when others fixed, a simple yet effective alternating method is proposed. We apply it to quantize LSTM and GRU on language models. By 2-bit weights and activations, we achieve only a reasonably accuracy loss compared with full precision one, with ∼16× reduction in memory and ∼6× real acceleration on CPUs. By 3-bit quantization, we can attain compatible or even better result than the full precision one, with ∼10.5× reduction in memory and ∼3× real acceleration. Both beat existing works with a large margin. We also apply our alternating quantization to image classification tasks. In both RNNs and feedforward neural networks, the method can still achieve very plausible performance. In this section, we discuss the implementation of the binary multiplication kernel in CPUs. The binary multiplication is divided into two steps: Entry-wise XNOR operation (corresponding to entry-wise product in the full precision multiplication) and bit count operation for accumulation (corresponding to compute the sum of all multiplied entries in the full precision multiplication). We test it on Intel Xeon E5-2682 v4 @ 2.50 GHz CPU. For the XNOR operation, we use the Single instruction, multiple data (SIMD) _mm256 _xor _ps, which can execute 256 bit simultaneously. For the bit count operation, we use the function _popcnt64 (Note that this step can further be accelerated by the up-coming instruction _mm512 _popcnt_epi64 , which can execute 512 bits simultaneously.

APPENDIX A BINARY MATRIX VECTOR MULTIPLICATION IN CPUS:

Similarly, the XNOR operation can also be further accelerated by the up-coming _mm512 _xor _ps instruction to execute 512 bits simultaneously). We compare with the much optimized Intel Math Kernel Library (MKL) on full precision matrix vector multiplication and execute all codes in the single-thread mode. We conduct two scales of experiments: a matrix of size 4096 × 1024 multiplying a vector of size 1024 and a matrix of size 42000 × 1024 multiplying a vector of size 1024, which respectively correspond to the hidden state product W h h t-1 and the softmax layer W s h t for Text8 dataset during inference with batch size of 1 (See Eq. ( 6)). The results are shown in Table 6 . We can see that our alternating quantization step only accounts for a small portion of the total executing time, especially for the larger scale matrix vector multiplication. Compared with the full precision one, the binary multiplication can roughly achieve 6× acceleration with 2-bit quantization and 3× acceleration with 3-bit quantization. Note that this is only a simple test on CPU. Our alternating quantization method can also be extended to GPU, ASIC, and FPGA.

B IMAGE CLASSIFICATION:

Sequential MNIST. As a simple illustration to show that our alternating quantization is not limited for texts, we conduct experiments on the sequential MNIST classification task (Cooijmans et al., 2017) . The dataset consists of a training set of 60K and a test set of 10K 28 × 28 gray-scale images.

Here we divide the last 5000 training images for validation. In every time, we sequentially use one row of the image as the input (28×1), which results in a total of 28 time steps. We use 1 hidden layer's LSTM of size 128 and the same optimization hyper-parameters as the language models. Besides the weights and activations, the inputs are quantized. The testing error rates for 1-bit input, 2-bit weight, and 2-bit activation are shown in 7, where our alternating quantized method still achieves plausible performance in this task.

MLP on MNIST. The alternating quantization proposed in this work is a general technique. It is not only suitable for RNNs, but also for feed-forward neural networks. As an example, we firstly conduct a classification task on MNIST and compare with existing work (Li et al., 2017) . The method proposed in (Li et al., 2017) is intrinsically a greedy multi-bit quantization method. For fair comparison, we follow the same setting. We use the MLP consisting of 3 hidden layers of 4096 units and an L2-SVM output layer. No convolution, preprocessing, data augmentation or pre-training is

:



Figures and Tables:

Quantization on the full precision pre-trained weight of GRU on the PTB dataset.

Table content: <table><tr><td/><td colspan="2">Relative MSE</td><td/><td/><td/><td colspan="2">Testing PPW</td></tr><tr><td>W-Bits</td><td>2</td><td>3</td><td>4</td><td/><td>2</td><td>3</td><td>4</td><td>FP</td></tr><tr><td>Uniform</td><td>1.070</td><td>0.404</td><td>0.302</td><td/><td>283.2</td><td>227.3</td><td>216.3</td></tr><tr><td>Balanced</td><td>0.891</td><td>0.745</td><td>0.702</td><td/><td colspan="3">10287.6 9106.4 8539.8</td></tr><tr><td>Greedy</td><td>0.146</td><td>0.071</td><td>0.042</td><td/><td>118.9</td><td>99.4</td><td>95.0</td><td>89.8</td></tr><tr><td>Refined</td><td>0.137</td><td>0.060</td><td>0.030</td><td/><td>105.3</td><td>95.4</td><td>93.1</td></tr><tr><td colspan="5">Alternating (ours) 0.125 0.043 0.019</td><td>103.1</td><td>93.8</td><td>91.4</td></tr><tr><td colspan="2">Relative MSE</td><td/><td/><td/><td/><td colspan="2">Testing PPW</td></tr><tr><td>W-Bits</td><td>2</td><td>3</td><td>4</td><td/><td>2</td><td>3</td><td>4</td><td>FP</td></tr><tr><td>Uniform</td><td>6.138</td><td>3.920</td><td>3.553</td><td colspan="5">3161906.6 771259.6 715781.9</td></tr><tr><td>Balanced</td><td>1.206</td><td>1.054</td><td>1.006</td><td/><td>2980.4</td><td>3396.3</td><td>3434.1</td></tr><tr><td>Greedy</td><td>0.377</td><td>0.325</td><td>0.304</td><td/><td>135.7</td><td>105.5</td><td>99.2</td><td>92.5</td></tr><tr><td>Refined</td><td>0.128</td><td>0.055</td><td>0.030</td><td/><td>111.6</td><td>99.1</td><td>97.0</td></tr><tr><td colspan="4">Alternating (ours) 0.120 0.044 0.021</td><td/><td>110.3</td><td>97.3</td><td>95.2</td></tr></table>

Testing PPW of multi-bit quantized LSTM and GRU on the PTB dataset. W-Bits and A-Bits represent the number of weight and activation bits, respectively.

Table content: <table><tr><td/><td/><td>LSTM</td><td/><td/><td/><td/><td/><td>GRU</td><td/><td/></tr><tr><td>W-Bits / A-Bits</td><td>2/2</td><td>2/3</td><td colspan="3">3/3 4/4 FP/FP</td><td>2/2</td><td>2/3</td><td colspan="3">3/3 4/4 FP/FP</td></tr><tr><td>Uniform</td><td>-</td><td>220</td><td>-</td><td>100</td><td>97</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>Balanced</td><td>126</td><td>123</td><td>-</td><td>114</td><td>107</td><td>142</td><td>-</td><td>-</td><td>116</td><td>100</td></tr><tr><td colspan="4">Refined Alternating (ours) 95.8 91.9 87.9 100.3 95.6 91.3</td><td>--</td><td>89.8</td><td colspan="3">105.1 100.3 95.9 101.2 97.0 92.9</td><td>--</td><td>92.5</td></tr></table>

Testing PPW of multi-bit quantized LSTM and GRU on the WikiText-2 dataset.

Table content: <table><tr><td/><td>LSTM</td><td/><td/><td/><td/><td>GRU</td><td/><td/></tr><tr><td>W-Bits / A-Bits</td><td>2/2</td><td>2/3</td><td>3/3</td><td>FP/FP</td><td>2/2</td><td>2/3</td><td>3/3</td><td>FP/FP</td></tr><tr><td colspan="5">Refined Alternating (ours) 106.1 102.7 98.7 108.7 105.8 102.2 100.1</td><td colspan="4">117.2 114.1 111.8 106.7 113.7 110.2 106.4</td></tr></table>

Testing PPW of multi-bit quantized LSTM and GRU on the Text8 dataset.

Table content: <table><tr><td/><td>LSTM</td><td/><td/><td/><td/><td>GRU</td><td/><td/></tr><tr><td>W-Bits / A-Bits</td><td>2/2</td><td>2/3</td><td>3/3</td><td>FP/FP</td><td>2/2</td><td>2/3</td><td>3/3</td><td>FP/FP</td></tr><tr><td colspan="5">Refined Alternating (ours) 108.8 105.1 98.8 135.6 122.3 110.2 101.1</td><td colspan="4">135.8 126.9 118.3 111.6 124.5 118.7 114.0</td></tr></table>

is a dataset released recently as an alternative to PTB. It contains 2088K training, 217K validation, and 245K test tokens, and has a vocabulary of 33K words, which is roughly 2 times larger in dataset size, and 3 times larger in vocabulary than PTB. We train with one layer's hidden state of size 512 and set the batch size to 100. The result is shown in Table4. Similar to PTB, our Alternating can use 1-bit less quantization to attain compatible or even lower PPW than Refined.

Table content: <table/>

Computing time of the binary matrix vector multiplication in CPUs, where Quant represents the cost to execute our alternating quantization on-line.

Table content: <table><tr><td>Weight Size</td><td colspan="5">W-Bits / A-Bits Total (ms) Quant (ms) Quant / Total Acceleration</td></tr><tr><td/><td>2/2</td><td>0.35</td><td>0.07</td><td>20%</td><td>5.6×</td></tr><tr><td>4096 × 1024</td><td>3/3</td><td>0.72</td><td>0.11</td><td>15%</td><td>2.7×</td></tr><tr><td/><td>FP/FP</td><td>1.95</td><td>-</td><td>-</td><td>1.0×</td></tr><tr><td/><td>2/2</td><td>3.17</td><td>0.07</td><td>2.2%</td><td>6.0×</td></tr><tr><td>42000 × 1024</td><td>3/3</td><td>6.46</td><td>0.11</td><td>1.7%</td><td>3.0×</td></tr><tr><td/><td>FP/FP</td><td>19.10</td><td>-</td><td>-</td><td>1.0×</td></tr></table>

Peer review (iclr2018):
 Summary of the paper ------------------------------- The authors propose a new way to perform multi-bit quantization based on greedy approximation and binary search tree for RNNs. They first show how this method, applied to the parameters only, performs on pre-trained networks and show great performances compared to other existing techniques on PTB. Then they present results with the method applied to both parameters and activations during training on 3 NLP datasets, showing again great performances compared to existing technique. Clarity, Significance and Correctness -------------------------------------------------- Clarity: The paper is clearly written. Significance: I*m not familiar with the quantization literature, so I*ll let more knowledgeable reviewers evaluate this point. Correctness: The paper is technically correct. Questions -------------- 1. It would be nice to have those memory and speed gains for training as well. Is it possible to use those quantization methods to train networks from scratch, i.e. without using a pre-train model? Pros ------ 1. The paper defines clear goals and contributions. 2. Existing methods (and their differences) are clearly and concisely presented. 3. The proposed method is well explained. 4. The experimental setup shows clear results compared to the non-quantized baselines and other quantization techniques. Cons ------- 1. It would be nice to have another experiment not based on text (speech recognition / synthesis, audio, biological signals, ...) to see how it generalizes to other kind of data (although I can*t see why it wouldn*t). Typos -------- 1. abstract: "gate recurrent unit" -> "gated recurrent unit" 2. equation (6): remove parenthesis in c_(t-1) 3. section 4, paragraph 1: "For the weight matrices, instead of on the whole, we quantize them row by row." -> "We don*t apply quantization on the full matrices but rather row by row." 4. section 4, paragraph 2: Which W matrix is it? W_h? (2x) Note ------- Since I*m not familiar with the quantization literature, I*m flexible with my evaluation based on what other reviewers with more expertise have to say.