Method for operating a neural network model, readable medium, and electronic device

By converting symmetric quantization parameters into asymmetric parameters, the problem that the neural network processor cannot run the symmetric quantization model is solved, and the versatility of the processor and the speed of model deployment are improved.

CN114492779BActive Publication Date: 2024-09-27ARM TECH CHINA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210141278.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-16
Publication Date
2024-09-27
Estimated Expiration
2042-02-16

AI Technical Summary

Technical Problem

Existing neural network processors can usually only run asymmetric quantized neural network models and cannot run symmetric quantized models, resulting in limited versatility and deployment speed.

Method used

By converting the parameters of the symmetric quantized neural network model into asymmetric quantized parameters and calling the preset asymmetric quantized operator's operation logic, the operation of the symmetric quantized model is realized, which increases the types of models that the processor can run and the deployment speed. .

Benefits of technology

It improves the versatility of the neural network processor, can run more types of neural network models, and reduces model deployment time and computing resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492779B
    Figure CN114492779B
Patent Text Reader

Abstract

The present application relates to the field of artificial intelligence, and discloses a method for operating a neural network model, a readable medium, and an electronic device. The method is applied to an electronic device, and includes: detecting a first neural network model, the first neural network model is a symmetric quantized neural network model, and the first neural network model includes symmetric quantization parameters of each operator of the first neural network model; converting the symmetric quantization parameters of each operator into an asymmetric quantization parameter; using the asymmetric quantization parameters of each operator, calling the operation logic of the preset asymmetric quantized operator to obtain the inference result of the first neural network model. In this way, an electronic device that can only run an asymmetric quantized neural network model can call the operation logic of the preset asymmetric quantized operator to implement the function of the symmetric quantized neural network model, thereby increasing the types of neural network models that can be run by the electronic device.
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, and in particular to an operating method, a readable medium and an electronic device of a neural network model. Background Art

[0002] With the rapid development of artificial intelligence (AI), neural network models are increasingly widely used in the field of artificial intelligence. Since the computing units that run neural network models, such as neural network processors (NPUs), are usually fixed-point computing units, in order to improve the running speed of the neural network model, each operator of the neural network model is usually quantized to obtain a fixed-point computing neural network model, which is then run by an electronic device. The quantization of each operator of the neural network model includes asymmetric quantization or symmetric quantization. However, in order to save development and manufacturing costs, some NPUs only have preset computing logic for asymmetric quantized operators. Such NPUs can only run asymmetric quantized neural network models, but cannot run symmetric quantized neural network models. Summary of the invention

[0003] In view of this, the embodiments of the present application provide a method for operating a neural network model, a readable medium, and an electronic device. The electronic device converts the symmetric quantization parameters of the symmetric quantized neural network model into asymmetric quantization parameters, and can call the operation logic of the preset asymmetric quantization operator according to the obtained asymmetric quantization parameters to implement the function of the symmetric quantized neural network model, thereby increasing the types of neural network models that can be run by the electronic device and improving the versatility of the NPU of the electronic device.

[0004] In a first aspect, an embodiment of the present application provides a method for operating a neural network model, which is applied to an electronic device, and the method includes: detecting a first neural network model, the first neural network model is a symmetric quantized neural network model, and the first neural network model includes symmetric quantization parameters of each operator of the first neural network model; converting the symmetric quantization parameters of each operator into an asymmetric quantization parameter; using the asymmetric quantization parameters of each operator, calling the operation logic of the preset asymmetric quantized operator to obtain an inference result of the first neural network model.

[0005] Through the method provided in the embodiment of the present application, if the processor (such as NPU) used to run the first neural network model in the electronic device can only call the operation logic of the asymmetric quantized operator to realize the reasoning of the neural network model, then the symmetric quantization parameters of each operator of the first neural network model can be converted into asymmetric quantization parameters, and the operation logic of the asymmetric quantized operator is called through the obtained asymmetric quantization parameters to reason the first neural network model and obtain the reasoning result of the first neural network model. In this way, the types of neural network models that can be run by the electronic device are increased, and the versatility of the NPU of the electronic device is improved. In addition, since there is no need to first convert the symmetric quantized neural network model into a floating-point neural network model and then convert it into an asymmetric quantized neural network model, the deployment speed of the neural network model is improved.

[0006] In a possible implementation of the first aspect, the electronic device includes a first processor, which can infer an asymmetric quantized neural network model but cannot infer a symmetric quantized neural network model; and the first neural network model is run by the first processor.

[0007] That is to say, the first processor of the electronic device can only call the operation logic of the asymmetric quantization operator to infer the neural network model. Through the method provided in the embodiment of the present application, the first processor can realize the function of the first neural network model by converting the symmetric quantization parameters of the first neural network model into asymmetric quantization parameters, and calling the operation logic of the asymmetric quantization operator based on the obtained asymmetric quantization parameters, thereby increasing the types of neural network models that the first processor can run and improving the versatility of the first processor.

[0008] In a possible implementation of the first aspect above, the above-mentioned symmetric quantization parameter includes at least one of the following parameters: a symmetric quantization scaling coefficient of input data, a symmetric quantization scaling coefficient of output data, and a symmetric quantization parameter of constant data, wherein the symmetric quantization parameter of constant data includes symmetric quantization constant data and a symmetric quantization scaling coefficient of symmetric quantization constant data.

[0009] In a possible implementation of the first aspect above, the conversion of the symmetric quantization parameters of each operator into an asymmetric quantization parameter includes: determining the maximum and minimum values ​​of the floating-point numbers corresponding to the input data or output data according to the data type of the input data or output data and the symmetric quantization scaling coefficient of the input data or output data; determining the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the input data or output data according to the maximum and minimum values ​​of the floating-point numbers corresponding to the input data or output data.

[0010] For example, when the data type of the input data or output data of an operator is INT8, if the symmetric quantization scaling coefficient of the input data or output data is 1, the maximum floating point value of the input data or output data is determined to be a floating point number of 127, and the minimum floating point value is determined to be a floating point number of -128. Then, according to formula (4) and formula (5) below, the asymmetric quantization scaling coefficient of the input data or output data is obtained to be 1, and the asymmetric quantization zero point is obtained to be 128.

[0011] In a possible implementation of the first aspect above, determining the maximum and minimum values ​​of the floating-point numbers corresponding to the input data or output data based on the data type of the input data or output data and the symmetric quantization scaling coefficient of the input data or output data includes: determining the maximum and minimum values ​​of the fixed-point numbers of the input data or output data based on the data type of the input data or output data of each operator; determining the maximum and minimum values ​​of the floating-point numbers corresponding to the input data or output data based on the symmetric quantization scaling coefficient of the input data or output data and the maximum and minimum values ​​of the fixed-point numbers of the input data or output data.

[0012] For example, when the data type of the input data or output data is INT8, the maximum value of the fixed-point number of the input data or output data is 127, and the minimum value is -128. Therefore, according to formula (11) below, it can be determined that the maximum value of the floating-point number of the input data or output data is a floating point number of 127, and the minimum value is a floating point number of -128.

[0013] In a possible implementation of the first aspect above, the above-mentioned symmetric quantization constant data includes a symmetric quantization constant and a symmetric quantization matrix; and the symmetric quantization parameters of each operator are converted into an asymmetric quantization parameter, including: determining the maximum value and the minimum value of the floating-point number corresponding to the symmetric quantization constant data according to the data type of the symmetric quantization constant data and the symmetric quantization scaling coefficient of the symmetric quantization constant data; determining the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point number corresponding to the symmetric quantization constant data according to the maximum value and the minimum value of the floating-point number corresponding to the symmetric quantization constant data; converting the floating-point constant data corresponding to the symmetric quantization constant data into asymmetric quantization constant data according to the determined asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point number corresponding to the symmetric quantization constant data, wherein the floating-point constant data corresponding to the symmetric quantization constant data is determined by the symmetric quantization parameter of the constant data.

[0014] For example, the constant data of a certain operator includes a symmetrically quantized constant 100, and the symmetrical quantization scaling coefficient of the symmetrically quantized constant data is 2. According to formula (11), the floating-point number constant corresponding to the constant is 50. Based on the data type of the constant data, such as INT8, the maximum value of the floating-point number corresponding to the constant data is 63.5, and the minimum value is -64. Then, according to formulas (4) and (5) below, the asymmetrical quantization scaling coefficient of the constant data is 2, and the asymmetrical quantization zero point is 128.

