Neural network model quantification method and device, medium and equipment

By dividing the quantified input data range into multiple preset data intervals, and determining the interval based on the gradient size of the output value change of the quantization operator, the storage pressure and accuracy problems of the quantitative table lookup operation in the deep learning model are solved, and a more efficient implementation is achieved. table lookup operation.

CN118607607APending Publication Date: 2024-09-06BEIJING HORIZON INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410773328.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

The floating-point operation time and hardware cost in the deep learning model are high. When performing quantized table lookup operations, the calculation is complex and the storage pressure is high for more complex operators such as exponential operators and sine operators, especially int16 lookups with large quantization bit widths. Table operations lead to greater storage pressure.

Method used

By dividing the quantified input data range into multiple preset data intervals, the interval is determined based on the gradient size of the output value change of the quantization operator, and segmented table lookup is performed to reduce storage pressure and improve table lookup accuracy.

Benefits of technology

It effectively reduces the storage pressure of table items and improves the overall table lookup accuracy. Especially in the part where the output value of the quantization operator fluctuates greatly, the segmented interval covers a smaller range of input data, which improves the table lookup accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118607607A
    Figure CN118607607A
Patent Text Reader

Abstract

The embodiment of the invention discloses a quantification method and device of a neural network model, a medium and equipment, and the method comprises the steps: determining the quantification input data corresponding to the input data based on an operator during the operation of the neural network model and the corresponding input data; determining a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on the change gradient of the output value of the quantization operator along with the input value; the quantization operator is an operator quantized by the operator; based on the quantized input data and index information corresponding to the target data interval, determining a target quantized output value corresponding to the quantized input data; and determining a quantization result of the input data calculated by the operator based on the target quantization output value. According to the embodiment of the invention, the overall table look-up precision can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to computer technology, and in particular to a quantization method, device, medium and equipment for a neural network model. Background Art

[0002] For deep learning models, floating-point operations take a lot of time and hardware costs, so the time and hardware costs are usually reduced by quantizing the model into integers. When calculating quantized data, for more complex operators, such as the exponential operator (exp operator) and the sine operator (sin operator), even if the quantized operators are obtained, the calculation is still complicated, and the calculation results are usually obtained by table lookup. However, for quantization table lookup operations with larger quantization bit widths, the table entries used for lookup are larger. For example, for the quantization table lookup operation of int16, the input data range includes 65536 integers. If a table of size 65536 is made to store 65536 different calculation results, it is easy to cause high storage pressure. Summary of the invention

[0003] The embodiments of the present disclosure provide a quantization method, apparatus, medium and device for a neural network model, which can divide the quantized input data range into multiple preset data intervals based on the gradient of the output value of the quantization operator with the input value, for segmented table lookup, reduce storage pressure, and improve overall table lookup accuracy.

[0004] A first aspect of the present disclosure provides a quantization method for a neural network model, comprising:

[0005] Determine quantized input data corresponding to the input data based on an operation operator and corresponding input data during operation of the neural network model;

[0006] Determine a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on a gradient of an output value of a quantization operator with respect to an input value; the quantization operator is an operator quantized by the operation operator;

[0007] Determining a target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval;

[0008] Based on the target quantized output value, a quantized result of the input data after being calculated by the operation operator is determined.

[0009] A second aspect of the present disclosure provides a quantization device for a neural network model, comprising:

[0010] A first processing module, used for determining quantized input data corresponding to the input data based on an operation operator and corresponding input data during operation of the neural network model;

[0011] A second processing module, configured to determine a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on a gradient of an output value of a quantization operator with respect to an input value; the quantization operator is an operator quantized by the operation operator;

[0012] A third processing module, configured to determine a target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval;

[0013] The fourth processing module is used to determine the quantization result of the input data after being calculated by the operation operator based on the target quantization output value.

[0014] According to a third aspect of the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and the computer program is used to execute the quantization method of the neural network model described in any of the above embodiments of the present disclosure.

[0015] The fourth aspect of the present disclosure provides an electronic device, comprising: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the quantization method of the neural network model described in any of the above embodiments of the present disclosure.

[0016] A fifth aspect of the present disclosure provides a computer program product. When the instructions in the computer program product are executed by a processor, the quantization method of the neural network model provided by any of the above embodiments of the present disclosure is executed.

[0017] Based on the quantization method, device, medium and equipment of the neural network model provided by the above-mentioned embodiments of the present disclosure, it is possible to determine the quantized input data corresponding to the input data based on the operation operator and the corresponding input data during the operation of the neural network model, determine the target data interval corresponding to the quantized input data from multiple preset data intervals, and then determine the target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval, and determine the quantization result of the input data after being calculated by the operation operator based on the target quantized output value. Since the quantization input data range is divided into multiple preset data intervals, each preset data interval can implement table lookup operations through smaller table entries, thereby reducing the storage pressure caused by the table entries, and since multiple preset data intervals are determined based on the gradient size of the output value of the quantization operator corresponding to the operation operator as the input value changes, the gradient size of the output value of the quantization operator in any preset data interval as the input value changes is similar, so that in the part where the output value of the quantization operator fluctuates greatly, the input data range covered by the divided preset data interval is smaller, so that the corresponding preset data interval is made within a smaller input data range, which helps to improve the table lookup accuracy. In the part where the output value of the quantization operator fluctuates less, the input data range covered by the divided preset data interval is larger. Since the output value of the quantization operator in this part fluctuates less, the impact on the table lookup accuracy of the corresponding preset data interval is less, thereby improving the overall table lookup accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 This is an exemplary application scenario of the quantization method of the neural network model provided by the present disclosure;

[0019] Figure 2 is a flowchart of a quantization method of a neural network model provided by an exemplary embodiment of the present disclosure;

[0020] Figure 3 is a schematic diagram of a process for determining multiple preset data intervals provided by an exemplary embodiment of the present disclosure;

[0021] Figure 4 is a schematic diagram of a process for determining multiple preset data intervals provided by another exemplary embodiment of the present disclosure;

[0022] Figure 5 is a schematic diagram of a process for determining multiple preset data intervals provided by another exemplary embodiment of the present disclosure;

[0023] Figure 6 is a flowchart of a quantization method of a neural network model provided by another exemplary embodiment of the present disclosure;

[0024] Figure 7 is a flowchart of a quantization method of a neural network model provided by another exemplary embodiment of the present disclosure;

[0025] Figure 8 is a schematic diagram of a process for determining table lookup area index information provided by an exemplary embodiment of the present disclosure;

[0026] Fig. 9 is a comparative schematic diagram of two methods of determining a quantized output value provided by an exemplary embodiment of the present disclosure;

[0027] Fig.10 is a schematic diagram of a process for determining table lookup area index information provided by another exemplary embodiment of the present disclosure;

[0028] Fig.11 is a schematic diagram of a process for determining table lookup area index information provided by another exemplary embodiment of the present disclosure;

[0029] Fig.12 is a schematic diagram of a lower convex shell provided by an exemplary embodiment of the present disclosure;

[0030] Fig.13 is a schematic diagram of a process for determining multiple preset data intervals provided by another exemplary embodiment of the present disclosure;

[0031] Fig.14 is a flowchart of a quantization method of a neural network model provided by another exemplary embodiment of the present disclosure;

[0032] Fig.15 is a schematic diagram of multiple preset data intervals provided by an exemplary embodiment of the present disclosure;

[0033] Fig.16 is a schematic diagram of multiple table lookup areas provided by an exemplary embodiment of the present disclosure;

[0034] Fig.17 is a structural schematic diagram of a quantization device for a neural network model provided by an exemplary embodiment of the present disclosure;

[0035] Fig.18 is a schematic structural diagram of a quantization device for a neural network model provided by another exemplary embodiment of the present disclosure;

[0036] Fig.19 is a structural schematic diagram of a quantization device for a neural network model provided by yet another exemplary embodiment of the present disclosure;

[0037] Fig. 20 is a structural schematic diagram of a quantization device for a neural network model provided by another exemplary embodiment of the present disclosure;

[0038] Fig.21 is a structural schematic diagram of a quantization device for a neural network model provided by yet another exemplary embodiment of the present disclosure;

[0039] Fig. 22 It is a structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0040] To explain the present disclosure, example embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. It should be understood that the present disclosure is not limited to the example embodiments.

[0041] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0042] SUMMARY OF THE DISCLOSURE

[0043] In the process of implementing the present disclosure, the inventors found that for deep learning models, the time and hardware costs of floating-point operations are high, and the time and hardware costs are usually reduced by quantizing the model into integers. When calculating quantized data, for more complex operators, such as exponential operators (exp operators), sine operators (sin operators), etc., even if the quantized operators are obtained, the calculation is still complicated, and the calculation results are usually obtained by table lookup. However, for quantization table lookup operations with larger quantization bit widths, the table entries used for lookup are larger, such as the quantization table lookup operation of int16, the input data range contains 65536 integers, and if a table of size 65536 is made to store 65536 different calculation results, it is easy to cause a large storage pressure. In the related art, the input data range is usually divided into 8 intervals, and the 8 intervals include two linear areas on the left and right and 6 equally divided table lookup areas in the middle. For the linear area, the fitting parameters of the linear area are obtained by linear fitting, and the quantized output value corresponding to the quantized input data is obtained based on the fitting parameters. For the table lookup area, each table lookup area corresponds to a table entry (or index information), which includes 64 preset index values ​​from 0 to 63 and the table lookup results corresponding to each preset index value (i.e., the quantized output value at the index value). Each table lookup area maps the quantized input data to the index value range of the table lookup area through a set of mapping parameters, which is used to perform table lookup operations to obtain the quantized output value corresponding to the quantized input data. For input data mapped between two adjacent preset index values, the corresponding quantized output value is obtained by interpolation. Since the input data intervals corresponding to the six table lookup areas are evenly divided, for some complex quantization operators, such as the operation operator , x represents the input data of the operator. If the output value of the quantization operator corresponding to the operator fluctuates greatly within the range of part of the input data, but falls within the preset index value range of i (i=0,1,…,62) to i+1 in the corresponding table lookup area, and the quantization output value within the range needs to be obtained by interpolating the quantization output values ​​at i and i+1, that is, the part of the quantization operator between i and i+1 is represented by a linear fitting line segment. Obviously, the line segment cannot represent the large fluctuation within the range. Therefore, it is easy to cause the table lookup accuracy of the part with larger fluctuation to be low, thereby reducing the overall table lookup accuracy of the quantization operator.

[0044] Exemplary Overview

[0045] Figure 1 This is an exemplary application scenario of the quantization method of the neural network model provided by the present disclosure. Figure 1 As shown, the neural network model 11 includes a plurality of operators, and the plurality of operators include, for example, n operators, including operators 111 to operators 11n. During the quantization process of the neural network model 11, for some complex operators in the neural network model 11, the quantization result of the input data of the operator after being calculated by the operator can be obtained through the quantization method of the neural network model disclosed in the present invention (executed in the quantization device 12 of the neural network model). Specifically, based on the operator and the corresponding input data during the operation of the neural network model, the quantized input data corresponding to the input data can be determined, and the target data interval corresponding to the quantized input data can be determined from multiple preset data intervals, and then the target quantized output value corresponding to the quantized input data can be determined based on the index information corresponding to the quantized input data and the target data interval, and based on the target quantized output value, the quantized result of the input data after being calculated by the operator can be determined. Since the quantization input data range is divided into multiple preset data intervals, each preset data interval can implement table lookup operations through smaller table entries, thereby reducing the storage pressure caused by the table entries, and since multiple preset data intervals are determined based on the gradient size of the output value of the quantization operator corresponding to the operation operator as the input value changes, the gradient size of the output value of the quantization operator in any preset data interval as the input value changes can be made similar, so that in the part where the output value of the quantization operator fluctuates greatly, the input data range covered by the divided preset data interval is smaller, so that the corresponding preset data interval is made within a smaller input data range, which helps to improve the table lookup accuracy. In the part where the output value of the quantization operator fluctuates less, the input data range covered by the divided preset data interval is larger. Since the output value of the quantization operator in this part fluctuates less, the impact on the table lookup accuracy of the corresponding preset data interval is less, thereby improving the overall table lookup accuracy.

[0046] Exemplary Methods

[0047] Figure 2 is a flowchart of a quantization method of a neural network model provided by an exemplary embodiment of the present disclosure. This embodiment can be applied to electronic devices, such as servers, terminal devices, vehicle-mounted computing platforms, and other electronic devices, such as Figure 2 As shown, the method of the embodiment of the present disclosure may include the following steps:

[0048] Step 201, based on the operation operator and the corresponding input data during the operation of the neural network model, determine the quantized input data corresponding to the input data.

