Model training method and device, storage medium and electronic equipment

By inserting pseudo-quantization nodes into the Transformer part of the Conformer model and performing operator fusion and perceptual quantization training, the problem of large model size and slow inference speed is solved, and the efficient compression and accuracy maintenance of the model are achieved.

CN118887947APending Publication Date: 2024-11-01MIDEA GRP (SHANGHAI) CO LTD +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410914007.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-08
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

Due to the huge structure and complex computing, the Conformer model has high memory footprint, making it difficult to effectively compress the model size and improve the inference speed.

Method used

The pseudo-quantization node is inserted into the Transformer part of the Conformer model, and the inserted pseudo-quantization nodes are subjected to operator fusion processing and perceptual quantization training, and the optimal quantization parameters are dynamically searched to realize the quantitative compression of the model.

Benefits of technology

On the premise of ensuring speech recognition accuracy, the model size is reduced, resource overhead is reduced, and the model inference speed is improved, thus achieving effective compression of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118887947A_ABST
    Figure CN118887947A_ABST
Patent Text Reader

Abstract

The invention provides a model training method and device, a storage medium and electronic equipment. The model training method comprises the following steps: inserting a pseudo quantization node in a first network structure to obtain a second network structure; performing operator fusion processing on a first target operator in the second network structure, wherein the first target operator comprises a pseudo quantization node; and performing perceptual quantization training on the second network structure based on the pseudo quantization node to obtain a speech recognition model. The second network structure can be quantitatively compressed in the training process, and the volume of the speech recognition model can be further reduced on the premise of ensuring the recognition precision of the speech recognition model obtained through training.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] The Conformer model (a speech recognition model) combines the strengths of the traditional CNN (Convolutional Neural Networks) model and the Transformer (a neural network architecture based on the self-attention mechanism) model. It can efficiently extract local features while also paying attention to long-range dependencies.

[0003] In the related art, the memory occupied by the Conformer structure model on the device remains high due to its large size and complex calculation. Summary of the invention

[0004] The present application aims to solve one of the technical problems existing in the prior art or related technology.

[0005] To this end, the first aspect of the present application proposes a model training method.

[0006] The second aspect of the present application proposes a model training device.

[0007] The third aspect of the present application proposes a model training device.

[0008] A fourth aspect of the present application provides a readable storage medium.

[0009] A fifth aspect of the present application provides an electronic device.

[0010] In view of this, according to the first aspect of the present application, a model training method is proposed, including: inserting a pseudo-quantization node into a first network structure to obtain a second network structure; performing operator fusion processing on a first target operator in the second network structure, wherein the first target operator includes a pseudo-quantization node; and performing perceptual quantization training on the second network structure based on the pseudo-quantization node to obtain a speech recognition model.

[0011] In this technical solution, the first network structure is a network structure in a conformer model, and the first network structure includes a transformer part and a convolution part. By inserting a pseudo-quantization node into the transformer part, the first network structure can be quantized and compressed in the subsequent training process. It should be noted that the pseudo-quantization node includes relevant parameters of floating-point data, and based on the pseudo-quantization node, the model can be quantized and compressed in the subsequent training process.

[0012] In this technical solution, the second network structure is a network structure after the pseudo quantization node is inserted. After the pseudo quantization node is inserted, the second network structure may have a quantization error during speech recognition. By fusing the first target operator in the second network structure, the quantization error caused by the insertion of the pseudo quantization node can be reduced.

[0013] It should be noted that the first target operator includes an operator with a pseudo quantization node inserted therein. By fusing the operator with the pseudo quantization node inserted therein with an adjacent operator, a new operator can be generated, thereby reducing the quantization error caused by the pseudo quantization node.

[0014] In this technical solution, a pseudo-quantization node has been inserted into the second network structure, and the first target operator of the pseudo-quantization node inserted into the second network structure is fused. At this time, the second network structure is subjected to perceptual quantization training to obtain the final speech recognition model. Since the second network structure includes inserted pseudo-quantization nodes, the perceptual quantization training can simulate the quantization behavior by performing floating-point operations in the quantization nodes during the training process, thereby ensuring the training efficiency and training accuracy as much as possible, thereby obtaining a speech recognition model of the pseudo-quantization model. Quantization perceptual training is a method of dynamically finding the optimal quantization parameters by training a pseudo-quantization model. After the training is completed, the quantization parameters are also fixed. Compared with quantization compression after the model is offline, it can improve the compression rate, reduce resource overhead, further reduce the model size, and improve the model inference speed.

[0015] In the technical solution of the present application, before the training starts, a pseudo-quantization node is inserted into the first network structure, and the first target operator including the pseudo-quantization node in the first network structure is fused to obtain a second network structure. By performing perceptual quantization training on the second network structure, the second network structure can be quantized and compressed during the training process, and the size of the speech recognition model can be further reduced while ensuring the recognition accuracy of the speech recognition model obtained by training.

[0016] In some technical solutions, optionally, a pseudo-quantization node is inserted into the first network structure to obtain a second network structure, including:

[0017] Determine a third target operator in the first network structure according to the second target operator, where the third target operator is an operator node in the first network structure except the second target operator;

[0018] Inserting a pseudo-quantization node into the first network structure;

[0019] The second target operator includes at least one of the following: a mask operator and a position encoding operator.

[0020] In this technical solution, in the process of inserting the pseudo-quantization node into the first network structure, it is necessary to select a third target operator that can insert the pseudo-quantization node. It can be understood that the first network structure includes an operator that will seriously affect the accuracy of the model after inserting the pseudo-quantization node, that is, the second target operator. Therefore, the second target operator in the first network structure is first determined, and then the operator other than the second target operator is used as the third target operator.

