{'fraction_non_alphanumeric': 0.02886100386100386, 'fraction_numerical': 0.014575289575289575, 'mean_word_length': 4.859917043740573, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Quantized Neural Networks: Characterization and Holistic Optimization

Quantized deep neural networks (QDNNs) are necessary for low-power, high throughput, and embedded applications. Previous studies mostly focused on developing optimization methods for the quantization of given models. However, quantization sensitivity depends on the model architecture. Therefore, the model selection needs to be a part of the QDNN design process. Also, the characteristics of weight and activation quantization are quite different. This study proposes a holistic approach for the optimization of QDNNs, which contains QDNN training methods as well as quantization-friendly architecture design. Synthesized data is used to visualize the effects of weight and activation quantization. The results indicate that deeper models are more prone to activation quantization, while wider models improve the resiliency to both weight and activation quantization. This study can provide insight into better optimization of QDNNs.


Introduction
Deep neural network (DNN) applications frequently demand extremely large models for an improved performance, which consumes a large amount of computation power not only for training but also for inference [45,8]. Thus, it is necessary to reduce their complexity for implementation on embedded devices. Various DNN compression methods have recently been devised to reduce the computational cost, power consumption, and storage space. Network quantization is one well-known method for substituting 32-bit floating-point weights with low bit-width numbers that usually employ one to four bits. Specifically, the performance of a quantized DNN (QDNN) is mostly maintained when retraining is applied after weight quantization [18,7]. Meanwhile, activation quantization has also been studied to reduce the computational cost and working memory footprint [31,43]. Therefore, activation quantization is particularly effective for DNN models with a large hidden-state dimension, such as convolutional neural networks (CNNs). Most previous studies on QDNN optimization have focused on the quantization number formats and training methods. The goal of these previous studies has been reducing the performance gap between the floatingpoint and quantized models. However, not all networks can be quantized in the same manner. Some networks are more robust to weight quantization, whereas some others are not [36]. Optimizing a QDNN requires understanding the characteristics of such quantization errors.
In this paper, we visualize the characteristics of the quantization errors and their effects on the performance of QDNNs when the model architecture and sizes are different. We use synthetic data and DNN models for error characteristic visualization. Based on the analysis results, we adopt two simple training methods to compensate weight and activation quantization errors; fine-tuning with cyclic learning rate scheduling for improved generalization and applying regularization term that reduces noise amplification through propagation. Experiments are conducted using CIFAR-10, ImageNet, and PASCAL VOC 2012 semantic image segmentation benchmark. The contributions of this paper are as follows: -We visualize the errors from the weight and activation quantization. The results indicate that the effect of the weight quantization error reduces the generalization capability whereas activation quantization error induces noise. -We show that increasing the width of a DNN model helps to mitigate the quantization effects of both the weight and activation whereas increasing the depth only decreases the weight quantization error. -We reduce the weight and activation quantization errors by employing training methods that improve the generalization capability and a regularization term that increases the noise robustness, respectively. -Our work is a holistic approach for the optimization of QDNN by examining the quantization effects of weights and activations, and also the architectural change.

Related Works on Network Quantization
Most DNN models are trained using 32-bit floating-point numbers. Apparently, DNN models do not demand 32-bit precision. Many quantization methods have been developed, some of which use an extremely small bit-width for a weight representation, such as 1-bit binary [7,31] or 2-bit ternary [10,44]. The signal-toquantization-noise ratio (SQNR) of several weight quantizers was also compared [25]. Quantization noise has been measured to find a better training scheme [17] or optimal quantization precision [33]. Activation quantization has also been developed to lower the computational costs [5]. An efficient QDNN implementation on embedded systems has also been studied [13,1]. The weight quantization effects usually depend on the model size; small DNN models tend to show considerable performance degradation after quantization [36]. In particular, increasing the number of parameters in CNNs reduces the quantization sensitivity [27].
However, considering the purpose of model compression, the number of parameters needs to be constrained. A recent study showed that weight quantization up to certain bits does not reduce the memorization capacity [2]. During the last several years, residual connections have been developed mainly for improved training of neural networks [15]. Architectural modifications of increasing the width or moving the location of activation and batch normalization have been studied [41,16]. These architectural changes also affect the quantization sensitivity.
The activation quantization has not been discussed as much as weight quantization, and most studies have not distinguished the effects of activation and weight quantization [31,20]. It has been observed that activation usually demands more bits than weights [43]. The different quantization approaches for the weight and activation are applied in [29] because the latter was not suitable for cluster-based quantization. Many studies have shown that a DNN can be vulnerable to noise. Even with an extremely small amount of noise, the inference of a DNN can easily be manipulated [37,22]. Previous studies have shown that quantizing the input makes it robust to adversarial attacks by reducing the amount of noise [40]. Several studies have shown that a QDNN can help defend from adversarial attacks [30,11]. However, QDNNs become more vulnerable to adversarial attacks than floating-point models when the noise exceeds a certain level [26]. The adversarial noise becomes larger at the deeper layers [24].

Revisit of QDNN Optimization
The process of uniform quantization for a DNN involves the following two steps, namely, clipping and quantization: The parameters of the DNNs are signed values so that the clip value β = −α = ∆(2 n−1 − 1) where n is the number of bits used to represent each parameter. Parameter quantization is mainly applied to the weights. For the sake of simple structure, all fixed-point weights in a layer share one scale factor ∆. The activation quantization is used to lower the computational cost and the size of the working memory for inference. When using the ReLU activation, the hidden vectors are represented with unsigned values and α and β becomes 0 and ∆(2 n − 1), respectively. Low-precision quantized networks require training in a fixed-point domain to improve the performance as follows: where E t is the loss computed through the model, f (·), at t-th iteration. Forward and backward propagations are conducted using quantized weights and activation. However, the computed gradients need to be added to the floating-point weights because those gradients are relatively small compared to the step size ∆ [7]. It is known that QDNNs perform better when retrained from a pretrained model at floating-point than trained from the scratch [43,20]. Most QDNN studies quantize the weights or activation according to Equation (1), although the processes of obtaining ∆, α, and β are different [18,5]. However, the effect of each quantization on the inference is quite different. The quantization errors are W = W − Q(W ) and a = a − Q(a) where W and a are errors owing to the quantization of the weight and activation, respectively. Because the trained weights have fixed values during inferences, W is a constant error. In other words, weight quantization can be modeled as the process of distorting the weights of the DNNs. This changes the direction of the inputprediction mapping function of the DNNs and thus causes distorted results at the inference. By contrast, a is an error that depends on the input applied during the inference process. Depending on the remainder of the hidden vector divided by ∆, the direction or magnitude of the error may change. That is, a induces noise with a maximum magnitude of ∆ 2 . In the rest of this paper, we analyze how such differences in quantization errors affect the performance of QDNNs under various model architectures. The weight quantization method in [18] and the PACT activation quantization [5] are adopted for our experiments. QDNNs are retrained from pretrained floatingpoint models.

Synthetic Dataset Generation
Most DNNs and their training samples used in real tasks have extremely high dimensions, and it is therefore very difficult to discern the effects of quantization. For a visualization analysis of QDNNs, we synthesized 2D inputs whose elements consist of x and y axes. The training dataset is composed of inputs S ∈ R 2 and C ∈ (0, 1), which are used to train FCDNNs for binary classification. The training dataset is synthesized through two steps. First, the core samples, s c , mapped to a label, c, are generated using the following equation: In our experiments, i is within {0, 1, 2, 3, 4} and r is 0.1. For each i, two semicircles correspond to one label. In each semicircle, we sample 100 points by increasing the angle linearly. Therefore, the total number of core samples is 2,000. Next, we generate subsamples by adding Gaussian noise to each core sample as follows: Nine subsamples for each core sample are used, and the samples are mapped to the same labels. As a result, the total number of datasets used for training is 10,000 for each label. The distribution of the generated dataset is shown in Fig. 1 (a). We quantize the FCDNN trained using the generated dataset and analyze the difference between the weight and activation quantization. In particular, we visualize the errors when varying the model depth or width. Two datasets are adopted for the evaluation of the trained model. The first is a test dataset. The correct answer dataset is constructed by dividing the area corresponding to each label by the radius of the semicircle. This dataset is used for quantitative analysis of the trained QDNNs by measuring accuracy. The other is a grid dataset that consists of (x, y) ∈ {(x, y)|0 < x < 1, 0 < y < 1}. By visualizing the prediction on the x-y plane, we can analyze whether the input-prediction mapping of a DNN is distorted or as added noise.

Results on Synthetic Dataset
We devise artificial DNN models for testing with the synthetic dataset. Fullyconnected DNN (FCDNN) models are employed with varying depth and width. In addition, models with residual connections are also considered. We indicate the experimental models as "width" -"depth" of FCDNNs. The prediction results of floating-point models using the evaluation dataset are shown in Fig. 1.
The 128-3 FCDNN shows quite a different prediction result from the actual data distribution. Fig. 1 (c,d) show that increasing the depth to 4 or the width to 256 is sufficient to learn the synthesized dataset quite faithfully. For the remaining experiments, we represent only the bottom-right quarter circle for detailed visualization. All QDNN results are reported after retraining. Fig. 2 (Left) shows the effects of the weight quantization according to the width and depth of FCDNNs. We can see that weight quantization distorts the input-prediction mapping of the DNN. The evaluation results of the weight quantized models resemble that of a small floating-point model, such as the 128-3 FCDNN shown in Fig. 1 (b). The experiment results show that the decrease in learning ability occurs similarly when the model size is reduced or the weights are quantized. As studied in [28], increasing the model size helps generalization. Our experiments show that the generalization capability decreases as the precision of the parameters is lowered. Thus, the effect of reduced generalization capability due to the weight quantization is not noticeable when the model size is large enough. The distortion with 2-bit weight quantization is barely found when the layer width or the number of layers is increased. Fig. 2 (Middle) shows the activation quantization results. The effect of the activation quantization is very different from that of the model capacity reduction in a DNN. Activation quantization appears to add noise to the prediction results. Although both the weight and activation quantization errors degrade the performance of DNNs, they behave in a completely different manner. When the activation is quantized to 2 bits, increasing the depth does not mitigate the noise added to the prediction results. Rather, the noise tends to worsen with weight quantization when the depth increases. Activation quantization is related to the dimension of each layer rather than the capacity of the model. Activation quantization in wide FCDNNs (Fig. 2 (e)) is more robust than in deep FCDNNs (Fig. 2  (h)). The effect of noise from the activation quantization is reduced because the number of dimensions of the hidden vector received as the input in each layer is increased. When quantizing both the weight and activation, the two errors are combined, and result in a noisy and distorted prediction, as shown in Fig. 2 (Right). The more results of different QDNNs are reported in Appendix A.
We also analyze the effect of residual connections on activation quantization. The residual connection helps train DNNs with an extremely large number of layers [15]. In our experiment, the residual connections are implemented by adding each hidden output to the activation of the next layer. The result is multiplied by 0.5 to preserve the scale of the intermediate results. Fig. 3 shows the results of the quantizing activation when the residual connection is applied. Residual connections help alleviate the distortion through weight quantization. However, FCDNNs with residual connections are more sensitive to activation quantization than the original models. With residual connections, the outputs of the quantized hidden layer are summed so that the activation quantization noise is also added. As a result, applying residual connections shows more noisy prediction in deep models, such as 128-8 FCDNNs.

QDNN Optimization with Architectural
Transformation and Improved Training The visualization results with the synthesized data show that weight quantization decreases the generalization capability of DNNs, while activation quantization induces noised inference. Also, the quantization effects depend on the architecture very much. Based on this observation, we employ three approaches for QDNN optimization. The first one is modifying the architecture quantizationfriendly. The second one is the training method for improved generalization. This technique is intended to reduce the effects of weight quantization. The third one is applying the regularization term that limits the amount of activation noise.

Architecture Transformation for Improved Robustness to Quantization
Deep CNN models are hard to train because of the gradient vanishing problem. The residual architecture was developed to solve this problem [15,39,38]. In CNN with residual connections, increasing the depth, often over 100, usually helps to improve the performance. Of course, widening the networks also increases the performance [41]. When the number of parameters is limited, increasing the depth is usually preferred because the model complexity rises in proportional to the depth, but squarely proportional to the width. However, our work in in Section 3 shows that deep CNN models are very prone to activation quantization. The conventional approach for QDNN design is developing the best performing floating-point model, and then quantizing it in the best way possible. In this case, the best performing floating-point model prefers deeper ones, which are, however, prone to activation quantization. Thus, we need to consider the effects of weight and activation quantization even for the initial floating-point model design. Wide CNN models, which are considered parameter inefficient, often show better performance than deep ones when the activation is severely quantized. Recent CNN models employ various residual blocks for improved performance or parameter efficiency. The most well-known residual blocks for CNNs are shown in Fig. 4. The depthwise block employed to MobileNetV2 [34] helps to reduce the number of parameters and computations. However, the quantization performances of these blocks are not well studied.

Cyclical Learning Rate Scheduling for Improved Generalization
We adopt the cyclic learning rate scheduling (CLR) as a way to reduce the effects of weight quantization. CLR increases and decreases the learning rate periodically, while conventional training usually reduces the learning rate in one direction. This method is known to increase the generalization capability of the model by leading to a flat loss surface [35]. Among a few different cyclical learning rate scheduling algorithms, we choose the one that alters the learning rate discretely, which is known to be more effective for generalization [19]. The maximum and minimum boundaries of the CLR are determined between the 100 and 0.1 times of the last learning rate of the retraining procedure, respectively. The learning rate changes 8 times in one cycle and exponentially decreases or increases. The CLR scheduling for each task is illustrated in Appendix B.

Regularization for Limiting the Activation Noise Amplification
Training methods to increase noise robustness of DNNs have been studied in the field of adversarial training. Parseval networks reduce the Lipschitz constant so that the noise of the input is not amplified as the layer increases [6]. In particular, [26] shows that activation quantized DNNs exacerbate performance degradation due to adversarial noise, and add the regularization term to the loss to keep the Lipschitz constant of each layer small. The regularization term is as follows: Note that convolution kernels are reshaped to (k ×k ×c in , c out ) where k, c in , and c out are the kernel size, input channels, and output channels, respectively. L Lip was applied to enhance the adversarial attack robustness of activation quantized DNNs [26]. We show that L Lip can reduce the noise due to activation quantization itself. Also, we compare the effect of the regularization term on the performance of weight quantized DNNs.

Visualizing the Effects of Quantization on the Segmentation Task
We first visualize the weight and activation quantization effects using a segmentation task. The PASCAL VOC 2012 dataset [9] is used. The dataset contains 1,464 training images and 1,449 validation images. Each image is labeled at pixel-level with 20 object classes and a background class. The MobileNetV2 [34] is adopted, which is trained according to DeepLabV3 [4] with 10,582 augmented training images [14] 1 . The model is used as a floating-point pretrained model after fine-tuned using the original 1,464 training images for 30K iterations. The output stride is 16 and Atrous Spatial Pyramid Pooling (ASPP) [3] is not applied. The performance is measured in terms of mean intersection over union (mIOU) without multi-scaling and flipping input images. Only the original training images are used for retraining and fine-tuning. The retraining is conducted for 30K iterations with a batch size of 16. The initial learning rate is 1e-3 and the learning rate policy is the same as [4]. The segmentation results of the retrained QDNNs are visualized in Fig. 5. Either weights or activations are quantized to 2 bits. When the object is simple, as shown in Fig. 5 (a), the weight quantized model seems to perform the segmentation fairly well. However, the results with the activation quantized model contains some noise on the section where the background and the object colors are similar. In the segmentation of a complex one, the weight quantized model fails to find the characteristics of the object, as shown in Fig. 5 (e). We can even consider that the activation noise corrupted model segments the bicycle more faithfully than the weight quantized model. The visualization results imply that weight quantization degrades the generalization ability, and activation quantization induces noise. The experiment with the segmentation task confirms the observation with the synthetic dataset in Section 3. More segmentation results of QDNNs are compared in Appendix C.

The Width and Depth Effects on QDNNs
We analyze the weight and activation quantization sensitivities when the depth and width of ResNet vary using the CIFAR-10 dataset [21]. The depth refers the number of layers and the width is that of channels in a CNN. Simple data augmentation techniques, cropping and flipping, are applied as suggested in [23]. The batch size is 128 and the number of epochs for pretraining is 200. The SGD optimizer with a momentum of 0.9 is used. The learning rate starts at 0.1 and decays by 0.1 times at 100 and 150 epochs. The L2 regularization is applied with a scale of 5e-4. Quantized models are retrained for 100 epochs with the initial learning rate of 0.01, and the learning rate decreases by a factor of 0.1 at 50 and 80 epochs. We do not employ the L2 regularization when retraining of the quantized model. The number of layers is either 20, 32, 56, or 110 and the width multiplier ranges from x1 to x10 times of the original ResNet. The experimental model denoted as ResNet×I employs I times larger number of channels. The width-expanded ResNets are compared in Fig. 6 (a). As the width of the ResNet20 increases, both weight and activation quantization errors decrease. The performance of ResNets when the depth of layers increases is shown in Fig. 6 (b). When the depth increases, the 2-bit weight quantized models show improved performance, but those with 2-bit quantized activations exhibit degraded performance. At least, 4-bit activation quantization is needed for deep ResNet. We also evaluate the quantization sensitivity of the MobileNetV2 [34]. The width multiplier is used to control the number of parameters of MobileNetV2. The MobileNetV2 performance on CIFAR-10 with various width-multiplication factors is shown in Fig. 7. Note that the MobileNetV2×1.0 is the same with the original model except that the first stride of 2 is replaced to 1. As the width decreases, the performances of full-precision and weight quantized models degrade gradually. However, the activation quantized models exhibit severe performance loss as the width decreases. The results indicate that DNNs with small widths are more vulnerable to the activation quantization.

QDNN Architecture Selection under the Parameter Constraint
We compare the quantization sensitivity of CNNs according to the model structure under the constraint on the number of parameters. CNNs with three different block types: basic, pre-activation, depthwise blocks are evaluated using CIFAR-10 dataset. The number of parameters of these models is approximately one million. The performance of the quantized CNNs is shown in Fig. 8. The experimented model configurations are summarized in Appendix D. When the number of parameters is comparable, increasing the depth to a certain range helps to improve the performance of full precision and weight quantized models. However, the models with 2-bit activation quantization show poor performances when the depth increases beyond certain numbers. We can also find that depthwise blocks are more robust to the activation quantization. The 2-bit CNNs with the basic or pre-activation blocks show severe performance degradation when the depth is over 32 while the performance with depthwise blocks is improves until the depth of 38. For the CIFAR-10 dataset, the best performing quantized ResNet can be designed by choosing the depth of 14 with the basic blocks or 38 with the depthwise ones.
We change the depth and width of the ResNets and evaluate the quantization performance on the ImageNet dataset [32]. Data augmentation methods and hyperparameters are the same as [20]. Pre-activation blocks are employed and the shortcut signals are quantized to 8 bits. 4-level 2-bit weight quantization is applied. The experimented ResNet structures are compared in Table 1. Since ResNets for ImageNet classification have four groups of residual blocks, which are separated by the convolution layers with the stride of 2, the number of blocks is represented as a list: [first, second, third, fourth] groups. For example, ResNet18×1.4 means that the depth is 18 with 8 number of blocks and the initial channel width is 90. The number of channels increases by a factor of 2 at every convolution layer with the stride of 2.
The performance degradation by the quantization is much lower when the model is shallow under a comparable number of parameter. However, the top-1 accuracy of 2-bit ResNet18×1.4 is 0.3% lower than the 2-bit ResNet34 because the floating-point performance is too low. When the depth, L, is 26 and the initial channel width, D init is 70, the top-1 accuracy of the floating-point model is 0.6% Table 1. Performance comparison of 2-bit ResNet on ImageNet validation set. 'L' and 'Dinit' represent the number of layers and initial channel dimension, respectively. 'B' is the stack of the residual blocks and represented separately according to the stride of 2.

Model
Top-1 Acc (%) These results indicate that the performance of QDNNs can be improved simply by designing proper depth and width of the model.

Results of Training Methods on QDNNs
We assess the effects of the training methods on QDNN optimization using the segmentation task. The effects of applying the CLR for improved generalization and adding the regularization term, L Lip , for noise robustness are summarized in Table 2. The mIOU of the floating-point pretrained model is 76.97, that of the retrained 4-bit weight is 73.63, and that of retrained 4-bit activation is 74.79. CLR is applied with a period of 3K iterations and fine-tuning was performed for 15K iterations (i.e. 5 cycles). L Lip is added to the loss after multiplying the scaling factor of 1e-4. Applying the CLR increases the mIOU of the 4-bit weight quantized model by 0.5 but it is not effective for the activation quantized model. Retraining with the regularization term that reduces the Lipschitz constant improves the mIOU of the 4-bit activation quantized model. However, the performance of the weight quantized model is decreased when L Lip is applied. The performances of QDNNs when both weights and activations are quantized are shown in Table 3. The results show that the proposed approach for reducing the quantization effects of weights by CLR and activations by adding the Lipschitz loss works well when the precision is equal to or lower than 6-bit. But these techniques are not effective when the precision of quantization is 8-bit or larger. Even, the L Lip regularization degrades the performance of the 8-bit quantized model.
We also evaluate the effects of the training methods for the classification task. The performance degradation by severe quantization can be alleviated with L Lip and CLR as shown in Table 4. L Lip is added to the loss with a factor of 1e-4 and CLR is applied for 40 epochs with the learning rates between 1e-3 and 1e-5. Although we can improve the performance of QDNN considerably for deep networks by applying CLR and L Lip constraint, the best performing QDNN can be found when the depth is 32.

Concluding remarks
We have presented a holistic approach for the optimization of quantized deep neural networks (QDNNs). We first visualize the effects of the weight and activation quantization error using a synthetic dataset. The result clearly shows that the effects of weight and activation quantization are different. Especially, activation quantization severely degrades the performance of deep models. Through additional experiments with real tasks, we confirm that the optimal model structure under a parameter constraint is different for the full-precision and quantized DNNs because floating-point models usually prefer the deep networks but QDNNs tend to show improved performances on wide networks. We also show the effects of the DNN training schemes for improved generalization and noise reduction to optimize QDNNs. The proposed holistic approach can yield much better QDNN when compared to the conventional design approaches that start from the best performing floating-point models and optimize them using elaborate quantization and training methods.  The cyclic learning rate (CLR) scheduling is shown in Fig. 11. The scale factor is multiplied to the base LR and changes 8 times in a single cycle; {1.0, √ 0.1, 0.1, 0.1 √ 0.1, 0.01, 0.1 √ 0.1, 0.1, √ 0.1 }. The cycle period and base LR for each dataset are as follows: CIFAR-10: The base LR is 1e-4, which is 10 times larger than the last LR of the retraining. The cycle period is 8 epochs, thus the LR scaling factor changes at every epoch. PASCAL VOC segmentation: The last LR of the retraining becomes 0 with the polynomial policy for this task. We set the base LR to 1e-5, which is 10 times smaller than the initial LR of the retraining. The cycle period is 3K iterations. Fig. 12. Visualization examples on the PASCAL VOC segmentation validation set. The first and second columns represent the input images and the ground truth labels. Third to fifth columns show the visualization results of the floating-point, 2-bit weight quantized, and 2-bit activation quantized models, respectively. Table 5. Quantization performance of various model structures on CIFAR-10 testset. 'L', 'Dinit', and 'B' represent the number of layers, initial channel dimension, and number of blocks, respectively.

Model
Test The details of the model structure for Fig. 8 in the main contents are shown in Table 5. The number of parameters in all the experimented models is approximately one million. All CNNs consist of three block groups. 'B' indicates the block structure; (number of blocks in each group) × (number of groups). The first block in second and third block groups have a stride of 2. D represents the channel width of the first layer and the channel width increases by 2 times at the beginning of second and third block groups. Floating-point and weight quantized networks perform better on deeper models, while shallow and wider models shows better performance when activations are quantized.