Model quantification method, device, equipment, storage medium and product

By calculating the sensitivity evaluation values ​​of each layer of the model network, selecting the network to be adjusted and setting a high-precision quantization configuration, the problem of poor quantization method of single-layer quantization error based on adjustment model is solved, and effective on resource-constrained devices Quantify and deploy.

CN118839742BActive Publication Date: 2024-12-20HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411329970.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2024-12-20
Estimated Expiration
2044-09-24

AI Technical Summary

Technical Problem

In the prior art, single-layer quantization error is difficult to ensure the effect of adjusting the model quantization method, and it is difficult to effectively deploy on resource-constrained embedded edge devices.

Method used

By obtaining the output data and correlation scores of the initial floating-point model, calculate the sensitivity evaluation value of each layer of network, select the network to be adjusted, and set a high-precision quantization configuration based on it, adjust the model quantization method to improve the quantization effect.

Benefits of technology

A more reasonable quantization method is realized, the quantization effect is improved, and a single-layer quantized output data that meets the constraints of the hardware platform is generated, suitable for devices with resource limitations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118839742B_ABST
    Figure CN118839742B_ABST
Patent Text Reader

Abstract

The present application relates to the field of model quantization technology, and discloses a model quantization method, device, equipment, storage medium and product, including: obtaining the model output data of the initial floating-point model, and the correlation score corresponding to each output node of the output layer of the initial floating-point model, and obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; calculating the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model; selecting the network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation values; setting the quantization configuration for the network to be adjusted and other layers of the network in the initial floating-point model; and quantizing the initial floating-point model according to the set quantization configuration. Since part of the network is selected as the network to be adjusted according to the sensitivity evaluation value that can characterize the degree of influence of the quantization of the network on the model output, and the network to be adjusted is set to a quantization configuration with higher quantization accuracy, it is ensured that the quantization method can be reasonably adjusted and the quantization effect is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of model quantization technology, and in particular to model quantization methods, devices, equipment, storage media and products. Background Art

[0002] Deep learning has achieved important results in many fields. Although deep learning has brought many benefits, the storage of trained models has become increasingly difficult. In addition, because deep learning trained models have high resource requirements, it is also difficult to deploy related computing workloads on embedded edge devices with limited computing resources. In order to ensure that resource-constrained devices can also use the model, quantization is a direction to compress and accelerate the model.

[0003] At present, the quantization of related technologies is generally to evaluate the degree of quantization loss of each layer of the network in the model through the single-layer quantization error of the network, and then adjust the quantization method. However, the single-layer quantization loss is not proportional to the impact of the layer of network on the output result. It is difficult to guarantee the effect of adjusting the quantization method based on this. Summary of the invention

[0004] The main purpose of this application is to provide a model quantization method, device, equipment, storage medium and product, aiming to solve the technical problem that the relevant technology directly uses the single-layer quantization error as the basis to adjust the quantization method of the model, and the effect is difficult to guarantee.

[0005] To achieve the above objectives, the present application proposes a model quantization method, which includes:

[0006] Obtain the model output data of the initial floating-point model, as well as the correlation scores corresponding to the output nodes of the output layer of the initial floating-point model, and obtain the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample after the network of the layer in the initial floating-point model is quantized separately;

[0007] Calculate the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data;

[0008] Selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value;

[0009] The network to be adjusted in the initial floating-point model is set as a network target quantization configuration, and other layer networks in the initial floating-point model except the network to be adjusted are set as network initial quantization configurations, wherein the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration;

[0010] The initial floating-point model is quantized according to the set quantization configuration.

[0011] In a possible implementation of the present application, before obtaining the model output data of the initial floating-point model, and the correlation scores corresponding to each output node of the output layer of the initial floating-point model, and obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model, it also includes:

[0012] Obtaining quantization constraint rules corresponding to each operator in the initial floating-point model, the quantization constraint rules including optional data types, bit relationship descriptions and / or type relationship descriptions; the optional data types are used to characterize the quantization configurations that can be set for the input, output or weight of the operator, and the quantization configurations include quantization data types and quantization bits; the bit relationship descriptions are used to characterize the association between quantization bits among inputs, outputs and / or weights in the operator; the type relationship descriptions are used to characterize the association between quantization data types among inputs, outputs and / or weights in the operator;

[0013] Determine an initial quantization configuration corresponding to each operator according to the quantization constraint rule, wherein the initial quantization configuration is a quantization configuration corresponding to the lowest quantization accuracy among the quantization configurations that can be set for each operator;

[0014] Obtaining the corresponding relationship between each layer network and the operator in the initial floating-point model;

[0015] Constructing the network initial quantization configuration of each layer of the network in the initial floating-point model according to the corresponding relationship and the initial quantization configuration corresponding to each operator;

[0016] The obtaining of single-layer quantized output data corresponding to each layer of the network in the initial floating-point model includes:

[0017] Based on the network initial quantization configuration, single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is obtained.

[0018] In a possible implementation of the present application, constructing the network initial quantization configuration of each layer of the network in the initial floating-point model according to the corresponding relationship and the initial quantization configuration corresponding to each operator includes:

[0019] Obtaining hardware constraint rules of the model deployment platform, where the hardware constraint rules are used to characterize the quantitative configuration used by the hardware support operator;

[0020] Adjusting the initial quantization configuration corresponding to each operator according to the hardware constraint rule to obtain the adjusted quantization configuration corresponding to each operator;

[0021] The network initial quantization configuration of each layer of the network in the initial floating-point model is constructed according to the corresponding relationship and the adjusted quantization configuration corresponding to each operator.

