Post-training quantification method and device of network model, electronic equipment and storage medium

By performing network block training on the quantification model based on the preset floating-point model in the PTQ method, and using the sliding average algorithm to adjust parameters, the overfitting problem caused by insufficient data in the PTQ method is solved, and the quantification accuracy and prediction accuracy are improved. .

CN118690833APending Publication Date: 2024-09-24NANJING HOUMO TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310287973.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-22
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Due to the small amount of calibration set data, the existing post-training quantization (PTQ) method can easily lead to overfitting during quantitative training, resulting in poor accuracy during testing.

Method used

Based on the trained preset floating-point model, the network blocks in the quantization model are trained through training data, and the weights and quantization parameters are adjusted using the sliding average algorithm to improve quantification accuracy and prediction accuracy.

Benefits of technology

By combining the second quantization model, the quantification accuracy and prediction accuracy are improved, effectively solving the over-fitting problem during quantization training, and improving the performance of the target quantification model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690833A
    Figure CN118690833A
Patent Text Reader

Abstract

The embodiment of the invention discloses a post-training quantification method and device of a network model, electronic equipment and a storage medium, and the method comprises the steps: determining initial parameters of two quantification models based on the network parameters of a trained preset floating point model and the activation output of each network layer, and obtaining a first quantification model and a second quantification model; wherein the network structures of the first quantization model and the second quantization model are the same as the preset floating point model, and the network structure comprises at least one network block; inputting training data into the preset floating point model, the first quantitative model and the second quantitative model at least once to train at least one network block in the first quantitative model; wherein the training data is used for training one network block in the first quantitative model every time; and obtaining a target quantification model corresponding to the preset floating point network in response to all network blocks included in the first quantification model through training.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to Internet technology, and in particular to a post-training quantization method and device, electronic device, and storage medium for a network model. Background Art

[0002] Neural network quantization is a model compression method that aims to convert floating-point models into full-integer models of target bits. It can significantly reduce the model size, reduce storage costs and increase computing speed at the same time. When deploying a neural network model, the target number of quantization bits can be determined based on information such as the computing power of the specific hardware device and the degree of support for the number of model bits. For example, a 32-bit single-precision floating-point network can be quantized to a full-integer network such as 16 bits, 8 bits, or 4 bits. According to the different scales of data required in the quantization process, neural network quantization can be divided into two categories: quantization-aware training (QAT) and post-training quantization (PTQ). Summary of the invention

[0003] Embodiments of the present disclosure provide a post-training quantization method and device for a network model, an electronic device, and a storage medium.

[0004] According to one aspect of an embodiment of the present disclosure, a post-training quantization method for a network model is provided, comprising:

[0005] Based on the network parameters of the trained preset floating-point model and the activation output of each network layer, initial parameters of two quantization models are determined to obtain a first quantization model and a second quantization model; wherein the network structures of the first quantization model and the second quantization model are the same as the preset floating-point model, and the network structure includes at least one network block;

[0006] Inputting training data into the preset floating-point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time;

[0007] In response to all network blocks included in the first quantization model being trained, a target quantization model corresponding to the preset floating-point network is obtained.

[0008] Optionally, the at least one network block includes at least one group of directly connected first network blocks and second network blocks, and each of the first network blocks corresponds to one second network block;

[0009] The step of inputting the training data into the preset floating-point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model includes:

[0010] For each network block training, the training data is input into the first network block of the preset floating point model, the first quantization model and the second quantization model;

[0011] Based on the activation outputs of the preset floating-point model, the first quantization model, and the first network block of the second quantization model, weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

[0012] Optionally, after adjusting the weight parameters and quantization parameters in the second network block in the first quantization model, the method further includes:

[0013] Based on the adjusted weight parameters and quantization parameters in the second network block, determine the weight parameters and quantization parameters in the second network block in the second quantization model.

[0014] Optionally, the determining, based on the adjusted weight parameter and quantization parameter in the second network block, the weight parameter and quantization parameter in the second network block in the second quantization model includes:

[0015] Using the adjusted weight parameters in the second network block as weight parameters of the second network block in the second quantization model;

[0016] The quantization parameters in the second network block in the second quantization model are determined by using a sliding average algorithm based on the quantization parameters determined in this training and the quantization parameters determined in the previous training.