[0049] Among them, the neural network model can be any model of any scene, for example, the neural network model can be a target detection model, a semantic segmentation model, an image classification model, a trajectory prediction model, a speech recognition model, a text recognition model, etc., without specific limitation. The operation operator during the operation of the neural network model refers to various operators that realize the operation of the neural network model. For example, the operation operator can include an exponential operator (exp operator), a sine operator (sin operator), a logarithmic operator (log) and any other possible operators, without specific limitation. The input data corresponding to the operation operator refers to the input data that needs to be calculated by the operation operator. The input data can be the input data of the model (that is, the current operation operator is the first operator of the model) or the feature data generated during the model reasoning process (that is, the feature data output by other operation operators before the current operation operator). The input data of the model can be image data, text data, speech data, etc. For example, the exponential operator is expressed as y=exp(x), then x represents the input data, and y represents the output data after the exponential operator operation. The quantized input data corresponding to the input data refers to the input data of the preset data format obtained by quantizing the input data according to the preset quantization method. The preset data format may include a data type and a bit width. For example, the preset data format is int8, int16, int12, int24, int32, etc. In which, int indicates that the data type is an integer, and the value after int indicates the bit width, such as int16 indicates an integer data with a bit width of 16.

[0050] For example, the operation operator is a floating point (float) exp operator, which is expressed as Among them, the input data x float and the output value y float Both represent floating-point tensors or values. Converting floating-point input data to fixed-point quantized input data through a set of constants is called quantization of input data. The quantization formula can be expressed as follows:

[0051]

[0052] Among them, scale and z are the above-mentioned set of constants, scale is a floating point number, and z is an integer in a specified range. The specified range can be, for example, int8 range, int16 range, etc., which is determined according to the quantization requirements. round() is a rounding function, and clamp() is used to saturate the result of round() within the specified range, which can be, for example, int8, int16, int32, etc. Taking int8 as an example, the data range of int8 is 0 to 255. If the result of round() is greater than 255, 255 is used as x. int If the result of round() is less than 0, 0 is used as x. int .

[0053] In some optional embodiments, the quantized input data corresponding to the input data may include one or more quantized input values. For example, if the input data is a tensor (e.g., a one-dimensional vector, a two-dimensional matrix, a three-dimensional tensor, etc.), that is, the input data includes multiple input values, then the quantized input data may include a quantized input value corresponding to each input value.

[0054] Step 202: determining a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on a gradient of an output value of a quantization operator with respect to an input value.

[0055] Among them, the quantization operator is the operator after the operation operator is quantized. The multiple preset data intervals are multiple data intervals into which the quantized input data range is divided based on the gradient size of the output value of the quantization operator within the quantized input data range with the input value. For example, the quantized input data range of int16 is in the range of -32768 to 32767, and the data range is divided into multiple data intervals as multiple preset data intervals. The number of preset data intervals included in the multiple preset data intervals can be any number, for example, the number of preset data intervals can be 2, 3, 6, 8, 12, etc.

[0056] In some optional embodiments, the plurality of preset data intervals may include a plurality of table lookup areas, that is, each preset data interval is a table lookup area.

[0057] In some optional embodiments, the plurality of preset data intervals may include linear regions and table lookup regions. The number of linear regions may be one or two. The number of table lookup regions may be at least one. For example, the plurality of preset data intervals may include two linear regions and a plurality of table lookup regions. The two linear regions are the intervals at the left and right ends of the quantized input data range, namely the left linear region (also referred to as the first linear region) and the right linear region (also referred to as the second linear region). The plurality of table lookup regions are nonlinear regions other than the linear region within the quantized input data range, and the nonlinear region is divided into a plurality of table lookup regions. For example, the quantized input data range [-32768, 32767] is divided into the first linear region [-32768, a1), the second linear region (a7, 32767], the table lookup region [a1, a2), the table lookup region [a2, a3), the table lookup region [a3, a4), the table lookup region [a4, a5), the table lookup region [a5, a6) and the table lookup region [a6, a7).

[0058] In some optional embodiments, the quantized input data may be matched with each preset data interval, and the preset data interval to which the quantized input data belongs may be determined as the target data interval corresponding to the quantized input data.

[0059] In some optional embodiments, the gradient of the change of the output value of the quantization operator with the input value can characterize the fluctuation degree of the quantization operator. The purpose of determining multiple preset data intervals based on the gradient of the change of the output value of the quantization operator with the input value is to make the fluctuation degree of the quantization operator in each preset data interval smaller, thereby avoiding or reducing the occurrence of large fluctuations in a preset data interval, reducing the adverse effects of fluctuations on table lookup accuracy, and thus improving the overall table lookup accuracy.

[0060] In some optional embodiments, the floating point arithmetic operator may be expressed as follows:

[0061] y float =f(x float ) Formula 2 The quantization operator corresponding to the operation operator can be determined as follows:

[0062] Based on the above quantization formula (Formula 1), the inverse quantization formula is as follows:

[0063] x float =(x int -z)*scale formula three

[0064] Substituting the inverse quantization formula (Formula 3) into the floating-point operator (Formula 2) yields:

[0065] (y int -z y )*scale=f((x int-z)*scale) Formula 4

[0066] By transforming Equation 4, the quantization operator can be obtained as follows:

[0067]

[0068] Taking the exponential operator as an example, the corresponding quantization operator can be expressed as follows:

[0069]

[0070] Based on the above process, the quantization operator corresponding to the operation operator can be obtained.

[0071] Step 203: Determine a target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval.

[0072] The index information corresponding to the target data interval is pre-determined table lookup information (also referred to as table entry). The index information may include a lookup rule for determining a corresponding quantized output value according to quantized input data.

[0073] In some optional embodiments, for each preset data interval, a table entry corresponding to the preset data interval may be determined in advance according to a specific operation condition of a quantization operator, for use in a table lookup operation of the preset data interval.

[0074] In some optional embodiments. For the lookup areas in multiple preset data intervals, the index information corresponding to each lookup area may include multiple preset index values ​​corresponding to the lookup area and the quantized output values ​​corresponding to each preset index value. For example, the multiple preset index values ​​corresponding to each lookup area include 64 preset index values ​​of 0, 1, 2, ..., 63, and the preset index values ​​have a certain mapping relationship with the quantized input data interval range of the lookup area, and the mapping relationship can be expressed as a mapping parameter. According to the mapping parameter, the quantized input value a corresponding to each preset index value i (i = 0, 1, 2, ..., 63) in the lookup area is determined. i , based on the quantized input value a i The quantization operator determines the quantized output value A corresponding to the preset index value i When a table lookup operation is required, the quantized input data a belonging to the table lookup area is converted based on the mapping parameters. j The data range mapped to the preset index value (the mapping result can be the preset index value or the index value falling between two adjacent preset index values) is used to obtain the quantized input data a through a table lookup operation. j The corresponding target quantized output value A j .

[0075] In some alternative embodiments, the index information corresponding to the look-up table area may further include mapping parameters of the data range from the quantized input values in the look-up table area to the preset index values. After determining the target data interval corresponding to the quantized input data, the quantized input data may be mapped to the index value range based on the mapping parameters, so as to look up the table through each preset index value to determine the target quantized output value corresponding to the quantized input data.

[0076] In some alternative embodiments, the mapping parameters corresponding to the look-up table area may also be stored independently of the index information. For example, each look-up table area and its corresponding mapping parameters are stored in a first storage space, and the index information corresponding to the look-up table area is stored in a second storage space.

[0077] In some alternative embodiments, if a linear region is included in multiple preset data intervals, the index information corresponding to each linear region may include fitting parameters of the linear region. The fitting parameters may include a fitting slope k, a fitting intercept b, quantization constants s1 and s2, and k, b, s1, and s2 are all integers. The target quantized output value y corresponding to the quantized input data is determined through the fitting parameters int , and can be expressed as follows:

[0078] y int = clamp((k * x+(b << s1)) >> s2) Equation VII

[0079] wherein, b << s1 represents shifting b to the left by s1 bits, and (k * x+(b << s1)) >> s2 represents shifting (k * x+(b << s1)) to the right by s2 bits.

[0080] Step 204, based on the target quantized output value, determine the quantization result after the input data is calculated by the arithmetic operator.

[0081] The quantization result after the input data is calculated by the arithmetic operator may include one or more quantized output values, which are specifically determined according to the number of input values included in the input data. For example, if the input data is a tensor and includes multiple elements (input values), then each input value corresponds to a quantized input value, and each quantized input value can obtain the corresponding target quantized output value through a look-up table operation. The target quantized output values respectively corresponding to the quantized input values constitute the quantization result after the input data is calculated by the arithmetic operator. If the input data only includes one input value, the target quantized output value may be determined as the quantization result after the input data is calculated by the arithmetic operator.

[0082] The quantization method of the neural network model provided in the present embodiment divides the quantization input data range into multiple preset data intervals, and each preset data interval can implement the table lookup operation through a smaller table entry, thereby reducing the storage pressure caused by the table entry. Moreover, since the multiple preset data intervals are determined based on the gradient size of the output value of the quantization operator corresponding to the operation operator as the input value changes, the gradient size of the output value of the quantization operator in any preset data interval as the input value changes can be made similar. Therefore, in the part where the output value of the quantization operator fluctuates greatly, the input data range covered by the divided preset data interval is smaller, so that the corresponding preset data interval is made to make table entries within the smaller input data range, which is helpful to improve the table lookup accuracy. In the part where the output value of the quantization operator fluctuates less, the input data range covered by the divided preset data interval is larger. Since the output value of the quantization operator in this part fluctuates less, the influence on the table lookup accuracy of the corresponding preset data interval is less, thereby improving the overall table lookup accuracy.

[0083] In some optional embodiments, in the above Figure 2 On the basis of the illustrated embodiment, the method of the embodiment of the present disclosure may further include: determining a plurality of preset data intervals within the range of the quantized input data based on the gradient of the output value of the quantization operator changing with the input value.

[0084] Figure 3 It is a schematic diagram of a process for determining multiple preset data intervals provided by an exemplary embodiment of the present disclosure.

[0085] In some optional embodiments, in the above Figure 2 Based on the illustrated embodiment, multiple preset data intervals can be obtained by the following steps:

[0086] Step 301: determine the quantization input data range of the quantization operator.

[0087] The quantization input data range is the data range corresponding to the quantization input data of the quantization operator. For example, the data range of the quantization input data of int8 is [0, 255], and the data range of the quantization input data of int16 is [-32768, 32767].

[0088] Step 302, according to the range of the quantized input data and the magnitude of the gradient of the quantization operator within the range of the quantized input data, determine the first linear region, the second linear region and multiple table lookup regions corresponding to the quantized input data, wherein the multiple table lookup regions are nonlinear regions.

[0089] The first linear region and the second linear region may be intervals at both ends of the quantized input data range, such as the first linear region [-32768, a1) and the second linear region (a7, 32767) mentioned above. The plurality of table lookup regions are intervals between the first linear region and the second linear region, such as the table lookup regions [a1, a2), [a6, a7), etc. mentioned above.

[0090] In some optional embodiments, the first linear region and the second linear region may be determined first according to the linear fitting conditions at both ends of the quantization operator. The middle nonlinear region may be determined based on the first linear region and the second linear region, and then multiple table lookup regions may be determined according to the gradient of the output value change of the quantization operator in the nonlinear region.

[0091] In some optional embodiments, the first linear region and the second linear region are determined by least squares fitting.

[0092] Step 303: Determine a plurality of preset data intervals based on the first linear region, the second linear region and each table lookup region.

[0093] The first linear region, the second linear region and each of the table lookup regions are taken as a preset data interval, and a plurality of preset data intervals within the range of the quantized input data are obtained.

[0094] In the disclosed embodiments, based on the magnitude of the gradient change of the quantization operator within the quantization input data range, the quantization input data range of the quantization operator is divided into a first linear region, a second linear region, and a plurality of table lookup regions, thereby effectively determining a plurality of preset data intervals. Since the table lookup region is determined based on the magnitude of the gradient change of the quantization operator within the quantization input data range, the fluctuation of the quantization operator within each table lookup region can be made smaller, thereby improving the overall table lookup accuracy.

[0095] Figure 4 It is a schematic diagram of a process for determining multiple preset data intervals provided by another exemplary embodiment of the present disclosure.

[0096] In some optional embodiments, such as Figure 4 As shown in the above Figure 3 Based on the illustrated embodiment, step 302 of determining the first linear region, the second linear region, and the plurality of table lookup regions corresponding to the quantized input data according to the quantized input data range and the change gradient size of the quantization operator within the quantized input data range may include the following steps:

[0097] Step 3021, determining a first linear region and a second linear region by least square fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range.

[0098] The operator output value is the real output value obtained by the quantization operator. int Calculate y int .