[0022] In a possible implementation of the present application, the step of calculating the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data includes:

[0023] Traversing each layer of the network in the initial floating-point model to obtain the current network;

[0024] Determine the output difference value corresponding to each output node of the output layer in the initial floating-point model according to the model output data and the single-layer quantized output data corresponding to the current network, wherein the output difference value is the square value of the difference between the model output data and the part corresponding to the output node in the single-layer quantized output data;

[0025] Determine the difference score corresponding to each output node according to the output difference value and the correlation score corresponding to each output node of the output layer in the initial floating point model, wherein the difference score is the product of the output difference value and the correlation score;

[0026] Add the difference scores corresponding to each output node to obtain a sensitivity evaluation value corresponding to the current network;

[0027] At the end of the traversal, the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model are obtained.

[0028] In a possible implementation of the present application, the step of performing model quantization on the initial floating-point model according to the set quantization configuration includes:

[0029] Obtaining an operator to be adjusted in the initial floating-point model, wherein the operator to be adjusted is an operator in the initial floating-point model that is directly adjacent to the network to be adjusted and whose quantization accuracy corresponding to the input quantization configuration is inconsistent with the quantization accuracy corresponding to the output in the network target quantization configuration, or an operator in the initial floating-point model that is directly adjacent to the network to be adjusted and whose quantization accuracy corresponding to the output quantization configuration is inconsistent with the quantization accuracy corresponding to the input in the network target quantization configuration;

[0030] Setting a precision conversion operator between the operator to be adjusted and the network to be adjusted in the initial floating-point model to obtain an adjusted initial floating-point model;

[0031] The adjusted initial floating-point model is quantized according to the set quantization configuration.

[0032] In a possible implementation of the present application, selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value includes:

[0033] Sorting the networks of each layer in the initial floating-point model from large to small according to the corresponding sensitivity evaluation values ​​to obtain a sorting result;

[0034] The first N layers of networks in the sorting result are used as the networks to be adjusted, where N is a positive integer.

[0035] In a possible implementation of the present application, before taking the top N layers of networks in the sorting result as the networks to be adjusted, the method further includes:

[0036] Obtaining a mixed precision adjustment ratio and a total number of network layers in the initial floating-point model;

[0037] N is determined according to the total number of network layers and the mixed precision adjustment ratio.

[0038] In addition, to achieve the above purpose, the present application also proposes a model quantization device, the device comprising:

[0039] An acquisition module is used to acquire the model output data of the initial floating-point model, and the correlation score corresponding to each output node of the output layer of the initial floating-point model, and to acquire the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample after the network of the layer in the initial floating-point model is quantized separately;

[0040] An evaluation module, used for calculating the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data;

[0041] A selection module, used for selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value;

[0042] A configuration module, used to set the network to be adjusted in the initial floating-point model as a network target quantization configuration, and set other layer networks in the initial floating-point model except the network to be adjusted as a network initial quantization configuration, wherein the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration;

[0043] The quantization module is used to perform model quantization on the initial floating-point model according to the set quantization configuration.

[0044] In addition, to achieve the above-mentioned purpose, the present application also proposes a model quantization device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the model quantization method as described above.

[0045] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the model quantization method as described above are implemented.

[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the model quantization method described above are implemented.

[0047] One or more technical solutions proposed in this application have at least the following technical effects:

[0048] Since some networks are selected as the networks to be adjusted based on the sensitivity evaluation value of the influence of the quantization of the network on the model output, and the networks to be adjusted are set to the quantization configuration with higher quantization accuracy, it is guaranteed that the quantization method can be reasonably adjusted to improve the quantization effect; and when obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model, the constraints of the hardware platform on the operator input / output / weight bits are fully considered, and a configuration that meets the constraints of the hardware platform is generated to perform single-layer quantization on each layer of the network in the initial floating-point model, so as to ensure that the obtained single-layer quantized output data has a strong reference. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0051] Figure 1 A schematic diagram of a flow chart provided for the first embodiment of the model quantization method of the present application;

[0052] Figure 2 A schematic diagram of the process flow provided for the second embodiment of the model quantization method of the present application;

[0053] Figure 3This is a schematic diagram of the functional modules of an embodiment of the present application;

[0054] Figure 4 A schematic diagram of a hardware calculation process of an embodiment of the present application;

[0055] Figure 5 This is a schematic diagram of an application process in the field of intelligent identification according to an embodiment of the present application;

[0056] Figure 6 This is a schematic diagram of an application process in the field of intelligent question answering according to an embodiment of the present application;

[0057] Figure 7 This is a schematic diagram of the module structure of the model quantization device according to an embodiment of the present application;

[0058] Figure 8 Schematic diagram of the device structure of the hardware operating environment involved in the model quantization method in the embodiment of the present application.

[0059] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0060] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0061] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0062] Based on this, the present application embodiment provides a model quantization method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the model quantization method of the present application.

[0063] In this embodiment, the model quantization method includes steps S10 to S50:

[0064] Step S10: Obtain model output data of the initial floating-point model, as well as correlation scores corresponding to output nodes of the output layer of the initial floating-point model, and obtain single-layer quantized output data corresponding to each layer of the network in the initial floating-point model.

[0065] It should be noted that the executor of this embodiment can be the model quantization device, and the model quantization device can be an electronic device such as a personal computer or a server, or other devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the model quantization method of the present invention is described by taking the model quantization device as an example.

