Adaptive quantization method and system of deep neural network, and product

By performing error evaluation and bit width optimization on the quantization combination nodes of the deep neural network, the problem of inaccurate quantization error evaluation is solved, and more accurate quantization error evaluation and performance improvement are achieved.

CN118839736APending Publication Date: 2024-10-25CHONGQING CHANGAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410951375.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-10-25

AI Technical Summary

Technical Problem

In the existing deep neural network quantification method, since the calculation method is forward propagation layer by layer, the quantization error of each layer in the model will be accumulated into subsequent layers, resulting in inaccurate quantization error evaluation, especially the error in the later layers. The biggest impact.

Method used

By setting the quantization combination node for the original floating point model, the target floating point model is constructed, and the quantization parameters are determined through data set training, the quantization error and loss of each model layer are evaluated, and the quantization bit width is optimized until the set conditions are met to avoid error accumulation. .

Benefits of technology

The accuracy of quantization error evaluation is improved, making the performance evaluation of the quantization model more accurate, avoiding error accumulation, thereby improving the overall performance of the quantification model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118839736A_ABST
    Figure CN118839736A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an adaptive quantization method, system and product of a deep neural network, and the method comprises the steps: setting a quantization combination node for a model layer of an original floating point model, and constructing a target floating point model; training and quantizing the target floating point model, and determining a quantization parameter of a quantization combination node; performing quantization parameter setting on the quantization combination node through the quantization parameter to obtain a first quantization model; under the condition that the performance does not meet the set condition, comparing the floating-point number of the quantization node input into the quantization combination node with the floating-point number output by the inverse quantization node of the quantization combination node to obtain a quantization error; determining quantization loss of a model layer in the first quantization model according to the obtained quantization error; determining an optimization layer according to the quantization loss; and increasing the quantization bit width of the optimization layer, and re-determining the quantization parameter of the quantization combination node so as to construct a new quantization model. The objective of the invention is to improve model quantization error evaluation accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of deep neural network quantization, and specifically to an adaptive quantization method, system and product for a deep neural network. Background Art

[0002] The structure of a deep neural network model is usually composed of layers of neurons connected together, and the calculation is forward propagated layer by layer, so it has the characteristics of high computing density and frequent memory access. When deploying a deep neural network on an embedded platform, due to the limited chip computing power and memory bandwidth, it is usually necessary to convert the model from a 32-bit wide floating point number to a smaller bit width data type (8-bit, 16-bit integer, etc.) through quantization processing to reduce memory consumption and improve computing efficiency. In terms of data type, quantization is a lossy and irreversible conversion. Therefore, the quantized model usually has a certain degree of decline in algorithm performance. To address this problem, a mixed precision method is currently used to quantize the model to improve the model effect. The main process is to determine the quantization loss of each quantization node by comparing the output of the quantized model and the original floating point model layer by layer under the same input. The larger the loss, the higher the quantization bit width is used.

[0003] However, the main drawback of this solution is that since the calculation method of deep neural networks is forward propagation layer by layer, the quantization error of each layer in the model will be accumulated to the subsequent layers. Therefore, by comparing the output of the quantization model and the original floating-point model layer by layer, the quantization error of each layer is inaccurate. The later the layer, the greater the impact of the accumulated error. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a method, system and product for adaptive quantization of a deep neural network, aiming to improve the accuracy of quantization error evaluation of the model.

[0005] A first aspect of an embodiment of the present application provides an adaptive quantization method for a deep neural network, the method comprising:

[0006] Set a quantization combination node for the model layer of the original floating-point model to build a target floating-point model;

[0007] Performing post-training quantization on the target floating-point model using a first data set to determine a quantization parameter of the quantization combination node;

[0008] Setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a first quantization model;

[0009] When the performance of the first quantization model does not meet the set conditions, the floating point number of the quantization node in the input quantization combination node is compared with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error;

[0010] Determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node;

[0011] Determining an optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model;

[0012] The quantization bit width of the optimization layer is increased, and the quantization parameters of the quantization combination nodes are re-determined to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions.

[0013] Optionally, increasing the quantization bit width of the optimization layer includes:

[0014] Comparing the quantization loss of the optimization layer with a set threshold to obtain a comparison result;

[0015] According to the comparison result, determining an increase range of the quantization bit width of the optimization layer;

[0016] According to the amplitude, the quantization bit width of the optimization layer is increased.

[0017] Optionally, determining, according to the comparison result, an increase in the quantization bit width of the optimization layer includes:

[0018] When the comparison result shows that the quantization loss is less than or equal to the set threshold, determining to increase the quantization bit width of the optimization layer by a single amplitude;

[0019] When the comparison result shows that the quantization loss is greater than the set threshold, it is determined to increase the quantization bit width of the optimization layer by multiple times.

[0020] Optionally, determining an optimization layer for performing quantization bit width optimization according to quantization losses of each model layer of the first quantization model includes:

[0021] By comparing the quantization losses of each model layer of the first quantization model, determining the model layer with the largest quantization loss;

[0022] The model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

[0023] Optionally, a quantization combination node is set for the model layer of the original floating-point model to construct a target floating-point model, including:

[0024] The weights and activation values ​​of the model layers of the original floating-point model are then followed by setting quantization nodes and dequantization nodes, and initial quantization bit widths are set for the quantization nodes to construct a target floating-point model.

[0025] Optionally, before determining the optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model, the method further includes:

[0026] According to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule is determined as an initial optimization layer;

[0027] Increasing the quantization bit width of the initial optimization layer, and performing quantization-aware training on the target floating-point model currently undergoing quantization bit width increase through a second data set to determine a quantization parameter of a quantization combination node;

[0028] Setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a second quantization model;

[0029] When the performance of the second quantization model does not meet the set conditions, the floating point number of the quantization node in the input quantization combination node is compared with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error;

[0030] Determining the quantization loss of each model layer of the second quantization model according to the obtained quantization errors of each quantization combination node;

[0031] The step of determining the optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model includes:

[0032] An optimization layer for performing quantization bit width optimization is determined according to the quantization losses of each model layer of the second quantization model.

[0033] Optionally, increasing the quantization bit width of the optimization layer and re-determining the quantization parameters of the quantization combination node to construct a new quantization model includes:

[0034] The quantization bit width of the optimization layer is set, and the target floating-point model currently undergoing quantization bit width increase is retrained with the second data set to determine the quantization parameters of the quantization combination nodes so as to construct a new quantization model.