[0021] Specifically, the pseudo-quantization node is used to count the maximum and minimum values ​​of the floating-point data flowing through the operator, so as to calculate a pair of quantization parameters (the maximum and minimum values ​​of the floating-point data) for the pseudo-quantization operator in the trained speech recognition model. The quantization parameters are used to simulate the quantization results during training and serve to generate the final speech recognition model through training.

[0022] In the technical solution of the present application, in the process of inserting a pseudo-quantization node, a second target operator that does not need to be quantized is first determined, and a third target operator in the first network structure is screened based on the second target operator, wherein the second target operator includes a mask operator and a position encoding operator. Inserting a pseudo-quantization node in the first network structure improves the accuracy of inserting the pseudo-quantization node, and further reduces the impact of inserting the pseudo-quantization node on the recognition accuracy of the entire model.

[0023] In some technical solutions, optionally, inserting a pseudo-quantization node into the first network structure includes:

[0024] Determining a target position in the third target operator based on the weight information and the activation information in the third target operator;

[0025] Insert a Pseudo Quantize node at the target location.

[0026] In this technical solution, model quantization is a compression method that compresses model weight information and activation information from floating-point data to fixed-point data, thereby reducing the resource overhead occupied by the model and improving the reasoning speed of the model. Therefore, in the process of inserting pseudo-quantization nodes, the insertion position of the pseudo-quantization nodes in the third target operator is determined based on the weight information in the third target operator and the activation information.

[0027] In the technical solution of the present application, after determining the third target operator into which the pseudo quantization node needs to be inserted, the target position for inserting the pseudo quantization node is determined based on the weight information and activation information in the third target operator, and the pseudo quantization node is inserted into the target position, thereby improving the accuracy of inserting the pseudo quantization node.

[0028] In some technical solutions, optionally, before inserting the pseudo-quantization node into the first network structure, the model training method further includes:

[0029] A pseudo quantization node is constructed according to the floating-point data of the third target operator, wherein the pseudo quantization node includes a maximum value and a minimum value of the floating-point data.

[0030] In this technical solution, the pseudo-quantization node is used to count the maximum and minimum values ​​of the floating-point data flowing through the operator, so the maximum and minimum values ​​of the floating-point data of the third target operator can be determined according to the floating-point data of the third target operator. The maximum and minimum values ​​of the floating-point data are used as quantization parameters and inserted into the target position of the third target operator in the form of a pseudo-quantization node. During the training process, the model can be quantized and compressed through the quantization parameters in the pseudo-quantization node.

[0031] In the technical solution of the present application, a corresponding pseudo-quantization node is constructed based on the third target operator, so that the pseudo-quantization node includes the maximum and minimum values ​​of the floating-point data in the third target operator. By inserting the pseudo-quantization node into the third target operator, the maximum and minimum values ​​of the floating-point data in the pseudo-quantization node are used to simulate the quantization results during training, and serve to train and generate the final speech recognition model, thereby improving the compression rate of the speech recognition model finally obtained by training.

[0032] In some technical solutions, optionally, perceptual quantization training is performed on the second network structure based on the pseudo-quantization node to obtain a speech recognition model, including:

[0033] Determine a target difference value according to the pseudo quantization node, where the target difference value is the difference between the maximum value of the floating-point data and the minimum value of the floating-point data;

[0034] Determine the scaling factor according to the target difference and the preset floating point number interval;

[0035] Determine a zero reference point according to the scaling factor, the maximum value of the floating-point data, and the maximum value of the fixed-point data, the maximum value of the fixed-point data corresponding to the maximum value of the floating-point data;

[0036] The second network structure is quantized and trained according to the scaling factor and the zero reference point to obtain a speech recognition model.

[0037] In this technical solution, during the perceptual quantization training of the second network structure, the scaling factor can be determined according to the maximum value of the floating-point data in the pseudo-quantization node and the minimum value of the floating-point data, and then the zero reference point of the quantization is determined based on the scaling factor. When the zero reference point is determined, the floating-point data in the second network structure can be mapped to the corresponding fixed-point data, and the quantization training of the second network structure can be completed.

[0038] In the technical solution of the present application, in the process of quantizing the second network structure based on the pseudo-quantization node, the scaling factor can be determined based on the maximum and minimum values ​​of the floating-point data in the quantization node, and the corresponding zero reference point can be determined, so that the third target operator in the second network structure can be quantized according to the scaling factor and the zero reference point to train a speech recognition model.

[0039] In some technical solutions, optionally, performing operator fusion processing on the first target operator in the second network structure includes:

[0040] Determine the multiplication-addition operator and the first fully connected operator in the second network structure according to the pseudo-quantization node;

[0041] Determining a multiplication parameter in a multiply-add operator, and a first weight and a first bias in a first fully connected operator;

[0042] The multiplication-addition operator and the first fully connected operator in the second network structure are fused according to the multiplication parameter, the first weight and the first bias.

[0043] In the technical solution, the first target operator includes a multiplication-addition operator and a first fully connected operator, wherein the first fully connected operator is a fully connected operator adjacent to the multiplication-addition operator. In the process of fusing the multiplication-addition operator with the first fully connected operator, it is necessary to extract the multiplication parameter in the multiplication-addition operator, as well as the first weight and the first bias in the first fully connected layer, and perform linear algebra based on the multiplication parameter, the first weight and the first bias to complete the fusion of the multiplication operator with the first fully connected operator, wherein the fusion results in a new fully connected operator.