[0066] It should be noted that quantization refers to approximating the floating-point values ​​in the model with fixed-point numbers, or approximating them with floating-point values ​​with lower precision. The initial floating-point model may be a model that has not been quantized and uses high-precision data types and bit numbers such as high-bit floating-point numbers (such as BF16, FP32) to represent model parameters (model parameters may include parameters such as input, output, and weights of each layer of the network or each operator). The model output data may be the output data of the initial floating-point model for standard samples, that is, the data output by the initial floating-point model after the standard samples are input and output into the initial floating-point model for analysis.

[0067] The correlation score is used to characterize the contribution of each output node in the output layer to the model output data, that is, the influence of each output node on the model output data. The larger the correlation score of the output node, the greater the contribution of the output node to the model output data, that is, the higher the influence on the model output data.

[0068] The single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample by quantizing the layer of the network in the initial floating-point model separately. For example, the single-layer quantized output data corresponding to the i-th layer of the network in the initial floating-point model can be the output data of the quantized model for the standard sample by quantizing the i-th layer of the network in the initial floating-point model separately, and maintaining other layers of the network in the initial floating-point model to continue to represent the model parameters with high-precision data types and bit numbers. After that, the output data of the single-layer quantized model for the standard sample is used as the single-layer quantized output data corresponding to the i-th layer of the network.

[0069] Step S20: Calculate the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantization output data.

[0070] It should be noted that the sensitivity evaluation value corresponding to the network can be used to characterize the degree of influence of the quantization of the network layer on the output result of the model after the network is quantized.

[0071] In actual use, the correlation score corresponding to each output node can be used as a weight coefficient to weight the model output data and the difference between the partial data corresponding to each output node in the single-layer quantized output data corresponding to the network, so as to obtain the sensitivity evaluation value corresponding to the network.

[0072] In a possible implementation of this embodiment, in order to accurately and quickly obtain the sensitivity evaluation values ​​corresponding to each layer of the network, step S20 in this embodiment may include:

[0073] Traversing each layer of the network in the initial floating-point model to obtain the current network;

[0074] Determine the output difference value corresponding to each output node of the output layer in the initial floating-point model according to the model output data and the single-layer quantized output data corresponding to the current network;

[0075] Determine the difference score corresponding to each output node according to the output difference value and correlation score corresponding to each output node of the output layer in the initial floating point model;

[0076] Add the difference scores corresponding to each output node to obtain a sensitivity evaluation value corresponding to the current network;

[0077] At the end of the traversal, the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model are obtained.

[0078] It should be noted that the output difference value may be the square value of the difference between the model output data and the part corresponding to the output node in the single-layer quantized output data. Of course, other methods may be used for calculation, such as directly using the difference as the output difference value, or using the absolute value of the difference as the output difference value. This embodiment does not limit this. The difference score is the product of the output difference value and the correlation score.

