Self-adaptive mixing precision quantification method, device, equipment and medium

By using an adaptive mixed-precision quantization method, the method comprehensively sorts the data by multiplying the cosine similarity difference between adjacent layers with the sensitivity weight, and introduces iterative optimization. This solves the problem of low quantization efficiency in existing technologies, achieves efficient and automated mixed-precision quantization, and lowers the barrier to entry for users.

CN121787485APending Publication Date: 2026-04-03HUNAN GREAT WALL GALAXY TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing mixed-precision quantization methods require a lot of manpower and resources, have low quantization efficiency, and cannot be self-verified and adjusted, resulting in suboptimal results.

Method used

The adaptive mixed-precision quantization method uses the product of the cosine similarity difference between adjacent layers and the sensitivity weight of each layer operator to perform comprehensive sorting. Combined with the iterative optimization mechanism, the configuration is automatically adjusted to find the optimal mixed-precision model.

Benefits of technology

It enables accurate identification of bottleneck layers that are susceptible to quantization and critical to final accuracy, and automatically finds the optimal solution that meets preset performance targets, thus lowering the technical barrier to entry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121787485A_ABST
    Figure CN121787485A_ABST
Patent Text Reader

Abstract

The invention relates to a self-adaptive mixing precision quantification method and device, equipment and a medium, and the method comprises the steps: carrying out the comprehensive sorting through the product of the cosine similarity difference value of adjacent layers and the sensitivity weight of each layer, so as to guarantee that bottleneck layers which are liable to be influenced by quantification and are crucial to the final precision can be accurately recognized; therefore, precise positioning of a protection target is realized, an iterative optimization loop is introduced, an optimal solution meeting a preset performance target can be spontaneously found finally by continuously evaluating a time-precision balance point of an overall model and automatically adjusting configuration, and a suboptimal result caused by improper primary configuration is avoided; and the input of the user is simplified into a visual final performance target, and the complicated layer sorting and selection process is automatically processed in the system, so that the use threshold of the technology is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of deep learning technology and relates to an adaptive mixed precision quantization method, apparatus, device and medium. Background Technology

[0002] In recent years, neural networks have been widely used in image recognition, natural language processing and other fields. As the structure of neural networks becomes more and more complex, their computational and storage requirements also increase. In order to efficiently deploy complex neural networks with limited hardware resources, neural network models face the dual challenges of accuracy and speed in actual deployment. Hybrid precision quantization is a more suitable compromise.

[0003] Currently, the common mixed-precision quantization method is to first train the neural network model and then quantize the high-bit fp32 data type into low-bit uint8 or int16 data types. However, low-bit data types usually face the problem of insufficient inference precision. The usual solution is to manually select nodes with large precision loss for mixed quantization to meet the precision requirements. However, this method requires a lot of manpower and resources and has low quantization efficiency. Summary of the Invention

[0004] To address the problems existing in the above-mentioned traditional methods, this invention proposes an adaptive mixed-precision quantization method, an adaptive mixed-precision quantization device, a computer device, and a computer-readable storage medium, which can improve the efficiency of mixed-precision quantization when deploying neural network models.

[0005] To achieve the above objectives, the embodiments of the present invention adopt the following technical solutions: On the one hand, an adaptive mixed-precision quantization method is provided, including the following steps: Convert deep learning floating-point models to ONNX format; After acquiring the quantized image and setting the normalization parameters, the ONNX format deep learning floating-point model is quantized using a toolchain to obtain the UINT8 quantized model. The FP32 model and the UINT8 quantization model are run simultaneously. Tensor outputs are extracted layer by layer from the operators. Based on the tensor outputs of each layer of operators, the cosine similarity and cosine similarity difference between each layer are calculated. Dynamically calculate the sensitivity weights of each layer of operators; The sensitivity weight of each layer operator is multiplied by the cosine similarity difference between adjacent layers to obtain the comprehensive score of each quantization sensitivity, and all layer operators are ranked according to the comprehensive score of each quantization sensitivity. After selecting the top K operators with the highest comprehensive quantization sensitivity scores and configuring them as high-bit precision types, a mixed-precision weighted quantization file is generated; K is a positive integer. An iterative optimization mechanism is adopted to continuously adjust the number of high-bit precision type configurations of the first K operators until the model reaches a preset balance between inference time and precision index, at which point the iteration terminates and the optimal mixed precision model corresponding to the deep learning floating-point model is output.