[0044] In the technical solution of the present application, by fusing the multiplication-addition operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0045] In some technical solutions, optionally, performing operator fusion processing on the first target operator in the second network structure includes:

[0046] Determining an activation operator and a second fully connected operator in a second network structure, wherein the activation operator includes a pseudo-quantization node;

[0047] The activation operator and the second fully connected operator in the second network structure are fused.

[0048] In this technical solution, the first target operator includes an activation operator and a second fully connected operator, wherein the first fully connected operator is a fully connected operator adjacent to the activation operator, and the activation operator is fused with the first fully connected operator.

[0049] In the technical solution of the present application, by fusing the activation operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0050] In some technical solutions, optionally, after performing perceptual quantization training on the second network structure based on pseudo-quantization nodes to obtain a speech recognition model, the model training method further includes: inputting audio features into the speech recognition model to obtain audio recognition results.

[0051] In the technical solution of the present application, after a speech recognition model is obtained through training, the speech recognition model is configured in a household appliance, and after audio features are acquired, the audio features are input into the speech recognition model to obtain an audio recognition result.

[0052] According to the second aspect of the present application, a model training device is proposed, including: a processing module, used to insert a pseudo-quantization node in a first network structure to obtain a second network structure; a processing module, used to perform operator fusion processing on a first target operator in the second network structure, the first target operator including a pseudo-quantization node; a training module, used to perform perceptual quantization training on the second network structure to obtain a speech recognition model.

[0053] In the technical solution of the present application, before the training starts, a pseudo-quantization node is inserted into the first network structure, and the first target operator including the pseudo-quantization node in the first network structure is fused to obtain a second network structure. By performing perceptual quantization training on the second network structure, the second network structure can be quantized and compressed during the training process, and the size of the speech recognition model can be further reduced while ensuring the recognition accuracy of the speech recognition model obtained by training.

[0054] According to the third aspect of the present application, a model training device is proposed, wherein the model training device includes a processor and a memory, wherein a program or instruction is stored in the memory, and when the program or instruction is executed by the processor, the steps of the model training method in any of the above technical solutions are implemented. Therefore, the model training device has all the beneficial effects of the model training method in any of the above technical solutions, which will not be repeated here.

[0055] According to the fourth aspect of the present application, a readable storage medium is proposed, on which a program or instruction is stored. When the program or instruction is executed by a processor, a model training method as in any of the above-mentioned technical solutions is implemented, thereby having all the beneficial technical effects of the model training method in any of the above-mentioned technical solutions.

[0056] According to the fifth aspect of the present application, an electronic device is proposed, comprising: a model training device as in any of the above technical solutions, and / or a readable storage medium as in any of the above technical solutions, and thus has all the beneficial technical effects of the model training device as in any of the above technical solutions, and / or the readable storage medium as in any of the above technical solutions, and no further details will be given here.

[0057] Additional aspects and advantages of the present application will become apparent in the following description or will be learned through practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0059] Figure 1 One of the flow diagrams of a model training method provided in some embodiments of the present application is shown;

[0060] Figure 2a A schematic diagram showing a first network structure provided in some embodiments of the present application;

[0061] Figure 2b A schematic diagram of quantizing an operator provided in some embodiments of the present application is shown;

[0062] Figure 3 One of the operator fusion schematic diagrams provided in some embodiments of the present application is shown;

[0063] Figure 4 A second schematic diagram of operator fusion provided in some embodiments of the present application is shown;

[0064] Figure 5 One of the schematic block diagrams of a model training device is shown in some embodiments of the present application;

[0065] Figure 6 A second schematic block diagram of a model training device is shown in some embodiments of the present application;

[0066] Figure 7 A schematic block diagram of an electronic device provided in some embodiments of the present application is shown. DETAILED DESCRIPTION

[0067] In order to more clearly understand the above-mentioned objectives, features and advantages of the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. It should be noted that, in the absence of conflict, the present embodiment and the features in the embodiment can be combined with each other.

[0068] In the following description, many specific details are set forth to facilitate a full understanding of the present application. However, the present application may also be implemented in other ways different from those described herein. Therefore, the scope of protection of the present application is not limited to the specific embodiments disclosed below.

[0069] Refer to the following Figures 1 to 7 Describe a model training method, a model training device, a readable storage medium, and an electronic device according to some embodiments of the present application.

[0070] According to one embodiment of the present application, Figure 1 One of the flow charts of a model training method provided in some embodiments of the present application is shown, such as Figure 1 As shown, a model training method is proposed, which is applied to electronic devices. The model training method includes:

[0071] Step 102, inserting a pseudo-quantization node into the first network structure to obtain a second network structure;

[0072] In this embodiment, the first network structure is a network structure in a conformer model, and the first network structure includes a transformer part and a convolution part. By inserting a pseudo-quantization node into the transformer part, the first network structure can be quantized and compressed in the subsequent training process. It should be noted that the pseudo-quantization node includes relevant parameters of floating-point data, and based on the pseudo-quantization node, the model can be quantized and compressed in the subsequent training process.

[0073] Figure 2a A schematic diagram of a first network structure provided in some embodiments of the present application is shown, such as Figure 2a As shown in the figure, the first network structure is the network structure in the conformer model, where the reasoning process of the transformer part is as follows:

