Title: LINEAR SYMMETRIC QUANTIZATION OF NEURAL NETWORKS FOR LOW-PRECISION INTEGER HARD-WARE

Abstract: With the proliferation of specialized neural network processors that operate on low-precision integers, the performance of Deep Neural Network inference becomes increasingly dependent on the result of quantization. Despite plenty of prior work on the quantization of weights or activations for neural networks, there is still a wide gap between the software quantizers and the low-precision accelerator implementation, which degrades either the efficiency of networks or that of the hardware for the lack of software and hardware coordination at designphase. In this paper, we propose a learned linear symmetric quantizer for integer neural network processors, which not only quantizes neural parameters and activations to low-bit integer but also accelerates hardware inference by using batch normalization fusion and low-precision accumulators (e.g., 16-bit) and multipliers (e.g., 4-bit). We use a unified way to quantize weights and activations, and the results outperform many previous approaches for various networks such as AlexNet, ResNet, and lightweight models like MobileNet while keeping friendly to the accelerator architecture. Additional, we also apply the method to object detection models and witness high performance and accuracy in YOLO-v2. Finally, we deploy the quantized models on our specialized integer-arithmetic-only DNN accelerator to show the effectiveness of the proposed quantizer. We show that even with linear symmetric quantization, the results can be better than asymmetric or non-linear methods in 4-bit networks. In evaluation, the proposed quantizer induces less than 0.4% accuracy drop in ResNet18, ResNet34, and AlexNet when quantizing the whole network as required by the integer processors.

1. INTRODUCTION:

Deep neural networks have shown excellent performance on various computer vision and natural language processing tasks, such as classification (Krizhevsky et al., 2012; Simonyan & Zisserman, 2015; He et al., 2016) , object detection (Girshick, 2015; Redmon et al., 2016; He et al., 2017) , segmentation (Long et al., 2015; Noh et al., 2015) , machine translation (Zhang et al., 2018b) , speech recognition (Nassif et al., 2019) , etc. While the past few years witnessed the success of DNNs on cloud and server-end computers, neural networks have been recently pushed to embedded and mobile areas to enable edge intelligence. For these scenarios, the power provision and computational strength on the edge computing devices are limited. As a result, it is essential to have more efficient network architectures and less expensive inference overhead. Therefore, there is increasing attention from the research community to study the compression of modern deep neural networks that are typically over-parameterized and computationally costly.

Several categories of approaches are proposed to decrease the computational overhead of neural networks, such as lightweight neural network architectures (Howard et al., 2017) , neural architecture search (NAS) (Elsken et al., 2018) , and network pruning (Han et al., 2015; 2016; Wen et al., 2016;  Table 1 : Comparison between different quantizers: All-Layer (AL) denotes quantizing all the parameters of all the operators in networks, including weights, bias, activations, and the scaling factor for low-precision networks; BN donates that the BN operation is only invoked in training but merged into weights and induces no overhead in integer inference; Linear-Symmetric (LS) denotes linear symmetric quantization; Activation Functions (AF) donates the support of Leaky ReLU and activation functions besides ReLU. Structure-Intact (SI) indicates the network structure is unmodified. Molchanov et al., 2017) . Besides these techniques, quantizing high-precision floating-point networks to lower bitwidth representation can also drastically decrease both the static parameters and the intermediate data generated during the network inference, resulting in reduced memory footprint and also computational intensity. And this paper focuses on the quantization of neural networks.

Quantization technique is also closely related to the implementation of specialized hardware that maps the procedure of network inference onto the energy-efficient low-precision integer or fixedpoint arithmetic circuits. In the hardware perspective, low-precision integer accelerators or processors are dominating the solutions targeted on neural network inference, especially for mobile and embedded scenarios. Google's Tensor Processing Unit 1.0 (TPU) (Jouppi et al., 2017) , Unified Deep Neural Network Accelerator (UNPU) (Lee et al., 2018) , Eyeriss (Chen et al., 2018) , Stripes (Judd et al., 2016) , Pragmatic (Albericio et al., 2017) and many other newly proposed hardware implementations are generally reliant on the effectiveness of the underlying quantization techniques, which are especially crucial for the low-precision integer hardware designed to process binary, ternary, 4-bit or 8-bit networks. In other words, quantization is not only a method to reduce the memory footprint as in traditional work, but also a mandatory step to make the network deployable on integer hardware.

Though there is a lot of prior work that investigates low-precision quantization, they mainly target on reducing the memory overhead caused by floating or high precision data representation in the networks, but not focus on specialized integer hardware for network inference. To enable the neural network processors to work with low-precision integer operands and minimize the accuracy losses, a good network quantizer must satisfy the constraints as enlisted in Table 1 .

First, all the parameters, including weights, bias, activations, partial results that eventually accumulate to an activation, and even the scaling factors, which are indispensable for low-precision networks like binary and ternary representation, must be quantized into low bitwidth integers as required by the underlying specialized hardware. In some prior work (Zhou et al., 2016; Zhu et al., 2017; Zhang et al., 2018a; Mishra et al., 2018; Choi, 2018) , they either leave bias and scaling factors unquantized or keep the first and last layer in full or high precision. Besides, some designs rely on high-precision internal register or ALUs to support high-precision partial results that are generated during computation before the final output of activations or features. For example, Krishnamoorthi (2018) , which quantizes the weights and activations to 8-bit, directly use 32-bit accumulators to cache the intermediate values or partial results to avoid overflows. However, for 4-bit and lower bitwidth, the integer accelerators cannot afford high bitwidth accumulators, which indicates higher silicon area and power cost. For integer-only-arithmetic, we quantize the bias to fixed-point numbers by using a straight-forward method. The value range of these numbers is wide, resulting in overflows of the low bitwidth accumulators. To overcome this problem, we quantize the bias to 8-bit and finetune the bias of the model. As shown in Figure 1 , the bitwidth of accumulators can be reduced to 16-bit.

Second, the BatchNorm (BN) layer does not necessarily need to be processed during inference for the reduction of computation and memory cost. For most of the convolutional neural networks, BN layers are often after the Conv or FC layers. In these situations, BN can be merged into the weights and biases of the corresponding Conv or FC layers. However, in Zhou et al. (2016) ; Zhang et al. (2018a) , they use asymmetric or non-linear quantization, causing barriers to BN fusion. There are two ways to overcome this obstacle. One is "BN folded training" (Krishnamoorthi, 2018) , which adopts BN fusion before weights quantization in every training step; the other is to use symmetric linear quantization. However, the first method doubles the training time, while the second one has no additional computational overhead, which will be introduced in Section 3.4.

