Data processing method, electronic device, storage medium and computer program

By counting the input and output data of unquantized operators in the offline stage of the neural network model and correcting the quantization scaling coefficient, the problem of large data processing errors after quantization is solved and the accuracy of the neural network model is improved.

CN119337947APending Publication Date: 2025-01-21ARM TECH CHINA CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411386762.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

The data processing error after quantization of operators in neural network models is large, resulting in large data processing errors in neural network models.

Method used

By counting the input and output data of the unquantized operator in the offline stage, the correction value of the quantized scaling coefficient is determined to reduce the quantization error. The specific method includes determining the quantized scaling coefficient So according to the output data of the operator, and correcting the quantized scaling coefficient Si by using the input data of the operator So to obtain a more reasonable corrected quantized scaling coefficient Si'.

Benefits of technology

By modify the quantitative zoom coefficient, reduce quantitative errors, and improve the accuracy of neural network models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119337947A_ABST
    Figure CN119337947A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, in particular to a data processing method, electronic equipment, a storage medium and a computer program. In the method, in an offline stage, a quantization scaling coefficient of input data can be determined according to a floating point interval in which floating point data input by an operator is located, and a quantization scaling coefficient of output data can be determined according to a floating point interval in which floating point data output by the operator is located; and correcting the quantization scaling coefficient of the input data through the quantization scaling coefficient of the output data to obtain a corrected quantization scaling coefficient. The corrected quantization scaling coefficient is more reasonable than the quantization scaling coefficient before correction, and quantization errors can be reduced by performing quantization through the corrected quantization scaling coefficient, so that the data processing errors of the quantized operator are reduced, and the data processing errors of the neural network model are further reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a data processing method, electronic equipment, storage medium and computer program. Background Art

[0002] Artificial Intelligence (AI) is increasingly being used in people's production and life. Text, video, audio, image and other data can be processed through neural network models to obtain the desired results. For example, when a user uses a mobile phone, the built-in face recognition model of the mobile phone can process the captured face image to identify the person's identity; for another example, the built-in text recognition model of the mobile phone can process a paragraph on a web page to obtain the source of the text; for another example, the built-in audio matching model of the mobile phone can process the audio and identify the sound / song, etc.

[0003] Since the neural network model is a resource-intensive algorithm with large amount of computation and high computational cost, the neural network model can be quantized, and the floating-point operations in the neural network model can be quantized into fixed-point operations to reduce the amount of computation of the neural network model and reduce the computational cost.

[0004] Neural network models usually include some operators, such as normalization operators, differential operators, integral operators, etc. The quantization of neural network models mainly involves quantizing these operators. In some cases, the data processing errors of these operators after quantization are large, resulting in large data processing errors of neural network models. Summary of the invention

[0005] Some embodiments of the present application provide a data processing method, an electronic device, a storage medium and a computer program. The present application is introduced from multiple aspects below, and the embodiments and beneficial effects of the following aspects can be referenced to each other.

[0006] In a first aspect, an embodiment of the present application provides a data processing method, which is applied to an electronic device, wherein a first model is deployed on the electronic device, the first model is a model trained by a second model, the first model includes a first operator, the second model includes a second operator, and the first operator is an operator quantized from the second operator; the method includes:

[0007] Acquire first floating-point data that needs to be processed by a first operator during the process of the first model processing input data, wherein the first floating-point data is intermediate data corresponding to the input data, and the first floating-point data is located in a first floating-point interval, and the first floating-point interval is the interval in which the floating-point data received by the second operator is located during the process of the second model processing sample data during the model training stage; based on the first quantization scaling coefficient determined in the model training stage, quantize the first floating-point data to obtain first fixed-point data; perform operation processing on the first fixed-point data by the first operator to obtain second fixed-point data; wherein the first quantization scaling coefficient is determined based on the second quantization scaling coefficient and the third quantization scaling coefficient; the second quantization scaling coefficient is determined based on the first floating-point interval and the preset first fixed-point interval, and the first fixed-point interval is the quantization interval corresponding to the first floating-point interval; the third quantization scaling coefficient is determined based on the second floating-point interval and the preset second fixed-point interval, and the second floating-point interval is the interval in which the floating-point data output by the second operator is located during the process of the second model processing sample data during the model training stage, and the second fixed-point interval is the quantization interval corresponding to the second floating-point interval.

[0008] The first model may be the trained face recognition model mentioned below. The second model may be the untrained face recognition model mentioned below. The first operator may be the operator B mentioned below. The second operator may be the operator A mentioned below. The first quantization scaling factor may be the quantization scaling factor S mentioned below. i The second quantization scaling factor may be the quantization scaling factor S mentioned below. i The third quantization scaling factor may be the quantization scaling factor S mentioned below. o The first floating-point data may be the floating-point data X1 mentioned below. The first fixed-point data may be the fixed-point data Q1 mentioned below. The second fixed-point data may be the fixed-point data Q2 mentioned below. The first floating-point interval may be the floating-point interval f1 mentioned below. The first fixed-point interval may be the fixed-point interval q1 mentioned below. The second floating-point interval may be the floating-point interval f2 mentioned below. The second fixed-point interval may be the fixed-point interval q2 mentioned below.

[0009] In the offline stage, when the neural network model processes the sample data, the input data and output data of the unquantized operator A in the neural network model are counted, and then the quantization scaling coefficient S of the input data of the operator B (such as the quantized normalization operator) after the quantization of the operator A in the online stage is determined according to the floating point interval of the input data of the operator A. i , and determine the quantization scaling factor S of the output data of operator B in the online stage according to the floating point interval of the output data of operator A o , and then quantize the scaling factor S o The quantization scaling factor S iCorrection is performed to obtain the corrected quantization scaling factor S i ', as the quantization scaling factor for the online stage operator B to quantize the floating point data into fixed point data.

[0010] It can be understood that for operator A (such as a normalization operator), the output data of operator A is usually more evenly distributed than its input data. This is because the operator maps the input data to a reasonable range after processing the input data, making the data distribution more even.

