A model training method, system, storage medium and terminal device

By using a smooth pseudo-quantization function in model training, the problem of unstable model quantization training is solved, and high-precision model application is achieved on low-computing power devices.

CN115563203BActive Publication Date: 2025-09-12TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110747436.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-02
Publication Date
2025-09-12
Estimated Expiration
2041-07-02

AI Technical Summary

Technical Problem

Existing model quantization technology causes unstable model training during training and fails to understand the rules of pseudo-quantization operators, resulting in the model being sensitive to quantization loss and severe accuracy loss.

Method used

A smooth pseudo-quantization function is used for quantization-aware training, and the parameter values ​​of the feature operation layer are adjusted by calculating the gradient of the loss function to ensure the differentiability of the loss function and the accuracy of the gradient.

Benefits of technology

It improves the stability and accuracy of model training, reduces quantization loss, and improves the application effect of the model on low-computing power devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115563203B_ABST
    Figure CN115563203B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a model training method, system, storage medium and terminal device, which are applied to the field of information processing technology based on artificial intelligence. The model training system determines that the initial training model includes a feature operation layer and a pseudo-quantization operator connected to its output and determines the training sample. In this way, during the backward propagation process of the model training, the loss function is calculated according to the calculated value of the pseudo-quantization operation, the first parameter to be learned in the feature operation layer and the annotation information in the training sample, and the first parameter to be learned is adjusted according to the gradient of the loss function. Since the process of calculating the gradient of the loss function is the process of deriving the loss function, and the calculated value of the pseudo-quantization operation involved in calculating the loss function is smooth as the curve of the feature information output by the feature operation layer is smooth, thereby ensuring the accuracy of the gradient calculation of the loss function, ensuring that the gradient of the loss function can be normally propagated, and thus ensuring the stability of the model training.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information processing technology based on artificial intelligence, and in particular to a model training method, system, storage medium and terminal device. Background Art

[0002] As deep learning models are applied in various fields, their size is also increasing as the evaluation metrics in each application continue to rise. This makes it difficult to deploy these models on devices with low computing power and limited resources, such as edge devices. Model quantization technology allows models to run on various devices in a low-bit manner. Most existing devices use hardware chips that support processing low-bit instructions, which can improve model inference speed while reducing memory usage, battery consumption, and device heat generation. Based on these advantages, model quantization technology is widely used and is a critical technology when deploying deep learning models on resource-limited devices.

[0003] While model quantization offers numerous advantages, it can also lead to precision loss and performance degradation. Designing a model quantization solution to minimize precision loss is a key research topic. Currently, existing solutions are based on quantization-aware training models, employing pseudo-quantization operators during training and using a straight-through estimator (STE) to calculate the gradients corresponding to these operators during backpropagation.

[0004] The quantization-aware training process of a model actually treats the pseudo-quantization operator as a regular perturbation of the feature map, which is a regularization operation. However, the existing mechanism for calculating gradients through the STE method makes it impossible to understand the regularity of the pseudo-quantization operator during model training. As a result, random perturbations are fitted during model training, making model training more difficult and causing the model to be more sensitive to quantization loss after training. Summary of the Invention

[0005] The embodiments of the present invention provide a model training method, system, storage medium and terminal device, which realize quantization perception training using a smooth pseudo-quantization function.

[0006] An embodiment of the present invention provides a model training method, including:

[0007] Determining an initial training model and a training sample, wherein the initial training model includes multiple feature operation layers, the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training sample includes sample labeling information;

[0008] Calculating a loss function associated with the initial training model, the loss function including a calculation formula between the labeling information of the sample, a first parameter to be learned in the feature operation layer, and a calculated value of the pseudo quantization operation, wherein a curve of the calculated value of the pseudo quantization operation changing smoothly with the feature information output by the feature operation layer;

[0009] Calculating the gradient of the loss function;

[0010] The parameter value of the first parameter to be learned in the feature operation layer is adjusted according to the gradient of the loss function to obtain a final training model.

[0011] Another embodiment of the present invention provides a model training system, including:

[0012] A training determination unit, configured to determine an initial training model and training samples, wherein the initial training model includes a plurality of feature operation layers, the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is configured to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training samples include sample labeling information;

[0013] a loss function unit, configured to calculate a loss function associated with the initial training model, wherein the loss function includes a calculation formula between the labeling information of the sample, a first parameter to be learned in the feature operation layer, and a calculated value of the pseudo-quantization operation, wherein a curve of the calculated value of the pseudo-quantization operation changing smoothly with the feature information output by the feature operation layer;