Third, linear quantization is necessary for state-of-the-art accelerators. There are many non-linear quantization methods which achieve excellent bitwidth reduction efficacy and accuracy tradeoffs. In these cases, it requires additional transformation to have correct arithmetic results after quantizing the value into non-linear distribution. For example, as in Han et al. (2016) ; Park et al. (2017) , it necessitates the operation of table lookup to have correct multiplication between quantized values. However, the linear quantization can make full use of the low-precision arithmetic components in off-the-shelf accelerators. Further, linear quantization can be divided into symmetric mode and asymmetric mode. Asymmetric quantization has one more parameter (e.g., zero-point (Krishnamoorthi, 2018 )) than symmetric quantization, and it requires additional subtraction or linearoperation before multiplication. As a result, the symmetrical mode is compatible with the mainstream integer accelerator chip design and do not require the redesign of datapath in these hardware.

Fourth, different CNNs or applications usually use a variety of activation functions. For instance, the object detection model Redmon et al. (2016) typically uses Leaky ReLU. And the bottleneck of ResNet block does not use any activation function. The quantization methods are expected to be adapted to these situations. However, Zhang et al. (2018a) ; Park et al. (2017) only focus on the quantization of activations after ReLU. In this paper, we demonstrate our method is friendly to different activation methods such as Leaky ReLU.

Some of the previous researches change the network structure for better quantization performance, e.g., Mishra et al. (2018) double or even triple the convolutional filters to reduce accuracy degradation. For the energy-efficient integer neural network chips, it needs to remap the changed network architecture to hardware and adds to computational and memory access overhead due to the increased filters and parameters. As a result, keeping the network structure intact is important.

Concerning all the factors above, in this paper, we present a learned linear symmetric quantization (LLSQ) method and also evaluate it on a low-precision neural network accelerator through hardware-software co-design. Specifically, our mainly contributions are:

• Unlike most of other quantization methods, we quantize the whole network including the first and last layers. We also quantize bias and scaling factors, in support of the low bitwidth integer arithmetic units and accumulators on the accelerator.

• We adopt learned linear symmetric quantization schemes which are hardware friendly (such as the convenience of BN fusion implementation) while achieving state-of-the-art prediction accuracy.

• We design a specialized low-precision CNN inference accelerator to validate the methodology, which supports 2/4/8 integer operating and work with high efficiency. We then deploy our quantization model on the accelerator to illustrate the efficacy of the workflow.

2. MOTIVATION:

Edge or embedded neural network accelerators generally have three primary design goals-smallfootprint, high-throughput/low-latency, and low-power. For different applications and scenarios, the prior researches on specialized deep learning processors are often falling into different categories: cloud-oriented hardware for warehouse machines, low power mobile processors and ultra-low power accelerators for IoT or cyber-physical devices.

For mobile and embedded usage, specialized neural network processors are becoming increasingly popular as an efficient hardware solution of inference. DianNao (Chen et al., 2014) is proposed for fast inference of DNNs and it uses 16-bit fixed-point multipliers for small silicon area and lowenergy. Later, ShiDianNao (Du et al., 2015) is introduced and it burns extremely low energy consumption by putting all weights onto the SRAM to eliminate considerable DRAM accesses. Besides, DeepBurning (Wang et al., 2016) simplifies the design flow of accelerator for different NN models. Eyeriss (Chen et al., 2018) is also another representative of low-power accelerators. And it presents a row-stationary (RS) dataflow to minimize data movement energy consumption on a spatial architecture. To further reduce computation overhead, EIE (Han et al., 2016) exploits the sparsity and low-bit compression of the NNs and achieves better throughput, energy and area efficiency. These typical edge neural network processors are accepting fixed-point data input and using fixed-point processing elements to reduce the power and chip area overhead caused by floating-point arithmetic components and memory. For the cloud scenarios, specialized architectures like TPU (Jouppi et al., 2017) and FPGA-based accelerator cards are also replacing conventional GPGPU and CPU for highthroughput inference tasks. Even for cloud-oriented inference architectures, fixed-point processing architectures like TPU are favored because they are able to deliver much higher throughput for the given power budget and silicon area overhead.

However, for the fixed-point or integer hardware targeted on neural network acceleration, quantization is prerequisite to convert the floating-point network model into the fixed-point format compatible with the specialized hardware, and it is also a critical step to ensure the accuracy of the network after conversion. Many prior quantization methods are intended to reduce the running overhead of networks but ignore the architecture and working mechanism of integer neural network processors, as illustrated in Table 1 , and they sometimes face considerable accuracy losses, or performance penalty or even fail to be supported on the realistic integer datapath due to the unconsciousness of the underlying hardware. This problem becomes particularly important for the hardware that is designed to run low bitwidth networks such as binary, ternary, and 2/4-bit models. For instance, Deep compression and WQ are clustering-based quantization methods, and they still need high-precision values to represent the weights, bias, and activations. As a result, they are not compatible with the hardware that only supports low-precision computing. LQ-Nets uses non-linear quantization based on the binary code and basis vector, and it can theoretically calculate the inner products between quantized weights and activations by bitwise operations only. However, it requires intensive modifications to the design of current processors by adding a lot of look-up tables in the datapath. Further, bias and scaling factors are not quantized in PACT and WRPN, resulting in performance penalty when employing additional high-precision or float-point ALUs to deal with them. In contrast, our LLSQ is designed to ease the model quantization flow for the specialized integer neural network processors by conforming to the constraints specified in Table 1 . To validate the importance of hardware-aware quantizer and software/hardware co-design, we also design a specialized CNN accelerator for wearable applications. And the specialized accelerator supports 2/4/8 integer operation and adopts the dataflow of low latency and energy design.

3. NETWORKS WITH LEARNED LINEAR SYMMETRIC QUANTIZATION:

In this section, we firstly give the overview of the proposed quantization scheme. Then we detail the scheme including low-precision representation, quantized network training, and the deployment of quantization model on our specialized integer-only CNN accelerator for fast inference. propose non-linear quantization methods but lacks of a detailed description of the hardware feasibility. Krishnamoorthi (2018) provides a quantization scheme that quantizes weights and activations into 8-bit integers and integer-arithmetic-only implementation on ARM CPUs. The method achieves evident hardware acceleration effects, but does not fully exploit lower-precision quantization. Based on the researches, we propose a quantization scheme for state-of-the-art specialized accelerators operating on low-precision integers only. Figure 1 shows an overview of the proposed scheme. Compared with prior work, our proposed quantization scheme pays more attention to the constraints imposed by real hardware. We use a unified learned linear symmetric quantizer to quantize weights and activations. And the quantizer has only one parameter, known as the scaling factor. Linear symmetric quantization consumes little additional resources based on the mainstream integer accelerator designs while achieving state-of-the-art accuracy in various networks. After that, we adopt BN fusion for fast inference on hardware. As for bias and scaling factors, we also quantize them to low-bitwidth integers. The integer accelerator illustrated in Figure 1 is an illustrative case of 4-bit quantization and hardware acceleration.

K R q S F Q L r / L k C K T n x e f o U 5 6 s w = " > A A A B 7 H i c b V B N S w M x E J 3 U r 1 q / q h 6 9 B I v g q e x W Q Y / V X r w I F d y 2 0 C 4 l m 2 b b 0 G x 2 S b J C W f o b v H h Q x K s / y J v / x r T d g 7 Y + G H i 8 N 8 P M v C A R X B v H + U a F t f W N z a 3 i d m l n d 2 / / o H x 4 1 N J x q i j z a C x i 1 Q m I Z o J L 5 h l u B O s k i p E o E K w d j B s z v / 3 E l O a x f D S T h P k R G U o e c k q M l b z 7 m 0 b f 7 Z c r T t W Z A 6 8 S N y c V y N H s l 7 9 6 g 5 i m E Z O G C q J 1 1 3 U S 4 2 d E G U 4 F m 5 Z 6 q W Y J o W M y Z F 1 L J Y m Y 9 r P 5 s V N 8 Z p U B D m N l S x o 8 V 3 9 P Z C T S e h I F t j M i Z q S X v Z n 4 n 9 d N T X j t Z 1 w m q W G S L h a F q c A m x r P P 8 Y A r R o 2 Y W E K o 4 v Z W T E d E E W p s P i U b g r v 8 8 i p p 1 a r u R b X 2 c F m p 3 + Z x F O E E T u E c X L i C O t x B E z y g w O E Z X u E N S f S C 3 t H H o r W A 8 p l j + A P 0 + Q P f Q Y 4 R < / l a t e x i t > M ACMc < l a t e x i t s h a 1 _ b a s e 6 4 = " D D / z F c L W T f x W v b Y o 4 a P k O x W n y P 4 = " > A A A B 8 H i c b V B N S w M x E J 2 t X 7 V + V T 1 6 C R b B U 9 m t g h 6 r v X g p V L A f 0 i 5 L N k 3 b 0 C S 7 J F m h L P 0 V X j w o 4 t W f 4 8 1 / Y 9 r u Q V s f D D z e m 2 F m X h h z p o 3 r f j u 5 t f W N z a 3 8 d m F n d 2 / / o H h 4 1 N J R o g h t k o h H q h N i T T m T t G m Y 4 b Q T K 4 p F y G k 7 H N d m f v u J K s 0 i + W A m M f U F H k o 2 Y A Q b K z 3 W b 2 p B W g / I N C i W 3 L I 7 B 1 o l X k Z K k K E R F L 9 6 / Y g k g k p D O N a 6 6 7 m x 8 V O s D C O c T g u 9 R N M Y k z E e 0 q 6 l E g u q / X R + 8 B S d W a W P B p G y J Q 2 a q 7 8 n U i y 0 n o j Q d g p s R n r Z m 4 n / e d 3 E D K 7 9 l M k 4 M V S S x a J B w p G J 0 O x 7 1 G e K E s M n l m C i m L 0 V k R F W m B i b U c G G 4 C 2 / v E p a l b J 3 U a 7 c X 5 a q t 1 k c e T i B U z g H D 6 6 g C n f Q g C Y Q E P A M r / D m K O f F e X c

3.2. MAKING FULL USE OF THE PRE-TRAINED PARAMETERS:

In experiments, we find that it is more efficient to start with the pre-trained full-precision parameters before quantization. Louizos et al. (2019) ; Zhou et al. (2017) use pre-trained weights for fast convergence and deployment, while Zhang et al. (2018a) ; Choi (2018) ; Cai et al. (2017) train quantized network from scratch to show the robustness of the algorithm. However, for some object detection models, the backbone models and pre-trained weights are essential to the detection performance. Redmon et al. (2016) shows that the pre-trained high-resolution classification network gives an increase of almost 4% mAP. To have better performance in classification, object detection, and other CNN based tasks, in this paper, we use pre-trained parameters to initialize the networks.

3.3. LOW-PRECISION REPRESENTATION AND QUANTIZATION ALGORITHM:

We use channel-wise quantization for Conv layers and layer-wise quantization for FC layers and activations. And we adopt the symmetric linear quantization to quantize weights or activations into k bits words(e.g., 4-bit), which can be defined as

EQUATION

where x r ∈ R is one kernel of weights or one layer of activations, the variable α ∈ R + is the quantization parameter, known as the scaling factor, while q ∈ {-2 k-1 , . . . , 0, 1, . . . , 2 k-1 -1} is the integer values flowing in the integer accelerator and x q ∈ {-2 k-1 α, . . . , 0, α, . . . , (2 k-1 -1)α} is the quantized weights or activations. Note that for activations, which are non-negative values if the ActFun is ReLU, we clamp them to [0, 2 k -1], resulting in q ∈ {0, 1, . . . , 2 k -1} and x q ∈ {0, α, . . . , (2 k-1 -1)α}, respectively.

As defined above, we use α as our quantization parameter. And we optimize it with: where x r , x q are the same factors defined in Equation 1, p(x r ) is the probability density distribution of x r , and l ∈ {1, 2} is an optional constraint (We use 2 in our experiments). In Figure 2 , we present the relationship between quantization error and α. When fixing weights x r , we can find the optimal α * by using the brute-force search approach, which induces high computation cost. Besides, the weights are updated during the re-training phase and the optimal value α * changes accordingly. In other words, the optimal value for the factors is not fixed and it takes considerable computational overhead to find the dynamic optimal value. Inspired by Zhang et al. (2018a) , we find through experiments that there is no need to find the optimal value α * , and it works well enough to find a near-optimal value α * . Generally, quantization can be considered as a regularization of the networks, and the quantization parameter α needs only to be adjusted to a near-optimal value to preserve the network capacity.