[0074] The input audio features are passed through W q , W k , W v After the three weight matrices, we get the query vector Q, the key value vector K, and the key value vector V respectively. Then we first perform the dot multiplication on Q and K and divide them by the built-in dimension d under the square root. kAs the score of the query vector. As another training input, the Attention Mask is calculated in advance from the sample. After the slice operation index_select and the mask operation masked_fill, a new input mask Mask is obtained. The new mask is multiplied by the score and the final score is obtained after the softmax (normalized exponential function) operation. The Conformer model also uses position encoding (PE, position embedding) to extract the relative position characteristics of the input audio, and combine the fully connected layer Wpe and the bias information to expand the final score to the time series. After completing the matrix multiplication operation of Wv and Wpe, the operation result passes through the weight matrix Wo, and the weighted score on the time series after linear transformation can be obtained. The output of the Conformer module is added to the input of the convolution module in the Conformer architecture to obtain Xatt (input before convolution). After the new mask_pad is used, it passes through the depthwise convolution and two pointwise convolutions, and then is accumulated with Xatt to obtain the final output. The output of ReLU (activation function) is also subjected to a non-quantized mask bit operation, which helps improve the accuracy of the model. Among them, Wpointwise1 is the pointwise weight, Wdepthwise is the depthwise weight, GLU is also the activation function, Xconv is the output after convolution, and bitwise is the bit-by-bit convolution.

[0075] Step 104, performing operator fusion processing on the first target operator in the second network structure, where the first target operator includes a pseudo quantization node;

[0076] In this embodiment, the second network structure is a network structure after the pseudo quantization node is inserted. After the pseudo quantization node is inserted, the second network structure may have a quantization error during speech recognition. By fusing the first target operator in the second network structure, the quantization error caused by the insertion of the pseudo quantization node can be reduced.

[0077] It should be noted that the first target operator includes an operator with a pseudo quantization node inserted therein. By fusing the operator with the pseudo quantization node inserted therein with an adjacent operator, a new operator can be generated, thereby reducing the quantization error caused by the pseudo quantization node.

[0078] Step 106: Perform perceptual quantization training on the second network structure based on the pseudo-quantization nodes to obtain a speech recognition model.

[0079] In this embodiment, a pseudo-quantization node has been inserted into the second network structure, and the first target operator of the pseudo-quantization node inserted into the second network structure is fused. At this time, the second network structure is subjected to perceptual quantization training to obtain the final speech recognition model. Since the second network structure includes inserted pseudo-quantization nodes, the perceptual quantization training can simulate the quantization behavior by performing floating-point operations in the quantization nodes during the training process, thereby ensuring the training efficiency and training accuracy as much as possible, thereby obtaining a speech recognition model of the pseudo-quantization model. Quantization perceptual training is a method of dynamically finding the optimal quantization parameters by training a pseudo-quantization model. After the training is completed, the quantization parameters are also fixed. Compared with quantization compression after the model is offline, it can improve the compression rate, reduce resource overhead, further reduce the model size, and improve the model reasoning speed.

[0080] In the embodiment of the present application, before the training starts, a pseudo-quantization node is inserted into the first network structure, and the first target operator including the pseudo-quantization node in the first network structure is fused to obtain a second network structure. By performing perceptual quantization training on the second network structure, the second network structure can be quantized and compressed during the training process, and the volume of the speech recognition model can be further reduced while ensuring the recognition accuracy of the speech recognition model obtained by training.

[0081] In some embodiments, optionally, inserting a pseudo-quantization node into the first network structure to obtain a second network structure includes:

[0082] Determine a third target operator in the first network structure according to the second target operator, where the third target operator is an operator node in the first network structure except the second target operator;

[0083] Inserting a pseudo-quantization node into the first network structure;

[0084] The second target operator includes at least one of the following: a mask operator and a position encoding operator.

[0085] In this embodiment, in the process of inserting the pseudo quantization node into the first network structure, it is necessary to select a third target operator that can be inserted into the pseudo quantization node. It can be understood that the first network structure includes an operator that will seriously affect the accuracy of the model after inserting the pseudo quantization node, that is, the second target operator. Therefore, the second target operator in the first network structure is first determined, and then the operator other than the second target operator is used as the third target operator.

[0086] Specifically, the pseudo-quantization node is used to count the maximum and minimum values ​​of the floating-point data flowing through the operator, so as to calculate a pair of quantization parameters (the maximum and minimum values ​​of the floating-point data) for the pseudo-quantization operator in the trained speech recognition model. The quantization parameters are used to simulate the quantization results during training and serve to generate the final speech recognition model through training.

[0087] For example, the end measurement hardware supports int8 (fixed-point data format) quantization, which compresses the floating-point numbers of fp32 (floating-point data format) in the model to the range of 0 to 255 under asymmetric quantization, or compresses the floating-point numbers of fp32 in the model to the range of -128 to 127 under symmetric quantization.

[0088] Figure 2b FIG. 4 shows a schematic diagram of quantizing an operator provided in some embodiments of the present application, such as Figure 2a and Figure 2b As shown in the figure, the text box with diagonal shadows represents operators with weights. It is necessary to perform symmetric quantization on these operators and asymmetric quantization on their outputs. The text box with horizontal shadows can be divided into mask operators and position encoding operators. Since mask operators are all Boolean arrays that are either 0 or 1, they do not have theoretical support for quantization. As a non-trainable constant in the model, the position encoding operator should also maintain a floating point form. Therefore, the positions involved in the operations before and after the mask operator and the position encoding operator are not quantized to avoid distorting the information given by the neural network, while the remaining operators without shadows are operators without weights, and their outputs need to be asymmetric activated and quantized. The operator with weights is the third target operator, and the mask operator and the position encoding operator are the second target operators. Among them, weight op is an operator with weights, w / o weight is an operator without weights, weight fake quant is a pseudo quantization node, and Activation_post_process is an activation output quantization operation.

