Model quantization method and apparatus, and device and storage medium

By constructing a layered quantification sequence and layered quantification of the image decoder model layer, the problem of inconsistent performance loss and decoding caused by low -bit quantitative quantification, and achieve the effect of improvement of performance and results consistency.

WO2025016306A1PCT designated stage expired Publication Date: 2025-01-23HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/105152
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-07-14
Filing Date
2024-07-12
Publication Date
2025-01-23

AI Technical Summary

Technical Problem

In image decoders, low bit quantization will lead to loss of model performance, and different calculation accuracy of different devices will lead to inconsistent decoding results.

Method used

By obtaining the performance deviation of each model layer in the model to be quantified, a hierarchical quantification sequence is constructed, and the model layers are hierarchically quantified based on the sequence, and parameter adjustments are used to reduce performance loss.

Benefits of technology

It effectively reduces the performance loss during low-bit quantization and ensures decoding consistency between different devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024105152_23012025_PF_FP_ABST
    Figure CN2024105152_23012025_PF_FP_ABST
Patent Text Reader

Abstract

A model quantization method and apparatus, and a device and a storage medium, which belong to the technical field of model quantization. The method comprises: acquiring a performance deviation corresponding to each model layer in a model to be quantized; constructing a hierarchical quantization sequence according to the performance deviations corresponding to the respective model layers; and performing hierarchical quantization processing on the model layers in said model on the basis of the hierarchical quantization sequence. A hierarchical quantization sequence is constructed according to performance deviations corresponding to respective model layers in a model to be quantized, hierarchical quantization processing is respectively performed on the model layers in said model according to the sequence order of the hierarchical quantization sequence, and after quantization during the processing, parameter adjustment and correction are used to reduce a performance loss of the model to the greatest possible extent, which performance loss is generated by low-bit quantization.
Need to check novelty before this filing date? Find Prior Art

Description

Model quantization method, device, equipment and storage medium Technical Field

[0001] The present application relates to the field of model quantization technology, and in particular to a model quantization method, apparatus, device and storage medium. Background Art

[0002] In the field of image coding and decoding, AI-based methods can achieve higher compression rates than traditional methods, and have therefore become an important trend in the field of coding and decoding. This is due to the fact that networks trained through deep learning can better compress and restore images. However, it also brings more computing power and resource consumption than traditional methods, which undoubtedly brings higher requirements to decoding equipment.

[0003] Image decoders are generally deployed on devices that decode bitstreams. The neural network in the decoder has a large number of parameters and computational complexity, which means its forward calculations require more storage and computing resources. At the same time, under floating-point parameters, due to differences in computational accuracy between different devices, the decoding results between different devices may be inconsistent.

[0004] Model quantization can quantize the floating-point parameters in the model into fixed-point types, which can reduce the storage consumption of the model while saving bandwidth during the forward calculation of the model. In addition, converting the floating-point parameters in the model into fixed-point parameters can reduce the computational complexity of the model and avoid the impact of inconsistent calculation accuracy, thereby ensuring decoding consistency between different devices.

[0005] However, the sensitivity of each layer of the neural network in the decoder to quantization is inconsistent, and it is difficult to guarantee the quantization performance of some layers at lower bits. Since some devices do not support high-bit quantization operations, in order to adapt to such scenarios, how to reduce the performance loss caused by quantizing the model at lower bits is a difficult problem.

[0006] The above content is only used to assist in understanding the technical solution of this application and does not constitute an admission that the above content is prior art.

[0007] Summary of the Invention

[0008] The main purpose of this application is to provide a model quantization method, device, equipment and storage medium, aiming to reduce the performance loss caused by quantizing the model using low bits.

[0009] To achieve the above objectives, the present application provides a model quantization method, which includes:

[0010] Obtain the performance deviation corresponding to each model layer in the model to be quantized;

[0011] Constructing a hierarchical quantization sequence according to the performance deviations corresponding to each model layer;

[0012] A hierarchical quantization process is performed on the model layers in the model to be quantized based on the hierarchical quantization sequence.

[0013] In a possible implementation of the present application, constructing a hierarchical quantization sequence according to the performance deviations corresponding to the model layers includes:

[0014] The model layers in the to-be-quantized model are sorted in descending order according to the corresponding performance deviations to obtain the hierarchical quantization sequence.

[0015] In a possible implementation of the present application, sorting the model layers in the to-be-quantized model in descending order of corresponding performance deviations to obtain a hierarchical quantization sequence includes:

[0016] Sorting the model layers in the to-be-quantized model in descending order of the corresponding performance deviations to obtain the model layer sequence;