[0099] In some optional embodiments, the least squares fitting refers to finding a straight line with the minimum fitting error or the fitting error within a preset error range by combining linear fitting with the least squares method, that is, given some points of the quantization operator at one end of the quantization input data range (that is, the quantization input value and the corresponding operator output value), a straight line is determined so that the sum of the squares of the distances of all points to the straight line is minimized or less than a preset value, and the descriptive parameters of the straight line (that is, the slope and the intercept) are obtained, thereby obtaining the straight line equation, and quantizing the straight line equation into the fitting parameters k, b, s1 and s2 of the linear region. Exemplarily, taking the first linear region (the left linear region) as an example, each quantization input value x of the quantization operator to be fitted is i (i=1,2,…n, n represents the number of quantized input values ​​within the quantized input data range) The corresponding operator output value is represented as y i , and (x i ,y i ) is regarded as a point, starting from the left end of the quantized input data range, first add (x1, y1) and (x2, y2) to the left linear region, calculate a straight line with the minimum error by the least squares method, and record the corresponding fitting error. If the fitting error is within the preset error range, then continue to add (x3, y3) to the left linear region, calculate a straight line with the minimum error by the least squares method, and record the corresponding fitting error. If the fitting error is within the preset error range, then continue to add the next point to the left linear region, and so on, until the last point (x t ,y t ) causes the fitting error to exceed the preset error range, t is an integer greater than 2, and the last point added (x t ,y t ) is removed from the left linear region, and the previously added points (x1, y1) to (x t-1 ,y t-1 ) corresponds to the quantized input data interval [x1,x t-1 ] is determined as the left linear region, and the corresponding fitted straight line equation is quantified as the fitting parameters k, b, s1 and s2 of the left linear region. The principle of determining the right linear region is similar to that of the left linear region, except that the right linear region is added to the right linear region starting from the right end point, and the details are not repeated one by one.

[0100] Step 3022: Determine the absolute value of the second difference corresponding to each quantization input value in the nonlinear region according to the operator output value of the quantization operator at each quantization input value in the nonlinear region.

[0101] Among them, the quadratic difference absolute value corresponding to each quantization input value refers to the absolute value of the quadratic difference of the operator output value of the quantization operator at the quantization input value. Since the quantization input value in the nonlinear region is a discrete value, the operator output value of the quantization operator at each quantization input value in the nonlinear region is a discrete value. Therefore, the quadratic difference absolute value is used to represent the magnitude of the change gradient of the quantization operator. The quadratic difference absolute value is similar to the second-order derivative of a continuous function. The second-order derivative of a continuous function represents the rate of change of the slope of the continuous function at the corresponding point, and the quadratic difference represents the gradient of the change of the operator output value at the corresponding quantization input value. That is, the difference between two adjacent changes. Two adjacent changes refer to the difference between two adjacent operator output values ​​among three adjacent operator output values. For example, the quantization input value x i The corresponding operator output value is y i , then the quantized input value x i The corresponding absolute value of the second difference y i " can be expressed as follows:

[0102] y i ″=|(y i+1 -y i )-(y i -y i-1 )| Formula 8

[0103] Among them, || means taking the absolute value.

[0104] Step 3023, determining the interval boundary values ​​corresponding to the plurality of table lookup regions respectively according to the absolute values ​​of the second-order differences corresponding to the quantized input values ​​in the nonlinear region respectively.

[0105] Among them, the absolute value of the quadratic difference corresponding to each quantized input value can characterize the change gradient of the quantized operator at each quantized input value, and the interval boundary values ​​corresponding to the multiple lookup areas can be determined according to the principle of minimizing the change gradient of each lookup area. That is, the sum of the absolute values ​​of the quadratic difference in each lookup area in the multiple lookup areas divided by the nonlinear area is less than the gradient threshold. The gradient threshold can be set according to the specific change of the quantized operator, or it can be determined by a certain search algorithm.

[0106] Step 3024, obtaining multiple table lookup areas according to the interval boundary values ​​corresponding to each table lookup area.

[0107] Among them, the interval boundary value of the lookup area represents the boundary of the quantized input value of the lookup area. Therefore, after determining the interval boundary value corresponding to each lookup area, the corresponding lookup area can be obtained according to the interval boundary value. For example, the interval boundary value of the lookup area includes the left boundary value a1 and the right boundary value a2, and the corresponding lookup area can be determined to be [a1, a2]. Whether the lookup area includes the interval boundary values ​​on both sides can be set according to actual needs. For example, the lookup area can also be expressed as (a1, a2].

[0108] In the disclosed embodiments, the absolute value of the quadratic difference of the quantization operator at each quantization input value can effectively represent the magnitude of the change gradient of the quantization operator, thereby providing an accurate and effective reference gradient for the segmentation of the lookup area, so that the change gradients of multiple lookup areas obtained are relatively close, avoiding large fluctuations in the same lookup area, thereby improving the lookup accuracy of the part where the quantization operator fluctuates more, and further improving the overall lookup accuracy.

[0109] In some optional embodiments, step 3023 determines the interval boundary values ​​corresponding to the plurality of table lookup regions respectively according to the absolute values ​​of the second differences respectively corresponding to the quantized input values ​​in the nonlinear region, including:

[0110] Determine the range of thresholds to be searched; determine the target threshold within the range of thresholds to be searched based on the binary search method, so that the sum of the absolute values ​​of the quadratic differences corresponding to the quantized input values ​​in each of the multiple intervals divided by the nonlinear area is less than or equal to the target threshold; and use the boundary values ​​of the intervals divided by the nonlinear area as the interval boundary values ​​of each lookup table area.

[0111] The threshold range to be searched refers to the range of the gradient threshold. To solve the problem of how to make the gradient of the quantization operator in each lookup area close to each other, that is, how to make the sum of the absolute values ​​of the quadratic differences in each lookup area as close as possible, a threshold range to be searched can be determined. The upper limit value s in the threshold range to be searched is max Large enough so that no matter how the nonlinear region is divided, the sum of the absolute values ​​of the quadratic differences in each lookup region (each of the multiple divided intervals) is less than s max The lower limit value s in the threshold range to be searched min Small enough that no matter how the nonlinear region is divided, the sum of the absolute values ​​of the quadratic differences in each lookup table region cannot be less than s min .s min and max All are integers. By searching in the threshold range to be searched [s min ,s max ] to find a minimum integer threshold s k , so that the sum of the absolute values ​​of the quadratic differences of each lookup table area divided in the nonlinear region is less than s k Obviously, the search for the threshold is monotonic, that is, if the threshold is large enough, the above gradient condition can be satisfied (that is, the sum of the absolute values ​​of the quadratic differences of each lookup area in the nonlinear region is less than the gradient threshold). If the threshold is small enough, the gradient condition cannot be satisfied. Based on this, the smallest s that satisfies the gradient condition is searched. k The end condition is: greater than s k The threshold value s k+1It can make the segmentation of the nonlinear region meet the above gradient conditions, and be less than s k The threshold value s k-1 The boundary values ​​of each interval of the nonlinear region segmentation that can satisfy the above gradient condition are determined as the interval boundary values ​​of each table lookup region. k is the target threshold.

[0112] In some optional embodiments, for any interval among the multiple intervals, the sum y″ of the absolute values ​​of the quadratic differences corresponding to the quantized input values ​​in the interval is alt It can be expressed as follows:

[0113]

[0114] Among them, m represents the number of quantized input values ​​in the interval, y i ″ represents the absolute value of the second difference corresponding to the i-th quantized input value in the interval.

[0115] In some optional embodiments, the binary search method is a search algorithm for finding a specific element (i.e., a target threshold that can meet the gradient condition) in an ordered array (i.e., an array composed of candidate thresholds within the threshold range to be searched). The search process starts from the middle element of the array. If the middle element happens to be the specific element to be found, the search process ends. If the specific element is larger than the middle element, the search continues in the half of the array that is larger than the middle element, and it still starts from the middle element of the half. Similarly, if the specific element is smaller than the middle element, the search continues in the half of the array that is smaller than the middle element. And so on, until the specific element is found or the array is empty (indicating that the specific element cannot be found), the search ends. This search algorithm reduces the search range by half each time, effectively improving the search efficiency.

[0116] In some optional embodiments, first in [s min ,s max ] determines the middle element as the currently searched threshold s i (called the current threshold), the nonlinear area can be divided into a variety of ways based on the current threshold, each way divides the nonlinear area into a preset number of lookup areas, the preset number can be any value, for example, the preset number can be 2, 3, 4, 5, 6, etc. The interval boundary value of at least one lookup area in the preset number of lookup areas of different division methods is different. For each division method, the sum of the absolute values ​​of the secondary differences of each lookup area is calculated, and according to the relationship between the sum of the absolute values ​​of the secondary differences of each lookup area and the current threshold, it is determined whether the division method meets the gradient condition (that is, the sum of the absolute values ​​of the secondary differences of each lookup area is less than the current threshold). If there is at least one division method that meets the gradient condition, the minimum target threshold s can be determined.k If it is less than or equal to the current threshold, then continue to increase from the threshold range [s min ,s i ] to search for the next threshold, that is, [s min ,s i ] is used as the current threshold. If no segmentation method that satisfies the gradient condition is found, it can be determined that the target threshold should be greater than the current threshold. Then, the target threshold is selected from the range greater than half of the current threshold [s i ,s max ] to determine the middle element s i+1 As the current threshold. Continue to follow the above process to determine whether there is a segmentation method that meets the gradient condition. When the target threshold is [s min ,s i ] range, if the current threshold s i+1 There is a segmentation method that satisfies the gradient condition, which can determine that the target threshold should be less than or equal to s i+1 , then continue in [s min ,s i+1 ] to determine the next threshold as the current threshold, otherwise continue in [s i+1 ,s i ] determines the next threshold as the current threshold, and so on, until the minimum target threshold s that satisfies the gradient condition is found k And the segmentation method that satisfies the gradient condition is used to obtain the interval boundary value of each lookup area.

[0117] In some optional embodiments, boundary value adjustment rules for multiple table lookup areas of nonlinear area segmentation can be set, and different segmentation methods are determined by adjusting the boundary values ​​of the table lookup areas. For example, the interval boundary values ​​of the table lookup areas of the initial segmentation method can be set, and after calculating the sum of the absolute values ​​of the secondary differences of each table lookup area, the interval boundary values ​​of the table lookup areas in the initial segmentation method are adjusted according to the boundary value adjustment rules to obtain a second segmentation method. After calculating the sum of the absolute values ​​of the secondary differences of each table lookup area, the steps of adjusting the interval boundary values ​​of the table lookup areas in the initial segmentation method according to the boundary value adjustment rules and calculating the sum of the absolute values ​​of the secondary differences of each table lookup area are repeatedly performed until a segmentation method that can meet the gradient condition is found, or the boundary value adjustment reaches the end condition. The boundary value adjustment rules can include the number of table lookup areas adjusted each time and the adjustment step size. It can be understood that the number of table lookup areas is at least two, because adjacent table lookup areas have the same boundary value at the critical point, so adjusting the boundary value of one table lookup area will inevitably lead to a change in the boundary value of another table lookup area that shares the boundary value. The adjustment step size can be set according to actual needs, for example, the adjustment step size can be 1, 2, 3, etc.

[0118] In the disclosed embodiment, the binary search method can accurately find the minimum target threshold value that can make the sum of the absolute values ​​of the quadratic differences in each segmented interval meet the gradient condition, so that the gradient of the operator output value change of the quantization operator in each segmented table lookup area is relatively close, avoiding large fluctuations of the quantization operator in a table lookup area, reducing the adverse effects of fluctuations on the table lookup accuracy, and thus greatly improving the table lookup accuracy. And by searching the target threshold value by the binary search method, the search efficiency can be improved.

[0119] Figure 5 It is a schematic diagram of a process of determining multiple preset data intervals provided by yet another exemplary embodiment of the present disclosure.

[0120] In some optional embodiments, such as Figure 5 As shown in the above Figure 3 Based on the illustrated embodiment, step 302 of determining the first linear region, the second linear region, and the plurality of table lookup regions corresponding to the quantized input data according to the quantized input data range and the change gradient size of the quantization operator within the quantized input data range may include:

[0121] Step 302a, determining a first linear region and a second linear region by least square fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range.

[0122] For the specific operation of step 302a, please refer to step 3021.

[0123] Step 302b: in response to the quantization operator being a preset quantization operator, dividing the nonlinear region into a plurality of sub-ranges.

[0124] Among them, the preset quantization operator can be a preset more complex operator, for example, the preset quantization operator can be a composite operator, and the composite operator refers to an operator composed of at least two operators. For example, a composite operator composed of a sine operator and an exponential operator. That is, the quantization input value in a sub-range of the quantization input data range is the input value of the sine quantization operator, and the quantization input value in another sub-range of the quantization input data range is the input value of the exponential quantization operator. If the required table lookup accuracy cannot be achieved by the above-mentioned preset number of table lookup areas, the nonlinear area can be divided into multiple sub-ranges. A fine-grained division of the nonlinear area is achieved to further improve the table lookup accuracy.

