Method and system for determining mixed precision quantization strategy for deep neural networks

By setting thresholds and iterating each layer using different quantization precisions for deep neural network inference, the quantization precision combinations that meet the accuracy and time requirements are screened out, which solves the problem of difficulty in screening mixed precision quantization strategies in the existing technology and achieves the best inference speed and accuracy.

CN112906883BActive Publication Date: 2024-09-03GUANGZHOU YUNCONG INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110158390.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-04
Publication Date
2024-09-03
Estimated Expiration
2041-02-04

AI Technical Summary

Technical Problem

It is difficult to accurately select the best mixed-precision quantization strategy in deep neural networks with existing technology, resulting in reduced inference accuracy and poor operation speed.

Method used

By setting the inference accuracy threshold and inference time threshold, iterate each layer using different quantization accuracy for inference, record the actual accuracy and time, and select the quantization accuracy combination that meets the threshold as a mixed precision strategy.

Benefits of technology

It achieves optimal inference speed and lowest power consumption while ensuring the accuracy of neural network inference, reduces labor and time costs, and adapts to different application scenarios and equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112906883B
    Figure CN112906883B
Patent Text Reader

Abstract

The present invention relates to quantized reasoning of deep neural networks, and specifically provides a method and system for determining a mixed precision quantization strategy for deep neural networks, aiming to solve the problem that existing methods cannot accurately and automatically screen out the best mixed precision quantization strategy for a specific neural network model. To this end, the method of the present invention includes: setting an inference accuracy threshold and an inference time threshold of a deep neural network; determining a plurality of different quantization accuracies that the hardware can support; iterating all layers with each quantization accuracy and recording the actual inference accuracy and actual inference time of each iteration, and screening out all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold for each layer; and determining one of the combinations of the screened quantization accuracies as the final mixed precision quantization strategy. The method of the present invention can simply and quickly complete the search for the best quantization strategy, greatly reducing manpower and time costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to quantized reasoning of deep neural networks, and specifically provides a mixed precision quantization strategy determination method and system for deep neural networks. Background Art

[0002] Artificial Neural Network (ANN) is an algorithmic mathematical model that imitates the behavioral characteristics of animal neural networks and performs distributed parallel information processing. This network relies on the complexity of the system to adjust the interconnected relationships between a large number of internal nodes to achieve the purpose of processing information, and has the ability of self-learning and self-adaptation. Deep Neural Network (DNN) refers to a neural network with multiple layers inside, which is an important technology in the field of machine learning (ML).

[0003] Operations related to deep neural networks include training, inference, and quantization. Training refers to inputting enough samples into the deep neural network and adjusting the network structure (mainly adjusting the weights) through a certain algorithm so that the output of the deep neural network matches the expected value. Inference refers to deploying a pre-trained deep neural network model to actual business scenarios, such as image classification, object detection, online translation, etc. Since inference is directly facing users, inference performance is crucial, especially for enterprise-level products. For this reason, it becomes a practical need to increase the computing speed by compressing the model size, and quantization is a typical model compression method, which reduces the computing accuracy by converting floating-point parameters into fixed-point parameters, thereby compressing the model and increasing the computing speed.

[0004] In the existing deep neural network training and reasoning process, higher precision (such as 32-bit double precision, 16-bit single precision) is generally used for reasoning. However, in actual scene applications, there are often higher requirements for the reasoning speed of neural networks. Due to the computing power limitations of terminal devices, in order to achieve low power consumption and low latency, lower precision (8 bits or less) is often used for reasoning. However, using lower precision for reasoning in the neural network reasoning process will lead to a higher precision loss, resulting in a larger result error, resulting in a decrease in the accuracy of the neural network.

[0005] In order to solve the above problems, there are methods in the prior art to quantize neural networks through mixed precision, that is, to screen out individual layers in the neural network that cause precision degradation, improve the reasoning precision of these layers separately, and still use low-precision algorithms for reasoning on other layers. However, in actual neural networks, due to the mutual influence and correlation of calculations within the same layer or between different layers, it is difficult to determine the best mixed precision optimal strategy through experience, that is, it is difficult to accurately screen out layers with reduced precision and select appropriate quantization precision for the layers with reduced precision.