[0017] The model layer sequence is cut from front to back according to a preset length to obtain the layered quantization sequence.

[0018] In a possible implementation of the present application, the performance deviation corresponding to the model layer in the model to be quantized is the deviation between the outputs of the model to be quantized before and after the model layer is quantized separately.

[0019] In a possible implementation of the present application, performing hierarchical quantization processing on the model layers in the to-be-quantized model based on the hierarchical quantization sequence includes:

[0020] Traversing the hierarchical quantization sequence and taking the currently traversed model layer as the current model layer;

[0021] Performing quantization processing on the current model layer;

[0022] Adjusting at least one model parameter in the model to be quantized with the goal of reducing the performance deviation corresponding to the current model layer;

[0023] Detecting whether there are any model layers that have not been traversed in the layered quantization sequence;

[0024] If the model layer that has not been traversed exists in the hierarchical quantization sequence, return to the step of traversing the hierarchical quantization sequence and use the currently traversed model layer as the current model layer.

[0025] In a possible implementation manner of the present application, adjusting at least one model parameter in the model to be quantized with the goal of reducing the performance deviation corresponding to the current model layer includes:

[0026] Adopting a gradient derivation method, with the goal of reducing the performance deviation corresponding to the current model layer, at least one model parameter in the model to be quantized is adjusted.

[0027] In a possible implementation manner of the present application, adjusting at least one model parameter in the to-be-quantified model includes at least one of the following:

[0028] Adjusting at least one model parameter of the current model layer;

[0029] Adjusting at least one parameter of the current model layer and at least one model parameter of a model layer adjacent to the current model layer;

[0030] At least one model parameter of each model layer in the model to be quantized is adjusted.

[0031] In a possible implementation of the present application, the method further includes:

[0032] If there is no untraversed model layer in the hierarchical quantization sequence, detecting whether there is any unquantized model layer in the model to be quantized;

[0033] If there is no unquantized model layer in the model to be quantized, it is determined that the quantization of the model to be quantized is completed.

[0034] In a possible implementation of the present application, the method further includes:

[0035] If there is an unquantized model layer in the model to be quantized, quantizing the unquantized model layer;

[0036] When the quantization process is completed, it is determined that the quantization of the to-be-quantized model is completed.

[0037] In a possible implementation manner of the present application, the model to be quantized is a decoding model or an encoding model.

[0038] In a possible implementation manner of the present application, the intercepting the model layer sequence from front to back according to a preset length includes: intercepting the model layer sequence from front to back according to the preset length, starting from the first model layer included in the model layer sequence.

[0039] In addition, to achieve the above objectives, the present application also proposes a model quantization device, which includes:

[0040] The acquisition module is used to obtain the performance deviation corresponding to each model layer in the model to be quantized;

[0041] A construction module, configured to construct a hierarchical quantization sequence according to the performance deviations corresponding to the model layers;

[0042] A quantization module is used to perform hierarchical quantization processing on the model layers in the model to be quantized based on the hierarchical quantization sequence.

[0043] In addition, to achieve the above-mentioned purpose, the present application also proposes a model quantization device, which includes: a processor, a memory, and a model quantization program stored on the memory and executable by the processor. When the model quantization program is executed by the processor, it implements any of the model quantization methods described above.

[0044] In addition, to achieve the above objectives, the present application also proposes a coding device, which includes: a processor, a memory, and a coding program stored in the memory and executable by the processor, and when the coding program is executed by the processor, it implements any model quantization method described above.

[0045] In addition, to achieve the above-mentioned purpose, the present application also proposes a decoding device, which includes: a processor, a memory, and a decoding program stored on the memory and runnable on the processor, and when the decoding program is executed by the processor, it implements any of the model quantization methods described above.

[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, on which a model quantization program is stored, and the model quantization program is configured to execute any of the model quantization methods described above.

[0047] The present application obtains the performance deviation corresponding to each model layer in the model to be quantized; constructs a hierarchical quantization sequence according to the performance deviation corresponding to each model layer; and performs hierarchical quantization processing on the model layers in the model to be quantized based on the hierarchical quantization sequence. Since the hierarchical quantization sequence is constructed according to the performance deviation corresponding to each model layer in the model to be quantized, and the hierarchical quantization processing is performed on each model layer in the model to be quantized according to the sequence order of the hierarchical quantization sequence, parameter adjustment correction is used after quantization during the processing process to minimize the performance loss of the model caused by low-bit quantization. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] FIG1 is a schematic structural diagram of an electronic device according to an embodiment of the present application;

