A Neural Network Quantization Method for Solving Regression Problems

By quantifying and simplifying the multiplication operation and activation function of the regression neural network, designing a nonlinear activation function that is easy to implement in hardware, and using shift operations and Straight-Through Estimator during the training process, the problems in hardware implementation of the regression neural network are solved. Resource overhead and speed issues are achieved to achieve efficient hardware computing.

CN114676826BActive Publication Date: 2024-09-24HUNAN PEISEN ELECTRONIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210436486.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-25
Publication Date
2024-09-24
Estimated Expiration
2042-04-25

AI Technical Summary

Technical Problem

When implementing regression neural networks in hardware, due to the large hardware overhead and time delay of multiplication operations and nonlinear activation functions, the hardware equipment area and power consumption increase, the calculation speed is slow, and the numerical accuracy requirements are high, which hinders its application in edge devices. deployment on.

Method used

In the training phase, the multiplication operations and activation functions of the regression neural network are quantified and simplified, a nonlinear activation function is designed that is easy to implement in hardware, and floating-point weight values ​​and bias values ​​are quantified, and shift operations are used to replace multiplication operations. Use Straight-Through Estimator to directly propagate the gradient of quantized data during the training process.

Benefits of technology

It greatly reduces hardware resource overhead while ensuring calculation accuracy, improves the calculation speed of regression neural networks, facilitates deployment to semi-customized or fully customized hardware platforms, and reduces the cost and complexity of hardware implementation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114676826B
    Figure CN114676826B
Patent Text Reader

Abstract

The present invention relates to the field of neural network technology, and discloses a neural network quantization method for solving regression problems. The present invention first obtains a training data set; then designs a nonlinear activation function that is easy to implement in hardware; then pre-trains a 32-bit floating-point fully connected layer neural network model based on the activation function; calls the pre-trained model, quantizes the floating-point weight value into the form of an integer power of 2, and performs fixed-point quantization on the floating-point bias value, the floating-point input and output of each layer, and the input and output of the activation function; finally, the quantized network model is trained using back propagation and gradient descent algorithms. The present invention uses a shift-sum operation to replace the multiplication operation in the neural network, and uses a circuit to implement a simple activation function. While ensuring the fitting accuracy of the network model, it greatly reduces the amount of calculation during model reasoning, facilitates the hardware implementation of the network model, and also speeds up the calculation speed of the regression neural network.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of neural network technology, and in particular to a neural network quantization method for solving regression problems. Background Art

[0002] With the rapid development of artificial intelligence technology, neural networks are not only widely used in classification tasks such as image recognition, target detection, and natural language processing, but are also used by more and more researchers to solve regression prediction problems in physics, chemistry, materials, medicine, and other fields. For example, molecular dynamics calculations in condensed matter physics, studies have shown that molecular dynamics calculations based on neural networks are 4 to 6 orders of magnitude faster than traditional methods. However, both multiplication operations and nonlinear activation functions in neural network models require a lot of hardware overhead and a large time delay. At the same time, compared with classification neural networks, recurrent neural networks have higher requirements for numerical accuracy. Therefore, when implementing the recurrent neural network model in hardware, greater hardware overhead is required to ensure calculation accuracy, which will result in a larger area and power consumption of the hardware equipment and a slower calculation speed. On the one hand, it increases the manufacturing cost of hardware design, and on the other hand, it also hinders the deployment of recurrent neural networks on edge devices.

[0003] In order to solve the above problems, there is an urgent need for a neural network quantization method for solving regression problems, which can reduce the resource overhead during hardware implementation and improve the speed of hardware calculation while ensuring the calculation accuracy of the regression neural network. Summary of the invention

[0004] The present invention provides a neural network quantization method for solving regression problems, which can solve the problems of the prior art. By quantizing and simplifying the multiplication operation and activation function in the regression neural network during the training phase, the purpose of facilitating hardware implementation, reducing hardware resource overhead, and improving hardware calculation speed is achieved. The technical solution to achieve the purpose of the present invention is:

[0005] A neural network quantization method for solving regression problems, the steps are as follows:

[0006] S1, obtaining a training data set, where the training data set includes sample data X and corresponding labels Y.

[0007] S2, design a nonlinear activation function A() that is easy to implement in hardware.

[0008] S3, based on the activation function A() and the training set in S1, pre-train a 32-bit floating-point fully connected layer neural network model M 1 .

[0009] S4, calls M in S3 1The model is constructed by quantizing the floating-point weight values ​​of the model into the form of integer powers of 2, and the floating-point bias values ​​of the model, the floating-point inputs and outputs of each layer, and the inputs and outputs of the activation function are fixed-point quantized to obtain the quantized neural network M. 2 .