[0089] Exemplarily, the second target operator can be manually labeled by the user. Manual labeling by the user can improve the accuracy of determining operators that do not need to be quantized. After the user manually labels the second target operator, the system can determine the third target operator that needs to insert a pseudo-quantization node based on the second target operator manually labeled by the user.

[0090] In the embodiment of the present application, in the process of inserting the pseudo-quantization node, the second target operator that does not need to be quantized is first determined, and the third target operator in the first network structure is screened based on the second target operator, wherein the second target operator includes a mask operator and a position encoding operator. Inserting the pseudo-quantization node in the first network structure improves the accuracy of inserting the pseudo-quantization node, and further reduces the impact of inserting the pseudo-quantization node on the recognition accuracy of the entire model.

[0091] In some embodiments, optionally, inserting a pseudo quantization node into the first network structure includes:

[0092] Determining a target position in the third target operator based on the weight information and the activation information in the third target operator;

[0093] Insert a Pseudo Quantize node at the target location.

[0094] In this embodiment, model quantization is a compression method that compresses model weight information and activation information from floating-point data to fixed-point data, thereby reducing the resource overhead occupied by the model and improving the reasoning speed of the model. Therefore, in the process of inserting a pseudo-quantization node, the insertion position of the pseudo-quantization node in the third target operator is determined based on the weight information in the third target operator and the activation information.

[0095] Exemplarily, when the third target operator includes an operator including a weight, it is determined based on the weight information and the activation information whether the weight of the operator needs to be symmetrically quantized and the output of the operator needs to be asymmetrically quantized.

[0096] Exemplarily, when the third target operator includes an operator without a weight, it is determined based on the weight information and the activation information whether an output of the operator needs to be asymmetric quantized.

[0097] In an embodiment of the present application, after determining the third target operator into which the pseudo quantization node needs to be inserted, the target position for inserting the pseudo quantization node is determined based on the weight information and activation information in the third target operator, and the pseudo quantization node is inserted into the target position, thereby improving the accuracy of inserting the pseudo quantization node.

[0098] In some embodiments, optionally, before inserting the pseudo quantization node into the first network structure, the model training method further includes:

[0099] A pseudo quantization node is constructed according to the floating-point data of the third target operator, wherein the pseudo quantization node includes a maximum value and a minimum value of the floating-point data.

[0100] In this embodiment, the pseudo quantization node is used to count the maximum and minimum values ​​of the floating-point data flowing through the operator, so the maximum and minimum values ​​of the floating-point data of the third target operator can be determined according to the floating-point data of the third target operator. The maximum and minimum values ​​of the floating-point data are used as quantization parameters and inserted into the target position of the third target operator in the form of a pseudo quantization node. During the training process, the model can be quantized and compressed by the quantization parameters in the pseudo quantization node.

[0101] Exemplarily, the pseudo quantization node includes a maximum value f_max of the floating-point data and a minimum value f_min of the floating-point data in the third target operator.

[0102] In an embodiment of the present application, a corresponding pseudo-quantization node is constructed based on the third target operator, so that the pseudo-quantization node includes the maximum and minimum values ​​of the floating-point data in the third target operator. By inserting the pseudo-quantization node into the third target operator, the maximum and minimum values ​​of the floating-point data in the pseudo-quantization node are used to simulate the quantization results during training, and serve to train and generate the final speech recognition model, thereby improving the compression rate of the speech recognition model obtained by the final training.

[0103] In some embodiments, optionally, performing perceptual quantization training on the second network structure based on the pseudo-quantization node to obtain a speech recognition model includes:

[0104] Determine a target difference value according to the pseudo quantization node, where the target difference value is the difference between the maximum value of the floating-point data and the minimum value of the floating-point data;

[0105] Determine the scaling factor according to the target difference and the preset floating point number interval;

[0106] Determine a zero reference point according to the scaling factor, the maximum value of the floating-point data, and the maximum value of the fixed-point data, the maximum value of the fixed-point data corresponding to the maximum value of the floating-point data;

[0107] The second network structure is quantized and trained according to the scaling factor and the zero reference point to obtain a speech recognition model.

[0108] In this embodiment, during the perceptual quantization training of the second network structure, the scaling factor can be determined according to the maximum value of the floating-point data in the pseudo-quantization node and the minimum value of the floating-point data, and then the zero reference point of the quantization is determined based on the scaling factor. When the zero reference point is determined, the floating-point data in the second network structure can be mapped to the corresponding fixed-point data to complete the quantization training of the second network structure.

[0109] Specifically, model quantization is a model compression method that compresses model weight information and activation information from floating-point data to fixed-point data. It can reduce the resource overhead occupied by the model and improve the inference speed. During the quantization process, the following relationship (1) needs to be satisfied:

[0110] f_max-f_min=scale×(Z_f-Z_o); (1)

[0111] Among them, f_max is the maximum value of the floating-point data, f_min is the minimum value of the floating-point data, scale is the scaling factor, Z_f is the fixed-point data corresponding to the maximum value of the floating-point data, and Z_o is the zero reference point of the fixed-point data.

[0112] For example, taking int8 quantization as an example, the floating point numbers of fp32 in the model are compressed to the range of 0 to 255 under asymmetric quantization, or the floating point numbers of fp32 in the model are compressed to the range of -128 to 127 under symmetric quantization, and the scaling factor is determined by the following relationship (2):

[0113]

[0114] Among them, scale is the scaling factor, f max is the maximum value of floating point data, f min The minimum value of floating point data.