[0079] In this embodiment, the squared difference value is used as the output difference value for explanation. If the output layer of the initial floating-point model includes n output nodes, taking a single standard sample as an example, the model output data can be represented as a vector Y=[y1, y2, ..., yn], where each element in the vector corresponds to an output node; the network quantization output corresponding to the current network can be represented as a vector Y'=[y1', y2', ..., yn'], where each element in the vector corresponds to an output node; the correlation score of each output node can also be represented as a vector S=[s1, s2, ..., sn], where each element in the vector corresponds to an output node, then the output difference value of the i-th output node can be represented as (yi-yi') 2 , the difference score corresponding to the i-th output node is si*(yi-yi') 2 At this time, the sensitivity evaluation value corresponding to the current network is P=s1*(y1-y1') 2 +...+si*(yi-yi') 2 ...+sn*(yn-yn') 2 .

[0080] However, due to the single standard sample, the sensitivity evaluation value obtained may be of weak reference value. Multiple standard samples can also be used. In this case, assuming that there are m standard samples, the sensitivity evaluation value of the current network under the tth standard sample is Pt=s1*(y1-y1') 2 +...+si*(yi-yi') 2...+sn*(yn-yn') 2 , then the overall sensitivity evaluation value of the current network is P all =1 / m∑Pt.

[0081] Step S30: selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value.

[0082] It should be noted that the sensitivity assessment value represents the degree of influence of the quantization of the network layer on the model output result after the user quantizes the representation network. The larger the sensitivity assessment value corresponding to the network, the greater the influence of the representation on the model output result after the network is quantized. The network to be adjusted is a network that will be set to adopt a quantization configuration with a higher quantization accuracy. In order to reduce the impact of model quantization on the model output data, the part of the network with a larger sensitivity assessment value corresponding to each layer of the network can be selected as the network to be adjusted. For example, an evaluation threshold is set in advance, and the part of the network with a corresponding sensitivity assessment value greater than the evaluation threshold in each layer of the initial floating-point model is selected as the network to be adjusted.

[0083] In a possible implementation of this embodiment, since the more networks with higher quantization accuracy are used, the higher the resource requirements of the model obtained after the final quantization, it is necessary to avoid setting too many networks as networks to be adjusted. At this time, step S30 in this embodiment may include:

[0084] Sorting the networks of each layer in the initial floating-point model from large to small according to the corresponding sensitivity evaluation values ​​to obtain a sorting result;

[0085] The first N layers of networks in the sorting result are used as the networks to be adjusted.

[0086] It should be noted that in order to avoid setting too many networks as networks to be adjusted, the administrator of the model quantization equipment can pre-set the number of networks N that are allowed to be selected as networks to be adjusted during the quantization process, where N is a positive integer. At this time, networks with larger sensitivity evaluation values ​​can be prioritized as networks to be adjusted. Therefore, the networks in each layer of the initial floating-point model can be sorted from large to small according to the corresponding sensitivity evaluation values, and then the networks in the first N layers of the sorting result can be selected as networks to be adjusted.

[0087] In a specific implementation, since the number of network layers of different networks is also different, directly setting N may not be applicable to different networks. In order to ensure that it can adapt to various different networks, before the step of using the first N layers of networks in the sorting result as the network to be adjusted in this embodiment, the following may also be included:

[0088] Obtaining a mixed precision adjustment ratio and a total number of network layers in the initial floating-point model;

[0089] N is determined according to the total number of network layers and the mixed precision adjustment ratio.

[0090] It should be noted that the total number of network layers can be the total number of networks in the initial floating-point model, and the mixed precision adjustment ratio can be the ratio of the network allowed to be set as the network to be adjusted in all networks included in the model. The mixed precision adjustment ratio can be set in advance by the manager of the model quantization device.

[0091] In actual use, N can be determined according to the total number of network layers and the mixed precision adjustment ratio by multiplying the total number of network layers by the mixed precision adjustment ratio, and using the product as N. Since the product may not be an integer, after obtaining the product, the product can be rounded up or down, and the rounded value is used as N.

[0092] Step S40: setting the network to be adjusted in the initial floating-point model as a network target quantization configuration, and setting other layer networks in the initial floating-point model except the network to be adjusted as a network initial quantization configuration.

[0093] It should be noted that the network initial quantization configuration may be network configurable, and the corresponding quantization configuration with the lowest quantization accuracy among the quantization configurations supported by the hardware device, wherein the quantization configuration may include a quantization data type and a quantization bit, wherein the quantization data type may be a data type used during quantization, such as an integer INT, or a floating point FP; the quantization bit may be the number of bits used during quantization, such as 8 bits, 16 bits, etc., and the quantization configuration is a combination of the quantization data type and the quantization bit, such as INT8, INT16, FP16, etc.

[0094] The quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration. The specific configuration of the network target quantization configuration can be pre-set by the administrator of the model quantization device, for example: the network target quantization configuration is set to be configurable for the network to be adjusted, and the corresponding quantization configuration with the highest quantization accuracy among the quantization configurations supported by the hardware device; or, the network target quantization configuration is set to be configurable for the network to be adjusted, and the corresponding quantization configuration with a medium quantization accuracy among the quantization configurations supported by the hardware device.

[0095] Step S50: performing model quantization on the initial floating-point model according to the set quantization configuration.

[0096] It can be understood that the quantization configuration after setting includes the quantization configuration corresponding to each layer of the network of the initial floating-point model. At this time, according to the quantization configuration, the input, output and / or weights in the network of each layer of the initial floating-point model can be approximately represented by the quantization data type and quantization bit corresponding to the quantization configuration, thereby completing the quantization of the model.

[0097] It can be understood that in the quantization configuration after setting, the quantization configuration of the network to be adjusted is set to a quantization configuration with higher quantization accuracy, thereby ensuring that the network that has a greater impact on the output data of the model can be quantized using a quantization configuration with higher quantization accuracy through the setting of mixed precision (that is, different layers use different quantization accuracies during the quantization process), thereby ensuring that the quantization loss of the final quantized model is low.

[0098] In a possible implementation of this embodiment, since different quantization configurations are used for different networks for quantization, after quantization, the quantization configurations between adjacent networks are different. The quantization accuracy of the output of the upper network layer and the input of the lower network layer may be inconsistent, resulting in data transmission loss accuracy or even failure to transmit. In order to avoid this phenomenon, this embodiment implements step S50, which may include:

[0099] Obtaining the operator to be adjusted in the initial floating-point model;

[0100] Setting a precision conversion operator between the operator to be adjusted and the network to be adjusted in the initial floating-point model to obtain an adjusted initial floating-point model;

[0101] The adjusted initial floating-point model is quantized according to the set quantization configuration.

[0102] It should be noted that the operator to be adjusted can be an operator in the initial floating-point model that is directly adjacent to the network to be adjusted, and the quantization accuracy corresponding to the input quantization configuration is inconsistent with the quantization accuracy corresponding to the output in the network target quantization configuration, or an operator in the initial floating-point model that is directly adjacent to the network to be adjusted, and the quantization accuracy corresponding to the output quantization configuration is inconsistent with the quantization accuracy corresponding to the input in the network target quantization configuration.

[0103] In actual use, a precision conversion operator can be set between the operator to be adjusted and the network to be adjusted, and a model with the precision conversion operator is set as the adjusted initial floating-point model, wherein the precision conversion operator is used to adjust the input of the operator to be adjusted so that its precision is consistent with the precision of the output of the network to be adjusted, or to adjust the output of the operator to be adjusted so that its precision is consistent with the precision of the input of the network to be adjusted.

[0104] For example, operator A is adjacent to the network to be adjusted and connected to the input layer of the network to be adjusted. The quantization configuration of operator A output is INT8, while the quantization configuration input in the network target quantization configuration of the network to be adjusted is FP16. At this time, the quantization accuracy corresponding to the quantization configuration of operator A is inconsistent with the quantization accuracy corresponding to the network target quantization configuration. In this case, operator A can be used as the operator to be adjusted, and a precision conversion operator can be set after the operator to be adjusted and before the network to be adjusted. Through this precision conversion operator, the INT8 precision data output by operator A is converted into FP16 precision data to ensure that it can be normally transmitted to the network to be adjusted.

[0105] This embodiment provides a model quantization method. Since part of the network is selected as the network to be adjusted according to the sensitivity evaluation value that can characterize the degree of influence of the quantization of the network on the model output, and the network to be adjusted is set to a quantization configuration with higher quantization accuracy, it is ensured that the quantization method can be reasonably adjusted and the quantization effect is improved.

[0106] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 Before step S10, the model quantization method further includes steps S01 to S04:

[0107] Step S01: obtaining quantization constraint rules corresponding to each operator in the initial floating-point model.

[0108] It should be noted that the quantization constraint rules corresponding to the operator include optional data types, bit relationship descriptions and / or type relationship descriptions.

[0109] Among them, the optional data type is used to represent the quantization configuration that can be set for the input, output or weight of the operator. The quantization configuration includes the quantization data type and quantization bit. For example, the optional data types of the input, output and weight (weight parameter in the operator) of the conv operator are INT8 and FP16.

[0110] The bit relationship description is used to characterize the correlation between the quantization bits of the input, output and / or weight in the operator. For example, the quantization bits of the input, output and weight of the conv operator need to be consistent, or the quantization bits of the input and output of the conv operator need to be consistent.

[0111] The type relationship description is used to characterize the association between the quantized data types of the input, output and / or weights in an operator. For example, the quantized data types of the input, output and weights of the conv operator need to be consistent.

[0112] In actual use, the quantization constraint rules corresponding to each operator can be obtained according to the type of each operator in the initial floating-point model. For example, the manager of the model quantization equipment can pre-set the constraint rule library to store the quantization constraint rules of each type of operator. When necessary, the quantization constraint rules corresponding to each operator can be obtained by searching in the constraint rule library according to the type of each operator in the initial floating-point model.

[0113] Step S02: determining the initial quantization configuration corresponding to each operator according to the quantization constraint rule.

[0114] It should be noted that the initial quantization configuration may be the quantization configuration with the lowest quantization accuracy among the quantization configurations that can be set for each operator, and the initial quantization configuration may include the quantization configurations of the operator's input, output, and weight.

[0115] Step S03: Obtain the corresponding relationship between each layer network and the operator in the initial floating-point model.

[0116] It should be noted that there is a corresponding relationship between operators and networks. At least one operator is connected through a topological relationship and combined into a layer of network, that is, a layer of network can include at least one operator.

[0117] In actual use, the correspondence between each layer of the network and the operator can be stored in the model structure file. Therefore, obtaining the correspondence between each layer of the network and the operator in the initial floating-point model can be done by extracting the correspondence between each layer of the network and the operator from the model structure file corresponding to the initial floating-point model.

[0118] Step S04: constructing the network initial quantization configuration of each layer of the network in the initial floating-point model according to the corresponding relationship and the initial quantization configuration corresponding to each operator.

[0119] It should be noted that, according to the correspondence between each layer of the network and the operator, the initial quantization configuration of at least one operator corresponding to the same network can be aggregated to obtain the network initial quantization configuration of each layer of the network in the initial floating-point model.

[0120] In this embodiment, the step S10 includes:

[0121] Step S10': obtaining the model output data of the initial floating point model and the correlation scores corresponding to the output nodes of the output layer of the initial floating point model, and obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating point model based on the network initial quantization configuration.

[0122] It should be noted that after determining the network initial quantization configuration corresponding to each layer of the network in each initial floating-point model, the network layer can be quantized separately according to the network initial quantization configuration corresponding to each layer of the network, and the standard sample can be input into the model obtained by the separate quantization to obtain the single-layer quantization output data corresponding to each layer of the network.

[0123] In a possible implementation of this embodiment, since the model needs to be deployed in a specific device after quantization, it is also necessary to consider whether the quantized model can run normally in the device during quantization. At this time, the step of obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model based on the initial quantization configuration of the network in this embodiment may include:

[0124] Obtain the hardware constraints of the model deployment platform;

[0125] Adjusting the initial quantization configuration corresponding to each operator according to the hardware constraint rule to obtain the adjusted quantization configuration corresponding to each operator;

[0126] The network initial quantization configuration of each layer of the network in the initial floating-point model is constructed according to the corresponding relationship and the adjusted quantization configuration corresponding to each operator.

[0127] It should be noted that the model deployment platform can be the device used to deploy the quantized model. For example, after the initial floating-point model is quantized, the quantized model needs to be deployed in the edge device for operation. In this case, the edge device is the model deployment platform. Hardware constraint rules are used to characterize the quantization configuration used by the hardware support operator. For example, in some model deployment platforms, the hardware constraint rule softmax operator only supports 16 bits, such as INT16, FP16, etc.

[0128] In actual use, the initial quantization configuration corresponding to each operator is adjusted according to the hardware constraint rules. The adjusted quantization configuration corresponding to each operator can be obtained by modifying the quantization configuration corresponding to each operator that does not comply with the hardware constraint rules to a quantization configuration that complies with the hardware constraint rules and has the lowest quantization accuracy.

[0129] For example: assuming that in the initial quantization configuration corresponding to each operator, the quantization configuration for the softmax operator is INT8, but the hardware constraint rule is that the softmax operator only supports 16 bits. In the initial quantization configuration corresponding to the operator, the quantization configuration of the softmax operator does not comply with the hardware constraint rule and needs to be modified. According to the hardware constraint rule, the available quantization configurations include INT8, FP16, BF16, etc., among which INT8 has the lowest quantization accuracy. In this case, the quantization configuration for the softmax operator in the initial quantization configuration corresponding to each operator can be modified to INT16, and the modified initial quantization configuration corresponding to each operator can be used as the adjusted quantization configuration corresponding to each operator.

[0130] In actual use, after obtaining the adjustment quantization configuration corresponding to each operator, the adjustment quantization configuration corresponding to at least one operator of the same network can be aggregated according to the correspondence between each layer of the network and the operator, so as to obtain the network initial quantization configuration of each layer of the network in the initial floating-point model.

[0131] For ease of understanding, now combined Figure 3 , 4 , 5 and 6 are used to illustrate, but not to limit this solution. Figure 3 This is a schematic diagram of the functional modules of the model quantization device in this embodiment. Figure 4 This is a schematic diagram of the hardware calculation process of the model quantization device in this embodiment. Figure 5 This is a schematic diagram of the application process of the model quantization method of this embodiment in the field of intelligent recognition. Figure 6 The figure is a schematic diagram of the application process of the model quantization method of this embodiment in the field of intelligent question answering.

[0132] The model quantization device can be divided into multiple functional modules, and the above model quantization method is executed collaboratively by multiple functional modules, such as Figure 3 As shown, the divided functional modules may include: a hardware mixed precision rule registration module, a quantization sensitivity statistics module for each layer, a model bit initialization module, and a mixed precision configuration module;

[0133] The functions of each functional module are as follows:

[0134] The hardware mixed precision rule registration module registers the hardware platform's constraints on the input / output / weight bits of each operator into operator rules in a unified format. The unified format of the input / output / weight rules of each operator is described in three parts: optional data type, bit relationship, and type relationship. Among them, the optional data type describes the data type that can be selected for the operator input / output / weight. For example, on the GPU hardware platform, the optional data types of the input / output / weight of the conv operator are both INT8 and FP16. The bit relationship describes the quantization bit correlation of the operator input / output / weight. For example, on the GPU hardware platform, the quantization bits of the input / output / weight of the conv operator need to be consistent. When the input quantization bits are configured to 16, the quantization bits of the output and weights also need to be modified to 16. The type relationship describes the quantization data type correlation of the operator input / output / weight. For example, on the GPU hardware platform, the quantization data type of the input / output / weight of the conv operator needs to be consistent. When the input quantization data type is configured to FP, the quantization data type of the output and weight also needs to be modified to FP.

[0135] The model bit initialization module sets the quantization configuration of the operators in the model to the full low-bit state (i.e., the initial quantization configuration. If the optional quantization bits are 8 bits / 16 bits, the model is initially quantized to full 8 bits). Based on this, the module adjusts the places that do not meet the rules according to the hardware platform's input / output / weight bit constraints on each operator. For example, if the softmax operator on some hardware platforms only supports 16 bits, the input / output quantization bits of the softmax operator need to be modified to 16 bits. After that, according to the correspondence between the operator and the network, the network initial quantization configuration of each network is constructed according to the quantization configuration of each operator.

[0136] The quantization sensitivity statistics module of each layer is used to calculate the quantization sensitivity of each layer and obtain the quantization sensitivity evaluation value (i.e., sensitivity evaluation value) of each layer. The larger the evaluation value, the higher the quantization sensitivity of the layer. When calculating the quantization sensitivity of each layer, the quantization sensitivity statistics module uses the network initialization configuration set by the model bit initialization module for each network when quantizing each layer of the network separately.

[0137] In the mixed precision configuration module, the user specifies N, and the first N layers in the quantization sensitivity sorting are used as the network to be adjusted, and the operators in the network to be adjusted are quantized and adjusted in sequence. The operator to be adjusted is found, and a precision conversion node is inserted between the operator to be adjusted and the network to be adjusted to convert the input / output of adjacent operators.

[0138] In this process, the computational interaction between the hardware in the model quantization device is as follows: Figure 4As shown, the designed hardware includes a main CPU, an external memory, a neural network processor 200, etc., wherein the neural network processor 200 may include: an input memory 2001, a weight memory 2002, an operation circuit 2003, a controller 2004, a storage unit access controller 2005, a common memory 2006, a vector calculation unit 2007, an accumulator 2008, a data memory 2009 and a bus interface unit 2010, etc.

[0139] The model quantification method of this embodiment can be applied to the field of intelligent recognition, such as the intelligent recognition system in the kitchen, to detect whether the chef's movements are standardized, whether he is wearing a chef's hat, whether the trash can is overflowing, and whether there are animals such as cockroaches and mice. The application process can be as follows: Figure 5 As shown, the user can customize the detection requirements (prompt) and transmit it together with the real-time scene image. At this time, the model quantization device can serialize and stitch the transmitted customized detection requirements and real-time scene images. After that, as input, it is input mixed precision quantization (i.e., input mixed precision quantization), input it into the quantized model, perform inference calculation, and finally output the result. Among them, the model used for inference calculation is a quantized model obtained after mixed precision quantization of the large model weights (i.e., the model weights represented by high-precision data types such as floating points).

[0140] At the same time, the model quantification method of this embodiment can also be applied to other fields, such as the field of intelligent question answering (such as customer dialogue intelligent question answering, etc.), and its application process can be as follows: Figure 6 As shown, the user input can be obtained and the user tokenized data can be transmitted together. At this time, the model quantization device can take the transmitted user input and tokenized data as input, and after input mixed precision quantization (i.e., input mixed precision quantization), input and output them into the quantized model, perform inference calculations, and finally output the results. Among them, the model used for inference calculations is a quantized model obtained after mixed precision quantization processing of large model weights (i.e., model weights represented by high-precision data types such as floating points).

[0141] Of course, the model quantization method of this embodiment can also be applied to more fields, and this embodiment does not limit this.

[0142] This embodiment provides a model quantization method. Since the initial quantization configuration of each layer of the network in the initial floating-point model is constructed according to the operator constraint rules and the hardware constraint rules of the model deployment platform, and the single-layer quantization output data corresponding to each layer of the network in the initial floating-point model is obtained according to the initial network quantization configuration, it is ensured that under the condition of satisfying the hardware platform constraints, within the optional range, the single-layer quantization output data corresponding to each layer of the network under the condition of minimum quantization accuracy is obtained as much as possible, so as to facilitate subsequent analysis and selection.

[0143] This application also provides a model quantization device, please refer to Figure 7 , the model quantization device comprises:

[0144] The acquisition module 10 is used to obtain the model output data of the initial floating-point model, and the correlation score corresponding to each output node of the output layer of the initial floating-point model, and obtain the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample after the network of the layer in the initial floating-point model is quantized separately;

[0145] An evaluation module 20, configured to calculate the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data;

[0146] A selection module 30, configured to select a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value;

[0147] A configuration module 40 is used to set the network to be adjusted in the initial floating-point model as a network target quantization configuration, and to set other layer networks in the initial floating-point model except the network to be adjusted as a network initial quantization configuration, wherein the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration;

[0148] The quantization module 50 is used to perform model quantization on the initial floating-point model according to the set quantization configuration.

[0149] The model quantization device provided by the present application adopts the model quantization method in the above embodiment, which can solve the technical problem that the related technology directly uses the single-layer quantization error as the basis to adjust the quantization method of the model, and the effect is difficult to guarantee. Compared with the prior art, the beneficial effects of the model quantization device provided by the present application are the same as the beneficial effects of the model quantization method provided by the above embodiment, and the other technical features in the model quantization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0150] The present application provides a model quantization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the model quantization method in the above-mentioned embodiment 1.

[0151] Reference below Figure 8 , which shows a schematic diagram of the structure of a model quantization device suitable for implementing the embodiment of the present application. The model quantization device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The model quantization device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0152] like Figure 8 As shown, the model quantization device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the model quantization device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the model quantization device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a model quantization device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0153] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0154] The model quantization device provided by the present application adopts the model quantization method in the above embodiment, which can solve the technical problem that the related technology directly uses the single-layer quantization error as the basis to adjust the quantization method of the model, and the effect is difficult to guarantee. Compared with the prior art, the beneficial effects of the model quantization device provided by the present application are the same as the beneficial effects of the model quantization method provided by the above embodiment, and the other technical features in the model quantization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0155] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0156] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0157] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the model quantization method in the above-mentioned embodiment.