[0035] Optionally, determining an optimization layer for performing quantization bit width optimization according to quantization losses of each model layer of the second quantization model includes:

[0036] By comparing the quantization losses of each model layer of the second quantization model, determining the model layer with the largest quantization loss;

[0037] The model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

[0038] Optionally, according to a preset screening rule, determining each model layer in the first quantization model whose quantization loss satisfies the preset screening rule as an initial optimization layer includes:

[0039] Sorting all model layers of the first quantization model based on the quantization loss to obtain a sorting result;

[0040] According to the ranking result, a preset percentage of model layers ranked top are determined as initial optimization layers.

[0041] Optionally, according to a preset screening rule, determining each model layer in the first quantization model whose quantization loss satisfies the preset screening rule as an initial optimization layer includes:

[0042] Determining a preset quantitative loss threshold;

[0043] Each model layer in the first quantization model whose quantization loss is greater than the preset quantization loss threshold is determined as an initial optimization layer.

[0044] Optionally, the method further includes:

[0045] Obtaining deep learning models for driver assistance that will be deployed on embedded platforms;

[0046] The assisted driving deep learning model is determined as an original floating-point model.

[0047] A second aspect of an embodiment of the present application provides an adaptive quantization system for a deep neural network, the system comprising:

[0048] A floating-point model building module is used to set quantization combination nodes for the model layer of the original floating-point model to build a target floating-point model;

[0049] A first quantization parameter determination module, configured to perform post-training quantization on the target floating-point model using a first data set to determine a quantization parameter of the quantization combination node;

[0050] A first quantization model determination module, configured to set quantization parameters for the quantization combination node using the quantization parameters to obtain a first quantization model;

[0051] A first quantization error determination module is used to compare the floating point number of the quantization node in the input quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error when the performance of the first quantization model does not meet the set conditions;

[0052] A first quantization loss determination module, used to determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node;

[0053] An optimization layer determination module, used to determine an optimization layer for performing quantization bit width optimization according to the quantization loss of each model layer of the first quantization model;

[0054] The second quantization parameter determination module is used to increase the quantization bit width of the optimization layer and re-determine the quantization parameters of the quantization combination nodes to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions.

[0055] A third aspect of an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and running on the processor, wherein when the computer program is executed by the processor, the steps in the adaptive quantization method of a deep neural network as described in the first aspect of the present application are implemented.

[0056] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the adaptive quantization method of a deep neural network as described in the first aspect of the present application are implemented.

[0057] The adaptive quantization method of a deep neural network provided in this application has the following advantages:

[0058] An adaptive quantization method for a deep neural network provided in an embodiment of the present application comprises the following steps: firstly, a quantization combination node is set for a model layer of an original floating-point model to construct a target floating-point model; the constructed target floating-point model is quantized after training using a first data set to determine the quantization parameters of the quantization combination node; the quantization parameters of the quantization combination node are set using the quantization parameters to obtain a first quantization model; when the performance of the first quantization model does not meet the set conditions, the floating-point number of the quantization node in the input quantization combination node is compared with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error; the quantization loss of each model layer of the first quantization model is determined according to the quantization errors obtained for each quantization combination node; the optimization layer for optimizing the quantization bit width is determined according to the quantization losses of each model layer of the first quantization model; the quantization bit width of the optimization layer is increased, and the quantization parameters of the quantization combination node are re-determined to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions. Therefore, when evaluating the quantization loss of each model layer of the quantization model converted from the original floating-point model, the present application compares and determines the floating-point number of the quantization node corresponding to the model layer of the input quantization model with the floating-point number of the dequantization node corresponding to the output of the model layer. In this way, the quantization loss evaluation of the model layer is only for the current model layer, and the errors caused by the quantization of the model layers before the model layer will not be accumulated, thereby effectively improving the accuracy of the model's quantization error evaluation. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.

[0060] Figure 1 A flowchart of an adaptive quantization method for a deep neural network is shown as an embodiment of the present application;

[0061] Figure 2 A schematic diagram of a quantization combination node setting in an adaptive quantization method for a deep neural network according to an embodiment of the present application;

[0062] Figure 3 A schematic diagram of quantization loss calculation in an adaptive quantization method of a deep neural network shown in one embodiment of the present application;

[0063] Figure 4 A schematic diagram of an adaptive quantization system for a deep neural network is shown as an embodiment of the present application. DETAILED DESCRIPTION

[0064] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0065] refer to Figure 1 , Figure 1 The following is a flow chart of an adaptive quantization method for a deep neural network according to an embodiment of the present application. Figure 1 As shown, the method includes:

[0066] Step S1: Set a quantization combination node for the model layer of the original floating-point model to construct a target floating-point model.

[0067] In this embodiment, an original floating-point model is first created, and the original floating-point model is a deep learning model using floating-point numbers. For the created original floating-point model, a corresponding quantization combination node is set for each model layer in the original floating-point model to construct a target floating-point model corresponding to the original floating-point model, wherein the quantization combination node includes a quantization node and a dequantization node, and the model layer refers to a neural network layer in a deep learning model, such as an input layer, an output layer, and each layer of neurons in a hidden layer in a deep learning model.

[0068] In combination with the above embodiments, in one implementation, the present application embodiment further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, the method further includes steps S01 to S02:

[0069] Step S01: Obtain an assisted driving deep learning model to be deployed on an embedded platform.

[0070] In this embodiment, the assisted driving deep learning model includes but is not limited to obstacle recognition models, path planning models, behavior prediction models, etc. applied in the field of assisted driving. For the qualified trained assisted driving deep learning model, before the assisted driving deep learning model is deployed on the embedded platform, it is first quantized so that it can be deployed on the embedded platform. At this time, the assisted driving deep learning model to be deployed on the embedded platform is first obtained.

[0071] Step S02: Determine the auxiliary driving deep learning model as an original floating point model

[0072] In this embodiment, after the assisted driving deep learning model is obtained, the assisted driving deep learning model is determined as the original floating point model to be quantized. It should be understood that the original floating point model can also be other deep learning models that are intended to be deployed in the embedded platform.

[0073] In combination with the above embodiments, in one implementation, the embodiment of the present application further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, step S1 may include: setting quantization nodes and dequantization nodes after the weights and activation values ​​of the model layer of the original floating-point model, and setting the initial quantization bit width for the quantization nodes to construct a target floating-point model.