[0115] The zero reference point in the asymmetric quantization process is determined by the following relationship (3):

[0116]

[0117] Among them, Z0 is the zero reference point, round() is the rounding function, and Z max is the fixed-point data corresponding to the maximum value of the floating-point data, scale is the scaling factor, f max The maximum value of floating point data.

[0118] Exemplarily, in the process of symmetric quantization, the zero reference point of quantization is set to 0, and in the process of asymmetric quantization, the zero reference point is calculated by the above relational expression (3).

[0119] In an embodiment of the present application, in the process of quantizing the second network structure based on the pseudo-quantization node, the scaling factor can be determined based on the maximum and minimum values ​​of the floating-point data in the quantization node, and the corresponding zero reference point can be determined, so that the third target operator in the second network structure can be quantized according to the scaling factor and the zero reference point to train a speech recognition model.

[0120] In some embodiments, optionally, performing operator fusion processing on the first target operator in the second network structure includes:

[0121] Determine the multiplication-addition operator and the first fully connected operator in the second network structure according to the pseudo-quantization node;

[0122] Determining a multiplication parameter in a multiply-add operator, and a first weight and a first bias in a first fully connected operator;

[0123] The multiplication-addition operator and the first fully-connected operator in the second network structure are fused according to the multiplication parameter, the first weight and the first bias.

[0124] In this embodiment, the first target operator includes a multiplication-addition operator and a first fully connected operator, wherein the first fully connected operator is a fully connected operator adjacent to the multiplication-addition operator. In the process of fusing the multiplication-addition operator with the first fully connected operator, it is necessary to extract the multiplication parameter in the multiplication-addition operator, as well as the first weight and the first bias in the first fully connected layer, and perform linear algebra based on the multiplication parameter, the first weight and the first bias to complete the fusion of the multiplication operator with the first fully connected operator, wherein the fusion results in a new fully connected operator.

[0125] Figure 3 One of the operator fusion schematic diagrams provided in some embodiments of the present application is shown, such as Figure 3 As shown, the multiplication-addition operator 302 is fused with the first fully connected operator 304 to obtain a new fully connected operator 306 .

[0126] Exemplarily, the multiplication-addition operator is fused with the first fully connected operator by the following relation (4):

[0127] W2(W1x+b1)+b2=W1W2x+(W2b1+b2); (4)

[0128] Among them, W1 is the multiplication parameter of the multiply-add operator, b1 and b2 are the biases of the first fully connected operator, W2 is the weight of the first fully connected operator, and x is the input.

[0129] In the embodiment of the present application, by fusing the multiplication-addition operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0130] In some embodiments, optionally, performing operator fusion processing on the first target operator in the second network structure includes:

[0131] Determining an activation operator and a second fully connected operator in a second network structure, wherein the activation operator includes a pseudo-quantization node;

[0132] The activation operator and the second fully connected operator in the second network structure are fused.

[0133] In this embodiment, the first target operator includes an activation operator and a second fully connected operator, wherein the first fully connected operator is a fully connected operator adjacent to the activation operator, and the activation operator is fused with the first fully connected operator.

[0134] Figure 4 FIG. 2 shows a second schematic diagram of operator fusion provided in some embodiments of the present application, such as Figure 4 As shown, the activation operator 402 is fused with the second fully connected operator 404 to obtain a new fully connected operator 406 .

[0135] Exemplarily, the multiplication-addition operator is fused with the first fully connected operator by the following relation (5):

[0136]

[0137] Among them, round() is the rounding function, clip() is the truncation function, b is the bias of the first fully connected operator, w is the weight of the second fully connected operator, scale is the scaling factor, Z0 is the zero reference point, relu() is the activation function, and x is the input.

[0138] It should be noted that the activation operator uses asymmetric quantization, and the pseudo-quantization nodes that can use ReLU (linear rectification function) can be fused into the fully connected operator to generate a new quantized fully connected layer.

[0139] In the embodiment of the present application, by fusing the activation operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0140] In some embodiments, optionally, after performing perceptual quantization training on the second network structure based on pseudo-quantization nodes to obtain a speech recognition model, the model training method further includes: inputting audio features into the speech recognition model to obtain audio recognition results.

[0141] In an embodiment of the present application, a speech recognition model is obtained through training, the speech recognition model is configured in a household appliance, and after audio features are acquired, the audio features are input into the speech recognition model to obtain an audio recognition result.

[0142] The size of the speech recognition model is greatly reduced. The model size of the speech recognition model obtained by quantization training is reduced from the original 6.7M to 2.0M, and the model volume compression rate reaches 70%. It also greatly reduces the consumption of household appliance memory and improves the recognition accuracy of the model.

[0143] According to one embodiment of the present application, Figure 5 One of the schematic block diagrams of a model training device is shown in some embodiments of the present application, such as Figure 5 As shown, a model training device 500 is proposed, comprising:

[0144] A processing module 502 is used to insert a pseudo-quantization node into the first network structure to obtain a second network structure;

[0145] A processing module 502 is used to perform operator fusion processing on a first target operator in the second network structure, where the first target operator includes a pseudo quantization node;

[0146] The training module 504 is used to perform perceptual quantization training on the second network structure to obtain a speech recognition model.

[0147] In the embodiment of the present application, before the training starts, a pseudo-quantization node is inserted into the first network structure, and the first target operator including the pseudo-quantization node in the first network structure is fused to obtain a second network structure. By performing perceptual quantization training on the second network structure, the second network structure can be quantized and compressed during the training process, and the volume of the speech recognition model can be further reduced while ensuring the recognition accuracy of the speech recognition model obtained by training.