[0010] S5, input the training set into the quantized network model M in S4 2 , using the back propagation and gradient descent of the loss function, the model M 2 Conduct training.

[0011] Furthermore, in S1, the sample data X in the training set includes but is not limited to a feature data set suitable for network training obtained by changing the original data.

[0012] Furthermore, in S2, the expression of the designed nonlinear activation function A() that is easy to implement in hardware is (but not limited to):

[0013]

[0014] A() has a similar function graph to the hyperbolic tangent activation function. When the network model is implemented in hardware, the division operation in A() is replaced by a right shift operation.

[0015] Furthermore, in S3, the fully connected layer neural network model M 1 It consists of an input layer, a hidden layer, and an output layer. The calculation formula of the hidden layer is shown in formula (2), which includes a matrix multiplication operation and a nonlinear activation function A(). The calculation formula of the output layer is shown in formula (3):

[0016] X i =A(X i-1 W i +B i ) (2)

[0017] X l =X l-1 W l +B l (3)

[0018] Among them, l represents the number of layers of the neural network; X i represents the output of the i-th layer; X i-1 represents the input of the i-th layer (also the output of the i-1-th layer); W i is the weight of the i-th layer; B i is the bias of the i-th layer.

[0019] Furthermore, in S3, the loss function used in model training is the mean square error loss function, which is expressed as formula (4):

[0020]

[0021] Where N is the number of samples; Y i is the label value in the training set; is the predicted value of the network model.

[0022] Furthermore, in S4, the quantization formula of the floating-point weight value is shown in formula (5):

[0023]

[0024] Among them, w represents the weight value before quantization; w q Indicates the quantized weight value; Q K () represents the quantization function; K represents the quantized w q Contains the sum of K integer powers of 2; n k is an exponent whose value range is an integer; s represents the positive or negative value of the weight w, whose value range is {-1, 0, 1}. When K is 1, the expression of the quantization function Q(w) is shown in formula (6):

[0025]

[0026] When the network model is implemented in hardware, the multiplication operation between the layer input value and the weight is directly replaced by a shift-and-sum operation with a base of 2, as shown in formula (7):

[0027]

[0028] Among them, x q represents the quantized layer input; P(x,n) represents the shift function, which is expressed as shown in formula (8):

[0029]

[0030] Furthermore, in S4, the fixed-point quantization formula used for the model's floating-point bias value, each layer's floating-point input and output, and the input and output of the activation function is as shown in formula (9):

[0031]

[0032] Where a represents the 32-bit floating point number to be quantized; a q Represents the quantized value; round() represents the rounding operation; m represents the number of decimal places after quantization.

[0033] Furthermore, in S5, in the model M 2In the training phase, Straight-Through Estimator (STE) is used at all quantization operation points, and the gradient of the quantized data is directly used as the gradient of the corresponding floating-point data. Therefore, the gradient of the loss function with respect to the weight matrix is:

[0034]

[0035] Among them, L is the loss function; W is the weight matrix; W q is the quantized weight matrix. The loss function used in the training phase is also the mean square error loss function, and its expression is shown in formula (4).

[0036] Furthermore, the model M 2 The quantization parameters in are already near the optimal solution, so training M 2 A smaller learning rate is used when training to avoid the loss function directly crossing the global optimal solution due to excessive learning rate during continued training. 2 The number of training steps is also less than that of model M 1 The number of training steps.

[0037] Compared with the prior art, the present invention has the significant advantage that, for a neural network that solves a regression problem, the present invention can greatly reduce the amount of computation during reasoning by quantizing the regression neural network model during the training phase while ensuring the fitting accuracy, making it easier to deploy the network model to a semi-customized or fully-customized hardware platform, greatly reducing hardware resource overhead and accelerating the calculation speed of the regression neural network. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is an operation flow chart of the present invention;

[0039] Figure 2 It is the image of the activation function A() and the hyperbolic tangent function Tanh() designed in the embodiment of the present invention;

[0040] Figure 3 is a schematic diagram of the structure of a fully connected layer neural network in an embodiment of the present invention;

[0041] Figure 4 It is a comparison of the quantization model fitting accuracy with the pre-training model fitting accuracy for different K values ​​in the embodiment of the present invention. DETAILED DESCRIPTION