[0049] FIG2 is a schematic diagram of a flow chart of a model quantization method according to an embodiment of the present application;

[0050] FIG3 is a schematic diagram of a codec architecture according to an embodiment of the present application;

[0051] FIG4 is a schematic diagram of the model layer structure of an embodiment of the present application;

[0052] FIG5 is a flow chart of a model quantization method according to an embodiment of the present application;

[0053] FIG6 is a schematic diagram of the correlation between model layer parameters according to an embodiment of the present application;

[0054] FIG7 is a schematic diagram of a flow chart of a model quantization method according to an embodiment of the present application;

[0055] FIG8 is a structural block diagram of a model quantization device according to an embodiment of the present application.

[0056] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0057] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.

[0058] Refer to Figure 1, which is a structural diagram of an electronic device (model quantization device) in a hardware operating environment involved in an embodiment of the present application.

[0059] As shown in Figure 1, the electronic device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to implement connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and optionally, the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (WI-FI) interface). The memory 1005 may be a high-speed random access memory (RAM) or a stable non-volatile memory (NVM), such as a disk storage. The memory 1005 may optionally also be other storage devices independent of the aforementioned processor 1001.

[0060] Those skilled in the art will understand that the structure shown in FIG1 does not limit the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0061] As shown in FIG1 , the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a model quantization program.

[0062] In the electronic device shown in Figure 1, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the electronic device calls the model quantization program stored in the memory 1005 through the processor 1001 to execute the model quantization method provided in the embodiment of the present application.

[0063] An embodiment of the present application provides a model quantization method. Referring to FIG. 2 , FIG. 2 is a flow chart of a first embodiment of a model quantization method of the present application.

[0064] In this embodiment, the model quantization method includes the following steps:

[0065] Step S10: Obtain the performance deviation corresponding to each model layer in the decoding model to be quantized.

[0066] It should be noted that the executor of this embodiment can be the model quantization device, or it can be an encoding device or decoding device that encodes / decodes image data. The model quantization device can be an electronic device such as a personal computer or a server. Of course, it can also be other electronic devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment and the following embodiments, the model quantization method of this application is explained using the model quantization device as an example.

[0067] It should be noted that the decoding model to be quantized can be a neural network model included in a decoder deployed in a device that decodes the bitstream. There can be multiple decoding models to be quantized. When there are multiple decoding models to be quantized, each can be independently quantized using a model quantization method. The performance deviation corresponding to a model layer is the deviation in the output of the decoding model to be quantized before and after quantizing the model layer in the decoding model to be quantized.

[0068] For ease of understanding, the following description will be given in conjunction with Figure 3, but this solution is not limited thereto. Figure 3 is a schematic diagram of the encoding and decoding architecture of an embodiment of the present application. The image encoding and decoding process based on artificial intelligence is shown in Figure 3. The network models involved in the overall encoding and decoding process mainly include: Analysis Transform Net, Prediction Fusion Net, Context Model Net, Hyper Decoder Net, Hyper Scale Decoder Net, Hyper Encoder Net, Synthesis Transform Net and ICCI filter. Among them, the lower half of Figure 3 is an image decoder, which is generally deployed on a device that decodes the bitstream. The neural network model involved in the decoder (including Synthesis Transform Net and ICCI filter, etc.) can be used as a decoding model to be quantized.

[0069] In a specific implementation, obtaining the performance deviation corresponding to each model layer in the decoding model to be quantized can be to first input a preset sample into the decoding model to be quantized, and obtain the model output, marked as the initial output, and then quantize each model layer in the decoding model to be quantized separately, and record the model output for the preset sample after quantization, thereby obtaining the quantized output corresponding to each model layer, and calculating the difference between the initial output and the quantized output corresponding to each model layer, thereby obtaining the performance deviation corresponding to each model layer in the decoding model to be quantized. Since this embodiment is to reduce the performance loss caused by using low bits to quantize the model, in this embodiment, when quantizing each model layer, low bits can be used for quantization (for example, 8 bits are used for quantization).

[0070] For ease of understanding, the following description is made in conjunction with FIG4 , but this solution is not limited thereto. FIG4 is a schematic diagram of the model layer structure of an embodiment of the present application. As shown in FIG4 , for a system including L model layers (each model layer can be represented by w 1, w2,......,w L ) is a decoding model to be quantized, and the preset sample x is input into the decoding model to be quantized. The model output can be expressed as: y=f(w1,w2,......,w L ; x).