[0011] Since the output data of operator A is more evenly distributed than its input data, in the offline stage, the quantization scaling factor S is obtained based on the output data of operator A. o , compared to the quantization scaling factor S obtained based on the input data of operator A i More reasonable, by quantizing the scaling factor S o The quantization scaling factor S i The correction can improve the rationality of the quantization scaling factor, reduce the quantization error, and thus improve the accuracy of the neural network model.

[0012] In some embodiments, the first quantization scaling factor is a product of a product of the second quantization scaling factor and the third quantization scaling factor raised to the Mth power and a first parameter, where M is greater than 0 and less than 1.

[0013] Specifically, it can be expressed by the formula: i '=α(S i S o ) M The quantization scaling factor S i Correction is performed to obtain the quantization scaling factor S i '.

[0014] The first parameter may be a hyperparameter α.

[0015] In some embodiments, the second quantization scaling factor is determined based on the ratio of the first value to the second value, the first value being the difference between the maximum fixed-point data and the minimum fixed-point data in the first fixed-point interval, and the second value being the difference between the maximum floating-point data and the minimum floating-point data in the second floating-point interval; the third quantization scaling factor is determined based on the ratio of the third value to the fourth value, the third value being the difference between the maximum fixed-point data and the minimum fixed-point data in the second fixed-point interval, and the fourth value being the difference between the maximum floating-point data and the minimum floating-point data in the second floating-point interval.

[0016] Assume that the floating point interval f1 of the input data of operator A is The floating point interval f2 where the output data of operator A is located is The floating point interval f1 is The corresponding fixed-point interval q1 is The floating point interval f2 is The corresponding fixed-point interval q2 is

[0017] For asymmetric quantization, the minimum floating-point data in the floating-point interval f1 can be and maximum floating point data And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substituting into the following formula (7), the quantization scaling factor S of asymmetric quantization is calculated: i , and the minimum floating point data in the floating point interval f2 and maximum floating point data And the minimum fixed-point data in the fixed-point interval q2 and maximum fixed-point data Substituting into the following formula (7), the quantization scaling factor S of asymmetric quantization is calculated: o .

[0018] In some embodiments, the second quantization scaling factor is determined based on the ratio of the fifth value to the sixth value, the fifth value being the absolute value of the fixed-point data with the largest absolute value in the first fixed-point interval, and the sixth value being the absolute value of the floating-point data with the largest absolute value in the first floating-point interval; the third quantization scaling factor is determined based on the ratio of the seventh value to the eighth value, the seventh value being the absolute value of the fixed-point data with the largest absolute value in the second fixed-point interval, and the eighth value being the absolute value of the floating-point data with the largest absolute value in the second floating-point interval.

[0019] Assume that the floating point interval f1 of the input data of operator A is The floating point interval f2 where the output data of operator A is located is The floating point interval f1 is The corresponding fixed-point interval q1 is The floating point interval f2 is The corresponding fixed-point interval q2 is

[0020] For symmetric quantization, the minimum floating-point data in the floating-point interval f1 can be and maximum floating point data And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substitute it into the following formula (3) to calculate the quantization scaling factor S of symmetric quantization: i , and the minimum floating point data in the floating point interval f2 and maximum floating point data And the minimum fixed-point data in the fixed-point interval q2 and maximum fixed-point data Substitute it into the following formula (3) to calculate the quantization scaling factor S of symmetric quantization: o .

[0021] In some embodiments, the second quantization scaling factor is determined based on a ratio of the first value to a ninth value, the ninth value being the product of the sixth value and the second parameter; and the third quantization scaling factor is determined based on a ratio of the third value to a tenth value, the tenth value being the product of the eighth value and the second parameter. The second parameter may be a value of 2.

[0022] Assume that the floating point interval f1 of the input data of operator A is The floating point interval f2 where the output data of operator A is located is The floating point interval f1 is The corresponding fixed-point interval q1 is The floating point interval f2 is The corresponding fixed-point interval q2 is

[0023] For symmetric quantization, the minimum floating-point data in the floating-point interval f1 can be and maximum floating point data And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substituting into formula (4), the quantization scaling factor S of symmetric quantization is calculated i , and the minimum floating point data in the floating point interval f2 and maximum floating point data And the minimum fixed-point data in the fixed-point interval q2 and maximum fixed-point data Substitute it into the following formula (4) to calculate the quantization scaling factor S of symmetric quantization: o .

[0024] In some embodiments, the first operator includes a quantized normalization operator, the operation processing of the quantized normalization operator includes fixed-point normalization operation processing, and the first fixed-point data is operated by the first operator to obtain the second fixed-point data, including: the first fixed-point data is operated by the quantized normalization operator to obtain the second fixed-point data.

[0025] In the process of the neural network model processing input data, the normalization operator in the neural network model performs fixed-point normalization operations on the data to be normalized in the neural network model instead of floating-point normalization operations, which can reduce the amount of operations and reduce the operation cost.

[0026] In some embodiments, the input data of the first model includes one of the following: image data; text data; audio data; video data.

[0027] In a second aspect, an embodiment of the present application provides an electronic device, including a memory for storing instructions executed by one or more processors of the electronic device; a processor, when the processor executes the instructions in the memory, the electronic device can execute the method described in any embodiment of the first aspect of the present application. The beneficial effects that can be achieved in the second aspect can refer to the beneficial effects of the method provided in any embodiment of the first aspect, and will not be repeated here.

[0028] In a third aspect, the present application provides a computer-readable storage medium on which instructions are stored, and when the instructions are executed on a computer, the computer can execute the method described in any embodiment of the first aspect. The beneficial effects that can be achieved in the third aspect can refer to the beneficial effects of the method provided in any embodiment of the first aspect, and will not be repeated here.

[0029] In a fourth aspect, the embodiments of the present application provide a computer program product, wherein the computer program product includes a computer program code, and when the computer program code is executed on a computer, the computer implements the method described in any embodiment of the first aspect. The beneficial effects that can be achieved in the fourth aspect can refer to the beneficial effects of the method provided in any embodiment of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 According to some embodiments of the present application, an example diagram of converting floating-point data into fixed-point data is shown;

[0031] Figure 2 According to some embodiments of the present application, a schematic diagram of the operation principle of a BN operator, a LN operator, an IN operator, and a GN operator is shown;

