A method for adaptively adjusting activation quantization bit width
Through the method of adaptively adjusting the activation quantization bit width, combined with the Relu6 model and SIMD technology, the activation bit width is dynamically adjusted, which solves the problem of unsatisfactory acceleration ratio and accuracy after model quantization in the existing technology, and achieves more efficient convolution operations. .
Patent Information
- Application Number
- CN202011622451.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2040-12-31
AI Technical Summary
In the existing technology, the quantized model cannot achieve the best acceleration ratio and accuracy, and the quantization bit width of different layers causes the overall quantization bit width to fail to decrease or the convergence effect is not ideal.
This paper proposes a method to adaptively adjust the activation quantization bit width. Through data quantization, using the Relu6 model and SIMD acceleration technology during the training process, the activation bit width is dynamically adjusted according to the activation distribution to ensure that the volume accumulation result is within 16 bits.
By adjusting the activation bit width, the SIMD acceleration effect is improved, the accuracy and acceleration ratio of the model are improved, and the problems of accuracy loss and unsatisfactory acceleration effect of the model after quantization are solved.
Smart Images

Figure CN114692862B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of convolutional neural network acceleration, and in particular to a method for adaptively adjusting activation quantization bit width. Background Art
[0002] In recent years, with the rapid development of science and technology, the era of big data has arrived. Deep learning uses deep neural networks (DNNs) as models and has achieved remarkable results in many key areas of artificial intelligence, such as image recognition, reinforcement learning, and semantic analysis. As a typical DNN structure, convolutional neural networks (CNNs) can effectively extract the hidden features of images and accurately classify images. They have been widely used in the fields of image recognition and detection in recent years.
[0003] In existing quantization model methods, all layers of the model are quantized to the same bit width, or the quantization bit width of a certain layer of the model is manually adjusted.
[0004] However, when different layers in a neural network model are quantized to different bit widths, the precision loss is different. When the entire model is quantized to the same bit width, the overall quantization bit width may not be reduced, or the model convergence effect is not ideal, and the optimal acceleration ratio cannot be achieved.
[0005] Common technical terms in the prior art include:
[0006] Convolutional Neural Networks (CNN): A type of feedforward neural network that includes convolution calculations and has a deep structure.
[0007] Quantization: Quantization refers to the process of approximating the continuous value of a signal (or a large number of possible discrete values) to a finite number (or fewer) of discrete values.
[0008] Low bit: Quantize the data into data with a bit width of 8 bits, 4 bits or 2 bits.
[0009] SIMD stands for Single Instruction Multiple Data. It is a technology that uses one controller to control multiple processors and simultaneously performs the same operation on each of a set of data (also known as "data vector") to achieve spatial parallelism. In the image processing process, since the commonly used data types of image data are RGB565, RGBA8888, YUV422 and other formats, the data characteristics of these formats are that a component of a pixel is always represented by data less than or equal to 8 bits. If a traditional processor is used for calculation, although the processor register is 32 or 64 bits, only the lower 8 bits can be used to process these data, which is too inefficient. If the 64-bit register is split into 8 8-bit registers, 8 operations can be completed at the same time, and the computing efficiency is increased by 8 times. This is the core idea of SIMD instructions. Summary of the invention
[0010] In order to solve the above problems, the purpose of this method is to overcome the defects existing in the above-mentioned prior art and solve the problem that the quantized model cannot achieve the optimal acceleration ratio and accuracy.
[0011] Specifically, the present invention proposes a method for adaptively adjusting the activation quantization bit width, the method comprising the following steps:
[0012] S1, data quantization: quantize the data to be quantized to obtain low-bit data;
[0013] S2, the data passed to the next layer when training the low-bit model, uses the Relu6 model for activation and quantizes the convolution. The result is:
[0014]
[0015] This equation is to illustrate conv(W sqf ,F uqf ) and conv(W q ,F q ), where wb and fb are the quantization bit widths of the weight and feature map, respectively. sqf is the weight data quantized to low bits and normalized to [-1 to 1], F uqf is the data quantized to the last bit and normalized to [-1 to 1], W q ,F q Quantize weights and feature maps to low-bit data respectively;
[0016] S3, during inference, without changing the weight channels, reducing the activation bit width can reduce the situation where the convolution accumulation result exceeds 16 bits. If conv(Wsqf ,F uqf )>1.0, reduce the activated quantization bit width until conv(W sqf ,F uqf )≤1.0; and perform the same operation on each output channel of the layer, so as to determine the corresponding bit width according to the distribution of each channel.
[0017] The step S1 includes:
[0018] 1), signed data quantization:
[0019]
[0020] 2), unsigned data quantization:
[0021]
[0022] Variable Description: W f For full precision data, it is an array. q For the simulated quantized data, max w is the full precision data W f The maximum value in , b is the bit width after quantization.
[0023] In step S2, the data transmitted to the next layer is:
[0024] If there is a symbol
[0025] If unsigned.
[0026] The formula of Relu6 is as follows:
[0027] relu6(x)=min(max(x,0),6)∈[0,6].
[0028] In step S3, SIMD acceleration is used to accelerate the convolution operation.
[0029] The operation in step S3 can be completed during model training, that is, when training the model, conv(W sqf ,F uqf )>1.0 then the n+1th step fb n+1 =fb n -1, if conv(W sqf ,F uqf )≤1.0, then the n+1th step fb n+1 =fb n .
[0030] The method performs full-precision model training.
[0031] Therefore, the advantage of the present application is that the accumulated result of the convolution is reduced by adjusting the activated bit width, thereby compressing the accumulated sum to within 16 bits, so as to improve the acceleration effect of using SIMD. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.
[0033] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0034] In order to more clearly understand the technical content and advantages of the present invention, the present invention is now further described in detail in conjunction with the accompanying drawings.
[0035] like Figure 1 As shown, the present invention relates to a method for improving the model accuracy of a convolutional neural network during quantization, and in particular, a method for adaptively adjusting the activation quantization bit width.
[0036] A method for adaptively adjusting activation quantization bit width, the method comprising the following steps:
[0037] S1, data quantization: quantize the data to be quantized to obtain low-bit data;
[0038] S2, the data passed to the next layer when training the low-bit model, uses the Relu6 model for activation and quantizes the convolution. The result is:
[0039]
[0040] This equation is to illustrate conv(W sqf ,F uqf ) and conv(W q ,F q ), where wb and fb are the quantization bit widths of the weight and feature map, respectively. sqf is the weight data quantized to low bits and normalized to [-1 to 1], F uqf is the data quantized to the last bit and normalized to [-1 to 1], W q ,F q Quantize weights and feature maps to low-bit data respectively;
[0041] S3, during inference, without changing the weight channels, reducing the activation bit width can reduce the situation where the convolution accumulation result exceeds 16 bits. If conv(W sqf ,Fuqf )>1.0, reduce the activated quantization bit width until conv(W sqf ,F uqf )≤1.0, this operation can be completed during model training, that is, when training the model, at the nth step, conv(W sqf ,F uqf )>1.0 then the n+1th step fb n+1 =fb n -1, if conv(W sqf ,F uqf )≤1.0, then the n+1th step fb n+1 =fb n ; and perform the same operation on each output channel of the layer, so as to determine the corresponding bit width according to the distribution of each channel. In other words, in order to improve the acceleration effect of SIMD, it is hoped that conv(W q ,F q ) is less than 16 bits. When wb = 8, fb = 8, the above equation shows that conv(W q ,F q ) result is less than 16 bits, then conv(W sqf ,F uqf ) must be less than 1.0. Without changing wb, you can change the size of fb to adjust conv(W sqf ,F uqf ) results, thereby achieving adaptive adjustment of the bit width of activation quantization.
[0042] Specifically, the method includes performing full-precision model training:
[0043] 1. Data quantization: quantize the data to be quantized according to the formula shown to obtain low-bit data:
[0044] As shown in the following formula group 1 composed of signed and unsigned quantization:
[0045] Signed quantization:
[0046] W f =min(max(W f ,-max w ),max w )
[0047]
[0048] W q =clamp(-2 b-1 ,2 b-1 -1,W int )
[0049] Unsigned quantization:
[0050] W f =min(max(W f ,0),max w )
[0051]
[0052] W q =clamp(0,2 b -1,W int )
[0053] Variable Description: W f For full precision data, it is an array. q For the simulated quantized data, max w Full precision data W f The maximum value in , b is the bit width after quantization.
[0054] 2. The data passed to the next layer when training the low-bit model is as shown in Formula Group 2:
[0055]
[0056] For the model with Relu6 activation, the result of the quantized post-convolution is shown in Formula 3:
[0057]
[0058] 3. During inference, SIMID acceleration is used to accelerate the convolution operation. According to the characteristics of SIMID, if the result of convolution accumulation is saved in 16 bits, it will be twice as fast as saving the accumulated result in 32 bits. From formula group 1 and formula 3, it can be seen that without changing the weight channel, reducing the activation bit width can reduce the situation where the convolution accumulation result exceeds 16 bits. Therefore, according to formula 3, if conv(W sqf ,F uqf )>1.0, reduce the activated quantization bit width until conv(W sqf ,F uqf )≤1.0. And the same operation can be performed on each output channel of the layer, so as to determine the corresponding bit width according to the distribution of each channel.
[0059] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for adaptively adjusting activation quantization bit width, characterized in that: The method comprises the following steps: S1, data quantization: quantize the data to be quantized to obtain low-bit data; S2, the data passed to the next layer when training the low-bit model, uses the Relu6 model for activation and quantizes the convolution. The result is: This equation is to illustrate conv(W sqf ,F uqf ) and conv(W q ,F q ), where wb and fb are the quantization bit widths of the weight and feature map, respectively. sqf is the weight data quantized to low bits and normalized to [-1 to 1], F uqf is the data quantized to the last bit and normalized to [-1 to 1], W q ,F q Quantize weights and feature maps to low-bit data respectively; S3, during inference, without changing the weight channels, reducing the activation bit width can reduce the situation where the convolution accumulation result exceeds 16 bits. If conv(W sqf ,F uqf )>1.0, reduce the activated quantization bit width until conv(W sqf ,F uqf )≤1.0; and perform the same operation on each output channel of the layer, so as to determine the corresponding bit width according to the distribution of each channel; and use SIMD acceleration to accelerate the convolution operation.
2. The method for adaptively adjusting the activation quantization bit width according to claim 1, characterized in that: The step S1 includes: 1), signed data quantization: 2), unsigned data quantization: Variable Description: W f For full precision data, it is an array. q For the simulated quantized data, max w is the full precision data W f The maximum value in , b is the bit width after quantization.
3. The method for adaptively adjusting the activation quantization bit width according to claim 1, characterized in that: In step S2, the data transmitted to the next layer is: If there is a symbol If unsigned.
4. The method for adaptively adjusting the activation quantization bit width according to claim 1, characterized in that: The formula of Relu6 is as follows: relu6(x)=min(max(x,0),6)∈[0,6].
5. The method for adaptively adjusting the activation quantization bit width according to claim 1, characterized in that: The operation in step S3 can be completed during model training, that is, when training the model, conv(W sqf ,F uqf )>1.0 then the n+1th step fb n+1 =fb n -1, if conv(W sqf ,F uqf )≤1.0, then the n+1th step fb n+1 =fb n .
6. The method for adaptively adjusting the activation quantization bit width according to claim 1, characterized in that: The method performs full-precision model training.