[0071] After that, each model layer is quantized separately. In this process, when the lth (1≤l≤L) model layer is quantized separately, each model layer can be expressed as

[0072] in, Represents the quantized l-th model layer. The quantized output corresponding to the l-th model layer can be expressed as

[0073] Accordingly, the performance deviation Pl of the lth model layer can be expressed as:

[0074] Step S20: constructing a hierarchical quantization sequence according to the performance deviation corresponding to each model layer.

[0075] It should be noted that constructing the hierarchical quantization sequence according to the performance deviation corresponding to each model layer may be to sort each model layer according to the performance deviation corresponding to each model layer, thereby constructing the hierarchical quantization sequence.

[0076] In actual use, in order to reduce the superposition of the noise gradient introduced by the straight-through estimator (STE) in each layer during the model quantization operation, it is necessary to start from the most difficult to quantize layer (the model layer with the largest performance deviation) and quantize the model step by step. Since the greater the performance deviation, the greater the performance loss when quantizing the model layer, when actually processing, it is necessary to first process the model layer with a larger performance loss caused by quantization. Then, step S20 described in the embodiment of the present application may include:

[0077] The model layers in the decoding model to be quantized are sorted in descending order according to the corresponding performance deviations to obtain a hierarchical quantization sequence.

[0078] It is understandable that because the model layer with the largest performance loss caused by quantization needs to be processed first, when constructing the hierarchical quantization sequence, it is necessary to ensure that the model layer with the largest performance loss is located at the front of the sequence. Therefore, the model layers in the quantization decoding model to be processed can be sorted in descending order according to the corresponding performance deviation to obtain a hierarchical quantization sequence. In some examples, each model layer can be represented by an identifier (such as a layer number), and the hierarchical quantization sequence can be a sequence containing the sorted identifiers.

[0079] For example, assuming the model has three layers, A, B, and C, and their corresponding performance deviations are a, b, and c, respectively. If c>a>b, the constructed hierarchical quantization sequence is CAB.

[0080] In a possible implementation of the embodiment of the present application, in order to increase the quantization rate as much as possible, the step of sorting the model layers in the decoding model to be quantized in descending order according to the corresponding performance deviations in the embodiment of the present application to obtain a hierarchical quantization sequence may include:

[0081] Sorting the model layers in the decoding model to be quantized in descending order according to the corresponding performance deviations to obtain a model layer sequence;

[0082] The model layer sequence is cut from front to back according to a preset length to obtain a hierarchical quantization sequence. In some examples, the model layer sequence can be cut from the first model layer of the model layer sequence to obtain a hierarchical quantization sequence. In some examples, the model layer sequence can be cut from the middle model layer of the model layer sequence to obtain a hierarchical quantization sequence according to the preset length.

[0083] In some implementations, the preset length may be pre-set by a manager of the model quantization device according to actual needs, for example, the preset length may be set to 3.

[0084] In actual use, since the performance loss caused by quantizing the model using low bits may be caused by a very small part of all model layers, only a part of them can be processed when processing them. Therefore, a preset length can be set in advance, and then the model layers in the decoding model to be quantized are sorted in order from large to small according to the corresponding performance deviation to obtain a model layer sequence, and then the model layer sequence is cut from front to back according to the preset length to obtain a layered quantization sequence.

[0085] For example, assuming the preset length is 3 and the model layer sequence is ABCDE, the model layer sequence is cut from front to back according to the preset length, and the obtained layered quantization sequence is ABC.

[0086] Of course, since the performance deviation can be used to represent the performance loss caused when the model layer is quantized, the model layer sequence can be cut from front to back instead of being cut by a preset length. Instead, a performance deviation threshold can be preset, and then the model layers in the decoding model to be quantized are sorted in descending order according to the corresponding performance deviation to obtain a model layer sequence. The part of the model layer sequence whose corresponding performance deviation is greater than the performance deviation threshold is cut, and the cut part is used as a layered quantization sequence.

[0087] For example: assuming the model layer sequence is ABCDE, and its corresponding performance deviations are a, b, c, d, and e, where a>b>c>d>e. Assuming the performance deviation threshold is x, and d<x<c, the intercepted layered quantization sequence is ABC.

[0088] Step S30: performing hierarchical quantization processing on the model layers in the decoding model to be quantized based on the hierarchical quantization sequence.

[0089] It should be noted that performing hierarchical quantization processing on the model layers in the decoding model to be quantized based on the hierarchical quantization sequence can be based on the sequence order defined by the hierarchical quantization sequence, and hierarchical quantization processing can be performed on the corresponding model layers in the decoding model to be quantized in sequence. The hierarchical quantization processing can include steps such as model quantization and parameter adjustment.