[0006] On the other hand, an adaptive hybrid precision quantization device is also provided, comprising: The ONNX conversion module is used to convert deep learning floating-point models to ONNX format; The U8 quantization module is used to acquire quantized images, set normalization parameters, and then perform UINT8 quantization on the ONNX format deep learning floating-point model through the toolchain to obtain the UINT8 quantized model. The similarity calculation module is used to run the FP32 model and the UINT8 quantization model simultaneously, extract tensor outputs layer by layer operators, and calculate the cosine similarity and cosine similarity difference between each layer based on the tensor outputs of each layer operator. The sensitivity weight module is used to dynamically calculate the sensitivity weight of each layer of operators; The sensitivity comprehensive ranking module is used to multiply the sensitivity weight of each layer operator by the cosine similarity difference between adjacent layers to obtain the comprehensive sensitivity score of each layer, and to rank all layer operators according to the comprehensive sensitivity score of each layer. The high-bit configuration module is used to select the top K operators with the highest comprehensive quantization sensitivity scores, configure them as high-bit precision types, and then generate a mixed-precision weighted quantization file; K is a positive integer. The iterative optimization module is used to continuously adjust the number of high-bit precision type configurations of the first K operators using an iterative optimization mechanism until the model reaches a preset balance between inference time and precision index, at which point the iteration terminates and outputs the optimal mixed precision model corresponding to the deep learning floating-point model.

[0007] In another aspect, a computer device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described adaptive mixed precision quantization method.

[0008] Furthermore, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the aforementioned adaptive mixed-precision quantization method.

[0009] One of the above technical solutions has the following advantages and beneficial effects: The aforementioned adaptive hybrid precision quantization method, apparatus, device, and medium comprehensively sort the layers by multiplying the cosine similarity difference between adjacent layers with the sensitivity weight of each layer. This ensures accurate identification of bottleneck layers that are susceptible to quantization effects and crucial to the final accuracy, thereby achieving precise positioning of the protected target. An iterative optimization loop is introduced to continuously evaluate the time-accuracy balance point of the overall model and automatically adjust the configuration, ultimately finding the optimal solution that meets the preset performance target spontaneously, avoiding suboptimal results caused by improper configuration. Furthermore, the user input is simplified to an intuitive final performance target, with the complex layer sorting and selection process automatically handled internally, lowering the barrier to entry for hybrid precision quantization technology. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of the present invention or the conventional technology, the drawings used in the description of the embodiments or the conventional technology will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a flowchart illustrating an adaptive hybrid precision quantization method in one embodiment; Figure 2 This is a logic block diagram of an adaptive mixed-precision quantization method in one embodiment; Figure 3 This is a schematic diagram of the module architecture of an adaptive hybrid precision quantization device in one embodiment. Detailed Implementation

[0012] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention.

[0013] It should be noted that, in this document, the reference to "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The presentation of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will understand that the embodiments described herein can be combined with other embodiments. The term "and / or" as used herein refers to any combination of one or more of the associated listed items, and all possible combinations, including such combinations.

[0014] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0015] Existing automatic mixed-bit quantization schemes for AI chips involve converting a deep learning floating-point model into an ONNX model and performing graph optimization; quantizing the graph-optimized ONNX model using INT8 and outputting the quantized ONNX model; then, based on the quantization coefficients, splitting the ONNX model into different subgraphs, with nodes having the same quantization coefficient grouped into the same subgraph; for each operator in the model, converting its input and the output of the corresponding previous-layer operator into high-bit input and output; then, performing inference on the subgraph containing the current operator and comparing the differences before and after modification; sorting the differences for all operators; and simultaneously, selecting the K operators with the best accuracy improvement based on a pre-defined number K of high-bit operators and configuring them as high-bit types, generating a mixed-bit configuration table; and finally, generating a mixed-bit model based on the selected mixed-bit configuration table.

