Computer implementation method, device and equipment for quantifying neural network model

By adaptively optimizing the quantization precision type of the operator, the problem of high cost and low versatility of manual adjustment in the existing technology is solved, realizing efficient quantization of neural network models and ensuring a balance between accuracy and performance of the model after quantization.

CN121809558APending Publication Date: 2026-04-07HORIZON JOURNEY (SHANGHAI) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, manually adjusting the quantization precision of operators is costly and has low versatility, failing to effectively balance the accuracy and performance requirements of the model.

Method used

By determining the neural network model to be quantized and the training dataset, and combining the quantization precision type supported by the neural network accelerator, the quantization sensitivity of the operator is determined. Based on this, the quantization precision type of the operator is adjusted, and the quantization parameters and network parameters are optimized to achieve adaptive optimization.

Benefits of technology

It reduces the manual cost of model quantization, improves the accuracy and effectiveness of operator quantization precision types, is applicable to quantization scenarios of any neural network model, and ensures the accuracy and performance of the model under the quantization precision type.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121809558A_ABST
    Figure CN121809558A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a computer implementation method, a computer implementation device and computer implementation equipment for quantifying a neural network model. The method comprises the following steps: determining a first calibration model based on a first neural network model, a training data set, and a first quantization precision type and a second quantization precision type supported by a neural network accelerator used for executing the first neural network model, determining the quantization sensitivity of an operator in the first calibration model based on the training data set, and determining the quantization precision of the operator in the second calibration model based on the quantization sensitivity. Adjusting a quantization precision type of an operator in the first calibration model to obtain a second calibration model, adjusting quantization parameters and network parameters of the second calibration model based on the training data set to obtain a second neural network model, and determining a quantization model of the first neural network model based on the second neural network model, therefore, the accuracy and effectiveness of the quantization precision type of the operator can be improved, the model quantization cost is reduced, and the universality is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to model quantization techniques, and in particular to a computer implementation method, apparatus, and device for quantizing neural network models. Background Technology

[0002] In deep learning, Quantization-Aware Training (QAT) is used to quantize the model's weights and activations from high-precision types to low-precision types to reduce computational and storage costs. However, QAT inevitably introduces errors during the process, affecting the model's accuracy across various tasks.

[0003] In related technologies, the quantization precision type of some operators is usually adjusted manually based on experience to balance the accuracy and performance requirements of the model through a quantization model with mixed precision types. However, manually adjusting the quantization precision type of operators is costly and has low versatility. Summary of the Invention

[0004] Embodiments of this disclosure provide a computer implementation method, apparatus, and device for quantizing neural network models to reduce quantization costs and improve versatility.

[0005] A first aspect of this disclosure provides a computer implementation method for quantizing a neural network model, comprising: determining a first neural network model to be quantized and a training dataset; determining a first calibration model based on the first neural network model, the training dataset, a first quantization precision type supported by a neural network accelerator for executing the first neural network model, and a second quantization precision type; determining the quantization sensitivity of operators in the first calibration model based on the training dataset; adjusting the quantization precision type of operators in the first calibration model based on the quantization sensitivity to obtain a second calibration model; adjusting the quantization parameters and network parameters of the second calibration model based on the training dataset to obtain a second neural network model; and determining a quantization model of the first neural network model based on the second neural network model.

[0006] A second aspect of this disclosure provides a computer implementation apparatus for quantizing a neural network model, comprising: at least one processor; the at least one processor being configured to: determine a first neural network model to be quantized and a training dataset; determine a first calibration model based on the first neural network model, the training dataset, a first quantization precision type supported by a neural network accelerator for executing the first neural network model, and a second quantization precision type; determine the quantization sensitivity of operators in the first calibration model based on the training dataset; adjust the quantization precision type of operators in the first calibration model based on the quantization sensitivity to obtain a second calibration model; adjust the quantization parameters and network parameters of the second calibration model based on the training dataset to obtain a second neural network model; and determine the quantization model of the first neural network model based on the second neural network model.

[0007] A third aspect of this disclosure is to provide a computer-readable storage medium storing a computer program that is executed by a processor to perform a computer implementation method for quantizing a neural network model as described in any of the foregoing embodiments of this disclosure.

[0008] A fourth aspect of this disclosure provides an electronic device, the electronic device comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory, the processor executing the executable instructions to implement the computer implementation method for quantizing a neural network model as described in any of the above embodiments of this disclosure.

[0009] A fifth aspect of this disclosure provides a computer program product that, when instructions in the computer program product are executed by a processor, performs a computer implementation method for quantizing a neural network model provided in any of the above embodiments of this disclosure.

[0010] Based on the computer implementation method, apparatus, and device for quantizing neural network models provided in the above embodiments of this disclosure, when quantization of a first neural network model is required, a first calibration model can be determined based on the first neural network model, a training dataset, a first quantization precision type supported by a neural network accelerator for executing the first neural network model, and a second quantization precision type. Then, based on the training dataset, the quantization sensitivity of operators in the first calibration model is determined. Based on the quantization sensitivity, the quantization precision type of operators in the first calibration model is adjusted to obtain a second calibration model. Based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain a second neural network model. Based on the second neural network model, the quantization model of the first neural network model is determined. Thus, by combining different quantization precision types supported by the neural network accelerator, a superior first calibration model is determined. Furthermore, adaptive optimization of the quantization precision type of operators is achieved based on the quantization sensitivity of the operators, improving the accuracy and effectiveness of the quantization precision type of the operators, avoiding manual setting of the quantization precision type of operators based on experience, and helping to reduce the manual cost of model quantization. After optimizing the quantization precision type of the operators, the quantization parameters and network parameters are adjusted to ensure the model accuracy and performance under the specified quantization precision type. Furthermore, the optimization process for quantization accuracy is based on the quantization sensitivity of the operator, which can be applied to quantization scenarios of any neural network model and has high versatility. Attached Figure Description

[0011] Figure 1 This is an exemplary application scenario of the computer implementation method for quantizing neural network models provided in this disclosure;

[0012] Figure 2 This is a flowchart illustrating a computer implementation method for quantizing a neural network model provided in an exemplary embodiment of this disclosure;

[0013] Figure 3 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in another exemplary embodiment of this disclosure.

[0014] Figure 4 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in yet another exemplary embodiment of this disclosure.

[0015] Figure 5 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in yet another exemplary embodiment of this disclosure.

[0016] Figure 6 This is a flowchart of a computer implementation method for quantizing a neural network model provided in an exemplary embodiment of this disclosure;

[0017] Figure 7 This is a schematic diagram of the structure of a computer implementation apparatus for quantizing a neural network model provided in an exemplary embodiment of the present disclosure;

[0018] Figure 8 This is a structural diagram of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0019] To explain this disclosure, exemplary embodiments of the disclosure will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the disclosure, and not all of them. It should be understood that the disclosure is not limited to exemplary embodiments.

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

[0021] This disclosure outlines

[0022] In developing this disclosure, the inventors discovered that Quantization-Aware Training (QAT) in deep learning is used to quantize the model's weights and activation values ​​from high-precision types to low-precision types, thereby reducing computational and storage costs. During QAT, errors are inevitably introduced, affecting the model's accuracy on various tasks. A task refers to the function the model can perform; tasks may include classification tasks, regression tasks, etc., or tasks may be further subdivided into object detection tasks, semantic segmentation tasks, speech recognition tasks, etc., and the specific task can be determined based on the model's actual situation.

[0023] In related technologies, the quantization precision type of some operators is usually adjusted manually based on experience. For example, the quantization precision type of specific operators in the model is set to a higher precision type (e.g., INT16), while the quantization precision type of other operators is set to a lower precision type (e.g., INT4). This is done to balance the accuracy and performance requirements of the model through a mixed-precision quantization model. However, manually adjusting the quantization precision type of operators is costly, has low accuracy and versatility, and cannot be transferred to different models.

[0024] Exemplary Overview

[0025] Figure 1 This is an exemplary application scenario of the computer implementation method for quantizing neural network models provided in this disclosure. For example... Figure 1As shown, the neural network model 11 can be any neural network model. For example, the neural network model 11 can include one or more models such as object detection model, semantic segmentation model, speech recognition model, and classification model, or the neural network model 11 can be a multi-task model. The network structure of the neural network model 11 can be, for example, a convolutional neural network, a recurrent neural network, a Transformer neural network, etc., and is not specifically limited. The neural network model 11 can include multiple operators 111, each of which can be used to perform operations for a specific function, such as multiplication, addition, multiplication-addition, convolution, etc. The neural network model 11 can be a trained model. When quantizing the neural network model 11, the computer implementation device 12 for quantizing neural network models of this disclosure embodiment can be used to execute the computer implementation method for quantizing neural network models of this disclosure embodiment to quantize the neural network model 11 and obtain the quantized model corresponding to the neural network model 11. Then, the quantized model is deployed to the terminal device 13. The terminal device 13 can be an in-vehicle terminal, a mobile phone, a tablet, etc.