[0014] A gradient calculation unit, used to calculate the gradient of the loss function;

[0015] An adjustment unit is used to adjust the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain a final training model.

[0016] On the other hand, an embodiment of the present invention further provides a computer-readable storage medium, which stores multiple computer programs, and the computer programs are suitable for being loaded by a processor and executing the model training method as described in one aspect of an embodiment of the present invention.

[0017] Another aspect of the present invention provides a terminal device, including a processor and a memory;

[0018] The memory is used to store multiple computer programs, and the computer programs are used to be loaded by the processor and execute the model training method as described in one aspect of an embodiment of the present invention; the processor is used to implement each computer program in the multiple computer programs.

[0019] It can be seen that in the method of this embodiment, when the model training system adopts the quantization-aware training method to train the model, it will determine that the initial training model includes the feature operation layer and the pseudo-quantization operator connected to its output and determine the training samples. In this way, during the backward propagation process of the model training, the loss function is calculated based on the calculated value of the pseudo-quantization operation, the first parameter to be learned in the feature operation layer and the annotation information in the training sample, and the first parameter to be learned is adjusted according to the gradient of the loss function. Since the process of calculating the gradient of the loss function is the process of deriving the loss function, and the calculated value of the pseudo-quantization operation involved in calculating the loss function is a smooth curve with the change of the feature information output by the feature operation layer, the loss function is differentiable, thereby ensuring the accuracy of the gradient calculation of the loss function, ensuring that the gradient of the loss function can be normally propagated, and thus ensuring the stability of the model training. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0021] Figure 1 is a schematic diagram of a model training method provided by an embodiment of the present invention;

[0022] Figure 2 This is a flow chart of a model training method provided by one embodiment of the present invention;

[0023] Figure 3 is a schematic structural diagram of an initial training model in one embodiment of the present invention;

[0024] Figure 4a is a schematic diagram of a pseudo quantization function in one embodiment of the present invention;

[0025] Figure 4b is a schematic diagram of various pseudo-quantization functions in one embodiment of the present invention;

[0026] Figure 5 This is a flow chart of a model training method provided by an application embodiment of the present invention;

[0027] Figure 6 is a schematic diagram of a distributed system to which a model training method in another application embodiment of the present invention is applied;

[0028] Figure 7 is a schematic diagram of a block structure in another application embodiment of the present invention;

[0029] Figure 8This is a schematic diagram of the logical structure of a model training system provided by an embodiment of the present invention;

[0030] Figure 9 This is a schematic diagram of the logical structure of a terminal device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0032] The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the invention described herein can, for example, be implemented in orders other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or apparatus.

[0033] The embodiment of the present invention provides a model training method, which mainly uses a quantization-aware training method to train the model by a model training system, so that the trained model can be applied to projects or products that require image processing through neural networks in mobile devices such as video image editing applications, short video applications, and video calls. It can also be used in projects or products in other fields such as voice and text that require model quantization. Specifically, Figure 1 As shown, the model training system can implement model training using the following steps:

[0034] Determine an initial training model and a training sample, wherein the initial training model includes multiple feature operation layers, and the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training sample includes the labeling information of the sample; calculate a loss function related to the initial training model, wherein the loss function includes a calculation formula between the labeling information of the sample, the first parameter to be learned in the feature operation layer, and the calculated value of the pseudo-quantization operation, and the calculated value of the pseudo-quantization operation has a smooth curve along with the change of the feature information output by the feature operation layer; calculate the gradient of the loss function; and adjust the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain a final training model.

[0035] The training model described above is a machine learning model based on artificial intelligence (AI). Artificial intelligence (AI) refers to the theories, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI is the study of the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.

[0036] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, and machine learning / deep learning.

[0037] Machine learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning.

[0038] In this way, since the process of calculating the gradient of the loss function is the process of deriving the loss function, and the calculated value of the pseudo-quantization operation involved in calculating the loss function has a smooth curve as the feature information output by the feature operation layer changes, the loss function is differentiable, thereby ensuring the accuracy of the gradient calculation of the loss function, ensuring that the gradient of the loss function can be propagated normally, and thus ensuring the stability of the model training.

[0039] The embodiment of the present invention provides a model training method, which is mainly a method performed by the above-mentioned model training system. The flow chart is as follows: Figure 2 Shown, including:

[0040] Step 101, determine the initial training model and the training samples. The initial training model includes multiple feature operation layers. The output of each feature operation layer is connected to a pseudo-quantization operator. The pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer. The training samples include multiple samples and labeling information of each sample.

[0041] It is understood that when determining the initial training model, the model training system can determine the initial values ​​of the first parameters to be learned in the multi-layer structure and each layer of the structure included in the initial training model. The first parameters to be learned refer to fixed parameters used in the calculation process of each layer of the structure in the initial training model that do not need to be assigned values ​​at any time, such as parameter scale, number of network layers, user vector length, weight value, etc.

[0042] Specifically, if Figure 3 As shown, the initial training model can include a feature extraction module for extracting feature information from input data, and a business operation module for performing specific business operations based on the feature information extracted by the feature extraction module. The specific business operations performed by the business operation module are primarily determined by the specific application scenario of the trained model, which also determines the input data of the feature extraction module and the annotation information of each sample in the training sample.

[0043] For example, if a trained model is used to determine user attributes based on user voice data, the input data for the feature extraction module is the user voice data, the service operation module is used to classify user attributes based on the feature information of the user voice data, and the training samples include the voice samples and their corresponding user attribute annotations. For another example, if a trained model is used to detect specific targets in an image, the input data for the feature extraction module is the image to be detected, the service operation module is used to detect the location information of the specific target based on the feature information of the image to be detected, and the training samples include the sample image and the location annotation information of the specific target contained therein.

[0044] In this embodiment, quantization-aware training is mainly used for model training, which mainly introduces a pseudo-quantization operator so that the training can simulate the quantization process with floating points, and the training process can make the neural network more robust to quantization loss. Specifically, the feature extraction module in the determined initial training model can specifically include: multiple (n is used as an example in the figure) feature operation layers, the output of each feature operation layer is connected to the pseudo-quantization operator, and the feature operation layer ranked first in the feature extraction module is also connected to the pseudo-quantization operator, so that each feature operation layer is connected to the front and back of the pseudo-quantization operator. Among them, the feature operation layer is used to perform certain operations on feature information, such as convolution operations or pooling operations; the pseudo-quantization operations of the pseudo-quantization operator mainly include quantization operations and inverse quantization operations, which simulate the process of quantization loss so that the model can perceive that the quantization operation is to quantize the input floating-point feature value to obtain the quantization value, and the inverse quantization operation is the inverse process of the quantization operation, which is mainly to calculate the input quantization value to obtain the corresponding floating-point feature value.

[0045] Step 102, calculate the loss function related to the initial training model, the loss function includes the labeling information of the sample, the calculation formula between the first parameter to be learned in the feature operation layer and the calculated value of the pseudo-quantization operation, and the calculated value of the pseudo-quantization operation changes smoothly with the characteristic information output by the feature operation layer (that is, the input data of the pseudo-quantization operator).

[0046] Specifically, the model training system will calculate a loss function related to the initial training model based on the result information obtained after the initial training model processes each sample and the labeling information of the corresponding sample in the training sample. This loss function is used to indicate the error between the result information obtained by the initial training model and the actual information of each sample (obtained based on the labeling information), such as the cross-entropy loss function. The model training process is to minimize the value of the above error. This training process continuously optimizes the parameter value of the first parameter to be learned in the initial training model determined in step 101 above through a series of mathematical optimization methods such as backpropagation derivation and gradient descent, and minimizes the calculated value of the above loss function.

[0047] Among them, the result information obtained after the initial training model processes the sample is mainly the information obtained after processing the sample according to the above-mentioned structure (including the feature extraction module and the business operation module). In this way, when calculating the loss function, it mainly includes the labeling information of the sample, the first parameter to be learned in the feature operation layer, and the calculation formula between the calculated value of the pseudo-quantization operation. For example, the loss function can be: the result information of the sample processed by the initial training model obtained based on the first parameter to be learned in the feature operation layer and the calculated value of the pseudo-quantization operation, and the square of the difference between the result information and the labeling information of the corresponding sample, and the calculated value of the pseudo-quantization operation is calculated based on the feature information output by the feature operation layer (that is, the input data of the pseudo-quantization operator) and the S-type function.

[0048] Here, the S-type function is a function relationship whose shape is similar to S, such as tanh, 2*sigmoid-1 and Any function whose value range is in the range [-1,1].