[0015] In a possible implementation of the first aspect above, the above-mentioned determining the maximum value and minimum value of the floating-point number corresponding to the symmetric quantization constant data according to the data type of the symmetric quantization constant data and the symmetric quantization scaling coefficient of the symmetric quantization constant data includes: determining the maximum value and minimum value of the fixed-point number of the symmetric quantization constant data according to the data type of the symmetric quantization constant data; determining the maximum value and minimum value of the floating-point number corresponding to the symmetric quantization constant data according to the symmetric quantization scaling coefficient of the symmetric quantization constant data and the determined maximum value and minimum value of the fixed-point number of the symmetric quantization constant data.

[0016] For example, when the data type of the symmetric quantization constant is INT8 and the symmetric quantization scaling factor of the symmetric quantization constant data is 2, the maximum value of the fixed-point number of the asymmetric quantization constant data is 127 and the minimum value is -128. Therefore, according to formula (11) below, it can be determined that the maximum value of the floating-point number corresponding to the asymmetric quantization constant data is a floating-point number of 63.5 and the minimum value is a floating-point number of -64.

[0017] In a possible implementation of the first aspect, the symmetric quantization constant data further includes a symmetric quantization lookup table, wherein the symmetric quantization lookup table includes a symmetric quantization lookup table index and a symmetric quantization lookup table result corresponding to each symmetric quantization lookup table index; and the symmetric quantization parameters of each operator are converted into an asymmetric quantization parameter, including: determining a floating-point lookup table index corresponding to each symmetric quantization lookup table index according to a symmetric quantization scaling coefficient of the symmetric quantization constant data; determining a floating-point lookup table result corresponding to each floating-point lookup table index according to a floating-point lookup table index corresponding to each symmetric quantization lookup table index and a calculation logic of each operator; and converting the symmetric quantization parameters of each operator into an asymmetric quantization parameter. The asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating point table lookup index obtain the asymmetric quantization table lookup index, and the symmetric quantization table lookup result is obtained based on the asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating point data table lookup result, wherein the asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating point table lookup index are determined based on the data type of the symmetric quantization table lookup index, and the asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating point table lookup result are determined based on the data type of the symmetric quantization table lookup result; based on each asymmetric quantization table lookup index and the corresponding asymmetric quantization table lookup result, an asymmetric quantization lookup table is obtained.

[0018] For example, for the Softmax operator described below, the electronic device may first calculate the symmetric quantization scaling factor (1.1×10 -5 ), determine the floating-point table lookup index corresponding to each table lookup index. For example, for the table lookup index [1, 5, 121], according to formula (11), the floating-point table lookup index can be obtained as [2727273, 4727273, 8272727]; then substitute the floating-point table lookup index into the calculation logic of the Softmax operator (formula (12)), and obtain the floating-point table lookup result [0.0069, 0.042, 0.9511] corresponding to the floating-point table lookup index, and then according to the asymmetric quantization scaling factor (1.1×10 -5 ), asymmetric quantization zero point 128, quantize the floating-point table lookup result to the fixed-point table lookup result [129, 133, 249].

[0019] In a possible implementation of the first aspect above, the method also includes: determining the maximum and minimum values ​​of the fixed-point numbers corresponding to the symmetric quantization lookup index or the asymmetric quantization lookup result according to the data type of the symmetric quantization lookup index or the asymmetric quantization lookup result, and based on the determined maximum and minimum values, determining the maximum and minimum values ​​of the fixed-point number lookup index corresponding to the symmetric quantization lookup index or the maximum and minimum values ​​of the fixed-point number lookup result corresponding to the asymmetric quantization lookup result according to the symmetric quantization scaling coefficient of the symmetric quantization constant data; determining the asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating-point number lookup index or the floating-point number lookup result according to the determined maximum and minimum values ​​of the fixed-point number lookup index corresponding to the symmetric quantization lookup index or the maximum and minimum values ​​of the fixed-point number lookup result corresponding to the asymmetric quantization lookup result.

[0020] For example, in the following symmetric quantization table lookup result of the Softmax operator, when the data type of the symmetric quantization table lookup result is INT8, the maximum value of the constant of the symmetric quantization table lookup result is 127, and the minimum value is -128. According to the symmetric quantization scaling factor (1.1×10 -5 ), the asymmetric quantization scaling factor of the symmetric quantization table lookup result is (255). Based on the formula (11) below, the maximum value of the floating-point number corresponding to the symmetric quantization table lookup index is 11545455 and the minimum value is -11636364. The maximum value of the floating-point number corresponding to the symmetric quantization table lookup result is 1 and the minimum value is -1. Then, according to the formulas (4) and (5) below, the asymmetric quantization scaling factor of the floating-point number table lookup index is 1.1×10 -5, the asymmetric quantization zero point is 128, the asymmetric quantization scaling coefficient of the floating-point table lookup result is 127.5, and the asymmetric quantization zero point is 128.

[0021] In a second aspect, an embodiment of the present application provides a readable medium, which contains instructions. When the instructions are executed by a processor of an electronic device, the electronic device implements an operating method of any neural network model provided by the first aspect and various possible implementations of the first aspect.

[0022] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions executed by one or more processors of the electronic device; and a processor, which is one of the processors of the electronic device, for executing instructions to enable the electronic device to implement the operating method of any one of the neural network models provided by the first aspect and various possible implementations of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1A According to some embodiments of the present application, a schematic diagram of 8-bit symmetric quantization is shown;

[0024] Figure 1B According to some embodiments of the present application, a schematic diagram of 8-bit asymmetric quantization is shown;

[0025] Figure 2 According to some embodiments of the present application, a schematic diagram of a scenario in which a symmetric quantized neural network model is deployed in an electronic device 100 is shown;

[0026] Figure 3 According to some embodiments of the present application, a scene diagram of an electronic device 100 running a symmetric quantized neural network model is shown;

[0027] Figure 4 According to some embodiments of the present application, a schematic diagram of the structure of a neural network model 10 is shown;

[0028] Figure 5 According to some embodiments of the present application, a schematic diagram of a process of an electronic device classifying an image 20 using a symmetric quantized neural network model 10 is shown;

[0029] Figure 6 According to some embodiments of the present application, a flowchart of a method for operating a neural network model is shown;

[0030] Figure 7 According to some embodiments of the present application, a schematic diagram of a process in which an electronic device 100 calls the operation logic of an asymmetric quantization operator to classify an image 20 is shown;

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

[0032] Illustrative embodiments of the present application include, but are not limited to, methods of operating a neural network model, readable media, and electronic devices.

[0033] To facilitate understanding, the terms involved in the embodiments of the present application are first introduced.

[0034] (1) Symmetric quantization

[0035] Symmetric quantization is to convert floating-point numbers into fixed-point numbers whose value range is symmetrical with respect to "0". Suppose the floating-point number to be quantized is x f , the quantitative goal is to convert x f Perform n-bit symmetric quantization, that is, the range of the fixed-point number after quantization is [-2 n-1 , 2 n -1 -1], the symmetric quantization process is expressed as the following formula (1).

[0036]

[0037] In formula (1), abs() is the absolute value function, max() is the maximum value function, min() is the minimum value function, round is the rounding function, and x q is a fixed-point number. In addition, in formula (1), as shown in formula (2), S c The term may be referred to as a symmetric quantization scaling factor. That is, for a symmetric quantized fixed number, the floating point number corresponding to the fixed point number may be determined according to the symmetric quantization scaling factor corresponding to the fixed point number.

[0038]

[0039] Specifically, Figure 1A According to some embodiments of the present application, a method for performing a calculation on a floating point number x is shown. f Schematic diagram of 8-bit symmetric quantization. Figure 1A The quantitative goal is to convert x f Quantization is performed by 8-bit symmetric quantization, that is, x f Convert to INT8 type (value range is [-128, 127]), assuming x f The maximum absolute value of is max(|x f |), then for x f The process of 8-bit symmetric quantization is to convert the interval [-max(|x f |), max(|x f |)] is mapped to the interval [-128, 127].

[0040] It can be understood that in some embodiments, the INT type can be represented as INTn, where n can be 4, 8, 16, 32, etc., or other integers, and the value range of the signed data of the INTn type is [-2 n-1 , 2 n-1 -1]. That is, for a given INT type data, the electronic device can determine the value range of the data according to the value of n, and calculate the value range of the floating point number corresponding to the data based on formula (1) and formula (2).

[0041] (2) Asymmetric quantization

[0042] Asymmetric quantization is to convert floating point numbers into values ​​in the range [0, 2 n -1], where n is the number of bits of asymmetric quantization. Assume that the floating point number to be quantized is x f , the quantitative goal is to convert x f Perform n-bit asymmetric quantization, that is, the range of the fixed-point number after quantization is [0, 2 n -1], the asymmetric quantization process is expressed as the following formula (3).

[0043]

