{'fraction_non_alphanumeric': 0.034209264827646316, 'fraction_numerical': 0.012419924173094522, 'mean_word_length': 4.800808897876643, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Searching for Low-Bit Weights in Quantized Neural Networks

Quantized neural networks with low-bit weights and activations are attractive for developing AI accelerators. However, the quantization functions used in most conventional quantization methods are non-differentiable, which increases the optimization difficulty of quantized networks. Compared with full-precision parameters (i.e., 32-bit floating numbers), low-bit values are selected from a much smaller set. For example, there are only 16 possibilities in 4-bit space. Thus, we present to regard the discrete weights in an arbitrary quantized neural network as searchable variables, and utilize a differential method to search them accurately. In particular, each weight is represented as a probability distribution over the discrete value set. The probabilities are optimized during training and the values with the highest probability are selected to establish the desired quantized network. Experimental results on benchmarks demonstrate that the proposed method is able to produce quantized neural networks with higher performance over the state-of-the-art methods on both image classification and super-resolution tasks.


Introduction
The huge success of deep learning is well demonstrated in considerable computer vision tasks, including image recognition [20], object detection [11,40], visual segmentation [18], and image processing [26]. On the other side, these deep neural architectures are often oversized for accuracy reason. A great number of network compression and acceleration methods have been proposed to eliminate the redundancy and explore the efficiency in neural networks , including pruning [16,48], low-bit quantization [6,39,56], weight decompostion [53,31], neural architecture search [34,49] and efficient block design [22,41,37].
Among these algorithms, quantization is very particular which represents parameters in deep neural networks as low-bit values. Since the low costs of quantized networks on both memory usage and computation, they can be easily deployed on mobile devices with specific hardware design. For example, compared with conventional 32-bit networks, binary neural networks (BNNs) can directly obtain a 32× compression ratio, and an extreme computational complexity reduction by executing bit-wise operations (e.g., 57× speed-up ratio in XNORNet [39]). However, the performance of the low-bit neural networks is usually worse than that of full-precision baselines, due to the optimization difficulty raised by the low-bit quantization functions.
To reduce the accuracy drop of quantized neural networks, some methods have been proposed in recent years. BiRealNet [35] inserts more shortcuts to help optimization. Structured Binary [59] and ABCNet [32] explore some sophisticated binary blocks and achieve comparable performance to that of full-precision networks, etc.
Admittedly, the aforementioned methods have made great efforts to improve the performance of the quantized neural networks. However, the accuracy gap between the full-precision network and its quantized version is still very huge, especially the binarized model. For example, the state-ofthe-art accuracy of binarized ResNet-18 is about 10% lower than that of the full-precision baseline. A common problem in existing quantization methods is the estimated gradients for quantization functions, using either STE [6,39] or self-designed gradient computation manner [34]. The estimated gradients may provide inaccurate optimization direction and consequently lead to worse performance. Therefore, an effective approach for learning quantized neural networks without estimated gradients is urgently required.
In this paper, we present a novel weight searching method for training the quantized deep neural network without gradient estimation. Since there are only a few values of low-bit weights (e.g., +1 and -1 in binary networks), we develop a weight searching algorithm to avoid the non-differentiable problem of quantization functions. All low-bit values of an arbitrary weight in the given network are preserved with different probabilities. These probabilities will be optimized during the training phase. To further eliminate the performance gap after searching, we explore the temperature factor and a state batch normalization for seeking consistency in both training and testing. The effectiveness of the proposed differentiable optimization method is then verified on image classification and super-resolution tasks, in terms of accuracy and PSNR values.

Related Works
To reduce memory usage and computational complexity of deep neural networks, a series of methods are explored, including efficient block design, network pruning, weight decomposition, and network quantization. MobileNet [22,41] and ShuffleNet [37] design novel blocks and construct the networks with high efficiency. Weight pruning methods such as DeepCompression [16] propose to remove redundant neurons in pre-trained models, while requires specific hardware for acceleration. Structured pruning methods [21,48,51] discard a group of weights (e.g., an entire filter) in pre-trained networks so that the compressed model can be directly accelerated in any off-the-shelf platforms. Low-rank decomposition methods [8,25,53,50] explore the relationship between weights and filters and explore more compact representations. Gradient-based neural architecture search methods [34,47] use the continuous relaxation strategy to search discrete operations for each layer. All the candidate operations are mixed with a learnable distribution during searching and the operation with the highest probability is selected as the final operation. Quantization methods [29,1,38,12,43,9,46,55] represent weights or activations in a given neural architecture as low-bit values. The model size and computational complexity of the quantized network are much smaller than those of its original version. Compared with previous model compression methods, network quantization does not change the architecture and the calculation process of original ones, which is supported by some mainstream platforms.
To maintain the high performance of quantized neural networks, considerable approaches have been explored for training low-bit weights and activations. For instance, Fixed point quantization [30] reduces about 20% complexity without loss of accuracy on CIFAR-10 dataset. BinaryConnect [6] represents weights by binary values {−1, +1}, TTQ [57] uses the ternary weights {−1, 0, +1}. Activations in these two methods are still full-precision values. DoReFa [56] quantizes both weights and activations to low-bit values. Among all the quantization methods, in extreme cases, if activations and weights are both 1 bit, the binary neural network not only occupies less storage space but also utilizes low-level bit operations xnor and bitcount to accelerate inference. ABCNet [32], CBCN [33], BENN [58] and SBNN [59] explored how to modify the BNN to match the performance with fullprecision networks. In [60], a clearly different viewpoint is investigated into gradient descent, which provides the first attempt for the field and is worth further exploration. The hidden relationship between different variables is carefully studied, which will benefit many applications.
Nevertheless, most of the quantization functions in existing methods are non-differentiable, which increases the optimization difficulty. Thus, this paper aims to explore a more effective algorithm for quantizing deep neural networks.

Methods
In this section, we first briefly introduce the optimization approach in the conventional weight quantization methods and the existing problems. Then, a low-bit weight search approach is developed for accurately learning quantized deep neural networks. The strategies, including gradually decreasing temperature and state batch normalization, are proposed to eliminate the quantization gap.

Optimization Difficulty in Network Quantization
Representing massive weights and activations in deep neural networks using low-bit values is effective for reducing memory usage and computational complexity. However, it is very hard to learn these low-bit weights in practice.
For the case of q-bit quantization, the coordinate axis is divided into m = 2 q intervals, and each interval corresponds to one discrete value in set where x ∈ R is the original full-precision values. Given full-precision latent convolutional filters W lat q , the weights are quantized as W q = Q(W lat q ), which are used to calculate the output features (i.e., activations). In the training phase, the gradients ∇ Wq w.r.t the quantized filters W q can be calculated with standard back-propagation algorithm. However, the gradients ∇ W lat q is hard to obtain, because the derivative of Q is zero almost everywhere and infinite at zero point. The Straight Through Estimator (STE) [6] is a widely used strategy to estimate the gradient of W lat q , i.e., where the approximate gradients ∇ W lat q are use to update weights W lat q , where η is the learning rate and σ(·) is the gradient clip function. Although Eq. 2 can provide the approximate gradients of W lat q , the estimation error cannot be ignored if we aim to further improve the performance of quantized networks. Considering that there are a number of layers and learnable parameters in modern neural networks, the optimization difficulty for learning accurate quantized models is still very large.

Low-bit Weight Searching
The parameters in a quantized neural network can be divided into two parts: the non-quantized parameters W f (e.g., in batch normalization, fully connected layer), and the quantized convolutional parameters W q . The target of training the network is to find W * f , W * q that minimizes where the W f and W q belong to different domains, which are real number R and discrete set V, respectively.
To optimize modern neural networks, the stochastic gradient descent (SGD) strategy is usually utilized. However, the discrete variables W q are not feasible to be optimized by SGD. The previously described solution (Eq. 2-3) by introducing the latent variables can be viewed as a heuristic solution that enables updating all the parameters in an end-to-end manner. However, the estimated and inaccurate gradients limit the upper bound of the performance. In contrast, inspired by gradient-based neural architecture search methods [34,49,17,52], we introduce the continuous relaxation strategy to search discrete weights.

Consider optimizing an
A new auxiliary tensor A ∈ R m×d1×···×dn is created to learn the distribution of W , and the probability over m discrete variables is computed according to the following formula, where P i is probability that the elements in W belong to the i-th discrete value v i , and τ is the temperature controlling the entropy of this system. The expectation of the quantized values for W can be obtained: where the continuous state tensor W c is calculated according to the probability over all the discrete values. W c is used for convolution during training, and the process of Eq. 6 is differentiable and friendly for end-to-end training. Here we optimize the auxiliary tensor A whose gradients can be accurately calculated so that we avoid the gradient estimation in previous works.
In the inference stage, the weights are quantized by selecting the discrete value with the maximum probability for each position. In formal, the quantized state weights are where I = onehot(arg max i (P i )), i ∈ {1, · · · , m} indicates the one-hot vectors with the maximum probability.
For a convolution layer in neural networks, a four-dimensional weight tensor W of size M × N × D K × D K is to be learned, where M, N , and D K are output channels, input channels, and kernel size, respectively. By using the proposed method to search for q-bit quantized weight W , the problem can be transformed into a special case of dimension n = 4 and discrete values m = 2 q (Eq. 1). The tensor A ∈ R m×M ×N ×D K ×D K is constructed to learn the distribution over the discrete value set V according to Eq. 5. By using the continuous relaxation, the learning of Eq. 4 could be transformed to learn the tensor A, W * f , A * = arg min where the entire network is differentiable and can be optimized end-to-end with accurate gradients.

Optimization Details
We use the full-precision tensor W c for training and quantized tensor W q for inference. Although the continuous relaxation method solves the problem of inaccurate gradient during training, there is still a quantization gap after converting W c to W q . This will lead to the mismatch between the W q and other parameters trained according to W c , such as the statistics in the batch normalization layers.

Reducing the Quantization Gap
In the proposed low-bit weight searching scheme, the continuous W c for training and the discrete W q for inference are not exactly the same. The quantization gap is introduced to measure the quantization error in the process of transforming the softmax distribution to the one-hot vector (Eq. 6-7), Fortunately, As stated in the temperature limit Theorem 1, the quantization gap W gap could be an infinitesimal quantity if the temperature τ is small enough. Theorem 1 ( Temperature Limit Theorem ) Assuming a ∈ R m is a vector in tensor A. If the temperature τ is gradually decreasing to zero, then the quantization gap is an infinitesimal quantity.

Algorithm 1 Training algorithm of SLB
Input: The network N constructed by convolution and state batch normalization, training iterations I, dataset D, initialize temperature τ s , end temperature τ e and temperature decay scheduler T . 1: for iter i in 1, . . . , I do 2: Update temperature parameter τ according to the temperature decay scheduler T . 3: Get minibatch data X and target Y from dataset D, calculate continuous weights W c and quantized weights W q of N according to the current temperature τ .

4:
The continuous state weights W c (Eq. 6) is computed and prediction P = N (X). The continuous state statistics in SBN are also updated. 5: Compute the discrete weights W q (Eq. 7) and the discrete state statistics in SBN layer are updated (Eq. 13). 6: The loss is calculated according to the prediction P and target Y , and the back-propogated gradients are used to update auxiliary matrix A. 7: end for 8: Record quantized tensors W q and the discrete state statistics in SBN. Output: A trained quantized neural network N * . proof 1 The distribution p is computed as, by gradually decreasing τ to zero, the index of the maximum value is k = arg max i p i , the quantization gap w gap is computed as, lim τ →0 We propose the gradually decreasing temperature strategy during training so that lim τ →0 W c = W q .
In particular, at the beginning of optimization, the temperature factor τ is high, and the distribution P is relatively smooth. With the change of temperature τ , the distribution P becomes sharper. In this way, the quantization gap will gradually decrease as τ changes.

State Batch Normalization
With the gradually decreasing temperature strategy, the continuous W c will converge to the discrete W q . Nevertheless, one problem that cannot be ignored is that the temperature cannot be decreased to a minimal value, i.e., 0. If a neuron w's probability of choosing its value to be a discrete value is greater than a relatively high threshold (e.g., max(p) > 0.999), we may infer that the discrete value will not change as we continue to decrease the temperature and make the distribution sharper. Under this assumption, the quantized weights are well optimized and the only difference between training and inference is the statistics difference for batch normalization layers. Thus we proceed to develop a corresponding state batch normalization that acts as a bridge between a sharp softmax distribution and a one-hot distribution.
Batch Normalization (BN) [24] is a widely-used module for increasing the training stability of deep neural networks. The conventional BN for a given input feature y can be written as, where i is the index of channel and µ i , σ i are the mean and standard deviation values for the i-th channel, respectively. In the proposed method, W c is used for convolution during training, so the normalization is formulated as, where x is the input data, ⊗ is the convolution operation and y c is the output. µ c,i and σ c,i are the mean value and standard deviation of the i-th channel in y c .
Therefore, the statistics of the quantized weights W q does not match with the statistics σ c and µ c of BN , which results in a precision decline in inference. To address this problem, we proposed the State Batch Normalization (SBN). To be specific, the SBN calculates two groups of statistics during training, one is for y c and the other is for y q where y q is the convolution output using quantized weights W q . The normalization process of y q is where µ q,i and σ q,i are the mean and standard deviation of the i-th channel in y q .
Bothŷ c andŷ q have a mean of zero and a standard deviation of one. We make they share the same group of affine coefficients, In this case, the proposed SBN eliminates the small quantization gap in the statistics for batch normalization layers.

Overall Algorithm
We view the training for quantized networks as a search problem, and utilize a differentiable method for learning the distribution of quantized weights. The strategies including gradually decreasing temperature and state batch normalization are proposed to eliminate the quantization gap. The overall training algorithm of searching for low-bit weights (SLB) is summarized in Algorithm 1. We examine our proposed method on quantized neural networks with different bitwidths. Following common practice in most works, we use the CIFAR-10 [28] and large scale ILSVRC2012 [7] recognition datasets to demonstrate the effectiveness of our method. For all the quantized neural networks, following previous methods [35,54,56], all convolution layers except for the first one are quantized. The low-bit set V is constructed by uniform distribution from −1 to 1.

Experiments on CIFAR-10
In this section, we first examine different temperature decay schedulers and then compare the results with other methods. We train the network for 500 epochs in total and decay the learning rate by a factor of 10 at 350, 440, and 475 epochs. The matrix A is initialized by kaiming initialization [19]. The quantization function for the activations is the same as DoReFa [56].
We test several different decay schedulers for temperature changing, including sin, linear and exp, which are widely used in adjusting the learning rate [36,22]. For convenience, we used T in this section to represent 1 τ in Eq. 5. The temperature T is used to control the entropy of the system. Given the start temperature factor T s , the end temperature T e and the total number of training iterations I. At iteration i, the temperature T t in different schedulers is calculated as follow, In Figure 1, we comprehensively compare different schedulers on binary ResNet20. We set T s = 0.01 and T e = 10. For sin and linear schedulers, the accuracies converge rapidly. However, some weights are not adequately trained, which results in relatively low accuracies. For the exp scheduler, the accuracies are much higher which indicates the weights converge to better local minima. In the following experiments, we adopt the exp scheduler for temperature adjusting.  We compare our results with other SOTA quantization methods including BNN, XNORNet, DoReFa, DSQ, SQ, and LQ-Net, on two different network architectures, i.e., VGG-Small [44] and ResNet20 [20]. As shown in Table 1 and Table 2, our method outperforms other methods and achieves state-of-the-art results on different bit-widths.

Experiments on ILSVRC2012
In the ILSVRC2012 classification experiments, we use ResNet18 [20,35] as our backbone and compare the results with other state-of-the-art methods. The learning rate starts from 1e-3, weight decay is set to 0, and Adam optimizer is used to update parameters. Table 3 presents the results of our method and a number of other quantization methods.
The binary neural network is the most potential method because the xnor and bitcount operations are relatively efficient. Our proposed method on the binary case achieves state-of-the-art accuracy with a Top-1 accuracy of 61.3% . When using more bits on the activations, the Top-1 accuracies gradually increase. Our method consistently outperforms other methods by a significant margin. By adding the bitwidth of weights, the proposed SLB also achieves state-of-the-art accuracies on different settings.

The Impact on State Batch Normalization
We further verify the importance of state batch normalization by removing it in binary ResNet18.
In particular, the discrete weights and discrete state statistics are not calculated during training, and the continuous state statistics are used after training. Because of the quantization gap, the SLB (w/o SBN) in Table 3 decreases the Top-1 accuracy by 0.3%. This indicates the essentiality to maintain two groups of statistics, which are estimated by the continuous state outputs and discrete state outputs, respectively.

Experiment on Super Resolution
To verify the generalization of the proposed method, we apply SLB to the image super-resolution task. The typical model VDSR [27] is selected as the baseline model. Following the original paper,  we use the 291 images as in [42] for training and test on Set5 dataset [3]. Each image in the training data is split into patches and augmented with rotation or flip. The baseline model and the binarized models using DoReFa and SLB algorithms are trained with the same setting as in [27].
The models are compared at different scale factors, i.e.×2 and ×3. From the results in Figure 2, we can see that SLB achieves much higher PSNR than DoReFa at both ×2 and ×3 scale factors. In Figure 2(a), the eyebrow in DoReFa's result is somewhat red while the result of SLB is normal and closer to the raw image. In Figure 2(b), the texture on the wing in DoReFa's result is blurry and hard to see clearly. SLB could well recover the texture and performs close to the full-precision model.

Conclusions
In this paper, we use the continuous relaxation strategy which addresses the gradient mismatch problem. To learn the discrete convolution kernels, an auxiliary probability matrix is constructed to learn the distribution for each weight from soft to hard, and the gradients are calculated to update the distribution. The state batch normalization is also proposed to minimize the gap between continuous state outputs and discrete state outputs. Our SLB can be applied to optimize quantized networks on a number of bitwidth cases and achieved state-of-the-art performance, which demonstrates the effectiveness of our method.