[0125] In some optional embodiments, a sub-range segmentation rule may be set, and the nonlinear region may be segmented into a plurality of sub-ranges based on the sub-range segmentation rule. The sub-range segmentation rule may include at least one of the number of sub-ranges and the number of quantized input values ​​of the sub-ranges. For example, the nonlinear region may be evenly segmented into a plurality of sub-ranges according to the number of sub-ranges. Alternatively, the nonlinear region may be segmented into a plurality of sub-ranges according to the number of quantized input values ​​of the sub-ranges.

[0126] For example, the nonlinear region can be divided from the middle quantized input value to obtain two sub-ranges. For example, the nonlinear region of [a1, a7] is divided into two sub-ranges of [a1, a4] and [a4, a7]. Of course, in practical applications, it can also be divided into more sub-ranges.

[0127] Step 302c, for any sub-range among the multiple sub-ranges, based on the change gradient of the quantization operator within the sub-range, determine multiple lookup areas corresponding to the sub-range; based on the lookup areas corresponding to each sub-range, obtain multiple lookup areas in the nonlinear region.

[0128] Among them, for any sub-range, the specific principle of determining the multiple lookup areas corresponding to the sub-range can refer to the aforementioned steps 3022 to 3024, that is, taking each sub-range as a non-linear area mentioned above, executing steps 3022 to 3024 to obtain multiple lookup areas corresponding to each sub-range, and the lookup areas corresponding to the multiple sub-ranges constitute multiple lookup areas of the non-linear area.

[0129] The disclosed embodiment of the present invention divides the nonlinear region into a plurality of sub-ranges to achieve further granularization of the nonlinear region, and then determines a plurality of table lookup areas for each sub-range, which is equivalent to determining two groups of table lookup areas for the nonlinear region. Increasing the number of table lookup areas helps to further improve the table lookup accuracy. For example, the table lookup operation of the [a1, a7] range was originally implemented through 6 table lookup areas, and this embodiment can be expanded to 12 table lookup areas. The average number of input quantization values ​​covered by each table lookup area is reduced, but the size of the table entry corresponding to each table lookup area can remain unchanged, that is, the number of preset index values ​​and the corresponding number of quantization output values ​​remain unchanged, which is equivalent to reducing the number of quantization input values ​​that need to be interpolated to obtain quantization output values, and interpolation is the main factor that causes the reduction of table lookup accuracy. Therefore, reducing the number of quantization input values ​​that need to be interpolated can effectively improve the table lookup accuracy.

[0130] Figure 6 It is a flowchart of a quantization method of a neural network model provided by another exemplary embodiment of the present disclosure.

[0131] In some optional embodiments, the index information corresponding to each table lookup area in the plurality of preset data intervals may include quantized output values ​​corresponding to the plurality of preset index values.

[0132] Among them, the multiple preset index values ​​corresponding to each lookup area are the lookup index values ​​used for table lookup, and the preset index values ​​of different lookup areas can be the same or different. For example, the multiple preset index values ​​of each lookup area can be 64 preset index values ​​from 0 to 63. Or, the multiple preset index values ​​of a lookup area can be 64 preset index values ​​from 0 to 63. The multiple preset index values ​​of another lookup area can be 64 preset index values ​​from 64 to 127. There is no specific limitation.

[0133] In some optional embodiments, the sum of the number of preset index values ​​corresponding to each lookup table area is less than or equal to the number of quantized input values ​​included in the nonlinear area. For example, for quantized input data of int16 or higher bit width, each lookup table area corresponds to 64 preset index values, there are 6 lookup table areas, and there are 64*6=384 preset index values ​​in total, that is, the table size of the nonlinear area is the quantized output value corresponding to 384 preset index values, and the quantized input data range of int16 includes 65536 quantized input values. If the quantized output value corresponding to each quantized input value is stored, the storage pressure is too large. By setting a smaller preset index value for each lookup table area, the table item storage capacity is reduced from 65536 to 384. It can be seen that the storage pressure of the table item can be effectively alleviated. Of course, in actual applications, the number of preset index values ​​corresponding to each lookup table area is not limited to 64, and can be set to any value according to actual storage requirements. The principle is that the storage pressure of the table item can be reduced relative to the overall number of quantized input values.

[0134] In some optional embodiments, such as Figure 6 As shown in the above Figure 2 Based on the illustrated embodiment, determining the target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval in step 203 may include:

[0135] Step 2031: In response to the target data interval being a table lookup area, a mapping parameter corresponding to the target data interval is obtained.

[0136] The mapping parameter is used to map the quantized input data from the quantized input data range to the preset index data range corresponding to the target data interval; the preset index data range is the data range of the table lookup index value corresponding to the target data interval. The table lookup index value is the preset index value mentioned above.

[0137] In some optional embodiments, the mapping parameters may be mapping parameters of linear mapping, and similar to the aforementioned fitting parameters, the mapping parameters may be expressed as k1, b1, s3, and s4, and the mapping parameters of each lookup area are used to map the quantized input values ​​in the lookup area to the preset index data range corresponding to the lookup area. For example, the quantized input values ​​belonging to the lookup area in the quantized input data range of int16 are mapped to the preset index data range of [0,63].

[0138] In some optional embodiments, mapping parameters of different table lookup areas may be different, and the mapping parameters are specifically determined according to the association relationship between the quantized input value of the table lookup area and the preset index data range.

[0139] Step 2032: Determine a target index value of the quantized input data within a preset index data range based on the mapping parameters.

[0140] Among them, the target index value can be a preset index value or a value between two adjacent preset index values. Since the total number of quantized input values ​​in the nonlinear area is inconsistent with the total number of preset index values, the quantized input value mapped to the preset index data range may not be an integer, that is, it is not a preset index value.

[0141] Exemplarily, the mapping parameters are represented as k1, b1, s3 and s4, and the target index value index can be represented as follows:

[0142]

[0143] Among them, x i Represents quantized input data (or quantized input values ​​in quantized input data).

[0144] Step 2033: Determine a target quantized output value corresponding to the quantized input data based on the target index value and the quantized output values ​​corresponding to the plurality of preset index values ​​in the index information.

[0145] The index information is predetermined and stored, that is, the quantized output value corresponding to the preset index value is predetermined and stored. The index information includes quantized output values ​​corresponding to multiple preset index values, so the quantized output values ​​corresponding to multiple preset index values ​​can be obtained from the index information. Based on the target index value and the quantized output values ​​corresponding to the multiple preset index values, the target quantized output value corresponding to the quantized input data is determined.

[0146] In the disclosed embodiments, by setting mapping parameters corresponding to preset data intervals, quantized input data in preset data intervals can be mapped to preset index data ranges, so as to facilitate table lookup operations on a large amount of quantized input data through table entries of a small number of preset index values, thereby effectively reducing the storage pressure of table entries in table lookup operations.

[0147] In some optional embodiments, determining the target quantized output value corresponding to the quantized input data based on the target index value and the quantized output values ​​respectively corresponding to the plurality of preset index values ​​in the index information in step 2033 may include:

[0148] In response to the target index value belonging to the target preset index value among the multiple preset index values, the quantization output value corresponding to the target preset index value is used as the target quantization output value. In response to the target index value not belonging to the multiple preset index values, the first preset index value and the second preset index value adjacent to the target index value among the multiple preset index values ​​are determined; based on the target index value, the first preset index value, the second preset index value, the first quantization output value corresponding to the first preset index value, and the second quantization output value corresponding to the second preset index value, the quantization output value corresponding to the target index value is determined as the target quantization output value.

[0149] Among them, if the target index value is exactly a preset index value, the quantization output value corresponding to the preset index value can be directly looked up in the table as the target quantization output value. If the target index value does not belong to any preset index value, it means that the target index value falls between two adjacent preset index values. Since the index information (i.e., the table item) only includes the quantization output values ​​corresponding to each preset index value, it is necessary to determine the quantization output value corresponding to the target index value based on interpolation as the target quantization output value. The interpolation process is to determine the first preset index value and the second preset index value adjacent to the target index value from multiple preset index values ​​based on the target index value, that is, the target index value falls between the first preset index value and the second preset index value. According to the position of the target index value between the first preset index value and the second preset index value, the first quantization output value corresponding to the first preset index value and the second quantization output value corresponding to the second preset index value can be interpolated, and the quantization output value corresponding to the target index value is obtained by quantization as the target quantization output value.

[0150] Exemplarily, the multiple preset index values ​​corresponding to the lookup table area are 0 to 63, and the target index value is a real number between [0, 63] (including the integer part and the decimal part). The integer part is extracted from the target index value to obtain the first preset index value (for example, i). The first preset index value plus 1 can obtain the second preset index value i+1. For example, if the target index value is 21.67, it can be determined that the first preset index value is 21, the second preset index value is 22, and the first quantized output value corresponding to the first preset index value is expressed as A 21 The second quantized output value corresponding to the second preset index value is represented by A 22 , then interpolate and quantize according to the position of 21.67 between 21 and 22 (equivalent to the position of 0.67 between 0 and 1), and obtain the quantized output value y corresponding to the target index value, which can be expressed as follows:

[0151] y=clamp(round((1-0.67)*A 21 +0.67*A 22 )) Formula 11 Among them, clamp() and round() can refer to the aforementioned embodiment.

[0152] In this embodiment, for the target index value that does not fall on the preset index value, the quantized output value corresponding to the target index value is obtained by interpolation, so that a large amount of quantized input data can be looked up in the table through fewer table entries. On the basis of improving the computing efficiency, the storage pressure of the table entries is reduced, which facilitates the deployment of the neural network model on the terminal side.

[0153] Figure 7 It is a flowchart of a quantization method of a neural network model provided by yet another exemplary embodiment of the present disclosure.

[0154] In some optional embodiments, the index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values ​​respectively; Figure 7 As shown in the above Figure 2 Based on the illustrated embodiment, the method of the embodiment of the present disclosure may further include:

[0155] Step 401: for any table lookup area in a plurality of preset data intervals, determine index information corresponding to the table lookup area.

[0156] The process of determining the index information corresponding to the table lookup area is the process of determining the quantized output values ​​corresponding to the plurality of preset index values ​​corresponding to the table lookup area.

[0157] In some optional embodiments, the operator output value of the quantization operator at the quantization input value corresponding to each preset index value can be used as the quantization output value corresponding to each preset index value. That is, for each preset index value, according to the mapping relationship between the quantization input data and the preset index value, the quantization input value corresponding to each preset index value is determined, the quantization input value is substituted into the quantization operator, the operator output value is calculated, and the operator output value is used as the quantization output value corresponding to the preset index value. The preset index values ​​corresponding to the table lookup area and the quantization output values ​​corresponding to the preset index values ​​are determined as the index information corresponding to the table lookup area, and the index information can be stored for subsequent table lookup operations. Based on this, the index information corresponding to each table lookup area can be determined.

[0158] Figure 8 FIG. 1 is a schematic diagram of a process for determining the table lookup area index information provided by an exemplary embodiment of the present disclosure. Figure 8As shown, for any table lookup area in a plurality of preset data intervals, determining the index information corresponding to the table lookup area in step 401 may include the following steps:

[0159] Step 4011, based on the mapping parameters corresponding to the table lookup area, determine the quantized input values ​​corresponding to the preset index values.

[0160] The process of determining the quantized input values ​​corresponding to the preset index values ​​is the reverse mapping process of the above formula 10. The details are not described in detail.

[0161] Step 4012, based on the quantization input values ​​corresponding to the preset index values, the operator output values ​​of the quantization operator at the preset index values ​​corresponding to the table lookup area are calculated.

[0162] The operator output values ​​corresponding to the preset index values ​​are calculated by taking the quantization input values ​​corresponding to the preset index values ​​as the inputs of the quantization operators.

[0163] Step 4013: for any preset index value, determine a plurality of candidate output values ​​within a preset range of the operator output value corresponding to the preset index value.

[0164] The preset range of the operator output value corresponding to the preset index value can be set to any range containing the operator output value according to actual needs. For example, the operator output value corresponding to the preset index value is y, and the preset range of the operator output value can be expressed as [ym, y+n], where m and n are both integers greater than or equal to 0. m and n can be equal or unequal, for example, m=n=5000.

[0165] For each preset index value, the candidate output value corresponding to the preset index value represents a value that may be used as the quantized output value corresponding to the preset index value within a preset range of the operator output value corresponding to the preset index value.

[0166] In some optional embodiments, the preset range can be expressed as ±D, where D is a positive integer. Taking D=5000 as an example, multiple preset index values ​​are 0, 1, ..., M from small to large, and each preset index value is taken as the current preset index value in turn. The current preset index value is represented as i (i=0, 1, ..., M), then the jth candidate output value A corresponding to i is i j It can be expressed as:

[0167] A i j =base i +jD Type 12

[0168] Where j = 0, 1, ..., 2D, base iIndicates that the current preset index value i corresponds to the operator output value, then the number of candidate output values ​​corresponding to the current preset index value i is 2D.