α * = arg min α p(x r )|x q -x r | l (2)

1/↵ < l a t e x i t s h a 1 _ b a s e 6 4 = " V + z 9 u W T q M 4 Y p / m s Q i c Q U 0 l 6 T e X g = " > A A A B 7 3 i c b V B N S 8 N A E J 3 U r 1 q / q h 6 9 h B Z B E G p S D 3 o s e v F Y w X 5 A E 8 p k u 2 2 X b j Z x d y O E 0 D 8 h g g d F v P p 3 v P X f u P 0 4 a O u D g c d 7 M 8 z M C 2 L O l H a c i Z V b W 9 / Y 3 M p v F 3 Z 2 9 / Y P i o d H T R U l k t A G i X g k 2 w E q y p m g D c 0 0 p + 1 Y U g w D T l v B 6 H b q t 5 6 o V C w S D z q N q R / i Q L A + I 6 i N 1 H Y v P O T x E L v F s l N x Z r B X i b s g 5 V r J O 3 + Z 1 N J 6 t / j t 9 S K S h F R o w l G p j u v E 2 s 9 Q a k Y 4 H R e 8 R N E Y y Q g H t G O o w J A q P 5 v d O 7 Z P j d K z + 5 E 0 J b Q 9 U 3 9 P Z B g q l Y a B 6 Q x R D 9 W y N x X / 8 z q J 7 l / 7 G R N x o q k g 8 0 X 9 h N s 6 s q f P 2 z 0 m K d E 8 N Q S J Z O Z W m w x R I t E m o o I J w V 1 + e Z U 0 q x X 3 s l K 9 N 2 n c w B x 5 O I E S n I E L V 1 C D O 6 h D A w h w e I Y 3 e L c e r V f r w / q c t + a s x c w x / I H 1 9 Q O F V p K b < / l a t e x i t > 1 ↵ ⇤ < l a t e x i t s h a 1 _ b a s e 6 4 = " / / D o C o j G 0 R u 9 M R X M P c M n J e t 6 z V I = " > A A A C A X i c b V C 7 S g N B F J 3 1 G e N r 1 U L F Z j A I Y h F 2 Y 2 H K o B a W E c w D s j H c n c w m Q 2 Y f z M w K Y V k b f 8 X G Q h F b f 0 L s t L H 1 M 5 w 8 C k 0 8 c O F w z r 3 c e 4 8 b c S a V Z X 0 Y M 7 N z 8 w u L m a X s 8 s r q 2 r q 5 s V m V Y S w I r Z C Q h 6 L u g q S c B b S i m O K 0 H g k K v s t p z e 2 d D f z a D R W S h c G V 6 k e 0 6 U M n Y B 4 j o L T U M n e c c 8 o V O J 4 A k t h p 4 g C P u n B 9 l L b M n J W 3 h s D T x B 6 T X K n 4 9 b b 9 + b 1 b b p n v T j s k s U 8 D R T h I 2 b C t S D U T E I o R T t O s E 0 s a A e l B h z Y 0 D c C n s p k M P 0 j x g V b a 2 A u F r k D h o f p 7 I g F f y r 7 v 6 k 4 f V F d O e g P x P 6 8 R K 6 / Y T F g Q x Y o G Z L T I i z l W I R 7 E g d t M U K J 4 X x M g g u l b M e m C D k P p 0 L I 6 B H v y 5 W l S L e T t 4 3 z h U q d x i k b I o D 2 0 j w 6 R j U 5 Q C V 2 g M q o g g m 7 R P X p E T 8 a d 8 W A 8 G y + j 1 h l j P L O F / s B 4 / Q H 9 P Z r 9 < / l a t e x i t >

Then the problem becomes how to find a α * in the forward pass of the network training phase. At the beginning of training, we assign α an initial value. Then in every training iteration, we explore between 2α and α/2 to find a better search direction d better ∈ {-1, 0, 1}, and use -α 2 d better as the simulated gradient (SG) of α which is detailed in Equation 9. The gradients of other parameters are still obtained by backpropagation algorithm. After that, we update all parameters with the gradients or simulated gradients. Another method is updating α by the exponential moving average (EMA). We experiment both of the methods, and the results show that SG is generally better than EMA on various networks (See Table 2 ). If not specifically stated, we use the SG method in experiments. The re-training process with weights and activations quantized is summarized in Step 1 of Algorithm 1.

3.4. BN LAYER FUSION OF QUANTIZED NETWORKS:

As described in Section 1, merging the BN layers into convolutional layers can reduce the latency of network inference by removing additional computation overhead. The operator of quantized Conv1 and FC layers can be expressed as o = α a q a α w q w + b (3)

where α, q are the same as Equation 1, α a q a , α w q w donate the quantized activations and weights, while b is the bias and o is the output feature vector. Note that α a , α w and b are full precision values. And the BN layer can be formulated as follows:

y = o -µ √ σ 2 + γ + β (4)

where µ and σ 2 are EMA statistics, γ and β are learned parameters in BN layers.

Obviously, we can merge BN layers and figure out the corrected parameters:

αw = ζα w ; b = (b -µ)ζ + β; ζ = γ √ σ 2 + (5)

3.5. BIAS AND SCALING FACTOR QUANTIZATION FOR LOW-BIT INTEGER ONLY ARITHMETIC:

Further, the outputs of layers are quantized according to Equation 1. For integer-only-arithmetic, the bias use α a α w as its scaling factor. And for the multiplier αaαw αo , we use bit-shift quantization (See Equation 10) so that no multiplication but bit-shift operation is needed in hardware.

α o q o = α a q a αw q w + b q o = α a αw α o (q a q w + q b )

where

EQUATION

Note that α a α w is a very small number, resulting in large quantization noise when adopting the clamp operation. In addition, the quantization of the scaling factors α can also raise the quantization noise of weights and activations. Parameter re-training summarized in Step 2 of Algorithm 1 is required.

In the re-training phase, we adopt STE (Bengio et al., 2013) to realize the non-differentiable quantization function.

For weights and bias, we have ∂y ∂w q ∂y ∂w r ; ∂y ∂b q ∂y ∂b r (7)