[0049] In this way, through the S-shaped function, the calculated value of the pseudo-quantization operation can be made smooth and differentiable as its input (i.e., the feature information output by the feature operation layer) changes. The function corresponding to this curve can be called a pseudo-quantization function, which is suitable for the derivation algorithm when calculating the gradient of the loss function. For example, Figure 4a The smooth curve 2 shown is differentiable, while the curve 1 in the figure is not differentiable.

[0050] In a specific embodiment, when the model training system obtains the calculated value of the pseudo-quantization operation based on the feature information output by the feature operation layer and the S-type function, it can first calculate a first calculated value based on the feature information output by the feature operation layer, use the first calculated value as the input value of the S-type function, and obtain the S-type function value. Then, based on the S-type function value, the quantization range of the input value of the pseudo-quantization operation and the quantization parameters involved in the pseudo-quantization operation, the calculated value of the pseudo-quantization operation is obtained.

[0051] In which, when calculating the first calculated value, the first calculated value can be calculated based on the feature information output by the feature operation layer and the deformation weight value λ of the pseudo-quantization operator. In this way, in the process of adjusting the first parameter to be learned later, the deformation weight value λ can be adjusted. In the process of changing the deformation weight value λ, the calculated value of the pseudo-quantization operation changes with the change curve of the input data of the pseudo-quantization operation (that is, the feature information output by the above-mentioned feature operation layer) between the pseudo-quantization step function and the authentication (Identity) function. By adjusting the deformation weight value λ, the deformation weight value λ that is most suitable for the pseudo-quantization operator can be learned, and the deformation weight value corresponding to the pseudo-quantization operator connected to the output of each feature operation layer can be different.

[0052] For example Figure 4bAs shown, curve 1 is the function curve of the pseudo-quantization step function, curve 2 is the curve of the calculated value of the pseudo-quantization operation in this embodiment changing with the input of the pseudo-quantization operation when the deformation weight value λ is 0.0001, and curve 3 is the curve of the calculated value of the pseudo-quantization operation in this embodiment changing with the input of the pseudo-quantization operation when the deformation weight value λ is 0.01. It can be seen that the larger the deformation weight value λ is, the closer the change curve of the calculated value of the pseudo-quantization operation is to the Identity function, that is, the function y=x, and the smaller the deformation weight value λ is, the closer the change curve of the calculated value of the pseudo-quantization operation is to the pseudo-quantization step function.

[0053] Step 103: Calculate the gradient of the loss function.

[0054] Specifically, the gradient of the loss function is used to represent the amount of change in the loss function. Specifically, the gradient of the loss function can be obtained by derivatizing the loss function with respect to the first parameter to be learned.

[0055] Step 104: Adjust the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain the final training model.

[0056] Specifically, the model training system replaces the parameter value of the first parameter to be learned with the difference between the current parameter value of the first parameter to be learned and the product of the gradient of the loss function, where the product of the gradient of the loss function is the product of the step size and the gradient of the loss function. Furthermore, the model training system may also adjust the deformation weight value λ involved in calculating the first calculated value based on the gradient of the loss function.

[0057] It should be noted that the above steps 101 to 104 are an adjustment of the parameter value of the first parameter to be learned in the initial training model by the result information obtained by processing each sample by the initial training model. In actual applications, it is necessary to continuously loop through the above steps 102 to 104 until the adjustment of the parameter value meets a certain stopping condition.

[0058] Therefore, after executing steps 101 to 104 of the above embodiment, the model training system needs to determine whether the current adjustment of the parameter value meets the preset stop condition. If so, the process ends; if not, the system returns to execute steps 102 to 104 for the initial training model after adjusting the parameter value. The preset stop condition includes, but is not limited to, any one of the following conditions: the difference between the parameter value of the first parameter to be learned currently adjusted and the parameter value last adjusted is less than a threshold, that is, the adjusted parameter value reaches convergence, and the calculated loss function also reaches a minimum value; and the number of parameter value adjustments is equal to the preset number, etc.

[0059] It can be seen that in the method of this embodiment, when the model training system adopts the quantization-aware training method to train the model, it will determine that the initial training model includes the feature operation layer and the pseudo-quantization operator connected to its output and determine the training samples. In this way, during the backward propagation process of the model training, the loss function is calculated based on the calculated value of the pseudo-quantization operation, the first parameter to be learned in the feature operation layer and the annotation information in the training sample, and the first parameter to be learned is adjusted according to the gradient of the loss function. Since the process of calculating the gradient of the loss function is the process of deriving the loss function, and the calculated value of the pseudo-quantization operation involved in calculating the loss function is a smooth curve with the change of the feature information output by the feature operation layer, the loss function is differentiable, thereby ensuring the accuracy of the gradient calculation of the loss function, ensuring that the gradient of the loss function can be normally propagated, and thus ensuring the stability of the model training.