[0026] Specifically, neural network model 11 can be identified as the first neural network model to be quantized. Based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model, a first calibration model can be determined. Then, based on the training dataset, the quantization sensitivity of the operators in the first calibration model is determined. Based on the quantization sensitivity, the quantization precision type of the operators in the first calibration model is adjusted to obtain a second calibration model. Based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain a second neural network model. Based on the second neural network model, the quantization model of the first neural network model is determined. Thus, by combining the different quantization precision types supported by the neural network accelerator, a superior first calibration model is determined. Furthermore, based on the quantization sensitivity of the operators, adaptive optimization of the quantization precision type of the operators is achieved, improving the accuracy and effectiveness of the quantization precision type of the operators. This avoids manually setting the quantization precision type of the operators based on experience, helping to reduce the manual cost of model quantization. After optimizing the quantization precision type of the operators, the quantization parameters and network parameters are adjusted to ensure the model accuracy and performance under the specified quantization precision type. Furthermore, the optimization process for quantization accuracy is based on the quantization sensitivity of the operator, which can be applied to quantization scenarios of any neural network model and has high versatility.

[0027] Exemplary methods

[0028] Figure 2This is a flowchart illustrating a computer implementation method for quantizing a neural network model provided in an exemplary embodiment of this disclosure. The computer implementation method for quantizing a neural network model provided in this embodiment can be applied to electronic devices, including but not limited to servers and terminal devices. The computer implementation method for quantizing a neural network model provided in this embodiment can also be applied to the computer implementation apparatus for quantizing a neural network model provided in this embodiment. Figure 2 As shown, the computer implementation method for quantizing a neural network model according to embodiments of this disclosure may include the following steps:

[0029] Step 210: Determine the first neural network model to be quantized and the training dataset.

[0030] The first neural network model (or original model) can be any neural network model, see neural network model 11 above. The first neural network model is a pre-trained, high-precision neural network model. For example, the first neural network model is a floating-point model. The training dataset is a pre-obtained dataset used for quantization-aware training of the first neural network model. The training dataset may include multiple training samples and their corresponding label data. Optionally, the training dataset may be a subset of data extracted from the training set and / or validation set corresponding to the first neural network model.

[0031] Step 220: Determine the first calibration model based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model.

[0032] The first quantization precision type can be the highest quantization precision type supported by the neural network accelerator, and the second quantization precision type can be the lowest quantization precision type supported by the neural network accelerator. A neural network accelerator is a hardware unit capable of accelerating the computational tasks corresponding to operators in a neural network model. Neural network accelerators include, but are not limited to, graphics processing units (GPUs) and neural network processing units (NPUs). Neural network accelerators can support multiple quantization precision types. Based on the quantization precision types supported by the neural network accelerator, the highest quantization precision type is determined as the first quantization precision type, and the lowest quantization precision type is determined as the second quantization precision type. For example, if the neural network accelerator supports quantization precision types including INT16, INT8, and INT4, then the first quantization precision type is INT16, and the second quantization precision type is INT4.

[0033] The first calibration model is a model that inserts pseudo-quantization nodes into the first neural network model and determines the calibration method to be used. Optionally, the first calibration model can be determined through calibration parameter tuning, and the optimal calibration method for the pseudo-quantization nodes can be determined from multiple calibration methods.

[0034] Calibration methods may include KL (Kullback-Leibler) calibration, MAX (maximum absolute value) calibration, Percentile calibration, etc.

[0035] KL calibration, also known as KL divergence calibration, calculates the KL divergence (i.e., information loss) of the activation value distribution before and after quantization. It then finds the range of values ​​(i.e., the quantization interval or range) that minimizes the quantization error. By dynamically adjusting the quantization interval, the quantized distribution is made as close as possible to the original floating-point data distribution. The boundary values ​​(or upper and lower limits) of the final adjusted quantization interval are the calibration thresholds.

[0036] MAX calibration directly takes the maximum absolute value MAX of the activation values ​​in the calibration data as the upper limit of the quantization range. For symmetric quantization, the lower limit of the quantization range can be symmetrically set to -MAX. For asymmetric quantization, the minimum value can be calculated separately as the lower limit.

[0037] Percentile calibration determines the quantization range based on the percentile value (such as 99% or other values) of the activation values ​​in the calibration data, and then determines the calibration threshold to eliminate the influence of extreme outliers.

[0038] Optionally, the calibration method corresponding to any pseudo-quantization node can be one of the aforementioned calibration methods. The calibration methods corresponding to any two pseudo-quantization nodes can be the same or different.

[0039] In some optional embodiments, the first calibration model may be a calibration model determined using a first quantization precision type and a second quantization precision type. First, a set of calibration methods and training parameters are determined based on the first quantization precision type. Then, based on the calibration methods and training parameters determined based on the first quantization precision type, the training parameters are reused, and the calibration methods are further optimized based on the second quantization precision type to obtain the first calibration model. Training parameters may include, but are not limited to, the learning rate and the number of iterations (step).

[0040] Step 230: Based on the training dataset, determine the quantization sensitivity of the operators in the first calibration model.

[0041] The quantization sensitivity of an operator refers to the degree of impact of quantization on the model's computational accuracy when the operator is quantized alone in the first calibration model. The quantization sensitivity of different operators indicates the degree of deviation of the output data of different layers from the output data of the floating-point model after quantization.

[0042] Optionally, the quantization sensitivity of an operator can be determined based on the quantization error of one or more training samples when quantizing the operator individually. The larger the quantization error, the higher the quantization sensitivity.

[0043] Step 240: Based on the quantization sensitivity, adjust the quantization precision type of the operator in the first calibration model to obtain the second calibration model.

[0044] Quantization sensitivity characterizes the degree to which operator quantization affects the computational accuracy of the model. A higher quantization sensitivity indicates a greater impact of quantization on computational accuracy. To ensure model accuracy, the quantization accuracy type of operators with higher quantization sensitivity can be adjusted to a higher quantization accuracy type. Based on this, the quantization accuracy type of operators in the first calibration model is adjusted according to quantization sensitivity to obtain the second calibration model. Optionally, the quantization accuracy type of the top K operators with higher quantization sensitivity, or a preset proportion of operators, can be adjusted from the current quantization accuracy type to a higher quantization accuracy type to obtain the second calibration model. For example, if the current quantization accuracy type of all operators in the first calibration model is the second quantization accuracy type (e.g., INT4), and the quantization accuracy type of half of the operators with higher quantization sensitivity is increased to INT8 according to the quantization sensitivity ranking from high to low, the second calibration model is obtained.

[0045] Optionally, the optimal second calibration model can be obtained by iteratively adjusting the quantization precision type of the operators. For example, after adjusting the quantization precision type of one or some operators at a time, the quantization sensitivity of each operator is calculated, and it is determined whether the model meets the computational accuracy and performance requirements. If not, based on the quantization sensitivity, the quantization precision type of one or some operators is adjusted again until the model meets the computational accuracy and performance requirements, thus obtaining the second calibration model corresponding to the first neural network model.

[0046] Step 250: Based on the training dataset, adjust the quantization parameters and network parameters of the second calibration model to obtain the second neural network model.

[0047] The quantization parameters are used to quantize floating-point data. These parameters may include a scaling factor and a zero-point, used to quantize floating-point data into a lower precision type. For example, FP32 floating-point data is quantized into INT4 or INT8. The quantization parameters of an operator are determined based on the calibration method corresponding to that operator and the range of values ​​for the calculated data. Since the quantization precision type of some operators in the second calibration model has been adjusted compared to the first calibration model, and the quantization precision type affects the range of values ​​for the quantized data, it will affect the quantization parameters of the operators. Therefore, the quantization parameters of the second calibration model need to be adjusted. That is, based on the training dataset, the scaling factor and zero-point of the second calibration model under the adjusted quantization precision type are determined.

[0048] Network parameters are the learnable floating-point weights of the model. During the quantization process, these floating-point weights are quantized, which can negatively impact the model's computational accuracy. By adjusting the network parameters, the quantization error after quantization can be minimized, thus reducing the adverse effects of floating-point weight quantization on the model.

[0049] Step 260: Based on the second neural network model, determine the quantization model of the first neural network model.

[0050] The calibration method, training parameters, quantization parameters, and network parameters of the obtained second neural network model are all optimized parameters. Based on the second neural network model, a quantization model can be determined. For example, pseudo-quantization nodes in the second neural network model can be removed, and the quantization parameters and quantized network parameters can be saved to obtain the quantization model.

[0051] In some optional embodiments, after obtaining the second neural network model, it can be further determined whether the second neural network model meets preset conditions, which are pre-set model accuracy and performance requirements. If the second neural network model meets the preset conditions, it can be converted into a quantized model. If the second neural network model does not meet the preset conditions, it can be further optimized in the manner described above for adjusting the first and second calibration models, until the second neural network model meets the preset conditions, and then converted into a quantized model.

[0052] The computer implementation method for quantizing neural network models provided in this embodiment, when quantizing a first neural network model is required, can determine a first calibration model based on the first neural network model, training dataset, and a first and second quantization precision type supported by the neural network accelerator used to execute the first neural network model. Then, based on the training dataset, the quantization sensitivity of operators in the first calibration model is determined. Based on the quantization sensitivity, the quantization precision type of operators in the first calibration model is adjusted to obtain a second calibration model. Based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain a second neural network model. Based on the second neural network model, the quantization model of the first neural network model is determined. Thus, by combining different quantization precision types supported by the neural network accelerator, a better first calibration model is determined. Furthermore, adaptive optimization of the quantization precision type of operators is achieved based on the quantization sensitivity of the operators, improving the accuracy and effectiveness of the quantization precision type of the operators, avoiding manual setting of the quantization precision type of operators based on experience, and helping to reduce the manual cost of model quantization. After optimizing the quantization precision type of the operators, the quantization parameters and network parameters are adjusted to ensure the model accuracy and performance under the specified quantization precision type. Furthermore, the optimization process for quantization accuracy is based on the quantization sensitivity of the operator, which can be applied to quantization scenarios of any neural network model, effectively improving the versatility of the quantization process.