[0032] Figure 3 According to some embodiments of the present application, an example diagram of an application scenario of the present application is shown;

[0033] Figure 4 According to some embodiments of the present application, a structural schematic diagram of a face recognition model is shown;

[0034] Figure 5 According to some embodiments of the present application, a comparison diagram of the data processing process of the normalization operator before quantization in the offline stage and the normalization operator after quantization in the online stage is shown;

[0035] Figure 6According to some embodiments of the present application, a distribution comparison diagram of input data and output data of a normalization operator is shown;

[0036] Figure 7 According to some embodiments of the present application, a flow chart of a data processing method is shown;

[0037] Figure 8 According to some embodiments of the present application, a schematic structural diagram of an electronic device is shown. DETAILED DESCRIPTION

[0038] The illustrative embodiments of the present application include, but are not limited to, a data processing method, an electronic device, a storage medium, and a computer program.

[0039] 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.

[0040] 1. Quantification

[0041] Quantization refers to mapping floating-point data in a certain range into fixed-point data in a specified range.

[0042] Assuming that the quantized bit width (referring to the number of binary bits required to represent a number, for example, the number of binary bits of types such as int32, int16, int8, int4, uint32, uint16, uint8, uint4, etc.) is n, the quantization mapping function can be Qant(X|b)=X->Q, where X is the floating-point data before quantization, Q is the fixed-point data after the floating-point data X is quantized, and the value range of Q is as follows:

[0043]

[0044] Where signed means signed, and unsigned means unsigned. The above formula (1) indicates that the value range of signed fixed-point data Q is {-2 n-1 ,...,2 n-1 -1}, the value range of unsigned fixed-point data Q is {0,...,2 n -1}.

[0045] For example, reference Figure 1 If the floating point data in the range of [-150.00, 150.00] is quantized into fixed point data of type int8, the value range of the quantized fixed point data is [-128, 127] (i.e. [-2 n-1 , 2 n-1 -1], where n=8).

[0046] It can be understood that the quantization method of the neural network model may include symmetric quantization and asymmetric quantization.

[0047] The following first introduces the symmetric quantization method and the asymmetric quantization method and the corresponding inverse quantization of each quantization method.

[0048] (1) Symmetric quantization

[0049] Symmetric quantization refers to a quantization method in which the quantization interval is symmetric about the zero point.

[0050] In some embodiments, the formula for symmetric quantization is as shown in the following formula (2):

[0051] Q=clip(round(X*S),Q min ,Q max )(2)

[0052] Among them, Q is fixed-point data, X is floating-point data, S is the quantization scaling factor of symmetric quantization, round() is the rounding function, and clip() is the truncation function.

[0053] It can be understood that the clip() function in formula (2) is used to limit the result of round(X*S) to Q min and Q max Specifically, when the result of round(X*S) is less than or equal to Q min When Q = Q min ; When the result of round(X*S) is greater than or equal to Q max When Q = Q max ; When the result of round(X*S) is greater than Q min and is less than Q max , Q = round(X*S).

[0054] Formula (3) shows a calculation formula for the quantization scaling factor S of symmetric quantization. min , X max ] range of floating point data is quantized into [Q min , Q max ], the quantization scaling factor S of the symmetric quantization can be calculated by the following formula (3):

[0055]

[0056] Among them, X max is the maximum value of the floating-point data to be quantized, X min is the minimum value of the floating-point data to be quantized, Q max To quantize the floating-point data to be quantized into the maximum value of fixed-point data, Qmin is the minimum value of the quantized fixed-point data, and the max() function is the maximum value function.

[0057] Formula (4) shows another calculation formula for the quantization scaling factor S of symmetric quantization. min , X max ] range of floating point data is quantized into [Q min , Q max ], the quantization scaling factor S of the symmetric quantization can be calculated by the following formula (4):

[0058]

[0059] It should be noted that, in addition to calculating the quantization scaling factor S of the symmetric quantization by the calculation method shown in formula (3) or formula (4), in other embodiments, the quantization scaling factor S of the symmetric quantization can also be calculated by other modified formulas, without any limitation.

[0060] It can be understood that the quantization scaling coefficient S of the symmetric quantization is floating point data.

[0061] (2) Inverse quantization corresponding to symmetric quantization

[0062] In some embodiments, for the inverse quantization corresponding to the symmetric quantization, the fixed-point data Q can be inversely quantized into the floating-point data X by the following formula (5).

[0063] X=Q / S(5)

[0064] (3) Asymmetric quantization

[0065] Asymmetric quantization refers to a quantization method in which the quantization interval is asymmetric about the zero point.

[0066] In some embodiments, the formula for asymmetric quantization is shown in the following formula (6):

[0067] Q=clip(round(X*scale)-zerop,Q min ,Q max )(6)

[0068] Among them, scale is the quantization scaling factor of asymmetric quantization, and zerop is the zero point offset.

[0069] It can be understood that the clip() function in formula (6) is used to limit the calculation result of round(X*scale)-zerop to Q min and Q max Specifically, when the result of round(X*scale)-zerop is less than or equal to Q minWhen Q = Q min ; When the result of round(X*scale)-zerop is greater than or equal to Q max When Q = Q max ; When the result of round(X*scale)-zerop is greater than Q min and is less than Q max , Q = round(X*scale)-zerop.

[0070] Formula (7) shows a calculation formula for the quantization scaling factor scale of asymmetric quantization. min , X max ] range of floating point data is quantized into [Q min , Q max ], the quantization scaling factor scale of asymmetric quantization can be calculated by the following formula (7):

[0071]

[0072] Formula (8) shows the calculation formula of the zero point offset zerop of asymmetric quantization. min , X max ] range of floating point data is quantized into [Q min , Q max ], the zero point offset zerop of asymmetric quantization can be calculated by the following formula (8):

[0073] zerop=Round(scale*X min -Q min )(8)

[0074] It should be noted that, in addition to calculating the quantization scaling factor scale of asymmetric quantization by the calculation method shown in the above formula (7), in other embodiments, the quantization scaling factor scale of asymmetric quantization can also be calculated by other modified formulas, without limitation. Similarly, in addition to calculating the zero point offset zerop of asymmetric quantization by the calculation method shown in the above formula (8), in other embodiments, the zero point offset zerop of asymmetric quantization can also be calculated by other modified formulas, without limitation.