[0060] The following is a specific application example to illustrate the model training method of the present invention. In this embodiment, the trained model is applied to image detection as an example. Figure 5 As shown, the model training method in this embodiment includes the following steps:

[0061] Step 201: Determine the initial training model and the training samples.

[0062] The structure of the initial training model determined in this embodiment can be as described above. Figure 3 As shown, specifically, the feature extraction module in the initial training model is used to extract feature information of the input image, and the business operation module is used to perform image detection based on the feature information of the input image, and the initial value of the first parameter to be learned in each feature operation layer in the feature extraction module is set; the determined training samples include multiple sample images and detection annotation information of each sample image. Among them, the quantization operation and dequantization operation in the pseudo-quantization operator included in the feature extraction module can be expressed by the following formulas 1 and 2 respectively:

[0063]

[0064] X F =(X Q -zero_point,qmin)*scale (2)

[0065] Among them, X Q is the output of the pseudo-quantization operator, X Fis the floating-point input of the pseudo-quantization operator. scale and zero_point are the quantization parameters of the pseudo-quantization operator, representing the step size and quantization value respectively. The input x of the pseudo-quantization operator ranges from [min_val, max_val], and the quantization range of the pseudo-quantization operation on the input value is [qmin, qmax]. If the quantization operation and the inverse quantization operation are symmetric quantization, the quantization parameter can be expressed by the following formula 3. If the quantization operation and the inverse quantization operation are asymmetric quantization, the quantization parameter can be expressed by the following formula 4:

[0066]

[0067]

[0068] Step 202 : Calculate a loss function related to the initial training model based on the current parameter value of the first parameter to be learned contained in each feature operation layer in the feature extraction module of the initial training model.

[0069] Specifically, when calculating the loss function, the following can be included:

[0070] (1) Calculate the calculated value of the pseudo-quantization operation

[0071] Specifically, the first calculated value of the feature information x output by the feature operation layer is first calculated, and the first calculated value is used as the input value of the S-type function to obtain the S-type function value phi, as shown in the following formula 5; then, according to the S-type function value, the quantization range of the input value of the pseudo quantization operation (i.e., [qmin, qmax]) and the quantization parameters scale and zero_point involved in the pseudo quantization operation, the calculated value X of the pseudo quantization operation is obtained. Fq , which can be specifically expressed as the following formula 6:

[0072] phi=A*STYPE(B*(xm)) (5)

[0073] X Fq =scale*clamp(idx+(SIGN(phi)+1)*0.5+qmin,qmin-zero_point,qmax-zero_point) (6)

[0075] Wherein, STYPE can be any S-type function with a value range in the range of [-1, 1], B*(xm) is the first calculated value based on the feature information output by the feature operation layer, wherein A, B and m can be expressed by the following formulas 7 and 8 respectively, and SIGN can be expressed by the following formula 9:

[0076]

[0077] m=min_val+idx*scale (8)

[0078]

[0079] It can be seen that the deformation weight value λ of the pseudo quantization operator is involved in the calculation of the first calculated value B*(xm), and the idx involved can be expressed by the following formula 10:

[0080]

[0081] (2) Calculating detection result information of each sample image by the initial training model based on the first parameter to be learned in the feature operation layer and the calculated value of the pseudo-quantization operation.

[0082] (3) Calculate the loss function

[0083] Specifically, the loss function may include the square of the difference between the detection result information of each sample image calculated above and the detection annotation information of the corresponding sample image.

[0084] Step 203 , calculating the gradient of the loss function: the gradient of the loss function can be obtained by taking the derivative of the loss function with respect to the first parameter to be learned.

[0085] Step 204, adjust the parameter value of the first parameter to be learned in the feature operation layer, and adjust the deformation weight value λ of the pseudo quantization operator used in calculating the calculated value of the pseudo quantization operation. Specifically, the parameter value of the first parameter to be learned can be replaced by: the current parameter value of the first parameter to be learned minus the difference obtained by multiplying the gradient based on the loss function, and the product based on the gradient of the loss function is the product of the step size and the gradient of the loss function.