[0006] To this end, Chinese patent application CN112183742A discloses a neural network hybrid quantization method based on progressive quantization and Hessian information, the steps of which include: given a set of image label pairs, dividing a sample set and a calibration set; defining the optional quantization accuracy range of each layer of the neural network; randomly selecting a quantization layer for bit reduction quantization, repeating sampling n times, and obtaining n basic mixed precision models; taking the image label pairs in the calibration set as input, performing a forward process on all candidate mixed precision neural network models; using Adam second-order Momentum information to calculate the Hessian approximation; then calculating the performance evaluation index, sorting the n indicators, selecting the minimum value corresponding to the mixed precision strategy as the best mixed precision combination under the current step, calculating the computational cost of the model, and then training the current mixed precision network model; iterating until the end condition is met. Although the above method gets rid of the dependence on manual experience, it adopts a random sampling method when quantizing each network layer, and the quantization results of random sampling are directly used to construct the mixed precision model, so that the precision combination selected by the performance evaluation index later may not accurately correspond to the optimal precision and operation speed of the entire network model.

[0007] Therefore, the field still needs a new method to solve the problem of automatic screening and determination of mixed precision quantization strategies. Summary of the invention

[0008] In order to solve the above-mentioned problems in the prior art, that is, in order to solve the problem that the existing methods cannot accurately and automatically screen out the best mixed precision quantization strategy for a specific neural network model, the present invention provides a mixed precision quantization strategy determination method for a deep neural network, characterized in that the method comprises the following steps: setting an inference accuracy threshold and an inference time threshold of the deep neural network; determining a plurality of different quantization precisons that can be supported by hardware running the deep neural network; in the process of inputting test data into the deep neural network for inference, iterating all layers of the deep neural network with each quantization accuracy and recording the actual inference accuracy and actual inference time of the deep neural network at each iteration, and screening out all quantization precisons whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold for each layer; and determining one of a plurality of different combinations of quantization precisons screened out for all layers as the mixed precision quantization strategy.

[0009] In the preferred implementation of the above-mentioned method for determining a mixed precision quantization strategy for a deep neural network, the step of "iterating all layers of the deep neural network with each quantization precision" specifically includes: on the premise of reasoning other layers with the highest quantization precision, reasoning each layer of the deep neural network separately with each quantization precision.

[0010] In a preferred implementation of the above-mentioned method for determining a mixed precision quantization strategy for a deep neural network, the step of "iterating all layers of the deep neural network with each quantization precision and recording the actual inference precision and actual inference time of the deep neural network at each iteration, and screening out all quantization precisions for each layer whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold" specifically includes: on the premise of using the highest quantization precision to infer other layers, using each quantization precision to infer the first layer of the deep neural network respectively, and recording the actual inference precision and actual inference time of each inference; screening out for the first layer all quantization precisions whose actual inference precision is greater than the inference precision threshold value and the actual inference time is less than the inference time threshold; on the premise that the quantization accuracy of the first layer is fixed to the lowest quantization accuracy selected and the highest quantization accuracy is used to infer other layers, the second layer of the deep neural network is inferred with each quantization accuracy, and the actual inference accuracy and actual inference time of each inference are recorded; for the second layer, all quantization accuracy with actual inference accuracy greater than the inference accuracy threshold and actual inference time less than the inference time threshold are selected; and so on, all layers of the deep neural network are iterated, and finally for each layer, all quantization accuracy with actual inference accuracy greater than the inference accuracy threshold and actual inference time less than the inference time threshold are selected.

[0011] In a preferred implementation of the above-mentioned method for determining a mixed precision quantization strategy for a deep neural network, the step of "determining one of multiple different combinations of quantization precisions screened out for all layers as the mixed precision quantization strategy" specifically includes: using each of the multiple different combinations of quantization precisions screened out for all layers to perform inference on the deep neural network respectively, and recording the actual inference accuracy and actual inference time of each inference; screening out one or more combinations whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold as the mixed precision quantization strategy.

[0012] In a preferred implementation of the above-mentioned method for determining a mixed precision quantization strategy for a deep neural network, when there is only one screened combination, the screened combination is directly used as the mixed precision quantization strategy; and / or when there are multiple screened combinations, one of the multiple screened combinations is selected as the mixed precision quantization strategy.