[0074] In this embodiment, a quantization combination node is set for the model layer of the original floating-point model to construct an optional implementation of the target floating-point model: the implementation method of setting the quantization combination node for each model layer in the original floating-point model is the same. Here, a model layer is used to set the quantization combination node as an example for explanation. A quantization node is set after each weight in the model layer, and an inverse quantization node is set after the set quantization node. A quantization node is set after each activation value in the model layer, and an inverse quantization node is set after the set quantization node. The quantization node and the inverse quantization node after the same weight constitute a corresponding quantization combination node; the quantization node and the inverse quantization node after the same activation value constitute a corresponding quantization combination node. The same initial quantization bit width is set for each quantization node. The initial quantization bit width is preferably 8 bits. It should be understood that the initial quantization bit width is only a preferred implementation method. The initial quantization bit width can also be other bit widths, which are not specifically limited here, such as 16 bits. After the quantization combination node and the initial quantization bit width are set in the same implementation method for each model layer in the original floating-point model, the target floating-point model is obtained. Figure 2 As shown, Figure 2 Where w represents the weight in the model layer. A quantization node is set after each weight, and an inverse quantization node is set after the set quantization node. A corresponding quantization combination node is formed for the quantization node and the inverse quantization node after a weight. At the same time, in the figure, y=f(w ’ ,x) represents the activation value, a quantization node is set after each activation value, and a dequantization node is set after the set quantization node, and a corresponding quantization combination node is formed for the quantization node and the dequantization node after an activation value.

[0075] Step S2: quantizing the target floating-point model after training using the first data set to determine the quantization parameter of the quantization combination node.

[0076] In this embodiment, after the target floating-point model is constructed through step S1, sample data for training the target floating-point model is prepared to form a first data set, and the constructed target floating-point model is trained through the first data set. After the training is completed, the trained target floating-point model is quantized through a subset of the first data set to determine the quantization parameters of each quantization combination node.

[0077] In this embodiment, when the target floating-point model is a floating-point model obtained by setting a quantization combination node and an initial quantization bit width after the weight and activation value of each model layer, after the training of the target floating-point model is completed, the present application uses a subset of the first data set to calculate the dynamic range of each weight and each activation value in the trained target floating-point model, and determines the quantization parameters of the quantization combination nodes after each weight and the quantization parameters of the quantization combination nodes after each activation value through a first algorithm based on the calculated dynamic range. The expression of the first algorithm for determining the quantization parameters of a single quantization combination node is:

[0078]

[0079] Where s is the quantization step size in the quantization parameter of the quantization combination node; r max 、r min is the maximum and minimum weights (or activation values) obtained by statistically analyzing the dynamic range calculated for the quantized combination node; z is the quantized zero point in the quantized parameter of the quantized combination node; q max ,q min It is the maximum and minimum values ​​of the quantized weight (or activation value) obtained by statistically analyzing the dynamic range calculated by the quantized combination node.

[0080] Step S3: setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a first quantization model.

[0081] In this embodiment, after the quantization parameters of each quantization combination node are determined through step S2, the quantization parameters of the corresponding quantization combination nodes are set according to the determined quantization parameters to obtain a first quantization model. The first quantization model obtained at this time is the quantization model obtained by quantizing the target floating-point model after training.

[0082] For example, assuming that there are 100 quantization combination nodes, the quantization parameters determined for the i-th quantization combination node are the quantization step si and the quantization zero point zi. Therefore, the quantization parameters of the i-th quantization combination node are set according to the determined quantization step si and the quantization zero point zi. After the corresponding quantization parameters are set for the 100 quantization combination nodes, the first quantization model is obtained.

[0083] Step S4: When the performance of the first quantization model does not meet the set conditions, the floating point number of the quantization node in the input quantization combination node is compared with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error.

[0084] In this embodiment, since the quantization processing of the floating-point model is a lossy process, after determining the first quantization model that has been quantized through step S3, the present application performs a performance evaluation on the first quantization model through a test sample data set to determine whether various indicators of the first quantization model meet the set conditions, and the various indicators include but are not limited to accuracy and recall rate. The set conditions can be set according to the scenario and are not specifically limited here. For example, when various indicators include accuracy and recall rate, a corresponding first threshold is set for the accuracy rate and a corresponding second threshold is set for the recall rate. When the accuracy of the first quantization model is greater than the first threshold and the recall rate is greater than the second threshold, it is determined that the performance of the first quantization model meets the set conditions.

[0085] In this embodiment, when the evaluation result obtained by evaluating the first quantization model is that the performance of the first quantization model meets the set conditions, it is determined that the quantization result performance of the first quantization model meets the requirements, and there is no need to perform subsequent steps. At this time, it is determined that the current first quantization model is a quantization model with qualified performance after quantization. When the evaluation result obtained by evaluating the first quantization model is that the performance of the first quantization model does not meet the set conditions, it is determined that the quantization result performance of the first quantization model does not meet the requirements, and the quantization loss of each model layer in the first quantization model is evaluated.

[0086] Specifically, in this embodiment, the implementation method for determining the quantization error of each quantization combination node in the first quantization model is the same, and the determination of the quantization error of a quantization combination node in the first quantization model is used as an example for explanation: the floating point number of the quantization node input into the quantization combination node is compared with the output floating point number of the dequantization node in the quantization combination node to determine the quantization error of the quantization combination node. Based on the same implementation method, a quantization error corresponding to each quantization combination node in the first quantization model can be determined.

[0087] In this embodiment, if Figure 3 As shown, Figure 3 The y in the above is the activation value. The activation value is input into the corresponding quantization node in the quantization combination node for quantization processing to obtain a corresponding value. The value is then dequantized by the dequantization node in the quantization combination node and output as y′. The output y′ is compared with the input y to determine the quantization error of the quantization combination node.

[0088] Step S5: Determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node.

[0089] In this embodiment, after the quantization error of each quantization combination node in the first quantization model is determined through step S4, the corresponding quantization loss is calculated for each model layer through the second algorithm, so as to obtain the quantization loss of each model layer.

[0090] Among them, the expression of the second algorithm for calculating the quantization loss of the model layer is:

[0091]

[0092] Among them, MSE represents the quantization loss of a single model layer, n represents the number of quantization combination nodes corresponding to the single model layer, and y′ i Represents the floating point number output by the dequantization node in the i-th quantization combination node in this single model layer, y i A floating point number representing the input to the quantization node in the i-th quantization combination node in this single model layer.

[0093] Step S6: determining an optimization layer for quantization bit width optimization according to the quantization losses of each model layer of the first quantization model.