[0169] Step 4014: Determine the fitting error term corresponding to each preset index value based on the candidate output value corresponding to each preset index value.

[0170] The fitting error term corresponding to any preset index value includes the fitting error corresponding to each candidate output value of the preset index value.

[0171] In some optional embodiments, each preset index value may be used as the current preset index value in sequence according to a preset order to determine the fitting error term corresponding to the current preset index value. The preset order may be an order from small to large or from large to small for each preset index value, and is not specifically limited.

[0172] In some optional embodiments, the fitting error term corresponding to the current preset index value includes the fitting error of each candidate output value corresponding to the current preset index value. Each candidate output value is taken as the target candidate output value, and the fitting error corresponding to the target candidate output value includes the error of the fitting line segment relative to the quantization operator of the target candidate output value and each candidate output value of the previous preset index value (which can be called the historical candidate output value) and the cumulative error of the fitting error corresponding to the historical candidate output value. The error of the fitting line segment relative to the quantization operator of the target candidate output value and each historical candidate output value can be determined by mapping the fitting value of each target quantization input value between the current preset index value and the previous preset index value on the fitting line segment and the operator output value on the quantization operator. The fitting error of the historical candidate output value is calculated when the previous preset index value is taken as the current preset index value. For example, the candidate output value of the current preset index value i is A i j , A i-1 k The fitting error is expressed as dp i-1,k , A i j The fitting error is A i j and A i-1 k The error and difference dp between the fitting segments relative to the quantization operator i-1,k The cumulative error.

[0173] That is to say, the fitting error term can be represented as a tensor with a certain data structure, such as an array, a matrix, etc., and each element in the tensor represents the cumulative error from a candidate output value of the previous preset index value to a candidate output value of the current preset index value.

[0174] Step 4015: Determine the index information corresponding to the table lookup area based on the fitting error terms corresponding to the preset index values.

[0175] After obtaining the fitting error terms corresponding to the preset index values, the fitting error terms corresponding to the preset index values ​​can be combined to determine the index information that meets the error condition. The error condition can be a condition that minimizes the total fitting error.

[0176] In some optional embodiments, steps 4011 to 4015 may be based on dynamic path planning to determine the index information corresponding to the table lookup area, that is, to find a plurality of fitting line segments (paths) with the minimum cumulative error (cost) from the minimum preset index value to the maximum preset index value (or from the maximum preset index value to the minimum preset index value). The fitting error term records the cost value of various possible choices in the path search process, and the optimal path is found by minimizing the overall path cost value. Based on the optimal path, starting from the last preset index value, the corresponding quantized output value is determined, and the quantized output value of each preset index value is obtained in sequence by reverse calculation according to the optimal path.

[0177] The quantized output values ​​corresponding to the preset index values ​​are formed into table entries according to a certain data structure as index information corresponding to the table lookup area.

[0178] Based on the above process, the index information corresponding to each table lookup area can be obtained. The index information corresponding to each table lookup area is stored correspondingly for subsequent table lookup operations, such as deployment to terminal devices, to facilitate the inference acceleration of the neural network model.

[0179] In some optional embodiments, Fig. 9 FIG. 1 is a schematic diagram comparing two methods of determining a quantized output value provided by an exemplary embodiment of the present disclosure. Fig. 9 As shown, the portion of the quantization operator curve S between two preset index values ​​i and i+1 is a concave curve (similar to the convex curve). At the two preset index values, the quantization output value determination method 1 (referred to as method 1) is to use the operator output value of the quantization operator as the quantization output value A corresponding to the preset index value. i and A i+1 Quantized output value determination method 2 (hereinafter referred to as method 2) is a quantized output value A′ obtained by minimizing the overall fitting error within a certain range of the corresponding operator output value in this embodiment. i and A′ i+1 It can be seen that for concave curve segments, when the quantized output value of the concave part is determined by table interpolation, the quantized output value obtained by the second method of minimizing the fitting error can reduce the error between the table interpolation result of the concave part and the actual operator output value, as shown in the figure. j At this point, the quantized output value obtained by interpolation in mode 1 is expressed as Aj , the operator output value is represented by y j , the quantized output value obtained by interpolation in method 2 is A′ j Obviously, |A′ j -y j |<|A j -y j |, and there is only a small error at the preset index values ​​at both ends, and there is also a part between the two preset index values ​​where the interpolated quantized output value is the same as the operator output value. It can be seen that method 2 can improve the overall table lookup accuracy.

[0180] In the disclosed embodiment, the index information of the table lookup area is determined by the fitting error terms corresponding to each preset index value, so as to balance the overall table lookup accuracy of the quantization operator and solve the problem that using the operator output value as the quantization output value corresponding to the preset index value easily leads to too low table lookup accuracy in the concave curve segment or convex curve segment of the quantization operator.

[0181] Fig.10 It is a schematic diagram of a process for determining table lookup area index information provided by another exemplary embodiment of the present disclosure.

[0182] In some optional embodiments, such as Fig.10 As shown, step 4014 of determining the fitting error term corresponding to each preset index value based on the candidate output value corresponding to each preset index value may include:

[0183] Step 40141, taking each of the preset index values ​​as the current preset index value in turn according to the preset order, and determining the fitting line segment between each historical candidate output value and each current candidate output value based on each historical candidate output value corresponding to the previous preset index value of the current preset index value and each current candidate output value corresponding to the current preset index value.

[0184] Among them, the preset order can be the order of the preset index values ​​from small to large or from large to small. The previous preset index value of the current preset index value is the preset index value adjacent to the current preset index value. It can be determined specifically according to the preset order of traversing the preset index values. For example, if the multiple preset index values ​​are in the order of small to large, the previous preset index value of the current preset index value is a preset index value adjacent to the current preset index value and smaller than the current preset index value. If the current preset index value is represented as i, the previous preset index value is i-1. If the multiple preset index values ​​are in the order of large to small, the previous preset index value of the current index value is a preset index value adjacent to the current preset index value and larger than the current preset index value. If the current preset index value is represented as i, the previous preset index value is i+1.

[0185] Each candidate output value corresponding to the previous preset index value is called a historical candidate output value, and each candidate output value corresponding to the current preset index value is called a current candidate output value. Taking the order from small to large as an example, determine each current candidate output value A i j (j=0, 1, ..., 2D) and each historical candidate output value A i-1 k For the fitting line segment of (k=0, 1, ..., 2D), each historical candidate output value is determined with the previous preset index value as the current preset index value.

[0186] In some optional embodiments, when the current preset index value is the first preset index value among multiple preset index values ​​(e.g., the smallest preset index value in the ascending order or the largest preset index value in the descending order), the fitting error term corresponding to the current preset index value may include the error between each candidate output value of the current preset index value and the operator output value of the current preset index value. That is, since there is no previous preset index value, the error is only generated by the difference between the candidate output value and the operator output value.

[0187] In some optional embodiments, for each current candidate output value corresponding to the current preset index value, each historical candidate output value corresponding to the previous preset index value may be linearly fitted with the current candidate output value to obtain a fitting line segment between the current candidate output value and the historical candidate output value. i-1 k ) and point (i,A i j ) is fitted into a line segment as the current candidate output value A i j With A i-1 k Based on this, we can get each current candidate output value A i j With each historical candidate output value A i-1 k The fitting line segment can be expressed as l i k→j .

[0188] Step 40142, based on the previous error term corresponding to the previous preset index value determined previously, the fitting line segment between each historical candidate output value and each current candidate output value, and the quantization operator, determine the fitting error term corresponding to the current preset index value.

[0189] Among them, the previous error term corresponding to the previous preset index value is the fitting error term corresponding to the previous preset index value. The previous determination refers to the determination in the process of using the previous preset index value as the current preset index value, that is, when traversing to the previous preset index value in the preset order, the fitting error term corresponding to the previous preset index value is determined according to the process from step 40141 to step 40142 as the previous error term of the current preset index value. The previous error term corresponding to the previous preset index value includes the fitting error corresponding to each historical candidate output value of the previous preset index value, which is similar to the fitting error term of the current preset index value and is not elaborated here. The error of the fitting segment relative to the quantization operator can be determined based on the fitting segment and the quantization operator between each historical candidate output value and each current candidate output value, and then the fitting error term corresponding to the current preset index value is determined in combination with the previous error term.

[0190] For example, the previous error term can be expressed as dp i-1,k , the fitting error term corresponding to the current preset index value can be expressed as dp i,j .dp i,j Yes A i j With A i-1 k The error of the fitting line segment relative to the quantization operator is related to dp i-1,k The cumulative error.

[0191] The error between the fitting line segment of each current candidate output value and each historical candidate output value and the quantization operator can be determined by mapping the fitting values ​​of each quantization input value between the previous preset index value and the current preset index value on the fitting line segment and the error between the operator output value on the quantization operator. That is, the error between the fitting line segment and the quantization operator is the sum of the errors between the fitting values ​​corresponding to each quantization input value and the operator output value. The error between the fitting value of the quantization input value and the operator output value can be expressed as the absolute value of the difference between the fitting value and the corresponding operator output value or the square of the difference. The specific error representation method is not limited.

[0192] This embodiment can accurately obtain the cumulative cost values ​​of various possible fitting paths from the starting preset index value to the current preset index value through the previous error term and the error of the fitting line segment relative to the quantization operator of each current candidate output value of the current preset index value and each historical candidate output value of the previous preset index value. Therefore, after recursively obtaining the fitting error term corresponding to the end preset index value, the candidate output value that minimizes the fitting error can be effectively obtained as the quantized output value of the end preset index value, thereby minimizing the overall fitting error and improving the overall table lookup accuracy.

[0193] In some optional embodiments, step 40142, based on the previous error term corresponding to the previous preset index value determined previously, the fitting line segment between each historical candidate output value and each current candidate output value, and the quantization operator, determines the fitting error term corresponding to the current preset index value, and may include:

[0194] Based on the quantization operator, calculate the operator output values ​​corresponding to each target quantization input value mapped between the current preset index value and the previous preset index value; for each fitting line segment between the historical candidate output value and each current candidate output value, determine the fitting value of each target quantization input value on the fitting line segment based on the fitting line segment; determine the fitting error term corresponding to the current preset index value based on the previous error term, the operator output value corresponding to each target quantization input value, and the fitting value of each target quantization input value on each fitting line segment.

[0195] Among them, each target quantization input value mapped to between the current preset index value and the previous preset index value can be determined based on the mapping formula of the above formula 10. For example, the first quantization input value corresponding to the previous preset index value and the second quantization input value corresponding to the current preset index value can be determined. The first quantization input value and the second quantization input value can represent the boundary value of the quantization input value that can be mapped to between the current preset index value and the previous preset index value. Each quantization input value within the range of the first quantization input value to the second quantization input value is the target quantization input value mapped to between the preset index value and the previous preset index value. The operator output value corresponding to each target quantization input value is obtained by quantization operator calculation. For each current candidate output value and each historical candidate output value fitting line segment, the fitting value of each target quantization input value on the fitting line segment is determined based on the fitting line segment. Then, the error sum of all fitting values ​​between the current candidate output value and the historical candidate output value can be calculated based on the error between the operator output value and the fitting value, and the total fitting error corresponding to each candidate output value is obtained by combining the fitting error corresponding to the historical candidate output value in the previous error term.

[0196] The process of determining the quantized output value corresponding to each preset index value is the process of determining the fitting path that minimizes the overall fitting error. The recursive process of the fitting error term can be expressed as:

[0197]

[0198] Among them, f(x) represents the operator output value of the target quantized input value x on the quantized operator, g(x) represents the fitting value of x on the fitting line segment, Indicates the solution to make dp i,j The smallest k. k=0, 1, ..., 2D. j=0, 1, ..., 2D, i=0, 1, ..., M-1, M is the number of preset index values. dpi-1,k Represents the previous error term. For each j of the current preset index value i, traverse k = 0, 1, ..., 2D, and determine the dp under each historical candidate output value i,j And store, you can find the dp i,j The smallest k, based on which the fitting error corresponding to each candidate output value of the current preset index value i can be obtained. By traversing i=0, 1, ..., M-1 through formula 13, the fitting error term corresponding to the preset index value M-1 is finally obtained. The fitting error term corresponding to the preset index value M-1 is equivalent to the cumulative error of all fitting paths from the preset index value 0 to M-1. Based on dp M-1,j Find the j with the smallest error and the optimal fitting path corresponding to the j with the smallest error. Based on the j with the smallest error, the quantized output value corresponding to M-1 can be obtained. The quantized output value corresponding to each preset index value is obtained by reverse searching through the optimal fitting path.

[0199] This embodiment achieves accurate calculation of the error of the fitting segment by mapping the fitting value and operator output value of each target quantized input value between the current preset index value and the previous preset index value, and effectively obtains the cumulative error of the fitting path in combination with the previous error term, thereby achieving effective determination of the quantized output value of each preset index value through dynamic path planning, minimizing the overall fitting error of the quantized output value of each preset index value, and effectively improving the table lookup accuracy.