[0017] Optionally, the adjusting the weight parameters and quantization parameters in the second network block of the first quantization model based on the activation output of the first network block of the preset floating-point model, the first quantization model, and the second quantization model includes:

[0018] Obtaining a comprehensive output based on the activation outputs of the first network block of the preset floating-point model, the first quantization model, and the second quantization model;

[0019] inputting the synthesis output into a second network block of the first quantization model;

[0020] A second network block based on the preset floating point model obtains a supervised activation output, and a second network block based on the first quantization model obtains a predicted activation output;

[0021] Based on the supervised activation output and the predicted activation output, weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

[0022] Optionally, the activation output of the first network block based on the preset floating point model, the first quantization model and the second quantization model obtains a comprehensive output, including:

[0023] The activation output of the first network block of the preset floating-point model, the activation output of the first network block of the first quantization model, and the activation output of the first network block of the second quantization model are weightedly summed to obtain the comprehensive output.

[0024] Optionally, the network block includes at least one network layer; each network layer in the first quantization model further includes a quantization layer;

[0025] The second network block based on the first quantization model obtains a predicted activation output, including:

[0026] Based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block is determined.

[0027] Optionally, determining the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer includes:

[0028] Determining whether the current network layer is the last network layer in the second network block;

[0029] In response to the current network layer being the last network layer in the second network block, performing a weighted summation on an initial output of the current network layer and a quantized output of a current quantized layer to determine a predicted activation output of the second network block;

[0030] In response to the current network layer not being the last network layer in the second network block, a weighted sum is performed on the initial output of the current network layer and the quantized output of the current quantized layer to determine the input of the next network layer; wherein the next network layer is a network layer that uses the output of the current network layer as input.

[0031] According to another aspect of an embodiment of the present disclosure, a post-training quantization device for a network model is provided, comprising:

[0032] A model initialization module, used to determine the initial parameters of two quantization models based on the network parameters of the trained preset floating-point model and the activation output of each network layer, and obtain a first quantization model and a second quantization model; wherein the network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block;

[0033] A quantization model training module, used to input training data into the preset floating-point model, the first quantization model and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time;

[0034] A quantization model determination module is used to obtain a target quantization model corresponding to the preset floating-point network in response to all network blocks included in the first quantization model being trained.

[0035] Optionally, the at least one network block includes at least one group of directly connected first network blocks and second network blocks, and each of the first network blocks corresponds to one second network block;

[0036] The quantization model training module includes:

[0037] A data input unit, used for inputting the training data into the first network block of the preset floating point model, the first quantization model and the second quantization model;

[0038] A parameter adjustment unit is used to adjust the weight parameters and quantization parameters in the second network block of the first quantization model based on the activation output of the first network block of the preset floating-point model, the first quantization model and the second quantization model.

[0039] Optionally, the quantization model training module further includes:

[0040] A parameter updating unit is used to determine the weight parameters and quantization parameters in the second network block in the second quantization model based on the adjusted weight parameters and quantization parameters in the second network block.

[0041] Optionally, the parameter updating unit is specifically used to use the adjusted weight parameters in the second network block as the weight parameters of the second network block in the second quantization model; and use a sliding average algorithm to determine the quantization parameters in the second network block in the second quantization model based on the quantization parameters determined in this training and the quantization parameters determined in the previous training.

[0042] Optionally, the parameter adjustment unit is specifically used to obtain a comprehensive output based on the activation outputs of the first network block of the preset floating-point model, the first quantization model and the second quantization model; input the comprehensive output into the second network block of the first quantization model; obtain a supervised activation output based on the second network block of the preset floating-point model, and obtain a predicted activation output based on the second network block of the first quantization model; and adjust the weight parameters and quantization parameters in the second network block of the first quantization model based on the supervised activation output and the predicted activation output.

[0043] Optionally, when the parameter adjustment unit obtains a comprehensive output based on the activation output of the first network block of the preset floating-point model, the first quantization model and the second quantization model, the parameter adjustment unit is used to weightedly sum the activation output of the first network block of the preset floating-point model, the activation output of the first network block of the first quantization model and the activation output of the first network block of the second quantization model to obtain the comprehensive output.

[0044] Optionally, the network block includes at least one network layer; each network layer in the first quantization model further includes a quantization layer;