[0094] In this embodiment, since the current quantization loss of the model layer is higher, it indicates that the deviation introduced by the quantization error of the model layer after quantization processing is larger under the current quantization bit width of the model layer, and in order to improve the performance of the quantization model, appropriately increasing the quantization bit width for such model layers can better improve the performance of the quantization model. Therefore, after determining the quantization loss of each model layer in the first quantization model through step S5, the present application determines the model layer with higher quantization loss in the first quantization model as the optimization layer for quantization bit width optimization based on the quantization loss of each model layer of the first quantization model. That is, a larger quantization bit width is reset for the optimization layer, so that the quantization degree of the optimization layer is reduced when the model is quantized in the next round (such as increasing the quantization bit width from 8bit to 16bit), thereby reducing the quantization loss introduced by the optimization layer, and then achieving the purpose of improving the performance of the quantization model.

[0095] In combination with the above embodiments, in one implementation, the present application embodiment further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, step S6 may include steps S61 to S62:

[0096] Step S61: Determine the model layer with the largest quantization loss by comparing the quantization losses of each model layer of the first quantization model.

[0097] In this embodiment, after the quantization loss of each model layer in the first quantization model is determined in step S5, the quantization losses of all model layers in the first quantization model are compared to determine a model layer with the largest quantization loss.

[0098] Step S62: Determine the model layer with the largest quantization loss as the optimization layer for quantization bit width optimization.

[0099] In this embodiment, after a model layer with the largest quantization loss in the first quantization model is determined in step S61, the model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

[0100] Step S7: increasing the quantization bit width of the optimization layer, and re-determining the quantization parameters of the quantization combination nodes to construct a new quantization model, until the performance of the constructed new quantization model meets the set conditions.

[0101] In this embodiment, after the optimization layer is determined by step S6, the quantization bit width of the optimization layer in the target floating-point model is increased (such as increasing the quantization bit width from 8 bits to 16 bits), and then the target floating-point model with the quantization bit width of the optimization layer increased is trained and quantized again with the first data set to determine the quantization parameters of each quantization combination node in the current target floating-point model. Then, the quantization parameters of the corresponding quantization combination nodes are set with the newly determined quantization parameters, so as to obtain a new first quantization model. Similarly, the performance of the new first quantization model is evaluated. If the performance of the new first quantization model meets the set conditions, there is no need to perform subsequent steps. If the performance of the new first quantization model does not meet the set conditions, the quantization loss of each model layer in the new first quantization model is determined. The specific method for determining the quantization loss is the same as the above-mentioned implementation method: compare the floating point number of the quantization node in the quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain the quantization error of the quantization combination node; then calculate the quantization error of all quantization combination nodes in the same model layer through the second algorithm to obtain the quantization loss of the same model layer, thereby calculating a quantization loss corresponding to itself for each model layer in the new first quantization model. Then, based on the quantization loss of each model layer in the new first quantization model, determine the model layer with the largest quantization loss as the optimization layer, and finally increase the quantization bit width for the currently determined optimization layer in the target floating point model, and then use the first data set again to train and quantize the target floating point model with the quantization bit width of the optimization layer added, determine the quantization parameters of each quantization combination node in the current target floating point model and the processing of subsequent steps, and repeat until the performance of the obtained new first quantization model meets the set conditions.

[0102] In combination with the above embodiments, in one implementation, the embodiment of the present application further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, increasing the quantization bit width of the optimization layer in step S7 may include steps S71 to S73:

[0103] Step S71: Compare the quantization loss of the optimization layer with a set threshold to obtain a comparison result.

[0104] In this embodiment, the quantization loss of the optimization layer determined in step S6 may be different in different situations. In order to improve the quantization efficiency of the quantization processing of the model, the present application increases the quantization bit width corresponding to different quantization losses. Specifically, the quantization loss of the determined optimization layer is compared with the set threshold to obtain the corresponding comparison result. Among them, the value of the set threshold can be set according to the actual application scenario, and is not specifically limited here.

[0105] Step S72: Determine the amount of increase in the quantization bit width of the optimization layer according to the comparison result.

[0106] In this embodiment, based on the comparison result obtained in step S71, the magnitude of the increase in the quantization bit width of the optimization layer determined in step S6 is determined. The greater the quantization loss of the optimization layer, the greater the magnitude of the increase in the quantization bit width of the optimization layer.

[0107] Step S73: increasing the quantization bit width of the optimization layer according to the amplitude.

[0108] In this embodiment, after the amplitude of increasing the quantization bit width of the optimization layer is determined in step S72, the quantization bit width of the optimization layer is increased by the amplitude.

[0109] In combination with the above embodiments, in one implementation, the present application embodiment further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, step S72 may include steps S721 to S722:

[0110] Step S721: when the comparison result is that the quantization loss is less than or equal to the set threshold, determine to increase the quantization bit width of the optimization layer by a single amplitude.

[0111] In this embodiment, when the comparison result obtained through step S71 is that the quantization loss of the optimization layer is less than or equal to the set threshold, it is determined that the quantization bit width of the optimization layer is increased by a single amplitude. For example, if the current quantization bit width of the optimization layer is 8 bits, and the comparison result obtained through step S71 is that the quantization loss of the optimization layer is less than or equal to the set threshold, it is determined that the quantization bit width of the optimization layer is increased by a single amplitude, that is, increased to 16 bits; if the current quantization bit width of the optimization layer is 16 bits, and the comparison result obtained through step S71 is that the quantization loss of the optimization layer is less than or equal to the set threshold, it is determined that the quantization bit width of the optimization layer is increased by a single amplitude, that is, increased to 32 bits.

[0112] Step S722: when the comparison result is that the quantization loss is greater than the set threshold, determine to increase the quantization bit width of the optimization layer by multiple times.

[0113] In this embodiment, when the comparison result obtained in step S71 is that the quantization loss of the optimization layer is greater than the set threshold, it is determined that the quantization bit width of the optimization layer is increased by multiple times, and the multiple increase is preferably a double increase. For example, the current quantization bit width of the optimization layer is 8 bits, and when the comparison result obtained in step S71 is that the quantization loss of the optimization layer is less than or equal to the set threshold, it is determined that the quantization bit width of the optimization layer is increased by a single amount, that is, increased to 32 bits.