[0200] In some optional embodiments, such as Fig.10 As shown, step 4015 of determining the index information corresponding to the table lookup area based on the fitting error terms corresponding to the preset index values ​​may include:

[0201] Step 40151, in reverse order of the preset order, take each preset index value as the target preset index value in turn, based on the correlation between the fitting error term corresponding to the target preset index value and the fitting error term corresponding to the previous preset index value of the target preset index value, and the quantized output value corresponding to the previous preset index value determined previously, determine the quantized output value corresponding to the target preset index value from the candidate output values ​​corresponding to the target preset index value.

[0202] Among them, since it is in the reverse order of the preset order of determining the fitting error term, if the preset order is from small to large, the reverse order is from large to small, that is, firstly, the preset index value of the fitting error term determined last (for example, the maximum preset index value M-1) is used as the target preset index value, and the fitting error term dp based on the target preset index value is M-1,j, find the j with the smallest error and the optimal fitting path (i.e. the optimal selection path) corresponding to the j with the smallest error. Based on the j with the smallest error, the quantized output value corresponding to M-1 can be obtained. The quantized output value corresponding to each preset index value is obtained by reverse searching through the optimal fitting path.

[0203] Step 40152, based on the quantized output values ​​corresponding to the preset index values, determine the index information corresponding to the table lookup area.

[0204] This embodiment recursively obtains the optimal selection path for the quantized output values ​​from the starting preset index value to the ending preset index value in a preset order, and then obtains the optimal candidate output value corresponding to each preset index value on the optimal selection path by reverse deduction, so that the sum of the fitting errors of the quantized output values ​​of all preset index values ​​is minimized, thereby maximizing the overall table lookup accuracy of the table lookup area and significantly improving the overall table lookup accuracy.

[0205] Fig.11 It is a schematic diagram of a process for determining table lookup area index information provided by yet another exemplary embodiment of the present disclosure.

[0206] In some optional embodiments, the index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values. Fig.11 As shown, step 401 determines the index information corresponding to any table lookup area in a plurality of preset data intervals, including:

[0207] Step 401a, for any preset index value among the preset index values, based on the operator output value corresponding to the preset index value and the preset range, determine the candidate offset value of each candidate output value corresponding to the preset index value relative to the operator output value.

[0208] Each preset index value is used as the current preset index value, and the candidate offset value of each candidate output value corresponding to the current preset index value relative to the operator output value refers to j in the above formula twelve.

[0209] Step 401b, based on the errors corresponding to different candidate offset values ​​in the previous error term, the candidate offset values ​​corresponding to each candidate output value, and preset conditions, determine the minimum errors corresponding to each candidate output value.

[0210] The preset condition can be determined according to the specific characteristics of the recursive process of the above formula 13. The determination process is as follows:

[0211] Let λ(x)=index(x)-i-1, μ(x)=1-λ(x) to facilitate the calculation of interpolation. i represents the current preset index value, index(x) represents the target index value corresponding to the target quantized input value x, and the fitting value g(x) corresponding to x obtained by interpolation is expressed as follows:

[0212] g(x)=a i *λ(x)+a i+1 *μ(x) Formula 14

[0213] Among them, a i represents the quantized output value corresponding to i, a i+1 Indicates the quantized output value corresponding to i+1. i and a i+1 Not confirmed yet, just for derivation purposes.

[0214] Substitute equation 14 into equation 13 above and simplify to obtain:

[0215]

[0216] Where c(x) = base i-1 +base i -Df(x), it can be seen that c(x) is a function that is only related to x and has nothing to do with j and k. It can be obtained that for dp i,j The necessary and sufficient conditions for choosing k1 over k2 when k1>k2 are:

[0217]

[0218] Simplifying the repeated terms in equation 16 yields:

[0219]

[0220] The coefficients in equation 17 are represented by symbols and simplified as follows:

[0221]

[0222] Where A1 = ∑μ(x) 2 , A2=∑2μ(x)c(x), A3=∑2λ(x)μ(x).

[0223] Combining similar terms in formula 18, we get:

[0224]

[0225] Transforming Equation 19, we get:

[0226]

[0227] Referring to Formula 20, it can be seen that Formula 20 is close to the expression for calculating the slope, that is, for dp i,j , if each possible decision k is regarded as a point on a plane (k, dp i-1,k +A1k2 +A2k), for a given j, dp i-1,k , A1, A2, A3 are all constants, and only k is a variable. Then the necessary and sufficient conditions for the decision (i.e., selection) k1 to be better than k2 are k1>k2, and the slope of the line connecting the point corresponding to k1 and the point corresponding to k2 is less than -A3j, and A3 is only related to i, and has nothing to do with j and k. Therefore, when i is determined, A3 is a constant, and the cycle of j can be from small to large, so as j cycles, the value of -A3j will change from large to small. Based on this, all possible decisions k=0, 1, ..., 2D can be transformed into points on the plane in the above manner. Then, for each j, it is necessary to select the most suitable point P, that is, there is no other point P' that satisfies the following conditions: point P' is on the left side of point P and the slope of the line connecting P' and P is greater than -A3j. The condition for selecting the most suitable point P is used as a preset condition. According to the above conditions, it can be obtained that the point that may be the optimal decision must fall on a lower convex hull. The lower convex hull represents a convex hull with increasing slopes of lines connecting adjacent points. Fig.12 Schematic diagram of a lower convex shell provided by an exemplary embodiment of the present disclosure. Fig.12 As shown, each point represents a possible decision k, and the line below is the lower convex hull. For all j, dp i,j The optimal decision k must be a point on the lower convex hull. In this way, the complexity of searching k for a j can be reduced from O(n) of traversing each k to O(1), thus greatly reducing the complexity of dynamic programming. That is, each query dp i,j When we are looking for the first point whose slope with the following points is greater than -A3j, this point is dp i,j The optimal decision k, since the cycle of j is from small to large, A3 is positive, and -A3j is from large to small, therefore, the point corresponding to the optimal decision k always moves from right to left on the convex hull. According to the amortized analysis, it can be determined that the complexity of finding the optimal decision k each time is O(1).

[0228] Based on the above content, the errors corresponding to different candidate offset values ​​in the previous error term (which is the obtained constant) dp i-1,k , each candidate output value corresponds to the candidate offset value and the above preset conditions, and determines dp i,j The optimal decision k, the error dp corresponding to the optimal decision k i,j That is, the minimum error of the candidate output value corresponding to j.

[0229] Step 401c: determining a quantized output value corresponding to the preset index value from each candidate output based on the minimum error corresponding to each candidate output value.

[0230] After obtaining the minimum errors corresponding to the candidate output values, the candidate output value with the smallest minimum error may be determined as the quantized output value corresponding to the preset index value.

[0231] Step 401d: Determine the index information corresponding to the table lookup area based on the quantized output values ​​corresponding to the preset index values.

[0232] This embodiment can reduce the search complexity and improve the efficiency of determining the quantized output value of the preset index value by converting the complex dynamic programming process into a process of searching for the minimum error of the candidate output value based on the preset conditions.

[0233] Fig.13 It is a schematic diagram of a process of determining multiple preset data intervals provided by yet another exemplary embodiment of the present disclosure.

[0234] In some optional embodiments, such as Fig.13 As shown, in Figure 2 Based on the illustrated embodiment, multiple preset data intervals can be obtained in the following manner:

[0235] Step 501: determine the function type of the quantization operator.

[0236] Among them, the function types include even functions and odd functions, that is, the quantization operator satisfies the conditions of axisymmetry or center symmetry.

[0237] Step 502 , in response to the function type being an even function or an odd function, determining a first sub-range and a second sub-range based on a quantization input data range of a quantization operator; the first sub-range and the second sub-range are respectively half of the range of the quantization input data.

[0238] If the function type is an even function or an odd function, the quantization input data range of the quantization operator can be divided into a first sub-range and a second sub-range based on the symmetry of the even function and the odd function.

[0239] Exemplarily, for an even function, f(x)=f(-x) is satisfied, and the quantization input data range is divided into a first sub-range less than 0 and a second sub-range greater than 0 at x=0. For an odd function, f(x)=-f(-x) is satisfied, and the quantization input data range is divided into a first sub-range less than 0 and a second sub-range greater than 0 at x=0.

[0240] Step 503, determining multiple preset data intervals according to the first sub-range and the change gradient size of the quantization operator within the first sub-range; or determining multiple preset data intervals according to the second sub-range and the change gradient size of the quantization operator within the second sub-range.

[0241] Among them, after the quantization input data range is divided into a first sub-range and a second sub-range, due to the symmetry of the quantization operator, only one of the first sub-range and the second sub-range can be tabulated (i.e., the index information corresponding to the sub-range is determined). Taking the tabulation of the first sub-range as an example, the quantization input value in the first sub-range obtains the corresponding quantization output value by looking up the table, and the quantization input value of the second sub-range is converted into the table lookup operation of the first sub-range according to the symmetry of the quantization operator to obtain the quantization output value corresponding to the quantization input value of the second sub-range. Taking the odd function as an example, for the odd function of the int16 type, only [-32768,0] is tabulated. For the quantization input value x, if x is greater than 0, x can be changed to -x. After obtaining the quantization output value y through the index information corresponding to multiple preset data intervals of [-32768,0], -y is used as the quantization output value corresponding to x.

[0242] In some optional embodiments, the specific principle of determining multiple preset data intervals of the first sub-range or the second sub-range can refer to the principle of determining multiple preset data intervals for the quantized input data range in any of the aforementioned embodiments, and will not be repeated here.

[0243] In some optional embodiments, the function type may also include other functions that meet the axisymmetric condition in addition to the odd function and the even function, such as a symmetric function whose axis of symmetry is not the y axis (for example, the axis of symmetry is x=a, and a is a constant greater than 0), and the quantized input data range may be divided according to the axis of symmetry to obtain a first sub-range and a second sub-range. Tabulation is performed for the first sub-range or the second sub-range, and when looking up the table, the full-range table lookup under the partial range tabulation is implemented according to the corresponding symmetric relationship.

[0244] For odd functions or even functions, the disclosed embodiment divides the quantized input data range into a first sub-range and a second sub-range, and only tabulates one of the sub-ranges, which is equivalent to narrowing the tabulated quantized input data range. When the number of preset data intervals and the number of preset index values ​​of each preset data interval remain unchanged, it is equivalent to expanding the table entries. For example, the original 65536 results of int16 were fitted by 512 quantized output values ​​of 64*8. The half-side tabulation of this embodiment can achieve the result of fitting half of int16 by 512 quantized output values. For half of the range, it is equivalent to doubling the table entries. At the same time, the other half of the range can also perform table lookup operations through the half-side table entries to determine the corresponding quantized output values. Therefore, the table lookup accuracy can be effectively improved.

[0245] Fig.14 It is a flowchart of a quantization method of a neural network model provided by another exemplary embodiment of the present disclosure.

[0246] In some optional embodiments, such as Fig.14 As shown, step 202 of determining the target data interval corresponding to the quantized input data from a plurality of preset data intervals may include:

[0247] Step 2021: Determine the input value to be looked up in the table corresponding to the quantized input data according to the quantized input data and the function type of the quantized operator.

[0248] Among them, for odd functions and even functions, if the quantized input data is within the sub-range of the tabulation, the quantized input data can be used as the input value to be looked up in the table. If the quantized input data does not belong to the sub-range of the tabulation, the input value to be looked up in the table corresponding to the quantized input data is the negative value of the quantized input data, that is, if the quantized input data is x, the input value to be looked up in the table is -x.

[0249] Step 2022: According to the input value of the table to be looked up, determine the target data interval corresponding to the input value of the table to be looked up from multiple preset data intervals.

[0250] For the specific operation of this step, reference may be made to the specific operation of step 202 in the above embodiment.

[0251] Determining the target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval in step 203 may include:

[0252] Step 203a, based on the table input value to be looked up and the index information corresponding to the target data interval, determine the quantized output value corresponding to the table input value to be looked up.

[0253] The specific operation of this step may refer to the specific operation of the aforementioned step 203.

[0254] Step 203b, determining the target quantized output value corresponding to the quantized input data according to the quantized output value corresponding to the input value to be looked up in the table.

[0255] Among them, in the case where the quantized input data belongs to the tabulated sub-range (such as the first sub-range or the second sub-range of the index information of multiple preset data intervals has been determined), the quantized output value corresponding to the input value to be looked up in the table is the target quantized output value corresponding to the quantized input data. In the case where the quantized input data does not belong to the tabulated sub-range, for odd functions, the target quantized output value corresponding to the quantized input data is the negative value of the quantized output value corresponding to the input value to be looked up in the table. For even functions, the quantized output value corresponding to the input value to be looked up in the table is the target quantized output value corresponding to the quantized input data. It can be determined specifically according to the symmetry of the odd function or the even function.