[0044] In formula (3), max() is the maximum value function, min() is the minimum value function, round is the rounding function, and x q is a fixed-point number. In addition, in formula (3), as shown in formula (4) below: c The term can be called an asymmetric quantization scaling factor, as shown in the following formula (5): p The term may be referred to as an asymmetric quantization zero point. That is, for an asymmetric quantized fixed-point number, the floating-point number corresponding to the fixed-point number may be determined according to the asymmetric quantization scaling coefficient and the asymmetric quantization zero point corresponding to the fixed-point number.

[0045]

[0046] Z p =round(-AS c ·min(x f )) (5)

[0047] Based on formula (3) to formula (5), another representation of asymmetric quantization shown in formula (6) can be obtained:

[0048] x q =round(x f ·AS c +Zp ) (6)

[0049] Specifically, Figure 1B According to some embodiments of the present application, a method for performing a calculation on a floating point number x is shown. f Schematic diagram of 8-bit asymmetric quantization. Figure 1B The quantitative goal is to convert x f Quantization is performed by 8-bit asymmetric quantization, that is, x f Convert to UINT8 type (value range is [0, 255]), assuming x f The maximum value of max(x f ), the minimum value is min(x f ), then for x f The process of 8-bit asymmetric quantization is to convert the interval [min(x f ), max(x f )] is mapped to the interval [0, 255].

[0050] It can be understood that in some embodiments, the UINT type can be represented as UINTn, where n can be 4, 8, 16, 32, etc., or other integers, and the value range of the unsigned data of the UINTn type is [0, 2 n -1]. That is, for a given UINT type data, the electronic device can determine the value range of the data according to the value of n, and calculate the value range of the floating point number corresponding to the data based on formula (6).

[0051] (3) Quantization of Neural Network Model

[0052] Neural network model quantization is the process of converting the input data, output data, and constant data in each operator of the neural network model from floating-point numbers of large data types (for example, 32-bit floating-point numbers) to fixed-point numbers of smaller data types (for example, 4 / 8 / 16-bit fixed-point numbers). The number of bits of the fixed-point number usually matches the number of bits of the fixed-point number supported by the computing unit that runs the neural network model, such as the NPU, to increase the speed at which the NPU runs the neural network model.

[0053] Generally, the quantization process of the neural network model is to determine the quantization parameters of the floating-point input data, floating-point output data and floating-point constant data of each operator according to the value range of the floating-point input data and the floating-point output data of each operator, and the type of the quantized fixed-point number (for example, UINT8) (for example, the quantization parameters of asymmetric quantization include asymmetric quantization scaling coefficients and asymmetric quantization zero points, and the quantization parameters of symmetric quantization include symmetric quantization scaling coefficients). That is, the quantization parameters of the quantized operator include the quantization parameters of the input data of the operator, the quantization parameters of the output data, the quantized constant data and the quantization parameters of the constant data. In the electronic device used to run the quantized neural network model, the operation logic of the quantized operator is preset. The operation logic of the quantized operator takes the fixed-point number as input and the fixed-point number as output, and the parameters in the operation logic include the quantization parameters of the input data, the quantization parameters of the output data, the quantized constant data and the quantization parameters of the constant data. When the electronic device runs a quantized operator, it calls the preset operation logic according to the quantization parameters of the operator, and the function of the operator can be realized through fixed-point operation.

[0054] The technical solution of the embodiments of the present application is described below in conjunction with the accompanying drawings.

[0055] To facilitate understanding, the following first takes the convolution operator as an example to illustrate the operation logic of operators using symmetric quantization and asymmetric quantization.

[0056] Assuming that B_f is the floating-point input matrix of the convolution operator, C_f is the floating-point convolution kernel, and D_f is the floating-point convolution result, the relationship between B_f, C_f, and D_f can be expressed as formula (7).

[0057] D_f=B_f*C_f (7)

[0058] In formula (7), “*” is the convolution operation symbol. The specific process of the convolution operation will be introduced later and will not be described here.

[0059] According to formula (6), we can get B_f=(B_q-Z p _B) / B_ASc, C_f=(C_q-Z p _C) / C_ASc, D_f=(D_q-Z p _D) / D_ASc, where: B_q is the fixed-point matrix of asymmetric quantization corresponding to B_f, B_ASc is the asymmetric quantization scaling factor for quantizing B_f to B_q, Z p _B is the asymmetric quantization zero point that asymmetrically quantizes B_f to B_q; C_q is the fixed-point convolution kernel of asymmetric quantization corresponding to C_f, C_ASc is the asymmetric quantization scaling factor that quantizes C_f to C_q, and Z p_C is the asymmetric quantization zero point for asymmetric quantization of C_f to C_q; D_q is the fixed-point matrix of asymmetric quantization corresponding to D_f, D_ASc is the symmetric quantization scaling coefficient for asymmetric quantization of D_f to D_q, Z p _D is the asymmetric quantization zero point for asymmetric quantization of D_f to D_q. Then, formula (7) can be expressed as the following formula (8).

[0060]

[0061] By transforming formula (8), we can obtain the operation logic of the asymmetric quantized convolution operator as shown in the following formula (9).

[0062]

[0063] That is to say, the electronic device is preset with the operation logic shown in formula (9), and the input of the operation logic includes: asymmetric quantized input data B_q, asymmetric quantization zero point Z of the input data B_q p _B, asymmetric quantization scaling coefficient B_ASc, asymmetric quantization convolution kernel C_q, asymmetric quantization zero point Z of convolution kernel C_q p _C, asymmetric quantization scaling coefficient C_ASc, asymmetric quantization zero point Z of output data D_q p _D, asymmetric quantization scaling coefficient D_ASc; the output data is the asymmetric quantization convolution result D_q.

[0064] Similarly, the operation logic of the symmetric quantized convolution operator can be expressed as the following formula (10). The specific derivation process can refer to the operation logic of the symmetric quantized convolution operator, which will not be repeated here.

[0065]

[0066] In formula (10), B_q is the symmetrically quantized input data, C_q is the symmetrically quantized convolution kernel, D_q is the fixed-point convolution result, B_Sc is the symmetrical quantization scaling coefficient of B_q, D_Sc is the symmetrical quantization parameter of the output data D_q, and C_Sc is the symmetrical quantization scaling coefficient of the convolution kernel.

[0067] It can be seen from formula (9) and formula (10) that for the same operator, the operation logic and input parameters of asymmetric quantization and symmetric quantization are not the same. As mentioned above, some NPUs can only run asymmetric quantized neural network models, that is, they can only run the operation logic of asymmetric quantized operators (such as the operation logic of the convolution operator shown in formula (9)), but cannot run symmetric quantized neural network models. If the symmetric quantized neural network model is deployed in an electronic device including the part of the NPU, it is necessary to first convert the symmetric quantized neural network model into a floating-point neural network model (that is, the input data, output data and constant data of each operator of the neural network model are all floating-point numbers), and then quantize the floating-point neural network model into an asymmetric quantized neural network before it can be deployed in the electronic device.

[0068] For example, refer to Figure 2 , the NPU of the electronic device 100 can only run an asymmetric quantized neural network model, while the neural network model to be run is a symmetric quantized neural network model. Therefore, the electronic device 200 needs to convert the symmetric quantized neural network model into a floating-point neural network model, and after quantizing the floating-point neural network model into an asymmetric quantized neural network model, the asymmetric quantized neural network model is deployed into the electronic device 100 to be run by the NPU of the electronic device 100. Since the process of quantizing a floating-point neural network model into a fixed-point neural network model (i.e., the input data, output data, constant data, etc. of each operator of the neural network model are fixed-point numbers) occupies a large amount of computing resources and is time-consuming, it is not conducive to the rapid deployment of the neural network model.

[0069] In order to solve the above problems, the embodiment of the present application provides a method for operating a neural network model. After detecting a symmetrically quantized neural network model, the electronic device 100 obtains the symmetrical quantization parameters of each operator of the symmetrically quantized neural network model, and converts the symmetrical quantization parameters of each operator into corresponding asymmetrical quantization parameters. The NPU of the electronic device 100 then calls the preset asymmetrically quantized operator operation logic according to the asymmetrical quantization parameters of each operator to implement the relevant functions of the symmetrically quantized neural network model. In this way, reference Figure 3Although the NPU of the electronic device 100 cannot run the symmetrically quantized neural network model, the electronic device 100 converts the symmetrically quantized parameters of each operator in the symmetrically quantized neural network model into an asymmetrically quantized parameter. The NPU of the electronic device 100 can call the preset asymmetrically quantized operator's operation logic to implement the relevant functions of the symmetrically quantized neural network model, without the need for other electronic devices to convert the symmetrically quantized neural network model into a floating-point neural network model, and then convert the floating-point neural network model into an asymmetrically quantized neural network model before running it by the NPU of the electronic device 100. This increases the types of neural network models that the electronic device 100 can run, improves the versatility of the NPU, and improves the deployment speed of the neural network model.