[0158] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0159] The computer-readable storage medium may be included in the model quantization device; or may exist independently without being assembled into the model quantization device.

[0160] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the model quantization device, the model quantization device:

[0161] Obtain the model output data of the initial floating-point model and the correlation score corresponding to each output node of the output layer of the initial floating-point model, and obtain the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the model for the standard sample after the network of the layer in the initial floating-point model is quantized separately; the sensitivity evaluation value corresponding to each layer of the network in the initial floating-point model is calculated according to the model output data, the correlation score and the single-layer quantized output data; the network to be adjusted is selected from each layer of the network in the initial floating-point model according to the sensitivity evaluation value; the network to be adjusted in the initial floating-point model is set as the network target quantization configuration, and the other layer networks in the initial floating-point model except the network to be adjusted are set as the network initial quantization configuration, and the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration; the initial floating-point model is model quantized according to the set quantization configuration.

[0162] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0163] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0164] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0165] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned model quantization method, and can solve the technical problem that the related technology directly uses a single-layer quantization error as the basis to adjust the quantization method of the model, and the effect is difficult to guarantee. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the model quantization method provided by the above-mentioned embodiment, and will not be repeated here.

[0166] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned model quantization method when executed by a processor.

[0167] The computer program product provided by the present application can solve the technical problem that the related art directly uses the single-layer quantization error as the basis to adjust the quantization method of the model, and the effect is difficult to guarantee. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the model quantization method provided by the above embodiment, and will not be repeated here.