For activations, we have

∂y ∂a q ∂y ∂a r if 0 ≤ a r ≤ (2 k -1)α 0 otherwise (8)

4. EXPERIMENTAL RESULTS:

In this section, three sets of experiments on Cifar10, ImageNet and Pascal VOC datasets are presented. First, we conduct our proposed learned linear symmetric quantization (LLSQ) on weights and activations, leaving the first and last layers in full precision for a fair comparison with Zhang et al. (2018a) . Second, we quantize the whole networks including the first and last layers, which is referred as LLSQF (LLSQ for Full network). Finally, we quantize the remaining bias and scaling factors. LLSQ is implemented in PyTorch (Paszke et al., 2017) , and most of the baselines it uses in evaluation are from PyTorch Model Zoo2 .

4.1. QUANTIZATION OF WEIGHTS AND ACTIVATIONS:

We firstly employ the VGG-Small network on Cifar10 to verify the LLSQ method. After that, we use AlexNet (Krizhevsky et al., 2012 ), ResNet18, ResNet34 (He et al., 2016) , particularly the lightweight and hard-to-compress network architecture of MobileNet (Howard et al., 2017; Sandler et al., 2018) etc. to conduct more detailed experiments on the ImageNet dataset. Finally, we also quantize YOLOv2 (Redmon & Farhadi, 2017) to demonstrate that LLSQ also works well for complicated applications and especially the task adopting the activation functions like Leaky ReLU other than ReLU used in previous work.

VGG-SMALL ON CIFAR10:

The VGG-Small architecture is the same with Louizos et al. (2019) ; Zhang et al. (2018a) , consisting of six Conv layers, three MaxPool layers, and one FC layer. We adopt a cosine learn rate scheduler to train the VGG-Small reference and the quantized models. Specifically, we train the reference network for 400 epochs using an initial learning rate of 2e-2. And for the training of the quantized network, we use a warmup learning rate scheduler in the first ten epochs with an initial learning rate of 2e-3. In all quantization experiments, the total training epochs are 100. The VGG-Small quantization results are provided in Table 3 . With 3-bit weights and 3-bit activations, the accuracy * first and last layer in full precision using our method is better than state-of-the-art method, LQ-Nets. And even when the first and last layers are all quantized in the same way, the loss of accuracy is minimal.

IMAGENET DATASET:

We then quantize AlexNet, ResNet18, ResNet34 and MobileNetv2 on ILSVRC2012 dataset with different bitwidth configuration to demonstrate the effectiveness of the method. All of the pretrained float-point weights except MobileNetv23 are downloaded from the PyTorch Model Zoo, and they are trained for 90 epochs with a step learning rate scheduler. After loading the pre-trained weights, we employ a warmup learning scheduler in the first three epochs and the cosine scheduler in the remained 57 epochs with an initial learning rate of 2e-2.

As shown in Figure 3a , when quantizing both weights and activations, our degradation of accuracy is significantly smaller than LQ-Nets, PACT, and RQ. Especially, LLSQ outperforms the baselines when quantizing weights and activations into 4-bit. And it also outperforms other non-linear quantization methods with different bitwidth. Figure 3b shows that even with the first and last layers quantized, it can still achieve near baseline performance. In overall, the accuracy drop is less than 0.4% in ResNet18, ResNet34, and AlexNet when quantizing the whole network. We also quantize MobileNetv2, a more compact network, and obtain results that are significantly better than RQ.

Please check Table 7 for detailed results.

OBJECT DETECTION ON PASCAL VOC:

We also apply the proposed LLSQ to YOLOv2. The backbone of YOLOv2 is Darknet-19, and its activation function is Leaky ReLU, so that the activations contain negative values. For YOLOv2 on Pascal VOC, we adopt the same quantization configuration (See Section 3.3) of the weights to the activations. Results are listed in Table 4 . As shown in the table, LLSQ induces minor losses of mAP in different bitwidth presentation. For comparison, we also quantize the activations into signed 5-bit integers using PACT, and consequently face considerable mAP losses (54.8mAP). Please note that we use the open-source PyTorch implementation of YOLOv24 as the baseline. We train the quantized model for 170 epochs (2/3 of baseline) with an initial learning rate of 1e-4 (1/10 of baseline). We adopt BN fusion in the PostAct (Conv¡BN¡ReLU) networks according to the formula in Section 3.4. And the scaling factor of bias is the product of the corresponding scaling factors belonging to the activations and the weights, respectively. After that, we visualize the bias value distribution of VGG-Small. Figure 4 shows b/α b is distributed between a vast range (-1000, 1000), resulting in overflows of low bitwidth accumulators. And the overflow phenomena have a significantly harmful impact on the network performance. To deal with this issue, we quantize the bias and the scaling factors to 8-bit words, and then fine-tune the networks to restore the original performance. Generally, we need fine-tuning for one epoch only. After the quantization of bias and scaling factor, we have a fully quantized model and have it deployed onto our integer-only accelerator with 16 bitwidth accumulators. Table 3 and 7 show that the accuracy loss is negligible with w4a4b8α8 quantization on both VGG-Small and AlexNet. 

L u V Z a C o 0 = " > A A A B 8 X i c b V B N S 8 N A E J 3 U r 1 q / q h 6 9 h B Z B E G p S D 3 o s e v F Y w X 5 g E 8 p k u 2 2 X b j Z h d y O E 0 H / R i w d F v P p v v P X f u P 0 4 a O u D g c d 7 M 8 z M C 2 L O l H a c q Z X b 2 N z a 3 s n v F v b 2 D w 6 P i s c n T R U l k t A G i X g k 2 w E q y p m g D c 0 0 p + 1 Y U g w D T l v B 6 H 7 m t 1 6 o V C w S T z q N q R / i Q L A + I 6 i N 9 B x c e c j j I X a D b r H s V J w 5 7 H X i L k m 5 V v I u J 9 N a W u 8 W v 7 1 e R J K Q C k 0 4 K t V x n V j 7 G U r N C K f j g p c o G i M Z 4 Y B 2 D B U Y U u V n 8 4 v H 9 r l R e n Y / k q a E t u f q 7 4 k M Q 6 X S M D C d I e q h W v V m 4 n 9 e J 9 H 9 W z 9 j I k 4 0 F W S x q J 9 w W 0 f 2 7 H 2 7 x y Q l m q e G I J H M 3 G q T I U o k 2 o R U M C G 4 q y + v k 2 a 1 4 l 5 X q o 8 m j T t Y I A 9 n U I I L c O E G a v A A d W g A A Q E T e I N 3 S 1 m v 1 o f 1 u W j N W c u Z U / g D 6 + s H R b 6 T o Q = = <