[0013] In another aspect, the present invention also provides a mixed precision quantization strategy determination system for a deep neural network, characterized in that the system includes: a threshold setting module, which is used to set the inference accuracy threshold and inference time threshold of the deep neural network; a quantization accuracy determination module, which is used to determine multiple different quantization accuracy that can be supported by the hardware running the deep neural network; a mixed precision strategy determination module, which, in the process of inputting test data into the deep neural network for inference, iterates all layers of the deep neural network with each quantization accuracy and records the actual inference accuracy and actual inference time of the deep neural network at each iteration, screens out all quantization accuracy for each layer whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold, and determines one of the multiple different combinations of quantization accuracy screened out for all layers as the mixed precision quantization strategy.

[0014] In a preferred implementation of the above-mentioned mixed precision quantization strategy determination system for a deep neural network, when iterating all layers of the deep neural network with each quantization precision, the mixed precision strategy determination module specifically performs the following operations: on the premise of using the highest quantization precision to infer other layers, each layer of the deep neural network is inferred separately with each quantization precision.

[0015] In the preferred implementation of the mixed precision quantization strategy determination system for a deep neural network, the mixed precision strategy determination module specifically performs the following operations: on the premise of using the highest quantization precision to infer other layers, use each quantization precision to infer the first layer of the deep neural network respectively, and record the actual inference precision and actual inference time of each inference; for the first layer, select all quantization precisions whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold; on the premise of fixing the quantization precision of the first layer to the selected lowest quantization precision and using the highest quantization precision to infer other layers, use each quantization precision to infer the second layer of the deep neural network, and record the actual inference precision and actual inference time of each inference; for the second layer, select all quantization precisions whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold; and so on, iterate all layers of the deep neural network, and finally select all quantization precisions whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold for each layer, and determine one of the multiple different combinations of quantization precisions selected for all layers as the mixed precision quantization strategy.

[0016] In a preferred implementation of the above-mentioned mixed precision quantization strategy determination system for a deep neural network, when one of multiple different combinations of quantization precision screened out for all layers is determined as the mixed precision quantization strategy, the mixed precision strategy determination module specifically performs the following operations: use each of the multiple different combinations to infer the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference; screen out one or more combinations whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold as the mixed precision quantization strategy.

[0017] In a preferred implementation of the above-mentioned mixed precision quantization strategy determination system for deep neural networks, when there is one screened combination, the mixed precision strategy determination module directly uses the one screened combination as the mixed precision quantization strategy; and / or when there are multiple screened combinations, the mixed precision strategy determination module selects one of the multiple screened combinations as the mixed precision quantization strategy according to the user's selection.

[0018] In another aspect, the present invention also provides a computer-readable storage medium, characterized in that a plurality of program codes are stored in the storage medium, and the program codes are suitable for being loaded and run by a processor to execute the method for determining a mixed precision quantization strategy for a deep neural network described in any of the above paragraphs.

[0019] In another aspect, the present invention also provides a control device, comprising a processor and a storage device, wherein the storage device stores a plurality of program codes, and wherein the program codes are suitable for being loaded and run by the processor to execute the method for determining a mixed precision quantization strategy for a deep neural network as described in any of the above paragraphs.

[0020] It can be understood by those skilled in the art that, under the condition of adopting the above technical solution, the present invention can obtain the following technical effects: 1. Obtain the best mixed precision quantization strategy, that is, through the technical solution of the present invention, the best reasoning speed and the lowest power consumption can be finally obtained under the premise of ensuring the reasoning accuracy of the neural network. 2. Save labor costs and time costs. The traditional manual trial method consumes a lot of manpower and time, and it is difficult to obtain the best mixed precision strategy. The use of this solution can complete the search for the best strategy in a fully automated manner, greatly reducing manpower and time costs. 3. It can be adapted to different application scenarios. Different chips can use different reasoning precisions. Even if two devices support the same low-precision operation, they may have different levels of acceleration ratios. For example, the acceleration ratio that can be obtained by NVIDIA-TESLA P4's 8-bit precision relative to 16-bit precision is not the same as the acceleration ratio that can be obtained by NVIDIA-TESLA-T4's 8-bit precision relative to 16-bit precision. Therefore, the optimal solution in a certain scenario and device is not the optimal solution in another scenario. However, the use of this solution can obtain a customized optimal mixed precision strategy in a specific scenario. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings, in which:

[0022] Figure 1 A flow chart of the main steps of a method for determining a mixed precision quantization strategy for a deep neural network according to the present invention;

