Mayo: Auto-generation of hardware-friendly deep neural networks.
Deep convolutional neural networks (CNNs) are powerful tools for a wide range of vision tasks, but the enormous amount of memory and compute resources required by CNNs poses a challenge in deploying them on constrained devices. Existing compression techniques show promising performance in reducing the size and computation complexity of CNNs for efficient inference, but there lacks a method to integrate them effectively. In this paper, we attend to the statistical properties of sparse CNNs and present focused quantization, a novel quantization strategy based on powers-of-two values, which exploits the weight distributions after fine-grained pruning. The proposed method dynamically discovers the most effective numerical representation for weights in layers with varying sparsities, to minimize the impact of quantization on the task accuracy. Multiplications in quantized CNNs can be replaced with much cheaper bit-shift operations for efficient inference. Coupled with lossless encoding, we build a compression pipeline that provides CNNs high compression ratios (CR) and minimal loss in accuracies. In ResNet-50, we achieve a 18.08 × CR with only 0.24% loss in top-5 accuracy, outperforming existing compression pipelines.READ FULL TEXT VIEW PDF
Mayo: Auto-generation of hardware-friendly deep neural networks.
Despite deep convolutional neural networks (CNNs) demonstrating state-of-the-art performance in many computer vision tasks, the parameter-rich and compute-intensive nature substantially hinders the efficient use of them in bandwidth- and power-constrained devices. To this end, recent years have seen a surge of interest in minimizing the memory and compute costs for CNN inference.
Pruning algorithms compress CNNs by setting weights to zero, thus removing connections or neurons from the models. In particular, fine-grained pruning(Liu et al., 2015; Guo et al., 2016) provides the best compression by removing connections at the finest granularity, i.e. individual weights. Quantization methods reduce the number of bits required to represent each value, and thus further provide memory, bandwidth and compute savings. Shift quantization of weights, which quantizes weight values in a model to powers-of-two values or zero, i.e. , is particularly of interest, as multiplications in convolutions become much simpler bit-shift operations. The computational cost in hardware can thus be significantly reduced without a detrimental impact on the model’s task accuracy (Zhou et al., 2017).
Fine-grained pruning, however, is often in conflict with quantization, as pruning introduces various degrees of sparsities to different layers. Linear quantization methods (integers) have uniform quantization levels and non-linear quantizations (logarithmic, floating-point and shift) have fine levels around zero but levels grow further apart as values get larger in magnitude. Both linear and nonlinear quantizations thus provide precision where it is actually not required in the case of a pruned CNN. It is observed that empirically, very few non-zero weights concentrate near zero in certain layers sparsified with fine-grained pruning (see Figure 0(c) for an example). Shift quantization is highly desirable as it can be implemented efficiently, but it becomes a poor choice for certain layers in sparse models, as most near-zero quantization levels are under-utilized (Figure 0(d)).
The weight distributions of the first 8 layers of ResNet-18 on ImageNet. (fig:intro:dense) shows the weight distributions of the layers, (fig:intro:sparse) similarly shows the distributions (excluding zeros) for a sparsified variant. Notice greedy pruning leaves some layers dense. (fig:intro:dense_quantized) and (fig:intro:sparse_quantized) respectively quantize the weight distributions on the left with 5-bit shift quantization. Shift quantization on the sparse layers results in poor utilization of the quantization levels.
This dichotomy prompts the question, how can we quantize sparse weights efficiently and effectively? Here, efficiency represents the minimized compute cost from replacing floating-point multiplications to numerical shifts. Effectiveness means that the quantization levels are well-utilized. From an information theory perspective, it is desirable to design a quantization function such that the quantized values in match as closely as possible the prior weight distribution. We address this issue by proposing a new approach to quantize parameters in CNNs which we call focused quantization that mixes shift and recentralized quantization methods. Following the minimum description length (MDL) principle (Hinton and van Camp, 1993; Graves, 2011)Figure 2), and independently quantizes the two masses (rightmost of Figure 2) to powers-of-2s. The compute pattern of a -bit recentralized quantization can be seen as a combination of a -bit shift quantization and a ternary quantization. This way, it not only preserves the compute-efficiency of convolutional layers using bit-shift operations, but also allows the shift quantization to effectively make use of its range of representable values. Additionally, not all layers consist of two probability masses, and recentralized quantization may not be necessary (as shown in Figure 0(c)). In such cases, we use the Wasserstein distance between the two Gaussian components to decide when to apply shift quantization. Finally, we present a complete compression pipeline comprising fine-grain pruning, focused quantization and Huffman encoding, and show its performance in comparison with many state-of-the-art compression techniques.
In this paper, we make the following contributions:
We propose focused quantization for sparse CNNs based on the MDL principle. The proposed quantization significantly reduces computation and model size with minimal loss of accuracy.
Focused quantization is hybrid, it systematically mixes a recentralized quantization with shift quantization to provide the most effective quantization on sparse CNNs.
We build a complete compression pipeline based on this mixed quantization and demonstrate state-of-the-art compression ratios on a range of modern CNNs.
The rest of the paper is structured as follows. Section 2 discusses related work in the field of DNN compression. Section 3 introduces focused quantization and the complete compression pipeline. Section 4 presents an evaluation of the proposed compression pipeline.
Recently, a wide range of techniques have been proposed and proven effective for reducing the memory and computation requirements of deep neural networks (DNNs). These proposed optimizations can provide direct reductions in memory footprints, bandwidth requirements, total number of arithmetic operations, arithmetic complexities or a combination of these properties.
Pruning-based optimization methods directly reduce the number of parameters in a network. Fine-grained pruning method (Guo et al., 2016) significantly reduces the size of a model but introduces element-wise sparsity. Coarse-grained pruning (Luo et al., 2017; Gao et al., 2019) shrinks model sizes or reduce computation at a higher granularity that is easier to accelerate on commodity hardware. Quantization methods allow parameters to be represented in more efficient data formats. Quantizing weights to powers-of-2 recently gained attention because it not only reduces the model size but also simplifies computation (Leng et al., 2018; Zhou et al., 2017; Miyashita et al., 2016). Previous research also focused on quantizing DNNs to extremely low bit-widths such as ternary (Zhu et al., 2017) or binary (Hubara et al., 2016) values. They however introduces large numerical errors and thus causes significant degradations in model accuracies. Lossy and lossless encoding is another popular method to reduce the size of a DNN, typically used in conjunction with pruning and quantization (Dubey et al., 2018; Han et al., 2016).
Since many compression techniques are available and building a compression pipeline can provide a multiplying effect in compression ratios, researchers start to chain multiple compression techniques. Han et al. (2016) proposed Deep Compression that combines pruning, quantization and Huffman encoding. Dubey et al. (2018) built a compression pipeline using their coreset representation of filters. Tung et al. (2018) and Polino et al. (2018) integrated multiple compression techniques. Tung et al. (2018) combined pruning with quantization and Polino et al. (2018) employed knowledge distillation on top of quantization. Although there are many attempts in building an efficient compression pipeline, the statistical relationship between pruning and quantization lacks exploration. In this paper, we look at exactly this problem and propose a new method that exploits the statistical properties of weights in pruned models to quantize them efficiently and effectively.
A high-level overview of the proposed quantization method is shown in Figure 2, and in this section we continue to explain the method and optimization techniques in detail. Given a model with a sequence of parameters trained on a dataset of input points and targets , compressing the model with quantization can be formulated as a minimum description length (MDL) optimization (Hinton and van Camp, 1993; Graves, 2011), and its objective is to encode the data and the model with the fewest number of bits. Given that we approximate the posterior with a distribution of quantized weights , where
contains the hyperparameters used to quantize, the MDL problem minimizes the following negative variational free energy (Graves, 2011):
where consists of two separate terms, the error cost and the complexity cost . The former represents the cost to communicate the true label , given the receiver already knows the inputs and the quantized model weights . The more accurate the model output, the fewer bits are therefore required to communicate the true label . The latter is the Kullback-Leibler (KL) divergence from to , which denotes the lower bound on the expected cost to communicate the model . Intuitively, the former reflects the cross-entropy loss of the quantized model trained on , and the latter minimizes the discrepancies between the weight distributions before and after quantization.
Shift quantization is a quantization scheme which constrains weight values to powers-of-two or zero values. A representable value in a -bit shift quantization is given by:
where denotes either zero or the sign of the value, is an integer bounded by , and is the bias, a layer-wise constant which scales the magnitudes of quantized values. We use to denote a -bit shift quantization with a bias of a weight value to the nearest representable value .
As we have discussed earlier and illustrated in Figure 1, shift quantization on sparse layers makes poor use of the range of representable values, i.e. the resulting distribution after quantization is a poor approximation of .
Intuitively, by concentrating quantization effort on the high probability regions in the weight distribution in sparse layers, the KL-divergence can be minimized better. Recentralized quantization is designed specifically for this purpose, and is defined as follows and applied in a layer-wise fashion:
where is a weight value of the layer, is the constant pruning mask containing binary values , and it is used to set pruned weights to 0. The set of components determines the specific locations to focus quantization effort. The Kronecker delta evaluates to either 1 when , or 0 otherwise. In effect, is a constant and it chooses which component in is used to quantize , and Section 3.3 explains how can be determined for each . Following (Zhu et al., 2017; Leng et al., 2018), we additionally introduce a layer-wise learnable scaling factor initialized to 1, which empirically improves the task accuracy. Finally, quantizes the component :
where the scalar constants , and are hyperparameters in to be optimized. We additionally use to indicate the distribution generated by applying the layer-wise quantization on all weights . The process of minimizing therefore finds the optimal .
The complexity cost is unfortunately intractable, and the relevant hyperparameters in cannot be computed analytically and a direct search is still difficult to accomplish. As recentralized quantization concerns with high-probability weights, we can approximately minimize the KL divergence by applying the following two-step process in a layer-wise manner, which first identifies regions with high probabilities (first block in Figure 2), then locally quantize them with recentralized quantization (second and third blocks in Figure 2).
First, we notice that in general, the weight distribution resembles a mixture of Gaussian distributions, and thus replace
with a surrogate, which is defined as a Gaussian mixture model, and subsequently used to approximate:
is the probability density function of the Gaussian distribution, the non-negative defines the mixing weight of the component and . We can then maximize with:
where comprises the optimal values for , , of all components . This solution is known as the maximum likelihood estimate (MLE). Theoretically, finding the MLE is equivalent to minimizing the KL divergence , and can be efficiently computed by the expectation-maximization (EM) algorithm (Dempster et al., 1977).
In practice, we found it sufficient to use two Gaussian components, , for identifying high-probability regions in the weight distribution. For faster EM convergence, we initialize and
respectively with the means and standard deviations of negative and positive values in weightsrespectively, and with .
We then generate from the mixture model, which individually selects the component to use for . An obvious design decision is to sample from the Gaussian mixture, and for each , follows a categorical distribution where we randomly assign a component to with the following probability:
Finally, we set the constant to a powers-of-two value, chosen to ensure that allows at most a proportion of
values to overflow and clips them to the maximum representable magnitude. In practice, this heuristic choice makes better use of the quantization levels provided by shift quantization than disallowing overflows.
After determining all of the relevant hyperparameters with the method described above, can be evaluated to quantize the layer weights .
Recentralized quantization is designed to capture the high-probability components in the weight distribution, which in theory provides a less redundant use of bits compared to shift quantization. We further reduce the bit-width by removing certain representable values that occur rarely after quantization. The tricks are generally applicable. Consider the (orange) and (blue) Gaussian components in the first block of Figure 2, it is notable that the means and are surrounded with many fine-grained quantization levels, thus sacrificing these representations by quantizing to nearby values is equivalently efficient. Similarly, very few values quantized by lie about the well-quantized region of and vice versa. Meaning that we can remove the largest representation from and smallest representation from . By removing these values from the representation, we use exactly at most bits to represent a quantized value which internally uses -bit shift quantization. To further simplify computation, we constrain and to the nearest powers-of-two values. For instance, a 3-bit recentralized quantization uses the following representable values if , where the first two sets correspond to values quantized by the and components respectively.
As we have discussed earlier, the weight distribution of sparse layers may not always have multiple high-probability regions. For example, fitting a mixture model of two Gaussian components on the layer in Figure 2(a) gives highly overlapped components. It is therefore of little consequence which component we use to quantize a particular weight value. This is due to the fact that quantizing with either gives us similar quantization results (Figure 2(b)), rendering the use of the component selector redundant. Under this scenario, we can simply use -bit shift quantization instead of a -bit which internally uses a -bit shift quantization. By moving the 1 bit used to represent the now absent to shift quantization, we further increase its precision.
To decide whether to use shift or recentralized quantization, it is necessary to introduce a metric to compare the similarity between the pair of components. While the KL-divergence provides a measure for similarity, it is however non-symmetric, making it unsuitable for this purpose. To address this, we propose to first normalize the distribution of the mixture, then to use the 2-Wasserstein metric between the two Gaussian components after normalization as a decision criterion, which we call the Wasserstein separation:
where and are respectively the mean and standard deviation of the component , and
denotes the variance of the entire weight distribution. Focused quantization can then adaptively pick to use recentralized quantization for all sparse layers except when, and shift quantization is used instead. In our experiments, we found usually provides a good decision criterion. In Section 4.3, we additionally study the impact of quantizing a model with different values.
Optimizing the overall cost requires us to minimize alongside , which is the expected training loss of the model using weights drawn from the quantized distribution. We propose to interleave the optimizations of and using dual-updates, and the rest of this section explains its rationale and algorithm.
Under the variational inference (VI) framework for neural networks (Graves, 2011; Hinton and van Camp, 1993; Nowlan and Hinton, 1992), the posterior approximation is sampled for each mini-batch during training, and often requires reparameterization tricks (Kingma et al., 2015) to reduce the training variance. These limitations make the large-scale use of VI a challenging endeavour. We address this by presenting an alternative optimization approach.
The procedure to minimize the complexity cost and sample the resulting quantized value described in Section 3.3
is time-consuming when compared to the forward/backward propagation time of the model. Because of this, it cannot be carried out for each stochastic gradient descent (SGD) step to minimize the error cost. Instead, we interleave the minimization stages of and . By doing so, is optimized with conventional SGD algorithm, where the forward pass uses the quantized weights for inference, and the subsequent backward pass updates the original values. We also found that in our experiments, exponentially increasing the interval between consecutive optimization stages helps to reduce the variance introduced by sampling and improves training quality.
We applied focused compression, a compression flow which consists of pruning, focused quantization and Huffman encoding, on a wide range of popular vision models including MobileNets (Howard et al., 2017; Sandler et al., 2018) and ResNets (He et al., 2016a, b) on the ImageNet dataset (Deng et al., 2009). For all of these models, focused compression produced models with high compression ratios (CRs) and permitted a multiplication-less hardware implementation while having minimal impact on the task accuracy. In our experiments, models are initially sparsified using Dynamic Network Surgery (Guo et al., 2016). Focused quantization is subsequently applied to restrict weights to low-precision values. During fine-tuning, we additionally employed Incremental Network Quantization (INQ) (Zhou et al., 2017) and gradually increased the proportion of weights being quantized to 25%, 50%, 75%, 87.5% and 100%. At each step, the models were fine-tuned for 3 epochs at a learning rate of 0.001, except for the final step at 100% we ran for 10 epochs, and decay the learning rate every 3 epochs. Finally, Huffman encoding was applied to model weights which further reduced model sizes.
Table 1 compares the accuracies and compression rates before and after applying the compression pipeline under different quantization bit-widths. It demonstrates the effectiveness of focused compression on the models. We found that sparsified ResNets with 7-bit weights are at least smaller than the original dense model with marginal degradations () in top-5 accuracies. MobileNets, which are much less redundant and more compute-efficient models to begin with, achieved a smaller CR at around and slightly larger accuracy degradations (). Yet when compared to the ResNet-18 models, it is not only more accurate, but also has a significantly smaller memory footprint at 1.71 MB.
In Table 2 we compare focused compression with many state-of-the-art model compression schemes. It shows that focused compression simultaneously achieves the best accuracies and the highest CR on both ResNets. Trained Ternary Quantization (TTQ) (Zhu et al., 2017) quantizes weights to ternary values, while INQ (Zhou et al., 2017) and extremely low bit neural network (denoted as ADMM) (Leng et al., 2018) quantize weights to ternary or powers-of-two values using shift quantization. Distillation and Quantization (D&Q) (Polino et al., 2018) quantize parameters to integers via distillation. Note that D&Q’s results used a larger model as baseline, hence the compressed model has high accuracies and low CR. We also compared against Coreset-Based Compression (Dubey et al., 2018) comprising pruning, filter approximation, quantization and Huffman encoding. For ResNet-50, we additionally compare against ThiNet (Luo et al., 2017), a filter pruning method, and Clip-Q (Tung et al., 2018), which interleaves training steps with pruning, weight sharing and quantization. Focused compression again achieves the highest CR () and accuracy (74.86%).
|TTQ (Zhu et al., 2017)||66.00||87.10||2.92||16.00|
|INQ (2 bits) (Zhou et al., 2017)||66.60||87.20||2.92||16.00|
|INQ (3 bits) (Zhou et al., 2017)||68.08||88.36||4.38||10.67|
|ADMM (2 bits) (Leng et al., 2018)||67.00||87.50||2.92||16.00|
|ADMM (3 bits) (Leng et al., 2018)||68.00||88.30||4.38||10.67|
|D&Q (large) (Polino et al., 2018)||73.10||91.17||21.98||2.13|
|Coreset (Dubey et al., 2018)||68.00||—||3.11||15.00|
|Focused compression (5 bits, sparse)||68.36||88.45||2.86||16.33|
|INQ (5 bits) (Zhou et al., 2017)||74.81||92.45||14.64||6.4|
|ADMM (3 bits) (Leng et al., 2018)||74.0||91.6||8.78||10.67|
|ThiNet (Luo et al., 2017)||72.04||90.67||16.94||5.53|
|Clip-Q (Tung et al., 2018)||73.70||—||6.70||14.00|
|Coreset (Dubey et al., 2018)||74.00||—||5.93||15.80|
|Focused compression (5 bits, sparse)||74.86||92.59||5.19||18.08|
Quantizing weights using focused quantization can significantly reduce computation complexities in models. By further quantizing activations and batch normalization parameters to integers, the expensive floating-point multiplications and additions in convolutions can be replaced with simple bit-shift operations and integer additions. This can be realized with much faster software or hardware implementations, which directly translates to energy saving and much lower latencies in low-power devices. InTable 3, we evaluate the impact on accuracies by progressively applying focused quantization on weights, and integer quantizations on activations and batch normalization parameters.
Figure 4 shows an efficient implementation of a layer with recentralized quantization. Table 4 shows the total number of BitOps required by the implementation to compute a batch-normalized convolution layer with
filters with a padding size of 1, which takes as input aactivation and produce a tensor output. The BitOps is an estimate for the cost in a corresponding hardware implementation and we demonstrate the hardware cost of the two different quantizations used in focused quantization. Perhaps most surprisingly, the convolution quantized using recentralized quantization use approximately the same amount of bit operations (BitOps) when compared to a shift-quantized alternative with the same bit-width for weights. The reason for this is that a weight with -bit recentralized quantization internally uses a -bit shift quantization. Comparing to -bit shift quantization, the former has exactly half of the dynamic range of the latter and thus uses an adder tree half of the size of the latter. Yet recentralized quantization doubles the number of additions, as Figure 4 now takes two parallel addition paths. Additionally, Huffman encoding has minimal overhead in the number of BitOps, because it uses a very small number of dictionary entries for quantized values. For instance, the number of possible entries for 3-bit values is only .
|Shift||463 M||5.74 M||6400|
|Focused Quantization||499 M||11.48 M||6400|
|Focused Quantization + Huffman||500 M||11.48 M||6400|
In Section 3.5, we mentioned that some of the layers in a sparse model may not have multiple high-probability regions. For this reason, we use the Wasserstein distance between the two components in the Gaussian mixture model as a metric to differentiate whether recentralized or shift quantization should be used. In our experiments, we specified a threshold such that for each layer, if then recentralized quantization is used, otherwise shift quantization is employed instead. Figure 5 shows the impact of choosing different ranging from 1.0 to 3.5 at 0.1 increments on the Top-1 accuracy. This model is a fast CIFAR-10 (Krizhevsky et al., 2014)
classifier with only 9 convolutional layers, so that it is possible to repeat training 100 times for eachvalue to produce high-confidence results. Note that the average validation accuracy is minimized when the layer with only one high-probability region uses shift quantization and the remaining 8 use recentralized quantization, which verifies our intuition.
In this paper, we exploit the statistical properties of sparse CNNs and propose focused quantization to efficiently and effectively quantize model weights. The quantization strategy uses Gaussian mixture models to locate high-probability regions in the weight distributions and quantize them in fine levels. Coupled with pruning and encoding, we build a complete compression pipeline and demonstrate high compression ratios on a range of CNNs. In ResNet-18, we achieve CR with minimal loss in accuracies. Furthermore, the proposed quantization uses only powers-of-2 values and thus provides an efficient compute pattern. The significant reductions in model sizes and compute complexities can translate to direct savings in power efficiencies for future CNN accelerators on IoT devices.
2009 IEEE Conference on Computer Vision and Pattern Recognition, pages 248–255, June 2009.
Proceedings of the Sixth Annual Conference on Computational Learning Theory, COLT ’93, 1993.
Thirty-Second AAAI Conference on Artificial Intelligence, 2018.