Hybrid and Non-Uniform DNN quantization methods using Retro Synthesis data for efficient inference

1 INTRODUCTION . Quantization is a widely used and necessary approach to convert heavy Deep Neural Network ( DNN ) models in Floating Point ( FP32 ) format to a light-weight lower precision format , compatible with edge device inference . The introduction of lower precision computing hardware like Qualcomm Hexagon DSP ( Codrescu , 2015 ) resulted in various quantization methods ( Morgan et al. , 1991 ; Rastegari et al. , 2016 ; Wu et al. , 2016 ; Zhou et al. , 2017 ; Li et al. , 2019 ; Dong et al. , 2019 ; Krishnamoorthi , 2018 ) compatible for edge devices . Quantizing a FP32 DNN to INT8 or lower precision results in model size reduction by at least 4X based on the precision opted for . Also , since the computations happen in lower precision , it implicitly results in faster inference time and lesser power consumption . The above benefits with quantization come with a caveat of accuracy loss , due to noise introduced in the model ’ s weights and activations . In order to reduce this accuracy loss , quantization aware fine-tuning methods are introduced ( Zhu et al. , 2016 ; Zhang et al. , 2018 ; Choukroun et al. , 2019 ; Jacob et al. , 2018 ; Baskin et al. , 2019 ; Courbariaux et al. , 2015 ) , wherein the FP32 model is trained along with quantizers and quantized weights . The major disadvantages of these methods are , they are computationally intensive and time-consuming since they involve the whole training process . To address this , various post-training quantization methods ( Morgan et al. , 1991 ; Wu et al. , 2016 ; Li et al. , 2019 ; Banner et al. , 2019 ) are developed that resulted in trivial to heavy accuracy loss when evaluated on different DNNs . Also , to determine the quantized model ’ s weight and activation ranges most of these methods require access to training data , which may not be always available in case of applications with security and privacy constraints which involve card details , health records , and personal images . Contemporary research in post-training quantization ( Nagel et al. , 2019 ; Cai et al. , 2020 ) eliminated the need for training data for quantization by estimating the quantization parameters from the Batch-Normalization ( BN ) layer statistics of the FP32 model but fail to produce better accuracy when BN layers are not present in the model . To address the above mentioned shortcomings , this paper proposes a data-independent post-training quantization method that estimates the quantization ranges by leveraging on ‘ retro-synthesis ’ data generated from the original FP32 model . This method resulted in better accuracy as compared to both data-independent and data-dependent state-of-the-art quantization methods on models ResNet18 , ResNet50 ( He et al. , 2016 ) , MobileNetV2 ( Sandler et al. , 2018 ) , AlexNet ( Krizhevsky et al. , 2012 ) and ISONet ( Qi et al. , 2020 ) on ImageNet dataset ( Deng et al. , 2009 ) . It also outperformed state-of-the-art methods even for lower precision such as 6 and 4 bit on ImageNet and CIFAR-10 datasets . The ‘ retro-synthesis ’ data generation takes only 10 to 12 sec of time to generate the entire dataset which is a minimal overhead as compared to the benefit of data independence it provides . Additionally , this paper introduces two variants of post-training quantization methods namely ‘ Hybrid Quantization ’ and ‘ Non-Uniform Quantization ’ . 2 PRIOR ART . 2.1 QUANTIZATION AWARE TRAINING BASED METHODS . An efficient integer only arithmetic inference method for commonly available integer only hardware is proposed in Jacob et al . ( 2018 ) , wherein a training procedure is employed which preserves the accuracy of the model even after quantization . The work in Zhang et al . ( 2018 ) trained a quantized bit compatible DNN and associated quantizers for both weights and activations instead of relying on handcrafted quantization schemes for better accuracy . A ‘ Trained Ternary Quantization ’ approach is proposed in Zhu et al . ( 2016 ) wherein the model is trained to be capable of reducing the weights to 2-bit precision which achieved model size reduction by 16x without much accuracy loss . Inspired by other methods Baskin et al . ( 2019 ) proposes a ‘ Compression Aware Training ’ scheme that trains a model to learn compression of feature maps in a better possible way during inference . Similarly , in binary connect method ( Courbariaux et al. , 2015 ) the network is trained with binary weights during forward and backward passes that act as a regularizer . Since these methods majorly adopt training the networks with quantized weights and quantizers , the downside of these methods is not only that they are time-consuming but also they demand training data which is not always accessible . 2.2 POST TRAINING QUANTIZATION BASED METHODS . Several post-training quantization methods are proposed to replace time-consuming quantization aware training based methods . The method in Choukroun et al . ( 2019 ) avoids full network training , by formalizing the linear quantization as ‘ Minimum Mean Squared Error ’ and achieves better accuracy without retraining the model . ‘ ACIQ ’ method ( Banner et al. , 2019 ) achieved accuracy close to FP32 models by estimating an analytical clipping range of activations in the DNN . However , to compensate for the accuracy loss , this method relies on a run-time per-channel quantization scheme for activations which is inefficient and not hardware friendly . In similar lines , the OCS method ( Zhao et al. , 2019 ) proposes to eliminate the outliers for better accuracy with minimal overhead . Though these methods considerably reduce the time taken for quantization , they are unfortunately tightly coupled with training data for quantization . Hence they are not suitable for applications wherein access to training data is restricted . The contemporary research on data free post-training quantization methods was successful in eliminating the need for accessing training data . By adopting a per-tensor quantization approach , the DFQ method ( Nagel et al. , 2019 ) achieved accuracy similar to the perchannel quantization approach through cross layer equalization and bias correction . It successfully eliminated the huge weight range variations across the channels in a layer by scaling the weights for cross channels . In contrast ZeroQ ( Cai et al. , 2020 ) proposed a quantization method that eliminated the need for training data , by generating distilled data with the help of the Batch-Normalization layer statistics of the FP32 model and using the same for determining the activation ranges for quantization and achieved state-of-the-art accuracy . However , these methods tend to observe accuracy degradation when there are no Batch-Normalization layers present in the FP32 model . To address the above shortcomings the main contributions in this paper are as follows : • A data-independent post-training quantization method by generating the ‘ Retro Synthesis ’ data , for estimating the activation ranges for quantization , without depending on the BatchNormalization layer statistics of the FP32 model . • Introduced a ‘ Hybrid Quantization ’ method , a combination of Per-Tensor and Per-Channel schemes , that achieves state-of-the-art accuracy with lesser inference time as compared to fully per-channel quantization schemes . • Recommended a ‘ Non-Uniform Quantization ’ method , wherein the weights in each layer are clustered and then allocated with a varied number of bins to each cluster , that achieved ‘ 1 % ’ better accuracy against state-of-the-art methods on ImageNet dataset . 3 METHODOLOGY . This section discusses the proposed data-independent post-training quantization methods namely ( a ) Quantization using retro-synthesis data , ( b ) Hybrid Quantization , and ( c ) Non-Uniform Quantization . 3.1 QUANTIZATION USING RETRO SYNTHESIS DATA . In general , post-training quantization schemes mainly consist of two parts - ( i ) quantizing the weights that are static in a given trained FP32 model and ( ii ) determining the activation ranges for layers like ReLU , Tanh , Sigmoid that vary dynamically for different input data . In this paper , asymmetric uniform quantization is used for weights whereas the proposed ‘ retro-synthesis ’ data is used to determine the activation ranges . It should be noted that we purposefully chose to resort to simple asymmetric uniform quantization to quantize the weights and also have not employed any advanced techniques such as outlier elimination of weight clipping for the reduction of quantization loss . This is in the interest of demonstrating the effectiveness of ‘ retro-synthesis ’ data in accurately determining the quantization ranges of activation outputs . However , in the other two proposed methods ( b ) , and ( c ) we propose two newly developed weight quantization methods respectively for efficient inference with improved accuracy . 3.1.1 RETRO-SYNTHESIS DATA GENERATION . Aiming for a data-independent quantization method , it is challenging to estimate activation ranges without having access to the training data . An alternative is to use “ random data ” having Gaussian distribution with ‘ zero mean ’ and ‘ unit variance ’ which results in inaccurate estimation of activation ranges thereby resulting in poor accuracy . The accuracy degrades rapidly when quantized for lower precisions such as 6 , 4 , and 2 bit . Recently ZeroQ ( Cai et al. , 2020 ) proposed a quantization method using distilled data and showed significant improvement , with no results are showcasing the generation of distilled data for the models without Batch-Normalization layers and their corresponding accuracy results . In contrast , inspired by ZeroQ ( Cai et al. , 2020 ) we put forward a modified version of the data generation approach by relying on the fact that , DNNs which are trained to discriminate between different image classes embeds relevant information about the images . Hence , by considering the class loss for a particular image class and traversing through the FP32 model backward , it is possible to generate image data with similar statistics of the respective class . Therefore , the proposed “ retrosynthesis ” data generation is based on the property of the trained DNN model , where the image data that maximizes the class score is generated , by incorporating the notion of the class features captured by the model . Like this , we generate a set of images corresponding to each class using which the model is trained . Since the data is generated from the original model itself we named the data as “ retro-synthesis ” data . It should be observed that this method has no dependence on the presence of Batch-Normalization layers in the FP32 model , thus overcoming the downside of ZeroQ . It is also evaluated that , for the models with Batch-Normalization layers , incorporating the proposed “ class-loss ” functionality to the distilled data generation algorithm as in ZeroQ results in improved accuracy . The proposed “ retro-synthesis ” data generation method is detailed in Algorithm 1 . Given , a fully trained FP32 model and a class of interest , our aim is to empirically generate an image that is representative of the class in terms of the model class score . More formally , let P ( C ) be the soft-max of the class C , computed by the final layer of the model for an image I . Thus , the aim is , to generate an image such that , this image when passed to the model will give the highest softmax value for class C. Algorithm 1 Retro synthesis data generation Input : Pre-determined FP32 model ( M ) , Target class ( C ) . Output : A set of retro-synthesis data corresponding to Target class ( C ) . 1 . Init : I ← random gaussian ( batch-size , input shape ) 2 . Init : Target←rand ( No . of classes ) 3 argmax ( Target ) = C 3 . Init : µ0 = 0 , σ0 = 1 4 . Get ( µi , σi ) from batch norm layers of M ( if present ) , i ∈ 0 , 1 , . . . , n where n → No.of batch norm layers 5. for j = 0 , 1 , . . . , No . of Epochs ( a ) Forward propagate I and gather intermediate activation statistics ( b ) Output = M ( I ) ( c ) LossBN=0 ( d ) for k = 0 , 1 , . . . , n i . Get ( µk , σk ) ii . LossBN ← LossBN+L ( ( µk , σk ) , ( µBNk , σBNk ) ) ( e ) Calculate ( µ′0 , σ′0 ) of I ( f ) LossG ← L ( ( µ0 , σ0 ) , ( µ′0 , σ′0 ) ) ( g ) LossC ← L ( Target , Output ) ( h ) Total loss = LossBN + LossG + LossC ( i ) Update I ← backward ( Total loss ) The “ retro-synthesis ” data generation for a target class C starts with random data of Gaussian distribution I and performing a forward pass on I to obtain intermediate activations and output labels . Then we calculate the aggregated loss that occurs between , stored batch norm statistics and the intermediate activation statistics ( LBN ) , the Gaussian loss ( LG ) , and the class loss ( LC ) between the output of the forward pass and our target output . The L2 loss formulation as in equation 1 is used for LBN and LG calculation whereas mean squared error is used to compute LC . The calculated loss is then backpropagated till convergence thus generating a batch of retro-synthesis data for a class C. The same algorithm is extendable to generate the retro-synthesis data for all classes as well . L ( ( µk , σk ) , ( µ BN k , σ BN k ) ) = ‖µk − µBNk ‖2 2 + ‖σk − σBNk ‖2 2 ( 1 ) Where L is the computed loss , µk , σk , and µBNk , σ BN k are the mean and standard deviation of the kth activation layer and the Batch-Normalization respectively . By observing the sample visual representation of the retro-synthesis data comparing against the random data depicted in Fig . 1 , it is obvious that the retro-synthesis data captures relevant features from the respective image classes in a DNN understandable format . Hence using the retro-synthesis data for the estimation of activation ranges achieves better accuracy as compared to using random data . Also , it outperforms the state-of-the-art data-free quantization methods ( Nagel et al. , 2019 ; Cai et al. , 2020 ) with a good accuracy margin when validated on models with and without BatchNormalization layers . Therefore , the same data generation technique is used in the other two proposed quantization methods ( b ) and ( c ) as well .

Summary: This paper considers the problem of data-free post-training quantization of classfication networks. It proposes three extensions of an existing framework ZeroQ (Cai et al., 2020): (1). in order to generate distilled data for network sensitivity analysis, the "Retro Synthesis" method is proposed to turn a random image into a one that represents a desired class label without relying on batch norm statistics like in ZeroQ; (2). a hybrid quantization strategy is proposed to optionally provide finer-grained per-channel quantization instead of the typical per-layer quantization; (3). a non-uniform quantization grid is proposed to better represent quantized weights, instead of uniform quantization as in ZeroQ.  Empirical evaluation demonstrate the effectiveness of the proposed approach.