[0023] Figure 2 A flowchart of detailed steps of an iterative process of a method for determining a mixed precision quantization strategy for a deep neural network according to an embodiment of the present invention;

[0024] Figure 3 A flowchart of detailed steps of an iterative process of a method for determining a mixed precision quantization strategy for a deep neural network according to another embodiment of the present invention;

[0025] Figure 4 The present invention is a flowchart of the detailed steps of the final strategy determination process of the mixed precision quantization strategy determination method for a deep neural network according to the present invention. DETAILED DESCRIPTION

[0026] To facilitate the understanding of the present invention, the present invention will be described more comprehensively and in detail below in conjunction with the accompanying drawings and embodiments. However, those skilled in the art should understand that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0027] In the description of the present invention, "module" and "processor" may include hardware, software or a combination of the two. A module may include hardware circuits, various suitable sensors, communication ports, and memories, and may also include software parts, such as program codes, or a combination of software and hardware. The processor may be a central processing unit, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and / or signal processing functions. The processor may be implemented in software, hardware, or a combination of the two. Non-temporary computer-readable storage media include any suitable medium that can store program codes, such as a magnetic disk, a hard disk, an optical disk, a flash memory, a read-only memory, a random access memory, and the like. The term "A and / or B" means all possible combinations of A and B, such as only A, only B, or A and B. The term "at least one A or B" or "at least one of A and B" has a similar meaning to "A and / or B", and may include only A, only B, or A and B. The singular terms "one" and "the" may also include plural forms.

[0028] See first Figure 1 The mixed precision quantization strategy determination method for deep neural networks of the present invention mainly includes the following steps:

[0029] S1, setting the inference accuracy threshold and inference time threshold of the deep neural network;

[0030] S2, determining a plurality of different quantization precisions that can be supported by the hardware running the deep neural network;

[0031] S3, in the process of inputting the test data into the deep neural network for reasoning, iterating all layers of the deep neural network with each quantization accuracy and recording the actual reasoning accuracy and actual reasoning time of the deep neural network at each iteration, and screening out all quantization accuracies for each layer whose actual reasoning accuracy is greater than the reasoning accuracy threshold and whose actual reasoning time is less than the reasoning time threshold;

[0032] S4: Determine one of the multiple different combinations of quantization precisions screened for all layers as the mixed precision quantization strategy.

[0033] Regarding the above method, it should be noted that the method of the present invention is used to determine the quantization precision combination of different layers of a neural network in a mixed precision quantization scenario, and does not involve specific quantization algorithms and quantization parameters (such as weights, activation values, feature maps, etc.). Without deviating from the basic principles of the present invention, those skilled in the art can adopt any suitable quantization algorithm, and can also quantize any parameters of the neural network.

[0034] Secondly, since the technical solution of the present invention is applicable to any neural network with more than 2 hidden layers, the term "deep neural network" in this application should be understood in a broad sense, that is, it includes all neural networks with more than 2 hidden layers.

[0035] In step S1, the inference accuracy threshold and inference time threshold of the deep neural network can be set by technical personnel according to the needs of specific application scenarios and combined with experience, or by field verification. Specifically, the highest accuracy that the hardware can support can be used to make an inference, and the output accuracy and operation time of the inference can be recorded. Then, the inference accuracy threshold and the inference time threshold can be set according to the output accuracy and operation time. Generally speaking, if the inference is performed with the highest accuracy, the output accuracy is usually the highest, but the operation time is the longest. At this time, the inference accuracy threshold can be determined by reducing the highest accuracy by a certain degree, that is, the acceptable minimum accuracy value. Accordingly, the operation time can be reduced by a certain degree to determine the inference time threshold, that is, the longest acceptable operation time.

[0036] In step S2, the multiple different quantization precisions that can be supported can be determined according to the instructions of the hardware product running the deep neural network. Each hardware manufacturer has clear instructions on the running precision of different products, and the relevant information can be directly queried.

[0037] For step S3, the present invention provides two different embodiments, which will be described below in combination with Figure 2 and 3 Describe in detail.

[0038] like Figure 2 As shown, in the first embodiment, step S3 further includes:

[0039] S311, on the premise of using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer each layer of the deep neural network respectively.

[0040] S312, recording the actual inference accuracy and actual inference time of the deep neural network in each iteration.