[0075] It can be understood that the quantization scaling factor scale of the asymmetric quantization is floating point data.

[0076] (4) Inverse quantization corresponding to asymmetric quantization

[0077] In some embodiments, for the inverse quantization corresponding to the asymmetric quantization, the fixed-point data Q can be inversely quantized into the floating-point data X by the following formula (9):

[0078] X=(Q+zerop) / scale(9)

[0079] 2. Tensor

[0080] A tensor can be understood as a multi-dimensional array of data. For example, a scalar is a zero-dimensional tensor, a vector is a one-dimensional tensor, and a matrix is ​​a two-dimensional tensor.

[0081] In a neural network model, a tensor can be used as a data representation of the input and output data of an operator (e.g., an integral operator, a differential operator, a cumulative summation operator, an exponential operator, a logarithmic operator, a normalization operator, etc.). For example, if the input data of an operator is image data, the input data of the operator can be represented as a tensor of the structure [N, C, H, W], where N represents the number of images, C represents the number of color channels, H represents the height of the image, and W represents the width of the image.

[0082] For example, assuming that the input tensor of the operator is [5, 3, 256, 512], it means that the input data of the operator is 5 3-channel (such as RGB channels) color images with a height of 256 pixels and a width of 512 pixels.

[0083] 3. Operator

[0084] In a neural network model, an operator refers to a computing unit in the network model, such as an integral operator, a differential operator, a cumulative summation operator, an exponential operator, a logarithmic operator, a normalization operator, etc. The following uses the normalization operator as an example for explanation.

[0085] In some embodiments, the normalization operation formula of the normalization operator is as follows:

[0086]

[0087] Among them, x i is the ith data to be normalized, i is a positive integer, mean is the mean of all data to be normalized, var is the variance of all data to be normalized, and epsilon is a very small number greater than 0 (for example, 1×10 -8 etc.), norm is the data x to be normalized i The normalized result of , γ is the normalized scaling factor, and β is the normalized translation factor.

[0088] It can be understood that the normalization operator includes but is not limited to a batch normalization (BN) operator, an instance normalization (IN) operator, a layer normalization (LN) operator, a group normalization (GN) operator, a mean square error normalization operator, and the like.

[0089] Combine the following Figure 2 The differences between BN operator, LN operator, IN operator and GN operator are introduced.

[0090] Figure 2 (a) in FIG. 1 shows the principle diagram of the BN operator; Figure 2 (b) in FIG. 4 shows the principle diagram of the LN operator; Figure 2 (c) in FIG. 5 shows the schematic diagram of the IN operator; Figure 2 (d) in FIG. 5 shows the principle diagram of the GN operator.

[0091] like Figure 2 As shown in (a), for a set of image data represented by the tensor [N, C, H, W], the BN operator normalizes the N images of this set of image data on the same color channel.

[0092] like Figure 2 As shown in (b), for a set of image data represented by the tensor [N, C, H, W], the LN operator normalizes all channels of each image in this set of image data.

[0093] like Figure 2 As shown in (c), for a set of image data represented by the tensor [N, C, H, W], the IN operator performs normalization on each channel of each image separately.

[0094] like Figure 2 As shown in (d), for a set of image data represented by the tensor [N, C, H, W], the GN operator divides the color of the image into multiple groups and then normalizes the channels of the content of each group.

[0095] The technical solution of the present application can be applied to any scenario where text, audio, image, video and other data need to be processed through a neural network model.

[0096] To facilitate understanding, the face recognition model is used as an example of a neural network model to introduce an exemplary application scenario of the face recognition model for processing image data.

[0097] Figure 3A scene diagram is shown in which the electronic device 100 recognizes a collected face image through a face recognition model.

[0098] like Figure 3 As shown, after the server 200 has trained the face recognition model to be trained in the floating-point domain, the trained face recognition model can be deployed in the electronic device 100, so that the electronic device 100 can perform face recognition processing on the face image data through the trained face recognition model to obtain the corresponding recognition result.

[0099] In some embodiments, the facial image data may be obtained by photographing the user by the electronic device 100, may be pre-stored by the electronic device 100, or may be transmitted to the electronic device 100 by other devices, without limitation.

[0100] It should be noted that the electronic device 100 includes but is not limited to mobile phones, tablet computers, smart screens, wearable devices (e.g., watches, bracelets, helmets, headphones, etc.), vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The server 200 can be a single server or a server cluster consisting of multiple servers. Figure 3 A mobile phone is taken as an example of the electronic device 100 .

[0101] Figure 4 A structural diagram of a face recognition model is shown.

[0102] like Figure 4 As shown in the figure, the face recognition model includes an input layer, a normalization layer, an output layer, and other network layers. The normalization layer is deployed with unquantized normalization operators, such as IN operator, LN operator, GN operator, BN operator, mean square error normalization, and other operators that support normalization operations. In the process of the face recognition model processing the input face image data, the normalization operator in the normalization layer can normalize the data (such as texture, contour, color and other feature data) superimposed by the front network layer (the network layer before the normalization layer) to unify the data range and avoid large fluctuations in the data range, which affects the convergence speed and recognition accuracy during the training of the face recognition model.

[0103] According to the normalization calculation formula shown in the above formula (10), the normalization process of the normalization operator involves radical operations, wherein radical operations belong to floating-point operations, and the amount of floating-point operations is large and the operation cost is high.

[0104] Based on this, in some embodiments, such as Figure 5 As shown, the normalization operator in the face recognition model can be quantized in the offline stage (the training stage of the face recognition model) so that the floating-point operation in the normalization operator is converted into a fixed-point operation. Then, in the online stage (the use stage of the face recognition model), the face recognition model can quantize the input floating-point data into fixed-point data through the quantized normalization operator, and then perform a fixed-point normalization operation on the fixed-point data instead of a floating-point normalization operation. In this way, the amount of calculation can be reduced and the calculation cost can be saved. Among them, the specific quantization process of the normalization operator is a prior art and will not be described in detail in this application.