[0053] Figure 3 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in another exemplary embodiment of this disclosure.

[0054] In some alternative embodiments, in the above... Figure 2 Based on the illustrated embodiments, as Figure 3 As shown, step 220, which determines the first calibration model based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model, may include:

[0055] Step 2210: Perform pseudo-quantization on the first neural network model to obtain the third neural network model.

[0056] The first neural network model includes operators for performing various calculations, such as convolution, addition, and multiplication operators. Pseudo-quantization processing refers to the insertion of pseudo-quantization nodes (or calibration nodes) before the quantization-supporting operators in the first neural network model. These pseudo-quantization nodes quantize the input data once and then dequantize it, simulating the quantization behavior of the hardware and detecting quantization errors. Operators that require pseudo-quantization nodes can include, but are not limited to, convolution, activation functions, and multiply-accumulate operations; specific operators are not limited and can be set according to actual needs. The pseudo-quantization nodes can sense the dynamic range of activation values ​​and weights, determine a calibration threshold based on the calibration method, and then simulate the hardware-introduced error behavior through quantization and dequantization based on the calibration threshold. The third neural network model includes the operators in the first neural network model and the pseudo-quantization nodes inserted before the quantization-supporting operators in the first neural network model. In other words, the third neural network model, compared to the first neural network model, simply adds pseudo-quantization nodes.

[0057] Step 2220: Based on the training dataset and the first quantization precision type, determine the calibration parameters corresponding to the third neural network model.

[0058] The calibration parameters may include, but are not limited to, the calibration method, the number of iterations used for calibration, and the batch size of the data used for each calibration.

[0059] In some optional embodiments, the calibration parameters of the third neural network model can be fine-tuned based on the training dataset and the first quantization precision type to obtain the calibration parameters corresponding to the third neural network model. For example, the current calibration parameters can be set as initial values ​​for the third neural network model, and the quantization precision type of all operators in the third neural network model can be the first quantization precision type. Based on the training dataset, the quantization sensitivity of the third neural network model under the current calibration parameters can be determined. Based on the quantization sensitivity, the current calibration parameters can be adjusted to obtain the adjusted calibration parameters. Based on the adjusted calibration parameters, it can be determined whether the model meets the computational accuracy and performance requirements. If the computational accuracy and performance requirements are met, the adjusted calibration parameters are determined as the calibration parameters corresponding to the third neural network model. If the adjusted calibration parameters do not meet the computational accuracy and performance requirements of the model, the adjusted calibration parameters are used as the current calibration parameters, and the current calibration parameters are adjusted according to the above process until the adjusted calibration parameters meet the computational accuracy and performance requirements of the model. Thus, the optimal calibration parameters under the first quantization precision type can be obtained.

[0060] Step 2230: Based on the training dataset and the second quantization accuracy type, adjust the calibration parameters corresponding to the third neural network model to determine the first calibration model.

[0061] The calibration parameters for the third neural network model are determined based on the first quantization precision type. This means they are the calibration parameters when all operators in the third neural network model are quantized using the first quantization precision type. If all operators in the third neural network model are quantized using the second quantization precision type, the quantization precision type changes, and the calibration parameters under the first quantization precision type may not be the optimal calibration parameters under the second quantization precision type. To ensure the effectiveness and accuracy of the calibration parameters, the calibration parameters for the third neural network model can be adjusted based on the training dataset and the second quantization precision type to further optimize the calibration parameters and ensure that the optimized calibration parameters better meet the accuracy and performance requirements of the quantized model quantized using the second quantization precision type. The specific adjustment process for the calibration parameters is similar to the adjustment process under the first quantization precision type, except that under the second quantization precision type, the calibration parameters for the third neural network model determined based on the first quantization precision type are used as the initial values ​​for the adjustment process. Compared to the adjustment process under the first quantization precision type, this initial value is closer to the optimal calibration parameters. Therefore, the adjustment process for the calibration parameters requires less time and fewer adjustments compared to the adjustment process under the first quantization precision type. For example, the optimal calibration parameters under the second quantization precision type can be obtained through fine-tuning. The first calibration model is a calibration model that uses the second quantization precision type and adjusted calibration parameters. The first calibration model can be obtained based on the third neural network model, the second quantization precision type, and the adjusted calibration parameters. For example, updating the quantization precision type of each operator in the third neural network model to the second quantization precision type and updating the calibration parameters to the adjusted calibration parameters yields the first calibration model.

[0062] Optionally, adjusting the calibration parameters corresponding to the third neural network model can yield an intermediate calibration model. Further optimization of the quantization parameters and network parameters of the intermediate calibration model can then be performed to obtain the first calibration model.

[0063] In the embodiments of this disclosure, a third neural network model is obtained by performing pseudo-quantization processing on the first neural network model and inserting pseudo-quantization nodes into the model. This facilitates the simulation of hardware quantization operations through the pseudo-quantization nodes. Based on the training dataset and the first quantization precision type, the calibration parameters corresponding to the third neural network model are determined, yielding the optimal calibration parameters for the third neural network model under the highest quantization precision type supported by the hardware unit. This provides an accurate and effective calibration parameter reference for determining the first calibration model. Furthermore, based on the training dataset and the second quantization precision type, the calibration parameters corresponding to the third neural network model are adjusted to further optimize the calibration parameters, obtaining the optimal calibration parameters under the second quantization precision type, ensuring the accuracy and performance of the first calibration model.

[0064] In some optional embodiments, based on any of the above embodiments, step 230, determining the quantization sensitivity of the operator in the first calibration model based on the training dataset, may include:

[0065] Based on the training dataset, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model.

[0066] In step 240, based on quantization sensitivity, the quantization precision type of the operators in the first calibration model is adjusted to obtain the second calibration model, which may include:

[0067] Based on one or more first quantization sensitivities, the quantization precision type of at least some operators in the first calibration model is adjusted to obtain the second calibration model.

[0068] In this embodiment of the disclosure, individually quantizing any operator in the first calibration model means quantizing that operator in the first calibration model, while other operators are not quantized and instead use the model's original floating-point data. The first quantization sensitivity indicates the degree to which the quantization of that operator affects the model's computational accuracy when quantized individually.

[0069] Optionally, for any operator, the number of first quantization sensitivities obtained after individually quantizing the operator can be one or more. The number of first quantization sensitivities can be determined based on the number of tasks supported by the first neural network model. The tasks supported by the model include, but are not limited to, one or more of the following: object classification tasks, object detection tasks, semantic segmentation tasks, speech recognition tasks, trajectory prediction tasks, etc. For example, if the first neural network model is a multi-task model, each task has corresponding output data, and each operator corresponds to one first quantization sensitivity for each task it participates in the computation of. For any operator A in the common network (e.g., backbone network) part of multiple tasks in the model, which participates in the computation of multiple tasks, operator A has multiple first quantization sensitivities under multiple tasks. For any operator B in the branch network (e.g., task head network) part of each task, which only participates in the computation of a single task, operator B has one first quantization sensitivity under the task it participates in.

[0070] Since the first quantization sensitivity characterizes the degree of influence of a single quantization operator on model performance and computational accuracy, the quantization precision type of at least some operators in the first calibration model can be adjusted based on one or more first quantization sensitivities to achieve the purpose of adjusting the computational accuracy and performance of the quantization model. Optionally, based on one or more first quantization sensitivities, the quantization precision type of some operators with higher first quantization sensitivities in the first calibration model can be increased, so that these operators adopt a higher quantization precision type, reducing the adverse impact of quantization of these operators on the computational accuracy of the model, thus balancing the requirements for the computational accuracy and performance of the model.

[0071] In some optional embodiments, the quantization precision type of the operator with a preset ratio of high first quantization sensitivity can be adjusted from the current quantization precision type to a higher third quantization precision type. For example, if the current quantization precision type is the second quantization precision type (INT4), the quantization precision type of the operator with the preset ratio of high first quantization sensitivity can be adjusted from INT4 to INT6 to obtain the second calibration model. The precision of the third quantization precision type is higher than that of the second quantization precision type but lower than that of the first quantization precision type.

[0072] In some optional embodiments, after obtaining the second calibration model, the quantization parameters and network parameters of the second calibration model can be adjusted based on the training dataset to obtain a second neural network model. Then, based on the second neural network model, the quantization model of the first neural network model is determined. Optionally, the steps of determining the first quantization sensitivity, determining the second calibration model, and determining the second neural network model can be iterative steps. For example, in the first iteration, after obtaining the second neural network model according to the above processing flow, it can be determined based on the evaluation dataset whether the second neural network model meets the requirements for the model's computational accuracy and performance. If it does not meet the requirements, the second neural network model can be used as the first calibration model, and the above process can be iteratively executed, adjusting the quantization accuracy type, quantization parameters, and network parameters until the second neural network model meets the requirements for the model's computational accuracy and performance. Then, based on the second neural network model, the quantization model of the first neural network model is determined.

[0073] In some optional embodiments, after obtaining the second calibration model, since the quantization precision type of some operators has been adjusted, the calibration parameters of the second calibration model can be tuned to obtain an intermediate calibration model with the optimal calibration parameters under the adjusted quantization precision. This intermediate calibration model is used as the second calibration model mentioned above. Then, based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain the second neural network model.