[0042] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0043] The present invention relates to a neural network quantization method for solving regression problems, such as Figure 1As shown, the method first obtains a training data set, which includes sample data and corresponding labels; then designs a nonlinear activation function that is easy to implement in hardware, and pre-trains a 32-bit floating-point fully connected layer neural network model based on the activation function; calls the pre-trained model, quantizes the floating-point weight value into the form of an integer power of 2, and performs fixed-point quantization on the model's floating-point bias value, each layer's floating-point input and output, and the input and output of the activation function to obtain a quantized neural network; finally, the quantized network model is trained using back propagation and gradient descent algorithms, and the final model is saved. Next, the atomic force fitting of the silicon (Si) system in the field of molecular dynamics calculation is used as an example for specific description:

[0044] 1. Obtain a training data set for the Si system, which includes feature data obtained by coordinate transformation of Si atoms and corresponding three-dimensional forces.

[0045] 2. Design a nonlinear activation function A() that is easy to implement in hardware, whose expression is (but not limited to):

[0046]

[0047] A() has a similar function graph to the hyperbolic tangent activation function Tanh(), such as Figure 2 As shown in the figure. In hardware implementation, the division operation in A() is replaced by a right shift operation by two bits, so the most complex circuit implementation part in A() is only a multiplier. Compared with the circuit implementation of the hyperbolic tangent activation function Tanh(), A() can save a lot of hardware overhead.

[0048] 3. Based on the activation function A() and the training set of the Si system, pre-train a 32-bit floating-point fully connected layer neural network model M 1 .

[0049] like Figure 3 As shown, the network model M 1 It consists of an input layer, a hidden layer, and an output layer. The calculation formula of the hidden layer is shown in formula (2), which includes a matrix multiplication operation and a nonlinear activation function A(). The calculation formula of the output layer is shown in formula (3):

[0050] X i =A(X i-1 W i +B i ) (2)

[0051] X l =X l-1 W l +B l (3)

[0052] Among them, l represents the number of layers of the neural network; X i represents the output of the i-th layer; X i-1 represents the input of the i-th layer (also refers to the output of the i-1-th layer); W i is the weight of the i-th layer; B i is the bias of the i-th layer.

[0053] The loss function used in the pre-training stage is the mean square error loss function, which is expressed as formula (4):

[0054]

[0055] Where N is the number of samples; Y i is the label value in the training set; is the predicted value of the network model.

[0056] The learning rate used in the pre-training phase is 0.01.

[0057] 4. Call M 1 The model is constructed by quantizing the floating-point weight values ​​of the model into the form of integer powers of 2, and the floating-point bias values ​​of the model, the floating-point inputs and outputs of each layer, and the inputs and outputs of the activation function are fixed-point quantized to obtain the quantized neural network M. 2 .

[0058] The quantization formula of floating-point weight value is shown in formula (5):

[0059]

[0060] Among them, w represents the weight value before quantization; w q Indicates the quantized weight value; Q K () represents the quantization function; K represents the quantized w q Contains the sum of K integer powers of 2; n k is an exponent whose value range is an integer; s represents the positive or negative value of the weight w, whose value range is {-1, 0, 1}. When K is 1, the expression of the quantization function Q(w) is shown in formula (6):

[0061]

[0062] When the network model is implemented in hardware, the multiplication operation between the layer input value and the weight is directly replaced by a shift-and-sum operation with a base of 2, as shown in formula (7):

[0063]

[0064] Among them, x q represents the quantized layer input, P(x,n) represents the shift function, which is expressed as shown in formula (8):

[0065]

[0066] For this embodiment, the Si atom force fitting accuracy obtained by taking K values ​​of 1, 2, 3, 4, and 5 is compared with the fitting accuracy of the pre-trained model. Figure 4 As shown in the figure. When K = 3, the quantized model of the continued training has achieved the same fitting accuracy as the pre-trained 32-bit floating-point model. Increasing the value of K will not improve the accuracy much, but will increase the resource overhead of hardware implementation. Considering the fitting accuracy and hardware overhead of the model, K = 3 is the best.

[0067] At the same time, the floating-point bias values ​​in the model, the floating-point input and output of each layer, and the input and output of the activation function are quantized. The quantization formula is shown in formula (9):

[0068]

[0069] Where a represents the 32-bit floating point number to be quantized; a q represents the quantized value; round() represents the rounding operation; m represents the number of decimal places after quantization. In this embodiment, the value of m is 10.

[0070] 5. Input the training set of Si system into the quantized network model M 2 , using the back propagation and gradient descent of the loss function, the model M 2 Conduct training.

[0071] In model M 2 In the training phase, Straight-Through Estimator (STE) is used at all quantization operation points, and the gradient of the quantized data is directly used as the gradient of the corresponding floating-point data. Therefore, the gradient of the loss function with respect to the weight matrix is:

[0072]

[0073] Among them, L is the loss function; W is the weight matrix; W q is the quantized weight matrix.