[0105] The quantization in the present application can be symmetric quantization or asymmetric quantization. The following uses asymmetric quantization as an example to introduce the process of quantizing the input floating-point data into fixed-point data by the normalization operator after quantization.

[0106] In the offline stage, the sample data can be input into the face recognition model to be trained, and the face recognition model is trained by the sample data. During the training process, the interval range of the floating point data input into the normalization operator is counted, which is recorded as [X min , X max If [X min , X max ] The floating point data in the interval is quantized into [Q min , Q max ] interval, the corresponding quantization scaling factor scale can be calculated by the above formula (7), and the corresponding zero point offset zerop can be calculated by the above formula (8).

[0107] In the online stage, the quantized normalization operator can first quantize the floating-point data to be normalized into corresponding fixed-point data through the above formula (6), and then perform normalization operation on the fixed-point data according to the fixed-point operation method corresponding to the above formula (10) to obtain the corresponding normalization result.

[0108] It can be understood that in the process of quantizing floating-point data into fixed-point data by formula (6), since formula (6) includes the rounding function round() and the truncation function clip(), the nonlinear operation of these two functions will produce certain errors, thereby bringing certain quantization errors, that is, there are certain errors in the fixed-point data after the floating-point data is quantized. In addition, according to formula (10), the normalization operator will calculate the mean and variance of the input data during the normalization operation, and the operations of the mean and variance involve the accumulation and summation of data, which will accumulate errors, resulting in a large error in the normalization result of the normalization operator.

[0109] In addition, according to formula (6) and formula (8), the error of quantizing floating-point data into fixed-point data depends on whether the value of the quantization scaling factor scale is reasonably selected. If the value of the quantization scaling factor scale is reasonably selected, the error of quantizing floating-point data into fixed-point data is small, and if the value of the quantization scaling factor scale is not reasonably selected, the error of quantizing floating-point data into fixed-point data is large.

[0110] In formula (7), Q min and Q max The value of is set in advance, so the value of the quantization scaling factor scale is the maximum floating point data X input to the unquantized normalization operator in the offline stage. max and the minimum floating point data X min Thus, when the multiple floating-point data input to the unquantized normalization operator in the offline stage are unevenly distributed, the value of the quantization scaling factor scale obtained according to formula (7) will be unreasonable.

[0111] For example, Figure 6 As shown, the multiple floating-point data input to the unquantized normalization operator in the offline stage are mostly distributed in [X min , X max ] interval, very few data are distributed in [X min , X max ] interval. In this case, the value of the quantization scaling factor scale calculated by formula (7) will be too large, resulting in the distribution of [X min , X max ] When the floating point data in the middle area of ​​the interval is quantized, the calculation result of round(X*scale)-zerop in formula (6) is the same as Q min or Q maxThe difference is too large, which leads to a large error in the calculation result of the clip() function, and then a large quantization error. In this way, when the quantized normalization operator performs normalization processing on the quantized fixed-point data, a large error will be generated, which leads to a large error in the recognition result of the face image model for the face image data.

[0112] In view of this, an embodiment of the present application provides a data processing method. In the method, in the offline stage, when the neural network model processes the sample data, the input data and output data of the unquantized operator A (such as the unquantized normalization operator) in the neural network model are counted, and then the quantization scaling coefficient S of the input data of the operator B (such as the quantized normalization operator) after the quantization of the operator A in the online stage is determined according to the floating point interval where the input data of the operator A is located. i , and determine the quantization scaling factor S of the output data of operator B in the online stage according to the floating point interval of the output data of operator A o , and then quantize the scaling factor S o The quantization scaling factor S i Correction is performed to obtain the corrected quantization scaling factor S i ', as the quantization scaling factor for the online stage operator B to quantize the floating point data into fixed point data.

[0113] It can be understood that for operator A, the output data of operator A is usually more evenly distributed than its input data. This is because after processing the input data, the operator maps the input data to a reasonable range, making the data distribution more even.

[0114] For example, Figure 6 As shown, the input data of the normalization operator is distributed in the form of distribution 1, which is unevenly distributed. After the normalization operator normalizes these input data, output data distributed in the form of distribution 2 can be obtained, which is relatively evenly distributed.

[0115] Since the output data of operator A is more evenly distributed than its input data, in the offline stage, the quantization scaling factor S is obtained based on the output data of operator A. o , compared to the quantization scaling factor S obtained based on the input data of operator A i More reasonable, by quantizing the scaling factor S o The quantization scaling factor S i The correction can improve the rationality of the quantization scaling factor, reduce the quantization error, and thus improve the accuracy of the neural network model.

[0116] In some embodiments, the quantization scaling factor S can be calculated by the following formula (11): iCorrection is performed to obtain the quantization scaling factor S' i :

[0117] S' i =α(S i S o ) M (11)

[0118] Wherein, α (as the first parameter) and M are hyperparameters set according to experience or determined by any search algorithm, and both α and M are greater than 0 and less than 1. Wherein, the search algorithm includes but is not limited to linear search, binary search, depth-first search, breadth-first search, random search and other algorithms. Optionally, α=0.4, M=0.5.

[0119] In some embodiments, in the online stage, when the trained neural network model processes the input data, the quantized operator B in the neural network model can first be based on the quantization scaling factor S' i The floating-point data input to operator B is quantized to obtain corresponding fixed-point data, and then the fixed-point data is subjected to corresponding fixed-point operation processing (such as fixed-point normalization operation processing) to output the corresponding operation result. i is the modified quantization scaling factor, operator B is quantized by the scaling factor S' i The input floating point data is quantized with a small quantization error, which can improve the data processing effect of the neural network model.

[0120] The technical solution of the present application is described below in conjunction with specific embodiments.

[0121] Figure 7 According to some embodiments of the present application, a flow chart of a data processing method is shown.

[0122] like Figure 7 As shown, the method includes:

[0123] S101: The first electronic device obtains sample data, and inputs the sample data into a neural network model to be trained.

[0124] In some embodiments, during an offline phase, the first electronic device acquires sample data, and inputs the sample data into a neural network model to be trained to train the neural network model.

[0125] It should be noted that the embodiment of the present application does not limit the method for obtaining sample data. The sample data can be downloaded from the Internet, pre-stored, or obtained from other devices.

[0126] It can be understood that the first electronic device can be a server, a mobile phone, a tablet computer, a smart screen, a wearable device (for example, a watch, a bracelet, a helmet, a headset, etc.), a vehicle-mounted device, an AR / VR device, a laptop computer, a UMPC, a netbook, a PDA, and other electronic devices.

[0127] It can be understood that the sample data can be image sample data (such as face image sample data, etc.), video sample data, audio sample data, text sample data, etc., which are used to train the neural network model.

[0128] It can be understood that the neural network model can be a face recognition model, a text recognition model, an audio matching model, etc.

[0129] Take the first electronic device as the server, the sample data as face image sample data, and the neural network model as the face recognition model as an example:

[0130] In the offline stage, the server can obtain facial image sample data and input the facial image sample data into the face recognition model to be trained, so as to train the face recognition model through the facial image sample data.

[0131] S102: When the neural network model is used to process sample data, the first electronic device counts the input floating-point data and output floating-point data of the unquantized operator A in the neural network model.

[0132] It can be understood that the input floating-point data is the floating-point data input to operator A. The output floating-point data is the floating-point data output by operator A.

[0133] It can be understood that the input floating-point data of operator A can be feature data after the preceding network layer of the network layer where operator A is located extracts features from the sample data. For example, if the sample data is image sample data, the input floating-point data of operator A can be image feature data representing features such as texture, contour, and color of the image. For another example, if the sample data is text data, the input floating-point data of operator A can be text feature data representing the part of speech, meaning, and word spacing of the text.

[0134] In some embodiments, during the process of the neural network model processing the sample data, the first electronic device can count the input floating point data and output floating point data of the unquantized operator A in the neural network model, and determine the floating point intervals of the input floating point data and output floating point data of the operator A. The floating point interval is the interval where the floating point data is located.

[0135] It can be understood that the operator A can be an integral operator, a differential operator, a cumulative summation operator, an exponential operator, a logarithmic operator, a normalization operator or other unquantized operators.

[0136] Take the first electronic device as a server, the sample data as face image sample data, the neural network model as a face recognition model, and the operator A as an unquantized normalization operator as an example:

[0137] During the process of the face recognition model processing the face image sample data, the server can count the input floating-point data and output floating-point data of the unquantized normalization operator in the face recognition model, and determine the floating-point interval f1 of the input floating-point data of the unquantized normalization operator and the floating-point interval f2 of the output floating-point data.

[0138] S103: The first electronic device determines a quantization scaling factor S according to the floating point interval f1 of the input data of the operator A and the preset fixed point interval q1. i , and determine the quantization scaling factor S according to the floating point interval f2 and the preset fixed point interval q2 where the input data of operator A is located o .

[0139] It can be understood that the fixed-point interval is the interval where the fixed-point data is located. The larger the bit width of the fixed-point data, the larger the range of the fixed-point interval. For example, if the bit width of the fixed-point data is 8 bits, the fixed-point interval can be [-127, 128]; if the bit width of the fixed-point data is 16 bits, the fixed-point interval can be [-32768, 32767].

[0140] It can be understood that the fixed-point interval q1 is the quantization interval corresponding to the floating-point interval f1, and the fixed-point interval q2 is the quantization interval corresponding to the floating-point interval f2. The fixed-point interval q1 and the fixed-point interval q2 can be the same interval or different intervals.

[0141] In some embodiments, the fixed-point interval q1 and the fixed-point interval q2 can be determined according to the number of data (denoted as N) that the operator A needs to process in the process of processing the sample data by the neural network model. For example, when N>Q (Q is a hyperparameter set according to experience or confirmed by any search algorithm), the bit width of the fixed-point data in the fixed-point interval q1 and the fixed-point interval q2 can be 16 bits, and the fixed-point interval q1 and the fixed-point interval q2 can be [-32768, 32767]; when N≤Q, the bit width of the fixed-point data in the fixed-point interval q1 and the fixed-point interval q2 can be 8 bits, and the fixed-point interval q1 and the fixed-point interval q2 can be [-127, 128].

[0142] It can be understood that the quantization scaling factor S i and the quantization scaling factor S oIt can be a symmetric quantization scaling coefficient or an asymmetric quantization scaling coefficient, and there is no limitation on this. The symmetric quantization scaling coefficient refers to a quantization scaling coefficient used for symmetric quantization, such as the quantization scaling coefficient calculated by the above formula (3) or formula (4). The asymmetric quantization scaling coefficient refers to a quantization scaling coefficient used for asymmetric quantization, such as the quantization scaling coefficient calculated by the above formula (7).

[0143] Assume that the floating point interval f1 of the input data of operator A is The floating point interval f2 where the output data of operator A is located is The floating point interval f1 is The corresponding fixed-point interval q1 is The floating point interval f2 is The corresponding fixed-point interval q2 is

[0144] In the case of symmetric quantization, the first electronic device can convert the minimum floating point data in the floating point interval f1 into and maximum floating point data And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substitute it into the above formula (3) or formula (4) to calculate the quantization scaling factor S of the symmetric quantization i , and the minimum floating point data in the floating point interval f2 and maximum floating point data And the minimum fixed-point data in the fixed-point interval q2 and maximum fixed-point data Substitute it into the above formula (3) or formula (4) to calculate the quantization scaling factor S of the symmetric quantization o .

[0145] In the case of asymmetric quantization, the first electronic device can convert the minimum floating point data in the floating point interval f1 into and the maximum floating point data X 1 max , and the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substituting into the above formula (7), the quantization scaling factor S of asymmetric quantization is calculated i , and the minimum floating point data in the floating point interval f2 and maximum floating point data And the minimum fixed-point data in the fixed-point interval q2 and maximum fixed-point data Substituting into the above formula (7), the quantization scaling factor S of asymmetric quantization is calculated o .

[0146] S104: The first electronic device quantizes the scaling factor S o The quantization scaling factor S i Correction is performed to obtain the quantization scaling factor S i '.

[0147] In some embodiments, the first electronic device obtains the quantized scaling factor S i and the quantization scaling factor S o After that, the first electronic device can quantize the scaling factor S i and the quantization scaling factor S o Substitute into the above formula (11) to calculate the quantization scaling factor S i '.

[0148] It can be understood that when the quantization scaling factor S o and the quantization scaling factor S i When the quantization scaling factor is symmetrical, the quantization scaling factor S i ' is a symmetric quantization scaling factor. When the quantization scaling factor S o and the quantization scaling factor S i When the quantization scaling factor is asymmetric, the quantization scaling factor S i ' is the asymmetric quantization scaling factor.

[0149] In some embodiments, after the first electronic device completes training of the neural network model to be trained using sample data, operator A in the neural network model can be quantized into operator B, and then the trained neural network model can be deployed to the second electronic device.

[0150] It can be understood that the second electronic device can be a server, a mobile phone, a tablet computer, a smart screen, a wearable device (for example, a watch, a bracelet, a helmet, a headset, etc.), a vehicle-mounted device, an AR / VR device, a laptop computer, a UMPC, a netbook, a PDA, and other electronic devices.

[0151] S105: In the process of the second electronic device acquiring the trained neural network model to process the input data, floating point data X1 that needs to be processed by operator B, wherein operator B is the operator after operator A is quantized.

[0152] It can be understood that the floating point data X1 can be feature data after the preceding network layer of the network layer where the operator B is located extracts features from the input data. For example, if the input data of the neural network model is image data, the floating point data X1 can be image feature data representing features such as texture, contour, and color of the image. For another example, if the input data of the neural network model is text data, the floating point data X1 can be text feature data representing features such as part of speech, word meaning, and word spacing of the text.

[0153] In some embodiments, in the online stage, when the trained neural network model on the second electronic device processes the input data, the predecessor operator of operator B in the neural network model (the operator located before operator B) processes the input data and outputs floating-point data X1 as the input data of operator B.

[0154] Take the second electronic device as a mobile phone, the neural network model as a face recognition model, the input data as face image data, and the operator B as a quantized normalization operator as an example:

[0155] In the online stage, the mobile phone can perform face image recognition processing on the face image data through the face recognition model. In the process of the face recognition model processing the face image data, the front network layer of the normalization layer of the face recognition model (the network layer before the normalization network) processes the input face image data and outputs the corresponding floating point data X1 as the input data of the normalization layer of the face recognition model, that is, as the input data of the quantized normalization operator deployed on the normalization layer. Among them, the floating point data X1 is the intermediate data corresponding to the face image data, such as the feature data used to characterize the texture, color, contour, etc. of the image.

[0156] S106: The second electronic device uses the quantized scaling factor S i ', quantize the floating-point data X1 to obtain the fixed-point data Q1.

[0157] It can be understood that the fixed-point data Q1 is the quantized data of the floating-point data X1. Like the floating-point data X1, the fixed-point data Q1 is feature data after the preceding network layer of the network layer where the operator B is located extracts features from the input data, such as image feature data, text feature data, and other feature data.

[0158] In some embodiments, the quantized scaling factor S i In the case where the quantization coefficient is a symmetric quantization coefficient, the second electronic device can quantize the floating point data X1 into fixed point data Q1 by using the operator B according to the aforementioned symmetric quantization method, for example, by converting the quantization scaling coefficient S i 'And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substitute into the above formula (2) to calculate the fixed-point data Q1.

[0159] In some other embodiments, the quantized scaling factor S i In the case where the quantization coefficient is asymmetric, the second electronic device can quantize the floating point data X1 into fixed point data Q1 by using the operator B according to the aforementioned asymmetric quantization method. For example, the quantization scaling coefficient S is first i 'And the minimum fixed-point data in the fixed-point interval q1 and maximum fixed-point data Substitute into the above formula (6) to calculate the fixed-point data Q1.

[0160] S107: The second electronic device performs operation processing on the fixed-point data Q1 by using an operator B to obtain fixed-point data Q2.

[0161] In some embodiments, after the second electronic device quantizes the floating-point data X1 into fixed-point data Q1 through operator B, the second electronic device may perform operation processing on the fixed-point data Q1 through operator B to obtain fixed-point data Q2, such as performing fixed-point normalization operation processing on the fixed-point data Q1 through a quantized normalization operator (as an example of operator B) to obtain fixed-point data Q2. Then, the second electronic device may perform subsequent processing on the fixed-point data Q2 through a post-operator of operator B in the neural network model (an operator located after operator B) and output a corresponding processing result.

[0162] It can be understood that the fixed-point data Q2 is the data of the fixed-point data Q1 after being mapped by the operator B, and the data may be feature data such as image feature data and text feature data.

[0163] In the embodiment of the present application, in the offline stage, when the sample data is processed according to the neural network model, the input floating point data of operator A determines the quantization scaling factor S i Then, the quantization scale S is determined based on the output floating-point data of operator A. o , and scaled by quantization S o The quantization scaling factor S i Correction is performed to obtain the corrected quantization scaling factor S i ', which improves the rationality of the selection of quantization scaling coefficients and reduces the quantization error in the online stage, thereby improving the accuracy of the neural network model.

[0164] It should be noted that in the above embodiment, the training process and the deployment and application process of the neural network model are completed on different electronic devices. In other implementations, the training process and the deployment and application process of the neural network model can also be completed on the same electronic device.

[0165] In some embodiments, in order to further optimize the normalization operator calculation process in the neural network dedicated hardware to improve the overall processing efficiency, the following strategy can be adopted: Given that the direct predecessor operator of the normalization operator (assuming it is Layer_i, whose output is Ti) is a fixed operator in the neural network model, such as the addition operator, when deploying the neural network model, the computing unit of Layer_i can be tightly coupled with the computing unit of the normalization operator in physical layout, and the data connection bit width between the two can be enhanced.

[0166] Specifically, if the tensor bit width used by the neural network model is 8 bits, the connection from Layer_i to the normalization operator can be configured as 16 bits or higher bit width to avoid Ti from being reduced from a high bit width to 8 bits during transmission. This optimization ensures that Ti can be directly passed to the normalization operator with higher precision and bit width without the need for bit width reduction. In this way, the entire neural network model does not need to be operated at high precision (such as 16 bits), and only the data flow between Layer_i and the normalization operator uses a higher bit width. For the normalization process, only the part used for cumulative summation to calculate the mean and variance uses a higher bit width, while the final mean and variance can still be processed at a lower bit width. Unnecessary computational complexity is reduced while maintaining accuracy. Such design optimization not only improves the accuracy of data processing, but also optimizes resource utilization efficiency and speeds up the overall speed of neural network calculations.

[0167] To facilitate understanding of the technical solutions of each implementation of the present application, the hardware structure of the electronic device 100 is introduced below.

[0168] further, Figure 8 According to some embodiments of the present application, a schematic diagram of the structure of an electronic device 100 is shown. Figure 8 The electronic device 100 shown includes one or more processors 101 , a system memory 102 , a non-volatile memory (NVM) 103 , a communication interface 104 , an input / output (I / O) device 105 , a system control logic 106 , and instructions 107 .

[0169] 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.

[0170] 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.

[0171] 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.

[0172] 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 to enable the electronic device 100 to implement the data processing method provided by each embodiment of the present application.

[0173] The communication interface 104 may include a transceiver for providing a wired or wireless communication interface for the electronic device 100, thereby 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 electronic device 100, for example, the communication interface 104 may be integrated into the processor 101. In some embodiments, the electronic device 100 may communicate with other devices through the communication interface 104.

[0174] 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 electronic device 100 via the input / output (I / O) device 105 .

[0175] System control logic 106 may include any suitable interface controller to provide any suitable interface with other modules of electronic device 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.

[0176] 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).