[0070] It can be understood that the symmetric quantization parameter of each operator includes at least one of the following parameters: a symmetric quantization scaling factor of input data, a symmetric quantization scaling factor of output data, symmetric quantization constant data, and a symmetric quantization scaling factor of symmetric quantization constant data. The asymmetric quantization parameter of each operator includes at least one of the following parameters: an asymmetric quantization scaling factor of input data, an asymmetric quantization zero point of input data, an asymmetric quantization scaling factor of output data, an asymmetric quantization zero point of output data, an asymmetric quantization constant data, an asymmetric quantization zero point of asymmetric quantization constant data, and an asymmetric quantization scaling factor of asymmetric quantization constant data.

[0071] It can be understood that in other embodiments, the asymmetric quantization parameter / symmetric quantization parameter of each operator may also include more or fewer parameters, which is not limited here.

[0072] It can be understood that the operation logic of the preset asymmetric quantization operator can be preset in the NPU by the developer of the NPU of the electronic device 100, or provided by the developer of the NPU to the developer of the electronic device 100, and preset in the memory of the electronic device 100 by the developer of the electronic device 100. The NPU of the electronic device 100 can call the operation logic of the asymmetric quantization operator according to the asymmetric quantization input data of the operator and the asymmetric quantization parameter of the asymmetric quantization input data, the asymmetric quantization parameter of the output data, and the asymmetric quantization constant data to obtain the asymmetric quantization fixed-point output data of the operator.

[0073] Specifically, in some embodiments, the above formula (1) and formula (2) can be used to obtain a calculation formula for converting a symmetrically quantized fixed-point number into a floating-point number as shown in formula (11).

[0074]

[0075] The electronic device 100 can determine the value range of the fixed-point input data according to the data type of the fixed-point input data of the symmetric quantization operator (for example, if the input data is INT8, it means that the value range is a fixed-point number [-128, 127], the maximum value is 127, and the minimum value is -128), and based on the maximum and minimum values ​​of the symmetric quantized input data and the symmetric quantization scaling coefficient of the symmetric quantized input data, determine the maximum and minimum values ​​of the floating-point number corresponding to the input data based on formula (11); then, based on the maximum and minimum values ​​of the floating-point number corresponding to the input data, determine the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the input data according to formula (4) and formula (5).

[0076] Similarly, the electronic device 100 can determine the value range of the fixed-point output data according to the type of output data of the symmetric quantization operator (for example, if the input data is INT8, it means that the value range is a fixed-point number [-128, 127], the maximum value is 127, and the minimum value is -128), and determine the maximum and minimum values ​​of the floating-point numbers corresponding to the output data based on formula (11) according to the maximum and minimum values ​​of the symmetric quantized output data and the symmetric quantization scaling coefficient; and then determine the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the output data based on formula (4) and formula (5).

[0077] Similarly, the electronic device 100 can also determine the maximum and minimum values ​​of the fixed-point numbers of the symmetric quantization constant data according to the data type of the symmetric quantization constant data in the symmetric quantization operator, and then determine the maximum and minimum values ​​of the floating-point numbers corresponding to the symmetric quantization constant data according to formula (11) based on the determined maximum and minimum values ​​and the symmetric quantization scaling coefficient of the symmetric quantization constant data; then determine the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the constant data according to formula (4) and formula (5) based on the determined maximum and minimum values ​​of the floating-point numbers; then, convert the symmetric quantization constant data to the corresponding floating-point constant data according to formula (11), and then convert the floating-point constant data corresponding to the symmetric quantization constant data to asymmetric quantization constant data according to formula (6) based on the determined asymmetric quantization scaling coefficient of the constant data, the asymmetric quantization zero point of the constant data and the floating-point constant data corresponding to the symmetric quantization constant data.

[0078] For example, suppose that the value range of each element in the input data matrix B_f of a convolution operator with asymmetric quantization of INT8 is a floating point number [-1, 1], and the floating point convolution kernel Then we can get that the value range of each element in the floating point convolution result D_f is [-0.7, 0.7].

[0079] According to formula (2), the symmetric quantization scaling coefficient of the input data B_Sc=127, and the symmetric quantization scaling coefficient of the output data D_Sc=181.43. Assuming that the quantization parameter of the convolution kernel C_f is the same as the symmetric quantization parameter of the input data B_f (i.e. C_Sc=127), according to formula (6), C_q= That is, the symmetric quantization parameters of the symmetric quantization convolution operator include: the symmetric quantization scaling coefficient B_Sc of the input data, the symmetric quantization scaling coefficient D_Sc of the output data, the symmetric quantization constant data C_q, and the symmetric quantization scaling coefficient C_Sc of the symmetric quantization constant data.

[0080] When the electronic device detects the above symmetric quantized convolution operator, it first determines the value range of the fixed-point input data D_q as [-128, 127], the maximum value is 127, and the minimum value is -128 according to the data type INT8 of the input data; q =127, B_Sc=127 are substituted into formula (11) to obtain the maximum floating point value corresponding to the input data, which is 1; q =0, B_Sc=-128 Substituting into formula (11), the minimum floating point number corresponding to the input data is -1, and then according to formula (4), the asymmetric quantization scaling coefficient of the input data B_ASc=(2 8 -1) / (1-(-1))=127.5. According to formula (5), the asymmetric quantization zero point Z of the input data can be obtained: p _B=round(-127.5×(-1))=128.

[0081] Similarly, the electronic device can determine the value range of the fixed-point output data D_q to be [-128, 127] according to the data type INT8 of the output data, with a maximum value of 127 and a minimum value of -128; q =127, D_Sc=181.43 are substituted into formula (11) to obtain the maximum floating point value corresponding to the output data, which is 127 / 181.43=0.7; q =-128, D_Ac = 181.43, and the minimum floating point number corresponding to the output data is 127 / 181.43 = -0.7. Then, according to formula (4), the asymmetric quantization scaling coefficient D_ASc = (2 8 -1) / (0.7-(-0.7))=182.14. According to formula (5), the asymmetric quantization zero point Z of the output data can be obtained: p _D=round(-182.14×(-0.7))=128.

[0082] Since the symmetric quantization parameter of the convolution kernel C_q is the same as the symmetric quantization parameter of the input data B_q, the asymmetric quantization parameter of the convolution kernel C_q should also be the same as the asymmetric quantization parameter of the input data B_q, that is, the asymmetric quantization scaling factor C_ASc of the convolution kernel C_q is 127.5, and the asymmetric quantization zero point Z of the convolution kernel is p _C=128. Substituting C_Sc=127 and C_q into formula (11), we can get Then C_f, C_ASc = 127.5, Z p _C=128 Formula (6) can obtain the symmetrically quantized convolution kernel

[0083] Then, the NPU of the electronic device 100 can be configured according to B_ASc=127.5, D_ASc=181.43, C_ASc=127.5, and Z p _B=128、Z p _C=128、Z p _D=128 and the fixed-point input data B_q is input to the convolution operator, the operation logic of the asymmetric quantized convolution operator shown in the preset formula (9) can be called to implement the function of the aforementioned symmetric quantized convolution operator, thereby increasing the types of neural network models that can be run by the NPU of the electronic device 100 and improving the versatility of the NPU.

[0084] The technical solution of the embodiment of the present application is introduced below in conjunction with a specific neural network model.

[0085] Figure 4 According to some embodiments of the present application, a schematic diagram of the structure of a neural network model 10 is shown. Figure 4 As shown, the neural network model 10 is a symmetric quantized neural network model, including an input layer 11, a convolution operator 12, a fully connected operator 13, a Softmax operator 14 and an output layer 15, which is used to classify the input image data. Among them, the input layer 11 is used to preprocess the input image and convert the input image data into symmetric quantized input data, such as INT8 type data; the convolution operator 12 is used to perform convolution operation on the symmetric quantized input data to obtain the symmetric quantized feature matrix corresponding to the input image; the fully connected operator 13 is used to perform a fully connected operation on the symmetric quantized feature matrix to obtain the score of the input image data belonging to each preset category; the Softmax operator 14 is used to obtain the probability that the input image data belongs to each preset category according to the score that the input image data belongs to each preset category; the output layer 15 is used to determine the category of the input image data according to the probability that the input image data belongs to each preset category, for example, the category with the highest probability that the input image data belongs to each preset category is used as the category of the input image data.

[0086] further, Figure 5 According to an embodiment of the present application, a schematic diagram of a process in which an electronic device classifies an image 20 using a neural network model 10 is shown.