L u V Z a C o 0 = " > A A A B 8 X i c b V B N S 8 N A E J 3 U r 1 q / q h 6 9 h B Z B E G p S D 3 o s e v F Y w X 5 g E 8 p k u 2 2 X b j Z h d y O E 0 H / R i w d F v P p v v P X f u P 0 4 a O u D g c d 7 M 8 z M C 2 L O l H a c q Z X b 2 N z a 3 s n v F v b 2 D w 6 P i s c n T R U l k t A G i X g k 2 w E q y p m g D c 0 0 p + 1 Y U g w D T l v B 6 H 7 m t 1 6 o V C w S T z q N q R / i Q L A + I 6 i N 9 B x c e c j j I X a D b r H s V J w 5 7 H X i L k m 5 V v I u J 9 N a W u 8 W v 7 1 e R J K Q C k 0 4 K t V x n V j 7 G U r N C K f j g p c o G i M Z 4 Y B 2 D B U Y U u V n 8 4 v H 9 r l R e n Y / k q a E t u f q 7 4 k M Q 6 X S M D C d I e q h W v V m 4 n 9 e J 9 H 9 W z 9 j I k 4 0 F W S x q J 9 w W 0 f 2 7 H 2 7 x y Q l m q e G I J H M 3 G q T I U o k 2 o R U M C G 4 q y + v k 2 a 1 4 l 5 X q o 8 m j T t Y I A 9 n U I I L c O E G a v A A d W g A A Q E T e I N 3 S 1 m v 1 o f 1 u W j N W c u Z U / g D 6 + s H R b 6 T o Q = = < / l a t e x i t > density (b) bias of conv2

Figure 4 : Distribution of the bias/scaling factor. The data is from VGG-Small with w4a4 quantization.

4.3. DEPLOYMENT ONTO REALISTIC HARDWARE:

The introduced linear symmetric quantization is intended to deploy the quantized networks to specialized integer-only-arithmetic CNN accelerators or other integer-only hardware. Our accelerators adopt the typical 2D systolic array architecture (Chen et al., 2018) , but they are featured with 4-bit or 2-bit low-precision operation. As shown in Figure 1 , the 8/4/2-bit accelerator has a 32x7 array of 5 shows that the 4/2-bit implementation achieves up to 2.56x lower silicon area and 5.56x lower power compared to that of the 8-bit baseline.

5. CONCLUSIONS:

In this paper, we introduced a learned linear symmetric quantization (LLSQ) to quantize the whole network including the bias and scaling factors. We also use BN fusion and low bitwidth accumulators to reduce the network inference overhead and the hardware resources in integer neural accelerators. We show that our proposed method performs well for various networks on Cifar10, ImageNet, and Pascal VOC datasets. We also show that even the linear symmetric quantizer can obtain better results than asymmetric or non-linear quantization in the case of 4-bit networks. Finally, we deploy the quantized network onto our specialized integer-only neural network accelerator. Currently, the bitwidth of every layer in a network is all the same. Prior researches empirically find that different layers have different sensitivity to bitwidth of quantization. Hence in the future, we will explore a framework to support more flexible bitwidth for different layers or finer-grained quantization. 

:

For brevity, we only consider the operation of one channel.

https://pytorch.org/docs/stable/torchvision/models.html

https://github.com/tonylins/pytorch-mobilenet-v2

https://github.com/marvis/pytorch-yolo2

Figures and Tables:

OVERVIEW OF LLSQ Many of the previous researches focus on the quantization-aware training in GPU, showing the potential of low-bit quantization on CNNs. Han et al. (2016); Park et al. (2017); Zhang et al. (2018a)

t e x i t s h a 1 _ b a s e 6 4 = " S M Q

Figure 1: An overview of LLSQ: using pre-trained weights for fast convergence; Retraining of the network with quantized weights and activations; BN fusion for efficient inference; Quantization of bias and scaling factors; Deployment of the quantized model to our accelerator. As shown in this figure, weights, activations, bias, and scaling factors are quantized to low-bit integers. And the bandwidth of accumulator can be set to lower (e.g., 16-bit in our experiments).

Figure 2: L2 distance of quantization. The data is from weights of the first FC layer in AlexNet. As shown in the figure, the optimal α * changes with the updating of weights.

Comparison of LLSQ and LLSQF. LLSQ outperforms the baseline, and LLSQF receives only minor performance penalty after quantizing the first and the last layers.

Figure 3: Quantization results on different networks.

t e x i t s h a 1 _ b a s e 6 4 = " Z / v b Q e D e k 9 N e E Y 0 C 6 9 q

t e x i t s h a 1 _ b a s e 6 4 = " Z / v b Q e D e k 9 N e E Y 0 C 6 9 q

Figure 5: Test curves for AlexNet, ResNet18, and ResNet34 on ImageNet.

Comparison of SG and EMA.

Table content: <table><tr><td colspan="2">Method VGGSmallw4a4</td><td>VGGSmallw2a2</td><td>ResNet18w4a4</td><td>ResNet18w3a3</td></tr><tr><td>EMA</td><td>93.95</td><td>92.78</td><td>69.48</td><td>66.80</td></tr><tr><td>SG</td><td>94.34</td><td>93.31</td><td>69.84</td><td>68.08</td></tr><tr><td colspan="4">VGGSmall is trained on Cifar10 and ResNet18 is on ImageNet.</td><td/></tr></table>

Comparison with the state-of-the-art low-bit quantization methods on CIFAR-10. The bitwidth for weights(w), activations(a), bias(b) and scaling factor(α) are given.