[0045] When the second network block based on the first quantization model obtains the predicted activation output, the parameter adjustment unit is used to determine the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block based on the initial output of each network layer in the second network block and the quantization output of the quantization layer corresponding to the network layer.

[0046] Optionally, when the parameter adjustment unit determines the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, the parameter adjustment unit is used to determine whether the current network layer is the last network layer in the second network block; in response to the current network layer being the last network layer in the second network block, the initial output of the current network layer and the quantized output of the current quantized layer are weightedly summed to determine the predicted activation output of the second network block; in response to the current network layer not being the last network layer in the second network block, the initial output of the current network layer and the quantized output of the current quantized layer are weighted summed to determine the input of the next network layer; wherein the next network layer is a network layer that takes the output of the current network layer as input.

[0047] According to another aspect of the embodiments of the present disclosure, there is provided an electronic device, including:

[0048] a memory for storing a computer program product;

[0049] The processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the post-training quantization method of the network model described in any of the above embodiments is implemented.

[0050] According to another aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the post-training quantization method of the network model described in any of the above embodiments is implemented.

[0051] According to another aspect of the embodiments of the present disclosure, a computer program product is provided, including computer program instructions, which, when executed by a processor, implement the post-training quantization method of the network model described in any of the above embodiments.

[0052] Based on the above embodiments of the present disclosure, a post-training quantization method and device for a network model, an electronic device, and a storage medium are provided. Based on the network parameters of a trained preset floating-point model and the activation output of each network layer, the initial parameters of two quantization models are determined to obtain a first quantization model and a second quantization model; wherein the network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block; training data is input into the preset floating-point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time; in response to all network blocks included in the first quantization model being trained, a target quantization model corresponding to the preset floating-point network is obtained; this embodiment improves the quantization accuracy by combining the second quantization model, and effectively improves the prediction accuracy of the quantized target quantization model.

[0053] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] The accompanying drawings, which constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0055] The present disclosure may be more clearly understood from the following detailed description with reference to the accompanying drawings, in which:

[0056] Figure 1 It is a flowchart of a post-training quantization method of a network model provided by an exemplary embodiment of the present disclosure;

[0057] Figure 2 This disclosure Figure 1A schematic flow chart of step 104 in the embodiment shown;

[0058] Figure 3 This disclosure Figure 2 A schematic flow chart of step 1042 in the embodiment shown;

[0059] Figure 4 It is a structural schematic diagram of a post-training quantization device for a network model provided by an exemplary embodiment of the present disclosure;

[0060] Figure 5 A block diagram of an electronic device according to an embodiment of the present disclosure is illustrated. DETAILED DESCRIPTION

[0061] Below, the exemplary embodiments according to the present disclosure will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described here.

[0062] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0063] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.

[0064] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.

[0065] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.

[0066] In addition, the term "and / or" in this disclosure is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this disclosure generally indicates that the previous and next associated objects are in an "or" relationship. The data referred to in this disclosure may include unstructured data such as text, images, and videos, and may also be structured data.

[0067] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.

[0068] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0069] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.

[0070] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered part of the specification.

[0071] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0072] The disclosed embodiments can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, servers, etc. include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.

[0073] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment, where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.

[0074] Application Overview

[0075] In the process of implementing the present disclosure, the inventors found that the general process of the existing PTQ method is: first establish a calibration set containing a small amount of unlabeled data, and then use the calibration set data as the neural network input to perform forward reasoning calculations, and the output activation value of each layer in the neural network can be obtained from the forward reasoning process. For each layer of the network, first determine a quantization parameter search space, and then calculate the quantization errors of the network's own weight value and output activation value in the search space, and take the quantization parameter with the smallest error as the result.

[0076] In the PTQ method, since the amount of calibration set data used is small, it is easy to cause overfitting during quantization training, that is, the network parameters are more biased towards the distribution of these small amounts of calibration set data, resulting in poor accuracy during testing.

[0077] Exemplary Methods

[0078] Figure 1 is a flow chart of a post-training quantization method of a network model provided by an exemplary embodiment of the present disclosure. This embodiment can be applied to electronic devices, such as Figure 1 As shown, the following steps are included:

[0079] Step 102, based on the trained network parameters of the preset floating-point model and the activation output of each network layer, determine the initial parameters of the two quantization models to obtain the first quantization model and the second quantization model.