[0087] refer to Figure 5 The electronic device first uses the input layer 11 to preprocess the image 20 to obtain the INT8 image matrix H, and the symmetric quantization scaling coefficient of the input layer 11 is Sc_out1=0.498.

[0088] Secondly, the image matrix H is respectively combined with the convolution kernel K using the convolution operator 12. i (i=1,2,3) performs convolution operation to obtain three feature matrices A i (i=1,2,3), the symmetric quantization scaling factor of the input data of the convolution operator 12 is Sc_in2=0.498, the symmetric quantization scaling factor of the output data is Sc_out2=0.0417, and the symmetric quantization constant data includes the convolution kernel K i (i=1, 2, 3) (the symmetric quantization parameter scaling coefficient of the convolution kernel is the same as the symmetric quantization scaling coefficient of the input data of the convolution operator 12).

[0089] Then use the fully connected operator 13 to pair the feature matrix A i (i=1,2,3) to perform full connection operation, for example, the feature matrix A i (i = 1, 2, 3) and the weight matrix W are inner-producted to obtain the score of the image 20 as a preset category (rabbit / dog / cat). The symmetric quantization scaling factor of the input data of the fully connected operator 13 is Sc_in3 = 0.0417, and the asymmetric quantization scaling factor of the output data is Sc_out3 = 1.1×10 -5 , the asymmetric quantization constant data includes a weight matrix W (the symmetric quantization scaling coefficient of the weight matrix is ​​the same as the symmetric quantization scaling coefficient of the input data of the fully connected operator 13).

[0090] Then, the Softmax operator 14 is used to obtain the probability that the image 20 is of the preset category from the lookup table LUT according to the score of the image 20 being of the preset category. The symmetric quantization scaling coefficient Sc_in4 of the input data of the Softmax operator 14 is 1.1×10 -5 , the symmetric quantization scaling coefficient of the output data is Sc_out4=127, and the asymmetric quantization constant data includes a lookup table LUT.

[0091] Finally, the output layer 15 is used to determine the category of image 20 according to the probability that image 20 belongs to each preset category. For example, the probabilities that image 20 belongs to each preset category are compared, and the highest probability among the probabilities that image 20 belongs to the preset category is determined as the category of image 20 (cat).

[0092] Combine the following Figure 4 The structure of the neural network model 10 shown and Figure 5 The process of classifying the image 20 by the neural network model 10 shown introduces the technical solution of the embodiment of the present application.

[0093] Specifically, Figure 6 According to some embodiments of the present application, a flowchart of a method for operating a neural network model is shown. The execution subject of the method is an electronic device 100, such as Figure 6 As shown, the process includes the following steps.

[0094] S601: A symmetric quantized neural network model is detected.

[0095] When the electronic device 100 detects that the neural network model to be run is a symmetric quantized neural network model, it triggers the method for running the neural network model provided in the embodiment of the present application.

[0096] In some embodiments, the electronic device 100 may determine whether the neural network is a symmetrically quantized neural network model based on the data type of the data in the neural network model to be run. Specifically, when the electronic device 100 detects that the data type of the data in the neural network model to be run is INT (INT includes but is not limited to INT4, INT8, INT16, INT32, etc.), for example, when the electronic device 100 detects that the data type of the data in the neural network model to be run is INT8, it determines that the neural network model to be run is a symmetrically quantized neural network model.

[0097] In some embodiments, the electronic device 100 may also determine whether the neural network model to be run is a symmetrically quantized neural network model based on the quantization parameters of each operator of the neural network model to be run. For example, the electronic device 100 may determine that the neural network model to be run is a symmetrically quantized neural network model when it is detected that the quantization parameters of the neural network model to be run include a scaling factor but do not include a zero point.

[0098] It can be understood that in other embodiments, the electronic device 100 can also determine whether the neural network model to be run is a symmetric quantized neural network model by other means, and when it is detected that the neural network model to be run is a symmetric quantized neural network model, it triggers the operation method of the neural network model provided in the embodiment of the present application.

[0099] S602: Acquire symmetric quantization parameters of input data / output data of each operator, and convert the symmetric quantization parameters into asymmetric quantization parameters.

[0100] That is, the electronic device 100 obtains the symmetric quantization parameters of the input data and output data of each operator in turn, and converts the symmetric quantization parameter of the input data (the symmetric quantization scaling coefficient of the input data) into the asymmetric quantization parameter of the input data (the asymmetric quantization scaling coefficient of the input data, the asymmetric quantization zero point of the input data), and converts the symmetric quantization parameter of the output data (the symmetric quantization scaling coefficient of the output data) into the asymmetric quantization parameter of the output data (the asymmetric quantization scaling coefficient of the output data, the asymmetric quantization zero point of the output data).

[0101] For example, for Figure 4 In the neural network model 10 shown, the symmetric quantization parameters of the input layer 11 include: the symmetric quantization scaling coefficient Sc_out1 of the output data = 0.498. Since the value range corresponding to INT8 is [-128, 127], according to formula (11), the maximum value of the floating point number corresponding to the output data is the floating point number 127 / 0.498 = 255, and the minimum value is the floating point number -128 / 0.498 = -257. The electronic device 100 can determine the asymmetric quantization scaling coefficient ASc_out1 of the output data of the input layer 11 based on formula (4) = (2 8 -1) / (255-(-257))=0.498, based on formula (5), the asymmetric quantization zero point Z of the output data of the input layer 11 is determined p _out1=round(-0.498×(-257))=128.