Table content: <table><tr><td>Method</td><td># Bits w/a/b/α</td><td>Acc(%)</td><td>Degradation(%)</td></tr><tr><td>LQ-Nets *</td><td>Reference</td><td>93.8</td><td/></tr><tr><td>(Zhang et al., 2018a)</td><td>3/3</td><td>93.8</td><td>0.0</td></tr><tr><td/><td>2/2</td><td>93.5</td><td>0.3</td></tr><tr><td>RQ</td><td>Reference</td><td>93.05</td><td/></tr><tr><td>(Louizos et al., 2019)</td><td>8/8</td><td>93.30</td><td>-0.25</td></tr><tr><td/><td>4/4</td><td>91.57</td><td>1.48</td></tr><tr><td/><td>2/2</td><td>90.92</td><td>2.31</td></tr><tr><td>LLSQ * (ours)</td><td>Reference</td><td>93.34</td><td/></tr><tr><td/><td>4/4</td><td>94.34</td><td>-1.00</td></tr><tr><td/><td>3/3</td><td>94.02</td><td>-0.68</td></tr><tr><td/><td>2/2</td><td>93.31</td><td>0.03</td></tr><tr><td>LLSQF(ours)</td><td>4/4</td><td>94.30</td><td>-0.96</td></tr><tr><td/><td>3/3</td><td>94.07</td><td>-0.73</td></tr><tr><td/><td>2/2</td><td>93.12</td><td>0.22</td></tr><tr><td/><td>4/4/8/8</td><td>93.84</td><td>-0.50</td></tr></table>

LLSQ on YOLOv2 detector. BN FUSION AND QUANTIZATION OF BIAS AND THE SCALING FACTOR

Table content: <table><tr><td colspan="3">bitwidth mAP aero bike bird boat bottle bus</td><td>car</td><td>cat</td><td>chair cow table dog horse mbike person plant sheep sofa train tv</td></tr><tr><td>FP32</td><td>73.2</td><td colspan="3">78.9 80.0 72.8 62.3 47.1 79.2 79.6 85.7 54.4 79.7 72.2 83.3 81.1 79.2 74.8 48.4 75.7 72.3 83.4 73.0</td></tr><tr><td>w4a5</td><td>70.3</td><td colspan="3">73.9 76.1 67.8 57.3 39.9 81.2 79.1 82.6 51.8 75.7 68.3 80.3 83.9 78.7 70.6 42.6 72.2 71.6 83.5 69.5</td></tr><tr><td>w32a5</td><td>71.2</td><td colspan="3">75.5 75.9 71.4 60.4 42.4 80.6 80.0 83.3 53.5 75.8 68.1 70.8 82.6 79.5 71.6 45.5 69.9 72.1 84.6 70.4</td></tr><tr><td>w4a8</td><td>73.4</td><td colspan="3">74.5 79.1 75.5 60.6 43.8 80.9 80.7 85.8 56.6 80.0 70.9 83.5 84.5 81.0 74.5 47.5 74.8 75.2 84.1 73.6</td></tr><tr><td>w4a32</td><td>74.2</td><td colspan="3">74.6 78.6 75.5 66.0 47.4 80.8 83.2 87.4 57.3 80.3 70.8 83.7 84.3 83.0 74.8 49.4 74.2 73.8 85.2 73.5</td></tr><tr><td>4.2</td><td/><td/><td/></tr></table>

Comparison of our low-precision integer Neural Network Processors. And the MAC unit in each PE consists of a 4-bit multiplier and a 16-bit accumulator. For the 4-bit accelerator, we use INT4 representation for weights, UINT4 for activations, INT8 for the bias and scaling factors, respectively. For the 2-bit accelerator, we use INT2 for weights, UINT2 for activations, INT8 for the bias and scaling factors, respectively. Through the quantization process described in the paper, we can have a fully quantized network that works directly on the CNN accelerator. In addition, as we use linear symmetric quantization, we can use a straight-forward way to conduct multiply-accumulate operations without introducing shifters or lookup tables, which means the quantized models can run on state-of-the-art integer accelerators and ensures that their output accuracy degradation is minimal as presented in the above sections. Finally, we implement the 8/4/2-bit integer neural network processors with Synopsys Design Compiler (DC) under the 40nm technology, clocked at 800MHz. Table

Table content: <table><tr><td colspan="2">Bitwidth #MAC Unit</td><td>Throughput (GOps/sec)</td><td>Silicon Area (mm 2 )</td><td>Power (mW)</td></tr><tr><td>8-bit</td><td>224</td><td>179.2</td><td>4.71</td><td>228</td></tr><tr><td>4-bit</td><td>224</td><td>179.2</td><td>2.80</td><td>93</td></tr><tr><td>2-bit</td><td>224</td><td>179.2</td><td>1.84</td><td>41</td></tr><tr><td colspan="5">Implemented and synthesized with Synopsys Design Compiler (DC) under the 40nm technology.</td></tr><tr><td colspan="2">processing elements (PE).</td><td/><td/><td/></tr></table>

Train Time of ResNet18 Conv layers, three FC layers, three MaxPool layers, and two Dropout layers. To prevent over-fitting, we keep the Dropout layers when quantizing AlexNet. As shown in Figure5d, we use the same learning rate scheduler for all experiments on ImageNet. The test curves are also shown in Figure5. As we begin with the pre-trained full-precision weights, the test accuracy is already acceptable after one-epoch training. The final results are listed in Table7.Training time. The proposed LLSQ requires about 2/3 training epochs than that of floating-point network training. In each training iteration, LLSQ needs extra computation cost to optimize the quantizers. Specifically, the simulated gradients generation of the scaling factors is the major cost. Table 6 shows the total training time comparison of ResNet18 network. The quantization training time is 70% of baseline only.

Table content: <table><tr><td>#Training Process</td><td>training time</td></tr><tr><td>Train the fp32 network from scratch</td><td>1.0x</td></tr><tr><td>Quantize w/a to 4/4 according to Step1 of Alg. 1</td><td>0.69x</td></tr><tr><td>Quantize w/a to 3/3 according to Step1 of Alg. 1</td><td>0.69x</td></tr><tr><td>Quantize b/α to 8/8 according to Step2 of Alg. 1</td><td>0.01x</td></tr><tr><td>and it consists of five</td><td/></tr></table>

Comparison with state-of-the-art quantization methods on ImageNet. Top1, Top5 accuracy(%) and degradation of Top1 are given.