[0080] The network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block.

[0081] In this embodiment, the preset floating-point model can be any deep neural network, such as a convolutional neural network, etc.; during the entire model post-training quantization process, the network parameters in the preset floating-point model are fixed.

[0082] Step 104: input the training data into the preset floating point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model.

[0083] The training data trains one network block in the first quantization model each time.

[0084] Optionally, the training data does not need to have labeled information. In this embodiment, the activation output of the preset floating-point model is used as the supervisory information. Since no labeled information is required, a lot of manpower and material resources are saved. Optionally, the network structure is divided into at least one network block according to basic components, and each network block includes at least one network layer. In this embodiment, each time the training data is input, only the weight parameters and quantization parameters in one network block in the first quantization model are trained.

[0085] Optionally, the training data may include, but is not limited to, data in the form of information such as images, texts, numbers, and codes.

[0086] Step 106: In response to at least one network block included in the first quantization model being trained, a target quantization model corresponding to a preset floating-point network is obtained.

[0087] Optionally, the first network block in the first quantization model cannot integrate the outputs of the three models and only relies on the preset floating-point model and the input of the first quantization model to adjust parameters. Therefore, this embodiment trains at least one network block in the first quantization model. For example, all network blocks in the first quantization model are trained in sequence. After all network blocks have been trained, the first quantization model after parameter adjustment can be used as the target quantization model.

[0088] The above-mentioned embodiment of the present disclosure provides a post-training quantization method for a network model, which determines the initial parameters of two quantization models based on the network parameters of a trained preset floating-point model and the activation output of each network layer to obtain a first quantization model and a second quantization model; wherein the network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block; training data is input into the preset floating-point model, the first quantization model and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time; in response to all network blocks included in the first quantization model being trained, a target quantization model corresponding to the preset floating-point network is obtained; this embodiment improves the quantization accuracy by combining the second quantization model, and effectively improves the prediction accuracy of the quantized target quantization model.

[0089] Optionally, the initial parameters in the first quantization model and the second quantization model can be determined by any method in the prior art. Alternatively, the first quantization model can be determined first, and then the first quantization model is deeply copied to obtain a second quantization model whose network structure and initial parameters are exactly the same as those of the first quantization model.

[0090] For example, in some optional examples, the quantization model is initialized by the following steps:

[0091] a, Collect a small amount of unlabeled data as a calibration dataset.

[0092] b. Input the calibration data set into the trained preset floating-point model to obtain the activation output of each network layer in the middle of the preset floating-point model.

[0093] c. Calibrate the quantization parameters and perform the following operations on the weights and activation values ​​of each layer in the network:

[0094] c1, calculate the maximum value of the weight parameter and the corresponding activation value respectively;

[0095] c2, sets the search space of the quantization parameters of weight parameters and activation values. The typical value is 100 data evenly spaced between 0.2 times the maximum value and 1.2 times the maximum value.

[0096] c3, for each value in the search space, calculate the MSE distance between the quantized output and the original floating-point output when the quantization parameter is set to this value space;

[0097] c4, select the quantization parameter with the smallest distance as the initial quantization parameter, and use the weight parameters in the preset floating-point model as the initial weight parameters in the two quantization models.

[0098] like Figure 2 As shown in the above Figure 1 Based on the illustrated embodiment, at least one network block includes at least one group of directly connected first network blocks and second network blocks, and each first network block corresponds to one second network block; the training of each network block in the first quantization model in step 104 may include the following steps:

[0099] Step 1041: input the training data into the first network block of the preset floating point model, the first quantization model and the second quantization model.

[0100] Step 1042: Based on the activation outputs of the first network block of the preset floating-point model, the first quantization model, and the second quantization model, the weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

[0101] In this embodiment, every two adjacent network blocks can be taken as a group. For example, the network structure includes network block 1, network block 2 and network block 3. In this case, network blocks 1 and 2 form a group, in which network block 1 is the first network block and network block 2 is the second network block. Network block 2 and network block 3 form a group, in which network block 2 is the first network block and network block 3 is the second network block. That is, the second network block in the previous group can be the first network block in the next group. By training the second network block in each group, all network blocks can be trained. In addition, in this embodiment, the activation output of the first network block of the three models (preset floating point model, first quantization model and second quantization model) is integrated to adjust the weight parameters and quantization parameters in the second network block, thereby improving the training efficiency of the network block.