[0102] For example, for Figure 4 In the neural network model 10 shown, the symmetric quantization parameters of the convolution layer 12 include: the symmetric quantization scaling coefficient Sc_in2=0.498 of the input data, and the symmetric quantization scaling coefficient Sc_out2=0.0417 of the output data. Since the value range corresponding to INT8 is [-128, 127], according to formula (11), the maximum value of the floating point number corresponding to the input data is the floating point number 127 / 0.498=255, and the minimum value is the floating point number -128 / 0.498=-257, and the maximum value of the floating point number corresponding to the output data is the floating point number 127 / 0.0417=3046, and the minimum value is the floating point number -128 / 0.0417=-3070. The electronic device 100 can determine the asymmetric quantization scaling coefficient ASc_in2=(2 8 -1) / (255-(-257))=0.498, the asymmetric quantization scaling factor of the output data ASc_out2=(28 -1) / (3046-(-3070))=0.0417, based on formula (5), the asymmetric quantization zero point Z of the input data of the convolution operator 12 is determined p _in2 = round (-0.498 × (-257) = 128, the asymmetric quantization zero point Z of the output data p _out2 = round (-0.0417 × (-3070)) = 128. Similarly, the asymmetric quantization scaling factor ASc_in3 = 0.0417 of the input data of the fully connected layer 13 and the asymmetric quantization zero point Z of the input data can be obtained. p _in3 = 128, asymmetric quantization scaling factor of output data ASc_out3 = 1.1 × 10 -5 , the asymmetric quantization zero point Z of the output data p _out3=128.

[0103] For example, for Figure 4 In the neural network model 10 shown in FIG. 1 , the asymmetric quantization parameters of the Softmax operator 14 include: the symmetric quantization scaling coefficient Sc_in4 of the input data = 1.1×10 -5 , the symmetric quantization scaling factor of the output data Sc_out4 = 127. Since the value range corresponding to INT8 is [-128, 127], according to formula (11), the maximum floating point value corresponding to the input data is 127 / (1.1×10 -5 )=11545455, the minimum value is a floating point number -128 / (1.1×10 -5 )=-11636364, the maximum floating point number corresponding to the output data is 127 / 127=1, and the minimum floating point number is -128 / 127=-1. Based on formula (4), the asymmetric quantization scaling coefficient ASc_in4=(2 8 -1) / (11545455-(-11636364))=1.1×10 -5 , the asymmetric quantization scaling factor of the output data ASc_out4 = (2 8 -1) / (1-(-1))=127.5, based on formula (5), the asymmetric quantization zero point Z of the input data of the Softmax operator 14 is determined p _in4 = round(1.1×10 -5 ×(-11636364)=128, asymmetric quantization zero point Z of output data p _out4=round(-0.0417×(-3070))=128.

[0104] S603: Determine whether the current operator includes symmetric quantization constant data.

[0105] The electronic device 100 determines whether the current operator includes symmetric quantization constant data. If so, it means that the symmetric quantization constant data needs to be converted into asymmetric quantization constant data, and the process goes to step S604; otherwise, it means that the symmetric quantization constant data does not need to be converted into asymmetric quantization constant data, and the process goes to step S605.

[0106] For example, for the aforementioned neural network model 10, when the current operator is the input layer 11 or the output layer 15, the current operator does not have symmetric quantization constant data, and the process goes to step S605; for the aforementioned neural network model 10, the convolution operator 12 has symmetric quantization constant data convolution kernel K i (i=1, 2, 3), the fully connected operator 13 has a symmetric quantization constant data weight matrix W, and the Softmax operator 14 has a symmetric quantization constant data lookup table LUT. When the current operator is the convolution operator 12, the fully connected operator 13 or the Softmax operator 14, the electronic device 100 can determine that the current operator includes symmetric quantization constant data and go to step S604.

[0107] S604: Convert the symmetric quantization constant data into asymmetric quantization constant data according to the symmetric quantization parameter of the symmetric quantization constant data.

[0108] When the current operator has symmetric quantization constant data, the electronic device 100 first determines the maximum and minimum values ​​of the fixed-point data of the symmetric quantization constant data according to the data type of the fixed-point data of the symmetric quantization constant data according to the symmetric quantization parameter of the symmetric quantization constant data of the current operator, thereby determining the maximum and minimum values ​​of the floating-point data corresponding to the symmetric quantization constant data according to formula (11); then determines the asymmetric quantization scaling coefficient and asymmetric quantization zero point for converting the floating-point constant data into asymmetric quantization constant data according to formula (4) and formula (5); then converts the symmetric quantization constant data into the corresponding floating-point constant data according to formula (11), and then converts the floating-point constant data into asymmetric quantization constant data according to formula (6) and the determined asymmetric quantization scaling coefficient and asymmetric quantization zero point for converting the floating-point constant data into asymmetric quantization constant data.

[0109] For example, when the current operator is the aforementioned convolution operator 12, the symmetric quantization constant data includes the convolution kernel K i (i=1,2,3). Since the convolution kernel K i The symmetric quantization parameter of is the same as the symmetric quantization parameter of the input data of the convolution operator 12, then the convolution kernel K iThe asymmetric quantization scaling coefficient of is the same as the asymmetric quantization scaling coefficient of the input data of the convolution operator 12 (both are ASc_in2), and the convolution kernel K i The asymmetric quantization zero point of the convolution operator 12 is the same as the asymmetric quantization zero point of the input data (both are Z p _in2). The electronic device 100 can first convert K i Convert to the corresponding floating point number K i _f=K i / Sc_in2; then according to formula (6), K i _f is converted to an asymmetric quantized convolution kernel K i ′=round(K i _f×ASc_in2+Z p _in2). Specifically, refer to Figure 7 , assuming but

[0110] For another example, when the current operator is the aforementioned fully connected operator 13, the symmetric quantization constant data includes a weight matrix W. Since the symmetric quantization parameter of the weight matrix W is the same as the symmetric quantization parameter of the input data of the fully connected operator 13, the asymmetric quantization scaling coefficient of the weight matrix W is the same as the asymmetric quantization scaling coefficient of the input data of the fully connected operator 13 (ie, ASc_in3), and the asymmetric quantization zero point of the weight matrix W is the same as the asymmetric quantization zero point of the input data of the fully connected operator 13 (ie, Z p _in3). The electronic device 100 can first convert W into a corresponding floating point number W_f=W / Sc_in3 according to formula (11); then convert W_f into an asymmetric quantized weight matrix W′=round(W_f×ASc_in3+Z p _in3).

[0111] Specifically, refer to Figure 7 , assuming

[0112]

[0113] but

[0114]

[0115] For another example, when the current operator is the aforementioned Softmax operator 14, the symmetric quantization constant data includes a lookup table LUT. The Softmax operation can be expressed as the following formula (12).

[0116]

[0117] In formula (12), ink _f represents the floating point input data of the Softmax operator, that is, the floating point score of the input image data in the kth category; P k _f is the floating point output result of the Softmax operator, which indicates the probability that the input image data belongs to the kth category, where k=1 indicates the category is rabbit, k=2 indicates the category is dog, and k=3 indicates the category is cat. From formula (12), we can see that P k The value range of _f is [0, 1].

[0118] The lookup table LUT is used to store different fixed-point input data in k _q is the constant result of the Softmax operation corresponding to _q. For example, assuming that the symmetric quantization scaling factor of the output data of the fully connected operator 13 is 1.1×10 -5 ,, in1_q=30, in2_q=52, in3_q=91, then we can get in1_f=2727273, in2_f=4727273, in3_f=8272727, substituting in1_f=2727273, in2_f=4727273, in3_f=8272727 into the above formula (12), we can get P1_f=0.0069, P2_f=0.042, P3 _f=0.9511, then P1_f=0.0069, P2_f=0.042, P3_f=0.9511 are 8-bit symmetrically quantized to obtain: P1_q=1, P2_q=5, P3_q=121, that is, in the lookup table LUT, the lookup result corresponding to the lookup index [30, 52, 91] (corresponding to [in1, in2, in3]) is [1, 5, 121] (corresponding to P1, P2, P3). The lookup results corresponding to other lookup indexes can be obtained by similar methods, which will not be repeated here.

[0119] When the electronic device 100 detects the above-mentioned lookup table LUT, it first converts the lookup table index of the lookup table LUT into a floating-point lookup table index according to formula (11), converts the floating-point lookup table index into a symmetrically quantized fixed-point lookup table index, and substitutes the floating-point lookup table index into the above-mentioned formula (12) to obtain the floating-point number P k _f, and then the floating point number P k_f is asymmetrically quantized and the asymmetric quantization table lookup result is used as the table lookup result of the fixed-point table lookup index of the asymmetric quantization in the new lookup table LUT'. For example, the table lookup index [30, 52, 91] is converted into a floating point number to obtain in1_f = 2727273, in2_f = 4727273, in3_f = 8272727, in1_f = 2727273, in2_f = 4727273, in3_f = 8272727 with an asymmetric quantization scaling factor of ASc_in4 and an asymmetric quantization zero point of Z p _in4, 8-bit asymmetric quantization is performed to obtain a new table lookup index [158, 180, 219], and in1_f = 2727273, in2_f = 4727273, in3_f = 8272727 is substituted into the above formula (12) to obtain P1_f = 0.0069, P2_f = 0.042, P3_f = 0.9511, and then P1_f = 0.0069, P2_f = 0.042, P3_f = 0.9511 is replaced with an asymmetric quantization scaling factor of ASc_out4 and an asymmetric quantization zero point of Z p _out4 is quantized by 8 bits, and P1_q = 129, P2_q = 133, P3_q = 249 are obtained. Figure 7 In the lookup table LUT′ shown, the lookup result corresponding to the lookup index [158, 180, 219] (corresponding to [in1′, in2′, in3′]) is [129, 133, 249] (corresponding to P1′, P2′, P3′). The results corresponding to other lookup indexes can be obtained by similar methods, which will not be described in detail here.

[0120] It can be understood that the above conversion of symmetric quantized constant data in the convolution operator, fully connected operator and Softmax operator into asymmetric quantized constant data is only an example. For symmetric quantized constant data in other operators (including but not limited to pooling operators, activation operators, sorting operators, normalization operators, etc.), similar methods can be used to convert them into asymmetric quantized constant data, which will not be elaborated here.

[0121] S605: Determine whether the conversion of quantization parameters of all operators is completed.

[0122] The electronic device 100 determines whether the conversion of all operators is completed. If so, the process proceeds to step S606; otherwise, the process proceeds to step S602 to convert the quantization parameter of the next operator.

[0123] S606: According to the asymmetric quantization parameters of each operator, the operation logic of the corresponding asymmetric quantization operator is called to realize the function of the symmetric quantization neural network model.

[0124] After completing the conversion of the quantization parameters of all operators, the electronic device 100 calls the operation logic of the corresponding asymmetric quantization operator through the NPU according to the asymmetric quantization parameters of each operator to implement the function of the symmetric quantization neural network model.

[0125] Specifically, refer to Figure 7 After the electronic device 100 converts the symmetric quantization parameters of each operator of the neural network model 10 into asymmetric quantization parameters, each operator can be expressed as Figure 7 Shown are an input layer 11', a convolution operator 12', a fully connected operator 13', a Softmax operator 14', and an output layer 15'.

[0126] The NPU of the electronic device 100 may first quantize the image 20 into an image matrix H′ based on formula (1) when the asymmetric quantization scaling factor ASc_out1=0.0498.

[0127] Secondly, the NPU of the electronic device 100 calls the operation logic of the asymmetric quantized convolution operator, such as the operation logic shown in the above formula (9), when the convolution kernel is K i ′(i=1,2,3), the image matrix H′ is respectively i 'Convolve to get the fixed-point feature matrix A i ′(i=1, 2, 3). That is, the NPU obtains the asymmetric quantized input data B_q (such as the aforementioned H′), the asymmetric quantized scaling coefficient B_ASc of the input data (such as the AS obtained in the aforementioned step S602), and the asymmetric quantized scaling coefficient B_ASc of the input data. c _in2), the asymmetric quantization zero point of the input data (for example, Z obtained in the above step S602) p _in2), an asymmetric quantized convolution kernel C_q (for example, the convolution kernel K obtained in the aforementioned step S603) i ′), the asymmetric quantization scaling coefficient C_Sc of the convolution kernel (for example, the aforementioned AS c _in2), the asymmetric quantization zero point of the convolution kernel (for example, Z obtained in the above step S602 p _in2), the asymmetric quantization scaling coefficient D_ASc of the output data (for example, the AS obtained in the above step S602) c _out2), the asymmetric quantization zero point of the output data (for example, the Z obtained in the above step S602) p _out2), and then obtain D_q according to the above formula (9). For example, in the case of B_q = H', C_q = K1', the above characteristic matrix A1' can be obtained.

[0128] It can be understood that since there is no circuit in the NPU that can directly implement the division operation, in some embodiments, the division operation in formula (9) can be implemented by multiplication shift to increase the speed of the NPU running the convolution operator. For example, assuming B_ASc×C_ASc=0.498 2 =0.248, 0.248 can be expressed as 1 / 1×2 -2 , so that (B_q-Z p _B)*(C_q-Z p _C)×D_ASc, shift the binary number corresponding to the result right by -2 bits and multiply it by 1 to get (B_q-Z p _B)*(C_q-Z p _C)×D_ASc / (BA_Sc×C_ASc), and then add Z to the result. p _D can get D_q.

[0129] Then, the NPU of the electronic device 100 calls the operation logic of the asymmetric quantized fully connected operator (for example, the operation logic shown in the following formula (17)), and respectively converts the feature matrix A i ' and the weight matrix W' perform a full connection operation, such as an inner product, to obtain the scores in1', in2' and in3' of the image 20 for each preset category; then call the operation logic of the asymmetric quantized Softmax operator, that is, use [in1', in2', in3'] as the table index to find the probability of the image 20 belonging to each preset category from the lookup table LUT'; finally, call the operation logic of the asymmetric quantized output layer, that is, take the preset category corresponding to the maximum probability of the image 20 belonging to each preset category as the category of the image 20, for example, determine the category of the image 20 as a cat. Among them, the derivation process of the operation logic of the asymmetric quantized fully connected operator will be introduced below, and will not be repeated here.

[0130] It can be understood that the operation logic of the asymmetric quantization operator can be pre-set in the NPU by the developer of the NPU of the electronic device 100, or provided by the developer of the NPU to the developer of the electronic device 100 and preset in the memory of the electronic device 100 by the developer of the electronic device 100.

[0131] It can be understood that each step from step S601 to step S605 can be completed entirely by the CPU of the electronic device 100, or entirely by the NPU of the electronic device 100, or some steps can be completed separately by the CPU and NPU of the electronic device 100, which is not limited here.

[0132] It can be understood that the running order of the above steps S601 to S605 is only an example. In some other embodiments, the running order of some steps can be adjusted, and some steps can also be combined or split. The embodiments of the present application do not make any limitations in this regard.

[0133] Through the method provided by the embodiments of the present application, the NPU of the electronic device 100 can implement the relevant functions of the symmetric quantization neural network model by calling a preset asymmetric quantization operator, without the need for other electronic devices to convert the symmetric quantization neural network model into a floating-point neural network model and then convert the floating-point neural network model into an asymmetric quantization neural network model before running on the NPU of the electronic device 100. This increases the types of neural network models that the electronic device 100 can run, improves the versatility of the NPU, and enhances the deployment speed of the neural network model.

[0134] The following introduces the specific process of convolution calculation and the operation logic of the symmetric quantization fully connected operator.

[0135] First, the calculation process of convolution operation is introduced.

[0136] Assume that the size of matrix B is M×M, the size of convolution kernel C is N×N, and the convolution step is k. Then the convolution result D of matrix B and convolution kernel C can be expressed as:

[0137]

[0138] In formula (13), D(m, n) is the element in the m-th row and n-th column of matrix D; m and n satisfy the following relational expressions:

[0139]

[0140] where is the floor operation, that is is the largest integer less than X. Since M - N < M and k is a positive integer, it can be seen that That is to say, the size of the convolution result D is always less than or equal to the size of matrix B.

[0141] To ensure that the size of the matrix corresponding to the convolution result is the same as the size of the input data and avoid losing the data features at the edges of the data matrix, usually in the process of convolution calculation, rows with a value of 0 are filled before the first row and after the last row of the input matrix, and rows or columns with a value of 0 are filled before the first column and after the last column of the input matrix, that is, rows or columns with a value of 0 are filled around the input matrix. Assume that the number of values of 0 filled around the input matrix B is P for each side. At this time, the size of the input matrix B becomes (M + 2P)×(M + 2P). At this time, m and n in formula (1) satisfy the following relational expressions:

[0142]

[0143] make The value of P can be calculated. For example, when the convolution kernel size is N=3 and the step size k=1, then P=1.

[0144] The operation logic of the asymmetric quantized fully connected operator is introduced below.

[0145] The fully connected operator is an operator that performs weighted calculation on the input data. The fully connected calculation result F of the input matrix E and the weight matrix W can be expressed as the following formula (14).

[0146]

[0147] Among them, E(i, j) is the element in the i-th row and j-th column of the input matrix, W(i, j) is the element in the i-th row and j-th column of the weight matrix, and the size of the input matrix E and the weight matrix W are both M×N.

[0148] Assuming that E_f is the floating-point input matrix of the fully connected operator, W_f is the floating-point weight matrix, and F_f is the floating-point fully connected calculation result, based on formula (14), the relationship between E_f, W_f, and F_f can be expressed as follows: formula (15).

[0149]

[0150] According to formula (6), we can get E_f = (E_q - Z p _E) / E_ASc, W_f=(W_q-Z p _W) / W_ASc, F_f=(F_q-Z p _F) / F_ASc, where: E_q is the fixed-point matrix of asymmetric quantization corresponding to E_f, E_ASc is the asymmetric quantization scaling factor that quantizes E_f to E_q, Z p _E is the asymmetric quantization zero point that quantizes E_f to E_q; W_q is the fixed-point weight matrix of the asymmetric quantization corresponding to W_f, W_ASc is the asymmetric quantization scaling factor that quantizes W_f to W_q, Z p _W is the asymmetric quantization zero point for quantizing W_f to W_q; F_q is the fixed-point number of asymmetric quantization corresponding to F_f, F_ASc is the asymmetric quantization scaling factor for quantizing F_f to F_q, Z p _F is the asymmetric quantization zero point for quantizing F_f to F_q. Then, formula (15) can be expressed as the following formula (16).

[0151]

[0152] By transforming formula (16), we can obtain the operation logic of the asymmetric quantized fully connected operator as shown in the following formula (17).

[0153]

[0154] When the NPU executes the operation logic of the fully connected operator shown in formula (17), it obtains the asymmetric quantized input data E_q (for example, the aforementioned A i ′(i=1,2,3)) and the asymmetric quantization scaling factor E_ASc of the input data (e.g., the AS obtained in the aforementioned step S602) c _in3), asymmetric quantization zero point Z of input data p _E (for example, Z obtained in the above step S602) p _in3), an asymmetric quantized weight matrix W_q (for example, the weight matrix W′ obtained in the aforementioned step S603), and an asymmetric quantized scaling coefficient W_ASc (for example, the aforementioned AS c _in3), asymmetric quantization zero point Z of the weight matrix p _E (for example, Z obtained in the above step S602) p _in3), the asymmetric quantization scaling factor F_ASc of the output data (for example, the AS obtained in the above step S602) c _out3), asymmetric quantization zero point Z of output data p _F (for example, Z obtained in the above step S602) p _out3), and then according to the above formula (17) we get A i The full connection calculation result of ′ and W′, for example, when E_q=A1′, the aforementioned in1′ can be obtained.