[0016] The static subgraph partitioning of the existing schemes mentioned above is based solely on the quantization coefficients, ignoring error propagation; the granularity of the difference value calculation only measures the local impact of improving the accuracy of a single operator on its direct output; simply selecting the top K operators with the largest difference values ​​is a greedy algorithm, and although each step of its selection is the best at the moment, the final overall combination may not be the global optimum.

[0017] In one embodiment, such as Figure 1 As shown, an adaptive mixed-precision quantization method is provided, which may include the following steps S10 to S22: S10 converts deep learning floating-point models to ONNX format; S12: After obtaining the quantized image and setting the normalization parameters, the deep learning floating-point model in ONNX format is quantized using a toolchain to obtain the UINT8 quantized model. The quantized image can be a randomly selected image from the training data, and the normalization parameters can be the data divided by 255, normalizing 0 to 255 to between 0 and 1.

[0018] S14, Simultaneously run the FP32 model and the UINT8 quantization model, extract tensor outputs layer by layer operators, and calculate the cosine similarity and cosine similarity difference between each layer based on the tensor outputs of each layer operator. S16, dynamically calculate the sensitivity weight of each layer of operators; S18, multiply the sensitivity weight of each layer operator by the cosine similarity difference between adjacent layers to obtain the comprehensive score of each quantization sensitivity, and sort all layer operators according to the comprehensive score of each quantization sensitivity; S20: Select the top K operators with the highest comprehensive quantization sensitivity scores and configure them as high-bit precision type to generate a mixed-precision weighted quantization file; K is a positive integer. S22 employs an iterative optimization mechanism to continuously adjust the number of high-bit precision type configurations for the first K operators until the model reaches a preset balance between inference time and precision metrics, at which point the iteration terminates and outputs the optimal mixed-precision model corresponding to the deep learning floating-point model.

[0019] It is understood that, in this embodiment, as Figure 2 As shown, the deep learning floating-point model to be quantized is first converted to ONNX format, and then UINT8 quantization is performed using a toolchain (an end-to-end technology stack consisting of multiple software tools, libraries, and components). This outputs a weight quantization file (.quantize) and a network structure description file (.json), which are the model files of the UINT8 quantized model corresponding to the deep learning floating-point model. Subsequently, the system simultaneously runs the FP32 model and the UINT8 quantized model, extracting tensor outputs layer by layer. Based on the tensor outputs of each layer's operators, the cosine similarity and its difference between layers are calculated as an evaluation metric for local quantization error (denoted as dissimilarity_score). On this basis, the contribution of each layer's operators to the final output error is dynamically calculated, i.e., the sensitivity weight (denoted as sensitivity_weight), thus establishing a comprehensive evaluation system across both local error and global impact dimensions. The cosine similarity difference between adjacent layers refers to the difference between the current layer and the previous layer; this difference reflects the accuracy loss, with a larger difference indicating a greater accuracy loss.

[0020] Furthermore, the sensitivity weight of each layer operator is multiplied by the cosine similarity difference between adjacent layers to obtain a comprehensive quantization sensitivity score. All layer operators are then ranked according to this comprehensive score. Based on the ranking, the system selects the K operators with the highest comprehensive quantization sensitivity scores and configures them as high-bit-precision types, generating a mixed-precision weighted quantization file. The entire process employs an iterative optimization mechanism, continuously adjusting the high-bit-layer configuration until the model reaches a preset balance between inference time and accuracy. Finally, the iteration automatically terminates, outputting the optimal mixed-precision model. K is a positive integer.

[0021] Specifically, all layer operators are sorted based on the product of the sensitivity weight of each layer and the cosine similarity difference between adjacent layers. The resulting comprehensive sensitivity score is then used... The formula is shown below:

[0022] Select the top-K layer operators with the highest priority scores (i.e., comprehensive quantization sensitivity scores), and replace the top-K layer operators with high-bit (e.g., INT16 and above) quantization data types; under the premise of meeting the preset precision loss threshold, find the minimum K value and generate the final mixed precision weighted quantization file.