[0090] The embodiment of the present application obtains the performance deviation corresponding to each model layer in the decoding model to be quantized; constructs a hierarchical quantization sequence based on the performance deviation corresponding to each model layer; and performs hierarchical quantization processing on the model layers in the decoding model to be quantized based on the hierarchical quantization sequence. Since the hierarchical quantization sequence is constructed based on the performance deviation corresponding to each model layer in the decoding model to be quantized, the hierarchical quantization processing is performed on the corresponding model layers in the decoding model to be quantized according to the sequence order of the hierarchical quantization sequence. During the processing, parameter adjustment is used after quantization to minimize the performance loss of the model caused by low-bit quantization.

[0091] Refer to FIG5 , which is a flow chart of a second embodiment of a model quantization method of the present application.

[0092] Based on the first embodiment above, step S30 of the model quantization method in the embodiment of the present application includes:

[0093] Step S301: traverse the layered quantization sequence, and use the traversed model layer as the current model layer.

[0094] It should be noted that traversing the layered quantization sequence may be traversing the layered quantization sequence according to the sequence order of the layered quantization sequence.

[0095] Step S302: performing quantization processing on the current model layer.

[0096] It should be noted that the quantization processing of the current model layer can be to use low bits (such as 8 bits) to quantize the model parameters in the current model layer, and approximate the model parameters represented by floating-point values ​​and the input and output features of the model layer using fixed-point values.

[0097] Step S303: with the goal of reducing the performance deviation corresponding to the current model layer, adjust at least one model parameter in the decoding model to be quantized.

[0098] It should be noted that, with the goal of reducing the performance deviation corresponding to the current model layer, adjusting at least one model parameter in the decoding model to be quantized may be adjusting at least one model parameter in the decoding model to be quantized, thereby attempting to reduce the performance deviation corresponding to the current model layer. After each parameter adjustment, the performance deviation corresponding to the current model layer (i.e., the performance deviation resulting from quantization of the current model layer) may be recalculated.

[0099] In actual use, the gradient derivation method can be used to adjust at least one model parameter in the quantized decoding model with the goal of reducing the performance deviation corresponding to the current model layer. For example, the straight-through gradient evaluation algorithm can be used to adjust at least one model parameter in the quantized decoding model with the goal of reducing the performance deviation corresponding to the current model layer. Of course, other similar algorithms can also be used.

[0100] When using an algorithm to adjust model parameters, the algorithm module provided by the model framework can be called to perform the adjustment. For example, if a straight-through gradient evaluation algorithm is used, the straight-through estimator (STE) in the model framework can be directly called. Of course, calculations can also be performed independently, and this embodiment does not limit this.

[0101] In practical applications, the parameters in each model layer in the decoding model to be quantized are correlated, that is, changing the parameters in one model layer will affect the input and output of other model layers. The relationship between the model layers is shown in Figure 6. Quantizing a parameter in a model layer causes a large deviation in the model output, resulting in a large performance loss of the model. The correlation between other parameters between the model layers and the parameter can be used to adjust the other parameters using the reconstructed output method to correct the offset caused by quantization. In addition, the correlation between cross-model layers can be used to further correct the feature deviation caused by quantization. Therefore, when adjusting at least one model parameter in the decoding model to be quantized, at least one of the following can be included:

[0102] Adjusting at least one model parameter of the current model layer;

[0103] Adjusting at least one model parameter of the current model layer and at least one model parameter of a model layer adjacent to the current model layer;

[0104] At least one model parameter of each model layer in the decoding model to be quantized is adjusted.

[0105] Assuming that the current model layer is the lth model layer, adjusting at least one model parameter of the current model layer may be performed to reduce the performance deviation P of the current model layer. lTo optimize the target, the gradient derivation method is used to optimize the model parameters in the l-th layer model layer (since the l-th layer has been quantized, its model parameters can be expressed as ) Update with gradient;

[0106] Adjusting at least one model parameter of the current model layer and at least one model parameter of the model layer adjacent to the current model layer may be to reduce the performance deviation P of the current model layer. l To optimize the target, the model parameters in the l-th model layer and the l-1 and l+1 model layers ( w l-1 、w l+1 ) to update;

[0107] Adjusting at least one model parameter of each model layer in the quantized decoding model can be to reduce the performance deviation P of the current model layer. l The model parameters of all model layers in the decoding model to be quantized are updated for the optimization objective.

[0108] Step S304: Detect whether there are any model layers that have not been traversed in the layered quantization sequence.