[0102] Optionally, after adjusting the weight parameter and the quantization parameter in the second network block in the first quantization model, the method further includes:

[0103] Based on the adjusted weight parameters and quantization parameters in the second network block, the weight parameters and quantization parameters in the second network block in the second quantization model are determined.

[0104] In this embodiment, a preset number of iterations (e.g., 20,000 times, etc.) may be used as a training completion condition, and after each iteration, the weight parameters and quantization parameters in the second network block of the first quantization model are adjusted, the weight parameters and quantization parameters in the corresponding second network block in the second quantization model are adjusted based on the weight parameters and quantization parameters. Optionally, it may include:

[0105] Using the adjusted weight parameters in the second network block as weight parameters of the second network block in the second quantization model;

[0106] The sliding average algorithm is used to determine the quantization parameters in the second network block in the second quantization model based on the quantization parameters determined in this training and the quantization parameters determined in the previous training.

[0107] Optionally, since the network structure of the second quantization model is completely consistent with the first quantization model, the weight parameters in the second network block of the first quantization model can be assigned to the weight parameters in the corresponding network block in the second quantization model after each adjustment of the parameters in the second network block, or, after completing a preset number of iterations, the weight parameters in the second network block of the first quantization model are assigned to the weight parameters in the corresponding network block in the second quantization model; and for the quantization parameters in the second network block in the second quantization model, it is necessary to, in each iteration, use the quantization parameters in the second network block of the first quantization model in this iteration and the quantization parameters in the second network block of the second quantization model in the previous iteration. The quantization parameter of the second quantization network is determined by a sliding average algorithm; for example, in an optional example, the quantization parameter in this iteration is the first setting parameter, the quantization parameter in the previous iteration is the second setting parameter, the first setting parameter corresponds to the first weight value, and the second setting parameter corresponds to the second weight value (the sum of the first weight value and the second weight value is 1), and the quantization parameter corresponding to the second network block of the second quantization model can be obtained by weighted summing the first setting parameter and the second setting parameter; because the quantization parameter in the previous iteration is combined when the quantization parameter of the second quantization network is updated in each iteration, the quantization parameter in all previous iterations is applied to the update of the quantization parameter in the current iteration. In this embodiment, the quantization parameter is accumulated by the quantization parameter obtained in each iteration, and is not only affected by the parameters of a certain iteration, so that a more stable and robust quantization parameter is obtained, and when the next second network block is trained, the activation output of the second network block (the first network block for the next second network block) in the second quantization model after parameter adjustment is combined, so as to improve the stability of the weight parameter in the next second network block, adapt to more test samples, and obtain better quantization accuracy.

[0108] like Figure 3 As shown in the above Figure 2 Based on the illustrated embodiment, step 1042 may include:

[0109] Step 301, obtaining a comprehensive output based on the activation outputs of the first network block of the preset floating point model, the first quantization model and the second quantization model.

[0110] Optionally, the activation output of the first network block of the preset floating-point model, the activation output of the first network block of the first quantization model, and the activation output of the first network block of the second quantization model are weightedly summed to obtain a comprehensive output.

[0111] Optionally, the weight values ​​corresponding to the activation outputs of the three models can be empirically set values ​​and serve as hyperparameters in the network training process, and are not adjusted during the training process; for example, the preset floating-point model, the first quantization model, and the second quantization model correspond to weights p, p, and 1-2p, respectively (the specific values ​​can be set according to empirical values, and the sum of the three weight values ​​must be 1), where the value of p can be between 0.3 and 0.5 (not equal to 0.5). Usually, the weight value of the second quantization model is smaller.

[0112] Step 302: input the synthesis output into the second network block of the first quantization model.

[0113] Step 303: The second network block based on the preset floating point model obtains a supervised activation output, and the second network block based on the first quantization model obtains a predicted activation output.

[0114] In this embodiment, the activation output based on the preset floating-point model is used as the supervision value. Therefore, the training data does not need to be labeled, saving labor costs.

[0115] Step 304: Based on the supervised activation output and the predicted activation output, the weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