[0023] The aforementioned adaptive hybrid precision quantization method comprehensively sorts layers by multiplying the cosine similarity difference between adjacent layers with the sensitivity weight of each layer. This ensures accurate identification of bottleneck layers that are susceptible to quantization effects and crucial to the final accuracy, thereby achieving precise positioning of the protected target. An iterative optimization loop is introduced to continuously evaluate the time-precision balance point of the overall model and automatically adjust the configuration, ultimately finding the optimal solution that meets the preset performance target spontaneously, avoiding suboptimal results caused by improper configuration. Furthermore, the user input is simplified to an intuitive final performance target, with the complex layer sorting and selection process automatically handled internally, lowering the technical barrier to entry.

[0024] In one embodiment, regarding step S14 above, during the process of calculating the cosine similarity and cosine similarity difference between each layer based on the tensor output of each layer operator, if the current layer operator has multiple inputs, then the largest cosine similarity difference is taken as the cosine similarity difference corresponding to the current layer operator.

[0025] Specifically, the cosine similarity difference (dissimilarity_score) between adjacent layer operators is calculated based on their tensor outputs. Simultaneously, the FP32 and UINT8 quantized models are run, saving the tensor outputs of each layer operator in both models. The cosine similarity of each layer operator is calculated, and the cosine similarity difference (represented by dissimilarity_score) between the current layer operator and the input layer operators is calculated. If the current layer operator has multiple inputs, the largest cosine similarity difference is taken. (where i is an integer) is used as the cosine similarity difference corresponding to the current layer operator.

[0026] In one embodiment, step S16 described above may specifically include the following processing: For each operator in the UINT8 quantization model, replace each operator with a high-bit quantized data type; Infer the changed UINT8 quantization model after the replacement and calculate the degree of change in the network output of the replaced UINT8 quantization model; Configure the sensitivity weights of each layer of operators according to the degree of change.

[0027] Specifically, in the process of dynamically calculating the contribution of each layer operator to the final output error, for each layer operator of the UINT8 quantization model, each layer operator is replaced with a high-bit (e.g., INT16 or higher) quantization data type. Then, the replaced UINT8 quantization model is inferred, and the degree of change in the network output of the replaced UINT8 quantization model is calculated. The greater the degree of change, the more sensitive the layer operator corresponding to the network output with a large degree of change, and the greater the impact of its quantization error on the final accuracy. The sensitivity weight of the corresponding layer operator (which can be used) is determined. (This indicates that the value should be set higher.)

[0028] In one embodiment, the iterative optimization mechanism for step S22 described above may include: Repeat steps S10 to S18; if the current high bit precision type configuration simultaneously meets the preset target inference time and target precision, then stop the iteration immediately.

[0029] It is understood that all steps from S10 to S18 above can be iterated repeatedly. Two key target thresholds can be preset: target inference time and target precision. If the current high bit precision type configuration simultaneously meets the preset target inference time and target precision (i.e., reaches the preset balance state), the iteration is stopped immediately. In this way, the optimal mixed precision model that simultaneously meets the preset target inference time and target precision is obtained with the least amount of iteration time.

[0030] In one embodiment, the iterative optimization mechanism may further include: if the accuracy improvement in multiple consecutive iterations is within a set threshold, then the iteration is stopped.

[0031] It is understandable that if the improvement in accuracy becomes negligible in multiple iterations (i.e., a certain threshold, such as 0.1% or 0.5%), then the iteration should be stopped to avoid excessive iteration time and to obtain the optimal mixed accuracy model that prioritizes balancing accuracy. In one embodiment, the iterative optimization mechanism may further include: if the number of iterations reaches the maximum number of iterations, then the iteration is forcibly stopped.

[0032] Understandably, a maximum number of iterations can also be set, and the iteration can be forcibly stopped after the maximum number of iterations is reached to prevent excessive occupation of system computing resources and obtain the optimal mixed precision model under the current conditions.