[0148] In some embodiments, optionally, the processing module 502 is used to determine a third target operator in the first network structure according to the second target operator, where the third target operator is an operator node in the first network structure except the second target operator;

[0149] A processing module 502 is used to insert a pseudo quantization node into the first network structure;

[0150] The second target operator includes at least one of the following: a mask operator and a position encoding operator.

[0151] In the embodiment of the present application, in the process of inserting the pseudo-quantization node, the second target operator that does not need to be quantized is first determined, and the third target operator in the first network structure is screened based on the second target operator, wherein the second target operator includes a mask operator and a position encoding operator. Inserting the pseudo-quantization node in the first network structure improves the accuracy of inserting the pseudo-quantization node, and further reduces the impact of inserting the pseudo-quantization node on the recognition accuracy of the entire model.

[0152] In some embodiments, optionally, the processing module 502 is configured to determine a target position in the third target operator based on weight information and activation information in the third target operator;

[0153] The processing module 502 is used to insert a pseudo quantization node into a target position.

[0154] In an embodiment of the present application, after determining the third target operator into which the pseudo quantization node needs to be inserted, the target position for inserting the pseudo quantization node is determined based on the weight information and activation information in the third target operator, and the pseudo quantization node is inserted into the target position, thereby improving the accuracy of inserting the pseudo quantization node.

[0155] In some embodiments, optionally, the processing module 502 is used to construct a pseudo quantization node according to the floating-point data of the third target operator, wherein the pseudo quantization node includes a maximum value and a minimum value of the floating-point data.

[0156] In an embodiment of the present application, a corresponding pseudo-quantization node is constructed based on the third target operator, so that the pseudo-quantization node includes the maximum and minimum values ​​of the floating-point data in the third target operator. By inserting the pseudo-quantization node into the third target operator, the maximum and minimum values ​​of the floating-point data in the pseudo-quantization node are used to simulate the quantization results during training, and serve to train and generate the final speech recognition model, thereby improving the compression rate of the speech recognition model obtained by the final training.

[0157] In some embodiments, optionally, the processing module 502 is configured to determine a target difference value according to the pseudo quantization node, where the target difference value is a difference between a maximum value of the floating-point data and a minimum value of the floating-point data;

[0158] A processing module 502 is used to determine a scaling factor according to a target difference and a preset floating point number interval;

[0159] A processing module 502, for determining a zero reference point according to a scaling factor, a maximum value of the floating-point data, and a maximum value of the fixed-point data, the maximum value of the fixed-point data corresponding to the maximum value of the floating-point data;

[0160] The processing module 502 is used to perform quantization training on the second network structure according to the scaling factor and the zero reference point to obtain a speech recognition model.

[0161] In an embodiment of the present application, in the process of quantizing the second network structure based on the pseudo-quantization node, the scaling factor can be determined based on the maximum and minimum values ​​of the floating-point data in the quantization node, and the corresponding zero reference point can be determined, so that the third target operator in the second network structure can be quantized according to the scaling factor and the zero reference point to train a speech recognition model.

[0162] In some embodiments, optionally, the processing module 502 is used to determine the multiplication-addition operator and the first fully connected operator in the second network structure;

[0163] A processing module 502 is used to determine a multiplication parameter in a multiplication-addition operator, and a first weight and a first bias in a first fully connected operator;

[0164] The processing module 502 is used to perform fusion processing on the multiplication-addition operator and the first fully connected operator in the second network structure according to the multiplication parameter, the first weight and the first bias.

[0165] In the embodiment of the present application, by fusing the multiplication-addition operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0166] In some embodiments, optionally, the processing module 502 is used to determine an activation operator and a second fully connected operator in the second network structure, wherein the activation operator includes a pseudo-quantization node;

[0167] The processing module 502 is used to perform fusion processing on the activation operator and the second fully connected operator in the second network structure.

[0168] In the embodiment of the present application, by fusing the activation operator with the first fully connected operator, a new quantized fully connected layer can be generated, thereby reducing the quantization error caused by the introduction of pseudo-quantization nodes through graph optimization.

[0169] In some embodiments, optionally, the processing module 502 is used to input audio features into a speech recognition model to obtain an audio recognition result.

[0170] In an embodiment of the present application, a speech recognition model is obtained through training, the speech recognition model is configured in a household appliance, and after audio features are acquired, the audio features are input into the speech recognition model to obtain an audio recognition result.

[0171] According to one embodiment of the present application, Figure 6 A second schematic block diagram of a model training device is shown in some embodiments of the present application. Figure 6 As shown, the model training device 600 includes a processor 602 and a memory 604. The memory 604 stores a program or instruction. When the program or instruction is executed by the processor 602, the steps of the model training method in any of the above embodiments are implemented. Therefore, the model training device 600 has all the beneficial effects of the model training method in any of the above embodiments, which will not be repeated here.

[0172] According to one embodiment of the present application, optionally, a readable storage medium is provided, on which a program or instruction is stored. When the program or instruction is executed by a processor, the model training method in any of the above embodiments is implemented, thereby having all the beneficial technical effects of the model training method in any of the above embodiments.

[0173] The readable storage medium includes a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0174] A computer readable storage medium may be a tangible device that can retain and store instructions for use by an instruction execution device. A computer readable storage medium may be an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the above devices, but is not limited thereto. A non-exhaustive list of more specific examples of computer readable storage media includes: portable computer floppy disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD), memory card, floppy disk, encoding mechanical device (such as a punch card or a groove with a raised structure with instructions recorded) and any suitable combination of the above devices. The computer readable storage medium used herein should not be understood as a transmission signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium, or an electrical signal transmitted through a wire, etc.