[0114] An adaptive quantization method for a deep neural network provided in an embodiment of the present application comprises the following steps: firstly, a quantization combination node is set for a model layer of an original floating-point model to construct a target floating-point model; the constructed target floating-point model is quantized after training using a first data set to determine the quantization parameters of the quantization combination node; the quantization parameters of the quantization combination node are set using the quantization parameters to obtain a first quantization model; when the performance of the first quantization model does not meet the set conditions, the floating-point number of the quantization node in the input quantization combination node is compared with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error; the quantization loss of each model layer of the first quantization model is determined according to the quantization errors obtained for each quantization combination node; the optimization layer for optimizing the quantization bit width is determined according to the quantization losses of each model layer of the first quantization model; the quantization bit width of the optimization layer is increased, and the quantization parameters of the quantization combination node are re-determined to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions. Therefore, when evaluating the quantization loss of each model layer of the quantization model converted from the original floating-point model, the present application compares and determines the floating-point number of the quantization node corresponding to the model layer of the input quantization model with the floating-point number of the dequantization node corresponding to the output of the model layer. In this way, the quantization loss evaluation of the model layer is only for the current model layer, and the errors caused by the quantization of the model layers before the model layer will not be accumulated, thereby effectively improving the accuracy of the model's quantization error evaluation.

[0115] In combination with the above embodiments, in one implementation, the embodiment of the present application further provides an adaptive quantization method for a deep neural network. In the adaptive quantization method for a deep neural network, before step S6, the method further includes steps S061 to S065:

[0116] Step S061: according to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule is determined as an initial optimization layer;

[0117] In this embodiment, Quantization-Aware Training (QAT) is a training method that introduces quantization constraints during the training of deep learning models. By simulating the errors caused by quantization operations during the training process, the model can maintain a high accuracy after quantization, but the training of quantization-aware training is slow and inefficient. In order to maintain the accuracy of the model after quantization, the present application introduces quantization-aware training to quantize the target floating-point model. In order to further improve the quantization efficiency of introducing quantization-aware training to quantize the target floating-point model, the present application first quantizes the target floating-point model after training with a small amount of data, and then selects some model layers with large quantization losses and increases the quantization bit width at the same time, so that when quantization-aware training is subsequently introduced to quantize the target floating-point model, the number of quantization-aware training can be reduced, thereby achieving the purpose of improving the training efficiency of the entire quantization-aware training.

[0118] Specifically, in the case where the adaptive quantization method for a deep neural network provided by the present application also includes steps S061 to S065, the implementation method of steps S1 to S5 in the adaptive quantization method for a deep neural network provided by the present application is the same as the above implementation method, except that for the first data set in step S2, the target floating-point model is trained and quantized using the first data set composed of a small amount of sample data. Then, after the quantization loss of each model layer of the first quantization model is determined through step S5, based on the preset screening rules, some model layers in the first quantization model whose quantization loss satisfies the preset screening rules and whose quantization loss is relatively large are determined as initial optimization layers.

[0119] In the present application, step S061 may include: sorting all model layers of the first quantization model based on the quantization loss to obtain a sorting result; and according to the sorting result, determining a preset percentage of model layers that are ranked top as initial optimization layers.

[0120] In this embodiment, another implementation method for step S061 is: after determining the quantization loss of each model layer of the first quantization model through step S5, all model layers in the first quantization model are sorted according to the quantization loss, and the model layers with the highest quantization loss are placed at the front to obtain the corresponding sorting result. Then, based on the sorting result, the model layers with a preset percentage of the top ranking are determined as the initial optimization layers. Among them, the preset percentage can be set according to the actual application scenario, and is not specifically limited here, such as taking the preset percentage as 10%.

[0121] In the present application, step S061 may include: determining a preset quantization loss threshold; and determining each model layer in the first quantization model whose quantization loss is greater than the preset quantization loss threshold as an initial optimization layer.

[0122] In this embodiment, another implementation method for step S061 is: after determining the quantization loss of each model layer of the first quantization model through step S5, a preset quantization loss threshold is determined, and then each model layer whose quantization loss is greater than the preset quantization loss threshold among all model layers in the first quantization model is determined as an initial optimization layer. The value of the preset quantization loss threshold can be set according to the actual application scenario and is not specifically limited here.

[0123] Step S062: increasing the quantization bit width of the initial optimization layer, and performing quantization-aware training on the target floating-point model currently undergoing quantization bit width increase through a second data set to determine quantization parameters of quantization combination nodes.

[0124] In this embodiment, after some initial optimization layers in the first quantization model are determined through step S062, the quantization bit width of these initial optimization layers in the target floating-point model is increased (such as increasing the quantization bit width of the determined 10 initial optimization layers from 8 bits to 16 bits), and then quantization-aware training is performed on the target floating-point model in which the quantization bit width of the initial optimization layers has been increased using a second data set including a large amount of sample data. After the quantization-aware training, the quantization parameters of each quantization combination node in the current target floating-point model are determined.

[0125] Step S063: setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a second quantization model.

[0126] In this embodiment, after the quantization parameters of each quantization combination node in the target floating-point model are determined through step S062, the quantization parameters of the corresponding quantization combination nodes are set according to the determined quantization parameters to obtain a second quantization model. The second quantization model obtained at this time is the quantization model obtained by quantizing the target floating-point model after the quantization perception training is completed.

[0127] Step S064: When the performance of the second quantization model does not meet the set conditions, the floating-point number of the quantization node in the input quantization combination node is compared with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error.

[0128] In this embodiment, after the second quantization model is determined through step S063, the present application performs a performance evaluation on the second quantization model through a test sample data set to determine whether various indicators of the second quantization model meet the set conditions, and the various indicators include but are not limited to accuracy and recall rate. The set conditions can be set according to the scenario and are not specifically limited here. For example, when various indicators involve accuracy and recall rate, a corresponding first threshold is set for the accuracy rate and a corresponding second threshold is set for the recall rate. When the accuracy of the first quantization model is greater than the first threshold and the recall rate is greater than the second threshold, it is determined that the performance of the second quantization model meets the set conditions.

[0129] In this embodiment, when the evaluation result obtained by evaluating the second quantization model is that the performance of the second quantization model meets the set conditions, it is determined that the quantization result performance of the second quantization model meets the requirements, and there is no need to perform subsequent steps. At this time, it is determined that the current second quantization model is a quantization model with qualified performance after quantization. When the evaluation result obtained by evaluating the second quantization model is that the performance of the second quantization model does not meet the set conditions, it is determined that the quantization result performance of the second quantization model does not meet the requirements, and the quantization loss of each model layer in the second quantization model is evaluated.