[0041] S313 , for each layer, screen out all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold.

[0042] For example, according to Figure 2 In the embodiment, if the system can support three precisions of fp32, fp16 and int8, when int8 or fp16 is used for reasoning on the first layer, the other layers are all inferred by fp32, and so on, when int8 or fp16 is used for reasoning on the second layer, the first layer is restored to fp32 precision, and the other layers are also inferred by fp32. It can be understood by those skilled in the art that since the other layers are kept at the highest precision when iterating each layer, theoretically, Figure 2 The embodiments can more accurately reflect the impact of each layer on the system output accuracy and computing time at each low precision.

[0043] Continue reading Figure 3 In the second embodiment, step S3 further includes:

[0044] S321, on the premise of using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer the first layer of the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference;

[0045] S322, for the first layer, screen out all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold;

[0046] S323, under the premise that the quantization accuracy of the first layer is fixed to the lowest quantization accuracy selected and the other layers are inferred with the highest quantization accuracy, the second layer of the deep neural network is inferred with each quantization accuracy, and the actual inference accuracy and actual inference time of each inference are recorded;

[0047] S324, for the second layer, screen out all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold;

[0048] S325, and so on, iterate all layers of the deep neural network, and finally screen out all quantization accuracies for each layer whose actual reasoning accuracy is greater than the reasoning accuracy threshold and whose actual reasoning time is less than the reasoning time threshold.

[0049] Continuing with the above example, follow Figure 3In an embodiment, if the system can support three precisions of fp32, fp16 and int8, firstly, int8 and fp16 are used for inference on the first layer respectively, and fp32 is used for inference on other layers. The results show that the actual output precision of the system meets the requirements only when fp16 is used, but not when int8 is used. Therefore, when the second layer is iterated next, the first layer is fixed to fp16 (the lowest acceptable precision for the first layer), and then the second layer is inferred with three different precisions. Of course, at this time, except for the first and second layers, all other layers are inferred with fp32. As described in the background technology section of this application, in an actual neural network, the calculations between different layers influence and relate to each other, and the full-precision layer is definitely only a small part in the final mixed-precision strategy. Therefore, Figure 3 The embodiments can more accurately reflect the impact of each layer on the system output accuracy and computing time when the final mixed precision strategy is adopted.

[0050] Next, combine Figure 4 To describe step S4, in step S4, the step of "determining one of the multiple different combinations of quantization precisions screened for all layers as the mixed precision quantization strategy" specifically includes:

[0051] S411, using each of the multiple different combinations of quantization precisions screened for all layers to perform reasoning on the deep neural network respectively, and recording the actual reasoning precision and actual reasoning time of each reasoning;

[0052] S412: Filter out one or more combinations whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold as the mixed precision quantization strategy.

[0053] More specifically, in step S412, when there is only one combination screened out, the one screened out combination is directly used as the mixed precision quantization strategy; when there are multiple combinations screened out, one selected from the multiple combinations screened out is used as the mixed precision quantization strategy. And, when there are multiple combinations screened out, the way to determine the final mixed precision quantization strategy is often based on experience. For example, if the technician believes that a certain layer or some layers are more important based on experience, the combination strategy with higher layer accuracy can be selected as the final strategy.

[0054] Continuing with the above example, assume that the network has a total of four layers, the minimum acceptable accuracy of the first layer is fp16, and accordingly, its available accuracy is fp16 and fp32; the minimum acceptable accuracy of the second layer is int8, and accordingly, its available accuracy is int8, fp16, and fp32; the minimum acceptable accuracy of the third and fourth layers is fp32, and accordingly, their available accuracy is only fp32. Therefore, the combinations of quantization accuracy screened for all four layers include the following six: 1. fp16, int8, fp32, fp32; 2. fp16, fp16, fp32, fp32; 3. fp16, fp32, fp32, fp32; 4. Fp32, int8, fp32, fp32; 5. Fp32, fp16, fp32, fp32; 6. Fp32, fp32, fp32, fp32. First, the sixth combination is a full-precision combination (i.e., the highest precision for each layer), which can be directly removed, and then the network is inferred using combinations 1-5, and each combination is selected based on its inference accuracy and operation time. Assuming that after reasoning with combinations 1-5, it is found that combinations 1-5 all meet the output accuracy requirements (i.e., the output accuracy is greater than the inference accuracy threshold), but only combinations 1 and 2 meet the operation time requirements (i.e., the operation time is less than the inference time threshold), then one of combinations 1 and 2 can be selected as the final strategy. More specifically, assuming that the technician believes that the second layer is more important and should adopt a relatively high precision, then combination 2 should be selected at this time. On the contrary, if there is no such consideration of importance, the combination with the shortest operation time can be used.

