An adaptive mixed-precision quantization method and apparatus
By generating a quantization scheme table offline and updating it dynamically during operation, the problem of decreased model inference accuracy caused by changes in edge device hardware resources is solved, achieving rapid adaptive adjustment and efficient resource adaptation.
Patent Information
- Application Number
- CN202611358826.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-03
- Publication Date
- 2026-11-27
AI Technical Summary
Existing mixed-precision quantization methods cannot quickly adapt to the frequent changes in edge device hardware resources, resulting in a decrease in model inference accuracy. Furthermore, existing search methods are time-consuming and difficult to adjust in real time when resources change.
A quantization scheme table is generated through offline pre-calculation. An appropriate quantization bit width allocation scheme is selected based on the available computing power and memory resources of the device, and the scheme is dynamically updated during operation to achieve adaptive adjustment.
It reduces the consumption of computing power in the equipment, enables rapid adaptive adjustment in response to fluctuations in hardware resources, maintains the accuracy of model inference, and simplifies debugging and optimization work.
Smart Images

Figure CN123178069A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of neural network model quantization technology, specifically relating to an adaptive mixed-precision quantization method and apparatus. Background Technology
[0002] Edge devices such as cameras, robots, and drones generally face limitations in computing power and memory resources. The industry typically uses mixed-precision quantization for model compression. This method allows for the configuration of differentiated quantization bits for different layers of the neural network, thus balancing model inference accuracy with hardware storage and computational overhead. Quantization essentially converts floating-point weights and activation values into low-bit-width integers, a common lightweighting technique for models across various domains. The basic mapping rules for converting floating-point data to integers are as follows: ; In the formula, These are the model's floating-point weights or activation values; This is the quantization scaling factor; For quantization zero point; This is for rounding up to the nearest integer. This is a numerical clipping function; , These represent the minimum and maximum values within the quantized integer range, respectively. The scaling factor calculation, zero-point calculation, symmetric quantization, asymmetric quantization, quantization-aware training gradient calculation, and the related operational logic of the HAQ and EdMIPS algorithms are all existing mature and publicly available technologies; therefore, this paper will not list their various derivations. Currently, conventional methods for determining mixed-precision bit-width allocation rely on reinforcement learning or differentiable architecture search to complete the computation. However, these methods have many shortcomings in practical applications.
[0003] Existing bit-width search processes can only match fixed hardware resource conditions. When edge devices experience multi-task contention for hardware resources or when models are migrated to different hardware platforms, the available computing power and memory of the devices will change. After resource conditions change, the entire search or training process needs to be repeated. The number of network bit-width combinations is huge, and re-adaptation consumes a lot of computing time, making it difficult to make real-time adjustments to frequently changing hardware resources. The quantization strategies generated by searching based on reinforcement learning and differentiable architectures lack a clear derivation path and cannot intuitively reflect the accuracy loss caused by selecting corresponding quantization bits for each network layer, which is not conducive to debugging and optimization work. Most existing processing methods do not set differentiated hierarchical evaluation standards for image classification and object detection visual tasks. Most of them use a uniform value to measure the accuracy reduction caused by single-layer quantization, which makes it difficult to accurately capture the changing characteristics of model output distribution under different tasks. The hierarchical compression order obtained by this method will be biased, and the model inference accuracy will decrease significantly under the same compression degree. Traditional processing methods require extensive sampling and optimization operations to cope with the exponentially expanding bit-width combination search space. When hardware constraints change, the entire search process must be re-executed. It is impossible to generate complete quantization schemes adapted to different compression levels in batches during the offline stage. When device hardware resources change, it is difficult to quickly retrieve the adapted scheme. Hybrid precision quantization technology cannot adapt to edge terminal usage scenarios with continuously changing resources. Summary of the Invention
[0004] This invention provides an adaptive mixed-precision quantization method, comprising: a deployment initial inference phase, wherein, based on the current available computing power and memory resource limit of the device, a quantization bit width allocation scheme is selected from an offline pre-computed quantization scheme table, the quantization bit width allocation scheme is loaded into the pre-trained model to be quantized, and the pre-trained model to be quantized is driven to perform inference; wherein, the quantization bit width allocation scheme is adapted to the current available computing power and memory resources, and is the scheme with the highest precision under the condition of the available computing power and memory resource limit; during the inference operation, the available computing power and memory resources of the device are continuously monitored, and if the available computing power or memory resources change, the quantization bit width allocation scheme with the highest precision corresponding to the current available computing power and memory resource limit is matched from the quantization scheme table, and the quantization bit width allocation scheme of the pre-trained model to be quantized is updated.
[0005] According to one embodiment of the present invention, the method further includes the step of offline pre-computation to generate the quantization scheme table, which further includes: based on a calibration set, the pre-trained model to be quantized, and a plurality of preset candidate quantization bit widths, obtaining quantization configuration information corresponding to the pre-trained model to be quantized under different candidate quantization bit widths through post-training quantization; based on a validation set, taking the output of all layers of the pre-trained model to be quantized using the highest candidate quantization bit width as a benchmark, adjusting the quantization bit width of the corresponding network layer layer by layer to each lower quantization bit width in turn, calling the quantization configuration information to complete quantization inference, calculating the quantization sensitivity respectively, and sorting the low quantization bit width combinations of each layer from low to high according to the quantization sensitivity; taking the highest candidate quantization bit width of all layers of the pre-trained model to be quantized as a baseline, gradually reducing the quantization bit width of each layer according to the quantization sensitivity sorting result, calling the quantization configuration information to perform quantization inference after each adjustment of the quantization bit width, recording the current quantization bit width allocation scheme, the corresponding compression ratio and model accuracy, and summarizing to form the quantization scheme table.
[0006] According to one embodiment of the present invention, the calculation of quantization sensitivity includes: for an image classification task, individually adjusting the quantization bit width of the corresponding network layer while keeping the quantization bit width of the remaining network layers unchanged, and obtaining the classification probability distribution of the output of the pre-trained model to be quantized before and after quantization. Divergence, the aforementioned The divergence value serves as the quantization sensitivity of the network layer.
[0007] According to one embodiment of the present invention, the calculation of quantization sensitivity includes: for the target detection task, adjusting the quantization bit width of the corresponding network layer individually, keeping the quantization bit width of the other network layers unchanged, and obtaining the classification probability distribution of the output of the pre-trained model to be quantized before and after quantization. Divergence and Manhattan distance of the detection box position; combined with the above A comprehensive index is constructed by combining the divergence and the Manhattan distance, and the value of the comprehensive index is used as the quantization sensitivity of the network layer.
[0008] According to one embodiment of the present invention, the quantization bit width allocation scheme is a list of quantization bit allocations covering all network layers of the pre-trained model to be quantized. Each set of quantization bit width allocation schemes is bound to the compression ratio and inference accuracy of the pre-trained model to be quantized. The quantization scheme table stores multiple sets of different quantization bit width allocation schemes, and each set of schemes is arranged in order from largest to smallest compression ratio and from highest to lowest inference accuracy.
[0009] According to one embodiment of the present invention, the step of loading the quantization bit width allocation scheme into the pre-trained model to be quantized and driving the pre-trained model to be quantized to perform inference includes: retrieving the quantization configuration information of the candidate quantization bit widths corresponding to each network layer obtained by offline pre-computation, the pre-trained model to be quantized completing the quantization mapping based on the quantization configuration information, and performing model inference calculation.
[0010] According to one embodiment of the present invention, the step of matching the quantization bit width allocation scheme with the highest accuracy corresponding to the current available computing power and the memory resource limit from the quantization scheme table includes: calculating a target compression ratio based on the available computing power and the memory resource limit; filtering all quantization bit width allocation schemes with a compression ratio less than or equal to the target compression ratio in the quantization scheme table; and selecting the set with the highest model inference accuracy from the filtered quantization bit width allocation schemes as the final quantization bit width allocation scheme used.
[0011] According to one embodiment of the present invention, the step of confirming that the available computing power or the memory resources have changed includes: periodically collecting the available computing power and the memory resources of the device; comparing the available computing power and the memory resources obtained in this collection with the results of the previous collection; confirming that any data of the available computing power or the memory resources is inconsistent with the results of the previous collection, and determining that the available computing power or the memory resources have changed.
[0012] According to one embodiment of the present invention, the step of updating the quantization bit width allocation scheme of the pre-trained model to be quantized includes: loading the quantization bit width allocation scheme with the highest accuracy obtained by matching onto the pre-trained model to be quantized; and replacing the quantization bit width allocation scheme currently used by the pre-trained model to be quantized with the quantization bit width allocation scheme with the highest accuracy.
[0013] This invention also provides an adaptive mixed-precision quantization device, comprising: an offline generation module for offline pre-computation to generate a quantization scheme table; an initial inference module for, during the initial inference deployment phase, selecting a quantization bit width allocation scheme from the quantization scheme table based on the device's current available computing power and memory resource limits, loading the quantization bit width allocation scheme into the pre-trained model to be quantized, and driving the pre-trained model to perform inference; wherein the quantization bit width allocation scheme is adapted to the current available computing power and memory resources, and is the scheme with the highest precision under the conditions of the available computing power and memory resource limits; a resource monitoring module for continuously monitoring the device's available computing power and memory resources during inference operation; and a dynamic update module for, when confirming changes in the available computing power or memory resources, matching again from the quantization scheme table the quantization bit width allocation scheme with the highest precision corresponding to the current available computing power and memory resource limits, and updating the quantization bit width allocation scheme of the pre-trained model to be quantized.
[0014] This solution separates the quantization scheme generation process from the device deployment inference process. All quantization bit width allocation related data is calculated and organized offline. During the device operation phase, scheme matching is completed only by table lookup operations. There is no need to repeat model training and bit width search operations, which can significantly reduce the device's computing power consumption and achieve rapid adaptive adjustment in scenarios with fluctuating hardware resources.
[0015] This scheme determines the compression order of each network layer according to the quantization sensitivity value, sets different sensitivity calculation methods for image classification tasks and object detection tasks, can accurately quantize a single layer to reduce the accuracy attenuation caused by quantization bit width, and forms an ordered scheme set after incremental quantization based on sensitivity sorting. Under the same compression degree, it can better preserve the model inference accuracy.
[0016] This solution fully records the compression ratio and inference accuracy corresponding to each quantization bit width allocation scheme. After the device calculates the target compression index based on the real-time hardware resource limit, it can directly select the quantization scheme that meets the constraints and has the best accuracy. The entire bit width allocation process has numerical judgment basis, which has stronger interpretability compared with the existing search method, and facilitates staff to carry out model debugging and performance iteration.
[0017] After the offline phase is completed, the training quantization, sensitivity calculation and multiple quantization schemes are summarized and stored. There is no need to repeatedly perform complex quantization calculations on the device. This can effectively shorten the time spent on edge terminal model deployment and resource re-adaptation, and adapt to the use scenarios of various edge intelligent devices with continuously changing computing power and memory, such as cameras, robots and drones. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0019] Figure 1 This is a flowchart of the adaptive hybrid precision quantization method provided by the present invention.
[0020] Figure 2 This is a flowchart of offline pre-calculation to generate a quantization scheme table.
[0021] Figure 3 This is a flowchart of matching the highest precision quantization bit width allocation scheme from the quantization scheme table with the current available computing power and memory resource limits.
[0022] Figure 4 It is a flowchart that confirms changes in available computing power or memory resources.
[0023] Figure 5 This is a flowchart of the quantization bit width allocation scheme for updating the pre-trained model to be quantized.
[0024] Figure 6 This is a block diagram of the adaptive hybrid precision quantization device provided by the present invention.
[0025] Figure 7 This is a flowchart of the offline pre-calculation process for generating a quantization scheme table.
[0026] Figure 8 This is a schematic diagram illustrating the principle of obtaining quantization configuration information through post-training quantization.
[0027] Figure 9 This is a schematic diagram illustrating the principle of quantifying sensitivity assessment and generating compression priorities for each layer.
[0028] Figure 10 This is a schematic diagram illustrating the principle of incremental quantization for acquiring quantization scheme information.
[0029] Figure 11 This is a schematic diagram of the process for dynamically updating quantitative configurations during the online deployment phase of this invention.
[0030] Figure 12 This is a curve comparing the accuracy of Faster R-CNN under different compression rates.
[0031] Figure 13 This is a comparison curve of YOLOX's accuracy at different compression rates.
[0032] Figure 14This is a bar chart comparing the GPU time required to generate quantization schemes using different quantization algorithms.
[0033] Figure label: 100: Adaptive mixed-precision quantization device; 110: Offline generation module; 120: Initial inference module; 130: Resource monitoring module; 140: Dynamic update module. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0035] To facilitate understanding of the technical solutions, calculation formulas, and accompanying drawings below, the main technical terms used in this invention are explained uniformly as follows: Quantization: A model compression method that converts the floating-point weights and activation values of the pre-trained model to be quantized into low-bit-width integers for storage and computation, thereby reducing the storage and computing power overhead of edge devices; Mixed precision quantization: different quantization bits are assigned to different network layers of the pre-trained model to be quantized, balancing the model's inference accuracy and the degree of model compression; Compression ratio: The ratio of the storage volume of the pre-trained model after quantization to the storage volume of the original full-precision version. The smaller the value, the higher the degree of model compression. Candidate quantization bit width: Multiple sets of quantization bit values pre-set in the offline process and available for each network layer of the pre-trained model to be quantized; Quantization configuration information: For the pre-trained model to be quantized, the scaling factor and zero-point parameters are obtained by post-training quantization solution. These are used as dedicated configurations for converting between floating-point and fixed-point. Each layer and each candidate quantization bit width corresponds to an independent set of quantization configuration information. Calibration set: A set of unlabeled representative samples used to process the pre-trained model to be quantized. It is only used to fit the quantization parameters and does not participate in the model accuracy evaluation. Validation set: A set of labeled independent samples used to evaluate the inference performance of the pre-trained model to be quantized, and used to calculate quantization sensitivity and test the inference accuracy of the model; Quantization sensitivity: After individually reducing the quantization bit width of a single layer of the pre-trained model to be quantized, the deviation of the model output from the full-height bit width benchmark is quantized. The higher the value, the greater the accuracy loss caused by the quantization of that layer. Divergence: an index used to measure the difference between two sets of probability distributions. This invention calculates the quantization sensitivity for image classification tasks of pre-trained models to be quantized. Manhattan distance ( Distance): Used to calculate the deviation of the bounding box coordinates, width, and height before and after quantization when the pre-trained model to be quantized performs an object detection task; Incremental quantization: Based on the highest bit width of all network layers of the pre-trained model to be quantized, the bit width is gradually reduced layer by layer according to the sensitivity from low to high, and the complete bit width allocation scheme is recorded in each round. Quantization scheme table: For the pre-trained model to be quantized, an ordered data table is generated through offline incremental quantization. Each record is bound to a set of layer bit allocation schemes, corresponding compression ratios and inference accuracy. Edge devices: Terminal inference hardware with limited computing power and memory resources, such as cameras, industrial robots, drones, and vehicle-mounted embedded boxes, where pre-trained models to be quantized are deployed.
[0036] The following is combined with Figures 1 to 14 The present invention describes the adaptive hybrid precision quantization method and apparatus. Figure 1 This is a flowchart of the adaptive hybrid precision quantization method provided by the present invention. Figure 1 As shown, the adaptive mixed-precision quantization method provided by the present invention includes: In step S100, during the initial inference deployment phase, based on the current available computing power and memory resource limits of the device, a quantization bit width allocation scheme is selected from the quantization scheme table generated offline and pre-computed. The quantization bit width allocation scheme is then loaded into the pre-trained model to be quantized, driving the pre-trained model to perform inference. The quantization bit width allocation scheme is adapted to the current available computing power and memory resources and is the scheme with the highest accuracy under the condition of meeting the upper limit of available computing power and memory resources. In step S200, during the inference process, the available computing power and memory resources of the device are continuously monitored. If the available computing power or memory resources change, the quantization bit width allocation scheme with the highest accuracy corresponding to the current upper limit of available computing power and memory resources is matched from the quantization scheme table, and the quantization bit width allocation scheme of the pre-trained model to be quantized is updated.
[0037] Specifically, the entire methodology operates in two consecutive phases: an offline pre-computation phase and an online inference phase. The complete workflow of both phases is presented in [the relevant documentation / platform]. Figure 1 In the offline phase, all quantization schemes are pre-generated. In the online phase, inference and dynamic adaptation are performed based on the pre-generated quantization schemes. All operations in both phases require the use of the quantization scheme table generated and saved in the offline phase as data support.
[0038] First, execute the initial deployment and inference-related operations corresponding to step S100. After the device completes the initialization of the pre-trained model to be quantized, read the available computing power and memory resource limit values that the local hardware can provide. These two sets of values objectively reflect the maximum scale of hardware resources that the device can occupy when running the pre-trained model to be quantized. After reading the resource-related values, retrieve the quantization scheme table stored locally. Select the scheme content that is suitable for the current hardware environment from all the quantization bit width allocation schemes stored in the quantization scheme table. The selection process needs to simultaneously consider both hardware resource constraints and model inference accuracy. The resource occupation scale corresponding to the selected quantization bit width allocation scheme cannot exceed the current available computing power and memory resource limit of the device. At the same time, select the quantization bit width allocation scheme with the highest model inference accuracy value from all quantization bit width allocation schemes that meet the resource constraints as the quantization bit width allocation scheme officially used in this deployment. After determining the target quantization bit width allocation scheme, extract the quantization bit configuration information of each network layer recorded in the scheme, load the entire quantization bit width allocation scheme into the pre-trained model to be quantized, and the pre-trained model to be quantized completes the quantization mapping process according to the quantization bit parameters of each layer specified in the scheme. After the entire mapping process is completed, the device can start uninterrupted model inference calculation.
[0039] After the device completes its initial deployment and enters a stable inference state, it continuously runs the dynamic adaptation operations corresponding to step S200. The device continuously collects its real-time available computing power and real-time memory resource values, and continuously compares the available computing power and memory resource data obtained from different collection periods. If any deviation occurs in the collection results for any type of resource value, it can be determined that the device's available computing power or memory resources have fluctuated. After the resource status changes, there is no need to re-perform quantization search or model compression related calculations. Instead, the locally stored quantization scheme table is retrieved again, and a quantization bit width allocation scheme that simultaneously satisfies resource constraints and optimal inference accuracy is re-matched based on the updated available computing power and memory resource limits. The re-matched quantization bit width allocation scheme is loaded into the pre-trained model to be quantized, and the original quantization bit width allocation rule currently being executed by the pre-trained model to be quantized is replaced with the new quantization bit width allocation scheme. After the replacement, all subsequent inference operations of the pre-trained model to be quantized will run according to the updated quantization parameters. The entire process relies on the pre-built quantization scheme table to achieve autonomous adaptation and adjustment when hardware resources fluctuate.
[0040] Figure 2 This is a flowchart of offline pre-calculation to generate a quantization scheme table. For example... Figure 2 As shown, according to an embodiment of the present invention, the adaptive mixed-precision quantization method provided by the present invention further includes the step of offline pre-calculation to generate a quantization scheme table, and further includes: In step PS100, based on the calibration set, the pre-trained model to be quantized, and multiple preset candidate quantization bit widths, the quantization configuration information of the pre-trained model to be quantized under different candidate quantization bit widths is obtained through post-training quantization. In step PS200, based on the validation set, and taking the output of all layers of the pre-trained model to be quantized with the highest candidate quantization bit width as the benchmark, the quantization bit width of the corresponding network layer is adjusted to each low quantization bit width in turn, the quantization configuration information is called to complete the quantization inference, the quantization sensitivity is calculated respectively, and the low quantization bit width combinations of each layer are sorted from low to high according to the quantization sensitivity. In step PS300, the highest candidate quantization bit width is used as the baseline for all layers of the pre-trained model to be quantized. The quantization bit width of each layer is gradually reduced according to the quantization sensitivity ranking result. After each adjustment of the quantization bit width, the quantization configuration information is called to perform quantization inference, and the current quantization bit width allocation scheme, corresponding compression ratio and model accuracy are recorded. The results are then summarized to form a quantization scheme table.
[0041] Specifically, all computational operations in the offline phase are performed according to... Figure 2 The demonstrated workflow unfolds sequentially, with all calculations revolving around the pre-trained model to be quantized. The data generated at each step continuously supports subsequent calculations. The workflow begins with the calculation of PS100, which requires a calibration set, the pre-trained model to be quantized, and multiple pre-defined candidate quantization bit widths. The entire post-training quantization operation runs based on these three types of data. The calibration set is only used in the post-training quantization process to solve for the scaling factor and zero-point parameters required for quantization mapping; it only participates in quantization parameter fitting and is not used for model accuracy evaluation. The data samples used for subsequent quantization sensitivity calculations are validation sets independent of the calibration set. Using these two datasets separately avoids sensitivity measurement bias caused by parameter fitting. The post-training quantization process will perform calculations separately for each group of candidate quantization bit widths, and solve for the quantization configuration information of each network layer of the pre-trained model to be quantized. The quantization configuration information stores all the parameters that the corresponding network layer needs to use to complete the quantization mapping under the current candidate quantization bit width. After completing this stage of calculation, the quantization configuration information covering all network layers and all candidate quantization bit widths can be obtained. All configuration data are stored in a unified manner for use in the next stage of quantization sensitivity measurement.
[0042] After solving the parameters in step PS100, the computation process for step PS200 begins. This process uses a validation set, distinct from the calibration set. At the start of the computation, all network layers of the pre-trained model are uniformly set to the highest candidate quantization bit width. A complete quantization inference process is executed, and the corresponding output is saved as baseline reference data. Subsequently, each corresponding network layer within the model is traversed sequentially. Each traversal modifies only the quantization bit width of a single corresponding network layer, adjusting it to any lower quantization bit width. The quantization bit widths of the remaining network layers remain unchanged, maintaining the highest candidate quantization bit width. After each adjustment of a single layer's quantization bit width, the previously saved quantization configuration information is retrieved, and a complete quantization inference is performed. The difference between the current inference output and the baseline output is compared, and the quantization sensitivity of the current network layer under the corresponding low quantization bit width condition is calculated based on this difference. After calculating the quantization sensitivity of all network layers and all low quantization bit width combinations, the various layer bit width combinations are arranged in ascending order of quantization sensitivity values, generating a compression priority sequence for subsequent computations.
[0043] Finally, incremental quantization and table summarization are performed for step PS300. In this stage, the initial calculation state remains the same: all network layers of the pre-trained model to be quantized use the highest candidate quantization bit width. Throughout the process, the quantization bit width of each corresponding network layer is progressively reduced according to the compression priority sequence generated in step PS200. After each network layer quantization bit width reduction operation, the quantization configuration information adapted to the current quantization bit width of each layer is retrieved for quantization inference. After the inference operation is completed, the current complete quantization bit width allocation scheme is recorded synchronously, along with the corresponding compression ratio and model inference accuracy. The quantization bit width of network layers is continuously reduced iteratively according to the compression priority sequence until all network layers are adjusted to the lowest candidate quantization bit width. All quantization bit width allocation schemes recorded during the iteration process, along with the corresponding compression ratio and model inference accuracy data, are uniformly integrated and organized to generate a complete quantization scheme table. The quantization scheme table consists of multiple independent records, each corresponding to a complete quantization bit width allocation scheme. Each record synchronously stores the quantization bit allocation information of all network layers, the model compression ratio corresponding to the scheme, and the complete inference accuracy result. All records are uniformly sorted according to compression ratio from largest to smallest and inference accuracy from highest to lowest. This table can provide all available quantization scheme related data for resource adaptation operations during the online inference stage.
[0044] According to an embodiment of the present invention, calculating quantization sensitivity includes: for an image classification task, adjusting the quantization bit width of the corresponding network layer individually while keeping the quantization bit width of the remaining network layers unchanged, and obtaining the classification probability distribution of the output of the pre-trained model to be quantized before and after quantization. Divergence, will The divergence value serves as the quantization sensitivity of the network layer.
[0045] Specifically, when performing quantization sensitivity calculations for image classification tasks, all quantization configuration information pre-calculated by PS100 in the offline stage is used throughout the process. Each calculation operation only modifies the quantization parameters of one target network layer. All other network layers of the pre-trained model to be quantized keep the highest candidate quantization bit width unchanged, thereby eliminating data interference caused by quantization operations of other network layers. Only the magnitude of the model output deviation caused by adjusting the quantization bit width of a single layer is observed.
[0046] After completing the single-layer bit width adjustment, the quantization configuration information matching the current bit width is retrieved to perform complete quantization inference. The unchanged baseline inference output and the perturbation inference output after the single-layer adjustment are recorded respectively. Both types of output contain the classification probability distribution data of the corresponding samples. The formula used to measure the difference between the two distributions is: ; In the formula, This represents the total number of samples in the validation set. The serial number corresponding to the sample. For the baseline model, the first The classification probability distribution of each sample output. For the single-layer quantization perturbation model, the first The classification probability distribution of each sample output. The calculation represents the difference between two probability distributions. The result of the overall calculation is the quantization sensitivity value corresponding to the current network layer. The divergence calculation covers all samples in the validation set to ensure that the calculation result is sufficiently representative.
[0047] When switching to different low quantization bit widths within the same network layer, the above calculation process is repeated. Different low quantization bit widths will generate different values. The divergence value directly reflects the degree of accuracy loss of the network layer under the corresponding bit width. The higher the value, the more significant the negative impact of quantization on the model's inference results. When organizing and compressing the priority sequence later, it will be directly based on each group. The divergence values are sorted in ascending order.
[0048] According to an embodiment of the present invention, calculating quantization sensitivity includes: for an object detection task, adjusting the quantization bit width of the corresponding network layer individually, while keeping the quantization bit width of the other network layers unchanged, and obtaining the classification probability distribution of the output of the pre-trained model to be quantized before and after quantization. Divergence and Manhattan distance of the bounding box position; combined with A comprehensive index is constructed using divergence and Manhattan distance, and the value of the comprehensive index is used as the quantization sensitivity of the network layer.
[0049] Specifically, when performing quantization sensitivity calculations for target detection tasks, all quantization configuration information stored in advance by the PS100 in the offline steps is still used. In a single calculation, only the quantization bit width of a single target network layer is modified. All other network layers of the pre-trained model to be quantized keep the highest candidate quantization bit width unchanged, thereby isolating the data interference caused by quantization operations at other levels. Only the change in the model detection results after adjusting the bit width at the current level is observed separately.
[0050] After completing single-layer bit-width adjustment and loading matching quantization configuration information to execute full quantization inference, two sets of data are simultaneously acquired: the baseline inference output and the single-layer perturbation inference output. These two sets of data contain both the classification probability distribution corresponding to the image targets and the bounding box coordinates for each target. The differences between the classification probability distributions are analyzed through... Divergence is used for measurement, and the detection box position deviation is used for measurement via Manhattan distance. The comprehensive index calculation method used in this invention is recorded as the formula: ; In the formula, This represents the total number of samples contained in the validation set; for the _i_th ... One sample, This represents the total number of detection boxes contained within the sample; For the baseline model The sample, the first The classification probability distribution of each target; For the single-layer quantization perturbation model The sample, the first The classification probability distribution of each target; The coordinates, width, and height of the detection box output by the baseline model; The coordinates, width, and height of the detection box output by the single-layer quantization perturbation model; The hyperparameter used to balance classification bias and localization bias is the result of the overall formula calculation, which is the quantization sensitivity value of the current network layer under the condition of low quantization bit width.
[0051] When switching the same network layer to different low quantization bit widths, the entire calculation process is repeated. Different low quantization bit widths will generate different comprehensive index values. The higher the comprehensive index value, the more prominent the negative impact on the overall output of the target detection model after the current network layer reduces the quantization bit width. When sorting the compression priority sequence later, the comprehensive index values corresponding to all layer bit width combinations are sorted from smallest to largest to ensure that the network with less accuracy loss is given priority for compression operation.
[0052] The sensitivity evaluation index of this invention is not limited. Divergence and Manhattan composite metrics have several equivalent alternatives: for image classification tasks, they can be... The divergence is replaced by the difference in cross-entropy between classification layers, the cosine similarity of the output vector, and the decrease in the accuracy of the first classification layer as the basis for determining the sensitivity of a single layer; at the same time, the evaluation granularity can be refined from a single network layer to a single convolutional channel, or the joint sensitivity can be calculated by joint perturbation of multiple network layers, all of which are equivalent to the innovative concepts of this invention.
[0053] All of the aforementioned replacement indices and stratified granularity adjustments are based on the inventive concept of measuring the loss of quantification accuracy by the difference in model output, and all fall under the same protection as this invention.
[0054] According to an embodiment of the present invention, the quantization bit width allocation scheme is a list of quantization bit allocations covering all network layers of the pre-trained model to be quantized, and each set of quantization bit width allocation schemes is bound to the compression ratio and inference accuracy of the pre-trained model to be quantized. The quantization scheme table stores multiple different quantization bit width allocation schemes, and each scheme is arranged in order of compression ratio from large to small and model inference accuracy from high to low.
[0055] Specifically, a complete list of quantization bit allocations will cover all network layers involved in forward inference, including convolutional layers, fully connected layers, normalization layers, and activation layers within the model. Each layer will be independently configured with corresponding quantization bits, and different bit widths can be selected for each layer to achieve mixed precision differential compression. For example, the network layers corresponding to the backbone network will be configured with an 8-bit quantization bit width, the shallow network with a 6-bit quantization bit width, and the detection output network layer with a 4-bit quantization bit width.
[0056] For each complete bit width allocation scheme generated, the offline process will simultaneously collect two sets of supporting data and bind them to the scheme for storage: First, the overall compression rate of the model corresponding to the current scheme. The compression rate is obtained by the ratio of the storage space of the quantized model to the storage space of the original full-precision model. The smaller the value, the stronger the lightweight nature of the model. Second, the model accuracy obtained by the scheme inference on the validation set. For image classification tasks, classification accuracy is used as the accuracy index. For object detection tasks, mAP@0.5 and mAP@0.5:0.95 can be used as accuracy indices. Here, mAP@0.5 represents the average accuracy calculated when the intersection-union ratio threshold is 0.5, and mAP@0.5:0.95 represents the average accuracy calculated under multiple thresholds from 0.5 to 0.95, reflecting the degree of accuracy loss caused by the quantization scheme.
[0057] The list of quantized bit allocations generated from all iterations, along with their respective bound compression ratio and accuracy data, is uniformly summarized and stored in the quantization scheme table. Within the table, all scheme records are uniformly sorted, with the primary sorting criterion being compression ratio, arranged in descending order. For multiple schemes with the same compression ratio, the secondary sorting criterion is model inference accuracy, with higher accuracy schemes appearing earlier in the list.
[0058] The ordered storage quantization scheme table simplifies the matching logic for online devices: after calculating the allowable target compression ratio based on real-time computing power and memory resource limits, the device iterates through the quantization scheme table to filter records with compression ratios not exceeding the target compression ratio, and selects the scheme with the highest model inference accuracy from the candidate schemes. Since the compression ratio and model inference accuracy of each scheme have been pre-calculated and stored in the offline stage, there is no need to re-execute model inference or accuracy evaluation in the online stage; only numerical filtering and comparison are required. This reduces the computational overhead of real-time device matching and ensures rapid quantization configuration updates when hardware resources fluctuate.
[0059] In addition to incremental compression based entirely on sensitivity in ascending order, a sorting rule based on the ratio of accuracy loss under the same compression magnitude can also be adopted to prioritize the compression of the network layer with the lowest accuracy decay under the same volume reduction. At the same time, the quantization scheme table retrieval method can be optimized into binary search, which greatly shortens the time spent traversing a large number of schemes. This is an extended equivalent implementation of the present invention.
[0060] This type of replacement sorting logic still completes the hierarchical compression based on sensitivity priority, which does not change the idea of the offline incremental generation scheme of the present invention, and is also within the protection scope of the present invention.
[0061] According to an embodiment of the present invention, the step of loading a quantization bit width allocation scheme into a pre-trained model to be quantized and driving the pre-trained model to perform inference includes: The quantization configuration information of the candidate quantization bit widths for each network layer obtained from offline pre-computation is retrieved. The pre-trained model to be quantized completes the quantization mapping based on the quantization configuration information and performs model inference calculation.
[0062] Specifically, the quantization bit width allocation scheme records the target quantization bit value used by each layer of the model. Based on this scheme, the quantization configuration information calculated and saved in advance during the offline stage can be matched layer by layer. The quantization configuration information consists of quantization parameters specific to the corresponding network layer and quantization bit width, mainly including two types of mapping parameters: quantization zeros and scaling factors. These parameters are pre-solved and persistently stored during the offline training quantization stage.
[0063] For example, if the network layer corresponding to the backbone network is allocated an 8-bit quantization width, the program will read the scaling factor and zero-point parameters corresponding to the 8 bits of the network layer pre-stored in the offline stage according to the layer number and the 8-bit index.
[0064] When the device loads the quantization scheme, it traverses all network layers of the model, reads the target quantization bits allocated to the current layer, retrieves the matching quantization configuration parameters by index, and writes them into the model's inference unit. During inference, the input floating-point features are converted between floating-point and low-ratio fixed-point data using scaling factors and zero-point operations. After each layer's fixed-point operation is completed, the data is mapped back to floating-point features, thus completing the forward inference process for image classification or object detection.
[0065] All quantization mapping parameters are pre-generated offline. The device only needs to read and load parameters online, without needing to fit quantization parameters in real time. When changing the quantization scheme, the model initialization can be completed quickly, ensuring that the inference service of edge devices is not interrupted for a long time.
[0066] Figure 3 This is a flowchart showing how to match the highest precision quantization bit width allocation scheme from the quantization scheme table, corresponding to the current available computing power and memory resource limits. For example... Figure 3 As shown, according to an embodiment of the present invention, the step of matching the quantization bit width allocation scheme with the highest precision corresponding to the current available computing power and memory resource limit from the quantization scheme table includes: In step S221, the target compression ratio is calculated based on the available computing power and the upper limit of memory resources; In step S222, all quantization bit width allocation schemes with a compression ratio less than or equal to the target compression ratio are selected from the quantization scheme table; In step S223, the quantization bit width allocation scheme with the highest model inference accuracy is selected from the selected quantization bit width allocation schemes as the final quantization bit width allocation scheme.
[0067] Specifically, the maximum storage space that the device can occupy during operation and the maximum computing throughput jointly constrain the lightweighting allowed by the model. The higher these two values are, the more bits the model can retain and the lower the compression level; conversely, the more strained the hardware resources, the greater the compression required by the model. The device first reads two types of hardware indicators: the current maximum available memory and the maximum inference computing power, and then calculates the target compression ratio using preset conversion rules.
[0068] The conversion relationship between device hardware resources and the model's allowable compression level is as follows: ; In the formula, This represents the maximum available computing power and memory before the equipment change. This represents the maximum available computing power and memory after the device update. This represents the compression ratio of the original model. This represents the target compression ratio adapted to the current hardware conditions.
[0069] This value represents the maximum model compression level that the current hardware can handle. For example, if the edge device's memory can only store quantized files that are 45% the size of the original model, then the target compression ratio obtained is 0.45. Any solution whose quantized size exceeds 45% of the original model cannot be adapted to this device.
[0070] After obtaining the target compression ratio, perform the filtering operation in step S222: traverse the pre-built offline ordered quantization scheme table, extract all records in the table whose compression ratio value is not greater than the target compression ratio, and form a candidate scheme set; since the quantization scheme table is pre-sorted according to compression ratio from large to small and precision from high to low under the same compression ratio, the traversal search does not require full sorting and comparison, and the search efficiency is higher.
[0071] After the screening is completed, the process proceeds to step S223, which selects the optimal quantization bit allocation list from the candidate set, based on the highest inference accuracy index. Since all schemes in the candidate set meet both memory and computing power hardware constraints, the scheme with the highest accuracy is "the scheme with the highest accuracy under the conditions of the available computing power and the upper limit of memory resources".
[0072] It should be noted that the above three-step matching logic does not distinguish between scenarios: whether it is the first loading of the model during the initial deployment of the device, or the rematching of the quantization scheme after monitoring the fluctuation of computing power and memory during operation, the matching process from S221 to S223 is exactly the same. Only the real-time values of the currently available computing power and memory resources are changed. The entire matching logic is unified, and there is no need to design two independent retrieval programs, which reduces the development and maintenance costs of local code on the device.
[0073] If the number of entries in the offline generated quantization scheme table is large, the compression rate can be pre-indexed in ascending order, and binary search can be used to replace sequential traversal to quickly locate the optimal quantization scheme that meets the constraints, further reducing the time spent on table lookup at the terminal. This is the preferred equivalent implementation method of the present invention.
[0074] The optimization method only optimizes the retrieval and traversal approach, without changing the matching logic of first calculating the target compression ratio and then selecting the optimal solution. This optimized implementation method is also protected by this solution.
[0075] Figure 4 This is a flowchart confirming changes in available computing power or memory resources. For example... Figure 4 As shown, according to an embodiment of the present invention, the step of confirming a change in available computing power or memory resources includes: In step S211, the available computing power and memory resources of the periodic acquisition device are considered; In step S212, the available computing power and memory resources obtained in this collection are compared with the results of the previous collection. In step S213, if any data of available computing power or memory resources is found to be inconsistent with the previous round of collection results, it is determined that the available computing power or memory resources have changed.
[0076] Specifically, the resource monitoring process will not be interrupted during the continuous operation of the model inference service. The system is pre-set with a fixed collection cycle, such as performing a resource collection operation every 1 second or 5 seconds. The cycle length can be flexibly configured according to the computing power availability of the edge devices. The collection objects are divided into two types of hardware indicators: one is the current remaining available memory capacity, which represents the upper limit of storage that the device can allocate to the model; the other is the idle computing power load, which represents the computing throughput that the device can supply to the model inference. Both types of data are read and cached synchronously.
[0077] After each round of data collection is completed, the comparison logic of step S212 will be executed. The system separately retains the available computing power and available memory values collected in the previous cycle as a benchmark. The two sets of data collected in this round are compared with the corresponding benchmark values one by one. The computing power and memory are verified separately and do not interfere with each other's judgment logic.
[0078] If either the memory usage value or the computing load value changes, proceed to step S213 to determine if resource fluctuations have occurred. For example: if the memory remaining was 2000MB in the previous round, but only 800MB remains in this round (other background programs are preempting memory); or if the CPU idle computing power was 70% in the previous round, but has dropped to 30% in this round (multi-task parallel computing power is being used). If either of these values is not equal to the previous round, it is determined that the device hardware resource conditions have changed, and the subsequent process of re-matching the quantization scheme is automatically triggered.
[0079] The method of setting up periodic polling comparison does not require continuous real-time monitoring of system resources, balancing monitoring sensitivity and device power consumption; at the same time, it adopts a judgment rule that triggers adaptation when any indicator changes, so that there will be no problem of missed updates when only memory changes and computing power remains unchanged, or ignoring memory constraints when only computing power changes, ensuring that as long as hardware resource constraints change, an appropriate quantization bit width allocation scheme is selected in a timely manner.
[0080] Figure 5 This is a flowchart illustrating the quantization bit width allocation scheme for updating the pre-trained model to be quantized. For example... Figure 5 As shown, according to an embodiment of the present invention, the step of updating the quantization bit width allocation scheme of the pre-trained model to be quantized includes: In step S231, the quantization bit width allocation scheme with the highest accuracy obtained by matching is loaded into the pre-trained model to be quantized; In step S232, the quantization bit width allocation scheme currently used by the pre-trained model to be quantized is replaced with the quantization bit width allocation scheme with the highest accuracy.
[0081] Specifically, when the system determines that the available computing power and memory resources of the device are fluctuating, and through... Figure 3 After the corresponding matching process selects the optimal quantization bit width allocation scheme that adapts to the new resource constraints, the scheme update operation is immediately executed. Step S231 is responsible for completing the data loading work of the new scheme. The system reads the entire set of quantization bit allocation list, and according to the quantization bit width index corresponding to each layer in the list, it retrieves the corresponding quantization configuration parameters such as scaling factor and zero point that are stored offline. The system completes the parameter reading and temporary caching layer by layer to prepare the data for replacing the original quantization rules.
[0082] After loading is complete, step S232 is executed to perform the replacement operation. This directly overwrites the old quantization bit width and mapping parameters currently in effect in the inference unit of the pre-trained model to be quantized, discarding the quantization configuration previously adapted to the old hardware resources. The entire process requires no retraining, no re-searching for quantization combinations, and no restarting of the pre-trained model's inference process. The replacement operation employs a layered synchronous update mechanism to avoid inference results being corrupted due to a mix of old and new parameters in some network layers.
[0083] After the replacement is completed, all subsequent image forward inference processes of the pre-trained model to be quantized will perform floating-point and fixed-point data mapping based on the newly loaded quantization configuration, continuously maintaining optimal detection or classification accuracy under the current hardware resource conditions. The entire update process is lightweight and time-efficient, and can seamlessly switch quantization strategies when edge device resources change dynamically, ensuring uninterrupted operation of inference services.
[0084] The present invention also provides an adaptive mixed-precision quantization device 100, such as... Figure 6 As shown, it includes: The offline generation module 110 is used for offline pre-calculation to generate a quantization scheme table; The initial inference module 120 is used to select a quantization bit width allocation scheme from the quantization scheme table based on the current available computing power and memory resource limits of the device during the initial inference deployment phase, load the quantization bit width allocation scheme into the pre-trained model to be quantized, and drive the pre-trained model to be quantized to perform inference; wherein, the quantization bit width allocation scheme is adapted to the current available computing power and memory resources, and is the scheme with the highest accuracy under the condition of meeting the upper limit of available computing power and memory resources. Resource monitoring module 130 is used to continuously monitor the available computing power and memory resources of the device during inference operation; The dynamic update module 140 is used to confirm that when the available computing power or memory resources change, it will match the highest precision quantization bit width allocation scheme corresponding to the current upper limit of available computing power and memory resources from the quantization scheme table again, and update the quantization bit width allocation scheme of the pre-trained model to be quantized.
[0085] The aforementioned offline generation module 110, initial inference module 120, resource monitoring module 130, and dynamic update module 140 correspond to all execution steps of offline pre-calculation, initial inference, resource monitoring, and dynamic update in the aforementioned adaptive mixed-precision quantization method. The execution logic and method flow of each module of the device correspond one-to-one and can be understood by mutual reference. To avoid repetition, the specific execution process of each module of the device will not be described here.
[0086] This invention also includes five detailed principle block diagrams, which correspond to the five major implementation stages: offline quantization process, post-training quantization parameter solving, quantization sensitivity hierarchical perturbation evaluation, incremental quantization to generate quantization schemes, and online deployment to dynamically update quantization configurations.
[0087] Figure 7 A complete flowchart for generating quantization schemes for offline pre-computation is provided, which connects all processes including calibration set processing, post-training quantization, hierarchical sensitivity measurement, incremental compression, and quantization scheme table archiving, fully demonstrating the complete execution chain for batch generation of multiple quantization schemes in the offline stage.
[0088] Figure 8 This diagram illustrates the principle of obtaining quantization configuration information for post-training quantization, showing three types of input data: calibration set, pre-trained model to be quantized, and preset candidate quantization bit width. It also shows the complete mapping process between the scaling factor and zero-point parameters of each network layer. All offline quantization conversion parameters are pre-calculated and stored through this process.
[0089] Figure 9 This diagram illustrates the principle of quantization sensitivity assessment and hierarchical compression priority generation. The model output with the highest quantization bit width across all networks is used as the benchmark. Bits are individually reduced layer by layer to generate perturbation inference results. The deviation from the benchmark output is compared to obtain the quantization sensitivity of each network layer. The index calculation is performed separately for image classification and object detection tasks to generate the hierarchical compression priority order.
[0090] Figure 10 This is a schematic diagram of the incremental quantization scheme information acquisition principle. The full-width model is used as the initial baseline. The network quantization bits are reduced layer by layer in order of sensitivity from low to high. After each round of compression, the current bit allocation scheme, corresponding compression rate and inference accuracy are recorded synchronously. The process is iterated until all networks switch to the lowest candidate bit width, and the ordered quantization scheme table is obtained.
[0091] Figure 11 This is a schematic diagram of the dynamic update quantization configuration process during the online deployment phase of the present invention. It shows three typical scenarios: changes in edge device memory usage, fluctuations in computing power load, and model migration across hardware. The device only needs to read the pre-stored quantization scheme table to complete the matching, without having to repeatedly perform quantization search or model retraining, and can quickly switch to adapt to the quantization strategy.
[0092] To comprehensively verify the overall implementation performance of this invention, performance tests were conducted through three sets of comparative experiments, and the experimental results correspond to... Figure 12 , Figure 13 , Figure 14 As shown, the overall technical effectiveness of this invention is fully demonstrated from two dimensions: model inference accuracy and offline quantization computing power overhead. In this experiment, the definition of compression ratio is completely consistent with the previous one. The smaller the compression ratio value, the stronger the lightweight compression degree of the model. Figure 12 The curves show the comparison of detection accuracy of the Faster R-CNN model under different compression rates. Figure 13 The two curves are comparison curves of the YOLOX lightweight detection model with the same specifications. Both curves use HAQ and EdMIPS, two mainstream hybrid quantization algorithms, as controls, and a full-precision model is added as a benchmark reference. In the entire compression ratio range, the present invention shows good accuracy preservation ability, and the accuracy advantage is particularly prominent in high compression and high lightweight scenarios, proving that the layered differential sensitivity compression strategy can effectively suppress the accuracy decay caused by quantization. Figure 14 A bar chart comparing the GPU time required to generate a complete set of quantization schemes offline for each algorithm is presented. Computational statistics are performed for Faster R-CNN and YOLOX models. Existing algorithms typically take ten to twenty hours for offline computation, while this invention only requires 1.3 hours and 1.7 hours respectively to generate a complete set of multi-level quantization schemes in batches, significantly reducing offline preprocessing computational overhead. The combined results of three sets of experiments demonstrate that this invention can significantly reduce the cost of generating offline quantization schemes while maintaining high inference accuracy. It also supports instantaneous table lookup adaptation under scenarios with fluctuating computing power and memory on edge devices, and its overall performance is significantly superior to existing quantization implementations.
[0093] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An adaptive mixed-precision quantization method, characterized in that, include: During the initial inference deployment phase, based on the device's current available computing power and memory resource limits, a quantization bit width allocation scheme is selected from the quantization scheme table generated offline and pre-computed. The quantization bit width allocation scheme is then loaded into the pre-trained model to be quantized, driving the pre-trained model to perform inference. The quantization bit width allocation scheme is adapted to the current available computing power and memory resources, and is the scheme with the highest accuracy under the conditions of the available computing power and memory resource limits. During inference, the available computing power and memory resources of the device are continuously monitored. If the available computing power or memory resources change, the device is matched with the highest precision quantization bit width allocation scheme corresponding to the current upper limit of the available computing power and memory resources from the quantization scheme table, and the quantization bit width allocation scheme of the pre-trained model to be quantized is updated.
2. The method according to claim 1, characterized in that, It also includes the step of offline pre-computation to generate the quantization scheme table, further including: Based on the calibration set, the pre-trained model to be quantized, and multiple preset candidate quantization bit widths, the quantization configuration information of the pre-trained model to be quantized under different candidate quantization bit widths is obtained through post-training quantization. Based on the validation set, and taking the output of all layers of the pre-trained model to be quantized with the highest candidate quantization bit width as the benchmark, the quantization bit width of the corresponding network layer is adjusted to each low quantization bit width in turn. The quantization configuration information is called to complete the quantization inference, the quantization sensitivity is calculated respectively, and the low quantization bit width combinations of each layer are sorted from low to high according to the quantization sensitivity. Using the highest candidate quantization bit width as the baseline for all layers of the pre-trained model to be quantized, the quantization bit width of each layer is gradually reduced according to the quantization sensitivity ranking result. After each adjustment of the quantization bit width, the quantization configuration information is called to perform quantization inference, and the current quantization bit width allocation scheme, corresponding compression ratio and model accuracy are recorded, and the quantization scheme table is summarized.
3. The method according to claim 2, characterized in that, The calculation of quantization sensitivity includes: For image classification tasks, the quantization bit width of the corresponding network layer is adjusted individually, while keeping the quantization bit width of the other network layers unchanged. The classification probability distribution of the output of the pre-trained model to be quantized before and after quantization is then calculated. Divergence, the aforementioned The divergence value serves as the quantization sensitivity of the network layer.
4. The method according to claim 2, characterized in that, The calculation of quantization sensitivity includes: For the object detection task, the quantization bit width of the corresponding network layer is adjusted individually, while keeping the quantization bit width of the other network layers unchanged. The classification probability distribution of the output of the pre-trained model to be quantized before and after quantization is then calculated. Divergence and Manhattan distance of the bounding box position; In conjunction with the above A comprehensive index is constructed by combining the divergence and the Manhattan distance, and the value of the comprehensive index is used as the quantization sensitivity of the network layer.
5. The method according to claim 1, characterized in that, The quantization bit width allocation scheme is a list of quantization bit allocations covering all network layers of the pre-trained model to be quantized. Each quantization bit width allocation scheme is bound to and records the compression rate and inference accuracy of the pre-trained model to be quantized. The quantization scheme table stores multiple different quantization bit width allocation schemes, and each scheme is arranged in order of compression ratio from large to small and model inference accuracy from high to low.
6. The method according to claim 1, characterized in that, The steps of loading the quantization bit width allocation scheme into the pre-trained model to be quantized and driving the pre-trained model to perform inference include: The quantization configuration information of the candidate quantization bit widths for each network layer obtained from offline pre-computation is retrieved. The pre-trained model to be quantized completes the quantization mapping based on the quantization configuration information and performs model inference calculation.
7. The method according to claim 1, characterized in that, The step of matching the highest precision quantization bit width allocation scheme corresponding to the current available computing power and the memory resource limit from the quantization scheme table includes: The target compression ratio is calculated based on the available computing power and the upper limit of memory resources; Filter all quantization bit width allocation schemes in the quantization scheme table whose compression ratio is less than or equal to the target compression ratio; The quantization bit width allocation scheme with the highest model inference accuracy is selected from the selected schemes and used as the final quantization bit width allocation scheme.
8. The method according to claim 1, characterized in that, The step of confirming changes in the available computing power or the memory resources includes: The available computing power and memory resources of the device are periodically collected; The available computing power and memory resources obtained in this collection are compared with the results of the previous collection. If any data of the available computing power or the memory resources is found to be inconsistent with the results of the previous round of collection, it is determined that the available computing power or the memory resources have changed.
9. The method according to claim 1, characterized in that, The steps for updating the quantization bit width allocation scheme of the pre-trained model to be quantized include: The quantization bit width allocation scheme with the highest accuracy obtained by matching is loaded into the pre-trained model to be quantized; The quantization bit width allocation scheme currently used by the pre-trained model to be quantized is replaced with the quantization bit width allocation scheme that has the highest accuracy.
10. An adaptive hybrid precision quantization device, characterized in that, include: The offline generation module is used for offline pre-calculation to generate a quantization scheme table; The initial inference module is used to select a quantization bit width allocation scheme from the quantization scheme table based on the current available computing power and memory resource limit of the device during the initial inference deployment phase, load the quantization bit width allocation scheme into the pre-trained model to be quantized, and drive the pre-trained model to be quantized to perform inference; wherein, the quantization bit width allocation scheme is adapted to the current available computing power and memory resources, and is the scheme with the highest accuracy under the condition of the available computing power and memory resource limit; The resource monitoring module is used to continuously monitor the available computing power and memory resources of the device during inference operation; The dynamic update module is used to, when it is confirmed that the available computing power or the memory resources have changed, match again from the quantization scheme table the highest precision quantization bit width allocation scheme corresponding to the current available computing power and the upper limit of the memory resources, and update the quantization bit width allocation scheme of the pre-trained model to be quantized.
