A visual model quantization method and system

CN122616620APending Publication Date: 2026-08-21AIXIN YUANZHI SEMICONDUCTOR (CHONGQING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610941824.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-26
Publication Date
2026-08-21

AI Technical Summary

Technical Problem

[0005]本申请实施例提供一种视觉模型量化方法及系统,旨在解决现有视觉模型量化中因忽略层间特征敏感度差异,难以在超低比特混合精度下实现精度与效率平衡的技术问题

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122616620A_ABST
    Figure CN122616620A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence, and provides a visual model quantification method and system.The visual model quantification method comprises the following steps: obtaining a target visual network full-precision base model, inserting a pseudo-quantization node to generate a pseudo-quantization model; dividing the network layer into a sensitive layer and a non-sensitive layer based on network layer feature sensitivity, and allocating differentiated initial quantization bit widths; taking the initial quantization bit width as a starting point, performing quantization perception training on the pseudo-quantization model, and jointly optimizing the quantization bit width, the gradient transmission coefficient of the pseudo-quantization node and the learnable quantization calibration parameter in the training process; and removing the pseudo-quantization node to generate a quantization visual model.The application balances the precision and efficiency under the condition of ultra-low bit mixed precision through feature sensitivity division, dynamic adjustment and double calibration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, specifically to a method and system for quantifying visual models. Background Technology

[0002] Model quantization is a core technology for lightweighting models and accelerating inference in deep learning. The core idea is to map network weights and activation values ​​from high-precision floating-point format to low-precision fixed-point representation. This completes the numerical representation downgrading under the premise of controllable precision loss, which can effectively reduce model storage overhead and improve memory access and computation efficiency. It is an important engineering means to achieve efficient deployment of neural networks on edge devices, mobile devices and embedded platforms.

[0003] Existing quantization techniques can be mainly divided into two categories: Post-Training Quantization (PTQ) and Quantization-Aware Training (QAT).

[0004] Post-training quantization methods, which do not require retraining the model, offer advantages such as high deployment efficiency and low resource consumption, and are widely used for the rapid lightweight quantization of various models. Quantization-aware training methods, by inserting pseudo-quantization operators during training to simulate real quantization effects, can achieve higher quantization accuracy, but suffer from high training costs and limited adaptability. Summary of the Invention

[0005] This application provides a visual model quantization method and system, aiming to solve the technical problem that existing visual model quantization methods struggle to achieve a balance between accuracy and efficiency at ultra-low bit mixing precision due to neglecting the differences in sensitivity of inter-layer features.

[0006] This application provides a visual model quantization method, including: Obtain the full-precision base model of the target visual network, and insert pseudo-quantization nodes into the weight layers of the full-precision base model to generate a pseudo-quantization model; Based on the feature sensitivity of the network layer according to the pseudo-quantization model, the network layer is divided into sensitive layer and non-sensitive layer, and different initial quantization bit widths are assigned to the sensitive layer and non-sensitive layer. Starting with the initial quantization bit width, quantization-aware training is performed on the pseudo-quantization model. During the training process, the quantization bit width, gradient transfer coefficients of pseudo-quantization nodes, and learnable quantization calibration parameters are jointly optimized.

[0007] Remove pseudo-quantization nodes from the pseudo-quantization model to generate a quantized visual model with quantized parameters.

[0008] In this way, differentiated initial bit width allocation is achieved through feature sensitivity partitioning, the bit width is made adaptive to the training process through a dynamic adjustment mechanism, and the quantization accuracy is further improved through dual calibration. Finally, a balance between accuracy and efficiency is achieved under ultra-low bit mixed precision.

[0009] In one possible implementation, during quantization-aware training, the quantization bit width of the network layer and the gradient transfer coefficient of the corresponding pseudo-quantization node are dynamically adjusted based on the quantization error of the network layer obtained from the quantization-aware training. During the quantization perception training process, the quantization parameters of the sensitive layer are periodically recalibrated. At the end of the training, global calibration constraints are calculated based on the feature sensitivity and quantization error of the network layer of the pseudo-quantization model, and the learnable quantization calibration parameters of the pseudo-quantization model are optimized based on the global calibration constraints.

[0010] In this way, by dynamically adjusting the bit width and gradient transfer coefficients, the quantization resource allocation achieves an adaptive response to real-time errors, maximizing computational efficiency while ensuring the accuracy of key layers. Combining the dual mechanisms of periodic recalibration and global calibration constraints, feature distribution drift and cross-layer error accumulation during training are suppressed, improving the convergence stability and final inference accuracy of the pseudo-quantized model.

[0011] In one possible implementation, the quantization perception training process also includes: Construct a learnable error propagation coefficient matrix, where the error propagation coefficient matrix is ​​used to characterize the influence weight of the quantization error in the previous network layer on the subsequent network layer. In each training iteration, the cumulative cross-layer error perceived by the subsequent network layer is calculated based on the error propagation coefficient matrix and the quantization error of the network layer. The cumulative error across layers is added as an additional loss term to the total loss function during training to drive network parameter updates.

[0012] In this way, the quantization error of the previous network layer is explicitly propagated to the loss function of the next network layer through a learnable error propagation matrix. This forces the parameter updates of the next network layer to compensate for the quantization distortion of the previous network layer, suppressing error propagation at the source and alleviating the problem of error accumulation in traditional layer-by-layer quantization.

[0013] In one possible implementation, the quantization perception training process also includes: Perform channel alignment and distribution alignment operations on the feature maps of adjacent network layers. Based on the mean and variance of the feature maps corresponding to the previous network layers, and the mean and variance of the feature maps corresponding to the next network layers, the quantized feature maps of the previous layers are scaled and shifted to match the distribution of the feature maps corresponding to the previous network layers.

[0014] In this way, by introducing a feature distribution alignment mechanism between adjacent layers, the quantized features are scaled and shifted using the mean and variance of the feature maps in the previous layer, eliminating the inter-layer distribution mismatch caused by quantization noise and ensuring the normal propagation of gradients in deep networks. At the same time, the alignment operation reduces the sensitivity of subsequent network layers to quantization distortion, allowing the feature representation capability under ultra-low bit quantization to be fully preserved, and improving the convergence stability and inference accuracy of the pseudo-quantized model.

[0015] In one possible implementation, based on the feature sensitivity of the network layers in the pseudo-quantization model, the network layers are divided into sensitive layers and non-sensitive layers, including: Calculate the gradient norm of the task loss function relative to the output feature map of the network layer, and use the gradient norm as the feature sensitivity of the network layer; The comparison threshold is determined based on the maximum value of the feature sensitivity of all network layers; Network layers with feature sensitivity greater than or equal to the comparison threshold are classified as sensitive layers, and network layers with feature sensitivity less than the comparison threshold are classified as insensitive layers.

[0016] In this way, the sensitivity of each layer to quantization error is objectively quantified by the gradient norm, and sensitive and non-sensitive layers are automatically divided based on adaptive thresholds, avoiding the subjectivity and non-universality of human experience settings.

[0017] In one possible implementation, the quantization bit width of the network layer and the gradient transfer coefficients of the corresponding pseudo-quantization nodes are adjusted based on the quantization error of the network layer obtained from quantization-aware training, including: Obtain the quantization error between the quantized feature map of the network layer and the corresponding full-precision feature map of the base model; If the quantization error is greater than the first error threshold, increase the quantization bit width of the network layer and increase the gradient propagation coefficient of the corresponding pseudo-quantization node. If the quantization error is less than the second error threshold, the quantization bit width of the network layer is reduced, and the gradient propagation coefficient of the corresponding pseudo-quantization node is reduced. The first error threshold is greater than the second error threshold.

[0018] In this way, based on the comparison between real-time error and dual thresholds, the bit width and gradient transfer coefficient are dynamically adjusted in conjunction, enabling the training process to adaptively respond to changes in the quantization error of each layer, maximizing the compression efficiency of non-critical layers while protecting the accuracy of critical layers.

[0019] In one possible implementation, allocating an initial quantization bit width to the sensitive layer and the non-sensitive layer includes: allocating a first initial quantization bit width to the sensitive layer and allocating a second initial quantization bit width to the non-sensitive layer that is lower than the first initial quantization bit width; Increasing the quantization bit width of the network layer includes: adjusting the quantization bit width of the network layer from the second quantization bit width to the first quantization bit width; Reducing the quantization bit width of the network layer includes adjusting the quantization bit width of the network layer from the first quantization bit width to the second quantization bit width.

[0020] In this way, the switching operation directly corresponds to the update of the bit width parameter in the pseudo-quantization node. Clearly defining the specific levels of bit width switching ensures that the dynamic adjustment mechanism has a clear operational object and boundary in practical implementation, facilitating engineering implementation.

[0021] In one possible implementation, the quantization parameters of the sensitive layer are periodically recalibrated, including: Based on the numerical range of the full-precision feature map of the sensitive layer in the current iteration, recalculate the quantization scaling factor and zero point of the sensitive layer.

[0022] In this way, through periodic recalibration, the quantization parameters of the sensitive layer can be dynamically adjusted to follow the changes in feature distribution during training, thus avoiding the expansion of quantization error due to feature drift.

[0023] In one possible implementation, global calibration constraints are calculated based on the feature sensitivity of the network layers and the quantization error, including: Calculate the weight coefficient of the network layer in the global error based on the feature sensitivity of the network layer; The global cumulative quantization error is obtained by weighting and summing the quantization errors of the network layers according to the weight coefficients. The global calibration constraint factor is calculated based on the global cumulative quantization error and the preset global error threshold.

[0024] In this way, the global quantization error is obtained by weighted summation, and a global calibration constraint factor is generated accordingly, which provides guidance for the global optimal direction for subsequent local parameter optimization and avoids the problem of local extrema.

[0025] In one possible implementation, the learnable quantizable calibration parameters are optimized based on global calibration constraints, including: Using global calibration constraints as initialization or constraint conditions, the learnable equivalent transformation parameters introduced in the pseudo-quantization model are jointly optimized. Among them, the learnable equivalent transformation parameters include channel-level smoothing factors that act on network weights and activation values, and the joint optimization is performed on the basic structural blocks in the target visual network by minimizing the output difference of the basic structural blocks in the full-precision state and the quantized state.

[0026] In this way, global calibration constraints are used as prior conditions to guide the optimization of learnable equivalent transformation parameters. At the same time, local fine-tuning is performed using block-level reconstruction loss. This not only preserves the cross-layer compensation benefits accumulated from quantization-aware training, but also uses omnidirectional calibration to search for the optimal quantization step size and truncation threshold in the local tensor space, which helps to improve the accuracy performance of low-bit mixed-precision quantization.

[0027] This application also provides a visual model quantization system, including a memory and a processor. The memory stores a computer program, and the processor is configured to implement the above-described visual model quantization method when executing the computer program.

[0028] This application provides a visual model quantization method and system. The visual model quantization method includes: obtaining a full-precision basic model of a target visual network and inserting pseudo-quantization nodes to generate a pseudo-quantization model; dividing the network layer into sensitive and non-sensitive layers based on the sensitivity of network layer features and allocating differentiated initial quantization bit widths; performing quantization-aware training on the pseudo-quantization model starting from the initial quantization bit width, and jointly optimizing the quantization bit width, the gradient transfer coefficient of the pseudo-quantization nodes, and the learnable quantization calibration parameters during the training process; and removing the pseudo-quantization nodes to generate a quantized visual model.

[0029] This approach first divides sensitive and insensitive layers based on feature sensitivity and assigns differentiated initial bit widths, mitigating the risk of quantization distortion in critical layers from the outset and addressing the accuracy collapse problem caused by traditional quantization neglecting inter-layer characteristic differences. In quantization-aware training, joint optimization of quantization bit width, pseudo-quantization node gradient propagation coefficients, and learnable quantization calibration parameters is introduced. Combined with cross-layer error propagation modeling and adjacent layer feature distribution alignment mechanisms, this suppresses cross-layer accumulation of quantization noise and inter-layer distribution shifts, ensuring gradient propagation stability. Furthermore, a two-stage calibration strategy—periodic recalibration of sensitive layer quantization parameters and global calibration constraints at the end of training—counters feature distribution drift during training, avoiding overfitting risks from local parameter optimization. Ultimately, in ultra-low bit-weighted mixed-precision scenarios down to INT4 and below, the quantization model accuracy approaches the full-precision baseline, while significantly reducing model storage overhead and inference latency, greatly improving training convergence stability, and efficiently adapting to deployment requirements in resource-constrained scenarios such as edge computing and embedded systems. Attached Figure Description

[0030] To more clearly illustrate the implementation methods in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings.

[0031] Figure 1 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 1 .

[0032] Figure 2 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 2 .

[0033] Figure 3 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 3 .

[0034] Figure 4 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 4 .

[0035] Figure 5 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 5 .

[0036] Figure 6 A flowchart illustrating a visual model quantization method provided in this application embodiment. Figure 6 . Detailed Implementation

[0037] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of this application.

[0038] It should be noted that many specific details are set forth in the following description in order to provide a full understanding of this application. However, this application may also be implemented in other ways different from those described herein. Therefore, the scope of protection of this application is not limited to the specific embodiments disclosed below.

[0039] In this application, the use of terms such as "first," "second," etc., is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of those features.

[0040] The various embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of protection of this application.

[0041] In the field of low-bit mixed-precision quantization, the omnidirectional calibration quantization method achieves gradient optimization of quantization parameters through omnidirectional calibration logic, showing excellent performance in low-bit scenarios. However, it is mainly designed and optimized for large language models and does not fully consider the core characteristics of visual networks, such as strong spatial feature dependence and large dynamic range differences of feature maps.

[0042] This application provides a method for quantizing visual models, such as... Figure 1 As shown, it includes steps S110 to S140.

[0043] Step S110: Obtain the full-precision base model of the target visual network, and insert pseudo-quantization nodes into the weight layer of the full-precision base model to generate a pseudo-quantization model.

[0044] Specifically, a pre-trained model of the target visual network is loaded to obtain a full-precision base model M0. For example, the pre-trained model is a convolutional neural network model or a visual Transformer model. Straight-Through Estimator (STE) pseudo-quantization nodes are inserted into all convolutional and fully connected layers of the full-precision base model M0 to obtain a pseudo-quantized model M1. The pseudo-quantization nodes are used to simulate the quantization and dequantization processes. The quantization parameters (scaling factor, offset) of the pseudo-quantization nodes are initialized to random values ​​and subsequently optimized through quantization-aware training.

[0045] In this context, pseudo-quantization nodes refer to operators that simulate the quantization and dequantization processes, achieving gradient approximation through a pass-through estimator (STE). Quantization error refers to the difference between the quantized feature map and the full-precision feature map, measured, for example, by mean squared error (MSE) or the L2 norm.

[0046] Step S120: Based on the feature sensitivity of the network layer in the pseudo-quantization model, divide the network layer into sensitive layers and non-sensitive layers, and assign different initial quantization bit widths to the sensitive layers and non-sensitive layers.

[0047] Specifically, a small number of calibration datasets collected in real-world scenarios are selected, and the gradient norm (GN) of the feature maps of all network layers is calculated as a measure of the feature sensitivity of the network layers. The network layers are then divided into sensitive and insensitive layers according to a preset threshold.

[0048] For example, determine the maximum value of the gradient norm in all network layers, and use 70% of this maximum value as a reference value. If the gradient norm of a network layer is greater than the reference value, the network layer is classified as a sensitive layer. If the gradient norm of a network layer is less than or equal to the reference value, the network layer is classified as a non-sensitive layer.

[0049] A higher initial quantization bit width (e.g., INT8) is assigned to the sensitive layer, and a lower initial quantization bit width (e.g., INT4) is assigned to the non-sensitive layer. This generates the initial bit width table for the pseudo-quantized model M1.

[0050] Step S130: Starting from the initial quantization bit width, perform quantization-aware training on the pseudo-quantization model. During the training process, jointly optimize the quantization bit width, the gradient transfer coefficient of the pseudo-quantization node, and the learnable quantization calibration parameters.

[0051] Specifically, the full-precision parameters of the full-precision base model M0 are used as the initial weights, and the initial bit-width table of the pseudo-quantized model M1 is loaded. Hyperparameters such as the base learning rate, optimizer, and batch size are then set to begin the quantization-aware training process. Different learning rates and decay strategies are used for sensitive and non-sensitive layers; for example, the initial learning rate for the sensitive layer is set to... Cosine annealing (slow decay) is employed, with 70% of the network iteration time dedicated to fine-tuning the sensitive layers. The initial learning rate for non-sensitive layers is set to... The training method employs a step-size decay (fast decay) approach, with training accounting for 30% of the total training load.

[0052] The joint optimization of quantization bit width, gradient propagation coefficients of pseudo-quantization nodes, and learnable quantization calibration parameters constitutes a cross-parameter space collaborative coupling mechanism. Specifically, the quantization bit width defines the upper limit of the numerical representation capability of the network layer. Gradient propagation of pseudo-quantization nodes is used to adjust the propagation strength of the quantization error gradient during backpropagation, thereby controlling the impact of quantization noise on network parameter updates. Learnable quantization calibration parameters (such as feature smoothing factors) are responsible for adjusting the feature distribution to adapt to the above mapping. During training, these three types of parameters are not updated independently, but form a closed-loop feedback through backpropagation: when the optimizer attempts to reduce the task loss, if limited by the low bit width, the gradient will prompt the learnable quantization calibration parameters to adjust the feature distribution, making the learnable quantization calibration parameters more adaptable to the low-bit mapping. At the same time, the gradient propagation coefficients dynamically correct the quantization step size update strategy based on the adjusted feature distribution. If the accuracy requirement is still not met after correction, an adaptive adjustment of the quantization bit width is triggered. This mechanism allows the pseudo-quantization model to automatically find the optimal balance point among the network layer bit width, the gradient propagation accuracy defined by the gradient propagation coefficients, and the feature distribution of the learnable quantization calibration parameters during training, rather than simply optimizing the weights.

[0053] In some embodiments, joint optimization is achieved by introducing a quantization error feedback signal, which evaluates the quantization error of each network layer in real time and backpropagates the quantization error to quantization-related hyperparameters (i.e., quantization bit width, gradient transfer coefficients of pseudo-quantization nodes, and learnable quantization calibration parameters).

[0054] For example, for network layers with large quantization errors, optimization tends to relax quantization constraints (such as increasing bit width or expanding the quantization range); for network layers with small quantization errors and stable feature distributions, optimization tends to tighten quantization constraints (such as reducing bit width or enhancing calibration compression). This joint optimization based on quantization error feedback ensures that, at the end of training, the model can achieve maximum compression efficiency globally with minimal accuracy loss.

[0055] Step S140: Remove pseudo-quantization nodes from the pseudo-quantization model and generate a quantized visual model after parameter quantization.

[0056] After the quantization perception training is completed, the pseudo-quantization nodes in the pseudo-quantization model are removed. Based on the final quantization parameters (including the quantization bit width, scaling factor and zero point of each network layer) obtained during the training process, the model weights and activations are actually fixed-point processed to generate a low-bit mixed-precision quantization visual model. This allows the quantization visual model to maintain high precision while reducing storage overhead and inference latency.

[0057] In this way, differentiated initial bit width allocation is achieved through feature sensitivity partitioning, the bit width is made adaptive to the training process through a dynamic adjustment mechanism, and the quantization accuracy is further improved through dual calibration. Finally, a balance between accuracy and efficiency is achieved under ultra-low bit mixed precision.

[0058] In some embodiments, such as Figure 1 As shown, the steps for jointly optimizing the quantization bit width, the gradient transfer coefficient of the pseudo-quantization node, and the learnable quantization calibration parameter during training include steps S131 to S132.

[0059] Step S131: During the quantization-aware training process, the quantization bit width of the network layer and the gradient transfer coefficient of the corresponding pseudo-quantization node are dynamically adjusted based on the quantization error of the network layer obtained from the quantization-aware training.

[0060] For example, during training, bit width evaluation and adjustment are performed every 100 iterations. Specifically, the mean square error between the quantized feature map and the full-precision feature map of each network layer is calculated in real time. and peak signal-to-noise ratio Set the first error threshold. Second error threshold ,in, Greater than Mean square error in network layers Greater than or equal to the first error threshold In this case, increase the quantization bit width of the network layer (e.g., from INT4 to INT8), and simultaneously increase the pseudo-quantization node size of the network layer. Gradient propagation coefficient (e.g., gradient propagation coefficient multiplied by 1.2). Mean squared error in network layers. Less than or equal to the second error threshold In this case, reduce the quantization bit width of the network layer (e.g., from INT8 to INT4) and simultaneously reduce the STE gradient propagation coefficient (e.g., multiply the gradient propagation coefficient by 0.8). When the mean squared error (MSE) is within a first error threshold... Second error threshold In the case of a given situation, the current bit width and gradient propagation coefficients are maintained. This allows the quantization bit width to adaptively adjust according to real-time errors during training, balancing accuracy and efficiency.

[0061] Step S132: During the quantization perception training process, the quantization parameters of the sensitive layer are periodically recalibrated. At the end of the training, global calibration constraints are calculated based on the feature sensitivity and quantization error of the network layer of the pseudo-quantization model. The learnable quantization calibration parameters of the pseudo-quantization model are then optimized based on the global calibration constraints.

[0062] For example, in the first stage: during training, the quantization parameters (scaling factor S and zeros Z) of the sensitive layer are recalibrated every 500 iterations. The scaling factor S and zeros Z are recalculated based on the numerical range of the full-precision feature map of the sensitive layer in the current iteration. In the second stage: towards the end of training, for example, in the last 20 iterations, global calibration constraints are calculated based on the feature sensitivity and quantization error of the network layers. These global calibration constraints are then used as prior conditions to jointly optimize the learnable quantization calibration parameters (such as learnable equivalent transformation parameters and learnable truncation thresholds) introduced into the pseudo-quantization model. Thus, through this dual calibration mechanism, the final accuracy and training stability of ultra-low bit hybrid quantization can be effectively improved.

[0063] In this way, by dynamically adjusting the bit width and gradient transfer coefficients, the quantization resource allocation achieves an adaptive response to real-time errors, maximizing computational efficiency while ensuring the accuracy of key layers. Combining the dual mechanisms of periodic recalibration and global calibration constraints, feature distribution drift and cross-layer error accumulation during training are suppressed, improving the convergence stability and final inference accuracy of the pseudo-quantized model.

[0064] In some embodiments, such as Figure 2 As shown, the quantitative perception training process also includes steps S210 to S230.

[0065] Step S210: Construct a learnable error propagation coefficient matrix, wherein the error propagation coefficient matrix is ​​used to characterize the influence weight of the quantization error in the previous network layer on the subsequent network layer.

[0066] For example, constructing a learnable error propagation coefficient matrix. , where matrix elements Used to characterize the previous network layer (the first) The quantization error of the first layer affects the subsequent network layers (the second layer). The influence weights of each layer. Matrix The size is ,in, This represents the total number of network layers. During initialization, for... The element (i.e. the first) Layer first, number For the case where the layer is later, set it to 0.01. The element is set to 0.

[0067] Step S220: In each training iteration, calculate the cross-layer cumulative error perceived by the subsequent network layer based on the error propagation coefficient matrix and the quantization error of the network layer.

[0068] During the forward propagation of each training iteration, the quantization error of each network layer is calculated. (For example, the quantization error uses the L2 norm). Then, based on the error propagation coefficient matrix W and the quantization error of each network layer, the cross-layer cumulative error perceived by the subsequent network layers is calculated. ,in, Iterate through all values ​​less than The network layer.

[0069] Step S230: The cross-layer cumulative error is added as an additional loss term to the total loss function of training to drive the network parameter update.

[0070] The cumulative error across layers is added as an additional loss term to the total loss function during training. The total loss function is as follows: ;in, , For the original task loss, These are the weighting coefficients. During backpropagation, the error propagation coefficient matrix... The weight parameters of the pseudo-quantized model are updated synchronously, enabling the pseudo-quantized model to learn the optimal coupling strength for error propagation between network layers.

[0071] In this way, the quantization error of the previous network layer is explicitly propagated to the loss function of the next network layer through a learnable error propagation matrix. This forces the parameter updates of the next network layer to compensate for the quantization distortion of the previous network layer, suppressing error propagation at the source and alleviating the problem of error accumulation in traditional layer-by-layer quantization.

[0072] In some embodiments, such as Figure 3 As shown, the quantitative perception training process also includes steps S310 to S320.

[0073] Step S310: Perform channel alignment and distribution alignment operations on the quantized feature maps of adjacent network layers.

[0074] For each pair of adjacent layers (layer k and layer k+1), the number of channels is first adjusted by 1×1 convolution (this step can be omitted if the number of channels is the same).

[0075] Step S320: Based on the mean and variance of the feature maps corresponding to the previous network layers, and the mean and variance of the feature maps corresponding to the subsequent network layers, the quantized feature maps in the previous network layers are scaled and translated to match the distribution of the feature maps corresponding to the previous network layers with the distribution of the feature maps corresponding to the subsequent network layers.

[0076] Based on the mean and variance of the feature maps corresponding to the previous network layers, and the mean and variance of the feature maps corresponding to the previous network layers, the quantized feature maps are scaled and shifted: This ensures that the distribution of quantized feature maps output from previous network layers matches the distribution of corresponding feature maps in subsequent network layers, thereby mitigating the inter-layer feature distribution shift caused by quantization. The mean of the quantized feature maps of layer k. Let the variance of the k-layer quantized feature map be... Let be the mean of the full-precision feature map of the (k+1)th layer. The standard deviation of the full-precision feature map of layer k+1 is given by the given value. This refers to the quantized feature map of the k-th layer, that is, the output feature map of the k-th layer after processing by the pseudo-quantization node. This refers to the alignment result of the quantized feature map at the k-th layer, i.e., through... Obtained by scaling and translation.

[0077] In this way, by introducing a feature distribution alignment mechanism between adjacent layers, the quantized features are scaled and shifted using the mean and variance of the feature maps in the previous layer, eliminating the inter-layer distribution mismatch caused by quantization noise and ensuring the normal propagation of gradients in deep networks. At the same time, the alignment operation reduces the sensitivity of subsequent network layers to quantization distortion, allowing the feature representation capability under ultra-low bit quantization to be fully preserved, and improving the convergence stability and inference accuracy of the pseudo-quantized model.

[0078] In some embodiments, after aligning the feature maps corresponding to the preceding network layers with those corresponding to the following network layers, a lightweight channel attention module can be inserted to generate channel weights. These weights are then multiplied channel-by-channel with the aligned features to obtain enhanced features. These enhanced features are then fused with the quantized feature maps from the following network layers using a learnable weighted fusion method. It should be noted that this weighted fusion using enhanced features is only used during the training phase and removed during the inference phase, without affecting the backbone network structure.

[0079] In this way, feature distribution alignment can alleviate the inter-layer feature shift caused by quantization, promote the cross-layer transfer of key features, stabilize the training process, and improve the performance of the quantized model.

[0080] In some embodiments, such as Figure 4 As shown, based on the feature sensitivity of the network layer of the pseudo-quantization model, the network layer is divided into sensitive layers and non-sensitive layers, including steps S410 to S430.

[0081] Step S410: Calculate the gradient norm of the task loss function relative to the output feature map of the network layer, and use the gradient norm as the feature sensitivity of the network layer.

[0082] Calculate the task loss function Relative to the feature map output by the network layer The gradient of the gradient is calculated, and the sample mean of the L2 norm of this gradient is used as a measure of the feature sensitivity of the corresponding network layer. ,in, To calibrate the dataset, the number of samples is typically between 1000 and 2000. A larger gradient means that even small changes in the feature maps of network layers can have a drastic impact on the final task loss, thus making the corresponding network layer more sensitive to quantization noise.

[0083] Step S420: Determine the comparison threshold based on the maximum value of the feature sensitivity of all network layers.

[0084] The maximum value of the feature sensitivity based on all network layers. Determine the comparison threshold .in, For example, a preset scaling factor. .

[0085] Step S430: Network layers with feature sensitivity greater than or equal to the comparison threshold are classified as sensitive layers, and network layers with feature sensitivity less than the comparison threshold are classified as insensitive layers.

[0086] Feature sensitivity greater than or equal to the comparison threshold The network layers are divided into sensitive layers, and features with sensitivity less than a comparison threshold are selected. The network layers are divided into non-sensitive layers. The threshold ratio can be used as a hyperparameter and fine-tuned based on prior knowledge of different visual tasks and network structures.

[0087] In this way, the sensitivity of each layer to quantization error is objectively quantified by the gradient norm, and sensitive and non-sensitive layers are automatically divided based on adaptive thresholds, avoiding the subjectivity and non-universality of human experience settings.

[0088] In some embodiments, such as Figure 5As shown, based on the quantization error of the network layer obtained from quantization perception training, the quantization bit width of the network layer and the gradient transfer coefficient of the corresponding pseudo-quantization node are adjusted, including steps S510 to S530.

[0089] Step S510: Obtain the quantization error between the quantized feature map of the network layer and the full-precision feature map of the corresponding full-precision base model.

[0090] The quantization error between the quantized feature map of the network layer and the corresponding full-precision feature map of the base model is obtained. Specifically, in each iteration, the data of the same input batch is fed into a fixed full-precision base model M0 and the pseudo-quantized model M1 being trained for forward propagation, and the full-precision feature map of the current batch is obtained simultaneously. Quantization feature map Calculate the mean square error between the two. and peak signal-to-noise ratio .

[0091] Set the first error threshold Second error threshold The first error threshold is greater than the second error threshold.

[0092] In step S520, if the quantization error is greater than the first error threshold, increase the quantization bit width of the network layer and increase the gradient propagation coefficient of the corresponding pseudo-quantization node.

[0093] When the quantization error is greater than the first error threshold In this case, increase the quantization bit width of the network layer and increase the gradient propagation coefficient of the corresponding pseudo-quantization node.

[0094] Step S530: If the quantization error is less than the second error threshold, reduce the quantization bit width of the network layer and reduce the gradient propagation coefficient of the corresponding pseudo-quantization node. The first error threshold is greater than the second error threshold.

[0095] When the quantization error is less than the second error threshold In the case of a certain error, reduce the quantization bit width of the network layer and decrease the gradient propagation coefficient of the corresponding pseudo-quantized node. If the quantization error is between these two values, maintain the current bit width and gradient propagation coefficient.

[0096] In this way, based on the comparison between real-time error and dual thresholds, the bit width and gradient transfer coefficient are dynamically adjusted in conjunction, enabling the training process to adaptively respond to changes in the quantization error of each layer, maximizing the compression efficiency of non-critical layers while protecting the accuracy of critical layers.

[0097] In some embodiments, allocating an initial quantization bit width to sensitive and non-sensitive layers includes: allocating a first initial quantization bit width (e.g., INT8) to sensitive layers and allocating a second initial quantization bit width (e.g., INT4) to non-sensitive layers that is lower than the first initial quantization bit width.

[0098] When performing the operation to increase the quantization bit width of the network layer, the quantization bit width of the network layer is adjusted from the second quantization bit width (INT4) to the first quantization bit width (INT8).

[0099] When performing the operation of reducing the quantization bit width of the network layer, the quantization bit width of the network layer is adjusted from the first quantization bit width (INT8) to the second quantization bit width (INT4).

[0100] In this way, the switching operation directly corresponds to the update of the bit width parameter in the pseudo-quantization node. Clearly defining the specific levels of bit width switching ensures that the dynamic adjustment mechanism has a clear operational object and boundary in practical implementation, facilitating engineering implementation.

[0101] In some embodiments, the quantization parameters of the sensitive layer are periodically recalibrated, including recalculating the quantization scaling factor and zeros of the sensitive layer based on the numerical range of the full-precision feature map of the sensitive layer in the current iteration.

[0102] For example, during quantization-aware training, the quantization parameters of the sensitive layer are recalibrated every 500 iterations. Based on the numerical range of the full-precision feature map of the sensitive layer in the current iteration, the quantization scaling factor S and zero point Z of the corresponding network layer are recalculated.

[0103] .

[0104] .

[0105] in, This refers to the bit width currently actually used by the sensitive layer. This refers to the first [number]th ... The full-precision feature map of the layer. The updated scaling factor S and zero point Z are immediately reflected in the pseudo-quantization node, ensuring that the quantization representation of the sensitive layer always closely follows the current feature range.

[0106] In this way, through periodic recalibration, the quantization parameters of the sensitive layer can be dynamically adjusted to follow the changes in feature distribution during training, thus avoiding the expansion of quantization error due to feature drift.

[0107] In some embodiments, such as Figure 6 As shown, the global calibration constraint is calculated based on the feature sensitivity and quantization error of the network layer, including steps S610 to S630.

[0108] Step S610: Calculate the weight coefficients of the network layer in the global error based on the feature sensitivity of the network layer.

[0109] First, based on the feature sensitivity of the network layers Calculate the weight coefficients of the network layers in the global error. ,in, It is the sum of the feature sensitivities of all network layers. Satisfy normalization constraints .

[0110] Step S620: The quantization error of the network layer is weighted and summed according to the weight coefficients to obtain the global cumulative quantization error.

[0111] Secondly, the quantization error of the network layer is determined based on the weight coefficients. Perform a weighted summation to obtain the global cumulative quantization error. .

[0112] Step S630: Calculate the global calibration constraint factor based on the global cumulative quantization error and the preset global error threshold.

[0113] Finally, based on the global cumulative quantization error and the preset global error threshold... (The value can be adaptively adjusted within the range of 0.1 to 0.2 according to the task accuracy requirements), and the global calibration constraint factor is calculated. and will Limited to the interval [0.8, 1.2], it serves as the global constraint benchmark for subsequent omnidirectional calibration, where, The preset global error limit is adaptively adjusted within the range of 0.1 to 0.2 according to the accuracy requirements of the target task.

[0114] In this way, the global quantization error is obtained by weighted summation, and a global calibration constraint factor is generated accordingly, which provides guidance for the global optimal direction for subsequent local parameter optimization and avoids the problem of local extrema.

[0115] In some embodiments, optimizing learnable quantizable calibration parameters based on global calibration constraints includes: using global calibration constraint factors. As initialization or constraint conditions, the learnable equivalent transformation parameters introduced in the pseudo-quantization model are jointly optimized. These learnable equivalent transformation parameters include channel-level smoothing factors that act on network weights and activation values. For operations on adjacent convolutional layers Perform mathematical equivalent transformations: , ,in, It is a learnable vector with the same dimension and number of channels. ⊘ represents element-wise division, and ⊙ represents element-wise multiplication. Initialization When introduced Dynamic constraints: This method transfers outliers from activation values ​​to weights, mitigating the truncation error of visual features at low bit depths. is the channel-level smoothing factor for the k-th layer (dimension and number of channels are the same), and is the upper and lower bounds of the learnable weight truncation (dimension and number of weight channels are the same).

[0116] Joint optimization is performed on a per-unit basis, such as residual blocks or Transformer blocks, in the target vision network. It minimizes the output difference between the basic structural blocks in the full-precision state and the quantized state. The block-level reconstruction loss is defined as follows: .

[0117] in, and Cut off the upper and lower bounds for learnable weights. For regularization weights, This is the L2 regularization penalty term for the smoothing factor. Utilizing a minimal learning rate (e.g.) The above calibration parameters are jointly optimized using gradient descent, freezing most of the parameters of the backbone network and optimizing only the learnable calibration parameters.

[0118] In this way, global calibration constraints are used as prior conditions to guide the optimization of learnable equivalent transformation parameters. At the same time, local fine-tuning is performed using block-level reconstruction loss. This not only preserves the cross-layer compensation benefits accumulated from quantization-aware training, but also uses omnidirectional calibration to search for the optimal quantization step size and truncation threshold in the local tensor space, which helps to improve the accuracy performance of low-bit mixed-precision quantization.

[0119] This application also provides a visual model quantization system, including a memory and a processor. The memory stores a computer program, and the processor is configured to implement the above-described visual model quantization method when executing the computer program.

[0120] Specifically, a visual model quantization system can be a computer device, such as a server, personal computer, or embedded device. The processor executes a computer program stored in memory to perform the following functions: acquire the full-precision base model of the target visual network and insert pseudo-quantized nodes; divide sensitive and non-sensitive layers based on feature sensitivity and assign initial bit widths; perform quantization-aware training that includes dynamic adjustment, cross-layer error compensation, and feature alignment; perform dual calibration that includes periodic recalibration and global calibration constraint optimization; and finally remove pseudo-quantized nodes to generate a quantized model.

Claims

1. A method for quantizing visual models, characterized in that, include: Obtain the full-precision base model of the target visual network, and insert pseudo-quantization nodes into the weight layer of the full-precision base model to generate a pseudo-quantization model; Based on the feature sensitivity of the network layer in the pseudo-quantization model, the network layer is divided into sensitive layers and non-sensitive layers, and different initial quantization bit widths are assigned to the sensitive layers and non-sensitive layers. Starting from the initial quantization bit width, quantization-aware training is performed on the pseudo-quantization model. During the training process, the quantization bit width, the gradient transfer coefficient of the pseudo-quantization node, and the learnable quantization calibration parameters are jointly optimized. Remove the pseudo-quantization nodes from the pseudo-quantization model to generate a quantized visual model with quantized parameters.

2. The visual model quantization method according to claim 1, characterized in that, The step of jointly optimizing the quantization bit width, the gradient transfer coefficients of the pseudo-quantization nodes, and the learnable quantization calibration parameters during training includes: During the quantization-sensing training process, the quantization bit width of the network layer and the gradient transfer coefficient of the corresponding pseudo-quantization node are dynamically adjusted based on the quantization error of the network layer obtained from the quantization-sensing training. During the quantization-aware training process, the quantization parameters of the sensitive layer are periodically recalibrated. At the end of the training, global calibration constraints are calculated based on the feature sensitivity and quantization error of the network layer of the pseudo-quantization model, and the learnable quantization calibration parameters of the pseudo-quantization model are optimized based on the global calibration constraints.

3. The visual model quantization method according to claim 1, characterized in that, The quantitative perception training process also includes: Construct a learnable error propagation coefficient matrix, where the error propagation coefficient matrix is ​​used to characterize the influence weight of the quantization error in the previous network layer on the subsequent network layer. In each training iteration, the cross-layer cumulative error perceived by the subsequent network layer is calculated based on the error propagation coefficient matrix and the quantization error of the network layer. The cross-layer cumulative error is added as an additional loss term to the total loss function during training to drive network parameter updates.

4. The visual model quantization method according to any one of claims 1-3, characterized in that, The quantitative perception training process also includes: Perform channel alignment and distribution alignment operations on the feature maps of adjacent network layers. Based on the mean and variance of the feature maps corresponding to the preceding network layers, and the mean and variance of the feature maps corresponding to the following network layers, the preceding quantized feature maps are scaled and shifted to match the distribution of the feature maps corresponding to the preceding network layers with the distribution of the feature maps corresponding to the following network layers.

5. The visual model quantization method according to claim 1, characterized in that, The feature sensitivity of the network layer based on the pseudo-quantization model divides the network layer into sensitive layers and non-sensitive layers, including: Calculate the gradient norm of the task loss function relative to the output feature map of the network layer, and use the gradient norm as the feature sensitivity of the network layer; The comparison threshold is determined based on the maximum value of the feature sensitivity of all network layers; Network layers whose feature sensitivity is greater than or equal to the comparison threshold are classified as sensitive layers, and network layers whose feature sensitivity is less than the comparison threshold are classified as insensitive layers.

6. The visual model quantization method according to claim 2, characterized in that, The step of adjusting the quantization bit width of the network layer and the gradient transfer coefficient of the corresponding pseudo-quantization node based on the quantization error of the network layer obtained from quantization-aware training includes: Obtain the quantization error between the quantized feature map of the network layer and the full-precision feature map of the corresponding full-precision base model; If the quantization error is greater than the first error threshold, the quantization bit width of the network layer is increased, and the gradient propagation coefficient of the corresponding pseudo-quantization node is increased. If the quantization error is less than the second error threshold, the quantization bit width of the network layer is reduced, and the gradient propagation coefficient of the corresponding pseudo-quantization node is reduced, where the first error threshold is greater than the second error threshold.

7. The visual model quantization method according to claim 6, characterized in that, The step of allocating an initial quantization bit width to the sensitive layer and the non-sensitive layer includes: allocating a first initial quantization bit width to the sensitive layer and allocating a second initial quantization bit width to the non-sensitive layer that is lower than the first initial quantization bit width; The step of increasing the quantization bit width of the network layer includes: adjusting the quantization bit width of the network layer from the second quantization bit width to the first quantization bit width; Reducing the quantization bit width of the network layer includes: adjusting the quantization bit width of the network layer from the first quantization bit width to the second quantization bit width.

8. The visual model quantization method according to claim 2, characterized in that, The periodic recalibration of the quantization parameters of the sensitive layer includes: Based on the numerical range of the full-precision feature map of the sensitive layer in the current iteration, the quantization scaling factor and zero point of the sensitive layer are recalculated.

9. The visual model quantization method according to claim 2, characterized in that, The calculation of global calibration constraints for the feature sensitivity and quantization error of the network layer based on the pseudo-quantization model includes: Calculate the weight coefficient of the network layer in the global error based on the feature sensitivity of the network layer; The quantization error of the network layer is weighted and summed according to the weight coefficients to obtain the global cumulative quantization error; The global calibration constraint factor is calculated based on the global cumulative quantization error and the preset global error threshold.

10. The visual model quantization method according to claim 2, characterized in that, The optimization of the learnable quantizable calibration parameters based on the global calibration constraints includes: Using the global calibration constraint as an initialization or constraint condition, the learnable equivalent transformation parameters introduced in the pseudo-quantization model are jointly optimized. The learnable equivalent transformation parameters include channel-level smoothing factors that act on network weights and activation values, and the joint optimization is performed on the basis of basic structural blocks in the target visual network by minimizing the output difference of the basic structural blocks in the full-precision state and the quantized state.

11. A visual model quantization system, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor being configured to implement the visual model quantization method as described in any one of claims 1 to 10 when executing the computer program.