[0055] Regarding the above example, it should also be pointed out that, in theory, of combination 1 and combination 2, combination 1 should have the shortest operation time. However, as mentioned above, in actual neural networks, the calculations between different layers are mutually influential and related. Although the second layer accuracy of combination 2 is higher than that of combination 1 when the accuracy of other layers is the same, in certain cases, it is possible that the final operation time of combination 2 is shorter than that of combination 1. Therefore, the most accurate judgment of the actual output accuracy and operation time of each combination can only be made through actual reasoning.

[0056] In addition, the above examples are only hypothetical for the purpose of illustrating the technical solution of the present invention. In practice, deep neural networks often have dozens or hundreds of layers, and cannot be simple single-digit. Therefore, the above examples are only used to illustrate the principles of the present invention and should not constitute any limitation on the scope of protection of the present invention.

[0057] Next, we will use a face recognition neural network to more vividly describe the technical solution of the present invention. The recognition accuracy of the network's fp32 (high precision) is 97.5%, and the speed of reasoning one picture is 5ms. During training, the data is divided into three categories with a total of 300,000 pictures: Asians (100,000 pictures), whites (100,000 pictures), and blacks (100,000 pictures). Our goal is to increase the network reasoning speed from 5ms to 3ms on the NVIDIA GPU-Tesla T4, and the accuracy is not less than 96.5%. In other words, for the NVIDIA GPU-Tesla T4, the reasoning accuracy threshold of the face recognition network is set to 96.5%, and the reasoning time threshold is set to 3ms. Next, prepare to tune the data set, randomly select 100 pictures from each of the three categories, a total of 300 pictures, and pre-process the pictures, such as normalizing the pictures in the channel or time or frequency dimension, so that they can be directly used as the input of the face recognition network. Since the GPU of TeslaT4 supports calculations of three precisions: fp32, fp16, and int8, it is determined that the precisions supported by the hardware running the face recognition network are fp32, fp16, and int8 respectively.

[0058] Next, iterate layer by layer, first set the first layer to int8 precision, observe the accuracy of the inference result, observe how much the system output precision is lost due to this operation (specifically, how much it has dropped from 97.5%), and record the time taken for the entire inference process (specifically, how much it has been reduced from 5ms), and then try to set the first layer to fp16, observe the precision loss and record the time taken. According to this method, continue to traverse all layers (set the second layer to int8, fp16 and record the precision loss and the time taken for the entire inference process, set the third layer to int8, fp16 and record the precision loss, and so on). Of course, as mentioned above, Figure 2 and 3 As described above, when iterating a certain layer, the iterated layer can be fixed to the acceptable minimum accuracy, or all other iterated and non-iterated layers can be fixed to the highest accuracy. Both methods have their own advantages and disadvantages, which will not be repeated here.

[0059] Finally, multiple precision combinations are sorted out according to the results recorded in the iterative process, and then reasoning is performed on these combinations respectively to screen out the combinations that meet the above thresholds. On this basis, the combination that meets the accuracy requirements and has the shortest time can be directly used as the final strategy, or sorting methods or other more complex algorithms can be used, or experience can be used to screen out a mixed precision strategy with optimal speed and meeting the accuracy requirements.

[0060] Another aspect of the present invention provides a mixed precision quantization strategy determination system for a deep neural network, the system comprising: a threshold setting module, which is used to set the inference accuracy threshold and inference time threshold of the deep neural network; a quantization accuracy determination module, which is used to determine multiple different quantization accuracy that can be supported by hardware running the deep neural network; a mixed precision strategy determination module, which, in the process of inputting test data into the deep neural network for inference, iterates all layers of the deep neural network with each quantization accuracy and records the actual inference accuracy and actual inference time of the deep neural network at each iteration, screens out all quantization accuracy for each layer whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold, and determines one of the multiple different combinations of quantization accuracy screened out for all layers as the mixed precision quantization strategy.