[0256] In the embodiment of the present disclosure, in the case of half-side tabulation, a table lookup operation of the entire quantized input data range can be implemented based on the table entries of the half-side, thereby effectively improving the table lookup accuracy while ensuring the operation efficiency.

[0257] In some optional embodiments, Fig.15 FIG. 1 is a schematic diagram of multiple preset data intervals provided by an exemplary embodiment of the present disclosure. Fig.15 As shown, for the curve of the quantization operator (i.e., the quantization operator curve 13), the first linear region 131 on the left, the multiple table lookup regions 132 in the middle (including six table lookup regions from table lookup region 1321 to table lookup region 1326), and the second linear region 133 on the right can be determined according to the range of x. For each table lookup region (table lookup region 1321 is taken as an example in the figure), the input quantization value in the table lookup region is mapped to multiple preset index values ​​14 of the table lookup region (i.e., 64 values ​​from 0 to 63 in the figure), and each preset index value corresponds to a quantization output value 15 (i.e., the black dot below the preset index value in the figure). Fig.15 The table lookup area in the multiple preset data intervals is used as an example to illustrate the multiple preset data intervals by equal division, and is not a limitation of the embodiments of the present disclosure. In the embodiments of the present disclosure, the table lookup area is determined based on the change gradient of the operator output value of the quantization operator, and the table lookup area is not evenly divided. Fig.16 FIG. 1 is a schematic diagram of multiple table lookup areas provided by an exemplary embodiment of the present disclosure. Fig.16 As shown, multiple table lookup areas 132 are determined based on the change gradient size of the operator output value of the quantization operator, so that the change gradient size of the operator output value in each table lookup area is close, avoiding the situation where the operator output value in the same table lookup area fluctuates greatly, and improving the overall table lookup accuracy. If the average division method is adopted, the peak and trough in the middle may be in one table lookup area, resulting in large fluctuations and reducing the table lookup accuracy.

[0258] The above-mentioned embodiments of the present disclosure may be implemented separately or in any combination without conflict. The specific configuration may be based on actual needs and the present disclosure does not limit this.

[0259] Any quantization method of a neural network model provided in the embodiments of the present disclosure can be executed by any appropriate device with data processing capabilities, including but not limited to: terminal devices and servers, etc. Alternatively, any quantization method of a neural network model provided in the embodiments of the present disclosure can be executed by a processor, such as the processor executing any quantization method of a neural network model mentioned in the embodiments of the present disclosure by calling corresponding instructions stored in a memory. This will not be described in detail below.

[0260] Exemplary Devices

[0261] Fig.17 is a schematic diagram of a quantization device for a neural network model provided by an exemplary embodiment of the present disclosure. The device of this embodiment can be used to implement the corresponding method embodiments of the present disclosure, such as Fig.17The device shown may include: a first processing module 61 , a second processing module 62 , a third processing module 63 and a fourth processing module 64 .

[0262] The first processing module 61 may be used to determine quantized input data corresponding to the input data based on the operation operator and the corresponding input data during the operation of the neural network model.

[0263] The second processing module 62 can be used to determine the target data interval corresponding to the quantized input data from multiple preset data intervals, and the multiple preset data intervals are determined based on the gradient of the output value of the quantization operator with the input value; the quantization operator is the operator after the operation operator is quantized.

[0264] The third processing module 63 may be used to determine a target quantized output value corresponding to the quantized input data based on index information corresponding to the quantized input data and the target data interval.

[0265] The fourth processing module 64 may be used to determine the quantization result of the input data after being calculated by the operation operator based on the target quantization output value.

[0266] Fig.18 It is a structural schematic diagram of a quantization device for a neural network model provided by another exemplary embodiment of the present disclosure.

[0267] In some optional embodiments, such as Fig.18 As shown in the above Fig.17 On the basis of the illustrated embodiment, the apparatus of the embodiment of the present disclosure may further include: a fifth processing module 71, which may be used to determine a plurality of preset data intervals.

[0268] The fifth processing module 71 may include: a first determining unit 711 , a first processing unit 712 , and a second processing unit 713 .

[0269] The first determining unit 711 may be configured to determine a quantization input data range of a quantization operator.

[0270] The first processing unit 712 can be used to determine the first linear region, the second linear region and multiple table lookup regions corresponding to the quantized input data according to the quantized input data range and the change gradient size of the quantization operator within the quantized input data range, and the multiple table lookup regions are nonlinear regions.

[0271] The second processing unit 713 may be configured to determine a plurality of preset data intervals based on the first linear region, the second linear region, and each table lookup region.

[0272] In some optional embodiments, the first processing unit 712 can be specifically used to: determine the first linear region and the second linear region by least squares fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range. Determine the absolute value of the secondary difference corresponding to each quantization input value in the nonlinear region according to the operator output value of the quantization operator at each quantization input value in the nonlinear region. Determine the interval boundary values ​​corresponding to multiple table lookup regions according to the absolute value of the secondary difference corresponding to each quantization input value in the nonlinear region. Obtain multiple table lookup regions according to the interval boundary values ​​corresponding to each table lookup region.

[0273] In some optional embodiments, the first processing unit 712 may be specifically configured to:

[0274] Determine the range of thresholds to be searched; determine the target threshold within the range of thresholds to be searched based on the binary search method, so that the sum of the absolute values ​​of the quadratic differences corresponding to the quantized input values ​​in each of the multiple intervals divided by the nonlinear area is less than or equal to the target threshold; and use the boundary values ​​of the intervals divided by the nonlinear area as the interval boundary values ​​of each lookup table area.

[0275] In some optional embodiments, the first processing unit 712 can be specifically used to: determine the first linear region and the second linear region by least square fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range. In response to the quantization operator being a preset quantization operator, the nonlinear region is divided into a plurality of sub-ranges. For any sub-range of the plurality of sub-ranges, based on the change gradient size of the quantization operator within the sub-range, a plurality of table lookup regions corresponding to the sub-range are determined; based on the table lookup regions corresponding to each sub-range, a plurality of table lookup regions of the nonlinear region are obtained.

[0276] Fig.19 It is a structural schematic diagram of a quantization device for a neural network model provided by yet another exemplary embodiment of the present disclosure.

[0277] In some optional embodiments, the index information corresponding to each table lookup area in the plurality of preset data intervals may include quantized output values ​​corresponding to the plurality of preset index values.

[0278] In some optional embodiments, such as Fig.19 As shown in the above Fig.17 On the basis of the illustrated embodiment, the third processing module 63 may include: a third processing unit 631 , a fourth processing unit 632 and a fifth processing unit 633 .

[0279] The third processing unit 631 may be configured to obtain a mapping parameter corresponding to the target data interval in response to the target data interval being a table lookup area.

[0280] The mapping parameter is used to map the quantized input data from the quantized input data range to the preset index data range corresponding to the target data interval; the preset index data range is the data range of the table lookup index value corresponding to the target data interval.

[0281] The fourth processing unit 632 may be configured to determine a target index value of the quantized input data within a preset index data range based on the mapping parameters.

[0282] The fifth processing unit 633 may be configured to determine a target quantized output value corresponding to the quantized input data based on the target index value and the quantized output values ​​respectively corresponding to a plurality of preset index values ​​in the index information.

[0283] In some optional embodiments, the fifth processing unit 633 can be specifically used to: in response to the target index value belonging to a target preset index value among multiple preset index values, use the quantization output value corresponding to the target preset index value as the target quantization output value. In response to the target index value not belonging to multiple preset index values, determine the first preset index value and the second preset index value adjacent to the target index value among the multiple preset index values; based on the target index value, the first preset index value, the second preset index value, the first quantization output value corresponding to the first preset index value, and the second quantization output value corresponding to the second preset index value, determine the quantization output value corresponding to the target index value as the target quantization output value.

[0284] Fig. 20 It is a structural schematic diagram of a quantization device for a neural network model provided by yet another exemplary embodiment of the present disclosure.

[0285] In some optional embodiments, the index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values ​​respectively; Fig. 20 As shown in the above Fig.17 On the basis of the illustrated embodiment, the apparatus of the disclosed embodiment may further include: a sixth processing module 72, which may be used to determine the index information corresponding to each lookup area in the plurality of preset data intervals. That is, for any lookup area in the plurality of preset data intervals, determine the quantized output values ​​corresponding to the plurality of preset index values ​​of the lookup area.

[0286] In some optional embodiments, such as Fig. 20 As shown, the sixth processing module 72 may include: a second determining unit 721 , a sixth processing unit 722 , a seventh processing unit 723 , a third determining unit 724 and a fourth determining unit 725 .

[0287] The second determining unit 721 may be configured to determine the quantized input values ​​corresponding to the preset index values ​​based on the mapping parameters corresponding to the table lookup area.

[0288] The sixth processing unit 722 may be configured to calculate the operator output value of the quantization operator at each preset index value corresponding to the table lookup area based on the quantization input value corresponding to each preset index value.

[0289] The seventh processing unit 723 may be configured to determine, for any preset index value, a plurality of candidate output values ​​within a preset range of the operator output value corresponding to the preset index value.

[0290] The third determining unit 724 may be configured to determine the fitting error term corresponding to each preset index value based on the candidate output value corresponding to each preset index value.

[0291] The fitting error term corresponding to any preset index value includes the fitting error corresponding to each candidate output value of the preset index value.

[0292] The fourth determining unit 725 may be configured to determine index information corresponding to the table lookup area based on the fitting error terms corresponding to the preset index values.

[0293] In some optional embodiments, the third determination unit 724 can be specifically used to: sequentially use each of the preset index values ​​as the current preset index value in a preset order, determine the fitting line segment between each historical candidate output value and each current candidate output value based on each historical candidate output value corresponding to the previous preset index value of the current preset index value and each current candidate output value corresponding to the current preset index value. Determine the fitting error term corresponding to the current preset index value based on the previous error term corresponding to the previous preset index value determined previously, the fitting line segment between each historical candidate output value and each current candidate output value, and the quantization operator.

[0294] In some optional embodiments, the third determination unit 724 can be specifically used to: calculate, based on the quantization operator, the operator output values ​​corresponding to each target quantization input value mapped between the current preset index value and the previous preset index value; for each fitting line segment between each historical candidate output value and each current candidate output value, determine, based on the fitting line segment, the fitting value of each target quantization input value on the fitting line segment; determine the fitting error term corresponding to the current preset index value based on the previous error term, the operator output value corresponding to each target quantization input value, and the fitting value of each target quantization input value on each fitting line segment.

[0295] In some optional embodiments, the fourth determination unit 725 can be specifically used to: in the reverse order of the preset order, take each preset index value as the target preset index value in turn, and determine the quantized output value corresponding to the target preset index value from the candidate output values ​​corresponding to the target preset index value based on the correlation between the fitting error term corresponding to the target preset index value and the fitting error term corresponding to the previous preset index value of the target preset index value, and the quantized output value corresponding to the previous preset index value determined previously. Based on the quantized output values ​​corresponding to each preset index value, determine the index information corresponding to the lookup area.

[0296] In some optional embodiments, the index information corresponding to each lookup area in a plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values. The sixth processing module 72 can be specifically used to: for any preset index value among the preset index values, determine the candidate offset values ​​of each candidate output value corresponding to the preset index value relative to the operator output value based on the operator output value and the preset range corresponding to the preset index value. Based on the errors corresponding to different candidate offset values ​​in the previous error term, the candidate offset values ​​corresponding to each candidate output value, and the preset conditions, determine the minimum errors corresponding to each candidate output value. Based on the minimum errors corresponding to each of the candidate output values, determine the quantized output value corresponding to the preset index value from each candidate output. Based on the quantized output values ​​corresponding to each preset index value, determine the index information corresponding to the lookup area.

[0297] Fig.21 It is a structural schematic diagram of a quantization device for a neural network model provided by yet another exemplary embodiment of the present disclosure.

[0298] In some optional embodiments, such as Fig.21 As shown in the above Fig.17 On the basis of the illustrated embodiment, the apparatus of the embodiment of the present disclosure may further include: a fifth processing module 71, which may be used to determine a plurality of preset data intervals.

[0299] In some optional embodiments, such as Fig.21 As shown, the fifth processing module 71 may include:

[0300] The fifth determining unit 71a may be configured to determine a function type of a quantization operator.

[0301] The sixth determination unit 71b can be used to determine the first sub-range and the second sub-range based on the quantization input data range of the quantization operator in response to the function type being an even function or an odd function; the first sub-range and the second sub-range are respectively half of the range of the quantization input data.

[0302] The seventh determination unit 71c can be used to determine multiple preset data intervals based on the first sub-range and the change gradient size of the quantization operator within the first sub-range; or determine multiple preset data intervals based on the second sub-range and the change gradient size of the quantization operator within the second sub-range.