[0074] The loss function used in the continued training stage is also the mean square error loss function, and its expression is as shown in formula (4). The learning rate used in the continued training stage is 0.0001.

[0075] In summary, the embodiments of the present invention are directed to a neural network for solving regression problems. By quantizing the regression neural network model in the training stage, replacing complex multiplication operations with shift operations, and designing a circuit to implement a simple nonlinear activation function, the amount of calculation during reasoning can be greatly reduced while ensuring the fitting accuracy of the network model. This makes it easier to deploy the network model to a semi-customized or fully-customized hardware platform, thereby reducing hardware resource overhead and speeding up the calculation speed of the regression neural network.

[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention, rather than to limit the protection scope of the present invention. With reference to the description of the embodiment, ordinary technicians in the field should be able to understand and make relevant modifications or replacements to the technical solution of the present invention without departing from the essence and scope of the present invention.

Claims

1. A neural network quantization method for solving regression problems, characterized in that: The following steps are involved: S1, obtaining a training data set, wherein the training data set includes sample data X and corresponding labels Y; The sample data X in the training set includes but is not limited to a feature data set suitable for network training obtained by changing the original data; S2, design a nonlinear activation function A() that is easy to implement in hardware; The expression of the nonlinear activation function A() can be but is not limited to: A() has a similar function graph to the hyperbolic tangent activation function. When implementing the hardware of the network model, a right shift operation is used to replace the division operation in A(); It can be other odd functions. When -2 < x < 2, the function value range is (-1, 1), and the coefficient divided in the expression should be a multiple of 2 so that a shift operation can be used for hardware implementation; S3, based on the activation function A() and the training set in S1, pre-train a 32-bit floating point fully connected layer neural network model M1; The fully connected neural network model M1 consists of an input layer, a hidden layer, and an output layer. The calculation formula of the hidden layer is shown in formula (2), including a matrix multiplication operation and a nonlinear activation function A(). The calculation formula of the output layer is shown in formula (3): X i =A(X i-1 W i +B i ), (2) X l =X l-1 W l +B l , (3) Among them, l represents the number of layers of the neural network, X i represents the output of the i-th layer, X i-1 represents the input of the i-th layer and the output of the i-1-th layer, X i is the weight of the i-th layer, B i is the bias of the i-th layer; The loss function used in the training of the fully connected layer neural network model M1 is the mean square error loss function, which is expressed as formula (4): Where N is the number of samples, Y i is the label value in the training set, is the predicted value of the network model; S4, calling the M1 model in S3, quantizing the floating-point weight values ​​of the model into the form of integer powers of 2, and performing fixed-point quantization on the floating-point bias values ​​of the model, the floating-point inputs and outputs of each layer, and the inputs and outputs of the activation function, to obtain the quantized neural network M2; The quantization formula used for the floating-point weight value quantization is shown in formula (5): Among them, w represents the weight value before quantization, w q Represents the quantized weight value, Q K () represents the quantization function, K represents the quantized w q Contains the sum of K integer powers of 2, n k is an exponent whose value range is an integer, s represents the positive or negative value of the weight w, and its value range is {-1, 0, 1}; when K is 1, the expression of the quantization function Q(w) is shown in formula (6): When the network model is implemented in hardware, the multiplication operation between the layer input value and the weight is directly replaced by a shift-and-sum operation with a base of 2, as shown in formula (7): Among them, x q represents the quantized layer input, P(x,n) represents the shift function, which is expressed as shown in formula (8): The fixed-point quantization formula used for the floating-point bias value of the model, the floating-point input and output of each layer, and the input and output of the activation function is shown in formula (9): Among them, a represents the 32-bit floating point number to be quantized, a q Represents the quantized value, round() represents the rounding operation, and m represents the number of decimal places after quantization; S5, inputs the training set into the quantized network model M2 in S4, and trains the model M2 using back propagation and gradient descent of the loss function; In the training phase of the model M2, the Straight-Through Estimator (STE) is used at all quantization operation points, and the gradient of the quantized data is directly used as the gradient of the corresponding floating-point data. Therefore, the gradient of the loss function to the weight matrix is: Among them, L is the loss function, W is the weight matrix, and W q is the quantized weight matrix; the loss function used in the training phase is also the mean square error loss function, and its expression is as shown in formula (4); The quantization parameters in the model M2 are already near the optimal solution, so a smaller learning rate is used when training M2 to avoid the loss function directly crossing the global optimal solution due to an excessively large learning rate during continued training. At the same time, the number of training steps for the model M2 is also less than that for the model M1. S6, deploys the trained network model M2 to a semi-customized or fully-customized hardware platform.