[0033] In response to the existing solutions that rely on a single indicator (such as layer output difference) or human experience to determine which layers are "important", this invention will comprehensively rank the layers by multiplying the "local error propagation assessment" (cosine similarity difference between adjacent layers) and the "global influence assessment" (sensitivity weight of each layer) to ensure that the "bottleneck layers" that are susceptible to quantification (such as high cosine similarity difference between adjacent layers) and are crucial to the final accuracy (such as high sensitivity weight) can be accurately identified, thereby achieving precise positioning of the protected target.

[0034] The existing solutions described above are typically one-time static configurations that cannot be self-verified or adjusted. This invention introduces an iterative optimization loop that continuously evaluates the "time-accuracy" balance point of the overall model and automatically adjusts the configuration. Ultimately, it can spontaneously find the optimal solution that meets the preset performance goals, avoiding suboptimal results caused by improper configuration in a single instance.

[0035] The existing solutions described above require users to preset complex intermediate parameters (such as which layers or how many layers to protect), demanding a high level of user expertise. This invention simplifies user input into an intuitive final performance target, with the system automatically handling the complex layer sorting and selection process. This lowers the barrier to entry, enabling even non-expert users to efficiently apply advanced mixed-precision technology.

[0036] It should be understood that, although Figure 1 The steps are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order in which these steps are executed; they can be performed in other orders. Figure 1 At least some of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0037] In one embodiment, such as Figure 3As shown, an adaptive mixed-precision quantization device is provided, including an ONNX conversion module 11, a U8 quantization module 13, a similarity calculation module 15, a sensitivity weight module 17, a sensitivity comprehensive ranking module 19, a high-bit configuration module 21, and an iterative optimization module 23. The ONNX conversion module 11 converts the deep learning floating-point model to ONNX format. The U8 quantization module 13 acquires the quantized image, sets normalization parameters, and then performs UINT8 quantization on the ONNX format deep learning floating-point model using a toolchain to obtain a UINT8 quantized model. The similarity calculation module 15 simultaneously runs the FP32 model and the UINT8 quantized model, extracting tensor outputs layer by layer, and calculating the cosine similarity and cosine similarity difference between each layer based on the tensor output of each layer's operator. The sensitivity weight module 17 dynamically calculates the sensitivity weights of each layer's operator. The sensitivity comprehensive ranking module 19 multiplies the sensitivity weight of each layer operator by the cosine similarity difference between adjacent layers to obtain a comprehensive quantization sensitivity score, and then ranks all layer operators according to their comprehensive quantization sensitivity scores. The high-bit configuration module 21 selects the top K operators with the highest comprehensive quantization sensitivity scores and configures them as high-bit precision types, generating a mixed-precision weighted quantization file; K is a positive integer. The iterative optimization module 23 uses an iterative optimization mechanism to continuously adjust the number of high-bit precision type configurations for the top K operators until the model reaches a preset balance between inference time and accuracy, at which point the iteration terminates and outputs the optimal mixed-precision model corresponding to the deep learning floating-point model.

[0038] The aforementioned adaptive hybrid precision quantization device comprehensively sorts layers by multiplying the cosine similarity difference between adjacent layers with the sensitivity weight of each layer. This ensures accurate identification of bottleneck layers that are susceptible to quantization effects and crucial to the final accuracy, thereby achieving precise positioning of the protected target. An iterative optimization loop is introduced to continuously evaluate the time-accuracy balance point of the overall model and automatically adjust the configuration, ultimately finding the optimal solution that meets the preset performance target spontaneously, avoiding suboptimal results caused by improper configuration. Furthermore, the user's input is simplified to an intuitive final performance target, with the complex layer sorting and selection process automatically handled internally, lowering the technical barrier to entry.

[0039] In one embodiment, during the process of calculating the cosine similarity and cosine similarity difference between layers based on the tensor output of each layer operator, if the current layer operator has multiple inputs, then the largest cosine similarity difference is taken as the cosine similarity difference corresponding to the current layer operator.