[0061] In a preferred embodiment, when iterating all layers of the deep neural network with each quantization precision, the mixed precision strategy determination module specifically performs the following operations: on the premise of using the highest quantization precision to infer other layers, each layer of the deep neural network is inferred separately with each quantization precision.

[0062] In a preferred embodiment, the mixed precision strategy determination module specifically performs the following operations: on the premise of using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer the first layer of the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference; for the first layer, screen out all quantization accuracy whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold; on the premise of fixing the quantization accuracy of the first layer to the screened lowest quantization accuracy and using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer the second layer of the deep neural network, and record the actual inference accuracy and actual inference time of each inference; for the second layer, screen out all quantization accuracy whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold; and so on, iterate all layers of the deep neural network, and finally screen out all quantization accuracy whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold for each layer, and determine one of multiple different combinations of quantization accuracy screened out for all layers as the mixed precision quantization strategy.

[0063] In a preferred embodiment, when one of multiple different combinations of quantization accuracy screened out for all layers is determined as the mixed precision quantization strategy, the mixed precision strategy determination module specifically performs the following operations: use each of the multiple different combinations to infer the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference; screen out one or more combinations whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold as the mixed precision quantization strategy.

[0064] In a preferred embodiment, when there is only one screened combination, the mixed precision strategy determination module directly uses the screened combination as the mixed precision quantization strategy; and / or when there are multiple screened combinations, the mixed precision strategy determination module selects one of the multiple screened combinations as the mixed precision quantization strategy based on the user's selection.

[0065] It is understood by those skilled in the art that in actual operation, each module in the system can be adaptively split or merged. Such splitting or merging of specific modules will not cause the technical solution to deviate from the principle of the present invention. Therefore, the technical solutions after splitting or merging will fall within the protection scope of the present invention. Further, it should be understood that since the setting of each module is only to illustrate the functional unit of the system of the present invention, the physical devices corresponding to these modules can be the processor itself, or a part of the software in the processor, a part of the hardware, or a part of the combination of software and hardware.

[0066] It is understood by those skilled in the art that all or part of the process of the method of the above embodiment can also be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device, medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium that can carry the computer program code. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0067] Furthermore, another aspect of the present invention provides a computer-readable storage medium, in which a plurality of program codes are stored, and the program codes are suitable for being loaded and run by a processor to execute the mixed precision quantization strategy determination method for a deep neural network described above.

[0068] Furthermore, another aspect of the present invention provides a control device, which includes a processor and a storage device, wherein the storage device stores multiple program codes, and is characterized in that the program code is suitable for being loaded and run by the processor to execute the mixed precision quantization strategy determination method for deep neural networks described above.

[0069] So far, the technical solution of the present invention has been described in conjunction with an embodiment shown in the accompanying drawings, but it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

Claims

1. A method for determining a mixed precision quantization strategy for a deep neural network, characterized in that: The method comprises the following steps: Setting a reasoning accuracy threshold and a reasoning time threshold of the deep neural network; Determining a plurality of different quantization precisions that can be supported by hardware running the deep neural network; In the process of inputting the test data into the deep neural network for reasoning, iterating all layers of the deep neural network with each quantization precision and recording the actual reasoning precision and actual reasoning time of the deep neural network at each iteration, and screening out all quantization precisions for each layer whose actual reasoning precision is greater than the reasoning precision threshold and whose actual reasoning time is less than the reasoning time threshold; Determine one of a plurality of different combinations of quantization accuracies screened for all layers as the mixed precision quantization strategy; The step of "iterating all layers of the deep neural network with each quantization precision" specifically includes: Under the premise of using the highest quantization accuracy to infer other layers, each layer of the deep neural network is inferred using each quantization accuracy; The step of "determining one of the multiple different combinations of quantization precisions screened for all layers as the mixed precision quantization strategy" specifically includes: Performing inference on the deep neural network using each of a plurality of different combinations of quantization accuracies screened for all layers, and recording an actual inference accuracy and an actual inference time for each inference; One or more combinations in which the actual inference accuracy is greater than the inference accuracy threshold and the actual inference time is less than the inference time threshold are selected as the mixed precision quantization strategy.

