Model training method, device, equipment, storage medium and program product
By determining the error degree and adjusting the parameter weights during model training, the problem of low model training efficiency under limited hardware resources is solved, achieving more efficient training and better model performance.
Patent Information
- Application Number
- CN202510896704.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-06-30
AI Technical Summary
With limited hardware resources, model training efficiency cannot be effectively improved, and there are fluctuations in the direction and amplitude of parameter updates during model training, which leads to increased training time and decreased model performance.
By determining the error of model parameters at the end of training iterations and adjusting parameter weights based on the error, model parameters are updated to ensure the correct update direction and magnitude, thereby improving training efficiency under limited hardware resources.
This reduces fluctuations during model training, shortens training time, and improves the model's prediction accuracy and generalization ability.
Smart Images

Figure CN120409741B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to model training methods, devices, equipment, storage media and program products. Background Art
[0002] Currently, before applying models (such as neural networks) to specific business domains, they are typically trained based on data from that domain. Model training efficiency is generally closely related to the hardware resources used during training. For example, using multiple graphics processing units (GPUs) to train models in parallel can significantly improve training efficiency. However, when hardware resources are limited, this improvement in model training efficiency cannot be achieved effectively. Summary of the Invention
[0003] The present application provides a model training method, a model training device, an electronic device, a computer non-volatile readable storage medium and a computer program product to at least solve the problem in the related art that the training efficiency of the model cannot be effectively improved when hardware resources are limited.
[0004] This application provides a model training method, including:
[0005] Obtaining model training information, the model training information including first model parameters of a trained model obtained at the end of a current training iteration;
[0006] Determining an error degree of the first model parameter, the error degree representing a degree of fluctuation and a degree of deviation of the first model parameter;
[0007] Determining a parameter weight of the first model parameter based on the error degree, where the parameter weight represents the importance of the first model parameter in the model training process, wherein the greater the error degree, the smaller the parameter weight;
[0008] The first model parameters are updated according to the parameter weights to obtain second model parameters, and the second model parameters are used as initial model parameters for the next training iteration.
[0009] This application also provides a model training device, comprising:
[0010] An information acquisition module, configured to acquire model training information, wherein the model training information includes a first model parameter of a trained model obtained at the end of a current training iteration;
[0011] a parameter evaluation module, configured to determine an error degree of the first model parameter, wherein the error degree represents a degree of fluctuation and a degree of deviation of the first model parameter;
[0012] a weight determination module, configured to determine a parameter weight of the first model parameter based on the error degree, wherein the parameter weight represents the importance of the first model parameter in the model training process;
[0013] A parameter updating module is used to update the first model parameters according to the parameter weights to obtain second model parameters, and use the second model parameters as initial model parameters for the next training iteration.
[0014] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of the above-mentioned model training method when executing the computer program.
[0015] The present application also provides a computer non-volatile readable storage medium, in which a computer program is stored, wherein the computer program implements the steps of the above-mentioned model training method when executed by a processor.
[0016] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned model training method when executed by a processor.
[0017] In the technical solutions of some embodiments of the present application, at the end of the current training iteration, the error degree of the first model parameter can be determined based on the first model parameter obtained in the current training iteration. Furthermore, when the error degree is large, the first model parameter can be given a smaller parameter weight, and when the error degree is small, the first model parameter can be given a larger parameter weight. In this way, after the first model parameter is updated based on the parameter weight and the updated second model parameter is used as the initial model parameter of the next training iteration, when the parameter update direction or update amplitude of the current training iteration is incorrect, the impact of the current training iteration on the entire model training process can be reduced. Furthermore, during the model training process, the model parameters can always be updated in the correct parameter update direction or update amplitude, thereby avoiding the problem of increased model training time due to fluctuations in the model training process. Therefore, even in the case of limited hardware resources, the model training efficiency can be greatly improved, thereby solving the problem in some technologies that the model training efficiency cannot be effectively improved when hardware resources are limited. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0019] Figure 1 A schematic diagram of the hardware resource interaction during some model training processes;
[0020] Figure 2 Schematic diagram of parallel training of models in some scenarios;
[0021] Figure 3 Schematic diagram of parallel training of models in other scenarios;
[0022] Figure 4 A flowchart of a model training method provided for some embodiments of the present application;
[0023] Figure 5 A schematic diagram of a module of a model training device provided in some embodiments of the present application;
[0024] Figure 6 A schematic diagram of a module of an electronic device provided for some embodiments of the present application. DETAILED DESCRIPTION
[0025] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0026] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements but also other elements not explicitly listed, or also includes elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or precedence.
[0027] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0028] Model training refers to the process of inputting training data into the model and automatically adjusting the model parameters based on the difference between the output and the actual results. Model training can specifically include the following steps:
[0029] 1) Based on the model's desired functionality, construct a training dataset for the model. This dataset can include multiple (e.g., tens of thousands) pieces of training data. Training data can include images, text, and other items.
[0030] 2) Use the training data in the training dataset to train the model for multiple iterations. In this application, a complete traversal of the training data in the training dataset is called an iteration. In other words, a round of training the model using all the training data in the training dataset is called an iteration. For example, assuming that the training dataset includes training data 1, 2, ..., 10001, a round of training the model using training data 1, 2, ..., 10001 is called the first iteration. A round of training the model using training data 1, 2, ..., 10001 is called the second iteration. And so on. During each iteration of training, the model automatically adjusts the model parameters based on the difference between the output result and the true result to minimize the difference between the output result and the true result. In this way, during multiple iterations of training, the model parameters can be gradually accurate, and the accuracy of the model output results can be different in different iterations of training. For example, in the first iteration, when the model is trained using the training data 1, 2, ..., 10001, the model's output accuracy is only 20%. However, in the second iteration, when the model is trained again using the training data 1, 2, ..., 10001, the model's output accuracy reaches 25%. After multiple iterations of training, when the difference between the output and the true result is less than a threshold, the model is considered trained.
[0031] See also Figure 1 , which is a schematic diagram of the interaction of hardware resources during some model training processes. Figure 1 In this example, hardware resources can include a hard drive, motherboard, and graphics card. The motherboard integrates a central processing unit (CPU) and memory, while the graphics card integrates video memory and at least one graphics processing unit (GPU). The motherboard and graphics card can be connected via a PCIe (Peripheral Component Interconnect Express) bus. The hard drive can be used to persist model training data.
[0032] When model training starts, the central processing unit can perform the following operations: 1) Initialize the model and save the model's initialization parameters to the memory. 2) Load the training data from the hard disk into the memory and preprocess the training data, such as normalization, data enhancement, etc. 3) Divide the preprocessed training data into multiple batches (i.e., batches). For example, assuming that the central processing unit loads 10,000 training data of the model from the hard disk, the training data can be divided into 10 batches, each batch including 1,000 training data. 4) Based on the PCIe bus between the motherboard and the graphics card, save the model's initialization parameters and at least part of the batch of training data to the graphics memory.
[0033] Multiple GPUs can read initialization parameters and training data from the graphics memory and train the model in parallel based on the read initialization parameters and training data. Specifically, two scenarios of parallel training are described below.
[0034] Scenario 1: Based on initialization parameters, each GPU can run the same model (i.e., the models running in different GPUs are identical). Different GPUs can use different batches of training data to train the models they run. It is understandable that because different GPUs use different training data, even if they run the same model, the gradient data and other data obtained during training will not be exactly the same. Each GPU can save the gradient data to video memory. After performing an aggregation calculation (such as averaging) on the gradient data of each GPU stored in video memory, the final gradient data can be obtained. Based on this final gradient data, the model parameters in each GPU can be updated. This ensures that the models running in each GPU remain consistent. In this way, model training can be completed after multiple training iterations.
[0035] For easier understanding, please refer to Figure 2 , which is a schematic diagram of parallel training of models in some scenarios. Figure 2 In the example, it is assumed that the central processing unit divides the training data into 10 batches, and the graphics card is integrated with 5 graphics processing units G1, G2, G3, G4, and G5. Then, the graphics processing units G1, G2, G3, G4, and G5 can run the model M respectively based on the initialization parameters. Furthermore, the graphics processing unit G1 can train the running model M based on the training data in batches 1 and 6, obtain the corresponding gradient data D1, and save the gradient data D1 to the video memory. The graphics processing unit G2 can train the running model M based on the training data in batches 2 and 7, obtain the corresponding gradient data D2, and save the gradient data D2 to the video memory. And so on, we can get Figure 2 The gradient data D1, D2, D3, D4, and D5 are shown. Because the graphics processing units G1, G2, G3, G4, and G5 use different batches of training data to train the models they run, the resulting gradient data D1, D2, D3, D4, and D5 may not be exactly the same. Aggregating the gradient data D1, D2, D3, D4, and D5 yields the final gradient data D. Based on the gradient data D, the model parameters of each model can be updated.
[0036] Scenario 2: When the model is a neural network model, different GPUs run different neural network layers of the same model and train the running neural network layers based on the training data. For example, refer to Figure 3 , which is a schematic diagram of parallel training of models in other scenarios. Figure 3 In the example, assume that the graphics card has five graphics processing units (GPUs) G1, G2, G3, G4, and G5 integrated into it, and the model includes neural network layers L1 to L10. Then, GPU G1 can run neural network layers L1 and L2 and train them based on the training data. GPU G2 can run neural network layers L3 and L4 and train them based on the training data. And so on. Data between neural network layers can be transmitted between different GPUs. For example, GPU G1 can send the output of neural network layer L2 to GPU G2 as the input of neural network layer L3. In this way, after multiple iterations of training, the model training can be completed.
[0037] Based on the descriptions of the two scenarios above, it is understandable that parallel training can greatly improve model training efficiency. However, this parallel training relies on sufficient hardware resources. If hardware resources are limited, the model training efficiency cannot be effectively improved. For example, in scenarios 1 and 2 above, if the graphics card only has one graphics processing unit, parallel training based on multiple graphics processing units cannot be performed, and thus the model training efficiency cannot be effectively improved.
[0038] In addition, although parallel training can improve training efficiency, it also has some defects. For example, take the above scenario 1 as an example. Since the training data used by each graphics processing unit is only part of the training data, it is easily affected by the noise interference of the training data, causing the update direction and update amplitude of the model parameters to fluctuate, which in turn causes the updated model parameters to be inaccurate. For example, in the third training iteration, the obtained model parameters are already relatively accurate, but in the fourth training iteration, the accuracy of the obtained model parameters may be lower than the accuracy of the model parameters in the third training iteration. This will cause large fluctuations in the update direction and update amplitude of the model parameters. In this way, on the one hand, there will be instability problems in the model training process, which reduces the model training efficiency. On the other hand, it will have a great impact on the model performance, such as the model's prediction results are not accurate enough and the model's generalization ability is relatively poor.
[0039] In view of this, the present application provides a model training method that can improve the model training efficiency when hardware resources are limited. At the same time, it can also improve the model performance, such as improving the prediction accuracy and generalization ability of the model. The model training method can be applied to electronic devices. The electronic devices may include but are not limited to tablet computers, laptop computers, servers, etc. Figure 4 , which is a flow chart of the model training method provided in some embodiments of the present application. Figure 4 In [1], the model training method includes the following steps:
[0040] Step S401: Obtain model training information, where the model training information includes first model parameters of the trained model obtained at the end of the current training iteration.
[0041] Specifically, the first model parameters refer to the trainable parameters in the trained model, such as the weight matrix, bias vector, scaling / offset factor of the normalization layer, etc.
[0042] In this embodiment, at the end of the current training iteration, a snapshot operation can be performed on the trainable parameters of the trained model (i.e., the trainable parameters and their related states are completely saved). In this way, the first model parameters of the trained model at the end of the current training iteration can be obtained.
[0043] Step S402: determining the error degree of the first model parameter, where the error degree represents the degree of fluctuation and deviation of the first model parameter.
[0044] Specifically, the degree of fluctuation refers to the difference between the first model parameters and the model parameters in the adjacent historical training iterations. For example, the first model parameters can be compared with the model parameters in the previous training iteration. If the difference is large, it indicates that the first model parameters have experienced significant fluctuations; if the difference is small, it indicates that the first model parameters have experienced minimal fluctuations. For another example, the first model parameters can be compared with the average of the model parameters from the previous training iterations. If the difference is large, it indicates that the first model parameters have experienced significant fluctuations; if the difference is small, it indicates that the first model parameters have experienced minimal fluctuations. It is understood that changes in model parameters between adjacent training iterations of model training should be relatively small. If the first model parameters differ significantly from the model parameters in the adjacent historical training iterations, this may indicate that the parameter update in the current training iteration is inaccurate, i.e., the first model parameters are inaccurate. Generally, the degree of fluctuation can indicate the degree of parameter stability during model training. Based on the definition of the degree of fluctuation, the degree of fluctuation of the first model parameters can be determined by comparing the first model parameters with the model parameters in the adjacent historical training iterations.
[0045] The degree of bias refers to the uncertainty of the prediction result when using a trained model with first model parameters for prediction. Uncertainty refers to the confidence level of the prediction result. Simply put, if the confidence level of the prediction result obtained when using a trained model with first model parameters for prediction is high, it indicates that the degree of bias of the first model parameters is relatively low. Conversely, if the confidence level of the prediction result obtained when using a trained model with first model parameters for prediction is low, it indicates that the degree of bias of the first model parameters is relatively low. Generally, the degree of bias can indicate the performance of the trained model, which can be evaluated based on the trained model's loss value, gradient data, and other factors. For example, if the loss value of the trained model is relatively large during the current training iteration, this can indicate that the degree of bias of the first model parameters is relatively large. Conversely, if the loss value of the trained model is relatively small, this can indicate that the degree of bias of the first model parameters is relatively small.
[0046] In this embodiment, either the degree of fluctuation or the degree of deviation can be used as the degree of error, or the degree of fluctuation and the degree of deviation can be weighted to obtain the degree of error. This application is not limited to this. In subsequent embodiments of this application, various methods for calculating the degree of error are provided, which will not be repeated here.
[0047] Step S403: determining a parameter weight of the first model parameter based on the error degree, where the parameter weight represents the importance of the first model parameter in the model training process, wherein the greater the error degree, the smaller the parameter weight.
[0048] Specifically, when the error degree of the first model parameter is small, it indicates that the update direction and update amplitude of the model parameter are correct in the current training iteration. Therefore, the first model parameter can have a larger parameter weight. Conversely, when the error degree of the first model parameter is large, it indicates that the update direction and update amplitude of the model parameter are incorrect in the current training iteration. Therefore, the first model parameter can have a smaller parameter weight. In this embodiment, the calculation relationship between the error degree and the parameter weight can be shown as Expression (1).
[0049]
[0050] Where F represents the parameter weight of the first model parameter, represents the error of the first model parameter, represents a hyperparameter. The value change trend and error of The value change trend of is the same, that is The value of the error Increases with increasing error Decrease and decrease. And because In the denominator, so the error When it increases, As the value of increases, the value of the parameter weight F decreases. On the contrary, when the error degree When decreasing, As the value of decreases, the value of the parameter weight F increases. In this way, the logic that the greater the error, the smaller the parameter weight is achieved.
[0051] Furthermore, by adjusting the hyperparameters The value of can control the influence of error on parameter weight. For example, in the hyperparameter When the value of is 10, a small change in the error can lead to a large change in the parameter weight. When the value of is 0.5, a large change in the error may only cause a small change in the parameter weight. Therefore, in practical applications, the hyperparameters can be determined according to actual needs. This application does not impose any restrictions on the value of .
[0052] Furthermore, it is understandable that the calculation relationship between the error degree and the parameter weight may not be limited to the relationship shown in expression (1). For example, the calculation relationship between the error degree and the parameter weight may also be as shown in expression (2). This application does not impose any restrictions on this calculation relationship.
[0053] (2)
[0054] Step S304: Update the first model parameters according to the parameter weights to obtain second model parameters, and use the second model parameters as initial model parameters for the next training iteration.
[0055] In this embodiment, the parameter weights can be substituted into Expression (3) to obtain the second model parameters.
[0056]
[0057] in, represents the first model parameter, represents the second model parameter, That is, the parameter weight.
[0058] It can be understood that during the model training process, updating the model parameters obtained in each training iteration based on expression (3) is equivalent to implementing weighted calculation of the model parameters of multiple training iterations. That is, for training iterations with the correct parameter update direction or update amplitude, the model parameters of these training iterations can have higher weights, and for training iterations with the wrong parameter update direction or update amplitude, the model parameters of these training iterations can have lower weights. In this way, during the model training process, the impact of training iterations with the wrong parameter update direction or update amplitude on the model training process can be weakened, and the model can be guided to always update parameters according to the correct parameter update direction or update amplitude. For example, suppose the model parameters for the 1st to 4th training iterations all have low errors, but the model parameters in the 5th training iteration fluctuate significantly compared to the model parameters in the 4th training iteration (i.e., the model parameters in the 4th training iteration differ significantly from those in the 5th training iteration). In this case, due to factors such as noise in the training data, errors occurred in the parameter update direction or amplitude in the 5th training iteration. By reducing the parameter weights of the model parameters in the 5th training iteration, the model parameters can be controlled to avoid being updated along the parameter update direction or amplitude of the 5th training iteration during model training. This avoids problems such as fluctuations in the training process caused by errors in the parameter update direction or amplitude, and accordingly, reduces the increase in training time caused by fluctuations in the training process, thereby achieving the goal of improving model training efficiency.
[0059] In this embodiment, if the parameter weights for the current training iteration are lower than the weight threshold (i.e., the error is greater than the error threshold), this may indicate a serious error in the parameter update direction or magnitude for the current training iteration, causing significant fluctuations in the model training process and significantly increasing training time. In this case, the first model parameters obtained in the current training iteration can be discarded, and the updated model parameters obtained in the previous training iteration can be used as the initial model parameters for the next training iteration. This avoids the problem of significantly increased training time caused by errors in the parameter update direction or magnitude for the current training iteration.
[0060] In summary, in the technical solutions of some embodiments of the present application, at the end of the current training iteration, the error degree of the first model parameter can be determined based on the first model parameter obtained in the current training iteration. Furthermore, when the error degree is large, the first model parameter can be given a smaller parameter weight, and when the error degree is small, the first model parameter can be given a larger parameter weight. In this way, after the first model parameter is updated based on the parameter weight and the updated second model parameter is used as the initial model parameter of the next training iteration, when the parameter update direction or update amplitude of the current training iteration is incorrect, the impact of the current training iteration on the entire model training process can be reduced. Furthermore, during the model training process, the model parameters can always be updated in the correct parameter update direction or update amplitude, thereby avoiding the problem of increased model training time due to fluctuations in the model training process. Therefore, even in the case of limited hardware resources, the model training efficiency can be greatly improved, thereby solving the problem in some technologies that the model training efficiency cannot be effectively improved when hardware resources are limited.
[0061] For ease of understanding, the following is explained by way of examples. For example, in some technologies, because there are fluctuations in the model training process, it may take 200 iterations to complete the model training. If you rely on limited hardware resources to run these 200 iterations, it will take a long time and the efficiency of the model training will be low. However, by using more hardware resources to perform model training in parallel, the model training time can be shortened, thereby greatly improving the model training efficiency. In the solution of the present application, by reducing the fluctuations in the model training process, the parameter update direction of the model training can always be updated in the correct direction. Therefore, the number of iterations of model training can be reduced, for example, only 20 iterations are required to complete the model training. Since the number of iterations of model training is greatly reduced, if the hardware resources are effective, the model training time can also be greatly shortened, thereby improving the model training efficiency.
[0062] Furthermore, in the model training method of the present application, since the model parameters can always be updated in the correct update direction and update amplitude, the final model parameters are relatively accurate, and thus the trained model can have better performance, such as relatively high prediction accuracy and good generalization ability. In contrast, in some technologies, although a large amount of hardware resources are consumed, because the amplitude and magnitude of the parameter updates fluctuate greatly, the model parameters at the time of model convergence may not be optimal, that is, the performance of the trained model is not good enough, such as insufficient prediction accuracy and weak generalization ability.
[0063] The above step S402 is further described below.
[0064] In some embodiments, determining the error degree of the first model parameter in step S402 may include:
[0065] Get the reference model parameters for the current training iteration;
[0066] A first difference between the reference model parameter and the first model parameter is determined, and an error degree is determined based on the first difference.
[0067] Specifically, the initial model parameters of the current training iteration can be used as the reference model parameters. The initial model parameters of the current training iteration are the model parameters obtained in the previous training iteration after being updated according to the parameter weights. Since there are typically multiple model parameters, the initial model parameters can be subtracted from the first model parameters point-by-point, and the L2 norm of the subtraction results can be squared (i.e., the sum of the squares of all difference results). The L2 norm squared result can be considered the squared distance between the initial model parameters and the first model parameters, and this squared distance can be used as the first difference between the reference model parameters and the first model parameters.
[0068] Furthermore, the term "point-to-point" refers to subtracting the reference model parameters from the corresponding parameters in the first model parameters. For ease of understanding, the following example illustrates this. Assume that the model parameters of the trained model include (trq1, trq2, trq3). It is understood that the same parameter can have different values in different training iterations of the model. For example, in the first training iteration, after updating the parameter weights, the value of parameter trq1 is 0.2, the value of parameter trq2 is 0.4, and the value of parameter trq3 is 0.8. Since the model parameters updated based on the parameter weights in the first training iteration serve as the initial model parameters for the second training iteration, in the second training iteration, the initial values of parameter trq1 are 0.2, the initial value of parameter trq2 is 0.4, and the initial value of parameter trq3 is 0.8. After training in the second training iteration, the value of parameter trq1 becomes 0.5, the value of parameter trq2 becomes 0.3, and the value of parameter trq3 becomes 0.6. Then, when the second training iteration is the current training iteration, point-to-point subtraction means subtracting the final value of parameter trq1, 0.5, from the initial value, 0.2, to get 0.3, subtracting the final value of parameter trq2, 0.3, from the initial value, 0.4, to get -0.1, and subtracting the final value of parameter trq3, 0.6, from the initial value, 0.8, to get -0.2. After completing the subtraction, the sum of the squares of the difference results can be calculated, that is, The result can be used as the first difference size. Since the difference is squared in the L2 norm square, if there is a large difference (i.e., abnormal fluctuation), the squared value will also be amplified (i.e., it can amplify the abnormal fluctuation). This can better monitor the model parameters of abnormal fluctuations.
[0069] Generally, a larger first difference indicates a greater fluctuation in the parameter update direction or update amplitude of the current training iteration, and thus, the error can be larger. Conversely, a smaller first difference indicates a greater fluctuation in the parameter update direction or update amplitude of the current training iteration, and thus, the error can be smaller.
[0070] In the above embodiment, the error degree is determined based on the difference between the initial model parameters of the current training iteration and the first model parameters, which can be used to evaluate whether the model parameters are updated in the correct direction or magnitude. Furthermore, when the parameter update direction or magnitude is incorrect, the error degree can be used to control the influence of the first model parameters on the entire model training process, thereby reducing the problem of increased training time caused by incorrect parameter update direction or magnitude.
[0071] In other embodiments, the first difference size can be determined based on methods other than the L2-norm square. For example, among the differences obtained by performing a point-by-point subtraction between the initial model parameters and the first model parameters, if the absolute value of at least a specified number of differences is greater than a difference threshold, it indicates that the first difference size between the initial model parameters and the first model parameters for the current training iteration is large, and the error degree can be large. Conversely, if the absolute value of less than a specified number of differences is greater than the difference threshold, it indicates that the first difference size between the initial model parameters and the first model parameters for the current training iteration is small, and the error degree can be small. For example, assume that the specified number is 2 and the difference threshold is 0.15. For the above-mentioned model parameters (trq1, trq2, trq3), the absolute values of the differences obtained by performing a point-by-point subtraction between the initial model parameters and the first model parameters include 0.3, 0.1, and 0.2. Since the absolute values of two differences are greater than the difference threshold of 0.15, the error degree can be large.
[0072] In some embodiments, average model parameters for multiple training iterations can be obtained based on the initial model parameters of the current training iteration and the multiple training iterations before the current training iteration, and the average model parameters can be used as reference model parameters. For example, assume that the model parameters of the trained model include (trq1, trq2, trq3). After training in the current training iteration A, the value of parameter trq1 becomes 0.5, the value of parameter trq2 becomes 0.3, and the value of parameter trq3 becomes 0.6. In the current training iteration A, the initial value of parameter trq1 is 0.4, the initial value of parameter trq2 is 0.2, and the initial value of parameter trq3 is 0.1. In the training iteration B before the current training iteration A, the initial value of parameter trq1 is 0.3, the initial value of parameter trq2 is 0.22, and the initial value of parameter trq3 is 0.15. In the training iteration C before training iteration B, the initial value of parameter trq1 is 0.1, the initial value of parameter trq2 is 0.26, and the initial value of parameter trq3 is 0.18. Then, the initial values of parameter trq1 at training iterations A, B, and C can be averaged to obtain an average value of 0.26 for parameter trq1, and the initial values of parameter trq2 at training iterations A, B, and C can be averaged to obtain an average value of 0.23 for parameter trq2. Similarly, the initial values of parameter trq3 at training iterations A, B, and C can be averaged to obtain an average value of 0.14 for parameter trq3. Furthermore, the value of 0.5 of parameter trq1 at the end of the current training iteration can be subtracted from the average value of 0.26 for trq1, the value of 0.3 of trq2 at the end of the current training iteration can be subtracted from the average value of 0.23 for trq2, and the value of 0.6 of trq3 at the end of the current training iteration can be subtracted from the average value of 0.14 for trq3. In this way, point-to-point subtraction between the reference model parameters and the first model parameters is achieved, obtaining a first difference.
[0073] In the above embodiment, the initial model parameters of the current training iteration and multiple training iterations before the current training iteration are averaged, and the result of the average calculation is used as the reference model parameter, which can neutralize the fluctuations of each training iteration, making the reference model parameter more accurate, and thus making the first difference size more accurate.
[0074] In some embodiments, the method of the present application may further include:
[0075] If the first difference is not greater than the first difference threshold, the first difference is used as the error degree;
[0076] If the first difference size is greater than the first difference threshold, the first difference size is increased to obtain a second difference size, and the second difference size is used as the error degree.
[0077] Specifically, when the first difference size is not greater than the first difference threshold, it means that there is no serious error in the parameter update direction or update amplitude of the current training iteration. In this case, the first difference size can be directly used as the error degree, and then the parameter update direction or update amplitude during the model training process can be controlled according to the parameter weight of the first model parameter. When the first difference size is greater than the first difference threshold, it means that there is a serious error in the parameter update direction or update amplitude of the current training iteration. In this case, the second difference size can be increased. In this way, the error degree obtained is larger, and accordingly, the parameter weight obtained based on the error degree is smaller. In this way, during the model training process, the model can be suppressed from updating parameters according to the wrong parameter update direction or update amplitude, thereby shortening the model training time.
[0078] Furthermore, in some embodiments, the difference threshold may include a first difference threshold and a second difference threshold, wherein the second difference threshold may be greater than the first difference threshold. If the first difference size is not greater than the first difference threshold, the first difference size is used as the error degree. If the first difference size is greater than the first difference threshold but less than the second difference threshold, the first difference size is increased to obtain the second difference size, and the second difference size is used as the error degree. If the first difference size is greater than the second difference threshold, the first model parameters obtained in the current training iteration may be discarded, and the updated model parameters obtained in the previous training iteration may be used as the initial model parameters for the next training iteration. In this way, the problem of greatly increased training time caused by errors in the parameter update direction or update amplitude of the current training iteration can be avoided.
[0079] In some embodiments, the method of the present application may further include:
[0080] If the first difference size is greater than the second difference threshold, obtaining a third difference threshold, where the third difference threshold represents a maximum allowable difference size between the second model parameter and the initial model parameter of the current training iteration;
[0081] If the difference between the second model parameters and the initial model parameters of the current training iteration is greater than the difference amplitude, the second model parameters are clipped so that the difference between the second model parameters and the initial model parameters of the current training iteration is within a third difference threshold.
[0082] The third difference threshold is used to limit the parameter update amplitude of the current training iteration. If the first difference is greater than the second difference threshold, it indicates that the parameter update of the current training iteration has experienced significant fluctuations. To prevent the parameters of the current training iteration from having an excessive impact on the model training process, the third difference threshold can be used to force the parameter update amplitude of the current training iteration to be limited.
[0083] Specifically, in the solution of the present application, after the parameters are updated and the first model parameters are obtained in the current training iteration, the first model parameters will be updated according to the parameter weights, and the updated second model parameters will be used as the initial model parameters of the next iteration. Therefore, the second model parameters can be regarded as the final model parameters obtained in the current training iteration. Based on this, in order to prevent the parameter update amplitude of the current training iteration from being too large, after obtaining the second model parameters, the second model parameters can be subtracted from the initial model parameters of the current training iteration point-to-point to obtain the difference between the second model parameters and the initial model parameters of the current training iteration. If the difference is greater than the second difference threshold, it means that the parameter amplitude of the current training iteration update is too large. Therefore, the second model parameters can be clipped so that the difference between the second model parameters and the initial model parameters of the current training iteration is within the third difference threshold. In this way, the impact of the parameter update of the current training iteration on the next training iteration can be effectively reduced, thereby avoiding errors in the parameter update direction or parameter update amplitude.
[0084] In some embodiments, determining the error degree of the first model parameter in step S402 includes:
[0085] Get the first loss curve of the current training iteration. The first loss curve represents the loss value obtained when the trained model is trained using different batches of training data in the current training iteration.
[0086] Determining a first dispersion of loss values according to the first loss curve;
[0087] An error degree is determined according to the first discreteness.
[0088] Specifically, the training data can be divided into N batches in the current training iteration. When these N batches of training data are used for model training, N loss values can be obtained. It can be understood that if the parameter update of the trained model does not fluctuate significantly in the current training iteration, then the N loss values obtained should be relatively concentrated. Conversely, if the parameter update of the trained model fluctuates significantly in the current training iteration, then the N loss values obtained should be relatively discrete. Therefore, the first discreteness of the loss value can reflect whether the model parameter update in the current training iteration is correct. Simply put, the larger the first discreteness, the greater the error degree can be.
[0089] In the above embodiment, the error of the first model parameter is evaluated based on the discrete degree of the loss value, and it is also possible to evaluate whether there are serious errors in the parameter update direction or update amplitude of the current training iteration, thereby shortening the training time of the model.
[0090] In some embodiments, determining the error degree of the first model parameter in step S402 includes:
[0091] Get the second loss curve of the current training iteration. The second loss curve represents the loss value obtained when the trained model is verified using different batches of verification data at the end of the current training iteration.
[0092] determining a second dispersion of loss values according to the second loss curve;
[0093] The error degree is determined according to the second dispersion.
[0094] The principles of the first and second discreteness are similar, with the primary difference being that the second discreteness is derived based on validation data after the current training iteration. Because the second discreteness is derived based on validation data, it can be used to assess the degree of deviation in the first model parameters obtained during the current training iteration (i.e., the confidence level in the model's predictions). Specifically, a larger second discreteness indicates a greater degree of deviation in the first model parameters, and thus a higher degree of error.
[0095] In some embodiments, determining the error of the first model parameter includes:
[0096] Obtaining a gradient curve for the current training iteration, where the gradient curve represents gradient values obtained when the trained model is trained using training data from different batches in the current training iteration;
[0097] determining a third discreteness of the gradient value according to the gradient curve;
[0098] The error degree is determined according to the third dispersion.
[0099] Similar to the loss value, if the parameter updates of the trained model do not experience significant fluctuations during the current training iteration, the resulting gradient data should be relatively concentrated. Conversely, if the parameter updates of the trained model experience significant fluctuations during the current training iteration, the resulting gradient data should be relatively discrete. Therefore, the third discreteness of the gradient value can also reflect whether the model parameter updates during the current training iteration are correct. Simply put, the larger the third discreteness, the greater the error tolerance.
[0100] In some embodiments, the first model parameter includes a plurality of sub-parameters; determining the error degree of the first model parameter may include:
[0101] Get the sum of changes of multiple sub-parameters in the current training iteration;
[0102] Determine the degree of error based on the sum of the changes.
[0103] For example, consider the model parameters (trq1, trq2, trq3) above. After subtracting the model parameter values from the second training iteration from the updated model parameter values from the first training iteration (i.e., the initial model parameters from the second training iteration), the change in model parameter trq1 is 0.3, the change in model parameter trq2 is 0.1, and the change in model parameter trq3 is 0.2. Therefore, the sum of the changes in the multiple sub-parameters of the first model parameter during the current training iteration is 0.3 + 0.2 + 0.1. The larger the sum of the changes, the greater the error margin.
[0104] In the above embodiment, the sum of the changes can directly reflect the overall change degree of the model parameters, which is intuitive for understanding the stability of the model parameters. At the same time, determining the error degree based on the sum of the changes can simplify the calculation logic, thereby improving calculation efficiency.
[0105] In some embodiments, determining the error degree of the first model parameter in step S402 may include:
[0106] Obtaining a weighted average value and a weighted square average value of the first model parameter, wherein the weighted average value is used to track a change trend of the first model parameter, and the weighted square average value is used to track a change trend of a square value of the first model parameter;
[0107] A degree of error is determined based on the weighted mean and the weighted squared mean of the first model parameters.
[0108] The weighted mean and weighted squared mean are indicators derived from the exponential moving average (EMA). Based on the principle of EMA, data closer to the current time point in the time series is given a higher weight, while data farther from the current time point has its weight exponentially reduced. This allows for smooth estimation of time series and tracking of changing trends.
[0109] Applying the exponential moving average to the solution of this application can track the changing trend of the model parameters. Specifically, referring to Expression (4) and Expression (5), the calculation formulas for the average weight and average square weight in the exponential moving average are shown.
[0110]
[0111]
[0112] In expressions (4) and (5), is the weighted average of the current training iteration, which is used to track the first-order moment index of the model parameters (i.e., the mean trend of the model parameters). are the model parameters of the current training iteration, is the weighted average of the previous training iteration, is the decay rate of historical data, is the weighted square average of the current training iteration, which is used to track the second moment index of the model parameters (i.e., the square trend of the model parameters). is the weighted square mean of the previous training iteration, Represents element-wise multiplication, that is, element-wise square operation.
[0113] Furthermore, based on expression (6), the variance estimation can be performed parameter by parameter to obtain the variance estimate .
[0114] (6)
[0115] Then, for all elements The average or weighted sum is taken, and the result obtained can be used to evaluate the error degree. Specifically, the larger the result obtained, the larger the error degree can be.
[0116] In some embodiments, determining the error degree of the first model parameter in step S402 may include:
[0117] Get the second-order moment index of the gradient in the current training iteration. The second-order moment index of the gradient is used to characterize the gradient noise in the current training iteration.
[0118] The error degree is determined based on the gradient second moment indicator.
[0119] This embodiment is similar to the above-mentioned scheme for determining the error degree based on the weighted average and weighted square average of the first model parameters. The main difference is that this embodiment tracks the gradient second-order moment index of each model training iteration based on expression (7). , and the gradient second moment index As the gradient variance of the current training iteration. If the gradient variance of the current training iteration is relatively large, it means that the reliability of the model parameters of the current training iteration is low and the error can be large.
[0120] (7)
[0121] In expression (7), represents the second-order moment index of the gradient of the previous training iteration, represents the element-wise square of the gradient of the current training iteration, Expressed as the decay rate of historical gradient data.
[0122] This completes the instructions for error calculation.
[0123] Based on the obtained error, it is also possible to determine whether the learning rate setting during model training is appropriate. Specifically, when the error is large (such as in the early stages of model training), it indicates that the model parameter updates are unstable and the gradient noise is large. In this case, the learning rate for model training can be appropriately reduced based on the current learning rate to ensure robust convergence of model training. Conversely, when the error is small (such as in the later stages of model training), it indicates that the model parameter updates are stable and are close to convergence or stuck in a local optimum. In this case, the learning rate for model training can be appropriately increased based on the current learning rate to escape the local optimum and continue to explore the optimal solution.
[0124] Based on the above description, in some embodiments, the model training method of the present application may further include:
[0125] If the error is greater than the first robustness threshold, a second learning rate is obtained based on the first learning rate of the current training iteration, and the second learning rate is used as the learning rate of the next training iteration, wherein the second learning rate is less than the first learning rate;
[0126] If the error degree is less than the second robustness threshold, a third learning rate is obtained based on the first learning rate of the current training iteration, and the third learning rate is used as the learning rate of the next training iteration, wherein the third learning rate is greater than the first learning rate.
[0127] Specifically, the first robustness threshold can be greater than the second robustness threshold. When the error is greater than the first robustness threshold, it indicates that the model parameters are fluctuating significantly. Therefore, the learning rate can be reduced to ensure robust convergence of the model. If the error is less than the second robustness threshold, it indicates that the model parameter update may have entered a local optimum. In this case, increasing the learning rate can help the model training escape the local optimum.
[0128] In the above embodiment, by increasing the learning rate, the update of the model parameters can be reduced in fluctuation, which can enable the model training to converge as quickly as possible, shorten the training time, and thus improve the efficiency of model training. By reducing the learning rate, it is possible to jump out of the local optimum during the model training process and continue to explore the optimal solution, so that the model parameters obtained by training have higher accuracy, thereby improving the model performance. In addition, dynamically adjusting the learning rate based on the error degree can ensure that the learning rate of model training matches the different model training stages, avoiding the problem of increased model training time or insufficient model performance obtained by training due to unreasonable learning rate settings.
[0129] Furthermore, in some embodiments, the trained model includes multiple neural network layers, and the parameters of different neural network layers may have their own corresponding parameter change characteristics. For example, in the later stages of model training, for the convolution layer close to the input layer, the parameter changes are usually small and the changes are very stable, but for the fully connected classification layer, the parameter fluctuations may be relatively large. In this case, if all neural network layers share the same error degree and learning rate, it may be impossible to distinguish the differences in parameter characteristics of different neural network layers, and then the model training time may be increased and the model training efficiency may be reduced due to problems such as unreasonable learning rate settings.
[0130] In view of this, the above-mentioned determination of the parameter weight of the first model parameter based on the error degree may include:
[0131] For one of the target neural network layers among multiple neural network layers, the layer parameter weight of the target neural network layer is determined based on the error degree of the target neural network layer. The layer parameter weight represents the importance of the parameters of the target neural network layer obtained in the current training iteration in the model training process.
[0132] Accordingly, updating the first model parameters according to the parameter weights may include:
[0133] For one of the target neural network layers among the multiple neural network layers, the first model parameters of the target neural network layer are updated based on the layer parameter weights of the target neural network layer to obtain the second model parameters of the target neural network layer, and the second model parameters of the target neural network layer are used as the initial layer parameters of the target neural network layer in the next training iteration.
[0134] In this way, different neural network layers can have their own corresponding layer parameter weights. Based on the layer parameter weights, the differences in parameter characteristics of different neural network layers can be distinguished, so that neural network layers with more stable parameter changes can have higher weights, and neural network layers with larger parameter fluctuations can have lower weights. In this way, parameter updates during model training can be precisely controlled, effectively retaining correct information and eliminating incorrect information, thereby accelerating the convergence of model training and improving model training efficiency.
[0135] In some embodiments, updating the first model parameters according to the parameter weights to obtain the second model parameters includes:
[0136] Obtaining a first parameter change trend of a current training iteration, where the first parameter change trend represents an amount and direction of change of a model parameter of the current training iteration;
[0137] According to the parameter weight, the first parameter change trend is updated to obtain the second parameter change trend;
[0138] The second model parameters are obtained according to the initial model parameters and the change trend of the second parameters in the current training iteration.
[0139] Specifically, the first model parameters can be updated according to expression (8) to obtain the second model parameters.
[0140] (8)
[0141] in, represents the second model parameter, Indicates the degree of error, represents the parameter weight, Indicates the changing trend of the first parameter, Indicates the adjustment coefficient (can be selected according to actual needs ), Indicates the second parameter change trend obtained by updating the first parameter change trend. Represents the initial model parameters for the current training iteration.
[0142] It can be understood that since the first parameter change trend reflects the change amount and change direction of the model parameters of the current training iteration, updating the first parameter change trend based on the parameter weight is equivalent to updating the change amount and change direction of the model parameters. Furthermore, on the basis of the initial model parameters of the current training iteration, adding the second parameter change trend obtained after updating the first parameter change trend is equivalent to adjusting the first model parameters based on the parameter weight.
[0143] Expression (7) and Expression (3) can be viewed as two parallel schemes for updating the first model parameters. In practical applications, one of the two schemes can be selected to update the first model parameters according to actual needs.
[0144] Furthermore, in some embodiments, obtaining the first parameter change trend of the current training iteration may include:
[0145] Obtaining a change trend of a third parameter in a previous training iteration, where the change trend of the third parameter represents a change amount and a change direction of the model parameter in the previous training iteration;
[0146] A first difference between the initial model parameters of the current training iteration and the first model parameters is determined, and a first parameter change trend is obtained based on the third parameter change trend and the first difference.
[0147] Specifically, the relationship between the first parameter change trend and the third parameter change trend can be shown as expression (9).
[0148] (9)
[0149] In expression (9), is the change trend of the third parameter in the previous training iteration, Indicates the first difference between the initial model parameters and the first model parameters of the current training iteration. is the weight of the third parameter change trend. The larger the value of , the greater the influence of the third parameter change trend in the previous training iteration on the first parameter change trend in the current training iteration. Based on expression (9), the trends of different training iterations can be accumulated, thereby accelerating the progress in the flat areas of the model training process and smoothing the oscillations in the oscillating areas of the model training process. In this way, the robustness of model training can be improved.
[0150] This completes the entire description of the method of the present application. In the method of the present application, at the end of the current training iteration, the error degree of the first model parameter can be determined based on the first model parameter obtained in the current training iteration. Furthermore, when the error degree is large, the first model parameter can be given a smaller parameter weight, and when the error degree is small, the first model parameter can be given a larger parameter weight. In this way, after the first model parameter is updated based on the parameter weight and the updated second model parameter is used as the initial model parameter of the next training iteration, when the parameter update direction or update amplitude of the current training iteration is incorrect, the impact of the current training iteration on the entire model training process can be reduced. Furthermore, during the model training process, the model parameters can always be updated in the correct parameter update direction or update amplitude, thereby avoiding the problem of increased model training time due to fluctuations in the model training process. Therefore, even in the case of limited hardware resources, the model training efficiency can be greatly improved, thereby solving the problem in some technologies that the model training efficiency cannot be effectively improved when hardware resources are limited.
[0151] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0152] See also Figure 5 , which is a module diagram of the model training device provided in some embodiments of the present application. Figure 5 In [1], the model training device includes:
[0153] An information acquisition module 501 is used to acquire model training information, where the model training information includes a first model parameter of the trained model obtained at the end of a current training iteration;
[0154] A parameter evaluation module 502 is configured to determine an error degree of a first model parameter, where the error degree represents a degree of fluctuation and a degree of deviation of the first model parameter;
[0155] A weight determination module 503 is configured to determine a parameter weight of the first model parameter based on the error degree, where the parameter weight represents the importance of the first model parameter in the model training process;
[0156] The parameter updating module 504 is configured to update the first model parameters according to the parameter weights to obtain second model parameters, and use the second model parameters as initial model parameters for the next training iteration.
[0157] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0158] Get the reference model parameters for the current training iteration;
[0159] A first difference between the reference model parameter and the first model parameter is determined, and an error degree is determined based on the first difference.
[0160] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0161] The initial model parameters of the current training iteration are used as reference model parameters, or the average model parameters of multiple training iterations are obtained based on the initial model parameters of the current training iteration and multiple training iterations before the current training iteration, and the average model parameters are used as the reference model parameters.
[0162] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0163] If the first difference is not greater than the first difference threshold, the first difference is used as the error degree;
[0164] If the first difference size is greater than the first difference threshold, the first difference size is increased to obtain a second difference size, and the second difference size is used as the error degree.
[0165] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0166] If the first difference size is greater than the second difference threshold, obtaining a third difference threshold, where the third difference threshold represents a maximum allowable difference size between the second model parameter and the initial model parameter of the current training iteration;
[0167] If the difference between the second model parameters and the initial model parameters of the current training iteration is greater than the difference amplitude, the second model parameters are clipped so that the difference between the second model parameters and the initial model parameters of the current training iteration is within a third difference threshold.
[0168] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0169] Get the first loss curve of the current training iteration. The first loss curve represents the loss value obtained when the trained model is trained using different batches of training data in the current training iteration.
[0170] Determining a first dispersion of loss values according to the first loss curve;
[0171] An error degree is determined according to the first discreteness.
[0172] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0173] Get the second loss curve of the current training iteration. The second loss curve represents the loss value obtained when the trained model is verified using different batches of verification data at the end of the current training iteration.
[0174] determining a second dispersion of loss values according to the second loss curve;
[0175] The error degree is determined according to the second dispersion.
[0176] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0177] Get the gradient curve of the current training iteration. The gradient curve represents the gradient value obtained when the trained model is trained using different batches of training data in the current training iteration.
[0178] Determining a third discreteness of the gradient value according to the gradient curve;
[0179] The error degree is determined according to the third discreteness.
[0180] In some embodiments, the first model parameter includes multiple sub-parameters; the parameter evaluation module 502 is specifically configured to:
[0181] Get the sum of changes of multiple sub-parameters in the current training iteration;
[0182] Determine the degree of error based on the sum of the changes.
[0183] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0184] Obtaining a weighted average value and a weighted square average value of the first model parameter, wherein the weighted average value is used to track a change trend of the first model parameter, and the weighted square average value is used to track a change trend of a square value of the first model parameter;
[0185] A degree of error is determined based on the weighted mean and the weighted squared mean of the first model parameters.
[0186] In some embodiments, the parameter evaluation module 502 is specifically configured to:
[0187] Get the second-order moment index of the gradient in the current training iteration. The second-order moment index of the gradient is used to characterize the gradient noise in the current training iteration.
[0188] The error degree is determined based on the gradient second moment indicator.
[0189] In some embodiments, the parameter updating module 504 is further configured to:
[0190] If the error is greater than the robustness threshold, a second learning rate is obtained based on the first learning rate of the current training iteration, and the second learning rate is used as the learning rate of the next training iteration, wherein the second learning rate is smaller than the first learning rate;
[0191] If the error degree is not greater than the robustness threshold, a third learning rate is obtained based on the first learning rate of the current training iteration, and the third learning rate is used as the learning rate of the next training iteration, wherein the third learning rate is greater than the first learning rate.
[0192] In some embodiments, the trained model includes multiple neural network layers; the weight determination module 503 is specifically used to:
[0193] For one of the target neural network layers among multiple neural network layers, the layer parameter weight of the target neural network layer is determined based on the error degree of the target neural network layer. The layer parameter weight represents the importance of the parameters of the target neural network layer obtained in the current training iteration in the model training process.
[0194] In some embodiments, the parameter updating module 504 is specifically configured to:
[0195] For one of the target neural network layers among the multiple neural network layers, the first model parameters of the target neural network layer are updated based on the layer parameter weights of the target neural network layer to obtain the second model parameters of the target neural network layer, and the second model parameters of the target neural network layer are used as the initial layer parameters of the target neural network layer in the next training iteration.
[0196] In some embodiments, the parameter updating module 504 is specifically configured to:
[0197] Obtaining a first parameter change trend of a current training iteration, where the first parameter change trend represents an amount and direction of change of a model parameter of the current training iteration;
[0198] According to the parameter weight, the first parameter change trend is updated to obtain the second parameter change trend;
[0199] The second model parameters are obtained according to the initial model parameters and the change trend of the second parameters in the current training iteration.
[0200] In some embodiments, the parameter updating module 504 is specifically configured to:
[0201] Obtaining a change trend of a third parameter in a previous training iteration, where the change trend of the third parameter represents a change amount and a change direction of the model parameter in the previous training iteration;
[0202] A first difference between the initial model parameters of the current training iteration and the first model parameters is determined, and a first parameter change trend is obtained based on the third parameter change trend and the first difference.
[0203] See also Figure 6 An embodiment of the present application also provides an electronic device, including a memory 10 and a processor 20, wherein the memory 10 stores a computer program, and the processor 20 is configured to run the computer program to execute the steps in any one of the above-mentioned model training method embodiments.
[0204] An embodiment of the present application also provides a computer non-volatile readable storage medium, which stores a computer program, wherein the computer program is configured to execute the steps of any of the above-mentioned model training method embodiments when running.
[0205] In an exemplary embodiment, the above-mentioned computer non-volatile readable storage medium may include, but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0206] An embodiment of the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned model training method embodiments.
[0207] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-mentioned model training method embodiments are implemented.
[0208] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0209] The above is a detailed introduction to a model training method, device, equipment, storage medium and program product provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A model training method, characterized in that: The method comprises: Training the trained model using model training data, where the model training data includes at least one of image data and text data; Obtaining model training information, the model training information including first model parameters of the trained model obtained at the end of a current training iteration; Determining an error degree of the first model parameter, the error degree representing a degree of fluctuation and a degree of deviation of the first model parameter; Determining a parameter weight of the first model parameter based on the error degree, where the parameter weight represents the importance of the first model parameter in the model training process, wherein the greater the error degree, the smaller the parameter weight; updating the first model parameters according to the parameter weights to obtain second model parameters, and using the second model parameters as initial model parameters for the next training iteration; If the error degree is greater than a first robustness threshold, obtaining a second learning rate based on the first learning rate of the current training iteration, and using the second learning rate as the learning rate of the next training iteration, wherein the second learning rate is less than the first learning rate; If the error degree is less than a second robustness threshold, a third learning rate is obtained based on the first learning rate of the current training iteration, and the third learning rate is used as the learning rate of the next training iteration, wherein the third learning rate is greater than the first learning rate.
2. The method according to claim 1, characterized in that Determining the error degree of the first model parameter includes: Obtaining reference model parameters for the current training iteration; A first difference between the reference model parameters and the first model parameters is determined, and the error degree is determined based on the first difference.
3. The method according to claim 2, characterized in that The obtaining of the reference model parameters of the current training iteration includes: The initial model parameters of the current training iteration are used as the reference model parameters, or based on the initial model parameters of the current training iteration and multiple training iterations before the current training iteration, the average model parameters of multiple training iterations are obtained, and the average model parameters are used as the reference model parameters.
4. The method according to claim 2, characterized in that Determining the error degree according to the first difference includes: If the first difference is not greater than a first difference threshold, taking the first difference as the error degree; If the first difference size is greater than the first difference threshold, the first difference size is increased to obtain a second difference size, and the second difference size is used as the error degree.
5. The method according to claim 2, characterized in that The method further comprises: If the first difference size is greater than a second difference threshold, obtaining a third difference threshold, where the third difference threshold represents a maximum difference size allowed between the second model parameters and the initial model parameters of the current training iteration; If the difference between the second model parameters and the initial model parameters of the current training iteration is greater than the third difference threshold, the second model parameters are clipped so that the difference between the second model parameters and the initial model parameters of the current training iteration is within the third difference threshold.
6. The method according to claim 1, characterized in that Determining the error degree of the first model parameter includes: Obtaining a first loss curve for the current training iteration, where the first loss curve represents loss values obtained when the trained model is trained using training data from different batches in the current training iteration; determining a first dispersion of loss values according to the first loss curve; The error degree is determined according to the first discreteness.
7. The method according to claim 1, characterized in that Determining the error degree of the first model parameter includes: Obtaining a second loss curve for the current training iteration, where the second loss curve represents a loss value obtained when the trained model is validated using validation data from different batches at the end of the current training iteration; determining a second dispersion of loss values according to the second loss curve; The error degree is determined according to the second dispersion.
8. The method according to claim 1, characterized in that Determining the error degree of the first model parameter includes: Obtaining a gradient curve for the current training iteration, where the gradient curve represents gradient values obtained when the trained model is trained using training data from different batches in the current training iteration; determining a third discreteness of the gradient value according to the gradient curve; The error degree is determined according to the third dispersion.
9. The method according to claim 1, characterized in that The first model parameter includes a plurality of sub-parameters; and determining the error degree of the first model parameter includes: Obtaining the sum of changes of the multiple sub-parameters in the current training iteration; The error degree is determined according to the sum of the changes.
10. The method according to claim 1, characterized in that Determining the error degree of the first model parameter includes: Obtaining a weighted average value and a weighted square average value of the first model parameter, wherein the weighted average value is used to track a change trend of the first model parameter, and the weighted square average value is used to track a change trend of a square value of the first model parameter; The error degree is determined based on a weighted average and a weighted square average of the first model parameters.
11. The method according to claim 1, wherein Determining the error degree of the first model parameter includes: Obtaining a gradient second-order moment indicator in the current training iteration, where the gradient second-order moment indicator is used to characterize the gradient noise in the current training iteration; The error degree is determined based on the gradient second moment indicator.
12. The method according to any one of claims 1 to 11, characterized in that: The trained model includes multiple neural network layers; The determining, based on the error degree, a parameter weight of the first model parameter includes: For one of the target neural network layers among the multiple neural network layers, the layer parameter weight of the target neural network layer is determined based on the error degree of the target neural network layer, and the layer parameter weight represents the importance of the parameters of the target neural network layer obtained by the current training iteration in the model training process.
13. The method according to claim 12, characterized in that The updating of the first model parameter according to the parameter weight includes: For one target neural network layer among the multiple neural network layers, the first model parameters of the target neural network layer are updated based on the layer parameter weights of the target neural network layer to obtain the second model parameters of the target neural network layer, and the second model parameters of the target neural network layer are used as the initial layer parameters of the target neural network layer in the next training iteration.
14. The method according to claim 1, wherein The updating of the first model parameters according to the parameter weights to obtain second model parameters includes: Obtaining a first parameter change trend of the current training iteration, where the first parameter change trend represents a change amount and a change direction of the model parameter of the current training iteration; updating the first parameter change trend according to the parameter weight to obtain a second parameter change trend; The second model parameters are obtained according to the initial model parameters of the current training iteration and the change trend of the second parameters.
15. The method according to claim 14, characterized in that The obtaining of the first parameter change trend of the current training iteration includes: Obtaining a third parameter change trend of a previous training iteration, where the third parameter change trend represents a change amount and a change direction of the model parameter in the previous training iteration; A first difference between the initial model parameters of the current training iteration and the first model parameters is determined, and the first parameter change trend is obtained based on the third parameter change trend and the first difference.
16. A model training device, characterized in that: The device comprises: A training module, configured to train a trained model using model training data, wherein the model training data includes at least one of image data and text data; An information acquisition module, configured to acquire model training information, wherein the model training information includes a first model parameter of a trained model obtained at the end of a current training iteration; a parameter evaluation module, configured to determine an error degree of the first model parameter, wherein the error degree represents a degree of fluctuation and a degree of deviation of the first model parameter; a weight determination module, configured to determine a parameter weight of the first model parameter based on the error degree, wherein the parameter weight represents an importance of the first model parameter in a model training process; A parameter updating module is used to update the first model parameters according to the parameter weights to obtain second model parameters, and use the second model parameters as the initial model parameters of the next training iteration; and if the error degree is greater than a first robustness threshold, obtain a second learning rate based on the first learning rate of the current training iteration, and use the second learning rate as the learning rate of the next training iteration, wherein the second learning rate is less than the first learning rate; and if the error degree is less than a second robustness threshold, obtain a third learning rate based on the first learning rate of the current training iteration, and use the third learning rate as the learning rate of the next training iteration, wherein the third learning rate is greater than the first learning rate.
17. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the model training method according to any one of claims 1 to 15 when executing the computer program.
18. A computer-readable non-volatile storage medium, characterized in that: The computer non-volatile readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the model training method according to any one of claims 1 to 15.
19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the model training method according to any one of claims 1 to 15 is implemented.
Citation Information
Patent Citations
Model training method and device, equipment and medium
CN119227836A