[0109] It should be noted that, during the traversal of the hierarchical quantization sequence, the index value during the traversal can also be recorded to determine whether the traversal of the hierarchical quantization sequence is complete. If the traversal is not complete, it can be determined that there are model layers that have not been traversed.

[0110] Of course, it is also possible to record the layer number of the currently traversed model layer during traversal, and mark the traversed model layers in the hierarchical quantization sequence according to the layer number, and then determine whether there are any model layers that have not been traversed based on the mark. This embodiment does not limit this.

[0111] Step S305: If there is a model layer that has not been traversed, return to the step of traversing the hierarchical quantization sequence and use the traversed model layer as the current model layer.

[0112] It is understandable that if there are model layers that have not been traversed, the layered quantization sequence can be continued to be traversed. Therefore, the process can return to step S301 to continue traversing the layered quantization sequence.

[0113] The embodiment of the present application traverses the hierarchical quantization sequence and quantizes the current model layer traversed. After the processing is completed, at least one model parameter in the quantized decoding model is adjusted with the goal of reducing the performance deviation corresponding to the current model layer. The embodiment attempts to correct the model output through parameter adjustment to reduce the performance loss of the model caused by low-bit quantization, so as to minimize the performance loss of the entire model caused by low-bit quantization.

[0114] Refer to FIG7 , which is a flow chart of a third embodiment of a model quantization method of the present application.

[0115] Based on the above second embodiment, after step S304, the model quantization method in the embodiment of the present application further includes:

[0116] Step S305': if there is no untraversed model layer in the hierarchical quantization sequence, then detecting whether there is any unquantized model layer in the decoding model to be quantized;

[0117] Step S306 ′: if there is no unquantized model layer, then the traversal of the hierarchical quantization sequence is terminated.

[0118] It should be noted that since the hierarchical quantization sequence may be obtained by intercepting the model layer sequence, it may not contain all the model layers in the decoding model to be quantized. Therefore, when there are no untraversed model layers in the hierarchical quantization sequence, some model layers in the decoding model to be quantized may not have been quantized. Therefore, when there are no untraversed model layers in the hierarchical quantization sequence, it is also necessary to detect whether there are any unquantized model layers in the decoding model to be quantized.

[0119] Among them, detecting whether there are still unquantized model layers in the decoding model to be quantized can be detecting whether there are still model parameters or input-output features expressed in floating point type in the decoding model to be quantized. If there are model parameters or input-output features expressed in floating point type, it can be determined that there are still unquantized model layers; if there are no model parameters or input-output features expressed in floating point type, it can be determined that there is no unquantized model layer.

[0120] It can be understood that if there is no unquantized model layer, it means that all model layers in the decoding model to be quantized have been quantized. Therefore, the traversal of the hierarchical quantization sequence can be terminated directly.

[0121] In order to ensure that all model layers in the decoding model to be quantized are quantized, after the step of detecting whether there are any unquantized model layers in the decoding model to be quantized if there are no untraversed model layers in the embodiment of the present application, the following steps may be further included:

[0122] If there is an unquantized model layer, quantizing the unquantized model layer;

[0123] When the quantization process is completed, the traversal of the hierarchical quantization sequence is terminated.

[0124] It should be noted that if there are no untraversed model layers in the hierarchical quantization sequence, but there are unquantized model layers in the decoding model to be quantized, it means that the hierarchical quantization sequence is formed by truncating the model layer sequence, which does not include all model layers in the decoding model to be quantized. When truncating, the model layers that are generally not added to the hierarchical quantization sequence are model layers with extremely small performance loss during quantization, and have extremely small impact on the overall performance. Therefore, the unquantized model layers in the decoding model to be quantized can be directly quantized. Among them, quantizing the unquantized model layers in the decoding model to be quantized can be quantizing the model parameters and input and output features in the unquantized model layers in the decoding model to be quantized using low bits.

[0125] It can be understood that when the quantization processing of all unquantized model layers in the decoding model to be quantized is completed, all model layers in the decoding model to be quantized have been quantized, and therefore, the traversal of the hierarchical quantization sequence can be terminated.

[0126] The embodiment of the present application detects whether there are any unquantized model layers in the decoding model to be quantized when there are no untraversed model layers in the hierarchical quantization sequence, and quantizes the unquantized model layers if any, to ensure that all model layers in the decoding model to be quantized are quantized when the processing is completed.

[0127] In addition, an embodiment of the present application further proposes a storage medium, on which a model quantization program is stored. When the model quantization program is executed by a processor, the steps of the model quantization method described above are implemented.