[0116] In this embodiment, a loss (e.g., minimum mean square error, etc.) is determined based on the difference between a supervised activation output and a preset activation output, and based on the loss, weight parameters and quantization parameters in the second network block of the first quantization model are adjusted; for example, the loss can be used to adjust the weight parameters and quantization parameters through gradient back propagation; in this embodiment, by combining the activation outputs of the preset floating-point network, the first quantization model, and the second quantization model, the obtained parameters are more robust, more stable, can adapt to more test samples, and obtain better quantization accuracy.

[0117] Optionally, obtaining a predicted activation output based on the second network block of the first quantization model includes:

[0118] Based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block is determined.

[0119] Optionally, the network block includes at least one network layer; each network layer in the first quantization model also includes a quantization layer; the initial output of each network layer is input into the quantization layer corresponding to the network layer for processing, and the corresponding quantized output is output, and the initial output and the quantized output are combined and input into the next network layer together, until the initial output of the last network layer and the quantized output of the quantization layer corresponding to the last network layer are combined to obtain the predicted activation output.

[0120] Optionally, based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, determining the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block includes:

[0121] determining whether the current network layer is the last network layer in the second network block;

[0122] In response to the current network layer being the last network layer in the second network block, performing a weighted summation on an initial output of the current network layer and a quantized output of the current quantized layer to determine a predicted activation output of the second network block;

[0123] In response to the current network layer not being the last network layer in the second network block, a weighted sum is performed on an initial output of the current network layer and a quantized output of the current quantized layer to determine an input of a next network layer.

[0124] Among them, the next network layer is a network layer that uses the output of the current network layer as input.

[0125] In this embodiment, each initial output and quantized output are weighted and summed to determine the input of the next network layer. The two weight values ​​can be set according to empirical values, and it is sufficient that the sum of the two weight values ​​is 1. In this embodiment, the output of each network layer and the output of the corresponding quantized layer are weighted and summed and then input into the next network layer, which combines more information during the training process and improves the efficiency of model training.

[0126] Any post-training quantization method of a network model provided in the embodiments of the present disclosure may be executed by any appropriate device with data processing capabilities, including but not limited to: a terminal device and a server, etc. Alternatively, any post-training quantization method of a network model provided in the embodiments of the present disclosure may be executed by a processor, such as a processor executing any post-training quantization method of a network model mentioned in the embodiments of the present disclosure by calling corresponding instructions stored in a memory. This will not be described in detail below.

[0127] Exemplary Devices

[0128] Figure 4 Schematic diagram of the structure of a post-training quantization device for a network model provided by an exemplary embodiment of the present disclosure. Figure 4 As shown, the device provided in this embodiment includes:

[0129] The model initialization module 41 is used to determine the initial parameters of the two quantization models based on the network parameters of the trained preset floating-point model and the activation output of each network layer to obtain the first quantization model and the second quantization model.

[0130] The network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block.

[0131] The quantization model training module 42 is used to input training data into the preset floating point model, the first quantization model and the second quantization model at least once to implement training of at least one network block in the first quantization model.

[0132] The training data trains one network block in the first quantization model each time.

[0133] The quantization model determination module 43 is used to obtain a target quantization model corresponding to a preset floating-point network in response to all network blocks included in the first quantization model being trained.

[0134] The above-mentioned embodiment of the present disclosure provides a post-training quantization device for a network model, which determines the initial parameters of two quantization models based on the network parameters of a trained preset floating-point model and the activation output of each network layer to obtain a first quantization model and a second quantization model; wherein the network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block; training data is input into the preset floating-point model, the first quantization model and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time; in response to all network blocks included in the first quantization model being trained, a target quantization model corresponding to the preset floating-point network is obtained; this embodiment improves the quantization accuracy by combining the second quantization model, and effectively improves the prediction accuracy of the quantized target quantization model.

[0135] Optionally, at least one network block includes at least one group of directly connected first network blocks and second network blocks, and each first network block corresponds to one second network block;

[0136] The quantization model training module 42 includes:

[0137] A data input unit, used to input training data into the first network block of the preset floating point model, the first quantization model and the second quantization model;

[0138] A parameter adjustment unit is used to adjust the weight parameters and quantization parameters in the second network block of the first quantization model based on the activation output of the first network block of the preset floating point model, the first quantization model and the second quantization model.