2. The method for determining a mixed precision quantization strategy according to claim 1, characterized in that: The step of "iterating all layers of the deep neural network with each quantization precision and recording the actual inference precision and actual inference time of the deep neural network at each iteration, and screening out all quantization precisions for each layer whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold" specifically includes: Under the premise of using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer the first layer of the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference; for the first layer, select all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold; On the premise that the quantization accuracy of the first layer is fixed to the lowest quantization accuracy selected and the other layers are inferred with the highest quantization accuracy, the second layer of the deep neural network is inferred with each quantization accuracy, and the actual inference accuracy and actual inference time of each inference are recorded; for the second layer, all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold are selected; By analogy, all layers of the deep neural network are iterated, and finally all quantization accuracies whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold are screened out for each layer.

3. The method for determining a mixed precision quantization strategy according to claim 1, characterized in that: When the number of screened combinations is one, the screened combination is directly used as the mixed precision quantization strategy; When there are multiple screened combinations, one of the multiple screened combinations is selected as the mixed precision quantization strategy.

4. A mixed precision quantization strategy determination system for deep neural networks, characterized in that: The system comprises: A threshold setting module, which is used to set the inference accuracy threshold and the inference time threshold of the deep neural network; A quantization precision determination module, which is used to determine a plurality of different quantization precisions that can be supported by the hardware running the deep neural network; a mixed precision strategy determination module, which, in the process of inputting test data into the deep neural network for inference, iterates all layers of the deep neural network with each quantization precision and records the actual inference precision and actual inference time of the deep neural network at each iteration, screens out all quantization precisions whose actual inference precision is greater than the inference precision threshold and whose actual inference time is less than the inference time threshold for each layer, and determines one of a plurality of different combinations of quantization precisions screened out for all layers as the mixed precision quantization strategy; Wherein, when iterating all layers of the deep neural network with each quantization precision, the mixed precision strategy determination module specifically performs the following operations: Under the premise of using the highest quantization accuracy to infer other layers, each layer of the deep neural network is inferred using each quantization accuracy; When one of the multiple different combinations of quantization precisions screened for all layers is determined as the mixed precision quantization strategy, the mixed precision strategy determination module specifically performs the following operations: Using each of the multiple different combinations to perform reasoning on the deep neural network, and recording the actual reasoning accuracy and actual reasoning time of each reasoning; One or more combinations in which the actual inference accuracy is greater than the inference accuracy threshold and the actual inference time is less than the inference time threshold are selected as the mixed precision quantization strategy.

5. The mixed precision quantization strategy determination system according to claim 4, characterized in that: The mixed precision strategy determination module specifically performs the following operations: Under the premise of using the highest quantization accuracy to infer other layers, use each quantization accuracy to infer the first layer of the deep neural network respectively, and record the actual inference accuracy and actual inference time of each inference; For the first layer, all quantization accuracies whose actual reasoning accuracy is greater than the reasoning accuracy threshold and whose actual reasoning time is less than the reasoning time threshold are screened out; On the premise that the quantization accuracy of the first layer is fixed to the lowest quantization accuracy selected and the other layers are inferred with the highest quantization accuracy, the second layer of the deep neural network is inferred with each quantization accuracy, and the actual inference accuracy and actual inference time of each inference are recorded; For the second layer, all quantization accuracies whose actual reasoning accuracy is greater than the reasoning accuracy threshold and whose actual reasoning time is less than the reasoning time threshold are screened out; By analogy, all layers of the deep neural network are iterated, and finally all quantization precisons whose actual inference accuracy is greater than the inference accuracy threshold and whose actual inference time is less than the inference time threshold are screened out for each layer, and one of multiple different combinations of quantization precisons screened out for all layers is determined as the mixed precision quantization strategy.

6. The mixed precision quantization strategy determination system according to claim 4, characterized in that: When there is only one selected combination, the mixed precision strategy determination module directly uses the selected combination as the mixed precision quantization strategy; When there are multiple screened combinations, the mixed precision strategy determination module selects one of the multiple screened combinations as the mixed precision quantization strategy according to the user's selection.

7. A computer-readable storage medium, characterized in that: The storage medium stores a plurality of program codes, and the program codes are suitable for being loaded and run by a processor to execute the mixed precision quantization strategy determination method for a deep neural network according to any one of claims 1 to 3.

8. A control device, comprising a processor and a storage device, wherein the storage device stores a plurality of program codes, characterized in that: The program code is suitable for being loaded and run by the processor to execute the mixed precision quantization strategy determination method for a deep neural network according to any one of claims 1 to 3.