Table content: <table><tr><td>Method</td><td>Model</td><td># Bits</td><td colspan="3">Top1(%) Top5(%) Degradation(%)</td></tr><tr><td/><td/><td>w/a/b/α</td><td/><td/><td/></tr><tr><td>LQ-Nets *</td><td>ResNet18</td><td>Reference</td><td>70.3</td><td>89.5</td><td/></tr><tr><td>(Zhang et al., 2018a)</td><td/><td>4/4</td><td>69.3</td><td>88.8</td><td>1.0</td></tr><tr><td/><td/><td>3/3</td><td>68.2</td><td>87.9</td><td>2.1</td></tr><tr><td>RQ</td><td>ResNet18</td><td>Reference</td><td>69.54</td><td>89.19</td><td/></tr><tr><td>(Louizos et al., 2019)</td><td/><td>8/8</td><td>69.97</td><td>89.44</td><td>-0.43</td></tr><tr><td/><td/><td>4/4</td><td>61.52</td><td>83.99</td><td>8.02</td></tr><tr><td>RQ+ST</td><td/><td>8/8</td><td>69.63</td><td>89.33</td><td>-0.09</td></tr><tr><td>(Louizos et al., 2019)</td><td/><td>4/4</td><td>62.46</td><td>84.78</td><td>7.08</td></tr><tr><td>LLSQ(ours) *</td><td>ResNet18</td><td>Reference</td><td>69.76</td><td>89.08</td><td/></tr><tr><td/><td/><td>4/4</td><td>69.84</td><td>89.14</td><td>-0.08</td></tr><tr><td/><td/><td>3/3</td><td>68.08</td><td>88.20</td><td>1.68</td></tr><tr><td>LLSQF(ours)</td><td>ResNet18</td><td>4/4</td><td>69.40</td><td>88.72</td><td>0.36</td></tr><tr><td/><td/><td>3/3</td><td>66.67</td><td>87.42</td><td>3.09</td></tr><tr><td>LQ-Nets *</td><td>ResNet34</td><td>Reference</td><td>73.80</td><td>91.40</td><td/></tr><tr><td>(Zhang et al., 2018a)</td><td/><td>3/3</td><td>71.9</td><td>90.2</td><td>1.9</td></tr><tr><td>LLSQ(ours) *</td><td>ResNet34</td><td>Reference</td><td>73.30</td><td>91.42</td><td/></tr><tr><td/><td/><td>4/4</td><td>73.60</td><td>91.28</td><td>-0.30</td></tr><tr><td/><td/><td>3/3</td><td>72.02</td><td>90.66</td><td>1.28</td></tr><tr><td>LLSQF(ours)</td><td>ResNet34</td><td>4/4</td><td>72.94</td><td>91.20</td><td>0.36</td></tr><tr><td/><td/><td>3/3</td><td>70.97</td><td>89.95</td><td>2.33</td></tr><tr><td>LLSQ(ours) *</td><td>AlexNet</td><td>Reference</td><td>56.55</td><td>79.09</td><td/></tr><tr><td/><td/><td>4/4</td><td>56.57</td><td>79.02</td><td>-0.02</td></tr><tr><td/><td/><td>4/4/8/8</td><td>56.45</td><td>80.15</td><td>0.10</td></tr><tr><td/><td/><td>3/3</td><td>55.36</td><td>78.20</td><td>0.19</td></tr><tr><td>LLSQF(ours)</td><td>AlexNet</td><td>4/4</td><td>56.40</td><td>78.85</td><td>0.15</td></tr><tr><td/><td/><td>4/4/8/8</td><td>55.58</td><td>77.47</td><td>0.97</td></tr><tr><td/><td/><td>3/3</td><td>54.28</td><td>77.65</td><td>2.27</td></tr><tr><td>RQ</td><td>Mobilenet(v1)</td><td>Reference</td><td>70.61</td><td>89.47</td><td/></tr><tr><td>(Louizos et al., 2019)</td><td/><td>8/8</td><td>70.43</td><td>89.42</td><td>0.18</td></tr><tr><td/><td/><td>6/6</td><td>68.02</td><td>88.00</td><td>2.59</td></tr><tr><td/><td/><td>5/5</td><td>61.38</td><td>83.73</td><td>9.23</td></tr><tr><td>RQ+ST</td><td>Mobilenet(v1)</td><td>8/8</td><td>70.06</td><td>89.52</td><td>0.55</td></tr><tr><td>(Louizos et al., 2019)</td><td/><td>6/6</td><td>67.62</td><td>87.78</td><td>2.99</td></tr><tr><td/><td/><td>5/5</td><td>56.85</td><td>80.35</td><td>13.76</td></tr><tr><td>LLSQ(ours) *</td><td colspan="2">MobileNet(v2) Reference</td><td>71.80</td><td>90.37</td><td/></tr><tr><td/><td/><td>6/6</td><td>71.20</td><td>89.99</td><td>0.60</td></tr><tr><td/><td/><td>5/5</td><td>70.45</td><td>89.69</td><td>1.35</td></tr><tr><td/><td/><td>4/4</td><td>67.37</td><td>87.99</td><td>4.43</td></tr></table>

Peer review (iclr2020):
The submission proposes to train a linear symmetric quantizing function for integer processors. The proposed idea makes sense at a high level, and the empirical results look somewhat compelling, but the write-up is not particularly clear (see clarity-related comments). I found it hard to extract a complete picture of how the proposed approach operates: from the leftmost diagram in Figure 1 I can infer what high-level steps are involved, but I wouldn’t know how to re-implement the approach from the textual description itself. Clarity-related comments: - The submission never explicitly states what x^r and p(x^r) correspond to in the network. My understanding from the context is that x^r is the scalar value of a model parameter or activation, and that p(x^r) is the empirical distribution over all model parameters and activations. Can the authors clarify? - Some kind of pseudo-code for the re-training of the weights and activations (Section 3.3) would help clear up reader confusion. At this point, are only the weights and activations quantized in the network? How is backpropagation handled (and if the straight-through estimator is used, why is it only mentioned in Section 3.5)? How do parameter and alpha updates interleave? - How many alpha values are there? Section 3.3 gives the impression that there is a single quantization parameter shared by all parameters and activations, but Equation 3 uses different alpha values for the weights and activations. - Section 3.4 is difficult to parse due to bad notation. If the output of the convolution layer is fed into the batch normalization layer, it would be clearer to reuse symbols (i.e. change “x” to “o” in Equation 4). Additional comments: - Organization of the different sections could be improved. Related work discussion is scattered throughout three different sections, namely Introduction, Motivation, and Related Work. - Writing quality could be improved (e.g., “*Except that*, some designs rely [...]”, “Edge or embedded neural network accelerators *are generally having* three primary design goals [...]”) but has a relatively small negative impact on readability.