[0128] Refer to FIG8 , which is a structural block diagram of the first embodiment of the model quantization device of the present application.

[0129] As shown in FIG8 , the model quantization device proposed in the embodiment of the present application includes:

[0130] An acquisition module 10 is used to obtain the performance deviation corresponding to each model layer in the decoding model to be quantized;

[0131] A construction module 20 is configured to construct a hierarchical quantization sequence according to the performance deviations corresponding to the model layers;

[0132] The quantization module 30 is configured to perform hierarchical quantization processing on the model layers in the decoding model to be quantized based on the hierarchical quantization sequence.

[0133] The embodiment of the present application obtains the performance deviation corresponding to each model layer in the decoding model to be quantized; constructs a hierarchical quantization sequence according to the performance deviation corresponding to each model layer; and performs hierarchical quantization processing on the model layers in the decoding model to be quantized based on the hierarchical quantization sequence. Since the hierarchical quantization sequence is constructed according to the performance deviation corresponding to each model layer in the decoding model to be quantized, and the hierarchical quantization processing is performed on each model layer in the decoding model to be quantized according to the sequence order of the hierarchical quantization sequence, parameter adjustment can be used after quantization in the processing process to minimize the performance loss of the decoding model to be quantized caused by low-bit quantization.

[0134] In a possible implementation of the embodiment of the present application, the construction module 20 is further used to sort the model layers in the decoding model to be quantized in descending order according to the corresponding performance deviations to obtain a hierarchical quantization sequence.

[0135] In a possible implementation of this embodiment, the construction module 20 is also used to sort the model layers in the decoding model to be quantized in order from large to small according to the corresponding performance deviations to obtain a model layer sequence; and to truncate the model layer sequence from front to back according to a preset length to obtain a layered quantization sequence.

[0136] In a possible implementation of the embodiment of the present application, the performance deviation corresponding to the model layer is the deviation of the output of the decoding model to be quantized before and after the model layer in the decoding model to be quantized is quantized separately.

[0137] In a possible implementation of the embodiment of the present application, the quantization module 30 is also used to traverse the hierarchical quantization sequence and use the traversed model layer as the current model layer; perform quantization processing on the current model layer; adjust at least one model parameter in the decoding model to be quantized with the goal of reducing the performance deviation corresponding to the current model layer; detect whether there are any model layers that have not been traversed in the hierarchical quantization sequence; if there are any model layers that have not been traversed, return to the step of traversing the hierarchical quantization sequence and using the traversed model layer as the current model layer.

[0138] In a possible implementation of the embodiment of the present application, the quantization module 30 is further used to adjust at least one model parameter in the decoding model to be quantized by adopting a gradient derivation method with the goal of reducing the performance deviation corresponding to the current model layer.

[0139] In a possible implementation manner of the embodiment of the present application, adjusting at least one model parameter in the decoding model to be quantized includes at least one of the following:

[0140] Adjusting at least one model parameter of the current model layer;

[0141] Adjusting at least one model parameter of the current model layer and a model layer adjacent to the current model layer;

[0142] At least one model parameter of each model layer in the decoding model to be quantized is adjusted.

[0143] In a possible implementation of the embodiment of the present application, the quantization module 30 is also used to detect whether there are any unquantized model layers in the decoding model to be quantized if there are no unquantized model layers in the hierarchical quantization sequence; if there are no unquantized model layers, the traversal of the hierarchical quantization sequence is terminated.

[0144] In a possible implementation of the embodiment of the present application, the quantization module 30 is also used to perform quantization processing on the unquantized model layer in the decoding model to be quantized if there is an unquantized model layer in the decoding model to be quantized; when the quantization processing is completed, terminate the traversal of the hierarchical quantization sequence.

[0145] It should be understood that the above is only an example and does not constitute any limitation to the technical solution of the present application. In specific applications, technicians in this field can make settings as needed, and the present application does not impose any restrictions on this.

[0146] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of this application. In actual applications, technicians in this field can select part or all of it according to actual needs to achieve the purpose of the embodiment of this application, and no restrictions are imposed here.

[0147] In addition, for technical details not fully described in this embodiment, please refer to the model quantization method provided in any embodiment of this application, and will not be repeated here.

[0148] In addition, it should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.

[0149] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0150] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0151] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A model quantization method, comprising: Obtain the performance deviation corresponding to each model layer in the model to be quantized; Constructing a hierarchical quantization sequence according to the performance deviations corresponding to each model layer; Based on the hierarchical quantization sequence, a hierarchical quantization process is performed on the model layers in the model to be quantized.