[0168] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A model quantization method, characterized in that: The model quantization method comprises: Obtain the model output data of the initial floating-point model, as well as the correlation scores corresponding to the output nodes of the output layer of the initial floating-point model, and obtain the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample after the network of the layer in the initial floating-point model is quantized separately; Calculate the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data; Selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value; The network to be adjusted in the initial floating-point model is set as a network target quantization configuration, and other layer networks in the initial floating-point model except the network to be adjusted are set as network initial quantization configurations, wherein the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration; the network initial quantization configuration is a quantization configuration with the lowest quantization accuracy among the quantization configurations that are configurable by the network and supported by the hardware device; Performing model quantization on the initial floating-point model according to the set quantization configuration; The step of calculating the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data includes: Traversing each layer of the network in the initial floating-point model to obtain the current network; Determine the output difference value corresponding to each output node of the output layer in the initial floating-point model according to the model output data and the single-layer quantized output data corresponding to the current network, wherein the output difference value is the square value of the difference between the model output data and the part corresponding to the output node in the single-layer quantized output data; Determine the difference score corresponding to each output node according to the output difference value and the correlation score corresponding to each output node of the output layer in the initial floating point model, wherein the difference score is the product of the output difference value and the correlation score; Add the difference scores corresponding to each output node to obtain a sensitivity evaluation value corresponding to the current network; At the end of the traversal, the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model are obtained.