[0086] Step 205, determine whether the adjustment of the parameter value of the first parameter to be learned meets the preset stop condition. If so, end the process, and the parameter value of the first parameter to be learned included in the feature operation layer in the trained model is the parameter value of the first parameter to be learned adjusted in the above step 204; if not, return to execute step 202 for the adjusted parameter value of the first parameter to be learned.

[0087] In the specific practice, the jitter and normalized mean error (NME) of the model trained by the method of this embodiment are compared with the model trained by the existing STE method, as shown in Table 1 below. It can be seen that the stability of the model trained by the method of this embodiment is relatively high, and the NME of the accuracy is reduced. In general, the model trained by the method of this embodiment is better:

[0088] Training methods Jitter Precision NME Existing STE 32.44 0.04275 The training method in this embodiment 30.78 0.0427

[0089] Table 1

[0090] As can be seen, in this embodiment, when training the model using the quantization-aware training method, a differentiable sigmoid function is used to calculate the loss function during the model's backward propagation, ensuring the accuracy of the loss function's gradient calculation, thereby making the trained model relatively stable. In actual experiments, the model trained using the method of the present invention achieved certain accuracy improvements in tasks such as image classification and keypoint regression.

[0091] The following is another specific application example to illustrate the model training method in the present invention. The model training system in the embodiment of the present invention is mainly a distributed system 100, which may include a client 300 and multiple nodes 200 (any form of computing device in the access network, such as a server, a user terminal), and the client 300 and the node 200 are connected through network communication.

[0092] Taking the distributed system as the blockchain system as an example, see Figure 6 This is a schematic diagram of an optional architecture for a distributed system 100 provided in an embodiment of the present invention, applied to a blockchain system. The system consists of multiple nodes 200 (any type of computing device connected to a network, such as a server or user terminal) and clients 300. The nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol that runs on top of the Transmission Control Protocol (TCP). In a distributed system, any machine, such as a server or terminal, can join and become a node. Nodes include hardware, middleware, operating system, and application layers.

[0093] See also Figure 6 The functions of each node in the blockchain system shown include:

[0094] 1) Routing: A basic function of a node, used to support communication between nodes.

[0095] In addition to the routing function, nodes can also have the following functions:

[0096] 2) Applications, deployed in the blockchain, implement specific services based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.

[0097] For example, the business implemented by the application includes code that implements the model training function, which mainly includes:

[0098] Determine an initial training model and a training sample, wherein the initial training model includes multiple feature operation layers, and the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training sample includes the labeling information of the sample; calculate a loss function related to the initial training model, wherein the loss function includes a calculation formula between the labeling information of the sample, the first parameter to be learned in the feature operation layer, and the calculated value of the pseudo-quantization operation, and the calculated value of the pseudo-quantization operation has a smooth curve along with the change of the feature information output by the feature operation layer; calculate the gradient of the loss function; and adjust the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain a final training model.

[0099] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.

[0100] See also Figure 7 This is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction records stored in the block (the hash value of the current block) and the hash value of the previous block. The blocks are connected by hash values ​​to form a blockchain. In addition, the block may also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a series of data blocks generated using cryptographic methods. Each data block contains relevant information used to verify the validity of the information (anti-counterfeiting) and generate the next block.

[0101] The embodiment of the present invention also provides a model training system, the structural diagram of which is shown as follows: Figure 8 Specifically, it may include:

[0102] The training determination unit 10 is used to determine the initial training model and determine the training samples. The initial training model includes multiple feature operation layers. The output of each feature operation layer is connected to a pseudo-quantization operator. The pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer. The training samples include sample labeling information.

[0103] The loss function unit 11 is used to calculate the loss function related to the initial training model determined by the training determination unit 10, wherein the loss function includes the labeling information of the sample, the calculation formula between the first parameter to be learned in the feature operation layer and the calculated value of the pseudo-quantization operation, and the calculated value of the pseudo-quantization operation has a smooth curve as the feature information output by the feature operation layer changes.

[0104] The loss function unit 11 is configured to calculate a first calculated value based on the feature information output by the feature operation layer when the calculated value of the pseudo quantization operation is obtained by calculating the feature information output by the feature operation layer and the sigmoid function; use the first calculated value as an input value of the sigmoid function to obtain a sigmoid function value; and obtain the calculated value of the pseudo quantization operation based on the sigmoid function value, a quantization range of the input value of the pseudo quantization operation, and a quantization parameter involved in the pseudo quantization operation. When calculating the first calculated value, the first calculated value is calculated based on the feature information output by the feature operation layer and a deformation weight value of the pseudo quantization operator.