2. The model quantization method according to claim 1, characterized in that: The step of constructing a hierarchical quantization sequence according to the performance deviations corresponding to each model layer includes: The model layers in the model to be quantized are sorted in descending order according to the corresponding performance deviations to obtain the hierarchical quantization sequence.

3. The model quantization method according to claim 2, characterized in that: The step of sorting the model layers in the to-be-quantized model in descending order according to the corresponding performance deviations to obtain the hierarchical quantization sequence includes: Sorting each model layer in the to-be-quantized model according to the corresponding performance deviations in descending order to obtain a model layer sequence; The model layer sequence is cut from front to back according to a preset length to obtain the layered quantization sequence.

4. The model quantization method according to claim 1, characterized in that: The performance deviation corresponding to the model layer in the model to be quantized is the deviation between the output of the model to be quantized before and after the model layer is quantized separately.

5. The model quantization method according to any one of claims 1 to 4, characterized in that: The step of performing hierarchical quantization processing on the model layer in the to-be-quantized model based on the hierarchical quantization sequence includes: Traversing the hierarchical quantization sequence, and taking the currently traversed model layer as the current model layer; Performing quantization processing on the current model layer; With the goal of reducing the performance deviation corresponding to the current model layer, adjusting at least one model parameter in the model to be quantized; Detecting whether there are any model layers that have not been traversed in the hierarchical quantization sequence; If there is a model layer that has not been traversed in the hierarchical quantization sequence, return to the step of traversing the hierarchical quantization sequence and use the currently traversed model layer as the current model layer.

6. The model quantization method according to claim 5, characterized in that: The step of adjusting at least one model parameter in the model to be quantized with the goal of reducing the performance deviation corresponding to the current model layer includes: A gradient derivation method is adopted to adjust at least one model parameter in the model to be quantized with the goal of reducing the performance deviation corresponding to the current model layer.

7. The model quantization method according to claim 5, characterized in that: The adjusting of at least one model parameter in the to-be-quantized model includes at least one of the following: Adjusting at least one model parameter of the current model layer; Adjusting at least one model parameter of the current model layer and at least one model parameter of a model layer adjacent to the current model layer; At least one model parameter of each model layer in the model to be quantized is adjusted.

8. The model quantization method according to claim 5, characterized in that: The method further comprises: If there is no untraversed model layer in the hierarchical quantization sequence, detecting whether there is still an unquantized model layer in the model to be quantized; If there is no unquantized model layer in the model to be quantized, it is determined that the quantization of the model to be quantized is completed.

9. The model quantization method according to claim 8, characterized in that: The method further comprises: If there is an unquantized model layer in the model to be quantized, quantizing the unquantized model layer; When the quantization process is completed, it is determined that the quantization of the model to be quantized is completed.

10. The model quantization method according to any one of claims 1 to 9, characterized in that: The model to be quantized is a decoding model or an encoding model.

11. The model quantization method according to claim 3, characterized in that: The step of intercepting the model layer sequence from front to back according to a preset length includes: The model layer sequence is cut from front to back starting from the first model layer included in the model layer sequence according to a preset length.

12. A model quantization device, comprising: An acquisition module is used to obtain the performance deviation corresponding to each model layer in the model to be quantized; A construction module, used to construct a hierarchical quantization sequence according to the performance deviations corresponding to each model layer; A quantization module is used to perform hierarchical quantization processing on the model layers in the model to be quantized based on the hierarchical quantization sequence.

13. A model quantization device, characterized in that: The model quantization device includes: a processor, a memory, and a model quantization program stored in the memory and executable by the processor. When the model quantization program is executed by the processor, the model quantization method according to any one of claims 1 to 11 is implemented.

14. A coding device, characterized in that: The encoding device includes: a processor, a memory, and an encoding program stored in the memory and executable on the processor, wherein the encoding program implements the model quantization method according to any one of claims 1 to 11 when executed by the processor.

15. A decoding device, characterized in that: The decoding device comprises: a processor, a memory, and a decoding program stored in the memory and executable by the processor, wherein the decoding program, when executed by the processor, implements the model quantization method according to any one of claims 1 to 11.

16. A storage medium, characterized in that: The storage medium stores a model quantization program, and the model quantization program is configured to execute the model quantization method according to any one of claims 1-11.

Citation Information

Patent Citations

  • Joint neural network model compression method based on channel pruning and quantitative training

    CN111652366A

  • Data processing method and device, equipment and computer readable storage medium

    CN113762503A