[0130] Specifically, in this embodiment, the implementation method for determining the quantization error of each quantization combination node in the second quantization model is the same, and the determination of the quantization error of a quantization combination node in the second quantization model is used as an example for explanation: the floating point number of the quantization node input into the quantization combination node is compared with the output floating point number of the dequantization node in the quantization combination node to determine the quantization error of the quantization combination node. Based on the same implementation method, a quantization error corresponding to each quantization combination node in the second quantization model can be determined.

[0131] Step S065: Determine the quantization loss of each model layer of the second quantization model according to the obtained quantization errors of each quantization combination node.

[0132] In this embodiment, after the quantization error of each quantization combination node in the second quantization model is determined through step S064, the corresponding quantization loss is calculated for each model layer through the second algorithm, so as to obtain the quantization loss of each model layer.

[0133] Among them, the expression of the second algorithm for calculating the quantization loss of the model layer is:

[0134]

[0135] Among them, MSE represents the quantization loss of a single model layer, n represents the number of quantization combination nodes corresponding to the single model layer, and y′ i Represents the floating point number output by the dequantization node in the i-th quantization combination node in this single model layer, y i A floating point number representing the input to the quantization node in the i-th quantization combination node in this single model layer.

[0136] In the present application, in a case where an adaptive quantization method for a deep neural network provided in the present application also includes steps S061 to S065, step S6 includes: determining an optimization layer for quantization bit width optimization according to the quantization loss of each model layer of the second quantization model.

[0137] In this embodiment, since the current quantization loss of the model layer is higher, it indicates that the deviation introduced by the quantization error of the model layer after quantization processing is greater under the current quantization bit width of the model layer, and in order to improve the performance of the quantization model, appropriately increasing the quantization bit width for this type of model layer can better improve the performance of the quantization model. Therefore, after determining the quantization loss of each model layer in the second quantization model through step S065, the present application executes step S6. In this embodiment, the implementation method of step S6 is: based on the quantization loss of each model layer of the second quantization model, the model layer with higher quantization loss in the second quantization model is determined as the optimization layer for quantization bit width optimization. That is, a larger quantization bit width is set for the optimization layer, so that the quantization degree of the optimization layer is reduced when the model is trained for quantization perception in the next round (such as increasing the quantization bit width from 8bit to 16bit), thereby reducing the quantization loss introduced by the optimization layer, and then achieving the purpose of improving the performance of the quantization model.

[0138] In the present application, an optimization layer for quantization bit width optimization is determined based on the quantization loss of each model layer of the second quantization model, including: determining the model layer with the largest quantization loss by comparing the quantization losses of each model layer of the second quantization model; and determining the model layer with the largest quantization loss as the optimization layer for quantization bit width optimization.

[0139] In this embodiment, after the quantization loss of each model layer in the second quantization model is determined through step S065, the quantization losses of all model layers in the second quantization model are compared to determine the model layer with the largest quantization loss, and then the model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

[0140] In the present application, in a case where an adaptive quantization method for a deep neural network provided in the present application also includes steps S061 to S065, step S7 includes: setting the quantization bit width of the optimization layer, and re-performing quantization-aware training on the target floating-point model currently undergoing quantization bit width increase through the second data set, determining the quantization parameters of the quantization combination nodes, and constructing a new quantization model.

[0141] In this embodiment, after the quantization loss of each model layer in the second quantization model is determined by step S065, the quantization losses of all model layers in the second quantization model are compared to determine a model layer with the largest quantization loss, and then the model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization, and the quantization bit width of the optimization layer in the target floating-point model is increased (such as increasing the quantization bit width from 8 bits to 16 bits), and then the target floating-point model with the quantization bit width increased by the second data set is again trained for quantization perception, and the quantization parameters of each quantization combination node in the current target floating-point model are determined. Then, the quantization parameters of the corresponding quantization combination nodes are set with the newly determined quantization parameters, so as to obtain a new second quantization model. Similarly, the performance of the new second quantization model is evaluated. If the performance of the new second quantization model meets the set conditions, there is no need to perform subsequent steps. If the performance of the new second quantization model does not meet the set conditions, the quantization loss of each model layer in the new second quantization model is determined. The specific method for determining the quantization loss is the same as the above-mentioned implementation method: compare the floating point number of the quantization node in the quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain the quantization error of the quantization combination node; then calculate the quantization error of all quantization combination nodes in the same model layer through the second algorithm to obtain the quantization loss of the same model layer, thereby calculating a quantization loss corresponding to itself for each model layer in the new second quantization model. Then, based on the quantization loss of each model layer in the new second quantization model, determine the model layer with the largest quantization loss as the optimization layer, and finally increase the quantization bit width of the currently determined optimization layer in the target floating point model, and then use the second data set again to train and quantize the target floating point model with the quantization bit width of the optimization layer added, determine the quantization parameters of each quantization combination node in the current target floating point model and the processing of subsequent steps, and repeat until the performance of the obtained new second quantization model meets the set conditions.

[0142] In this embodiment, the increase in the quantization bit width of the optimization layer in the target floating-point model can be achieved by comparing the quantization loss of the optimization layer with a set threshold, and determining whether to increase the quantization bit width by a single factor or by a multiple factor based on the comparison result.

[0143] For an adaptive quantization method for a deep neural network provided in the present application, an optional implementation method is: first, a quantization combination node is set for a model layer of an original floating-point model to construct a target floating-point model; the constructed target floating-point model is trained and quantized by a first data set to determine the quantization parameters of the quantization combination node; the quantization parameters of the quantization combination node are set by the quantization parameter to obtain a first quantization model; when the performance of the first quantization model does not meet the set conditions, the floating-point number of the quantization node in the input quantization combination node is compared with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error; according to the quantization errors of the obtained quantization combination nodes, the quantization loss of each model layer of the first quantization model is determined;

[0144] According to the quantization loss of each model layer of the first quantization model, determine the optimization layer for quantization bit width optimization; increase the quantization bit width of the optimization layer, and re-determine the quantization parameters of the quantization combination nodes to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions. Therefore, when evaluating the quantization loss of each model layer of the quantization model converted from the original floating-point model, the present application compares and determines the floating-point number of the quantization node corresponding to the model layer of the input quantization model with the floating-point number of the dequantization node corresponding to the output of the model layer. In this way, the quantization loss evaluation of the model layer is only for the current model layer, and the errors generated by the quantization of the model layer before the model layer will not be accumulated, thereby effectively improving the accuracy of the quantization error evaluation of the model.