[0105] The gradient calculation unit 12 is used to calculate the gradient of the loss function calculated by the loss function unit 11.

[0106] The adjustment unit 13 is used to adjust the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function calculated by the gradient calculation unit 12 to obtain the final training model.

[0107] The above-mentioned gradient calculation unit 12 is specifically used to use the loss function to derive the first parameter to be learned to obtain the gradient of the loss function; the adjustment unit 13 is specifically used to replace the parameter value of the first parameter to be learned with: the current parameter value of the first parameter to be learned minus the difference obtained by multiplying the product of the gradient based on the loss function, and the product of the gradient based on the loss function is the product of the step size and the gradient of the loss function.

[0108] The adjusting unit 13 is further configured to adjust the deformation weight value of the pseudo quantization operator according to the gradient of the loss function.

[0109] Furthermore, the model training system may also include: an adjustment determination unit 14, which is used to notify the adjustment unit 13 to stop adjusting the parameter value when the number of adjustments to the parameter value of the first parameter to be learned is equal to a preset number, or if the difference between the currently adjusted parameter value and the last adjusted parameter value is less than a threshold value; otherwise, it notifies the loss function unit 11 to recalculate the loss function based on the adjusted parameter value of the first parameter to be learned.

[0110] In the system of this embodiment, since the process of calculating the gradient of the loss function by the gradient calculation unit 12 is the process of deriving the loss function, and the calculated value of the pseudo-quantization operation involved in calculating the loss function by the loss function unit 11 is smooth as the curve of the change of the feature information output by the feature operation layer, the loss function is differentiable, thereby ensuring the accuracy of the gradient calculation of the loss function, ensuring that the gradient of the loss function can be propagated normally, and thus ensuring the stability of the model training.

[0111] The embodiment of the present invention further provides a terminal device, the structural diagram of which is shown in FIG. Figure 9 As shown, the terminal device may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 20 (for example, one or more processors) and memory 21, and one or more storage media 22 (for example, one or more mass storage devices) storing application programs 221 or data 222. Memory 21 and storage medium 22 may be temporary storage or permanent storage. The program stored in storage medium 22 may include one or more modules (not shown), each module may include a series of instruction operations in the terminal device. Furthermore, the CPU 20 may be configured to communicate with the storage medium 22 to execute a series of instruction operations in the storage medium 22 on the terminal device.

[0112] Specifically, the application 221 stored in the storage medium 22 includes an application for model training, and the program may include the training determination unit 10, the loss function unit 11, the gradient calculation unit 12, the adjustment unit 13, and the adjustment determination unit 14 in the above-mentioned model training system, which are not described in detail here. Furthermore, the central processing unit 20 can be configured to communicate with the storage medium 22 and execute a series of operations corresponding to the application for model training stored in the storage medium 22 on the terminal device.

[0113] The terminal device may also include one or more power supplies 23, one or more wired or wireless network interfaces 24, one or more input and output interfaces 25, and / or one or more operating systems 223, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.

[0114] The steps performed by the above model training system in the above method embodiment can be based on the Figure 9 The structure of the terminal device shown.

[0115] On the other hand, an embodiment of the present invention further provides a computer-readable storage medium, which stores multiple computer programs, and the computer programs are suitable for being loaded by a processor and executing the model training method performed by the above-mentioned model training system.

[0116] Another aspect of the present invention provides a terminal device, including a processor and a memory;

[0117] The memory is used to store multiple computer programs, and the computer programs are used to be loaded by the processor and execute the model training method as performed by the above-mentioned model training system; the processor is used to implement each computer program in the multiple computer programs.

[0118] Furthermore, according to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the model training methods provided in the various optional implementations described above.

[0119] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc.