[0177] It can be understood that the electronic device 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, super mobile personal computers, netbooks, as well as cellular phones, personal digital assistants, ARVR devices, etc., and the embodiments of the present application are not limited thereto.

[0178] Understandably, Figure 8 The structure of the electronic device 100 shown is only an example. In other embodiments, the electronic device 100 may include more or fewer components than shown, or combine some components, or separate 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.

[0179] An embodiment of the present application further provides a readable storage medium, in which one or more programs are stored. When the one or more programs are executed by an electronic device, the electronic device implements the methods provided in the aforementioned embodiments.

[0180] The embodiments of the present application also provide a program product, which, when executed on an electronic device, can enable the electronic device to implement the methods provided in the aforementioned embodiments.

[0181] 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.

[0182] 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.

[0183] 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.

[0184] 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).

[0185] 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.

[0186] 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.

[0187] 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.

[0188] 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, applied to an electronic device, characterized in that: A first model is deployed on the electronic device, the first model is a model trained by a second model, the first model includes a first operator, the second model includes a second operator, and the first operator is an operator quantized from the second operator; The method comprises: Acquire first floating-point data that needs to be processed by the first operator during the process of the first model processing the input data, wherein the first floating-point data is intermediate data corresponding to the input data, and the first floating-point data is located in a first floating-point interval, and the first floating-point interval is the interval in which the floating-point data received by the second operator is located during the process of the second model processing the sample data in the model training stage; Based on a first quantization scaling coefficient determined in a model training phase, quantizing the first floating-point data to obtain first fixed-point data; Performing operation processing on the first fixed-point data by using the first operator to obtain second fixed-point data; Wherein, the first quantization scaling factor is determined based on the second quantization scaling factor and the third quantization scaling factor; The second quantization scaling factor is determined based on the first floating point interval and a preset first fixed point interval, and the first fixed point interval is a quantization interval corresponding to the first floating point interval; The third quantization scaling factor is determined based on a second floating-point interval and a preset second fixed-point interval, the second floating-point interval being the interval in which the floating-point data output by the second operator is located when the second model processes the sample data during the model training phase, and the second fixed-point interval being the quantization interval corresponding to the second floating-point interval.

