Multiplication-free deep neural network model compression method based on parity logarithmic quantization
Through the multiplication-free deep neural network model compression method based on parity logarithmic quantization, the problem of large calculation amount and parameter amount of the deep learning model is solved, a low-bit multiplication-free deep neural network is realized, and the quantization error and hardware resource consumption are reduced. Improved model accuracy and running speed.
Patent Information
- Application Number
- CN202111448717.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-11-30
AI Technical Summary
Existing deep learning models have a large amount of calculations and parameters, and are especially difficult to deploy on end-side devices with limited resources. Moreover, the uniform quantization method has problems with quantization error and high hardware resource consumption.
A multiplication-free deep neural network model compression method based on logarithmic parity quantification is adopted. By constructing a set of integer values, mapping floating-point data to integer data, and replacing multiplication operations with shift and addition operations in convolution calculations, it is achieved Low-bit multiplication-free deep neural networks.
The quantization error is reduced, the model accuracy is improved, the hardware resource occupation and power consumption are reduced, and the running speed is improved.
Smart Images

Figure CN114239798B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to a multiplication-free deep neural network model compression method based on parity logarithm quantization. Background Art
[0002] In recent years, deep learning technology has developed rapidly and has achieved great success in computer vision, natural language processing and other fields. However, as deep learning models continue to improve and increase accuracy, they also bring huge amounts of computation and parameters. For example, the most commonly used backbone model ResNet50 has 25.56M parameters and 4.14G multiplication and addition operations, which brings great challenges to the deployment of deep learning models, especially for end-side devices with limited resources.
[0003] In order to reduce the number of model parameters and computational complexity and improve model operation efficiency, model compression technology has emerged, mainly including low-bit quantization, network pruning, knowledge distillation, etc. As the most direct and effective method of model compression technology, low-bit quantization has been widely studied and used by academia and industry. Its core idea is to represent the 32-bit floating point (FP32) data in the deep learning model with lower-bit fixed-point data, such as INT8 and INT4, which can not only reduce memory bandwidth, but also improve computing efficiency and reduce power consumption.
[0004] Existing quantization methods can basically be divided into two categories: uniform quantization and non-uniform quantization. Uniform quantization refers to uniformly mapping the original floating-point data to uniformly distributed integer data according to the scaling factor, while non-uniform quantization mainly refers to logarithmic quantization, that is, mapping the floating-point data to the power of 2. Although uniform quantization is a method that has been studied more thoroughly and applied more widely, it has two problems: first, the distribution difference between floating-point data and integer data is large, which will inevitably cause greater quantization errors; second, although uniform quantization can convert floating-point calculations in deep learning models into fixed-point calculations, it still relies on a large number of matrix multiplication operations, and the hardware resource consumption is relatively high. Although ordinary logarithmic quantization can convert multiplication into shift and addition, its values are too discrete and cannot well guarantee the loss of precision, so it is not currently used on a large scale.
[0005] The above information disclosed in this Background section is only for enhancement of understanding of the background of the invention and therefore it may contain information that does not form the prior art that is already known to a person of ordinary skill in the art. Summary of the invention
[0006] The purpose of the present invention is to provide a multiplication-free deep neural network model compression method based on parity logarithm quantization. In order to achieve the above purpose, the present invention provides the following technical solutions:
[0007] A multiplication-free deep neural network model compression method based on parity logarithm quantization of the present invention comprises:
[0008] The first step is to construct an integer value set V according to a predetermined bit width. bit represents an even power of 2, N = bit-M-1 bit represents an odd power of 2, and the remaining 1 bit represents the sign bit, so V′ = ±(2 m +2 n ), where m = 2k, k∈0, 1, ..., 2 M -2, n=2k+1, k∈0,1,...,2 N -2;
[0009] In the second step, the floating-point data is mapped to integer data according to the quantization coefficient, T represents any floating-point tensor to be quantized, C represents the dynamic range of the floating-point tensor: C = Max(Abs(T), and the scaling factor is obtained as: Scale T =C / V max , quantized to an integer tensor: The Round() function rounds the input data to the nearest integer value in V, and the Clip() function truncates the input data at V. min and V max between;
[0010] The third step is to map the integer data into discrete floating point data according to the quantization coefficient. q =T int *Scale T , T q is the discrete data used to approximate the floating-point tensor T after quantization and dequantization, and T q The mean square error with T represents the quantization error: The Numel() function returns the total number of input elements;
[0011] The fourth step is to use the first step to the third step to realize a low-bit multiplication-free deep neural network, and the convolution calculation Y=conv(W, X)+B, where conv() represents the convolution calculation, X / Y represents the input / output floating-point data, W / B represents the weight / bias floating-point parameter, and X / Y / W / B is quantized and dequantized to obtain discrete data, which is used to approximate the convolution calculation: Y q =conv(W q , Xq )+B q , the approximate convolution calculation is equivalently transformed into a pure integer convolution calculation formula: And the multiplication calculation of input data and weight parameters in the convolution calculation is replaced by shift operation and addition calculation.
[0012] In the multiplication-free deep neural network model compression method based on parity logarithmic quantization, the collected data includes forming a floating-point model to be quantized and its training set.
[0013] In the multiplication-free deep neural network model compression method based on parity logarithm quantization, two shifters and an adder replace a multiplier to perform a multiplication-free convolution operation.
[0014] In the multiplication-free deep neural network model compression method based on parity logarithm quantization, four adders replace one multiplier to perform multiplication-free convolution operations.
[0015] In the above technical scheme, the multiplication-free deep neural network model compression method based on parity logarithmic quantization provided by the present invention has the following beneficial effects: the multiplication-free deep neural network model compression method based on parity logarithmic quantization described in the present invention can replace the more expensive multipliers with lower-cost shifters and adders. This method not only solves the problem of inconsistency between the distribution of traditional uniformly quantized integer data and the distribution of floating-point data, but also overcomes the disadvantage that the ordinary logarithmic quantization numerical distribution is too discrete and has low expression ability, thereby greatly reducing the quantization error and improving the accuracy of low-bit neural networks. It is suitable for operators that rely on dense matrix multiplication calculations such as convolution and fully-connected, which are common in deep neural networks. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only one embodiment recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0017] Figure 1 Floating point data (a) of the weight parameters of the first convolution layer of ResNet18 in the multiplication-free deep neural network model compression method based on parity logarithmic quantization in the present invention, and a discrete data distribution histogram quantized using uniform quantization (b), logarithmic quantization (c), and the EOLQ algorithm (d) proposed in the present invention;
[0018] Figure 2It is a schematic diagram of the calculation principle of replacing multipliers with shifters and adders in the multiplication-free deep neural network model compression method based on parity logarithm quantization in the present invention. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described in combination with the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0020] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0021] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings. Figure 1 to Figure 2 ,Multiplication-free deep neural network model compression methods based on parity logarithm quantization include,
[0022] First, construct an integer value set V according to the predetermined bit width (bit), and use bit represents an even power of 2, N = bit-M-1 bit represents an odd power of 2, and the remaining 1 bit represents the sign bit, so V = ±(2 m +2 n ), where m = 2k, k∈0, 1, ..., 2 M -2, n=2k+1, k∈0,1,...,2 N -2. That is, when the M or N bits are all 1, it represents the value 0. The minimum and maximum values of V can be obtained as follows:
[0023] For example, if B=5, M=2, N=2, then:
[0024] V=±{0,1,2,3,4,6,8,9,12,16,18,24,32,33,36,48},
[0025] For example, if B=4, M=2, and N=1, then:
[0026] V=±{0, 1, 2, 3, 4, 6, 16, 18}.
[0027] Map the floating-point data to integer data according to the quantization coefficient. T represents any floating-point tensor to be quantized, and C represents the dynamic range of the floating-point tensor: C = Max(Abs(T). The scaling factor can be obtained as: Scale T =C / V max , quantized to an integer tensor: The Round() function rounds the input data to the nearest integer value in V, and the Clip() function truncates the input data at V. min and V max between.
[0028] Map the integer data to discrete floating-point data according to the quantization coefficient, T q =T int *Scale T , T q It is the discrete data used to approximate the floating-point tensor T after quantization and dequantization. It is generally represented by T q The mean square error with T represents the quantization error: The Numel() function returns the total number of elements in the input.
[0029] The above quantization method is used to implement a low-bit multiplication-free deep neural network. Taking the most common convolution calculation as an example: Y = conv(W, X) + B, where conv() represents the convolution calculation, X / Y represents the input / output floating-point data, and W / B represents the weight / bias floating-point parameters. The convolution calculation can be more specifically expressed as: Use the above method to quantize X / Y / W / B to get discrete data, which is used to approximate convolution calculation: Y q =conv(w q , X q )+B q , this approximate calculation is equivalent to: Y int *Scale y =conv(W int *Scale w , X int *Scale x )+B int *Scale w Scale x , and then transform it into a pure integer calculation formula: And the multiplication calculation of input data and weight parameters that exists in large quantities in convolution calculation can be replaced by shift operation and addition calculation. Assume that w is W int An element of X, x is int If we quantize w as ±(2 m +2 n), then w*x can be implemented by two shifts of x and one addition,
[0030] w*x=±(2 m +2 n )*x=±(x<<m+x<<n)
[0031] If we also quantize x to ±(2 u +2 v ), then w*x can be implemented using 4 shifts,
[0032] w*x=±(2 m +2 n )(2 u +2 v )
[0033] =±(1<<(m+u)+1<<(n+u)+1<<(m+v)+1<<(n+v)).
[0034] In one embodiment, the method includes,
[0035] Prepare the floating-point model to be quantized (such as ResNet18) and its full-precision parameters trained on the training set (such as ImageNet).
[0036] According to the number of bits B allocated to each parameter, an integer value set V is constructed, and then the parameters are quantized. For example, if we want to use 5 bits to represent the weight parameters of the first layer of ResNet18, we can compare the performance differences between traditional uniform quantization and logarithmic quantization and the EOLQ quantization algorithm proposed in this invention. Figure 1 (a) is the distribution histogram of the full-precision floating-point data of the weight parameters of the first convolutional layer of the ResNet18 model. It can be seen that the distribution of floating-point data is dense in the middle and sparse at both ends; Figure 1 (b) is the distribution histogram of discrete data after traditional uniform quantization. It is obvious that since uniform quantization has a uniform and consistent resolution within the numerical representation range, it is quite different from the distribution of the original floating-point data. Therefore, the numerical representation capacity of the large absolute values at both ends is wasted, and the dense data near 0 cannot be better represented. Figure 1 (c) is the distribution histogram of discrete data obtained by traditional logarithmic quantization. Since logarithmic quantization can only use the power of 2 to represent data, its values are too discrete and cause certain distortion to the distribution of the original floating-point data. Figure 1 (d) is the distribution histogram of discrete data after quantization by the EOLQ algorithm proposed in the present invention. Overall, the distribution state of floating-point data is restored to the greatest extent, ensuring that no information is lost. In addition, the results of quantitative analysis show that the quantization loss E qIt is only about 1 / 5 of uniform quantization and about 1 / 3 of logarithmic quantization.
[0037] After obtaining the quantized data, the floating-point operations that originally relied on multiplication can be replaced with integer operations without multiplication. Figure 2 The schematic diagram of two non-multiplication calculations proposed by the present invention is shown in FIG. Figure 2 In (a), EOLQ-A can replace one multiplier with only two shifters and one adder. Figure 2 In (b), EOLQ-B can replace one multiplier with only four adders. In order to verify the hardware benefits brought by replacing the multiplier in the present invention, we compare the above two multiplication-free computing schemes with the traditional Booth multiplier. From the results in Table 1, EOLQ can reduce 60% of resource usage and 36% of power consumption, and also brings a 1.7 times speed improvement.
[0038] Table 1: Power consumption, hardware resource usage, and latency comparison of replacing multipliers with multipliers and adders.
[0039]
[0040] The EOLQ quantization algorithm proposed in this paper is applied to the ImageNet large-scale classification task, and the ResNet18 / 34 / 50 models are quantized, and the results are compared with other classic algorithms. From the experimental results in Table 2, it can be seen that the Top-1 and Top-5 accuracy of the EOLQ algorithm are significantly higher than most existing uniform quantization and logarithmic quantization algorithms.
[0041] Table 2: Quantitative results on the ImageNet classification task
[0042]
[0043] In one embodiment, in the method, firstly, an integer value set V is constructed according to a predetermined bit width (bit): V = ± (2 m +2 n ), where m = 2k, k∈0, 1, ..., 2 M -2, n=2k+1,k∈0,1,...,2 N -2, N = bit-M-1; then the floating-point data is mapped to integer data according to the quantization coefficient. For example, T represents any full-precision floating-point tensor to be quantized, and C represents the dynamic range of the floating-point tensor: C = Max(Abs(T), then the scaling factor can be obtained: Scale T =C / V max , quantize the floating point data into low bit integer data T according to the scaling factor int : The Round() function rounds the input data to the nearest integer value in V, and the Clip() function truncates the input data at V. min and V max Then dequantize to get floating point discrete data T q :T q =T int *Scale T , used to approximate the full-precision floating-point tensor T, generally T q The quantization error is expressed as the mean square error with T: The Numel() function returns the total number of elements of the input data. Finally, the above quantization method is used to construct a low-bit multiplication-free deep neural network. Taking the most common convolution calculation as an example: Y = conv(W, X) + B, where conv() represents the convolution calculation, X / Y represents the input / output floating-point data, and W / B represents the weight / bias floating-point parameters. X / Y / W / B is quantized and dequantized to obtain discrete data, which is used to approximate the convolution calculation: Y q =conv(W q , X q )+B q , this approximate calculation can be equivalently transformed into a pure integer convolution calculation formula: Furthermore, the multiplication calculations of input data and weight parameters that exist in large quantities in convolution calculations can be replaced by shift operations and addition calculations.
[0044] Finally, it should be noted that the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making any creative work are within the scope of protection of the present application.
[0045] The above description is only by way of illustration of certain exemplary embodiments of the present invention. It is undoubted that those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the above drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.
Claims
1. A multiplication-free deep neural network model compression method based on parity logarithm quantization, comprising the following steps: The first step is to collect data, wherein collecting data includes forming a floating-point model to be quantized and its training set, preparing the floating-point model to be quantized and its parameters trained on ImageNet, and calculating the number of bits allocated to each parameter. B Constructing a collection of integer values V , bits represent even powers of 2, The bit represents the odd power of 2, and the remaining 1 bit represents the sign bit, so , where m = 2k, k ,n = 2k+1, k ; The second step is to map the floating point data to integer data according to the quantization coefficient. T represents any floating-point tensor to be quantized, C Represents the dynamic range of the floating point tensor: C = Max(Abs( T ), the scaling factor is obtained as: , quantized to an integer tensor: , where the Round() function rounds the input data to the nearest V The Clip() function truncates the input data at and between; The third step is to map the integer data into discrete floating point data according to the quantization coefficient. , is the discrete data used to approximate the floating-point tensor T after quantization and dequantization. The mean square error with T represents the quantization error: , where the Numel() function returns the total number of elements in the input; The fourth step is to use the first step to the third step to realize a low-bit multiplication-free deep neural network and convolution calculation ,in, conv ( ) represents convolution calculation, X / Y Represents input / output floating point data, W / B represents weight / bias floating point parameters, X / Y / W / B Quantization and dequantization are performed to obtain discrete data, which is used to approximate convolution calculations: , the approximate convolution calculation is equivalently transformed into a pure integer convolution calculation formula: , and replace the multiplication calculation of input data and weight parameters in the convolution calculation with shift operation and addition calculation; where, Two shifters and an adder replace one multiplier to implement a convolution operation without multiplication; or, Four adders replace one multiplier to implement convolution operations without multiplication; in, The more expensive multipliers are replaced by lower-cost shifters and adders. The method not only solves the problem of inconsistency between the distribution of traditional uniformly quantized integer data and floating-point data, but also overcomes the drawback of the common logarithmic quantization numerical distribution being too discrete and having low expression ability, thereby greatly reducing the quantization error and improving the accuracy of low-bit neural networks. It is suitable for common convolution and fully-connected operators in deep neural networks that rely on dense matrix multiplication calculations. The method is applied to the ImageNet large-scale classification task.