[0040] It is understood that specific limitations regarding the aforementioned adaptive mixed-precision quantization device can be found in the corresponding limitations of the adaptive mixed-precision quantization method described above, and will not be repeated here. Each module in the aforementioned adaptive mixed-precision quantization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of a device with data processing capabilities, or stored in software within the memory of the aforementioned device, so that the processor can call and execute the operations corresponding to each module. The aforementioned device can be, but is not limited to, various types of data computing devices already existing in the art.

[0041] In one embodiment, a computer device is also provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following processing steps: converting a deep learning floating-point model to ONNX format; acquiring a quantized image and setting normalization parameters, then performing UINT8 quantization on the ONNX format deep learning floating-point model using a toolchain to obtain a UINT8 quantized model; simultaneously running the FP32 model and the UINT8 quantized model, extracting tensor outputs layer by layer from the operators, and calculating the cosine similarity and cosine similarity difference between each layer based on the tensor outputs of each layer's operators; dynamically calculating... Sensitivity weights for each layer of operators are calculated. The sensitivity weight of each layer is multiplied by the cosine similarity difference between adjacent layers to obtain a comprehensive quantization sensitivity score. All layer operators are then ranked according to their comprehensive quantization sensitivity scores. The top K operators with the highest comprehensive quantization sensitivity scores are selected and configured as high-bit-precision types to generate a mixed-precision weighted quantization file. K is a positive integer. An iterative optimization mechanism is used to continuously adjust the number of high-bit-precision type configurations for the top K operators until the model reaches a preset balance between inference time and accuracy, at which point the iteration terminates, and the optimal mixed-precision model corresponding to the deep learning floating-point model is output.

[0042] In one embodiment, when the processor executes the computer program, it can also implement the steps or sub-steps added in the various embodiments of the adaptive mixed precision quantization method described above.

[0043] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When executed by a processor, the computer program performs the following processing steps: converting a deep learning floating-point model to ONNX format; acquiring a quantized image and setting normalization parameters, then performing UINT8 quantization on the ONNX format deep learning floating-point model using a toolchain to obtain a UINT8 quantized model; simultaneously running the FP32 model and the UINT8 quantized model, extracting tensor outputs layer by layer from the operators, and calculating the cosine similarity and cosine similarity difference between each layer based on the tensor outputs of each layer's operators; dynamically calculating the cosine similarity between each layer's operators. Sensitivity weights are calculated; the sensitivity weight of each layer operator is multiplied by the cosine similarity difference between adjacent layers to obtain a comprehensive quantization sensitivity score, and all layer operators are sorted according to the comprehensive quantization sensitivity scores; the top K operators with the highest comprehensive quantization sensitivity scores are selected and configured as high-bit precision types to generate a mixed-precision weight quantization file; K is a positive integer; an iterative optimization mechanism is used to continuously adjust the number of high-bit precision type configurations for the top K operators until the model reaches a preset balance between inference time and accuracy, at which point the iteration terminates and the optimal mixed-precision model corresponding to the deep learning floating-point model is output.

[0044] In one embodiment, when the computer program is executed by a processor, it can also implement the steps or sub-steps added in the various embodiments of the adaptive mixed precision quantization method described above.

[0045] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), memory bus DRAM (RDRAM), and interface DRAM (DRDRAM), etc.

[0046] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0047] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of protection of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and all such modifications and improvements fall within the scope of protection of the present invention.

Claims

1. An adaptive mixed-precision quantization method, characterized in that, Including the following steps: Convert deep learning floating-point models to ONNX format; After acquiring the quantized image and setting the normalization parameters, the ONNX format deep learning floating-point model is quantized using a toolchain to obtain the UINT8 quantized model. The FP32 model and the UINT8 quantization model are run simultaneously. Tensor outputs are extracted layer by layer from the operators. Based on the tensor outputs of each layer of operators, the cosine similarity and cosine similarity difference between each layer are calculated. Dynamically calculate the sensitivity weights of each layer of operators; The sensitivity weight of each layer operator is multiplied by the cosine similarity difference between adjacent layers to obtain the comprehensive score of each quantization sensitivity, and all layer operators are ranked according to the comprehensive score of each quantization sensitivity. After selecting the top K operators with the highest comprehensive quantization sensitivity scores and configuring them as high-bit precision types, a mixed-precision weighted quantization file is generated; K is a positive integer. An iterative optimization mechanism is adopted to continuously adjust the number of high-bit precision type configurations of the first K operators until the model reaches a preset balance between inference time and precision index, at which point the iteration terminates and the optimal mixed precision model corresponding to the deep learning floating-point model is output.