[0074] In the embodiments of this disclosure, by determining one or more first quantization sensitivities obtained after individually quantizing each operator in the first calibration model, and then adjusting the quantization precision type of at least some operators in the first calibration model based on one or more first quantization sensitivities, a second calibration model with mixed precision is obtained, so that operators with different quantization sensitivities can be quantized using appropriate quantization precision types, effectively balancing the computational precision and performance of the model, and effectively meeting the computational precision and performance requirements of different users for the model.

[0075] Figure 4 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in yet another exemplary embodiment of this disclosure.

[0076] In some optional embodiments, determining one or more first quantization sensitivities based on the training dataset after individually quantizing each operator in the first calibration model may include:

[0077] Step 2310: Based on the training dataset and the first neural network model, determine the first output data corresponding to each training sample in the training dataset.

[0078] The first output data consists of the data output by the first neural network model after the training samples are input and the model performs inference. Each training sample corresponds to a set of first output data. For example, if the first neural network model is an object detection model and the training samples are input images, then the first output data is the object detection result corresponding to the input image.

[0079] Step 2320: Based on the training dataset and the first calibration model, determine the second output data corresponding to each training sample in the training dataset.

[0080] The second output data consists of the output data obtained by inputting the training samples into the first calibration model and inferring from the results. Each training sample can correspond to a set of second output data.

[0081] In some optional embodiments, during the initial iteration, the quantization precision type used by each operator in the first calibration model is the second quantization precision type, and the calibration parameters are the optimal calibration parameters corresponding to the second quantization precision type. During subsequent iterations, the quantization precision type used by each operator in the first calibration model is the quantization precision type adjusted in the previous iteration, and the calibration parameters are the optimal calibration parameters obtained from the previous calibration parameter tuning.

[0082] It should be noted that the execution of steps 2310 and 2320 is not in any particular order.

[0083] Step 2330: For each training sample, determine the quantization error corresponding to the training sample based on the first output data and the second output data.

[0084] Here, quantization error represents the error between the second output data and the first output data. Optionally, quantization error can be determined by one or more of the following: cosine similarity (CS), mean squared error (MSE), mean relative error (MRE), and signal-to-noise ratio (SNR) between the first and second output data.

[0085] Step 2340: Based on the quantization error and preset error conditions corresponding to each training sample, the training samples whose quantization error satisfies the preset error conditions are taken as target training samples.

[0086] The preset error condition can be the maximum quantization error or a preset error threshold. For each training sample, if the quantization error corresponding to the training sample is the largest among multiple training samples, or if the quantization error corresponding to the training sample is greater than the preset error threshold, it indicates that the training sample may be a bad case, and the training sample is used as the target training sample.

[0087] Step 2350: Based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model.

[0088] Optionally, the number of target training samples can be one or more. The target training sample can be input into a first calibration model, and by individually quantizing each operator in the first calibration model, the single-operator quantization output data corresponding to the target training sample can be obtained. Each target training sample can correspond to multiple single-operator quantization output data. For example, the first calibration model includes operators A, B, and C. Operator A is quantized individually in the first calibration model to obtain the single-operator quantization model corresponding to operator A. Each target training sample is input into this single-operator quantization model to obtain the single-operator quantization output data of the target training sample under this single-operator quantization model. Similarly, operators B and C each correspond to their respective single-operator quantization models, and based on each target training sample, the single-operator quantization output data of the target training sample under each single-operator quantization model can be obtained. Furthermore, based on the first output data and single-operator quantization output data corresponding to the target training sample, the single-operator quantization error can be determined, and based on the single-operator quantization error, the first quantization sensitivity of the operator can be determined. Taking a target training sample as an example, for any operator, multiple single operator quantization errors can be obtained based on multiple target training samples. Based on the multiple single operator quantization errors, the first quantization sensitivity of the operator can be determined.

[0089] Optionally, during the first iteration, the quantization precision type used by each quantization operator in the first calibration model is the second quantization precision type, and the calibration parameters are the optimal calibration parameters corresponding to the second quantization precision type. During subsequent iterations, the quantization precision type used by each quantization operator in the first calibration model is the quantization precision type adjusted in the previous iteration, and the calibration parameters are the optimal calibration parameters obtained from the previous calibration parameter tuning.

[0090] In this embodiment, the quantization error of the training samples is determined by the first output data of the first neural network model and the second output data of the first calibration model. Based on the quantization error, negative samples with large precision loss are selected and used as target training samples. This improves the effectiveness of the training samples used to determine the first quantization sensitivity of the operator and reduces the number of training samples used to calculate the quantization sensitivity, thereby improving computational efficiency. Furthermore, the quantization precision type of the operator is adjusted based on the first quantization sensitivity of the operator, which helps to further improve the accuracy of the quantization precision type.

[0091] In some optional embodiments, step 2350, based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model, determining one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model, may include:

[0092] Based on the target training samples, the third output data of each operator in the first calibration model is determined separately; based on the third output data and the first output data corresponding to the target training samples, the first quantization sensitivity corresponding to each operator is determined.

[0093] The third output data consists of the single-operator quantization output data obtained by inputting the target training samples into the single-operator quantization model that quantizes each operator individually. The single-operator quantization model for any operator refers to a model in the first calibration model where the pseudo-quantization node corresponding to that operator is enabled individually to quantize that operator, while other operators are not quantized. Based on the third output data and the first output data, the quantization error corresponding to that operator can be determined, and based on the quantization error, the first quantization sensitivity corresponding to that operator can be determined.

[0094] In this embodiment, based on the target training samples with significant accuracy loss, the third output data of each operator in the first calibration model is determined and quantized separately. Compared with the training dataset, this can effectively reduce the number of training samples and improve the effectiveness and computational efficiency of the training samples.

[0095] In some optional embodiments, the first output data includes first output sub-data corresponding to multiple tasks of the first neural network model; the second output data includes second output sub-data corresponding to multiple tasks; and determining the quantization error corresponding to the training sample based on the first and second output data in step 2330 may include:

[0096] For each of the multiple tasks, the first quantization error of the task under the training samples is determined based on the first output sub-data and the second output sub-data corresponding to the training samples.

[0097] In this context, "multiple tasks" in the first neural network model refers to the various functions that the first neural network model can achieve. These multiple tasks include, but are not limited to, multiple tasks such as object classification, object detection, semantic segmentation, speech recognition, and trajectory prediction. The first neural network model may include a shared network for multiple tasks and a task head network corresponding to each task. The output of each task head network is the first output sub-data corresponding to that task. Similarly, the output of each task head network in the first calibration model is the second output sub-data corresponding to that task.

[0098] Optionally, for each of the multiple task weights, the error between the first output sub-data and the second output sub-data corresponding to each training sample is determined as the first quantization error of that task under that training sample.

[0099] For example, the number of tasks in the first neural network model is M, and the number of training samples in the training dataset is N, where N is an integer greater than 1. The training dataset D can be represented as follows:

[0100]

[0101] Where, x i Let i represent the i-th training sample.

[0102] For the i-th training sample x in the training dataset i Quantization error E(x) i The following is represented:

[0103] E(x i )=E(f(x i ),f q (x i )) Formula (2)

[0104] Where f() represents the first output data, f q () represents the second output data, and E(,) represents the measurement function that measures the difference between the first output data and the second output data.

[0105] For the M tasks of the first neural network model, the first output data f(x) i This can be represented as follows:

[0106] f(x i )=(f1(x i ),f2(x i ),…,f M (x i )) Formula (3)

[0107] Among them, f j (x i) represents the j-th task in the i-th training sample x. i The first output sub-data, j = 1, 2, ..., M.