[0155] It can be understood that since there is no circuit in the NPU that can directly implement the division operation, in some embodiments, the division operation in formula (17) can be implemented by shifting and multiplication to increase the speed of the NPU running the fully connected operator. For example, assuming E_ASc×W_ASc=0.0417 2 = 0.00174, 0.00174 can be expressed as 1 / 9×2 -6 , thus The binary number corresponding to the result of the shift right by -6 bits (that is, shift left by 6 bits) and then multiply by 9, we can get The result of the operation is finally added to Z p _F can get the full connection calculation result F_q.

[0156] It can be understood that in other embodiments, the full connection operator may also adopt other operation logics, which is not limited in the embodiments of the present application.

[0157] It can be understood that for other asymmetric quantization operators, the operation logic can be obtained by similar methods, which will not be described in detail here.

[0158] 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 As shown, the electronic device 100 includes one or more processors 101A, NPU 101B, system memory 102, non-volatile memory (NVM) 103, communication interface 104, input / output (I / O) device 105, and system control logic 106 for coupling the processor 101A, system memory 102, non-volatile memory 103, communication interface 104 and input / output (I / O) device 105. Among them:

[0159] The processor 101A 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) processor or a programmable logic device FPGA (Field Programmable Gate Array) The processing module or processing circuit may include one or more single-core or multi-core processors.