[0145] Another optional implementation is: first, set a quantization combination node for the model layer of the original floating-point model to construct a target floating-point model; train and quantize the constructed target floating-point model through a first data set composed of a small amount of sample data to determine the quantization parameters of the quantization combination nodes; set the quantization parameters of the corresponding quantization combination nodes through the determined quantization parameters to obtain a first quantization model; when the performance of the first quantization model does not meet the set conditions, compare the floating-point number of the quantization node in the input quantization combination node with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error; determine the quantization loss of each model layer of the first quantization model based on the quantization errors obtained for each quantization combination node; determine each model layer in the first quantization model whose quantization loss meets the preset screening rules as an initial optimization layer based on the preset screening rules; increase the quantization bit width of each initial optimization layer, and use the second data set to compare the current optimization layer. The target floating-point model with increased quantization bit width is subjected to quantization-aware training to determine the quantization parameters of the quantization combination nodes; the quantization parameters of the corresponding quantization combination nodes are set by the determined quantization parameters to obtain a second quantization model; when the performance of the second quantization model does not meet the set conditions, the floating-point number of the quantization node in the input quantization combination node is compared with the floating-point number output by the dequantization node in the quantization combination node to obtain a quantization error; according to the quantization errors obtained for each quantization combination node, the quantization loss of each model layer of the second quantization model is determined; according to the quantization loss of each model layer of the second quantization model, the optimization layer for quantization bit width optimization is determined; the quantization bit width of the optimization layer is set, and the target floating-point model currently undergoing quantization bit width increase is subjected to quantization-aware training again by the second data set to determine the quantization parameters of the quantization combination nodes to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions. Therefore, the target floating-point model is first trained with a small amount of data and then quantized. Then, some model layers with larger quantization loss are selected and the quantization bit width is increased. Therefore, when quantization-aware training is subsequently introduced to quantize the target floating-point model, the number of quantization-aware training can be reduced, thereby improving the training efficiency of the entire quantization-aware training.

[0146] Based on the same inventive concept, an embodiment of the present application provides a system for adaptive quantization of a deep neural network, such as Figure 4 As shown, the system 400 includes:

[0147] The floating-point model construction module 401 is used to set a quantization combination node for the model layer of the original floating-point model to construct a target floating-point model;

[0148] A first quantization parameter determination module 402, configured to perform post-training quantization on the target floating-point model using a first data set to determine a quantization parameter of the quantization combination node;

[0149] A first quantization model determination module 403 is used to set the quantization parameter of the quantization combination node by using the quantization parameter to obtain a first quantization model;

[0150] A first quantization error determination module 404 is used to compare the floating point number of the quantization node in the input quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error when the performance of the first quantization model does not meet the set conditions;

[0151] A first quantization loss determination module 405, configured to determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node;

[0152] An optimization layer determination module 406, configured to determine an optimization layer for performing quantization bit width optimization according to the quantization loss of each model layer of the first quantization model;

[0153] The second quantization parameter determination module 407 is used to increase the quantization bit width of the optimization layer and re-determine the quantization parameters of the quantization combination nodes to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions.

[0154] Optionally, the second quantization parameter determining module 407 includes:

[0155] A first comparison module, used to compare the quantization loss of the optimization layer with a set threshold to obtain a comparison result;

[0156] An amplitude determination module, used to determine an amplitude of increasing the quantization bit width of the optimization layer according to the comparison result;

[0157] The quantization bit width increasing module is used to increase the quantization bit width of the optimization layer according to the amplitude.

[0158] Optional, amplitude determination module, including:

[0159] A first amplitude determination module, configured to determine, when the comparison result shows that the quantization loss is less than or equal to the set threshold, to increase the quantization bit width of the optimization layer by a single amplitude;

[0160] The second amplitude determination module is used to determine whether to increase the quantization bit width of the optimization layer by multiple times when the comparison result shows that the quantization loss is greater than the set threshold.

[0161] Optionally, the optimization layer determination module 406 includes:

[0162] A second comparison module is used to determine the model layer with the largest quantization loss by comparing the quantization losses of each model layer of the first quantization model;

[0163] The optimization layer determination submodule is used to determine the model layer with the largest quantization loss as the optimization layer for quantization bit width optimization.

[0164] Optionally, the floating-point model construction module 401 is used to set quantization nodes and dequantization nodes for the weights and activation values ​​of the model layer of the original floating-point model, and set an initial quantization bit width for the quantization nodes to construct a target floating-point model.

[0165] Optionally, the system further includes:

[0166] An initial optimization layer determination module, used to determine, according to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule as an initial optimization layer;

[0167] A third quantization parameter determination module is used to increase the quantization bit width of the initial optimization layer, and perform quantization perception training on the target floating-point model currently undergoing quantization bit width increase through the second data set to determine the quantization parameter of the quantization combination node;

[0168] A second quantization model determination module, configured to set quantization parameters for the quantization combination node using the quantization parameters to obtain a second quantization model;

[0169] A second quantization error determination module is used to compare the floating point number of the quantization node in the input quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error when the performance of the second quantization model does not meet the set conditions;

[0170] A second quantization loss determination module, used to determine the quantization loss of each model layer of the second quantization model according to the obtained quantization errors of each quantization combination node;

[0171] The optimization layer determination module 406 is used to determine the optimization layer for quantization bit width optimization according to the quantization loss of each model layer of the second quantization model.

[0172] Optionally, the second quantization parameter determination module is used to set the quantization bit width of the optimization layer, and re-perform quantization-aware training on the target floating-point model whose quantization bit width is currently increased through the second data set to determine the quantization parameters of the quantization combination nodes to construct a new quantization model.

[0173] Optionally, the optimization layer determination module 406 includes:

[0174] A third comparison module is used to determine the model layer with the largest quantization loss by comparing the quantization losses of each model layer of the second quantization model;

[0175] The first optimization layer determination module is used to determine the model layer with the largest quantization loss as the optimization layer for quantization bit width optimization.

[0176] Optionally, the initial optimization layer determination module includes:

[0177] A sorting module, used to sort all model layers of the first quantization model based on the quantization loss to obtain a sorting result;

[0178] The first initial optimization layer determination module is used to determine a preset percentage of model layers ranked top as initial optimization layers according to the sorting result.

[0179] Optionally, the initial optimization layer determination module includes:

[0180] A preset quantization loss threshold determination module, used to determine a preset quantization loss threshold;

[0181] The second initial optimization layer determination module is used to determine each model layer in the first quantization model whose quantization loss is greater than the preset quantization loss threshold as an initial optimization layer.

[0182] Optionally, the system 400 further includes:

[0183] Model acquisition model, used to acquire the assisted driving deep learning model to be deployed on the embedded platform;

[0184] The model determination module is used to determine the auxiliary driving deep learning model as an original floating-point model.

[0185] Based on the same inventive concept, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and running on the processor. When the computer program is executed by the processor, it implements the steps in the adaptive quantization method of a deep neural network as described in the first aspect of the present application.

[0186] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the adaptive quantization method of a deep neural network as described in the first aspect of the present application are implemented.

[0187] As for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0188] It should be noted that, for the method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.

[0189] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0190] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the embodiments of the present application may adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the embodiments of the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0191] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0192] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0193] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0194] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.

[0195] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0196] The above is a detailed introduction to the adaptive quantization method, system and product of a deep neural network provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. An adaptive quantization method for a deep neural network, characterized in that: The method comprises: Set a quantization combination node for the model layer of the original floating-point model to build a target floating-point model; Performing post-training quantization on the target floating-point model using a first data set to determine a quantization parameter of the quantization combination node; Setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a first quantization model; When the performance of the first quantization model does not meet the set conditions, the floating point number of the quantization node in the input quantization combination node is compared with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error; Determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node; Determining an optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model; The quantization bit width of the optimization layer is increased, and the quantization parameters of the quantization combination nodes are re-determined to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions.

2. The method for adaptive quantization of a deep neural network according to claim 1, characterized in that: Increasing the quantization bit width of the optimization layer includes: Comparing the quantization loss of the optimization layer with a set threshold to obtain a comparison result; According to the comparison result, determining an increase range of the quantization bit width of the optimization layer; According to the amplitude, the quantization bit width of the optimization layer is increased.

3. The method for adaptive quantization of a deep neural network according to claim 2, characterized in that: Determining, according to the comparison result, an increase in the quantization bit width of the optimization layer includes: When the comparison result shows that the quantization loss is less than or equal to the set threshold, determining to increase the quantization bit width of the optimization layer by a single amplitude; When the comparison result shows that the quantization loss is greater than the set threshold, it is determined to increase the quantization bit width of the optimization layer by multiple times.

4. The method for adaptive quantization of a deep neural network according to claim 1, characterized in that: Determining an optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model includes: By comparing the quantization losses of each model layer of the first quantization model, determining the model layer with the largest quantization loss; The model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

5. The method for adaptive quantization of a deep neural network according to claim 1, characterized in that: Set the quantization combination node for the model layer of the original floating-point model and build the target floating-point model, including: The weights and activation values ​​of the model layers of the original floating-point model are then followed by setting quantization nodes and dequantization nodes, and initial quantization bit widths are set for the quantization nodes to construct a target floating-point model.

6. The method for adaptive quantization of a deep neural network according to claim 1, characterized in that: Before determining the optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model, the method further includes: According to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule is determined as an initial optimization layer; Increasing the quantization bit width of the initial optimization layer, and performing quantization-aware training on the target floating-point model currently undergoing quantization bit width increase through a second data set to determine a quantization parameter of a quantization combination node; Setting the quantization parameters of the quantization combination node by using the quantization parameters to obtain a second quantization model; When the performance of the second quantization model does not meet the set conditions, the floating point number of the quantization node in the input quantization combination node is compared with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error; Determining the quantization loss of each model layer of the second quantization model according to the obtained quantization errors of each quantization combination node; The step of determining the optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the first quantization model includes: An optimization layer for performing quantization bit width optimization is determined according to the quantization losses of each model layer of the second quantization model.

7. The method for adaptive quantization of a deep neural network according to claim 6, characterized in that: Increasing the quantization bit width of the optimization layer and re-determining the quantization parameters of the quantization combination node to construct a new quantization model, including: The quantization bit width of the optimization layer is set, and the target floating-point model currently undergoing quantization bit width increase is retrained with the second data set to determine the quantization parameters of the quantization combination nodes so as to construct a new quantization model.

8. The method for adaptive quantization of a deep neural network according to claim 6, characterized in that: Determining an optimization layer for performing quantization bit width optimization according to the quantization losses of each model layer of the second quantization model includes: By comparing the quantization losses of each model layer of the second quantization model, determining the model layer with the largest quantization loss; The model layer with the largest quantization loss is determined as the optimization layer for quantization bit width optimization.

9. The method for adaptive quantization of a deep neural network according to claim 6, characterized in that: According to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule is determined as an initial optimization layer, including: Sorting all model layers of the first quantization model based on the quantization loss to obtain a sorting result; According to the ranking result, a preset percentage of model layers ranked top are determined as initial optimization layers.

10. The method for adaptive quantization of a deep neural network according to claim 6, characterized in that: According to a preset screening rule, each model layer in the first quantization model whose quantization loss satisfies the preset screening rule is determined as an initial optimization layer, including: Determining a preset quantitative loss threshold; Each model layer in the first quantization model whose quantization loss is greater than the preset quantization loss threshold is determined as an initial optimization layer.

11. The method for adaptive quantization of a deep neural network according to claim 1, characterized in that: The method further comprises: Obtaining deep learning models for driver assistance that will be deployed on embedded platforms; The assisted driving deep learning model is determined as an original floating-point model.

12. An adaptive quantization system for a deep neural network, characterized in that: The system comprises: A floating-point model building module is used to set quantization combination nodes for the model layer of the original floating-point model to build a target floating-point model; A first quantization parameter determination module, configured to perform post-training quantization on the target floating-point model using a first data set to determine a quantization parameter of the quantization combination node; A first quantization model determination module, configured to set quantization parameters for the quantization combination node using the quantization parameters to obtain a first quantization model; A first quantization error determination module is used to compare the floating point number of the quantization node in the input quantization combination node with the floating point number output by the dequantization node in the quantization combination node to obtain a quantization error when the performance of the first quantization model does not meet the set conditions; A first quantization loss determination module, used to determine the quantization loss of each model layer of the first quantization model according to the obtained quantization errors of each quantization combination node; An optimization layer determination module, used to determine an optimization layer for performing quantization bit width optimization according to the quantization loss of each model layer of the first quantization model; The second quantization parameter determination module is used to increase the quantization bit width of the optimization layer and re-determine the quantization parameters of the quantization combination nodes to construct a new quantization model until the performance of the constructed new quantization model meets the set conditions.

13. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and running on the processor, wherein the computer program, when executed by the processor, implements the steps in the adaptive quantization method for a deep neural network as described in any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps in the adaptive quantization method for a deep neural network as described in any one of claims 1 to 11.