Method and device for improving precision of model quantification
By separately calculating and sorting the quantization errors of each layer in the neural network, and restoring the floating point layer according to the error value, the problem of indirect error gradient propagation and slow training speed in the traditional method is solved, and the rapid optimization and optimization of the model quantification accuracy are achieved. Improvement of computational efficiency.
Patent Information
- Application Number
- CN202310391219.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-12
- Publication Date
- 2024-10-18
AI Technical Summary
In the process of model quantification, the traditional method is difficult to effectively find the quantization layer that has a large impact on the error of the model results because the error gradient propagation is not direct, the training speed is slow, and there is a risk of overfitting.
By obtaining the cumulative raw output of the floating-point model, each layer is individually selected and quantified, the error value is calculated and sorted, and the floating-point layers are restored from high to low according to the error value until the difference is less than the preset loss threshold to form an optimized hybrid model. .
It can quickly find and recover the quantization layer that has a large error in the result, optimize the model accuracy, make the calculation faster, avoid the risk of over-fitting, and is suitable for networks with convolutional layers and batch normalization layers.
Smart Images

Figure CN118798267A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of neural network models, and in particular to a method and device for improving the accuracy of model quantization. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the present application as recited in the claims. The description herein is not admitted to be prior art as disclosed by virtue of its inclusion in this section.
[0003] Mixed precision optimization means that during the model quantization process, some network layers use low precision, which causes relatively large errors in the results. These network layers need to be restored to high precision such as FP32 or FP16 for calculation to ensure that the error of the final result of the model is within an acceptable range. Therefore, the task of mixed precision optimization is to find which quantized network layers have a greater impact on the error of the results.
[0004] The error generated by the quantization of each layer of convolution or matrix multiplication parameters, due to the high-dimensional nonlinear characteristics of the neural network, the error is transmitted layer by layer, and the influence of the quantization error from other layers makes it impossible to directly calculate the impact of the quantization error of each layer on the final result. The more effective traditional method is to use the error back propagation method to determine the error gradient of each quantization layer on the result. After multiple trainings with a small amount of data, the quantization layer with a greater impact on the result error is finally found. This method has the following disadvantages: 1) The error gradient propagation is not direct. Because it is a training method, many hyperparameters need to be set. Moreover, due to the unanalyzability of the neural network, it cannot be guaranteed that the training converges to the optimal state, and there is a risk of overfitting. 2) The training speed is relatively slow, and it requires multiple batch data inferences, as well as gradient back propagation and parameter updates. Summary of the invention
[0005] The purpose of this application is to provide a method and device for improving the accuracy of model quantization, which can quickly find which network layers have large errors in the results after quantization, and restore them, thereby optimizing the accuracy of the hybrid model.
[0006] The present application discloses a method for improving the accuracy of model quantization, comprising:
[0007] Obtaining a floating point model, the floating point model having a plurality of floating point layers, and calculating the cumulative raw outputs of all floating point layers of the floating point model;
[0008] Selecting a floating point layer in the floating point model separately for quantization to form a hybrid model including a quantized layer, and calculating the error of the cumulative output of all layers in the hybrid model relative to the cumulative original output;
[0009] sorting the calculated error values; and
[0010] All floating-point layers of the floating-point model are quantized, and the corresponding quantized layers are restored to floating-point layers one by one in the order of error values from high to low, and the difference between the cumulative output of all layers of the restored model and the cumulative original output is calculated until the difference is less than the preset loss threshold to obtain the target hybrid model.
[0011] In a preferred example, the floating-point model further includes a batch normalization layer, which is located after the floating-point layer and is used to normalize the output of the floating-point layer.
[0012] In a preferred example, before quantizing all floating-point number layers of the floating-point model, the method further comprises: removing the last normalized exponential function layer of the floating-point model.
[0013] In a preferred example, after the difference is less than a preset loss threshold, the method further includes: adding a normalized exponential function layer to the target mixture model as the last layer of the target mixture model.
[0014] In a preferred example, the data format of the floating point layer is: floating point type FP32 or floating point type FP16.
[0015] The present application also discloses a device for improving the accuracy of model quantization, including:
[0016] An acquisition module, used for acquiring a floating point model, the floating point model having a plurality of floating point layers, and calculating the accumulated original outputs of all floating point layers of the floating point model;
[0017] A quantization module, used for individually selecting a floating point layer in the floating point model for quantization to form a hybrid model including a quantization layer, and calculating an error of the cumulative output of all layers in the hybrid model relative to the cumulative original output;
[0018] A sorting module, used for sorting the calculated error values; and
[0019] The recovery module is used to quantize all the floating-point layers of the floating-point model, restore the corresponding quantized layers to floating-point layers one by one in the order of error values from high to low, and calculate the difference between the cumulative output of all layers of the restored model and the cumulative original output until the difference is less than a preset loss threshold, so as to obtain the target hybrid model.
[0020] In a preferred example, the floating-point model further includes a batch normalization layer, which is located after the floating-point layer and is used to normalize the output of the floating-point layer.
[0021] In a preferred example, before quantizing all floating-point number layers of the floating-point model, the recovery module further includes: removing the last normalized exponential function layer of the floating-point model.
[0022] In a preferred example, the recovery module is further used to add a normalized exponential function layer to the target mixture model as the last layer of the target mixture model after the difference is less than a preset loss threshold.
[0023] In a preferred example, the data format of the floating point layer is: floating point type FP32 or floating point type FP16.
[0024] The embodiments of the present application have the following beneficial effects:
[0025] 1) The present invention separately calculates the error caused by each quantization layer to the final result to screen out the quantization layer that has a greater impact on the final result, and restores the quantization layer that has a greater impact on the final result to the original floating-point layer, thereby obtaining an optimized target mixed model. Compared with the traditional error back-propagation method, this calculation method is faster and can directly correspond to the final result, so the optimal target mixed model can be selected more intuitively. 2) The present invention has a wide range of applicability. As long as the network layer is a fusion of the convolution layer and the batch normalization layer, this method can be applied. In practical applications, most cases meet this condition.
[0026] The specification of the present application records a large number of technical features, which are distributed in various technical solutions. If all possible combinations of technical features of the present application (i.e., technical solutions) are to be listed, the specification will be too long. In order to avoid this problem, the various technical features disclosed in the above-mentioned invention content of the present application, the various technical features disclosed in the various embodiments and examples below, and the various technical features disclosed in the accompanying drawings can be freely combined with each other to form various new technical solutions (these technical solutions should all be regarded as having been recorded in this specification), unless the combination of such technical features is technically infeasible. For example, in one example, feature A+B+C is disclosed, and in another example, feature A+B+D+E is disclosed, and features C and D are equivalent technical means that play the same role. Technically, only one can be used, and it is impossible to use them at the same time. Feature E can be combined with feature C technically. Then, the solution of A+B+C+D should not be regarded as having been recorded because it is technically infeasible, and the solution of A+B+C+E should be regarded as having been recorded. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a flowchart of a method for improving the accuracy of model quantization according to the first embodiment of the present application.
[0028] Figure 2 The figure shows the quantization error of the subsequent network layers after the Mobilenet_v2 model quantizes each layer in one embodiment of the present application.
[0029] Figure 3 The figure shows the quantization error of the subsequent network layers after the Resnet50 model quantizes each layer in one embodiment of the present application.
[0030] Figure 4 It shows that in one embodiment of the present application, the Mobilenet_v2 model quantizes each layer and then quantizes the quantization error of the network layer of the last layer separately.
[0031] Figure 5 It shows that in one embodiment of the present application, the shufflenet_v2_x1_0 model quantizes each layer and then quantizes the quantization error of the network layer of the last layer separately.
[0032] Figure 6 and Figure 7 The quantization errors of vgg16 without BN and with BN in one embodiment of the present application are respectively shown.
[0033] Figure 8 and Fig. 9 The quantization errors of the Mobilenet_v2 model without softmax and with softmax in one embodiment of the present application are respectively shown.
[0034] Fig.10 It is a schematic diagram of the structure of a device for improving the accuracy of model quantization according to the second embodiment of the present application. DETAILED DESCRIPTION
[0035] In the following description, many technical details are provided to help readers better understand the present application. However, those skilled in the art can understand that the technical solution claimed in the present application can be implemented even without these technical details and various changes and modifications based on the following embodiments.
[0036] Description of some concepts:
[0037] FP32 is a single-precision floating point number, which uses 8 bits to represent the exponent and 23 bits to represent the decimal, occupying 4 bytes.
[0038] FP16 is a half-precision floating point number, which uses 5 bits to represent the exponent and 10 bits to represent the decimal, occupying 2 bytes.
[0039] INT8 is an eight-bit integer, occupying 1 byte.
[0040] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0041] The first embodiment of the present application relates to a method for improving the accuracy of model quantization, the process of which is as follows: Figure 1 As shown, the method comprises the following steps:
[0042] Step 101, obtain a floating point model, the floating point model has multiple floating point layers, and calculate the cumulative original output of all floating point layers of the floating point model. The cumulative original output is the final result of the floating point model.
[0043] As described above, the floating point model further includes a plurality of batch normalization (BN) layers, each of which is located after a quantizable floating point layer and is used to normalize the output of the floating point layer. For details on the error locality effect of the BN layer, please refer to the following.
[0044] In one embodiment, the data format of the floating point layer may be a floating point type FP32 or a floating point type FP16.
[0045] Step 102, individually select a floating point layer in the floating point model for quantization to form a hybrid model including a quantized layer, and calculate the error of the cumulative output of all layers in the hybrid model relative to the cumulative original output.
[0046] It can be understood that in step 102, only one floating-point layer in the floating-point model is quantized in each quantization process to obtain a hybrid model including one quantization layer, and each floating-point layer in the floating-point model is quantized once, thereby obtaining multiple hybrid models including one quantization layer. The error of the cumulative output of all layers in each hybrid model (i.e., the final result of the hybrid model) relative to the cumulative original output is calculated to obtain the error caused by each quantization layer to the final result.
[0047] For example, suppose that the first choice is to quantize the first floating-point layer, thus forming a hybrid model in which only the first layer is a quantized layer and all other layers are still floating-point layers. At this time, the error of the cumulative output of all layers in the hybrid model relative to the cumulative original output (that is, the difference between the final result of the hybrid model and the final result of the original floating-point model) is calculated, which is the error caused by the first quantized layer to the final result; the second choice is to quantize the second floating-point layer, thus forming a hybrid model in which only the second layer is a quantized layer and all other layers are floating-point layers. Calculate the error of the cumulative output of all layers of the current hybrid model relative to the cumulative original output, which is the error caused by the second quantized layer to the final result; repeat the above steps, select a different floating-point layer for quantization each time, and you can calculate the error caused by each quantized layer to the final result.
[0048] In one embodiment, the quantization process may be to convert the data format of the floating point layer from a higher precision (such as floating point type FP16 or floating point type FP32) to a lower precision (such as integer type INT8 or integer type INT16).
[0049] Step 103, sorting the calculated error values. As described above, after calculating the error caused by each quantization layer to the final result, the error can be sorted to select the quantization layer with a greater error impact on the final result.
[0050] Step 104, quantize all floating-point layers of the floating-point model, restore the corresponding quantized layers to floating-point layers one by one in the order of error values from high to low, and calculate the difference between the cumulative output of all layers of the restored model and the cumulative original output until the difference is less than a preset loss threshold.
[0051] It can be understood that in step 104, all floating-point layers in the floating-point model are quantized to obtain a model consisting entirely of quantized layers, and the quantized layer with the highest error value is restored to a floating-point layer according to the sorting of the error values from high to low, and the difference between the cumulative output of all layers of the restored model and the cumulative original output is calculated, and the difference is compared with a preset loss threshold. If the difference is greater than the preset loss threshold, the quantized layer with the second highest error value is restored to a floating-point layer according to the sorting of the error values from high to low, and the difference between the cumulative output of all layers of the restored model and the cumulative original output is calculated again, and the new difference is compared with the preset loss threshold. If the new difference is greater than the preset loss threshold, the above steps are repeated until the difference between the calculated cumulative output and the cumulative original output is less than the preset loss threshold, thereby obtaining the target hybrid model.
[0052] In one embodiment, before all floating point layers in the floating point model are quantized, the last normalized exponential function (softmax) layer of the floating point model may be removed. Correspondingly, after obtaining the target mixed model, a normalized exponential function layer is added to the last layer of the target mixed model.
[0053] In order to better understand the technical solution of this application, the following is an explanation in conjunction with specific experimental data. The details listed are mainly for ease of understanding and are not intended to limit the scope of protection of this application. The following uses Mobilenet_v2, Mnasmet0_5, Efficientnet-b0, Resnet50, shufflenet_v2_x1_0, vgg16 and other neural network models as examples for explanation.
[0054] The accuracy of the hybrid model obtained by the method provided by the present application for different neural network models is shown in Table 1 below. Table 1 only lists the corresponding data after some quantization layers are restored to floating-point layers. Taking the model mobilenet_v2 as an example, when the data format of all its layers is floating-point FP32, the cumulative original output of the model is 0.71872. After quantizing all its layers and converting the data format of all layers to INT8, the cumulative output of all layers in the model is 0.68928. The data 48 in the table indicates that the quantization (INT8) layer of the 48th layer is restored to a floating-point layer (FP32), and the corresponding 0.68896 indicates the cumulative output of all layers in the restored model; the data 0 in the table indicates that on the basis of restoring the 48th layer to a floating-point layer, the quantization layer of the 0th layer is further restored to a floating-point layer, and the corresponding 0.69172 indicates the cumulative output of all layers in the hybrid model after the 48th layer and the 0th layer are restored, and the other data are analogous. It should be noted that the recovery order of the quantization layers is restored one by one in the order from high to low error values. As can be seen from Table 1, after the corresponding quantized layers are restored to floating-point layers one by one according to the order of error values from high to low, the accuracy of the hybrid model generally shows an upward trend.
[0055] Table 1 Hybrid model accuracy:
[0056]
[0057] Error locality effect of BN layer
[0058] The BN layer in the neural network transforms the neuron input into a Gaussian distribution with a mean of 0 and a variance of 1, and then translates and scales it. The goal is to make the distribution of sample features more regular, which is convenient for parameter updating and model convergence.
[0059] Our research found that since the quantization error presents a Gaussian statistical distribution, the superposition of two Gaussian distributions is still a Gaussian distribution, so the characteristic distribution of samples with quantization errors is still a Gaussian distribution. As long as the quantization error distribution is similar to the original sample characteristic distribution, by calculating its KL divergence, it can be seen that the Gaussian distribution before and after quantization is not much different, so the BN layer can still play a good role, making each layer of quantization distribution close to the original distribution, thereby greatly reducing the impact on the next network layer.
[0060] from Figure 2 and Figure 3 It can be seen that the influence of quantizing each layer separately on each subsequent layer follows a similar rule, and this rule remains basically unchanged for different test sets, indicating that due to the effect of the BN layer, the distribution law of the quantization layer remains basically unchanged and has little influence on the subsequent network layers. We call this phenomenon the quantization error local effect (QELE) caused by the BN layer.
[0061] On the interaction between quantization layers
[0062] Figure 4 and Figure 5 The Mobilenet_v2 model and the shufflenet_v2_x1_0 model quantize a certain layer, then quantize each other layer and calculate the average quantization error of the last layer features to test the interaction between quantizing a certain layer and quantizing other layers.
[0063] Take the shufflenet_v2_x1_0 model as an example, Figure 5 The top curve represents quantizing the first layer, then quantizing the 1st to 57th layers respectively, and calculating the average quantization error of the last layer feature. A total of 57 values are obtained to obtain this curve, and the other curves are similar.
[0064] It can be seen that the quantization error propagates through layers, and the superposition interference of quantization errors in other layers basically follows the same rule for the error in the last layer. That is to say, the influence of a certain quantization layer on the final result (relative to the size of other layers) has nothing to do with the interaction with other layers and the test set, but is only determined by the type of network model.
[0065] About the influence of BN layer on network layer error
[0066] Figure 6 and Figure 7The difference between vgg16 with and without BN layer is shown respectively. It can be seen that without BN layer, the overall shape is parabolic. This is because without the effect of BN layer, the quantization error has a superposition effect and becomes larger and larger. In the end, because the network is trained to minimize the loss, the sample feature deviation and variance (quantization error is also regarded as sample feature deviation and variance) will be trained to be minimum, thus forming a constraint in the last layer. This constraint is back-propagated and hits the superposition effect of quantization error, forming a peak and a parabolic shape. The curve of the network with BN layer is relatively flat due to the error locality effect.
[0067] About the influence of Softmax on quantization error
[0068] Figure 8 and Fig. 9 The difference between the last layer without and with softmax is shown. It should be noted that the curve deviation is larger after adding softmax, so Fig. 9 The actual result is the feature of the second-to-last layer of softmax. It can be seen that the error is significantly reduced after adding softmax.
[0069] The second embodiment of the present application relates to a device for improving the accuracy of model quantization, the structure of which is as follows: Fig.10 As shown, the device for improving the accuracy of model quantization includes an acquisition module 1001, a quantization module 1002, a sorting module 1003 and a recovery module 1004. The acquisition module 1001 is used to acquire a floating-point model, the floating-point model having multiple floating-point layers, and calculate the cumulative original outputs of all floating-point layers of the floating-point model. The quantization module 1002 is used to select a floating-point layer in the floating-point model for quantization to form a mixed model including a quantization layer, and calculate the error of the cumulative outputs of all layers in the mixed model relative to the cumulative original output. The sorting module 1003 is used to sort the calculated error values. The recovery module 1004 is used to quantize all the floating-point layers of the floating-point model, restore the corresponding quantization layers to floating-point layers one by one in the order of error values from high to low, and calculate the difference between the cumulative outputs of all layers of the restored model and the cumulative original output, until the difference is less than a preset loss threshold, so as to obtain a target mixed model.
[0070] In one embodiment, the floating-point model further includes a batch normalization layer, which is located after the floating-point layer and is used to normalize the output of the floating-point layer.
[0071] In one embodiment, before quantizing all floating-point number layers of the floating-point model, the recovery module 1004 further includes: removing the last normalized exponential function layer of the floating-point model.
[0072] In one embodiment, the recovery module 1004 is further configured to add a normalized exponential function layer to the last layer of the current model after the difference is less than a preset loss threshold.
[0073] In one embodiment, the data format of the floating point layer is a floating point type FP32 or a floating point type FP16.
[0074] The first implementation manner is a method implementation manner corresponding to the present implementation manner. The technical details in the first implementation manner can be applied to the present implementation manner, and the technical details in the present implementation manner can also be applied to the first implementation manner.
[0075] The inventors of the present application have discovered that batch normalization of a neural network model can produce a good local error effect, which can effectively prevent errors from being transmitted backward in the middle layer of the network and causing errors to overlap with each other. Based on this effect, we can individually calculate the error caused by each quantization layer to the final result, thereby screening out the quantization layer that has a greater impact on the final result, and restoring the quantization layer that has a greater impact on the final result to the original floating-point layer, and we can get an optimized target hybrid model. This calculation method is faster than the traditional method and can directly correspond to the final result, so the optimal target hybrid model can be selected more intuitively.
[0076] It should be noted that those skilled in the art should understand that the implementation functions of each module shown in the above-mentioned device for improving the accuracy of model quantization can be understood by referring to the relevant description of the method for improving the accuracy of model quantization. The functions of each module shown in the above-mentioned device for improving the accuracy of model quantization can be implemented by a program (executable instruction) running on a processor, or by a specific logic circuit. If the device for improving the accuracy of model quantization in the embodiment of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or partly contributed to the prior art can be embodied in the form of a software product, which is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM, Read Only Memory), a disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific combination of hardware and software.
[0077] Accordingly, the present application also provides a computer-readable storage medium in which computer executable instructions are stored, and when the computer executable instructions are executed by the processor, the various method embodiments of the present application are implemented. Computer-readable storage media include permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be a computer-readable instruction, a data structure, a module of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media do not include temporary computer-readable media (transitory media), such as modulated data signals and carriers.
[0078] It should be noted that in the application documents of this patent, relational terms such as first and second 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 the process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "including one" do not exclude the existence of other identical elements in the process, method, article or device including the elements. In the application documents of this patent, if it is mentioned that an action is performed according to an element, it means that the action is performed at least according to the element, which includes two situations: performing the action only according to the element, and performing the action according to the element and other elements. Expressions such as multiple, multiple, and multiple include 2, 2 times, 2 kinds, and more than 2, more than 2 times, and more than 2 kinds.
[0079] All documents mentioned in this specification are considered to be included in the disclosure of this application as a whole, so that they can be used as a basis for modification when necessary. In addition, it should be understood that the above is only a preferred embodiment of this specification and is not intended to limit the scope of protection of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification should be included in the scope of protection of one or more embodiments of this specification.
[0080] In some cases, the actions or steps described in the claims may be performed in a different order than in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A method for improving the accuracy of model quantization, characterized in that: include: Obtaining a floating point model, the floating point model having a plurality of floating point layers, and calculating the cumulative raw outputs of all floating point layers of the floating point model; Selecting a floating point layer in the floating point model separately for quantization to form a hybrid model including a quantized layer, and calculating the error of the cumulative output of all layers in the hybrid model relative to the cumulative original output; Sort the calculated error values; as well as All floating-point layers of the floating-point model are quantized, and the corresponding quantized layers are restored to floating-point layers one by one in the order of error values from high to low, and the difference between the cumulative output of all layers of the restored model and the cumulative original output is calculated until the difference is less than the preset loss threshold to obtain the target hybrid model.
2. The method for improving the accuracy of model quantization according to claim 1, characterized in that: The floating-point model also includes a batch normalization layer, which is located after the floating-point layer and is used to normalize the output of the floating-point layer.
3. The method for improving the accuracy of model quantization according to claim 1, characterized in that: Before quantizing all floating-point layers of the floating-point model, the method further includes: removing the last normalized exponential function layer of the floating-point model.
4. The method for improving the accuracy of model quantization according to claim 3, characterized in that: After the difference is less than a preset loss threshold, the method further includes: adding a normalized exponential function layer to the target mixture model as the last layer of the target mixture model.
5. The method for improving the accuracy of model quantization according to claim 1, characterized in that: The data format of the floating point layer is: floating point type FP32 or floating point type FP16.
6. A device for improving the accuracy of model quantization, characterized in that: include: An acquisition module, used for acquiring a floating point model, the floating point model having a plurality of floating point layers, and calculating the accumulated original outputs of all floating point layers of the floating point model; A quantization module, used for individually selecting a floating point layer in the floating point model for quantization to form a hybrid model including a quantization layer, and calculating an error of the cumulative output of all layers in the hybrid model relative to the cumulative original output; A sorting module, used for sorting the calculated error values; as well as The recovery module is used to quantize all the floating-point layers of the floating-point model, restore the corresponding quantized layers to floating-point layers one by one in the order of error values from high to low, and calculate the difference between the cumulative output of all layers of the restored model and the cumulative original output until the difference is less than a preset loss threshold, so as to obtain the target hybrid model.
7. The device for improving the accuracy of model quantization according to claim 6, characterized in that: The floating-point model also includes a batch normalization layer, which is located after the floating-point layer and is used to normalize the output of the floating-point layer.
8. The device for improving the accuracy of model quantization according to claim 6, characterized in that: Before quantizing all floating-point number layers of the floating-point model, the recovery module further includes: removing the last normalized exponential function layer of the floating-point model.
9. The device for improving the accuracy of model quantization according to claim 8, characterized in that: The recovery module is also used to add a normalized exponential function layer to the target mixture model as the last layer of the target mixture model after the difference is less than a preset loss threshold.
10. The device for improving the accuracy of model quantization according to claim 6, characterized in that: The data format of the floating point layer is: floating point type FP32 or floating point type FP16.