[0303] In some optional embodiments, such as Fig.21 As shown, the second processing module 62 may include: an eighth determining unit 621 and a ninth determining unit 622 .

[0304] The eighth determining unit 621 may be configured to determine the input value to be looked up in the table corresponding to the quantized input data according to the quantized input data and the function type of the quantized operator.

[0305] The ninth determining unit 622 may be configured to determine, according to the input value of the table to be looked up, a target data interval corresponding to the input value of the table to be looked up from a plurality of preset data intervals.

[0306] The third processing module 63 may include an eighth processing unit 63a and a ninth processing unit 63b.

[0307] The eighth processing unit 63a may be configured to determine a quantized output value corresponding to the input value to be looked up in the table based on the input value to be looked up in the table and index information corresponding to the target data interval.

[0308] The ninth processing unit 63b may be configured to determine a target quantized output value corresponding to the quantized input data according to a quantized output value corresponding to the input value to be looked up in the table.

[0309] The beneficial technical effects corresponding to the exemplary embodiment of the present device can be found in the corresponding beneficial technical effects of the above exemplary method section, which will not be repeated here.

[0310] Exemplary Electronic Devices

[0311] Fig. 22 It is a structural diagram of an electronic device provided by an embodiment of the present disclosure, including at least one processor 91 and a memory 92.

[0312] The processor 91 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 90 to perform desired functions.

[0313] The memory 92 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 91 may execute one or more computer program instructions to implement the methods and / or other desired functions of the various embodiments of the present disclosure described above.

[0314] In one example, the electronic device 90 may further include: an input device 93 and an output device 94 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0315] The input device 93 may also include, for example, a keyboard, a mouse, etc.

[0316] The output device 94 can output various information to the outside, and may include, for example, a display, a speaker, a printer, a communication network and its connected remote output devices, etc.

[0317] Of course, to simplify, Fig. 22 Only some of the components related to the present disclosure in the electronic device 90 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 90 may also include any other appropriate components.

[0318] Exemplary computer program products and computer-readable storage media

[0319] In addition to the above methods and devices, embodiments of the present disclosure may also provide a computer program product, including computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the methods of various embodiments of the present disclosure described in the above “Exemplary Methods” section.

[0320] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0321] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the processor executes the steps in the method of various embodiments of the present disclosure described in the above “Exemplary Method” section.

[0322] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium is, for example, but not limited to, a system, device or device including electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0323] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and cannot be considered as necessary for each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, rather than limitation, and the above details do not limit the present disclosure to being implemented by adopting the above specific details.

[0324] Those skilled in the art may make various changes and modifications to the present disclosure without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the present disclosure claims and their equivalents, the present disclosure is also intended to include these modifications and variations.

Claims

1. A quantization method for a neural network model, comprising: Determine quantized input data corresponding to the input data based on an operation operator and corresponding input data during operation of the neural network model; Determine a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on a gradient of an output value of a quantization operator with respect to an input value; the quantization operator is an operator quantized by the operation operator; Determining a target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval; Based on the target quantized output value, a quantized result of the input data after being calculated by the operation operator is determined.

2. The method according to claim 1, wherein: The multiple preset data intervals are obtained in the following manner: Determining a quantization input data range of the quantization operator; Determine, according to the range of the quantized input data and the magnitude of the gradient of the quantization operator within the range of the quantized input data, a first linear region, a second linear region, and a plurality of table lookup regions corresponding to the quantized input data, wherein the plurality of table lookup regions are nonlinear regions; The plurality of preset data intervals are determined based on the first linear region, the second linear region and each of the table lookup regions.

3. The method according to claim 2, wherein: The determining, according to the range of the quantized input data and the magnitude of the gradient of change of the quantized operator within the range of the quantized input data, a first linear region, a second linear region, and a plurality of table lookup regions corresponding to the quantized input data comprises: Determining the first linear region and the second linear region by least square fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range; Determining, according to the operator output value of the quantization operator at each of the quantization input values ​​in the nonlinear region, the absolute value of the secondary difference corresponding to each of the quantization input values ​​in the nonlinear region; Determine interval boundary values ​​corresponding to a plurality of table lookup regions respectively according to the quadratic difference absolute values ​​respectively corresponding to the quantized input values ​​in the nonlinear region; The plurality of table lookup areas are obtained according to the interval boundary values ​​respectively corresponding to the table lookup areas.

4. The method according to claim 3, wherein: The determining of interval boundary values ​​corresponding to a plurality of table lookup regions respectively according to the quadratic difference absolute values ​​respectively corresponding to the quantized input values ​​in the nonlinear region comprises: Determine the threshold range to be searched; Determine a target threshold within the threshold range to be searched based on a binary search method, so that the sum of the absolute values ​​of the secondary differences corresponding to the quantized input values ​​in each of the multiple intervals divided by the nonlinear region is less than or equal to the target threshold; The boundary values ​​of each interval divided by the nonlinear area are used as the interval boundary values ​​of each table lookup area.

5. The method according to claim 1, wherein: The index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values ​​respectively; The determining, based on the quantized input data and the index information corresponding to the target data interval, a target quantized output value corresponding to the quantized input data includes: In response to the target data interval being a table lookup area, obtaining a mapping parameter corresponding to the target data interval; the mapping parameter is used to map the quantized input data from the quantized input data range to a preset index data range corresponding to the target data interval; the preset index data range is a data range of a table lookup index value corresponding to the target data interval; Based on the mapping parameters, determining a target index value of the quantized input data within a preset index data range; The target quantized output value corresponding to the quantized input data is determined based on the target index value and the quantized output values ​​respectively corresponding to a plurality of preset index values ​​in the index information.

6. The method according to claim 5, wherein: The determining the target quantized output value corresponding to the quantized input data based on the target index value and the quantized output values ​​respectively corresponding to the plurality of preset index values ​​in the index information comprises: In response to the target index value belonging to a target preset index value among the multiple preset index values, taking a quantized output value corresponding to the target preset index value as the target quantized output value; In response to the target index value not belonging to the plurality of preset index values, determining a first preset index value and a second preset index value adjacent to the target index value among the plurality of preset index values; Based on the target index value, the first preset index value, the second preset index value, the first quantization output value corresponding to the first preset index value, and the second quantization output value corresponding to the second preset index value, determine the quantization output value corresponding to the target index value as the target quantization output value.

7. The method according to claim 2, wherein: The determining, according to the range of the quantized input data and the magnitude of the gradient of change of the quantized operator within the range of the quantized input data, a first linear region, a second linear region, and a plurality of table lookup regions corresponding to the quantized input data comprises: Determining the first linear region and the second linear region by least square fitting according to the quantization input data range and the operator output value of the quantization operator at each quantization input value within the quantization input data range; In response to the quantization operator being a preset quantization operator, dividing the nonlinear region into a plurality of sub-ranges; For any sub-range among the multiple sub-ranges, multiple table lookup areas corresponding to the sub-range are determined based on the change gradient size of the quantization operator within the sub-range; and the multiple table lookup areas of the nonlinear area are obtained based on the table lookup areas corresponding to each of the sub-ranges.

8. The method according to any one of claims 1 to 7, wherein: The index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values ​​respectively; The method further comprises: For any table lookup area in the plurality of preset data intervals, the index information corresponding to the table lookup area is obtained in the following manner: Determine, based on the mapping parameters corresponding to the table lookup area, the quantized input values ​​corresponding to the preset index values; Calculating the operator output value of the quantization operator at each preset index value corresponding to the table lookup area based on the quantization input value corresponding to each preset index value; For any of the preset index values, determine a plurality of candidate output values ​​within a preset range of the operator output value corresponding to the preset index value; Based on the candidate output values ​​corresponding to the preset index values, respectively, determining the fitting error terms corresponding to the preset index values; the fitting error term corresponding to any preset index value includes the fitting error corresponding to each candidate output value of the preset index value; Based on the fitting error terms respectively corresponding to the preset index values, the index information corresponding to the table lookup area is determined.

9. The method according to claim 8, wherein: The determining, based on the candidate output values ​​corresponding to the preset index values, the fitting error terms corresponding to the preset index values ​​respectively, comprises: Taking each of the preset index values ​​as the current preset index value in sequence according to a preset order, and determining a fitting line segment between each historical candidate output value and each current candidate output value based on each historical candidate output value corresponding to a previous preset index value of the current preset index value and each current candidate output value corresponding to the current preset index value; Based on the previous error term corresponding to the previous preset index value determined previously, the fitting line segment between each historical candidate output value and each current candidate output value, and the quantization operator, the fitting error term corresponding to the current preset index value is determined.

10. The method according to claim 9, wherein: The determining of the fitting error term corresponding to the current preset index value based on the previous error term corresponding to the previous preset index value determined previously, the fitting line segment between each historical candidate output value and each current candidate output value, and the quantization operator comprises: Based on the quantization operator, calculating operator output values ​​corresponding to each target quantization input value mapped between the current preset index value and the previous preset index value; For each fitting line segment between each historical candidate output value and each current candidate output value, based on the fitting line segment, determining the fitting values ​​of each of the target quantized input values ​​on the fitting line segment; Based on the previous error term, the operator output values ​​corresponding to the target quantized input values, and the fitting values ​​of the target quantized input values ​​on each fitting line segment, the fitting error term corresponding to the current preset index value is determined.

11. The method according to claim 9, wherein: The determining the index information corresponding to the table lookup area based on the fitting error terms respectively corresponding to the preset index values ​​includes: In the reverse order of the preset order, each of the preset index values ​​is sequentially used as a target preset index value, and based on the correlation between the fitting error term corresponding to the target preset index value and the fitting error term corresponding to the previous preset index value of the target preset index value, and the previously determined quantized output value corresponding to the previous preset index value, the quantized output value corresponding to the target preset index value is determined from the candidate output values ​​corresponding to the target preset index value; The index information corresponding to the table lookup area is determined based on the quantized output values ​​respectively corresponding to the preset index values.

12. The method according to any one of claims 1 to 7, wherein: The index information corresponding to each table lookup area in the plurality of preset data intervals includes quantized output values ​​corresponding to a plurality of preset index values ​​respectively; The method further comprises: For any table lookup area in the plurality of preset data intervals, the index information corresponding to the table lookup area is obtained in the following manner: For any preset index value among the preset index values, determining, based on the operator output value corresponding to the preset index value and a preset range, candidate offset values ​​of each candidate output value corresponding to the preset index value relative to the operator output value; Determining the minimum error corresponding to each of the candidate output values ​​based on the errors corresponding to different candidate offset values ​​in the previous error term, the candidate offset values ​​corresponding to each of the candidate output values, and a preset condition; Determine, from each of the candidate outputs, a quantized output value corresponding to the preset index value based on the minimum error corresponding to each of the candidate output values; The index information corresponding to the table lookup area is determined based on the quantized output values ​​respectively corresponding to the preset index values.

13. The method according to any one of claims 1 to 7, wherein: The multiple preset data intervals are obtained in the following manner: Determining a function type of the quantization operator; In response to the function type being an even function or an odd function, determining a first sub-range and a second sub-range based on a quantization input data range of the quantization operator; the first sub-range and the second sub-range are respectively half ranges of the quantization input data range; Determining the plurality of preset data intervals according to the first sub-range and a change gradient of the quantization operator within the first sub-range; Alternatively, the plurality of preset data intervals are determined according to the second sub-range and a change gradient of the quantization operator within the second sub-range.

14. The method according to claim 13, wherein: The determining a target data interval corresponding to the quantized input data from a plurality of preset data intervals includes: Determining, according to the quantized input data and the function type of the quantized operator, an input value to be looked up in a table corresponding to the quantized input data; According to the input value of the table to be looked up, determining a target data interval corresponding to the input value of the table to be looked up from the multiple preset data intervals; The determining, based on the quantized input data and the index information corresponding to the target data interval, a target quantized output value corresponding to the quantized input data includes: Determine a quantized output value corresponding to the input value in the table to be looked up based on the index information corresponding to the target data interval; According to the quantized output value corresponding to the input value to be looked up in the table, a target quantized output value corresponding to the quantized input data is determined.

15. A quantization device for a neural network model, comprising: A first processing module, used for determining quantized input data corresponding to the input data based on an operation operator and corresponding input data during operation of the neural network model; A second processing module, configured to determine a target data interval corresponding to the quantized input data from a plurality of preset data intervals, wherein the plurality of preset data intervals are determined based on a gradient of an output value of a quantization operator with respect to an input value; the quantization operator is an operator quantized by the operation operator; A third processing module, configured to determine a target quantized output value corresponding to the quantized input data based on the index information corresponding to the quantized input data and the target data interval; The fourth processing module is used to determine the quantization result of the input data after being calculated by the operation operator based on the target quantization output value.

16. A computer-readable storage medium storing a computer program, wherein the computer program is used to execute the method according to any one of claims 1 to 14.

17. An electronic device, comprising: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the method described in any one of claims 1-14.