[0139] Optionally, the quantization model training module 42 further includes:

[0140] The parameter updating unit is used to determine the weight parameters and quantization parameters in the second network block in the second quantization model based on the adjusted weight parameters and quantization parameters in the second network block.

[0141] Optionally, the parameter updating unit is specifically used to use the adjusted weight parameters in the second network block as the weight parameters of the second network block in the second quantization model; and use a sliding average algorithm to determine the quantization parameters in the second network block in the second quantization model based on the quantization parameters determined in this training and the quantization parameters determined in the previous training.

[0142] Optionally, the parameter adjustment unit is specifically used to obtain a comprehensive output based on the activation output of the first network block of the preset floating-point model, the first quantization model and the second quantization model; input the comprehensive output into the second network block of the first quantization model; obtain a supervised activation output based on the second network block of the preset floating-point model, and obtain a predicted activation output based on the second network block of the first quantization model; and adjust the weight parameters and quantization parameters in the second network block of the first quantization model based on the supervised activation output and the predicted activation output.

[0143] Optionally, when the parameter adjustment unit obtains the comprehensive output based on the activation output of the first network block of the preset floating-point model, the first quantization model and the second quantization model, the activation output of the first network block of the preset floating-point model, the activation output of the first network block of the first quantization model and the activation output of the first network block of the second quantization model are weighted to obtain the comprehensive output.

[0144] Optionally, the network block includes at least one network layer; each network layer in the first quantization model further includes a quantization layer;

[0145] The parameter adjustment unit is used to determine the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, when the second network block based on the first quantization model obtains the predicted activation output.

[0146] Optionally, the parameter adjustment unit is used to determine whether the current network layer is the last network layer in the second network block when determining the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer; in response to the current network layer being the last network layer in the second network block, performing a weighted summation on the initial output of the current network layer and the quantized output of the current quantized layer to determine the predicted activation output of the second network block; in response to the current network layer not being the last network layer in the second network block, performing a weighted summation on the initial output of the current network layer and the quantized output of the current quantized layer to determine the input of the next network layer; wherein the next network layer is a network layer that takes the output of the current network layer as input.

[0147] Exemplary Electronic Devices

[0148] Below, reference Figure 5 The electronic device according to the embodiment of the present disclosure is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signals from them.

[0149] Figure 5 A block diagram of an electronic device according to an embodiment of the present disclosure is illustrated.

[0150] like Figure 5 As shown, the electronic device includes one or more processors and memory.

[0151] The processor may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.

[0152] The memory may store one or more computer program products, and the memory may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program products may be stored on the computer-readable storage medium, and the processor may run the computer program product to implement the post-training quantization method of the network model of each embodiment of the present disclosure described above and / or other desired functions.

[0153] In one example, the electronic device may further include: an input device and an output device, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0154] In addition, the input device may also include, for example, a keyboard, a mouse, and the like.

[0155] The output device can output various information to the outside, including determined distance information, direction information, etc. The output device can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0156] Of course, to simplify, Figure 5 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.

[0157] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps in the post-training quantization method of the network model according to various embodiments of the present disclosure described in the above part of this specification.

[0158] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0159] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, cause the processor to execute the steps of the post-training quantization method of the network model according to various embodiments of the present disclosure described in the above part of this specification.

[0160] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0161] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.

[0162] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0163] The block diagrams of the devices, apparatuses, equipment, and systems involved in this disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including," "comprising," "having," and the like are open words, referring to "including but not limited to," and can be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or," and can be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and can be used interchangeably therewith.

[0164] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.

[0165] It should also be noted that in the apparatus, device and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.

[0166] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

[0167] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.

Claims

1. A post-training quantization method for a network model, It is characterized in that include: Based on the network parameters of the trained preset floating-point model and the activation output of each network layer, initial parameters of two quantization models are determined to obtain a first quantization model and a second quantization model; wherein the network structures of the first quantization model and the second quantization model are the same as the preset floating-point model, and the network structure includes at least one network block; Inputting training data into the preset floating-point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time; In response to at least one network block included in the first quantization model being trained, a target quantization model corresponding to the preset floating-point network is obtained.