2. The model quantization method according to claim 1, characterized in that: Before obtaining the model output data of the initial floating-point model, the correlation scores corresponding to the output nodes of the output layer of the initial floating-point model, and obtaining the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model, the method further includes: Obtaining quantization constraint rules corresponding to each operator in the initial floating-point model, the quantization constraint rules including optional data types, bit relationship descriptions and / or type relationship descriptions; the optional data types are used to characterize the quantization configurations that can be set for the input, output or weight of the operator, and the quantization configurations include quantization data types and quantization bits; the bit relationship descriptions are used to characterize the association between quantization bits among inputs, outputs and / or weights in the operator; the type relationship descriptions are used to characterize the association between quantization data types among inputs, outputs and / or weights in the operator; Determine an initial quantization configuration corresponding to each operator according to the quantization constraint rule, wherein the initial quantization configuration is a quantization configuration corresponding to the lowest quantization accuracy among the quantization configurations that can be set for each operator; Obtaining the corresponding relationship between each layer network and the operator in the initial floating-point model; Constructing the network initial quantization configuration of each layer of the network in the initial floating-point model according to the corresponding relationship and the initial quantization configuration corresponding to each operator; The obtaining of single-layer quantized output data corresponding to each layer of the network in the initial floating-point model includes: Based on the network initial quantization configuration, single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is obtained.

