Data processing method, medium and electronic device for neural network model
By adjusting the quantization parameters, the accuracy problem caused by the difference in floating-point domain and fixed-point domain values during the quantization process of the ThresholdReLU activation function in the neural network model is solved, and higher model operation accuracy is achieved.
Patent Information
- Application Number
- CN202210556167.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-20
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2042-05-20
AI Technical Summary
In the neural network model, during the quantization process of the ThresholdReLU activation function, due to the difference in values between the floating-point domain and the fixed-point domain, some data are not 0 in the floating-point domain but are 0 in the fixed-point domain, affecting the accuracy of the model operation. .
By adjusting quantization parameters and using post-quantization parameters to quantize floating-point data, we ensure that the corresponding floating-point value of fixed-point output data in the fixed-point domain is not 0, thereby improving the accuracy of model operation.
It effectively avoids errors due to the quantification process and improves the accuracy of the operating results of the neural network model in image, audio, text, and video data processing.
Smart Images

Figure CN114841325B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a data processing method, medium and electronic device for a neural network model. Background Art
[0002] With the development of artificial intelligence (AI), neural network models are increasingly used in the field of artificial intelligence. For example, they are used in image recognition, target detection, reinforcement learning, information recommendation, user behavior prediction and other application scenarios. Since neural networks are resource-intensive algorithms with high computational costs and memory consumption, in order to reduce the number of parameters in the neural network model, the amount of computation during computer operation, and reduce computational costs and memory usage, it is usually necessary to quantize the neural network model, convert the high-precision floating-point operations in the neural network model into fixed-point operations, and obtain a neural network model with fixed-point operations. The Threshold Rectified Linear Unit (ThresholdReLU) activation function is a commonly used activation function and is widely used in neural network models, such as performing nonlinear activation operations in the activation layer operator of a neural network. Therefore, when quantizing a neural network model, the quantization of the ThresholdReLU activation function is often involved.
[0003] During the operation of the neural network model, since the values of some data to be subjected to the ThresholdReLU activation operation in the floating-point domain are greater than the threshold parameter of the ThresholdReLU activation operation, but the values in the fixed-point domain are equal to the threshold parameter of the ThresholdReLU activation operation, the result of the ThresholdReLU activation operation in the floating-point domain for these data to be subjected to the ThresholdReLU activation operation is not 0, while the floating-point value corresponding to the fixed-point result obtained by the ThresholdReLU activation operation in the fixed-point domain is 0, which in turn affects the accuracy of the running results of the neural network model. Summary of the invention
[0004] To solve the above problems, the present application provides a data processing method, medium and electronic device for a neural network model.
[0005] In a first aspect, an embodiment of the present application provides a data processing method of a neural network model, which is applied to an electronic device and is characterized by comprising:
[0006] Determine the floating point data to be processed in the neural network model;
[0007] quantizing the floating-point data to obtain a fixed-point number by using a post-quantization parameter, wherein the post-quantization parameter is determined according to a preset floating-point threshold parameter;
[0008] The fixed-point number is used as fixed-point input data of a first threshold rectified linear unit (ThresholdRectified Linear Unit, ThresholdReLU) activation operation included in the neural network model to obtain fixed-point output data, wherein the first ThresholdReLU activation operation is associated with a post-quantization parameter.
[0009] It can be understood that in the embodiment of the present application, the post-quantization parameter is the second quantization parameter, the preset floating-point threshold parameter is a threshold parameter pre-set in the floating-point domain, and the first ThresholdReLU activation operation is a ThresholdReLU activation operation performed in the fixed-point domain.
[0010] It can be understood that the data processing method of a neural network model provided in the embodiment of the present application uses a post-quantization parameter to quantize the floating-point data to obtain a fixed-point number, and uses the fixed-point number as the fixed-point input data of the first ThresholdReLU activation operation included in the neural network model to obtain fixed-point output data. In this way, by simply adjusting the quantization parameter in the quantization method, it is convenient to avoid the situation in which the output result of the ThresholdReLU activation operation is greater than the floating-point threshold parameter and the floating-point data greater than 0 is obtained during the operation of the neural network model. Since the fixed-point value obtained after quantization is not greater than the fixed-point value obtained after quantization of the floating-point threshold parameter, the floating-point value corresponding to the output result obtained in the fixed-point domain is 0; it also realizes the fixed-point number obtained by quantizing the floating-point data greater than the threshold parameter through the post-quantization parameter, and the fixed-point threshold parameter obtained by quantizing the floating-point data greater than the floating-point threshold parameter using the post-quantization parameter, so that the floating-point value corresponding to the fixed-point output data obtained by the ThresholdReLU activation operation in the fixed-point domain is not 0, thereby improving the accuracy of the operation results of the neural network model.
[0011] In a possible implementation of the first aspect, the post-quantization parameter is determined according to a floating-point threshold parameter and a pre-quantization parameter.
[0012] It can be understood that in the embodiment of the present application, the front quantization parameter is the first quantization parameter.
[0013] It can be understood that in the embodiment of the present application, the post-quantization parameter is determined according to the floating-point threshold parameter and the pre-quantization parameter, that is, the post-quantization parameter can be determined by only knowing the floating-point threshold parameter and the pre-quantization parameter, and the logic is simple.
[0014] In a possible implementation of the first aspect, the post-quantization parameter is determined by the following method, including:
[0015] Determine a pre-quantization parameter according to the range of floating-point data to be processed in the neural network model and the data type of the fixed-point number;
[0016] A post-quantization parameter is obtained according to a pre-quantization parameter and a floating-point threshold parameter.
[0017] It can be understood that in the embodiment of the present application, the pre-quantization parameter is determined according to the range of the floating-point data to be processed in the neural network model and the data type of the fixed-point number, and then the post-quantization parameter is obtained according to the pre-quantization parameter and the floating-point threshold parameter. This reflects the correlation between the pre-quantization parameter and the post-quantization parameter, and enables a better understanding of the difference and connection between the post-quantization parameter and the pre-quantization parameter.
[0018] In a possible implementation of the first aspect, obtaining the post-quantization parameter according to the pre-quantization parameter and the floating-point threshold parameter includes:
[0019] quantizing the floating-point threshold parameter according to the previous quantization parameter to obtain a first fixed-point threshold parameter;
[0020] A post-quantization parameter is obtained according to the first fixed-point threshold parameter and the floating-point threshold parameter.
[0021] It can be understood that in the embodiment of the present application, the floating-point threshold parameter is quantized to obtain the first fixed-point threshold parameter according to the pre-quantization parameter, and then the post-quantization parameter is obtained according to the first fixed-point threshold parameter and the floating-point threshold parameter. The relationship between the first fixed-point threshold parameter and the post-quantization parameter can be analyzed, which is conducive to discussing how to quickly obtain the post-quantization parameter when the first fixed-point threshold parameter has different parities.
[0022] In a possible implementation of the first aspect, obtaining the post-quantization parameter according to the first fixed-point threshold parameter and the floating-point threshold parameter includes:
[0023] When the first fixed-point threshold parameter is an odd number, a post-quantization parameter is obtained according to an odd quantization parameter formula, wherein the odd quantization parameter formula includes the first fixed-point threshold parameter and a floating-point threshold parameter;
[0024] When the first fixed-point threshold parameter is an even number, a post-quantization parameter is obtained according to an even quantization parameter formula, wherein the even quantization parameter formula includes the first fixed-point threshold parameter and a floating-point threshold parameter.
[0025] It can be understood that in the embodiments of the present application, due to the specific rounding operation in the process of quantizing floating-point data into fixed-point numbers, the first fixed-point threshold parameter can use the corresponding odd quantization parameter formula and the even quantization parameter formula when the parity is different. Therefore, according to the different parities of the first fixed-point threshold parameter, there are corresponding odd quantization parameter formulas and even quantization parameter formulas, and then the corresponding post-quantization parameters can be obtained in a targeted and accurate manner, providing a variety of acquisition methods for obtaining the post-quantization parameters.
[0026] In a possible implementation of the first aspect, the first fixed-point threshold parameter and the floating-point threshold parameter are used to obtain a post-quantization parameter, including:
[0027] A post-quantization parameter is obtained according to a combined quantization parameter formula, wherein the combined quantization parameter formula includes a first fixed-point threshold parameter and a floating-point threshold parameter.
[0028] It can be understood that in the embodiment of the present application, the odd quantization parameter formula and the even quantization parameter formula are combined according to the combined quantization parameter formula, so that the post-quantization parameter can be obtained more directly without considering the parity of the first fixed-point threshold parameter.
[0029] In a possible implementation of the first aspect, the first ThresholdReLU activation operation is determined according to a post-quantization parameter and a floating-point threshold parameter.
[0030] It can be understood that in the embodiment of the present application, the first ThresholdReLU activation operation is determined according to the post-quantization parameter and the floating-point threshold parameter, that is, only the floating-point threshold parameter and the post-quantization parameter need to be known to determine the first ThresholdReLU activation operation, and the logic is simple.
[0031] In a possible implementation of the first aspect, the first ThresholdReLU activation operation is determined by the following method, including:
[0032] quantizing the floating-point threshold parameter according to the post-quantization parameter to obtain a second fixed-point threshold parameter;
[0033] A ThresholdReLU activation function for performing a first ThresholdReLU activation operation is obtained according to the second fixed-point threshold parameter.
[0034] It can be understood that in the embodiments of the present application, the floating-point threshold parameter is quantized according to the post-quantization parameter to obtain the second fixed-point threshold parameter. The method of obtaining the second fixed-point threshold parameter is the same as the method of quantizing the floating-point data to be processed, which is logically scientific. The ThresholdReLU activation function for performing the first ThresholdReLU activation operation can be obtained according to the second fixed-point threshold parameter, which has simple logic and is convenient for expansion and application.
[0035] In a possible implementation of the first aspect, the range of floating-point data to be processed in the neural network model is determined during the operation of the neural network model.
[0036] It can be understood that in the embodiment of the present application, the range of the floating-point data to be processed can be obtained by running the neural network model, and the acquisition method is convenient.
[0037] In a possible implementation of the first aspect, the data type of the fixed-point number includes at least one of the following: int32, int16, int8, int4, uint32, uint16, uint8 or uint4.
[0038] It can be understood that in the embodiments of the present application, the data type of the fixed-point number can include multiple data types, making the application more extensive.
[0039] In a possible implementation of the first aspect above, the floating-point data to be processed in the above neural network model is obtained based on at least one of image data, audio data, text data, and video data.
[0040] It can be understood that in the embodiments of the present application, the neural network has the functions of self-learning, associative storage, and efficient search for optimized solutions, and can process image data, audio data, text data, and video data well.
[0041] In a possible implementation of the first aspect, the quantization is symmetric quantization.
[0042] It can be understood that in the embodiments of the present application, the use of symmetric quantization to quantize floating-point data into fixed-point data can speed up the calculation speed of the neural network model and reduce device power consumption.
[0043] In a second aspect, an embodiment of the present application provides a data processing device for a neural network model, including: a first determination unit, configured to determine floating-point data to be processed in the neural network model;
[0044] A first acquisition unit is used to quantize the floating-point data to obtain a fixed-point number by using a post-quantization parameter, wherein the post-quantization parameter is determined according to a preset floating-point threshold parameter;
[0045] The second acquisition unit is used to use the fixed-point number as fixed-point input data of a first ThresholdReLU activation operation included in the neural network model to obtain fixed-point output data, wherein the first ThresholdReLU activation operation is associated with a post-quantization parameter.
[0046] It can be understood that in the embodiment of the present application, the post-quantization parameter is the second quantization parameter, and the first ThresholdReLU activation operation is a ThresholdReLU activation operation performed in the fixed-point domain.
[0047] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, including: a computer-readable storage medium storing instructions, which execute the method described in the first aspect and any one of the various possible implementations of the first aspect on an electronic device.
[0048] In a fourth aspect, an embodiment of the present application provides a computer program product, including: the computer program product includes instructions, and when the instructions are executed by one or more processors, they are used to implement the method described in the first aspect and any one of the various possible implementations of the first aspect.
[0049] In a fifth aspect, an embodiment of the present application provides an electronic device, including:
[0050] memory for storing instructions, and
[0051] One or more processors, when the instructions are executed by the one or more processors, the processors execute the method as described in the first aspect and any one of the various possible implementations of the first aspect.
[0052] Based on the above scheme, this application has the following beneficial effects:
[0053] The present application provides a data processing method for a neural network model, which obtains a post-quantization parameter by adjusting a pre-quantization parameter, quantizes the floating-point data to be processed according to the post-quantization parameter to obtain a fixed-point number, and uses the fixed-point number as the fixed-point input data of the first ThresholdReLU activation operation included in the neural network model to obtain the fixed-point output data. Thus, it can be avoided that when the original quantization parameter is used, due to the use of a rounding function, there is an error in the process of quantizing the floating-point data to the fixed-point data, and the floating-point value corresponding to the fixed-point output data obtained by performing the first ThresholdReLU activation operation that is greater than the floating-point threshold parameter is 0, thereby causing the neural network model to have a large error in the operation result. Moreover, the present application adopts a method of adjusting the quantization parameter, which is relatively simple in logic and easy to operate. It only needs to pay attention to the preset floating-point threshold parameter and the original quantization parameter. In the process of processing image data, audio data, text data, and video data, the accuracy of the results of the operation of the neural network model can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 According to some embodiments of the present application, a schematic diagram of a ThresholdReLU activation function is shown;
[0055] Figure 2 According to some embodiments of the present application, a schematic diagram of symmetric quantization is shown;
[0056] Figure 3 According to some embodiments of the present application, a scene diagram is shown in which the terminal 100 recognizes a collected face image through a face recognition model;
[0057] Figure 4 According to some embodiments of the present application, a relationship diagram between input data and fixed-point input data when a quantization parameter is 2 is shown;
[0058] Figure 5 According to some embodiments of the present application, a flow chart of using an adjusted quantization parameter to obtain a quantized ThresholdReLU activation function is shown;
[0059] Figure 6a According to some embodiments of the present application, a schematic diagram is shown in which the first fixed-point threshold parameter value is an even number;
[0060] Figure 6b According to some embodiments of the present application, a schematic diagram showing a first fixed-point threshold parameter value being an odd number is shown;
[0061] Figure 7aAccording to some embodiments of the present application, a schematic diagram is shown of obtaining a corresponding second fixed-point threshold parameter when the value of the first fixed-point threshold parameter is an even number;
[0062] Figure 7b According to some embodiments of the present application, a schematic diagram of obtaining a corresponding second fixed-point threshold parameter when the first fixed-point threshold parameter value is an odd number is shown;
[0063] Figure 8 According to some embodiments of the present application, a flowchart of neural network model data processing is shown;
[0064] Fig. 9 According to some embodiments of the present application, a schematic diagram of a data processing device for a neural network model is shown;
[0065] Fig.10 According to some embodiments of the present application, a schematic structural diagram of a terminal 100 is shown. DETAILED DESCRIPTION
[0066] The illustrative embodiments of the present application include, but are not limited to, a data processing method, medium, and electronic device of a neural network model.
[0067] In order to more clearly illustrate the solutions of the embodiments of the present application, some terms involved in the embodiments of the present application are explained below.
[0068] Neural network model quantization: Convert floating-point operations in neural network models to fixed-point operations.
[0069] Threshold Rectified Linear Unit (ThresholdReLU) activation function
[0070] The expression of the ThresholdReLU activation function in the floating-point domain is shown in the following formula 1:
[0071]
[0072] Among them, x is the input data of the ThresholdReLU activation function, a is the threshold parameter of the ThresholdReLU activation function (a≥0), and y is the output data of the ThresholdReLU activation function. Figure 1 A schematic diagram of the ThresholdReLU activation function is shown in some embodiments of the present application. For example, if the threshold parameter a is 10.1, if the input data is 10.5, the output data is 10.5, and if the input data is 9.5, the output data is 0.
[0073] Quantization of Threshold Rectified Linear Unit (ThresholdReLU) activation function
[0074] The ThresholdReLU activation function can be quantized by symmetric quantization or asymmetric quantization. In this application, the quantization method discussed is to quantize the ThresholdReLU activation function by symmetric quantization to obtain the quantized ThresholdReLU activation function.
[0075] For ease of understanding, the symmetric quantization method is first introduced below.
[0076] Symmetric Quantization:
[0077] Set the range to [X min , X max ] is mapped into a floating point number X in the range [Q min , Q max Fixed-point number Q within ]:
[0078] Q = round (X / S) (Formula 2)
[0079] Among them, the fixed-point number Q is a signed integer (integral numeric types, int), and its range is [Q min , Q max ]Specifically [-2 n-1 , 2 n-1 -1], where n is the number of quantized bits. For example, if the fixed-point number Q is of type int8, then [Q min , Q max ] is specifically [-128, 127], such as Figure 2 As shown, the floating point number X is quantized to a fixed point number in the range [-128, 127].
[0080] The round() function is a rounding function that rounds the value of X / S so that the obtained value is an integer. In some embodiments of the present application, the rounding rule of the round() function can be: let the largest integer less than the value of X / S be A, when the value of X / S is greater than the value of A+0.5, the value of round(X / S) is A+1; when the value of X / S is less than the value of A+0.5, the value of round(X / S) is A; when the value of X / S is equal to the value of A+0.5, round(X / S) is the closest even number to X / S. Specifically, when the value of X / S is equal to the value of A+0.5 and A is an even number, the value of round(X / S) is A; when the value of X / S is equal to the value of A+0.5 and A is an odd number, the value of round(X / S) is A+1. For example, if the value of X / S is 1.5, the value of round(X / S) is 2, which is the closest even number to 1.5. For another example, if the value of X / S is 3.5, the value of round(X / S) is 4, which is the closest even number to 3.5. It is understandable that in other embodiments, other rounding rules can be used to achieve the same result as the rounding rule of the round() function, which will not be described in detail here. It is understandable that in other implementations, the rounding function can also be a ceil() upward rounding function.
[0081] S is a quantization parameter for quantizing a floating-point number to a fixed-point number, and is the minimum scale for quantizing different floating-point numbers X to the same fixed-point number Q. S can be obtained according to a quantization parameter formula, such as the formula 3 below, or can be obtained by other modified formulas, which are not specifically limited here. The max() function in formula 3 is a maximum value function. |*| is an absolute value. It can be understood that for a fixed-point number, the floating-point number corresponding to the fixed-point number can be determined according to inverse quantization. In some embodiments, the above formula 2 is deformed to obtain an inverse quantization formula 2', and the floating-point number corresponding to the fixed-point number is obtained according to formula 2'.
[0082]
[0083] X=Q*S(Formula 2')
[0084] According to formula 1, it can be found that the quantization of the ThresholdReLU activation function requires the quantization of the input data x, threshold parameter a, and output data y in the activation function. The fixed-point numbers obtained by quantizing the input data x, threshold parameter a, and output data y are recorded as fixed-point input data x and y. q , fixed-point threshold parameter a q , fixed-point output data y q .
[0085] In some implementations, the input data x, the threshold parameter a, and the output data y are symmetrically quantized to obtain fixed-point input data x andq , fixed-point threshold parameter a q , fixed-point output data y q As can be understood, the fixed-point threshold parameter a q , fixed-point input data x q And fixed-point output data y q There is a relationship between the three as shown in the following formula 4.
[0086] It should be explained that in the following formula 4, the data type of the fixed-point input data is the same as that of the fixed-point output data, and the quantization parameter Sa in the symmetric quantization corresponding to the threshold parameter a, the quantization parameter Sy in the symmetric quantization corresponding to the output data y, and the quantization parameter Sx corresponding to the input data x are the same. Therefore, for the convenience of explanation, the quantization parameter Sa, the quantization parameter Sy, and the quantization parameter Sx are collectively referred to as the quantization parameter S below.
[0087] The quantized ThresholdReLU activation function may be a modified formula of Formula 4, and the specific form is not specifically required here.
[0088]
[0089] According to formula 4, the received fixed-point input data x q With the fixed-point threshold parameter a q Compare to get the fixed-point output data y q For example, the fixed-point threshold parameter a q is 10, if the fixed-point input data x q is 11, then the fixed-point output data y q is 11, if the fixed-point input data x q is 9, then the fixed-point output data y q is 0.
[0090] In order to better understand this solution, an application scenario of the technical solution of this application will be first introduced below.
[0091] Figure 3 FIG. 1 shows a scene diagram in which the terminal 100 recognizes a collected face image through a face recognition model. Figure 3 As shown, the terminal 100 is deployed with a face recognition model quantized by the server 200. After the terminal 100 collects the face image of the user, the quantized face recognition model can be used to perform face recognition on the collected face image, thereby obtaining a face recognition result.
[0092] Usually, in order to reduce the amount of data, the above-mentioned face recognition model will be quantized. For example, the server 200 quantizes the trained face recognition model, and then deploys the quantized face recognition model (hereinafter referred to as the quantized model) to the terminal device 100. In the process of using the quantized model for face recognition by the terminal 100, the activation layer operator usually involves using the quantized ThresholdReLU activation function to perform activation operations. After receiving the floating-point data to be activated by the ThresholdReLU activation operation, the floating-point data is quantized in the same way as the quantized ThresholdReLU activation function is obtained to obtain fixed-point data, and then the obtained fixed-point data is used as the fixed-point input data of the ThresholdReLU activation function, thereby obtaining the fixed-point output data of the ThresholdReLU activation operation. It can be understood that in the face recognition scenario, the input data for the activation operation in the face recognition model can be face image data.
[0093] In some implementations, the server 200 performs multiple model trainings using an unquantized face recognition model in advance, obtains the range of input data for the ThresholdReLU activation operation required in the quantization formula, substitutes the range of the obtained input data and the range of possible values corresponding to the data type of the fixed-point input data to be quantized into the quantization parameter formula to obtain the quantization parameter S, and quantizes the threshold parameter a according to the quantization parameter S to obtain the fixed-point threshold parameter a. q When the floating-point data to be activated by ThresholdReLU is received, the floating-point data is quantized to obtain fixed-point data according to the obtained quantization parameter S, and the obtained fixed-point data is used as the fixed-point input data x in Formula 4. q and with the fixed-point threshold parameter a q Comparison is performed to obtain fixed-point output data. It can be understood that the obtained fixed-point output data can be dequantized according to the quantization parameter S to obtain corresponding floating-point output data.
[0094] For example, for the threshold parameter a of the ThresholdReLU activation function, take the value of 4.1 as an example. Figure 3In the scenario shown, the server 200 uses an unquantized face recognition model to perform model training multiple times in advance, and obtains the input data range of the ThresholdReLU activation function in the floating-point domain of the ThresholdReLU activation function in the face recognition model during the training process is [-6.2, 254.0], the fixed-point input data data type is int8, and the corresponding possible value range is [-128, 127]. The quantization parameter S in the symmetric quantization method is obtained according to formula 3, S = 254.0 / 127 = 2, and the corresponding symmetric quantization formula 2 is Q = round (X / 2). According to the obtained symmetric quantization formula, the input data x and the fixed-point input data x can be obtained. q The relationship between Figure 4 As shown, Figure 4 It shows that when the quantization parameter is 2, the input data x and the fixed-point input data x q The relationship diagram between . The threshold parameter a of value 4.1 is symmetrically quantized to obtain the fixed-point threshold parameter a q =round(4.1 / 2)=2, thus determining the quantized ThresholdReLU activation function. When receiving the floating-point data to be activated by the ThresholdReLU, the floating-point data is quantized to obtain fixed-point data according to the quantization parameter S with a value of 2, and the obtained fixed-point data is used as the fixed-point input data x in Formula 4. q , substitute into formula 4, and get the fixed-point output data y q It can be understood that the obtained fixed-point output data can be dequantized according to Formula 2 to obtain the corresponding floating-point output data.
[0095] However, when the quantized ThresholdReLU activation function is used to activate the floating-point data to be activated during the operation of the face recognition model, there will be some floating-point data to be activated whose output data obtained by using the unquantized ThresholdReLU activation function is not 0, while the floating-point output data corresponding to the fixed-point output data obtained by using the quantized ThresholdReLU activation function is 0, which affects the face recognition results.
[0096] For example, Figure 4 As shown, the threshold parameter a=4.1 corresponds to the fixed-point threshold parameter a q is 2. According to the characteristics of the ThresholdReLU activation function, when the input data x is less than or equal to the threshold parameter a, the output data obtained by the activation operation is 0. When the input data x is greater than the threshold parameter a, the output data obtained by the activation operation is the original value. If during the operation of the face recognition model, the floating-point data to be activated is not only greater than the threshold activation function a, but also the fixed-point input data x obtained after quantizationq With the fixed-point threshold parameter a q The same value, then according to formula 4, we can get, according to the fixed-point input data x q The fixed-point output data y is obtained by q is 0.
[0097] For the convenience of explanation, the fixed-point input data x obtained after quantization is q With the fixed-point threshold parameter a q Input data with the same value is called "same fixed value data"; the fixed-point input data x obtained after quantization is less than or equal to the threshold parameter a q With the fixed-point threshold parameter a q The input data with the same value is called "left-same fixed-value data"; the fixed-point input data x obtained after quantization is greater than the threshold parameter a q With the fixed-point threshold parameter a q The input data with the same value is called “right same-value data”. For the same threshold parameter a, different quantization parameters will result in different same-value data ranges.
[0098] For example Figure 4 The input data in the interval l1 shown in the figure are all fixed value data. The specific range of interval l1 is [3,5]. The fixed point value of the data in this interval after quantization is 2, which is consistent with the fixed point threshold parameter a. q equal; the input data in the interval l2 shown are all fixed value data, the specific range of interval l2 is [3,4.1], which is less than or equal to the value of the threshold parameter a of 4.1. The fixed point value of the data in this interval after quantization is 2, which is equal to the fixed point threshold parameter a q =Equal; the input data in the interval l3 shown are all fixed value data, the specific range of interval l3 is (4.1, 5], which is greater than the value of the threshold parameter a of 4.1. The fixed point value of the data in this interval after quantization is 2, which is equal to the fixed point threshold parameter a. q equal.
[0099] Taking a right-handed fixed-value data 4.3 to be activated in the interval l3 as an example, the fixed-value data 4.3 is symmetrically quantized, specifically calculated as round(4.3 / 2)=2, to obtain fixed-point data 2, and the fixed-point data 2 is used as the fixed-point input data of the quantized ThresholdReLU activation function. According to formula 4, it can be found that since the fixed-point data value 2 is equal to the fixed-point threshold parameter a qThe value is 2, so the fixed-point output data obtained by the quantized ThresholdReLU activation function is 0. The fixed-point output data 0 is dequantized according to formula 2', and the floating-point output data obtained is 0; when the same fixed-value data 4.3 is activated using the unquantized ThresholdReLU activation function, according to formula 1, it can be found that since the same fixed-value data 4.3 is greater than the threshold parameter 4.1, the output data obtained is 4.3. The floating-point output data obtained by fixed-point operation is significantly different from the floating-point output data obtained by floating-point operation, which affects the result of face recognition.
[0100] Therefore, the present application proposes a data processing method for a neural network model, by adjusting the quantization parameter so that the maximum value within the new fixed-value data range is the threshold parameter a, thereby making the fixed-point value obtained by quantizing the original fixed-value data according to the adjusted quantization parameter greater than the fixed-point value obtained by quantizing the threshold parameter according to the adjusted quantization parameter. It can be understood that when the quantization parameter is changed, the fixed-point value obtained by the floating-point data according to the changed quantization parameter can be the same as or different from the fixed-point value obtained according to the original quantization parameter. For the same threshold parameter a, different quantization parameters correspond to different fixed-value data ranges.
[0101] It should be noted that neural network models are widely used in video, voice, image, text, etc. When the neural network model is used in the image aspect, during the operation of the neural network model, the input data for the activation operation can be image data or intermediate data obtained based on the image data, and the output data obtained after the activation operation is the data used for image processing. For example, in the above-mentioned face recognition scenario, during the operation of the face recognition model, the input data for the activation operation can be face image data or intermediate data obtained based on face image data, and the output data obtained after the activation operation is the data used for face image processing; when the neural network model is used in audio and video processing, during the operation of the neural network model, the input data for the activation operation can be audio and video data or intermediate data obtained based on audio and video data, and the output data obtained after the activation operation is the data used for face image processing. The output data obtained after the activation operation is still audio and video data. For example, in the smart home voice recognition scenario, during the operation of the voice recognition model, the input data for the activation operation can be voice data or intermediate data obtained based on voice data, and the output data obtained after the activation operation is data used for voice processing; when the neural network model is used in text processing, during the operation of the neural network model, the input data for the activation operation can be text data or intermediate data obtained based on text data, and the output data obtained after the activation operation is data used for text processing. For example, in the text recognition scenario, during the operation of the text recognition model, the input data for the activation operation can be text data or intermediate data obtained based on text data, and the output data obtained after the activation operation is data used for text processing.
[0102] For example, taking the above example, the quantization parameter S in the symmetric quantization is adjusted to obtain a new quantization parameter S', so that Figure 4 The fixed-point input data in the interval l3 shown in the figure is quantized according to the adjusted quantization parameter S', and the obtained fixed-point input data is greater than the threshold parameter a. The fixed-point threshold parameter a is obtained by quantization according to the adjusted quantization parameter q .
[0103] Specifically, an original quantization parameter (hereinafter referred to as a first quantization parameter) is first obtained, and the threshold parameter a is quantized according to the first quantization parameter to obtain a first fixed-point threshold parameter a q1 ; According to the first fixed-point threshold parameter a q1 The threshold parameter a adjusts the first quantization parameter according to a preset adjustment method to obtain an adjusted quantization parameter (hereinafter referred to as a second quantization parameter), and the threshold parameter a is quantized according to the second quantization parameter to obtain a second fixed-point threshold parameter a q2, where the maximum value of the fixed-value data range corresponding to the second quantization parameter is the threshold parameter a, that is, the right fixed-value data is empty, then the fixed-point value obtained by quantizing the original right fixed-value data according to the second quantization parameter must be greater than the second fixed-point threshold parameter a q2 ; Then according to the second fixed-point threshold parameter a q2 Determine the ThresholdReLU activation function after quantization.
[0104] For example, in the above example, the threshold parameter 4.1 is less than the maximum value 5 of the same fixed value data range; according to the first fixed point threshold parameter a with a value of 2 q1 The threshold parameter a with a value of 4.1 adjusts the first quantization parameter S to obtain the second quantization parameter S', so that the threshold parameter a is quantized according to the second quantization parameter to obtain the second fixed-point threshold parameter a q2 , where the maximum value of the fixed-value data range corresponding to the second quantization parameter is the value of the threshold parameter a, 4.1. When 4.3 is quantized using the second quantization parameter S', the obtained fixed-point value is greater than the second fixed-point threshold parameter; then according to the second fixed-point threshold parameter a q2 Determine the ThresholdReLU activation function after quantization.
[0105] Therefore, during the actual operation of the model, when the floating-point data to be subjected to the ThresholdReLU activation operation is received, the floating-point data is quantized using the second quantization parameter to obtain fixed-point data; the obtained fixed-point data is then used as the fixed-point input data of the ThresholdReLU activation function to obtain the fixed-point output data of the activation operation.
[0106] Therefore, the technical solution of the present application can make some output data obtained by using the unquantized ThresholdReLU activation function not 0 when the quantized ThresholdReLU activation function is used to activate the floating-point data to be activated during the operation of the face recognition model, while the floating-point data to be activated obtained by using the quantized ThresholdReLU activation function for activation operation is 0, and the output data obtained by using the quantized ThresholdReLU activation function for activation operation is not 0 according to the floating-point data corresponding to the fixed-point output data, thereby improving the accuracy of the model operation results.
[0107] For example, in the above example, taking the floating-point data 4.3 to be subjected to the ThresholdReLU activation operation as an example, the fixed-point output data obtained by the floating-point data 4.3 using the ThresholdReLU activation function quantized by the first quantization parameter is 0. Since the fixed-point value obtained by the floating-point data 4.3 according to the second quantization parameter in the ThresholdReLU activation function quantized by the second quantization parameter is greater than the second threshold parameter a q2 Therefore, the fixed-point output data obtained by the floating-point data 4.3 using the quantized ThresholdReLU activation function obtained by the second quantization parameter is not 0, thereby improving the accuracy of the model operation results.
[0108] It can be understood that the above method of adjusting the quantization parameter to obtain a fixed-point number by quantizing the floating-point data greater than the threshold parameter, and using the post-quantization parameter to quantize the fixed-point threshold parameter greater than the floating-point threshold parameter is not limited to using the round() rounding function for symmetric quantization. Using other rounding functions for symmetric quantization, and achieving the aforementioned symmetric quantization effect are all within the protection scope of this application.
[0109] It should be noted that the ThresholdReLU activation function after quantization in the neural network model can be determined by the terminal 100, or the ThresholdReLU activation function after quantization in the neural network model can be determined by the server 200. The terminal 100 includes but is not limited to a mobile phone, a tablet computer, a smart screen, a wearable device (e.g., a watch, a bracelet, a helmet, a headset, etc.), a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), and other electronic devices. The server 200 can be a single server or a server cluster consisting of multiple servers.
[0110] The following will take the server 200 determining the quantized activation function in the neural network model as an example. Figure 3 The face recognition scenario shown in the figure illustrates the process of obtaining the quantized ThresholdReLU activation function. Figure 5 As shown in the flowchart, a process of using the adjusted quantization parameter to obtain a quantized ThresholdReLU activation function provided by an embodiment of the present application includes the following steps:
[0111] S501: Determine a first quantization parameter based on floating-point input data for activation operation during the operation of the neural network model.
[0112] It can be understood that the floating-point input data for activation operation during the operation of the neural network model can be video data, audio data, image data, text data or data associated therewith, etc. Taking the application of the neural network model in video as an example, the floating-point input data for activation operation during the operation of the neural network model is video data, or other intermediate data obtained based on video data, such as feature data, vectors, etc.; when the neural network model is used in other aspects, the floating-point input data for activation operation during the operation of the neural network model is the same, and will not be repeated here.
[0113] In some implementations, when performing an activation operation according to the operation of the neural network model, the first quantization parameter is obtained from the input data range of the ThresholdReLU activation operation in the floating-point domain, the possible value range corresponding to the data type of the fixed-point input data of the ThresholdReLU activation operation in the fixed-point domain, and the quantization parameter formula. Among them, the input data range of the ThresholdReLU activation operation in the floating-point domain is determined during the training process of the neural network model; the data type of the fixed-point input data of the ThresholdReLU activation operation in the fixed-point domain can be int32, int16, int8, int4, uint32, uint16, uint8 or uint4.
[0114] For example, in Figure 3 In the scenario shown, the server 200 uses an unquantized face recognition model to perform model training multiple times in advance, and obtains the maximum value of the floating-point input data of the ThresholdReLU activation operation in the face recognition model during the training process as 254 and the minimum value as -6, and obtains the floating-point input data range as [-6, 254]; the data type of the fixed-point input data of the ThresholdReLU activation operation in the fixed-point domain is determined to be int8, and the corresponding value range of int8 is [-128, 127]. Substitute the maximum value 254, the minimum value -6 of the floating-point input data, and the maximum value 127 of the fixed-point input data into Formula 3, and obtain the first quantization parameter S as 2.
[0115] S502: According to the first quantization parameter, quantize the threshold parameter a to obtain a first fixed-point threshold parameter aq1.
[0116] In some implementations, the first quantization parameter is substituted into the symmetric quantization formula to obtain a first fixed-point threshold parameter aq1 corresponding to the threshold parameter a.
[0117] For example, the threshold parameter a is 4.1, and the first quantization parameter value 2 obtained in the above step is substituted into the above-mentioned symmetric quantization formula 2 to obtain the first fixed-point threshold parameter aq1 corresponding to the threshold parameter a of 4.1, which is round(4.1 / 2)=2.
[0118] For example, the threshold parameter a is 5.8, and the first quantization parameter value 2 obtained in the above step is substituted into the symmetric quantization formula 2 to obtain the value of the first fixed-point threshold parameter aq1 corresponding to the threshold parameter a of 5.8, which is round(5.8 / 2)=3.
[0119] S503: Adjust the first quantization parameter according to the first fixed-point threshold parameter aq1 and the threshold parameter a to obtain a second quantization parameter, wherein the maximum value of the fixed-value data range corresponding to the second quantization parameter is the threshold parameter a.
[0120] It can be understood that in some implementations, the second quantization parameter can be obtained based on the parity of the first fixed-point threshold parameter aq1 value and the quantization parameter formula corresponding to the parity. In other implementations, the parity of the first fixed-point threshold parameter aq1 value may be ignored, and the second quantization parameter can be directly obtained according to the quantization parameter formula corresponding to the parity.
[0121] In some implementations, when the obtained first fixed-point threshold parameter aq1 value is an even number, the first fixed-point threshold parameter aq1 and the threshold parameter a are substituted into the following formula 5 to obtain the second quantization parameter, so that the maximum value of the same fixed-value data range corresponding to the second quantization parameter is the threshold parameter a. For the sake of convenience, when the first fixed-point threshold parameter aq1 value is an even number, the formula 5 used to obtain the second quantization parameter is called an even quantization parameter formula.
[0122]
[0123] In Formula 5, S' is the second quantization parameter, aq1 is the first fixed-point threshold parameter, and a is the threshold parameter.
[0124] For example, Figure 6a In the formula, the threshold parameter a is 4.1, the first fixed-point threshold parameter aq1 is 2, which is an even number. Substituting the first fixed-point threshold parameter aq1 with a value of 2 and the threshold parameter a with a value of 4.1 into formula 5, the second quantization parameter value is S'=4.1 / (2+0.5)=1.64. At this time, the floating-point input data x obtained according to the second quantization parameter S' with a value of 1.64 is equal to the fixed-point input data x q The corresponding relationship is as follows Figure 7a shown.
[0125] In some implementations, when the obtained value of the first fixed-point threshold parameter aq1 is an odd number, the first fixed-point threshold parameter aq1 and the threshold parameter a are substituted into the following formula 6 to obtain the second quantization parameter S', so that the maximum value of the fixed-value data range corresponding to the second quantization parameter S' is the threshold parameter a. For the convenience of explanation, when the value of the first fixed-point threshold parameter aq1 is an even number, the formula 6 used to obtain the second quantization parameter is called an odd quantization parameter formula.
[0126]
[0127] In Formula 6, S' is the second quantization parameter, aq1 is the first fixed-point threshold parameter, and a is the threshold parameter.
[0128] For example, Figure 6b In the formula, the threshold parameter a is 5.8, the first fixed-point threshold parameter aq1 is 3, which is an odd number. Substituting the first fixed-point threshold parameter aq1 with a value of 3 and the threshold parameter a with a value of 5.8 into formula 6, the second quantization parameter value is S'=5.8 / (3-0.5)=2.32. At this time, the floating-point input data x obtained according to the second quantization parameter S' with a value of 2.32 is equal to the fixed-point input data x q The corresponding relationship is as follows Figure 7b shown.
[0129] It can be understood that in other implementations, the first fixed-point threshold parameter aq1 and the threshold parameter a are substituted into formula 7 to obtain the second quantization parameter S', so that the maximum value of the fixed-value data range corresponding to the second quantization parameter S' is the threshold parameter a. For the convenience of explanation, the quantization parameter formula corresponding to the parity of the first fixed-point threshold parameter aq1 value is referred to as the combined quantization parameter formula, that is, the following formula 7 used to obtain the second quantization parameter is called the combined quantization parameter formula.
[0130]
[0131] In Formula 7, S' is the second quantization parameter, aq1 is the first fixed-point threshold parameter, a is the threshold parameter, and the mod(aq1, 2) function is a remainder function, that is, the function result of mod(aq1, 2) is the remainder after the division operation of aq1 and 2, aq1 is the dividend, and 2 is the divisor.
[0132] For example, Figure 6aIn the formula, the threshold parameter a is 4.1, the first fixed-point threshold parameter aq1 is 2, and the first fixed-point threshold parameter aq1 with a value of 2 and the threshold parameter a with a value of 4.1 are substituted into formula 7 to obtain the second quantization parameter value, where the modulo function mod(2,2)=0, and the corresponding S'=4.1 / (2-0+0.5)=1.64. At this time, the floating-point input data x obtained according to the second quantization parameter S' with a value of 1.64 is equal to the fixed-point input data x q The corresponding relationship is as follows Figure 7a shown.
[0133] For example, Figure 6b In the formula, the threshold parameter a is 5.8, the first fixed-point threshold parameter aq1 is 3, and the first fixed-point threshold parameter aq1 with a value of 3 and the threshold parameter a with a value of 5.8 are substituted into formula 7 to obtain the second quantization parameter value, where the modulo function mod(3,2)=1, S'=5.8 / (3-1+0.5)=2.32. At this time, the floating-point input data x obtained according to the second quantization parameter S' with a value of 2.32 is equal to the fixed-point input data x q The corresponding relationship is as follows Figure 7b shown.
[0134] It can be understood that, for the first fixed-point threshold parameter aq1 and the threshold parameter a, the values of the second quantization parameters obtained according to the odd / even quantization parameter formula or the combined quantization parameter formula are the same.
[0135] S504: quantize the threshold parameter a according to the second quantization parameter to obtain a second fixed-point threshold parameter aq2.
[0136] In some implementations, the second quantization parameter obtained according to the combined quantization parameter formula, or the second quantization parameter obtained according to the odd / even quantization parameter formula, is substituted into the symmetric quantization formula 2, and the threshold parameter a is quantized to obtain the second fixed-point threshold parameter aq2.
[0137] For example, the threshold parameter a is 4.1, and the second quantization parameter value 1.64 obtained in the above step according to the combined quantization parameter formula or the even quantization parameter formula is substituted into the symmetric quantization formula 2 to obtain the value of the second fixed-point threshold parameter aq2 as round(4.1 / 1.64)=2. Figure 7a It shows that when the threshold parameter a value is 4.1, the corresponding second fixed-point threshold parameter aq2 value is 2. At this time, the maximum value of the floating-point input data range whose quantized fixed-point value is equal to the value of the second fixed-point threshold parameter aq2 is the value of the threshold parameter a, which is 4.1. Therefore, when the second quantization parameter value is 1.64, the maximum value of the corresponding fixed-point data range is the value of the threshold parameter a, which is 4.1.
[0138] For another example, the threshold parameter a is 5.8, and the second quantization parameter value 2.32 obtained in the above step according to the combined quantization parameter formula or the odd quantization parameter formula is substituted into the symmetric quantization formula 2 to obtain the value of the second fixed-point threshold parameter aq2 as round(5.8 / 2.32)=2. Figure 7b It shows that when the threshold parameter a value is 5.8, the corresponding second fixed-point threshold parameter aq2 value is 2. At this time, the maximum value of the floating-point input data range whose quantized fixed-point value is equal to the value of the second fixed-point threshold parameter aq2 is the value of the threshold parameter a, which is 5.8. Therefore, when the second quantization parameter value is 2.32, the maximum value of the corresponding fixed-point data range is the value of the threshold parameter a, which is 5.8.
[0139] S505: According to the second fixed-point threshold parameter aq2, a quantized ThresholdReLU activation function for performing activation operations during the operation of the neural network model is obtained.
[0140] It can be understood that during the operation of the neural network model, the quantized ThresholdReLU activation function is used to perform activation operations on the data to be activated.
[0141] In some implementations, the second fixed-point threshold parameter aq2 obtained according to the second quantization parameter is substituted into Formula 4 to obtain the quantized ThresholdReLU activation function.
[0142] For example, in the above example, the value of the second fixed-point threshold parameter aq2 obtained by the threshold parameter a being 4.1 is 2, and the second fixed-point threshold parameter aq2 having a value of 2 is substituted into Formula 4 to obtain the quantized ThresholdReLU activation function, as shown in the following Formula 8. During the operation of the neural network model, the operation logic shown in Formula 8 is used to perform activation operations on the data to be activated.
[0143]
[0144] For another example, in the above example, the value of the second fixed-point threshold parameter aq2 obtained by the threshold parameter a being 5.8 is 2, and the second fixed-point threshold parameter aq2 having a value of 2 is substituted into Formula 4 to obtain the quantized ThresholdReLU activation function, as shown in the following Formula 9. During the operation of the neural network model, the operation logic shown in Formula 9 is used to perform activation operations on the data to be activated.
[0145]
[0146] It can be understood that the execution order of steps S501 to S505 for obtaining the quantized ThresholdReLU activation function method is only an example. In other embodiments, other execution orders may be adopted, and some steps may be split or merged, which is not limited here.
[0147] It can be understood that after obtaining the quantized ThresholdReLU activation function, during the operation of the neural network model, the quantized ThresholdReLU activation function is used to perform the ThresholdReLU activation operation to obtain fixed-point output data, which can be data obtained by performing the ThresholdReLU activation operation on video data, performing the ThresholdReLU activation operation on audio data, performing the ThresholdReLU activation operation on image data, performing the ThresholdReLU activation operation on text data, etc., for example, Figure 3 In the scenario shown, in the process of using the face recognition model to process the face image data, the fixed-point output data may be image data obtained after performing ThresholdReLU activation operation on the face image data.
[0148] In order to better understand the technical solution of the embodiment of the present application, the activation operation performed by the terminal 100 in the process of processing data by running a neural network model is used as an example for explanation. Figure 8 As an example, the server 200 adopts the above Figure 5 The flowchart shown creates a quantized ThresholdReLU activation function, and after the quantized ThresholdReLU activation function is sent to the terminal 100, when the terminal 100 runs the deployed neural network model, in the process of the model processing data, according to the floating-point input data to be subjected to the ThresholdReLU activation operation, the determined quantized ThresholdReLU activation function is used to obtain a fixed-point output result. The specific process includes the following steps:
[0149] S801: Receive floating-point data to be activated by ThresholdReLU during the operation of the neural network model.
[0150] It can be understood that the floating-point data to be subjected to ThresholdReLU activation operation during the operation of the receiving neural network model can be floating-point video data, audio data, image data, text data or data related thereto.
[0151] For example, in Figure 3In the face recognition scenario shown, the floating-point data to be subjected to ThresholdReLU activation operation during the operation of the received face recognition model is image data, and the value of the floating-point data is 4.3.
[0152] S802: Quantize the above floating-point data to obtain fixed-point numbers, wherein the fixed-point number after quantization of the floating-point data greater than the threshold parameter is greater than the fixed-point number after quantization of the threshold parameter in the ThresholdReLU activation function.
[0153] It can be understood that the fixed-point numbers obtained by quantizing the above floating-point data are fixed-point video data, audio data, image data, text data, etc.
[0154] For example, in Figure 5 In the process of obtaining the quantized ThresholdReLU activation function shown in the figure, the threshold parameter a is 4.1, and the corresponding second quantization parameter is 1.64. The floating-point image data with a value of 4.3 in the above step S801 is quantized according to the symmetric quantization formula 2 to obtain a fixed-point number with a value of round(4.3 / 1.64)=3. The value of the obtained fixed-point image data is 3.
[0155] S803: Use the obtained fixed-point number as the fixed-point input data of the quantized ThresholdReLU activation function to obtain the fixed-point output data obtained after the activation operation during the operation of the neural network model.
[0156] It can be understood that during the operation of the neural network model, the above-mentioned fixed-point video, audio, image, text and other data are used as fixed-point input data of the quantized ThresholdReLU activation function to perform activation operations, and the fixed-point output data of the activation operations are obtained. The fixed-point output data of the activation operations obtained are video data, audio data, image data, text data, etc. When the input data for the activation operation is image data, the fixed-point output data obtained is also image data; when the input data for the activation operation is video data, the fixed-point output data obtained is also video data; when the input data for the activation operation is audio data, the fixed-point output data obtained is also audio data; when the input data for the activation operation is text data, the fixed-point output data obtained is also text data.
[0157] For example, according to Figure 5 In the process shown, the threshold parameter a is 4.1, and the corresponding quantized ThresholdReLU activation function is formula 8. Substituting the fixed-point image data value 3 into formula 8, it is found that the fixed-point image data value 3 is greater than the fixed-point threshold parameter a. q Value 2, so the fixed-point output data y qis 3, then the value of the image data obtained after the activation operation is 3.
[0158] It can be understood that the execution order of the above steps S801 to S803 is only an example. In other embodiments, other execution orders may be adopted, and some steps may be split or combined, which is not limited here.
[0159] It is understandable that the neural network model deployed to the terminal 100 can also be run by the server 200.
[0160] Fig. 9 According to some embodiments of the present application, a schematic diagram of a data processing device of a neural network model is shown. As shown in the figure, the device includes:
[0161] A first determining unit, used to determine the floating point data to be processed in the neural network model;
[0162] A first acquisition unit, configured to quantize the determined floating-point data to obtain a fixed-point number by using a second quantization parameter, wherein the second quantization parameter is determined according to a floating-point threshold parameter;
[0163] The second acquisition unit is used to use the obtained fixed-point number as fixed-point input data of a ThresholdReLU activation operation included in the neural network model to obtain fixed-point output data, wherein the ThresholdReLU activation operation is associated with a second quantization parameter.
[0164] To facilitate understanding of the technical solutions implemented in this application, the hardware structure of the terminal 100 is introduced below.
[0165] further, Fig.10 According to some embodiments of the present application, a schematic diagram of the structure of a terminal 100 is shown. Fig.10 The terminal 100 shown includes one or more processors 101 , system memory 102 , non-volatile memory (NVM) 103 , a communication interface 104 , an input / output (I / O) device 105 , a system control logic 106 , and instructions 107 .
[0166] Wherein: the processor 101 may include one or more processing units, for example, a central processing unit CPU (Central Processing Unit), an image processor GPU (Graphics Processing Unit), a digital signal processor DSP (Digital Signal Processor), a microprocessor MCU (Micro-programmed Control Unit), an AI (Artificial Intelligence, artificial intelligence) processor or a processing module or processing circuit of a programmable logic device FPGA (Field Programmable Gate Array) may include one or more single-core or multi-core processors. Wherein, the AI (Artificial Intelligence, artificial intelligence) processor includes a neural network processor (Neural Network Processing Unit, NPU), Zhouyi AIPU, etc.
[0167] The system memory 102 is a volatile memory, such as a random-access memory (RAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), etc. The system memory is used to temporarily store data and / or instructions. For example, in some embodiments, the system memory 102 can be used to store the relevant instructions of the above-mentioned neural network model data processing method.
[0168] The non-volatile memory 103 may include one or more tangible, non-temporary computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 103 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as a hard disk drive (HDD), a compact disc (CD), a digital versatile disc (DVD), a solid-state drive (SSD), etc. In some embodiments, the non-volatile memory 103 may also be a removable storage medium, such as a secure digital (SD) memory card, etc.
[0169] In particular, the system memory 102 and the non-volatile memory 103 may respectively include: a temporary copy and a permanent copy of the instruction 107. The instruction 107 may include: being executed by at least one of the processors 101 so that the terminal 100 implements the data processing method of the neural network model provided in each embodiment of the present application.
[0170] The communication interface 104 may include a transceiver for providing a wired or wireless communication interface for the terminal 100, and then communicating with any other suitable device through one or more networks. In some embodiments, the communication interface 104 may be integrated into other components of the terminal 100, for example, the communication interface 104 may be integrated into the processor 101. In some embodiments, the terminal 100 may communicate with other devices through the communication interface 104.
[0171] The input / output (I / O) device 105 may include input devices such as a keyboard, a mouse, etc., and output devices such as a display, etc. A user may interact with the terminal 100 via the input / output (I / O) device 105 .
[0172] System control logic 106 may include any suitable interface controller to provide any suitable interface with other modules of terminal 100. For example, in some embodiments, system control logic 106 may include one or more memory controllers to provide interfaces to system memory 102 and non-volatile memory 103.
[0173] In some embodiments, at least one of the processors 101 may be packaged together with the logic of one or more controllers for the system control logic 106 to form a system in package (SiP). In other embodiments, at least one of the processors 101 may also be integrated with the logic of one or more controllers for the system control logic 106 on the same chip to form a system-on-chip (SoC).
[0174] It can be understood that the terminal 100 can be any electronic device that can run a neural network model, including but not limited to mobile phones, wearable devices (such as smart watches, etc.), tablet computers, desktops, laptops, handheld computers, notebook computers, ultra-mobile personal computers (ultra-mobile personal computers, UMPC), netbooks, as well as cellular phones, personal digital assistants (personal digital assistants, PDA), augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) devices, etc., and the embodiments of the present application are not limited thereto.
[0175] Understandably, Fig.10 The structure of the terminal 100 shown is only an example. In other embodiments, the terminal 100 may include more or fewer components than shown, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0176] The various embodiments of the mechanism disclosed in the present application can be implemented in hardware, software, firmware or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device and at least one output device.
[0177] Program code can be applied to input instructions to perform the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0178] Program code can be implemented with high-level programming language or object-oriented programming language to communicate with the processing system. When necessary, program code can also be implemented with assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any specific programming language. In either case, the language can be a compiled language or an interpreted language.
[0179] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, instructions may be distributed over a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine (e.g., computer) readable form, including, but not limited to, floppy disks, optical disks, optical disks, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROM), random access memories (RAM), erasable programmable read-only memories (EPROM), electrically erasable programmable read-only memories (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable memories for transmitting information (e.g., carrier waves, infrared signal digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Accordingly, machine-readable media include any type of machine-readable media suitable for storing or transmitting electronic instructions or information in a form readable by a machine (eg, a computer).
[0180] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be required. Instead, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular figure does not mean that such features are required in all embodiments, and in some embodiments, these features may not be included or may be combined with other features.
[0181] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation method of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed by the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned device embodiments of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed by the present application, which does not mean that there are no other units / modules in the above-mentioned device embodiments.
[0182] It should be noted that in the examples and description of this patent, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises one" does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0183] Although the present application has been illustrated and described with reference to certain preferred embodiments thereof, it will be apparent to those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present application.
Claims
1. A data processing method of a neural network model, applied to electronic equipment, characterized in that: include: Determine the floating point data to be processed in the neural network model; quantizing the floating-point data to obtain a fixed-point number by using a post-quantization parameter, wherein the post-quantization parameter is determined according to a preset floating-point threshold parameter; Using the fixed-point number as fixed-point input data of a first threshold-corrected linear unit activation operation included in the neural network model to obtain fixed-point output data, wherein the first threshold-corrected linear unit activation operation is associated with the post-quantization parameter; The floating-point data to be processed in the neural network model is obtained based on at least one of image data, audio data, text data, and video data. The post-quantization parameter is determined according to a preset floating-point threshold parameter, including: The post-quantization parameter is obtained based on a combined quantization parameter formula, or the post-quantization parameter is obtained based on an odd quantization parameter formula and an even quantization parameter formula, and when a first fixed-point threshold parameter is an odd number, the post-quantization parameter is obtained according to the odd quantization parameter formula, and when the first fixed-point threshold parameter is an even number, the post-quantization parameter is obtained according to the even quantization parameter formula, and the first fixed-point threshold parameter is a fixed-point number obtained by quantizing the floating-point threshold parameter based on the previous quantization parameter; The combined quantization parameter formula is: Wherein, S' is the post-quantization parameter, a is the floating-point threshold parameter, and a q1 is the first fixed-point threshold parameter, mod(a q1 , 2) The function is the remainder function, a q1 is the dividend, 2 is the divisor; The odd quantization parameter formula is: The even quantization parameter formula is:
2. The method according to claim 1, characterized in that The pre-quantization parameter is determined by the following method, including: The pre-quantization parameter is determined according to the range of the floating-point data to be processed in the neural network model and the data type of the fixed-point number.
3. The method according to claim 1, characterized in that The first threshold-corrected linear unit activation operation is determined according to the post-quantization parameter and the floating-point threshold parameter.
4. The method according to claim 1 or 3, characterized in that: The first threshold rectified linear unit activation operation is determined by the following method, including: quantizing the floating-point threshold parameter according to the post-quantization parameter to obtain a second fixed-point threshold parameter; A threshold-corrected linear unit activation function for performing the first threshold-corrected linear unit activation operation is obtained according to the second fixed-point threshold parameter.
5. The method according to claim 2, characterized in that: The range of the floating-point data to be processed in the neural network model is determined during the operation of the neural network model.
6. The method according to claim 2, characterized in that The data type of the fixed-point number includes at least one of the following: int32, int16, int8, int4, uint32, uint16, uint8 or uint4.
7. The method according to claim 1, characterized in that The quantization is symmetric quantization.
8. A data processing device for a neural network model, used to execute the data processing method for a neural network model according to any one of claims 1 to 7, characterized in that: include, A first determining unit, used to determine the floating point data to be processed in the neural network model; A first acquisition unit, configured to quantize the floating-point data to obtain a fixed-point number by using a post-quantization parameter, wherein the post-quantization parameter is determined according to a preset floating-point threshold parameter; A second acquisition unit is used to use the fixed-point number as fixed-point input data of a first threshold-corrected linear unit activation operation included in the neural network model to obtain fixed-point output data, wherein the first threshold-corrected linear unit activation operation is associated with the post-quantization parameter; Among them, the floating-point data to be processed in the neural network model is obtained based on at least one of image data, audio data, text data, and video data.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which execute the method according to any one of claims 1 to 7 in an electronic device.
10. A computer program product, characterized in that The computer program product comprises instructions for implementing the method according to any one of claims 1 to 7 when the instructions are executed by one or more processors.
11. An electronic device, characterized in that: include: memory for storing instructions, and One or more processors, when the instructions are executed by the one or more processors, the processors perform the method according to any one of claims 1-7.