2. The method according to claim 1, It is characterized in that The at least one network block includes at least one group of directly connected first network blocks and second network blocks, and each of the first network blocks corresponds to a second network block; The step of inputting the training data into the preset floating-point model, the first quantization model, and the second quantization model at least once to implement training of at least one network block in the first quantization model includes: For each network block training, the training data is input into the first network block of the preset floating point model, the first quantization model and the second quantization model; Based on the activation outputs of the preset floating-point model, the first quantization model, and the first network block of the second quantization model, weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

3. The method according to claim 2, It is characterized in that After the weight parameters and quantization parameters in the second network block in the first quantization model are adjusted, the method further includes: Based on the adjusted weight parameters and quantization parameters in the second network block, determine the weight parameters and quantization parameters in the second network block in the second quantization model.

4. The method according to claim 3, It is characterized in that The determining, based on the adjusted weight parameter and quantization parameter in the second network block, the weight parameter and quantization parameter in the second network block in the second quantization model comprises: Using the adjusted weight parameters in the second network block as weight parameters of the second network block in the second quantization model; The quantization parameters in the second network block in the second quantization model are determined by using a sliding average algorithm based on the quantization parameters determined in this training and the quantization parameters determined in the previous training.

5. The method according to any one of claims 2 to 4, It is characterized in that The adjusting of the weight parameters and quantization parameters in the second network block of the first quantization model based on the activation output of the first network block of the preset floating point model, the first quantization model, and the second quantization model includes: Obtaining a comprehensive output based on the activation outputs of the first network block of the preset floating-point model, the first quantization model, and the second quantization model; inputting the synthesis output into a second network block of the first quantization model; A second network block based on the preset floating point model obtains a supervised activation output, and a second network block based on the first quantization model obtains a predicted activation output; Based on the supervised activation output and the predicted activation output, weight parameters and quantization parameters in the second network block of the first quantization model are adjusted.

6. The method according to claim 5, It is characterized in that The activation output of the first network block based on the preset floating point model, the first quantization model and the second quantization model obtains a comprehensive output, including: The activation output of the first network block of the preset floating-point model, the activation output of the first network block of the first quantization model, and the activation output of the first network block of the second quantization model are weightedly summed to obtain the comprehensive output.

7. The method according to claim 5 or 6, It is characterized in that The network block includes at least one network layer; each network layer in the first quantization model also includes a quantization layer; The second network block based on the first quantization model obtains a predicted activation output, including: Based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block is determined.

8. The method according to claim 7, It is characterized in that The determining, based on the initial output of each network layer in the second network block and the quantized output of the quantized layer corresponding to the network layer, the input of the next network layer corresponding to the network layer or the predicted activation output of the second network block comprises: Determining whether the current network layer is the last network layer in the second network block; In response to the current network layer being the last network layer in the second network block, performing a weighted summation on an initial output of the current network layer and a quantized output of a current quantized layer to determine a predicted activation output of the second network block; In response to the current network layer not being the last network layer in the second network block, a weighted sum is performed on the initial output of the current network layer and the quantized output of the current quantized layer to determine the input of the next network layer; wherein the next network layer is a network layer that uses the output of the current network layer as input.

9. A post-training quantization device for a network model, It is characterized in that include: A model initialization module, used to determine the initial parameters of two quantization models based on the network parameters of the trained preset floating-point model and the activation output of each network layer, and obtain a first quantization model and a second quantization model; wherein the network structure of the first quantization model and the second quantization model is the same as the preset floating-point model, and the network structure includes at least one network block; A quantization model training module, used to input training data into the preset floating-point model, the first quantization model and the second quantization model at least once to implement training of at least one network block in the first quantization model; wherein the training data trains one network block in the first quantization model each time; A quantization model determination module is used to obtain a target quantization model corresponding to the preset floating-point network in response to all network blocks included in the first quantization model being trained.

10. An electronic device, It is characterized in that include: a memory for storing a computer program product; A processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the post-training quantization method of the network model described in any one of claims 1-8 is implemented.

11. A computer readable storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the post-training quantization method of the network model described in any one of claims 1-8 is implemented.

12. A computer program product comprising computer program instructions, It is characterized in that When the computer program instructions are executed by a processor, the post-training quantization method of the network model described in any one of claims 1-8 is implemented.

Citation Information

Cited By

  • Model quantification method and computing device

    CN120471116A