3. The model quantization method according to claim 2, characterized in that: The constructing the network initial quantization configuration of each layer network in the initial floating-point model according to the corresponding relationship and the initial quantization configuration corresponding to each operator includes: Obtaining hardware constraint rules of the model deployment platform, where the hardware constraint rules are used to characterize the quantitative configuration used by the hardware support operator; Adjusting the initial quantization configuration corresponding to each operator according to the hardware constraint rule to obtain the adjusted quantization configuration corresponding to each operator; The network initial quantization configuration of each layer of the network in the initial floating-point model is constructed according to the corresponding relationship and the adjusted quantization configuration corresponding to each operator.

4. The model quantization method according to claim 1, characterized in that: The performing model quantization on the initial floating-point model according to the set quantization configuration includes: Obtaining an operator to be adjusted in the initial floating-point model, wherein the operator to be adjusted is an operator in the initial floating-point model that is directly adjacent to the network to be adjusted and whose quantization accuracy corresponding to the input quantization configuration is inconsistent with the quantization accuracy corresponding to the output in the network target quantization configuration, or an operator in the initial floating-point model that is directly adjacent to the network to be adjusted and whose quantization accuracy corresponding to the output quantization configuration is inconsistent with the quantization accuracy corresponding to the input in the network target quantization configuration; Setting a precision conversion operator between the operator to be adjusted and the network to be adjusted in the initial floating-point model to obtain an adjusted initial floating-point model; The adjusted initial floating-point model is quantized according to the set quantization configuration.

5. The model quantization method according to any one of claims 1 to 4, characterized in that: The step of selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value comprises: Sorting the networks of each layer in the initial floating-point model from large to small according to the corresponding sensitivity evaluation values ​​to obtain a sorting result; The first N layers of networks in the sorting result are used as the networks to be adjusted, where N is a positive integer.

6. The model quantization method according to claim 5, characterized in that: Before taking the top N layers of networks in the sorting result as the networks to be adjusted, the method further includes: Obtaining a mixed precision adjustment ratio and a total number of network layers in the initial floating-point model; N is determined according to the total number of network layers and the mixed precision adjustment ratio.

7. A model quantization device, characterized in that: The device comprises: An acquisition module is used to acquire the model output data of the initial floating-point model, and the correlation score corresponding to each output node of the output layer of the initial floating-point model, and to acquire the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model; the model output data is the output data of the initial floating-point model for the standard sample; the correlation score is used to characterize the contribution of each output node in the output layer to the model output data; the single-layer quantized output data corresponding to each layer of the network in the initial floating-point model is the output data of the quantized model for the standard sample after the network of the layer in the initial floating-point model is quantized separately; An evaluation module, used for calculating the sensitivity evaluation values ​​corresponding to each layer of the network in the initial floating-point model according to the model output data, the correlation score and the single-layer quantized output data; A selection module, used for selecting a network to be adjusted from each layer of the network in the initial floating-point model according to the sensitivity evaluation value; A configuration module, used to set the network to be adjusted in the initial floating-point model as a network target quantization configuration, and set other layer networks in the initial floating-point model except the network to be adjusted as a network initial quantization configuration, wherein the quantization accuracy of the network target quantization configuration is greater than the quantization accuracy of the network initial quantization configuration; the network initial quantization configuration is a quantization configuration with the lowest quantization accuracy among the quantization configurations that are configurable by the network and supported by the hardware device; A quantization module, used for performing model quantization on the initial floating-point model according to the set quantization configuration; The evaluation module is also used to traverse each layer of the network in the initial floating-point model to obtain the current network; determine the output difference value corresponding to each output node of the output layer in the initial floating-point model according to the model output data and the single-layer quantized output data corresponding to the current network, and the output difference value is the square value of the difference between the model output data and the part corresponding to the output node in the single-layer quantized output data; determine the difference score corresponding to each output node according to the output difference value and the correlation score corresponding to each output node of the output layer in the initial floating-point model, and the difference score is the product of the output difference value and the correlation score; add the difference score corresponding to each output node to obtain the sensitivity evaluation value corresponding to the current network; at the end of the traversal, obtain the sensitivity evaluation value corresponding to each layer of the network in the initial floating-point model.

8. A model quantization device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the model quantization method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the model quantization method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the model quantization method according to any one of claims 1 to 6 are implemented.