2. The method according to claim 1, characterized in that The first quantization scaling factor is the product of the Mth power of the product of the second quantization scaling factor and the third quantization scaling factor and a first parameter, where M is greater than 0 and less than 1.

3. The method according to claim 1, characterized in that The second quantization scaling factor is determined based on a ratio of a first value and a second value, the first value being a difference between a maximum fixed-point data and a minimum fixed-point data in the first fixed-point interval, and the second value being a difference between a maximum floating-point data and a minimum floating-point data in the second floating-point interval; The third quantization scaling factor is determined based on a ratio of a third value that is a difference between a maximum fixed-point data and a minimum fixed-point data in the second fixed-point interval and a fourth value that is a difference between a maximum floating-point data and a minimum floating-point data in the second floating-point interval.

4. The method according to claim 1, characterized in that: The second quantization scaling factor is determined based on a ratio of a fifth value and a sixth value, the fifth value being an absolute value of fixed-point data with a maximum absolute value in the first fixed-point interval, and the sixth value being an absolute value of floating-point data with a maximum absolute value in the first floating-point interval; The third quantization scaling factor is determined based on the ratio of the seventh value and the eighth value, wherein the seventh value is the absolute value of the fixed-point data with the largest absolute value in the second fixed-point interval, and the eighth value is the absolute value of the floating-point data with the largest absolute value in the second floating-point interval.

5. The method according to claim 1, characterized in that The second quantization scaling factor is determined based on a ratio of the first value to a ninth value, the ninth value being a product of the sixth value and a second parameter; The third quantization scaling factor is determined based on a ratio of the third value to a tenth value, the tenth value being a product of the eighth value and the second parameter.

6. The method according to claim 1, characterized in that The first operator includes a quantized normalization operator, and the operation processing of the quantized normalization operator includes a fixed-point normalization operation processing. Furthermore, the step of performing operation processing on the first fixed-point data by the first operator to obtain second fixed-point data includes: The first fixed-point data is processed by the quantized normalization operator to obtain the second fixed-point data.

7. The method according to any one of claims 1 to 6, characterized in that The input data of the first model includes one of the following: image data; text data; audio data; video data.

8. An electronic device, characterized in that: include: a memory for storing instructions executed by one or more processors of the electronic device; A processor, when the processor executes the instructions in the memory, causes the electronic device to perform the method according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which, when executed on a computer, cause the computer to perform the method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The method comprises a computer program / instructions which, when executed, cause a computer to perform the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Data processing method, electronic device, storage medium and program product

    CN121166074A

  • Data processing methods, electronic devices, storage media and software products

    CN121166074B