[0160] The neural network processor 101B can be used to call the operation logic of the preset asymmetric quantized operator to realize the reasoning of the neural network model. The neural network processor 101B can be an independent processor or integrated into the processor 101A. In some embodiments, the NPU can be used to run the instructions corresponding to the operation method of the neural network model provided in the embodiment of the present application.

[0161] 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 neural network model 10, asymmetric / symmetric quantization parameters, asymmetric / symmetric quantization constant data, etc., and can also be used to store the operation logic of a preset asymmetric quantization operator.

[0162] 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. In other embodiments, the non-volatile memory 103 may be used to store the relevant instructions, asymmetric / symmetric quantization parameters, asymmetric / symmetric quantization constant data, etc. of the above-mentioned neural network model 10, and may also be used to store the operation logic of a preset asymmetric quantization operator.

[0163] 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: when executed by at least one of the processor 101A and / or the neural network processor 101B, the electronic device 100 implements the operation method of the neural network model provided in various embodiments of the present application.

[0164] The communication interface 104 may include a transceiver for providing a wired or wireless communication interface for the electronic device 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 electronic device 100, for example, the communication interface 104 may be integrated into the processor 101A. In some embodiments, the electronic device 100 may communicate with other devices through the communication interface 104, for example, the electronic device 100 may obtain a neural network model to be run from other electronic devices through the communication interface 104.

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

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

[0167] In some embodiments, at least one of the processors 101A 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 101A 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).

[0168] 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, 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.

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

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

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

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

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

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

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

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

[0177] 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 method for operating a neural network model, applied to an electronic device, characterized in that: include: Inputting image data into a first neural network model, wherein the first neural network model is a symmetric quantized neural network model, and the first neural network model includes symmetric quantization parameters of each operator of the first neural network model; The symmetric quantization parameters include: symmetric quantization parameters of constant data, wherein the symmetric quantization parameters of the constant data include symmetric quantization constant data and symmetric quantization scaling coefficients of the symmetric quantization constant data, the symmetric quantization constant data also includes a symmetric quantization lookup table, and the symmetric quantization lookup table includes a symmetric quantization lookup table index and a symmetric quantization lookup table result corresponding to each symmetric quantization lookup table index; Converting the symmetric quantization parameters of the operators into asymmetric quantization parameters; The converting of the symmetric quantization parameters of the operators into asymmetric quantization parameters comprises: Determining, according to the symmetric quantization scaling coefficient of the symmetric quantization constant data, a floating point number lookup table index corresponding to each of the symmetric quantization lookup table indexes; Determine the floating-point table lookup result corresponding to each of the floating-point table lookup indexes according to the floating-point table lookup indexes corresponding to each of the symmetric quantization table lookup indexes and the operation logic of each of the operators; Obtain an asymmetric quantization table lookup index according to the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point table lookup index, and obtain a symmetric quantization table lookup result according to the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point table lookup result, wherein the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point table lookup index are determined based on the data type of the symmetric quantization table lookup index, and the asymmetric quantization scaling coefficient and the asymmetric quantization zero point of the floating-point table lookup result are determined based on the data type of the symmetric quantization table lookup result; Obtaining an asymmetric quantization lookup table based on each of the asymmetric quantization lookup table indexes and the corresponding asymmetric quantization lookup table results; Using the asymmetric quantization parameters of each of the operators, calling the operation logic of the preset asymmetric quantization operator, and obtaining the inference result of the first neural network model; A category of the image data is determined based on the inference result.

2. The method according to claim 1, characterized in that: The electronic device includes a first processor, the first processor can infer an asymmetric quantized neural network model but cannot infer a symmetric quantized neural network model; and The first neural network model is run by the first processor.

3. The method according to claim 1 or 2, characterized in that: The symmetric quantization parameter also includes at least one of the following parameters: a symmetric quantization scaling coefficient of input data and a symmetric quantization scaling coefficient of output data.

4. The method according to claim 3, characterized in that The converting the symmetric quantization parameters of the operators into asymmetric quantization parameters comprises: Determine a maximum value and a minimum value of a floating-point number corresponding to the input data or the output data according to a data type of the input data or the output data and a symmetric quantization scaling factor of the input data or the output data; An asymmetric quantization scaling coefficient and an asymmetric quantization zero point of the input data or the output data are determined according to a maximum value and a minimum value of the floating-point number corresponding to the input data or the output data.

5. The method according to claim 4, characterized in that Determining the maximum value and the minimum value of the floating-point number corresponding to the input data or the output data according to the data type of the input data or the output data and the symmetric quantization scaling coefficient of the input data or the output data, comprising: Determine the maximum and minimum fixed-point values ​​of the input data or the output data according to the data type of the input data or the output data of each operator; The maximum value and the minimum value of the floating-point number corresponding to the input data or the output data are determined according to the symmetric quantization scaling coefficient of the input data or the output data and the maximum value and the minimum value of the fixed-point number of the input data or the output data.

6. The method according to claim 3, characterized in that The symmetric quantization constant data includes a symmetric quantization constant and a symmetric quantization matrix; and the converting of the symmetric quantization parameters of each operator into an asymmetric quantization parameter includes: Determining a maximum value and a minimum value of a floating-point number corresponding to the symmetric quantization constant data according to a data type of the symmetric quantization constant data and a symmetric quantization scaling coefficient of the symmetric quantization constant data; Determining an asymmetric quantization scaling coefficient and an asymmetric quantization zero point of the floating-point number corresponding to the symmetric quantization constant data according to a maximum value and a minimum value of the floating-point number corresponding to the symmetric quantization constant data; According to the determined asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating-point number corresponding to the symmetric quantization constant data, the floating-point constant data corresponding to the symmetric quantization constant data is converted into asymmetric quantization constant data, wherein the floating-point constant data corresponding to the symmetric quantization constant data is determined by the symmetric quantization parameter of the constant data.

7. The method according to claim 6, characterized in that The determining, according to the data type of the symmetric quantization constant data and the symmetric quantization scaling coefficient of the symmetric quantization constant data, the maximum value and the minimum value of the floating-point number corresponding to the symmetric quantization constant data comprises: Determining the maximum value and the minimum value of the fixed-point number of the symmetric quantization constant data according to the data type of the symmetric quantization constant data; According to the symmetric quantization scaling coefficient of the symmetric quantization constant data and the determined maximum and minimum values ​​of the fixed-point numbers of the symmetric quantization constant data, the maximum and minimum values ​​of the floating-point numbers corresponding to the symmetric quantization constant data are determined.

8. The method according to claim 1, characterized in that Also includes: Determine the maximum and minimum values ​​of the fixed-point numbers corresponding to the lookup index of the symmetric quantization or the lookup result of the asymmetric quantization according to the data type of the lookup index of the symmetric quantization or the lookup result of the asymmetric quantization, and determine the maximum and minimum values ​​of the fixed-point number lookup index corresponding to the lookup index of the symmetric quantization or the maximum and minimum values ​​of the fixed-point number lookup result corresponding to the lookup result of the asymmetric quantization according to the symmetric quantization scaling coefficient of the symmetric quantization constant data based on the determined maximum and minimum values; Determine the asymmetric quantization scaling coefficient and asymmetric quantization zero point of the floating-point number lookup index or the floating-point number lookup result based on the maximum and minimum values ​​of the floating-point number lookup index corresponding to the determined symmetric quantization lookup index or the maximum and minimum values ​​of the floating-point number lookup result corresponding to the symmetric quantization lookup result.

9. A readable medium, characterized in that: The readable medium contains instructions, which, when executed by a processor of an electronic device, enable the electronic device to implement the operating method of the neural network model described in any one of claims 1 to 8.

10. An electronic device, characterized in that: include: a memory for storing instructions to be executed by one or more processors of the electronic device; And a processor, which is one of the processors of the electronic device, is used to execute the instructions to enable the electronic device to implement the operating method of the neural network model described in any one of claims 1 to 8.