[0175] Figure 7 A schematic block diagram of an electronic device provided in some embodiments of the present application is shown. Figure 7 As shown, according to one embodiment of the present application, optionally, an electronic device 700 is provided, including: a model training device 500 as in any of the above embodiments, and / or a readable storage medium 702 as in any of the above embodiments, and thus has all the beneficial technical effects of the model training device 500 in any of the above embodiments, and / or the readable storage medium 702 in any of the above embodiments, and no further details will be given here.

[0176] It should be clarified that in the claims, specification and drawings of the present application, the term "multiple" refers to two or more than two. Unless otherwise clearly defined, the orientation or position relationship indicated by the terms "upper" and "lower" is based on the orientation or position relationship shown in the drawings, which is only for the purpose of more conveniently describing the present application and making the description process easier, rather than indicating or implying that the device or element referred to must have the specific orientation described, be constructed and operated in a specific orientation, so these descriptions cannot be understood as limitations on the present application; the terms "connect", "install", "fix" and the like should be understood in a broad sense. For example, "connection" can be a fixed connection between multiple objects, or a detachable connection between multiple objects, or an integral connection; it can be a direct connection between multiple objects, or an indirect connection between multiple objects through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood based on the specific circumstances of the above data.

[0177] In the claims, specification and drawings of the present application, the description of the terms "one embodiment", "some embodiments", "specific embodiments" and the like means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In the claims, specification and drawings of the present application, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0178] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A model training method, characterized in that: include: Inserting a pseudo-quantization node into the first network structure to obtain a second network structure; Performing operator fusion processing on a first target operator in the second network structure, where the first target operator includes the pseudo quantization node; Based on the pseudo-quantization nodes, perceptual quantization training is performed on the second network structure to obtain a speech recognition model.

2. The model training method according to claim 1, characterized in that: Inserting a pseudo-quantization node into the first network structure to obtain a second network structure includes: Determine a third target operator in the first network structure according to the second target operator, where the third target operator is an operator node in the first network structure except the second target operator; inserting the pseudo quantization node into the third target operator; The second target operator includes at least one of the following: a mask operator and a position encoding operator.

3. The model training method according to claim 2, characterized in that: The inserting of a pseudo-quantization node into the first network structure comprises: Determining a target position in the third target operator based on the weight information and the activation information in the third target operator; The pseudo quantization node is inserted into the target position.

4. The model training method according to claim 2, characterized in that: Before inserting the pseudo-quantization node into the first network structure, the model training method further includes: The pseudo quantization node is constructed according to the floating-point data of the third target operator, wherein the pseudo quantization node includes a maximum value in the floating-point data and a minimum value in the floating-point data.

5. The model training method according to claim 4, characterized in that: The performing perceptual quantization training on the second network structure based on the pseudo quantization node to obtain a speech recognition model includes: Determine a target difference value according to the pseudo quantization node, wherein the target difference value is a difference between a maximum value of the floating-point data and a minimum value of the floating-point data; Determining a scaling factor according to the target difference and a preset floating point number interval; determining a zero reference point according to the scaling factor, a maximum value of the floating-point data, and a maximum value of the fixed-point data, the maximum value of the fixed-point data corresponding to the maximum value of the floating-point data; The second network structure is quantized and trained according to the scaling factor and the zero reference point to obtain a speech recognition model.

6. The model training method according to any one of claims 1 to 3, characterized in that: The performing operator fusion processing on the first target operator in the second network structure includes: Determine a multiplication-addition operator and a first fully connected operator in the second network structure; Determining a multiplication parameter in the multiply-add operator, and a first weight and a first bias in the first fully connected operator; The multiplication-addition operator and the first fully-connected operator in the second network structure are fused according to the multiplication parameter, the first weight and the first bias.

7. The model training method according to any one of claims 1 to 3, characterized in that: The performing operator fusion processing on the first target operator in the second network structure includes: Determining an activation operator and a second fully connected operator in the second network structure, wherein the activation operator includes the pseudo quantization node; The activation operator and the second fully connected operator in the second network structure are fused.

8. The model training method according to any one of claims 1 to 3, characterized in that: After performing perceptual quantization training on the second network structure based on the pseudo quantization node to obtain a speech recognition model, the model training method further includes: The audio features are input into the speech recognition model to obtain an audio recognition result.

9. A model training device, characterized in that: include: A processing module, used for inserting pseudo-quantization nodes into the first network structure to obtain a second network structure; The processing module is used to perform operator fusion processing on the first target operator in the second network structure, where the first target operator includes the pseudo quantization node; The training module is used to perform perceptual quantization training on the second network structure to obtain a speech recognition model.

10. A model training device, characterized in that: include: processor; A memory, wherein a program or instruction is stored in the memory, and the processor implements the steps of the model training method as described in any one of claims 1 to 8 when executing the program or instruction in the memory.

11. A readable storage medium, characterized in that: The readable storage medium stores programs or instructions, and when the programs or instructions are executed by the processor, the steps of the model training method as described in any one of claims 1 to 8 are implemented.

12. An electronic device, characterized in that: include: The model training device as claimed in claim 9 or 10; and / or The readable storage medium as claimed in claim 11.

Citation Information

Cited By

  • Model optimization method, service processing method, server and terminal equipment

    CN119272822A

  • Quantitative perception training method and device of neural network model, electronic equipment and storage medium

    CN121119003A

  • Quantization-aware training method and device of neural network model, electronic equipment and storage medium

    CN121119003B