[0120] The above is a detailed introduction to a model training method, system, storage medium and terminal device provided in an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for those skilled in the art, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A model training method, characterized in that: include: Determining an initial training model and a training sample, wherein the initial training model includes multiple feature operation layers, the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is used to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training sample includes sample labeling information; Calculating a loss function associated with the initial training model, the loss function including a calculation formula between the labeling information of the sample, a first parameter to be learned in the feature operation layer, and a calculated value of the pseudo-quantization operation, wherein a curve of the calculated value of the pseudo-quantization operation changing smoothly with the feature information output by the feature operation layer; wherein the calculated value of the pseudo-quantization operation is obtained by: calculating a first calculated value based on the feature information output by the feature operation layer; using the first calculated value as an input value of a sigmoid function to obtain a sigmoid function value; and obtaining the calculated value of the pseudo-quantization operation based on the sigmoid function value, a quantization range of the input value of the pseudo-quantization operation, and a quantization parameter involved in the pseudo-quantization operation; Calculating the gradient of the loss function; Adjusting the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain a final training model; When the training model is used to determine user attributes based on user voice data, the training sample includes a voice sample and its corresponding user attribute label; the feature extraction module of the training model extracts feature information of the input user voice data, and the service operation module of the training model is used to classify the user attributes based on the feature information of the user voice data; When the training model is used to detect a specific target in an image, the training sample includes the sample image and the location annotation information of the specific target; the feature information of the input image to be detected is extracted by the feature extraction module of the training model, and the business operation module of the training model is used to detect the location information of the specific target based on the feature information of the image to be detected.

2. The method according to claim 1, wherein The calculating of the first calculated value based on the feature information output by the feature operation layer specifically includes: calculating the first calculated value according to the feature information output by the feature operation layer and a deformation weight value of a pseudo quantization operator; The method further includes: adjusting the deformation weight value of the pseudo quantization operator according to the gradient of the loss function.

3. The method according to claim 1 or 2, wherein: Calculating the gradient of the loss function specifically includes: using the loss function to derive the first parameter to be learned to obtain the gradient of the loss function; The step of adjusting the parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function specifically includes: The parameter value of the first parameter to be learned is replaced by: the difference obtained by subtracting the product of the gradient of the loss function from the current parameter value of the first parameter to be learned, where the product of the gradient of the loss function is the product of the step size and the gradient of the loss function.

4. The method according to claim 1 or 2, wherein: The method further comprises: When the number of times the parameter value of the first parameter to be learned is adjusted is equal to a preset number, or when the difference between the currently adjusted parameter value and the last adjusted parameter value is less than a threshold, the adjustment of the parameter value is stopped.

5. A model training system, characterized in that: include: A training determination unit, configured to determine an initial training model and training samples, wherein the initial training model includes a plurality of feature operation layers, the output of each feature operation layer is connected to a pseudo-quantization operator, and the pseudo-quantization operator is configured to perform a pseudo-quantization operation on the feature information output by the feature operation layer, and the training samples include sample labeling information; A loss function unit is used to calculate a loss function related to the initial training model, wherein the loss function includes a calculation formula between the labeling information of the sample, the first parameter to be learned in the feature operation layer, and the calculated value of the pseudo-quantization operation, and the calculated value of the pseudo-quantization operation has a smooth curve as the feature information output by the feature operation layer changes; wherein the calculated value of the pseudo-quantization operation is obtained by: calculating a first calculated value based on the feature information output by the feature operation layer; using the first calculated value as an input value of a sigmoid function to obtain a sigmoid function value; and obtaining the calculated value of the pseudo-quantization operation based on the sigmoid function value, a quantization range of the input value of the pseudo-quantization operation, and a quantization parameter involved in the pseudo-quantization operation. A gradient calculation unit, used to calculate the gradient of the loss function; An adjustment unit, configured to adjust a parameter value of the first parameter to be learned in the feature operation layer according to the gradient of the loss function to obtain a final training model; When the training model is used to determine user attributes based on user voice data, the training sample includes a voice sample and its corresponding user attribute label; the feature extraction module of the training model extracts feature information of the input user voice data, and the service operation module of the training model is used to classify the user attributes based on the feature information of the user voice data; When the training model is used to detect a specific target in an image, the training sample includes the sample image and the location annotation information of the specific target; the feature information of the input image to be detected is extracted by the feature extraction module of the training model, and the business operation module of the training model is used to detect the location information of the specific target based on the feature information of the image to be detected.

6. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a plurality of computer programs, which are suitable for being loaded by a processor and executing the model training method according to any one of claims 1 to 4.

7. A terminal device, characterized in that: including processor and memory; The memory is used to store multiple computer programs, and the computer programs are used to be loaded by the processor and execute the model training method according to any one of claims 1 to 4; the processor is used to implement each computer program in the multiple computer programs.

8. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium; the processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the model training method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

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

    CN111652366A

  • Key point detection method and device, electronic equipment and storage medium

    CN112712068A