2. The adaptive hybrid precision quantization method according to claim 1, characterized in that, In the process of calculating the cosine similarity and cosine similarity difference between layers based on the tensor output of each layer operator, if the current layer operator has multiple inputs, then the largest cosine similarity difference is taken as the cosine similarity difference corresponding to the current layer operator.

3. The adaptive hybrid precision quantization method according to claim 1 or 2, characterized in that, The steps for dynamically calculating the sensitivity weights of each layer of operators include: For each operator in the UINT8 quantization model, replace each operator with a high-bit quantized data type; Infer the changed UINT8 quantization model after the replacement and calculate the degree of change in the network output of the replaced UINT8 quantization model; Configure the sensitivity weights of each layer of operators according to the degree of change.

4. The adaptive hybrid precision quantization method according to claim 3, characterized in that, Iterative optimization mechanisms include: Repeatedly iterate through the steps of converting the deep learning floating-point model to ONNX format until the step of selecting the top K operators with the highest comprehensive quantization sensitivity scores and configuring them as high-bit precision types to generate a mixed-precision weighted quantization file. If the current high-bit-precision type configuration simultaneously meets the preset target inference time and target precision, then the iteration should stop immediately.

5. The adaptive hybrid precision quantization method according to claim 4, characterized in that, Iterative optimization mechanisms also include: If the accuracy improvement in multiple consecutive iterations is within the set threshold, then the iteration should be stopped.

6. The adaptive hybrid precision quantization method according to claim 4, characterized in that, Iterative optimization mechanisms also include: If the maximum number of iterations is reached, then the iteration will be forcibly stopped.

7. An adaptive hybrid precision quantization device, characterized in that, include: The ONNX conversion module is used to convert deep learning floating-point models to ONNX format; The U8 quantization module is used to acquire quantized images, set normalization parameters, and then perform UINT8 quantization on the ONNX format deep learning floating-point model through the toolchain to obtain the UINT8 quantized model. The similarity calculation module is used to run the FP32 model and the UINT8 quantization model simultaneously, extract tensor outputs layer by layer operators, and calculate the cosine similarity and cosine similarity difference between each layer based on the tensor outputs of each layer operator. The sensitivity weight module is used to dynamically calculate the sensitivity weight of each layer of operators; The sensitivity comprehensive ranking module is used to multiply the sensitivity weight of each layer operator by the cosine similarity difference between adjacent layers to obtain the comprehensive sensitivity score of each layer, and to rank all layer operators according to the comprehensive sensitivity score of each layer. The high-bit configuration module is used to select the top K operators with the highest comprehensive quantization sensitivity scores, configure them as high-bit precision types, and then generate a mixed-precision weighted quantization file; K is a positive integer. The iterative optimization module is used to continuously adjust the number of high-bit precision type configurations of the first K operators using an iterative optimization mechanism until the model reaches a preset balance between inference time and precision index, at which point the iteration terminates and outputs the optimal mixed precision model corresponding to the deep learning floating-point model.

8. The adaptive hybrid precision quantization device according to claim 7, characterized in that, In the process of calculating the cosine similarity and cosine similarity difference between layers based on the tensor output of each layer operator, if the current layer operator has multiple inputs, then the largest cosine similarity difference is taken as the cosine similarity difference corresponding to the current layer operator.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the adaptive mixed precision quantization method as described in any one of claims 1 to 6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the adaptive mixed precision quantization method according to any one of claims 1 to 6.

Citation Information

Cited By

  • A mixed-precision automated optimization method for efficient deployment of neural networks on FPGA

    CN122261673A

  • A mixed-precision automated optimization method for efficient deployment of neural networks on FPGAs

    CN122261673B