[0108] The j-th task is on the i-th training sample x i The first quantization error E j (x i The following is represented:

[0109] E j (x i ) = E j (f j (x i ),f qj (x i ))

[0110] Among them, E j (f j (x i ),f qj (x i This means that the above metric function E(,) is used to measure the j-th task on the i-th training sample x. i The difference between the first and second output sub-data is used to obtain the result of the j-th task on the i-th training sample x. i The first quantization error.

[0111] Step 2340, based on the quantization error and preset error conditions corresponding to each training sample, selects training samples whose quantization errors satisfy the preset error conditions as target training samples, which may include:

[0112] For each of the multiple tasks, based on the first quantization error of the task under each training sample and the preset error condition, the training sample corresponding to the first quantization error that satisfies the preset error condition is taken as the target training sample of the task.

[0113] For each of the multiple tasks, a target training sample can be determined. This is achieved by identifying the training sample whose first quantization error satisfies the preset error condition from the multiple training samples, based on the first quantization error of that task and a preset error condition. For example, for each task with N training samples, N first quantization errors can be obtained. The training sample corresponding to the largest first quantization error among these N first quantization errors is then used as the target training sample for that task. If there are M tasks, target training samples can be determined for each of the M tasks.

[0114] Optionally, each task may correspond to one or more target training samples, and the target training samples corresponding to different tasks may be the same or different.

[0115] In this embodiment, for the multi-task model, for each task, based on the first quantization error of the task under multiple training samples and the preset error conditions, the target training sample with the larger accuracy loss for each task can be determined, thereby further improving the accuracy and effectiveness of the target training sample.

[0116] In some optional embodiments, step 2350, based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model, determining one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model, may include:

[0117] For each of the multiple tasks, based on the target training samples and the first calibration model corresponding to the task, determine one or more single-task output sub-data after each operator in the first calibration model for the task; based on the first output sub-data and one or more single-task output sub-data, determine one or more first quantization sensitivities obtained after each operator for the task.

[0118] In this process, for each of the multiple tasks, the target training sample corresponding to that task is input into the single-operator quantization model corresponding to each operator, resulting in single-task output sub-data for that task. If there are multiple target training samples for that task, multiple single-task output sub-data can be obtained. Based on the first output sub-data and one or more single-task output sub-data for that task, one or more quantization errors for that task can be determined. Based on these one or more quantization errors, the first quantization sensitivity obtained after quantizing the operator individually for that task can be determined. If the operator participates in multiple tasks, multiple first quantization sensitivities for that task can be obtained. For example, with M tasks, each corresponding to one target training sample, and K operators, each corresponding to one single-operator quantization model, the target training sample for task 1 is input into the single-operator quantization model corresponding to operator A, resulting in single-task output sub-data for task 1 under that target training sample. Based on the first output sub-data and the single-task output sub-data for task 1, the first quantization sensitivity of the single quantization operator A for task 1 is determined. Following the above method, based on the target training samples corresponding to Task 1 and the single-operator quantization model corresponding to Operator B, the first quantization sensitivity of the single quantization operator B corresponding to Task 1 can be determined; based on the target training samples corresponding to Task 2 and the single-operator quantization model of Operator A, the first quantization sensitivity of the single quantization operator A corresponding to Task 2 can be determined; and so on, one or more first quantization sensitivities can be obtained after quantizing each operator separately for each task.

[0119] Optionally, the first quantization sensitivity of each operator corresponding to multiple tasks can be stored in a preset format, such as in a table format, to form a quantization sensitivity table for later use.

[0120] In this embodiment, for each of the multiple tasks of the model, based on the target training samples with large accuracy loss corresponding to the task and the first calibration model, the single-task output sub-data of each quantization operator corresponding to the task can be determined. Then, based on the first output sub-data and the single-task output sub-data corresponding to the single task, the first quantization sensitivity of each quantization operator corresponding to the single task can be determined, thereby realizing the fine-grainedness of the first quantization sensitivity and further improving the accuracy and effectiveness of the first quantization sensitivity.

[0121] Figure 5 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in yet another exemplary embodiment of this disclosure.

[0122] In some optional embodiments, based on any of the above embodiments, adjusting the quantization precision type of at least some operators in the first calibration model based on one or more first quantization sensitivities to obtain a second calibration model may include:

[0123] Step 2410: Based on one or more first quantization sensitivities, determine one or more first operators corresponding to the first quantization sensitivities that satisfy the sensitivity conditions, as at least some operators to be adjusted.

[0124] For each operator, one or more first quantization sensitivities can characterize the degree of influence of the operator's quantization on the model's computational accuracy. If the quantization of the operator has a significant impact on the model's computational accuracy, it indicates that the current quantization accuracy of the operator is too low and needs to be adjusted. Based on this, sensitivity conditions can be preset. These conditions include, but are not limited to, a preset number or proportion of operators with high first quantization sensitivities as at least some of the operators to be adjusted. Optionally, if an operator has multiple first quantization sensitivities, a maximum quantization sensitivity or a fused quantization sensitivity can be determined based on these multiple first quantization sensitivities. The fused quantization sensitivity includes, but is not limited to, the average quantization sensitivity or quantization sensitivity fused in other ways. Based on the maximum quantization sensitivity or the fused quantization sensitivity, it is determined whether the operator is a first operator that satisfies the sensitivity conditions. One or more first operators can be determined in the above manner, and the one or more first operators that satisfy the sensitivity conditions are selected as operators to be adjusted.

[0125] For example, the first neural network model includes K operators, and S operators are first operators that satisfy the sensitivity condition. If S is less than K, then these S first operators can be used as operators to be adjusted.

[0126] Step 2420: Adjust the direction according to the preset accuracy type, and adjust the quantization accuracy type of at least some operators in the first calibration model from the current quantization accuracy type to the third quantization accuracy type to obtain the second calibration model.

[0127] The preset precision type adjustment direction is, for example, but not limited to, from low precision to high precision. For example, if the second quantization precision type is the lowest quantization precision type supported by the hardware unit, the preset precision type adjustment direction is from the first precision to high precision.

[0128] Optionally, the first quantization precision type can be the lowest quantization precision type supported by the hardware unit, and the second quantization precision type can be the highest quantization precision type supported by the hardware unit. In this case, the preset precision type adjustment direction is from high precision to low precision. When adjusting the quantization precision type of the operator based on quantization sensitivity, the quantization precision type of the operator with lower quantization sensitivity should be lowered to improve model performance while meeting the model calculation accuracy requirements.

[0129] After determining at least some operators to be adjusted, the quantization accuracy type of at least some operators in the first calibration model is adjusted from the current quantization accuracy type to the third quantization accuracy type according to the preset accuracy type adjustment direction, so as to obtain the second calibration model. The third quantization accuracy type is higher or lower than the current quantization accuracy type.

[0130] Optionally, the third quantization precision type is higher than the lowest quantization precision type supported by the hardware unit and lower than the highest quantization precision type supported by the hardware unit, ensuring that the third quantization precision type is within the range of quantization precision types supported by the hardware unit.

[0131] In this embodiment, based on one or more first quantization sensitivities, a first operator that meets the sensitivity condition is determined as the operator to be adjusted. According to the preset precision type adjustment direction, the quantization precision type of the operator to be adjusted is changed from the current quantization precision type to the third quantization precision type, thereby improving the accuracy and effectiveness of the operator's quantization precision type and taking into account the requirements for the computational accuracy and performance of the model.

[0132] In some optional embodiments, based on any of the above embodiments, step 2220, which determines the calibration parameters corresponding to the third neural network model based on the training dataset and the first quantization precision type, may include:

[0133] Based on the training dataset and the first quantization precision type, the parameters of the third neural network model are tuned to determine the calibration parameters and training parameters corresponding to the third neural network model; the training parameters include at least the learning rate and the number of iterations.

[0134] The parameter tuning of the third neural network model can be determined by iteratively adjusting the calibration and training parameters. After each parameter adjustment, the adjusted model can be evaluated based on an evaluation dataset to determine whether the adjusted parameters meet the model's computational accuracy and performance requirements. This process is repeated iteratively until the parameters meet the requirements, yielding the calibration and training parameters for the third neural network model. The adjusted model can be referred to as the third calibration model.

[0135] Optionally, training parameters may include, but are not limited to, the learning rate, the number of iterations, weight decay parameters, and data augmentation parameters. The weight decay parameter is a key regularization parameter; its core function is to constrain the model weights through regularization, preventing overfitting. Data augmentation parameters are parameters used to augment the training dataset during training. For example, flipping sample images to obtain new sample images increases sample richness. Data augmentation parameters may include the proportion of augmented samples, such as augmenting 50% of the training samples in the training dataset.

[0136] In some optional embodiments, after obtaining the third calibration model, the method of this disclosure may further include: adjusting the quantization parameters and network parameters of the third calibration model based on the training dataset to obtain a fourth neural network model.

[0137] Step 2230, which adjusts the calibration parameters of the third neural network model based on the training dataset and the second quantization precision type to determine the first calibration model, may include: adjusting the calibration parameters of the fourth neural network model based on the training dataset and the second quantization precision type to determine the first calibration model. The specific adjustment operations for the calibration parameters are described in the aforementioned embodiments.

[0138] In step 250, based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain the second neural network model, including:

[0139] Based on the training dataset and the current quantization accuracy type of the second calibration model, the current quantization parameters of the second calibration model are adjusted to obtain the fourth calibration model; the current quantization parameters include scaling factor and zero point; based on the training dataset and training parameters, the network parameters of the fourth calibration model are adjusted to obtain the second neural network model.

[0140] In this model, the current quantization precision type of the second calibration model is an adjusted quantization precision type derived from at least some operators in the first calibration model. Specifically, the current quantization precision type of the first operator in the second calibration model is the adjusted third quantization precision type, and the current quantization precision type of the second operator in the second calibration model is the unadjusted quantization precision type in the first calibration model. The second operator is any operator in the second calibration model other than the first operator. Changes in the quantization precision type affect the scaling factor and zeros used for quantization; therefore, the current quantization parameters of the second calibration model need to be adjusted and optimized to ensure they are compatible with the current quantization precision type. Optionally, based on the training dataset and the current calibration method of the second calibration model, the data range of floating-point data can be determined. Based on the data range of floating-point data and the data range of the current quantization precision type, the scaling factor and zeros mapping from floating-point data to the current quantization precision type can be determined to obtain the adjusted quantization parameters. The quantization parameters of the second calibration model are then updated to the adjusted quantization parameters to obtain the fourth calibration model.

[0141] After obtaining the fourth calibration model, the training parameters obtained above can be reused. Based on the training dataset and training parameters, the network parameters of the fourth calibration model can be adjusted to obtain the second neural network model. The process of adjusting the network parameters can be called the QAT training process, which is similar to the floating-point model training process. For example, based on the training dataset and the fourth calibration model, the quantized output data of the training samples is obtained. Based on the quantized output data and the label data or floating-point output data, the model loss is determined, and the network parameters are adjusted based on the model loss. The difference between the QAT training process and the floating-point model training process is that in the QAT training process, the model simulates the hardware quantization operation, which allows the adjusted network parameters to reduce the computational accuracy loss of the quantized model relative to the floating-point model, thus ensuring the computational accuracy of the quantized model.

[0142] In this embodiment, after adjusting the quantization precision type to obtain the second calibration model, the current quantization parameters are adjusted based on the training dataset and the current quantization precision type of the second calibration model to obtain the fourth calibration model, thereby improving the accuracy and effectiveness of the quantization parameters. Then, based on the training dataset and training parameters, the network parameters of the fourth calibration model are adjusted to further improve the accuracy of the network parameters under quantization, reduce the loss of computational accuracy of the quantized model, and improve the computational accuracy of the model.

[0143] In some optional embodiments, step 260, based on the second neural network model, determines the quantization model of the first neural network model, including:

[0144] In response to the second neural network model meeting the preset conditions, the second neural network model is converted into a quantized model of the first neural network model; or, in response to the second neural network model not meeting the preset conditions, the quantization precision type of the operators in the second neural network model is adjusted based on the quantization sensitivity of the operators in the second neural network model, and the adjusted calibration model is used as the second calibration model. The quantization parameters and network parameters of the second calibration model are iteratively adjusted based on the training dataset to obtain the second neural network model until the second neural network model meets the preset conditions.

[0145] The preset conditions refer to the predefined model accuracy and performance requirements. After obtaining the second neural network model, it can be evaluated based on the evaluation dataset to determine whether it meets the preset conditions. If the second neural network model meets the preset conditions, it can be converted into a quantized model of the first neural network model. If the second neural network model does not meet the preset conditions, the quantization accuracy type of the operators in the second neural network model can be further adjusted based on their quantization sensitivity. The adjusted calibration model is then used as the second calibration model. Iteratively, based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain the second neural network model until it meets the preset conditions.

[0146] Optionally, if the second neural network model does not meet the preset conditions, the quantization precision type of the operators in the second neural network model can be adjusted based on the quantization sensitivity of the operators in the second neural network model to obtain a fifth calibration model. Based on the training dataset and the fifth calibration model, the calibration parameters of the fifth calibration model are tuned to obtain a sixth calibration model. The sixth calibration model is then used as the second calibration model, and the quantization parameters and network parameters of the second calibration model are iteratively adjusted based on the training dataset to obtain a second neural network model, until the second neural network model meets the preset conditions. In other words, based on the first calibration model, the steps of adjusting the quantization precision type (e.g., adjusting the quantization precision type according to the specific operations of steps 230-240 to obtain the fifth calibration model), tuning the calibration parameters (e.g., adjusting the calibration parameters corresponding to the fifth calibration model according to the operation of step 2230 to obtain the sixth calibration model), and tuning the quantization parameters and network parameters (e.g., adjusting the quantization parameters and network parameters of the sixth calibration model according to the specific operations of step 250 to obtain the second neural network model) can be iteratively executed to obtain a second neural network model, until the second neural network model meets the preset conditions.

[0147] In this embodiment, if the second neural network model does not meet the preset conditions, the second neural network model that meets the preset conditions can be obtained through iterative parameter tuning, thereby obtaining a quantization model that meets the requirements of computational accuracy and performance based on the second neural network model.

[0148] In some alternative embodiments, Figure 6 This is a flowchart illustrating a computer implementation method for quantizing a neural network model, provided in an exemplary embodiment of this disclosure. Figure 6 As shown, the method of this disclosure embodiment may include the following steps:

[0149] Step 30: Insert pseudo-quantization nodes into the trained floating-point model to obtain a pseudo-quantized model. The floating-point model is the first neural network model. The pseudo-quantized model is the third neural network model.

[0150] Step 31: Adjust the quantization precision of all operators in the pseudo-quantization model to the highest quantization precision type supported by the hardware. The highest quantization precision type is, for example, the first quantization precision type, such as INT16.

[0151] Step 32 involves fine-tuning the calibration parameters of the pseudo-quantization model from Step 31 to obtain the adjusted calibration parameters. Specifically, based on the training dataset and the first quantization precision type, the calibration parameters corresponding to the third neural network model are determined. The third neural network model is then updated based on these calibration parameters to obtain the third calibration model.

[0152] Step 33: Perform QAT parameter tuning on the third calibration model from step 32 to obtain the adjusted training parameters and QAT model. The QAT model is the fourth neural network model obtained by QAT training at the highest quantization accuracy level and adjusting the quantization parameters and network parameters.

[0153] Step 34: Evaluate the accuracy of the QAT model in Step 33. That is, determine the computational accuracy of the QAT model based on the evaluation dataset.

[0154] Step 35: Determine whether the accuracy of the QAT model in Step 34 meets the requirements, i.e., whether the QAT model meets the accuracy requirements. If the QAT model accuracy meets the requirements, proceed to Step 36. If the QAT model accuracy does not meet the requirements, return to Step 32 and continue parameter tuning until the model accuracy meets the requirements. This yields the calibration parameters and training parameters corresponding to the third neural network model, as well as the QAT model with the required accuracy (which can be called the fourth neural network model).

[0155] Step 36: Deploy the QAT model that met the accuracy standard in Step 35 onto the hardware, test the QAT model, and obtain the upper limit of the model's accuracy and the lower limit of its performance. In other words, run the QAT model on hardware to determine the actual model accuracy and performance.

[0156] Step 37: Adjust the quantization precision type of all operators in the QAT model that met the accuracy standard in Step 36 to the lowest quantization precision type supported by the hardware. That is, adjust the quantization precision type of each operator in the fourth neural network model to the second quantization precision type to obtain the adjusted neural network model, which can be called the fifth neural network model.

[0157] Step 38 involves fine-tuning the calibration parameters of the fifth neural network model from step 37 to obtain the adjusted calibration parameters and the first calibration model. Specifically, based on the training dataset and the second quantization precision type, the calibration parameters corresponding to the fourth neural network model are adjusted to determine the first calibration model.

[0158] Step 39: Optimize the QAT parameters of the first calibration model from step 38 to obtain the adjusted training parameters and QAT model. That is, based on the adjusted calibration parameters obtained in step 38, optimize the quantization parameters and network parameters of the first calibration model, and use the optimized calibration model (QAT model) as the first calibration model.

[0159] Step 40: Evaluate the QAT model obtained in step 39.

[0160] Step 41: Determine if the accuracy of the QAT model in Step 39 meets the standard. If the accuracy of the QAT model meets the standard, proceed to Step 42; if the accuracy of the QAT model does not meet the standard, return to Step 38.

[0161] Step 42: Deploy the QAT model (i.e., the first calibration model) that meets the accuracy standard determined in Step 41 on the hardware, and obtain the lower limit of the model's accuracy and the upper limit of its performance.

[0162] Step 43: Calculate the quantization sensitivity for all operators in the QAT model (i.e., the first calibration model) that meets the accuracy standard in Step 41, sort the results, and obtain a quantization sensitivity table. That is, based on the training dataset, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model.

[0163] Step 44: Adjust the quantization precision type of at least some operators in the QAT model from step 43 to obtain a mixed precision model. That is, based on one or more first quantization sensitivities, adjust the quantization precision type of operators in the first calibration model to obtain a second calibration model. For example, based on the first quantization sensitivity, adjust half of the operators from INT4 to INT8.

[0164] Step 45 involves fine-tuning the calibration parameters and QAT parameters of the mixed-precision model from step 44 to obtain the second neural network model. The specific operations for fine-tuning the calibration parameters and QAT parameters are similar to those in steps 32 and 33 above.

[0165] Step 46: Determine whether the accuracy of the second neural network model in step 45 meets the standard. If it does, proceed to step 47. If it does not, jump to step 44 and continue to adjust the quantization accuracy type.

[0166] Step 47: Determine the quantization model that meets the expected accuracy and performance. That is, determine the quantization model of the first neural network model based on the second neural network model.

[0167] In related technologies, experts manually adjust sparse configuration parameters based on experience, which is costly, lacks interpretability, and the adjustment experience for one model cannot be transferred to different models. Each new model requires a long debugging time. Furthermore, expert experience is not always the optimal solution, and it is easy to set many operators that do not need high-precision types as high-precision types, affecting the deployment performance of the model.

[0168] In the embodiments of this disclosure, parameter tuning is performed based on the highest quantization precision type supported by the hardware to determine the optimal training parameters, which can be reused in subsequent tuning processes. Then, parameter tuning is performed using the lowest quantization precision type supported by the hardware. The resulting first calibration model serves as the starting calibration model for quantization precision type adjustment. Based on the first calibration model, the quantization sensitivity of operators is calculated, and the quantization precision type of operators is dynamically adjusted based on the quantization sensitivity. This allows different operators to use different quantization precision types. For example, operators with a significant impact on model accuracy can use a higher precision type, while operators with a smaller impact can use a lower precision type. This avoids using excessively low quantization precision types for operators with high quantization sensitivity, thus achieving better inference performance and ensuring that the quantization model meets the requirements for model computational accuracy and performance. Furthermore, the solution of this disclosure achieves automated tuning of various parameters, effectively improving debugging efficiency, reducing expert costs, and quickly and automatically searching for optimal parameters based on hardware characteristics. This improves the accuracy and effectiveness of operator quantization precision types, avoids setting many operators that do not require high precision types to high precision types, and improves model deployment performance. Furthermore, the solution disclosed herein is not constrained by different models, can be applied to any model, has strong portability, and avoids the situation where a long time of debugging is required every time a new model is encountered.

[0169] The embodiments described above can be implemented individually or in any combination without conflict. The specific implementation can be set according to actual needs, and this disclosure does not limit them.

[0170] Any of the computer implementation methods for quantizing neural network models provided in this disclosure can be executed by any suitable electronic device with data processing capabilities, including but not limited to: terminal devices and servers. Alternatively, any of the computer implementation methods for quantizing neural network models provided in this disclosure can be executed by a processor, such as by a processor executing any of the computer implementation methods for quantizing neural network models mentioned in this disclosure by calling corresponding instructions stored in memory. Further details will not be elaborated below.

[0171] Exemplary device

[0172] Figure 7 This is a schematic diagram of a computer implementation apparatus for quantizing a neural network model provided in an exemplary embodiment of this disclosure. The computer implementation apparatus for quantizing a neural network model in this embodiment can be used to implement the computer implementation method for quantizing a neural network model provided in any of the above embodiments of this disclosure, such as... Figure 7 The device 60 shown may include at least one processor 61.

[0173] At least one processor 61 is configured as follows:

[0174] The process involves: determining the first neural network model to be quantized and the training dataset; determining a first calibration model based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model; determining the quantization sensitivity of operators in the first calibration model based on the training dataset; adjusting the quantization precision type of operators in the first calibration model based on the quantization sensitivity to obtain a second calibration model; adjusting the quantization parameters and network parameters of the second calibration model based on the training dataset to obtain a second neural network model; and determining the quantization model of the first neural network model based on the second neural network model.

[0175] In some alternative embodiments, based on any of the above embodiments, at least one processor 61 is specifically configured as follows:

[0176] The first neural network model is pseudo-quantized to obtain the third neural network model. Based on the training dataset and the first quantization precision type, the calibration parameters corresponding to the third neural network model are determined. Based on the training dataset and the second quantization precision type, the calibration parameters corresponding to the third neural network model are adjusted to determine the first calibration model.

[0177] In some alternative embodiments, based on any of the above embodiments, at least one processor 61 is specifically configured as follows:

[0178] Based on the training dataset, one or more first quantization sensitivities are determined after individually quantizing each operator in the first calibration model. Based on the one or more first quantization sensitivities, the quantization precision type of at least some operators in the first calibration model is adjusted to obtain the second calibration model.

[0179] In some alternative embodiments, at least one processor 61 is specifically configured to:

[0180] Based on the training dataset and the first neural network model, the first output data corresponding to each training sample in the training dataset is determined. Based on the training dataset and the first calibration model, the second output data corresponding to each training sample in the training dataset is determined. For each training sample, based on the first and second output data, the quantization error corresponding to the training sample is determined. Based on the quantization error corresponding to each training sample and a preset error condition, training samples whose quantization errors satisfy the preset error condition are taken as target training samples. Based on the target training samples, the first output data corresponding to the target training samples, and the first calibration model, one or more first quantization sensitivities are determined after individually quantizing each operator in the first calibration model.

[0181] In some alternative embodiments, at least one processor 61 is specifically configured to:

[0182] Based on the target training samples, the third output data of each operator in the first calibration model is determined separately; based on the third output data and the first output data corresponding to the target training samples, the first quantization sensitivity corresponding to each operator is determined.

[0183] In some optional embodiments, the first output data includes first output sub-data corresponding to multiple tasks of the first neural network model; the second output data includes second output sub-data corresponding to multiple tasks; at least one processor 61 is specifically configured to:

[0184] For each of the multiple tasks, based on the first and second output sub-data corresponding to the training samples, the first quantization error of the task under the training samples is determined. For each of the multiple tasks, based on the first quantization error of the task under each training sample and a preset error condition, the training sample corresponding to the first quantization error that satisfies the preset error condition is taken as the target training sample for the task.

[0185] In some alternative embodiments, at least one processor 61 is specifically configured to:

[0186] For each of the multiple tasks, based on the target training samples and the first calibration model corresponding to the task, determine one or more single-task output sub-data after each operator in the first calibration model for the task; based on the first output sub-data and one or more single-task output sub-data, determine one or more first quantization sensitivities obtained after each operator for the task.

[0187] In some alternative embodiments, based on any of the above embodiments, at least one processor 61 is specifically configured as follows:

[0188] Based on one or more first quantization sensitivities, one or more first operators corresponding to the first quantization sensitivities that meet the sensitivity conditions are determined as at least some operators to be adjusted. According to the preset precision type adjustment direction, the quantization precision type of at least some operators in the first calibration model is adjusted from the current quantization precision type to the third quantization precision type to obtain the second calibration model.

[0189] In some optional embodiments, based on any of the above embodiments, at least one processor 61 is specifically configured to: perform parameter tuning on a third neural network model based on a training dataset and a first quantization precision type, and determine calibration parameters and training parameters corresponding to the third neural network model; the training parameters include at least the learning rate and the number of iterations.

[0190] At least one processor 61 is specifically configured as follows:

[0191] Based on the training dataset and the current quantization accuracy type of the second calibration model, the current quantization parameters of the second calibration model are adjusted to obtain the fourth calibration model; the current quantization parameters include scaling factor and zero point; based on the training dataset and training parameters, the network parameters of the fourth calibration model are adjusted to obtain the second neural network model.

[0192] In some alternative embodiments, at least one processor 61 is specifically configured to:

[0193] In response to the second neural network model meeting the preset conditions, the second neural network model is converted into a quantized model of the first neural network model; or, in response to the second neural network model not meeting the preset conditions, the quantization precision type of the operators in the second neural network model is adjusted based on the quantization sensitivity of the operators in the second neural network model, and the adjusted calibration model is used as the second calibration model. The quantization parameters and network parameters of the second calibration model are iteratively adjusted based on the training dataset to obtain the second neural network model until the second neural network model meets the preset conditions.

[0194] The embodiments described above can be implemented individually or in any combination without conflict. The specific implementation can be set according to actual needs, and this disclosure does not limit them.

[0195] The beneficial technical effects corresponding to the exemplary embodiments of this device can be found in the corresponding beneficial technical effects of the exemplary method section above, and will not be repeated here.

[0196] Exemplary electronic devices

[0197] Figure 8 This is a structural diagram of an electronic device provided in an embodiment of the present disclosure. The electronic device 90 includes at least one processor 91 and a memory 92.

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

[0199] 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. 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 computer implementation methods for quantizing neural network models and / or other desired functions of the various embodiments of this disclosure described above.

[0200] In one example, the electronic device 90 may also include an input device 93 and an output device 94, which are interconnected via a bus system and / or other forms of connection mechanism (not shown).

[0201] The input device 93 may also include, for example, a touchscreen, a microphone, various sensors, etc. Sensors may include, for example, image sensors (e.g., cameras, webcams), LiDAR, millimeter-wave radar, ultrasonic radar, positioning sensors, pressure sensors, air quality sensors, temperature sensors, etc. Image sensors, LiDAR, millimeter-wave radar, ultrasonic radar, etc., can be used for environmental perception, i.e., detecting moving and static objects in the surrounding environment. Moving and static objects may include, for example, static objects such as lane lines, curbs, arrows, signs, trees, and buildings, as well as dynamic objects such as surrounding vehicles, pedestrians, and cyclists. Positioning sensors are used to locate the mobile device (e.g., a bicycle, a robot, etc.) where the electronic device is located. Positioning sensors may include, for example, an Inertial Measurement Unit (IMU), a Global Positioning System (GPS), etc. Pressure sensors can be used to detect seat pressure. Temperature sensors can be used to detect the temperature inside the vehicle cabin. Air quality sensors can be used to detect the air quality inside the vehicle cabin.

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

[0203] Of course, for the sake of simplicity, Figure 8 Only some of the components of the electronic device 90 relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device 90 may include any other suitable components depending on the specific application.

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

[0205] In addition to the methods and apparatus described above, embodiments of this disclosure may also provide a computer program product, including computer program instructions that, when executed by a processor, cause the processor to perform the steps of the computer implementation methods for quantizing neural network models described in the various embodiments of this disclosure in the "Exemplary Methods" section above.

[0206] Computer program products can be written in any combination of one or more programming languages ​​to perform the operations of embodiments of this disclosure. These programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0207] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps in the computer implementation methods for quantizing neural network models of the various embodiments of this disclosure described in the "Exemplary Methods" section above.

[0208] Computer-readable storage media may take the form of any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, but is not limited to, systems, apparatuses, or devices that are electrical, magnetic, optical, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0209] The basic principles of this disclosure have been described above with reference to specific embodiments. However, the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.

[0210] Various modifications and variations can be made to this disclosure without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this disclosure and their equivalents, this disclosure is also intended to include such modifications and variations.

Claims

1. A computer implementation method for quantizing neural network models, comprising: Determine the first neural network model to be quantized and the training dataset; A first calibration model is determined based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model. Based on the training dataset, determine the quantization sensitivity of the operators in the first calibration model; Based on the quantization sensitivity, the quantization precision type of the operator in the first calibration model is adjusted to obtain the second calibration model; Based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain the second neural network model. Based on the second neural network model, the quantization model of the first neural network model is determined.

2. The method according to claim 1, wherein, The step of determining the first calibration model based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model includes: The first neural network model is pseudo-quantized to obtain the third neural network model. Based on the training dataset and the first quantization accuracy type, determine the calibration parameters corresponding to the third neural network model; Based on the training dataset and the second quantization accuracy type, the calibration parameters corresponding to the third neural network model are adjusted to determine the first calibration model.

3. The method according to claim 1, wherein, Determining the quantization sensitivity of operators in the first calibration model based on the training dataset includes: Based on the training dataset, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model; The step of adjusting the quantization precision type of the operators in the first calibration model based on the quantization sensitivity to obtain the second calibration model includes: Based on the one or more first quantization sensitivities, the quantization precision type of at least some operators in the first calibration model is adjusted to obtain the second calibration model.

4. The method according to claim 3, wherein, The step of adjusting the quantization precision type of at least some operators in the first calibration model based on the one or more first quantization sensitivities to obtain the second calibration model includes: Based on the one or more first quantization sensitivities, determine one or more first operators corresponding to the first quantization sensitivities that satisfy the sensitivity conditions, as the at least some operators to be adjusted; According to the preset accuracy type adjustment direction, the quantization accuracy type of at least some operators in the first calibration model is adjusted from the current quantization accuracy type to the third quantization accuracy type to obtain the second calibration model.

5. The method according to claim 3, wherein, The step of determining one or more first quantization sensitivities based on the training dataset after individually quantizing each operator in the first calibration model includes: Based on the training dataset and the first neural network model, determine the first output data corresponding to each training sample in the training dataset; Based on the training dataset and the first calibration model, determine the second output data corresponding to each training sample in the training dataset; For each training sample, the quantization error corresponding to the training sample is determined based on the first output data and the second output data; Based on the quantization error and preset error condition corresponding to each training sample, the training sample whose quantization error satisfies the preset error condition is taken as the target training sample. Based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model.

6. The method according to claim 5, wherein, The step of determining one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model includes: Based on the target training samples, determine the third output data of each operator in the first calibration model, quantized separately. Based on the third output data and the first output data corresponding to the target training sample, the first quantization sensitivity corresponding to each operator is determined.

7. The method according to claim 5, wherein, The first output data includes first output sub-data corresponding to each of the multiple tasks of the first neural network model; the second output data includes second output sub-data corresponding to each of the multiple tasks. The step of determining the quantization error corresponding to the training sample based on the first output data and the second output data includes: For each of the plurality of tasks, based on the first output sub-data and the second output sub-data corresponding to the training sample, the first quantization error of the task under the training sample is determined; The step of using the training samples whose quantization error satisfies the preset error condition as target training samples based on the quantization error and preset error condition corresponding to each training sample includes: For each of the plurality of tasks, based on the first quantization error of the task under each of the training samples and the preset error condition, the training sample corresponding to the first quantization error that satisfies the preset error condition is taken as the target training sample corresponding to the task.

8. The method according to claim 7, wherein, The step of determining one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model includes: For each of the plurality of tasks, based on the target training sample corresponding to the task and the first calibration model, determine one or more single-task output sub-data after individually quantizing each operator in the first calibration model corresponding to the task; Based on the first output sub-data corresponding to the task and the one or more single-task output sub-data, determine the one or more first quantization sensitivities obtained after individually quantizing each operator corresponding to the task.

9. The method according to claim 2, wherein, The step of determining the calibration parameters corresponding to the third neural network model based on the training dataset and the first quantization precision type includes: Based on the training dataset and the first quantization accuracy type, the parameters of the third neural network model are tuned to determine the calibration parameters and training parameters corresponding to the third neural network model; the training parameters include at least the learning rate and the number of iterations. The step of adjusting the quantization parameters and network parameters of the second calibration model based on the training dataset to obtain the second neural network model includes: Based on the training dataset and the current quantization accuracy type of the second calibration model, the current quantization parameters of the second calibration model are adjusted to obtain a fourth calibration model; the current quantization parameters include a scaling factor and a zero point. Based on the training dataset and the training parameters, the network parameters of the fourth calibration model are adjusted to obtain the second neural network model.

10. The method according to any one of claims 1-9, wherein, The step of determining the quantization model of the first neural network model based on the second neural network model includes: In response to the second neural network model satisfying a preset condition, the second neural network model is converted into a quantized model of the first neural network model; or, In response to the second neural network model not meeting the preset conditions, the quantization precision type of the operators in the second neural network model is adjusted based on the quantization sensitivity of the operators in the second neural network model. The adjusted calibration model is used as the second calibration model. The process of adjusting the quantization parameters and network parameters of the second calibration model based on the training dataset is iteratively executed to obtain the second neural network model until the second neural network model meets the preset conditions.

11. A computer implementation apparatus for quantizing a neural network model, comprising: At least one processor; The at least one processor is configured to: Determine the first neural network model to be quantized and the training dataset; A first calibration model is determined based on the first neural network model, the training dataset, and the first and second quantization precision types supported by the neural network accelerator used to execute the first neural network model. Based on the training dataset, determine the quantization sensitivity of the operators in the first calibration model; Based on the quantization sensitivity, the quantization precision type of the operator in the first calibration model is adjusted to obtain the second calibration model; Based on the training dataset, the quantization parameters and network parameters of the second calibration model are adjusted to obtain the second neural network model; Based on the second neural network model, the quantization model of the first neural network model is determined.

12. The apparatus according to claim 11, wherein, The at least one processor is specifically configured as follows: The first neural network model is pseudo-quantized to obtain the third neural network model. Based on the training dataset and the first quantization accuracy type, determine the calibration parameters corresponding to the third neural network model; Based on the training dataset and the second quantization accuracy type, the calibration parameters corresponding to the third neural network model are adjusted to determine the first calibration model.

13. The apparatus according to claim 11, wherein, The at least one processor is specifically configured as follows: Based on the training dataset, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model; The step of adjusting the quantization precision type of the operators in the first calibration model based on the quantization sensitivity to obtain the second calibration model includes: Based on the one or more first quantization sensitivities, the quantization precision type of at least some operators in the first calibration model is adjusted to obtain the second calibration model.

14. The apparatus according to claim 13, wherein, The at least one processor is specifically configured as follows: Based on the one or more first quantization sensitivities, determine one or more first operators corresponding to the first quantization sensitivities that satisfy the sensitivity conditions, as the at least some operators to be adjusted; According to the preset accuracy type adjustment direction, the quantization accuracy type of at least some operators in the first calibration model is adjusted from the current quantization accuracy type to the third quantization accuracy type to obtain the second calibration model.

15. The apparatus according to claim 13, wherein, The at least one processor is specifically configured as follows: Based on the training dataset and the first neural network model, determine the first output data corresponding to each training sample in the training dataset; Based on the training dataset and the first calibration model, determine the second output data corresponding to each training sample in the training dataset; For each training sample, the quantization error corresponding to the training sample is determined based on the first output data and the second output data; Based on the quantization error and preset error condition corresponding to each training sample, the training sample whose quantization error satisfies the preset error condition is taken as the target training sample. Based on the target training sample, the first output data corresponding to the target training sample, and the first calibration model, determine one or more first quantization sensitivities obtained by individually quantizing each operator in the first calibration model.

16. The apparatus according to claim 15, wherein, The at least one processor is specifically configured as follows: Based on the target training samples, determine the third output data of each operator in the first calibration model, quantized separately. Based on the third output data and the first output data corresponding to the target training sample, the first quantization sensitivity corresponding to each operator is determined.

17. The apparatus according to claim 15, wherein, The first output data includes first output sub-data corresponding to each of the multiple tasks of the first neural network model; the second output data includes second output sub-data corresponding to each of the multiple tasks. The at least one processor is specifically configured as follows: For each of the plurality of tasks, based on the first output sub-data and the second output sub-data corresponding to the training sample, the first quantization error of the task under the training sample is determined; The step of using the training samples whose quantization error satisfies the preset error condition as target training samples based on the quantization error and preset error condition corresponding to each training sample includes: For each of the plurality of tasks, based on the first quantization error of the task under each of the training samples and the preset error condition, the training sample corresponding to the first quantization error that satisfies the preset error condition is taken as the target training sample corresponding to the task.

18. The apparatus according to claim 17, wherein, The at least one processor is specifically configured as follows: For each of the plurality of tasks, based on the target training sample corresponding to the task and the first calibration model, determine one or more single-task output sub-data after individually quantizing each operator in the first calibration model corresponding to the task; Based on the first output sub-data corresponding to the task and the one or more single-task output sub-data, determine the one or more first quantization sensitivities obtained after individually quantizing each operator corresponding to the task.

19. The apparatus according to claim 12, wherein, The at least one processor is specifically configured as follows: Based on the training dataset and the first quantization accuracy type, the parameters of the third neural network model are tuned to determine the calibration parameters and training parameters corresponding to the third neural network model; the training parameters include at least the learning rate and the number of iterations. The at least one processor is specifically configured as follows: Based on the training dataset and the current quantization accuracy type of the second calibration model, the current quantization parameters of the second calibration model are adjusted to obtain a fourth calibration model; the current quantization parameters include a scaling factor and a zero point. Based on the training dataset and the training parameters, the network parameters of the fourth calibration model are adjusted to obtain the second neural network model.

20. The apparatus according to any one of claims 11-19, wherein, The at least one processor is specifically configured as follows: In response to the second neural network model satisfying a preset condition, the second neural network model is converted into a quantized model of the first neural network model; or, In response to the second neural network model not meeting the preset conditions, the quantization precision type of the operators in the second neural network model is adjusted based on the quantization sensitivity of the operators in the second neural network model. The adjusted calibration model is used as the second calibration model. The process of adjusting the quantization parameters and network parameters of the second calibration model based on the training dataset is iteratively executed to obtain the second neural network model until the second neural network model meets the preset conditions.

21. A computer-readable storage medium storing a computer program that is executed by a processor to perform the computer implementation method for quantizing a neural network model as described in any one of claims 1-10.

22. An electronic device, the electronic device comprising: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory, and execute the executable instructions to implement the computer implementation method for quantizing a neural network model as described in any one of claims 1-10.