Large language model training method and device, computer equipment and storage medium
By introducing backup parameters and regularization terms in large language model training, the problems of unstable parameter updates and difficult-to-control search ranges are solved, achieving rapid convergence and improved stability of the model, reducing training time and consumption of computing resources. Suppresses the overfitting phenomenon.
Patent Information
- Application Number
- CN202410139901.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-31
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-01-31
AI Technical Summary
In the training of large language models, there are problems such as unstable parameter updates and difficult to control the search range, which leads to large fluctuations in model parameters, deviation from the optimal solution, and may even cause training to crash, increasing the consumption of training time and computing resources.
In the training process of the large language model, backup parameters are introduced, and the regularization terms of the training parameters and backup parameters are added to the total loss value to limit the change range of the total loss value. By calculating the difference between the training parameters and the backup parameters, Regularization processing updates training parameters and backup parameters to ensure that the gap is not too large, and limits the update range and search range of training parameters.
It effectively improves the stability and robustness of model training, enables large models to converge quickly, reduces training time, reduces the consumption of computing resources, and suppresses the occurrence of over-fitting phenomena.
Smart Images

Figure CN117993461B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of large language models, and more specifically, to a large language model training method, a large language model training device, a computer device, and a non-volatile computer-readable storage medium. Background Art
[0002] With the rapid development of artificial intelligence technology, large-scale language models are playing an increasingly important role in industry applications. However, in the training of large language models, there are still problems that are difficult to solve, such as unstable parameter updates and difficult to control search ranges. This will lead to large fluctuations in model parameters, and the model will deviate far from the optimal solution during the iteration process, or even training crash, resulting in a long training process for large language models, which requires a lot of computing resources. Summary of the invention
[0003] Embodiments of the present application provide a large language model training method, a large language model training device, a computer device, and a non-volatile computer-readable storage medium.
[0004] The training method of the large language model of the implementation mode of the present application includes inputting training text into the large language model to generate output text; determining a first loss value according to the output text, and regularizing the difference between the backup parameters and the training parameters of the large language model to determine a second loss value; updating the training parameters according to the total loss value determined by the first loss value and the second loss value, and updating the backup parameters according to the updated training parameters and the backup parameters in the previous iteration; re-entering the step of inputting training text into the large language model to generate output text until a preset training termination condition is reached.
[0005] In some embodiments, determining a first loss value based on the output text and regularizing the difference between the backup parameters and the training parameters of the large language model to determine a second loss value includes: determining the first loss value based on a preset label of the training text and the output text; determining the second loss value based on the square root of the square of the difference between the backup parameters and the training parameters.
[0006] In some embodiments, updating the backup parameters based on the updated training parameters and the backup parameters in the previous iteration includes: determining an update value based on a preset momentum hyperparameter, the updated training parameters and the backup parameters in the previous iteration to update the backup parameters, and the size of the momentum hyperparameter is negatively correlated with the size of the update value.
[0007] In some embodiments, updating the training parameters according to the total loss value determined based on the first loss value and the second loss value includes: determining the gradient of the training parameters according to the total loss value; and updating the training parameters according to the gradient and a preset learning rate.
[0008] In some embodiments, the total loss value is determined based on the first loss value, the second loss value, and a weight factor corresponding to the second loss value.
[0009] In some embodiments, the training parameter is the same as the initial value of the backup parameter.
[0010] In some embodiments, the training termination conditions include the number of iterations reaching a first preset threshold, the total loss value falling below a second preset threshold, or the model evaluation accuracy reaching a third preset threshold.
[0011] The training device of the large language model of the implementation mode of the present application includes an input module, a determination module, an update module and a loop module. The input module is used to input training text into the large language model to generate output text. The determination module is used to determine a first loss value according to the output text, and regularize the difference between the backup parameters and the training parameters of the large language model to determine a second loss value. The update module is used to update the training parameters according to the total loss value determined by the first loss value and the second loss value, and update the backup parameters according to the updated training parameters and the backup parameters in the previous iteration. The loop module is used to re-enter the step of inputting training text into the large language model to generate output text until a preset training termination condition is reached.
[0012] The computer device of an embodiment of the present application includes a processor, a memory and a computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing the training method of the large language model described in any of the above embodiments.
[0013] The non-volatile computer-readable storage medium of an embodiment of the present application includes a computer program. When the computer program is executed by a processor, the processor executes the large language model training method described in any of the above embodiments.
[0014] The training method of the large language model, the training device of the large language model, the computer equipment and the non-volatile computer-readable storage medium of the implementation mode of the present application introduce backup parameters in the training process, and add the regularization term of the training parameters and the backup parameters to the total loss value, that is, the second loss value, to limit the variation range of the total loss value. After obtaining the output text according to the training parameters and the training text, the first loss value can be determined according to the output text, and then the total loss value is obtained by combining the second loss value obtained after regularizing the difference between the training parameters and the backup parameters. When the training termination condition has not yet been reached, the training parameters can be updated according to the total loss value to adaptively adjust the training parameters so that the total loss value calculated according to the updated training parameters decreases, and the backup parameters are updated according to the updated training parameters and the backup parameters in the previous iteration to ensure that the update range of the backup parameters is not large. During the training process, the smaller the total loss value, the better, and the second loss value is constructed according to the training parameters and the backup parameters. Therefore, when the training parameters are updated according to the total loss value, the gap between the training parameters and the backup parameters will not be too large. In addition, the update range of each backup parameter will be limited, which can limit the update range and search range of the training parameters to increase the robustness and stability of model training, effectively improve the stability of model training, and enable large models to complete training quickly. For example, large models can converge quickly, thereby reducing training time and reducing computing resources consumed during training.
[0015] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0017] Figure 1 It is a schematic diagram of an application scenario of a large language model training method in certain embodiments of the present application;
[0018] Figure 2 is a flowchart of a method for training a large language model in certain embodiments of the present application;
[0019] Figure 3 is a flowchart of a method for training a large language model in certain embodiments of the present application;
[0020] Figure 4 is a flowchart of a method for training a large language model in certain embodiments of the present application;
[0021] Figure 5is a flowchart of a method for training a large language model in certain embodiments of the present application;
[0022] Figure 6 It is a module schematic diagram of a large language model training device in certain embodiments of the present application;
[0023] Figure 7 is a schematic diagram of the structure of a computer device of certain embodiments of the present application;
[0024] Figure 8 It is a schematic diagram of the connection status of a non-volatile computer-readable storage medium and a processor in certain embodiments of the present application. DETAILED DESCRIPTION
[0025] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as limiting the embodiments of the present application.
[0026] To facilitate understanding of this application, the terms appearing in this application are explained below:
[0027] 1. Large Language Model (LLM) refers to a deep learning model trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. Large language models can handle a variety of natural language tasks, such as text parsing, classification, question-answering, dialogue, etc., or generate text based on the parsed content, especially in the field of code generation. LLM is an important path to artificial intelligence. Large language models currently support active intervention in its generated content by writing prompts, that is, for the same question, different prompts will have different answers.
[0028] With the rapid development of artificial intelligence technology, large-scale language models play an increasingly important role in industry applications. However, in the training of large language models, there are still problems that are difficult to solve, such as unstable parameter updates and difficult to control search ranges. This will lead to large fluctuations in model parameters, and the model will deviate far from the optimal solution during the iteration process, or even collapse during training, making it difficult for the training process to reach a stable convergence state. At this time, it can be judged that the model training has failed and certain adjustments are needed, such as training the model again after adjusting the parameters. Obviously, this will lead to a long training process for large language models and require a lot of computing resources.
[0029] In addition, during the training process of large language models, overfitting is often encountered. Overfitting causes the model to perform well on the training data, but loses its generalization ability on data that has not appeared, which will seriously affect the actual application effect of the model.
[0030] Specifically, the phenomenon of overfitting is that the model overfits the training data, which causes the model to lose the ability to generalize to new data. Simply put, overfitting means that the model remembers the noise and details in the training data, but does not really learn the general rules of the data. This usually causes the model to perform poorly on new data (i.e., data that has not been seen), which usually leads to a decrease in the performance of the model on new data. The reason for overfitting may be that there is too little training data, or the model is too complex, causing the model to overfit the training data. Among them, overfitting and loss of generalization ability are closely related. Overfitting is usually the main cause of loss of generalization ability. When a model overfits the training data, it becomes too complex and remembers the noise and details in the training data instead of learning the inherent rules of the data. This causes the model to perform poorly on new data because the new data may be different from the training data.
[0031] In order to solve the above technical problems, an embodiment of the present application provides a training method for a large language model.
[0032] The following first introduces the application scenarios of the technical solution of this application. Figure 1 As shown, it is a schematic diagram of an application scenario of a large language model training method provided in an embodiment of the present application. The application scenario involves a terminal device 110 and a server 120, and the terminal device 110 can communicate with the server 120.
[0033] Figure 1 One terminal device 110 and one server 120 are shown by way of example, but other numbers of terminal devices and servers may actually be included, and this embodiment of the present application does not impose any limitation on this.
[0034] In some possible implementations, Figure 1 The server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. This embodiment of the application does not limit this.
[0035] In some possible implementations, such as Figure 1The terminal device 110 shown may be installed with an application client, and when the application client runs in the terminal device 110, data can be exchanged with the server 120. For example, the client here may specifically include: a browser client, a car client, a smart home client, a game client, a multimedia client (such as a video client), a social client, and an information client (such as a news client).
[0036] Optionally, in the embodiment of the present application, the terminal device 110 may be a device that has a rich human-computer interaction mode, has the ability to access the Internet, is usually equipped with various operating systems, and has strong processing capabilities. The terminal device 110 may be a smart phone, smart glasses, a handheld terminal, a smart TV, a tablet computer, a car terminal, etc., but is not limited thereto.
[0037] In one achievable manner, the server 120 and the terminal device 110 may interactively execute the large language model training method provided in the embodiment of the present application, or the large language model training method provided in the embodiment of the present application may be executed by the terminal device 110 or the server 120.
[0038] The following is a detailed description of the training method of the large language model of this application:
[0039] See also Figure 2 The present application embodiment provides a method for training a large language model, and the method for training a large language model includes:
[0040] Step 011: Input the training text into the large language model to generate output text;
[0041] Specifically, the parameters involved in the large language model training process include training parameters and backup parameters. The training parameters are the actual parameters used when the large language model processes the input text, such as the training text. The backup parameters are a copy of the training parameters. The parameter definition and structure are exactly the same as the training parameters. At the beginning of training, the backup parameters and the training parameters are initialized with the same initialization weights, that is, the initial values of the training parameters and the backup parameters are the same. The difference between the backup parameters and the training parameters can be regarded as the change or step size of the model parameters, and can be used as an indicator to measure the complexity of the model. When the difference is large, it means that the training parameters have changed a lot, the model may be too complex, and there is a higher risk of overfitting. In this way, during the model training process, the backup parameters can be used to assist in the update of the training parameters, and the parameter changes during the model training process can be tracked based on the backup parameters.
[0042] During the training process, the result obtained after processing the training text according to the training parameters is needed to evaluate the error between the result and the training text, so as to determine whether the training parameters need to be adjusted and the corresponding adjustment value according to the error. Therefore, at this time, the training sample needs to be input into the large language model for forward propagation to obtain the output text.
[0043] Step 012: determining a first loss value according to the output text, and performing regularization processing on the difference between the backup parameters and the training parameters of the large language model to determine a second loss value;
[0044] Specifically, the first loss value corresponding to the training parameter can be determined according to the output text, for example, by using a language model loss function, such as cross entropy loss, to determine the first loss value.
[0045] Regularization is a general term for methods used to suppress overfitting. It reduces the complexity of the model by dynamically adjusting the values of model parameters. During model training, a regularization term is usually added to constrain the range of model parameters to limit the range of changes in the total loss value and make the large language model simpler and more robust. Specifically, the regularization term added to the total loss value can impose a penalty on the model parameters, especially when the parameter value is very large or very small. This penalty can be regarded as a control of the complexity of the model, because large parameter changes may cause the model to over-fit the training data at the expense of generalization ability. Common regularization methods include L1 norm and L2 norm. The L1 norm refers to the sum of the absolute values of each element, and the L2 norm refers to the sum of the squares of each element and then taking the square root.
[0046] Since the difference between the backup parameters and the training parameters can be used as an indicator to measure the complexity of the model, the difference can be included in the regularization term, that is, the difference between the backup parameters and the training parameters of the large language model is regularized so that a penalty can be imposed on large parameter changes. That is, by regularizing the difference, the amplitude of parameter adjustment can be controlled to avoid large fluctuations in the model during training. In this way, the difference between the backup parameters and the training parameters can help control the complexity of the model, thereby reducing the risk of overfitting, thereby helping to improve the generalization ability of the model and making the large language model perform better on new data. At the same time, the difference between the backup parameters and the training parameters can also be used to limit the amplitude of changes in the total loss value, thereby limiting the update amplitude of the training parameters.
[0047] Then, the total loss value may be determined according to the first loss value and the second loss value. For example, the total loss value is determined according to the first loss value, the second loss value and the weight factor corresponding to the second loss value, wherein the formula used is as follows:
[0048]
[0049] in, is the first loss value, y is the output text, is the correct result that should be obtained when inputting the training text when the large language model converges, γ is the preset weight factor, is the second preset value, φ t is the training parameter, φ b is the backup parameter. During the training process, the optimal balance point of model complexity can be found by adjusting the preset weight factor.
[0050] Step 013: updating the training parameters according to the total loss value determined by the first loss value and the second loss value, and updating the backup parameters according to the updated training parameters and the backup parameters in the previous iteration;
[0051] Specifically, after determining the total loss value, back propagation can be performed based on the total loss value to update the training parameters. It can be understood that during the update process, the smaller the total loss value, the better, and the second loss value is composed of the difference between the backup parameter and the training parameter, so the updated training parameter will not be too far from the backup parameter. Then, the backup parameter can be updated based on the updated training parameter and the backup parameter in the previous iteration to ensure that the update amplitude of the backup parameter will not be large during the update process, and it is convenient to use in the next iteration.
[0052] It can be understood that both backup parameters and training parameters can be updated during the training process, among which backup parameters are updated slower (conservative) and training parameters are updated faster (aggressive). Introducing regularization terms in the total loss value can limit the update amplitude of parameters to be neither too large nor too small, thereby ensuring that the model update is neither too aggressive nor too conservative.
[0053] In this way, when the update amplitude of the backup parameters is not large and the training parameters are not too far away from the backup parameters during the update, the update amplitude of the training parameters will also be limited, thereby limiting the search range of the training parameters, which can effectively improve the stability of model training. At the same time, regularization can reduce the complexity of the model by reducing or sparse parameters, thereby preventing overfitting. Therefore, after updating the training parameters according to the total loss value including the regularization term (i.e., the second loss value), the occurrence of overfitting can also be suppressed.
[0054] Step 014: Re-enter the step of inputting the training text into the large language model to generate the output text until the preset training termination condition is reached.
[0055] Specifically, after completing the update of the training parameters and backup parameters, you can re-enter the step of inputting the training text into the large language model to generate the output text. At this time, the large language model will generate the output text according to the updated training parameters, and then use the output text to determine the first loss value, and use the updated training parameters and backup parameters to determine the second loss value until the preset training termination condition is reached. After the training termination condition is reached, the loop can be ended. The preset training termination conditions include the number of iterations reaching the first preset threshold, the total loss value falling below the second preset threshold, or the model evaluation accuracy reaching the third preset threshold, where the first preset threshold is the maximum number of training times during training, the second preset threshold is the maximum total loss value when the large language model converges, and the model evaluation accuracy is the minimum evaluation accuracy when the large language model converges.
[0056] For example, before reaching the training termination condition, step 011 to step 013 are executed in a loop. When executing to step 012, after obtaining the total loss value, it is first determined whether the large language model has converged according to the total loss value. After determining that the large language model has converged, the training of the large language model can be stopped, the training parameters at this time are output, and the converged large language model is put into formal use. When it is determined that the large language model has not converged, the step 013 is entered to adaptively adjust the training parameters according to the total loss value.
[0057] In this way, the regularization term in the total loss value (i.e., the second loss value) can be used to limit the variation range and search range of the training parameters, so as to effectively improve the stability of the model training process, prevent the large language model from deviating far from the optimal solution or even the training crash during the training iteration process, and enable the large language model to quickly reach the training termination conditions, for example, enable the large language model to converge quickly, thereby achieving the effect of reducing the training time and reducing the computing resources consumed during the training process.
[0058] The training method of the large language model of the implementation mode of the present application introduces backup parameters in the training process, and adds regularization terms of the training parameters and backup parameters, i.e., the second loss value, to the total loss value to limit the variation range of the total loss value. After obtaining the output text according to the training parameters and the training text, the first loss value can be determined according to the output text, and then the total loss value is obtained by combining the second loss value obtained after regularizing the difference between the training parameters and the backup parameters. When the training termination condition has not yet been reached, the training parameters can be updated according to the total loss value to adaptively adjust the training parameters so that the total loss value calculated according to the updated training parameters is reduced, and the backup parameters are updated according to the updated training parameters and the backup parameters in the previous iteration to ensure that the update range of the backup parameters is not large. During the training process, the smaller the total loss value, the better, and the second loss value is constructed according to the training parameters and the backup parameters. Therefore, when the training parameters are updated according to the total loss value, the gap between the training parameters and the backup parameters will not be too large. Combined with the fact that the update range of the backup parameters is limited each time, the update range and search range of the training parameters can be limited to increase the robustness and stability of the model training, effectively improve the stability of the model training, and enable large models to complete training quickly, for example, enabling large models to converge quickly, thereby reducing training time and reducing the computing resources consumed during training. At the same time, the regularization process itself has the effect of suppressing overfitting, so after adjusting the training parameters using the total loss value including the second loss value, the occurrence of overfitting can also be reduced.
[0059] In addition, industry knowledge data is difficult to obtain, and high-quality data requires industry experts to label, resulting in scarce data for training large industry models. These large industry models often encounter overfitting problems during the training process, especially when dealing with limited industry data sets and small batches of data. The overfitting phenomenon causes the model to perform well on training data, but loses its generalization ability on unseen data, which seriously affects the actual application effect of the model. The training method of the present application can reduce the occurrence of overfitting, so that the present application can be applied to the overfitting suppression of large industry models. Of course, overfitting may also occur during the training process of large language models in other fields, so that the present application can also be migrated to fields such as general large models and multimodal large models, thereby making the present application highly scalable.
[0060] See also Figure 3 In some embodiments, step 012: determining a first loss value according to the output text, and performing regularization processing on the difference between the backup parameter and the training parameter of the large language model to determine a second loss value, includes:
[0061] Step 0121: Determine a first loss value according to a preset label of the training text and the output text;
[0062] Step 0122: Determine a second loss value based on the square root of the square of the difference between the backup parameter and the training parameter.
[0063] Specifically, the training text has a corresponding preset label, and the preset label is the correct result or target result output according to the training text when the large language model converges. It can be understood that the difference between the output text generated by the large language model based on the training text and the preset label can be used to reflect whether the large language model converges, and the difference can also be used to make targeted adjustments to the parameters later. Therefore, at this time, the first loss value can be determined based on the difference between the output text and the preset label. Among them, commonly used loss functions include cross entropy loss, mean square error, etc., and the specific choice depends on the task type and goal.
[0064] The L2 norm can be used to prevent model overfitting. Intuitively, L2 regularization is a severe penalty for large-value weight vectors. Therefore, the L2 norm can be used to regularize the difference between the backup parameters and the training parameters of the large language model to reduce the complexity of the model and avoid overfitting. At the same time, it can also limit the update range of the total loss value, thereby facilitating the subsequent limit on the update range of the parameters. At this time, the second loss value needs to be determined based on the square root of the square of the difference between the backup parameters and the training parameters. The formula used is as follows:
[0065]
[0066] Among them, φ t is the training parameter, φ b To backup parameters, n is the current iteration number.
[0067] Then, the total loss value can be determined according to the first loss value and the second loss value to add a regularization term to the total loss value, thereby facilitating accurate updating of training parameters and backup parameters according to the total loss value.
[0068] It can be found that compared with the existing large model training process, the training process of this application does not change the main logic framework of the existing training process. The existing large model training process determines the total loss value based on the training text and output text of the large language model, and this application adds a regularization term to the total loss value on this basis. Therefore, when applying the training scheme of this application, you only need to add a regularization term to the total loss value, which has the advantage of plug-and-play.
[0069] See also Figure 4 In some embodiments, step 013: updating the backup parameters according to the updated training parameters and the backup parameters in the previous iteration includes:
[0070] Step 0131: Determine an update value based on the preset momentum hyperparameter, the updated training parameters and the backup parameters in the previous iteration to update the backup parameters. The size of the momentum hyperparameter is negatively correlated with the size of the update value.
[0071] Specifically, the backup parameters can be updated by using a sliding average method. The formula used is as follows:
[0072]
[0073] Among them, β is the preset momentum hyperparameter, and for the first update of the backup parameters,
[0074] According to formula (3), it can be deduced that the update of backup parameters will be updated according to all historical backup parameters, for example right After the calculation formula is expanded, we can get
[0075] Since β is less than 1, as the power gradually increases, the power of β will gradually decrease. It is generally believed that after the power of β decays to 1 / e, the corresponding data item can be ignored, and the smaller β is, the faster the power of β will decay to 1 / e. Therefore, the smaller β is, the more data items can be ignored in the expression of the backup parameter, the fewer data items are used in weighted averaging, the smaller the power of β is, and the larger the backup parameter obtained after multiplication. In this way, it can be found that the size of the momentum hyperparameter is negatively correlated with the size of the update value, that is, the larger the momentum hyperparameter is, the smaller the update value is, and the smaller the update amplitude of the backup parameter is. Therefore, the momentum hyperparameter can also be used to limit the update amplitude of the backup parameter.
[0076] After setting the momentum hyperparameters as needed, the update value can be determined based on the updated training parameters and the backup parameters in the previous iteration, and the backup parameters can be updated based on the update value. In this way, the combination of the three can ensure that the backup parameters can be adjusted accordingly according to the total loss value on the one hand, and on the other hand, ensure that the update amplitude of the backup parameters will not be too large.
[0077] See also Figure 5 In some embodiments, step 013: updating the training parameters according to the total loss value determined by the first loss value and the second loss value, comprises:
[0078] Step 0132: Determine the gradient of the training parameters according to the total loss value;
[0079] Step 0133: Update the training parameters according to the gradient and the preset learning rate.
[0080] Specifically, the gradient is a vector whose direction points to the direction in which the function value increases the fastest, and its magnitude indicates the speed at which the function value increases. For a specific point of a function, its gradient direction indicates the direction in which the function value increases the most rapidly from that point. It can be understood that when the independent variable changes along the gradient direction, the function value will become larger and larger. Conversely, the opposite direction of the gradient is the direction in which the function value decreases, and when it changes along the opposite direction of the gradient, the function value will become smaller and smaller. Therefore, after determining the gradient according to the training parameters, the training parameters can determine the gradient direction according to the gradient, and the training parameters can change in the opposite direction of the gradient direction, so that the total loss value calculated according to the updated training parameters decreases until the preset training termination condition is reached. The learning rate can be used to limit the amplitude of each change of the training parameters in the opposite direction of the gradient direction, that is, the learning rate can also be used to limit the amplitude of the change of the training parameters and the search range. In summary, the gradient is used to indicate the direction of change of the training parameters, and the learning rate is used to determine the amplitude of each iteration change of the training parameters.
[0081] Then, after calculating the loss value, the gradient of the training parameters can be determined according to the total loss value, for example, the gradient can be determined by using the chain rule and the total loss value to determine the direction of change of the training parameters. Then, according to the gradient and the preset learning rate, the change amplitude of the training parameters in the gradient direction can be determined, and then the training parameters can be updated according to the determined gradient direction, change amplitude and the current value of the training parameters.
[0082] The update process can be expressed as: Among them, Optimizer is a model parameter optimizer, such as stochastic gradient descent SGD.
[0083] In this way, the gradient is determined according to the total loss value, and after updating the training parameters in combination with the gradient and the preset learning rate, it can ensure that after the training parameters are updated, the total loss value obtained in the next iterative calculation can be reduced. On the other hand, the learning rate can be used to limit the change range and search range of the training parameters to effectively improve the stability of the model training, thereby saving training time and computing resources consumed by training. At the same time, the second loss value itself can also be used to suppress overfitting to reduce the occurrence of overfitting.
[0084] See also Figure 6In order to facilitate better implementation of the large language model training method of the embodiment of the present application, the embodiment of the present application also provides a large language model training device 10. The large language model training device 10 may include an input module 11, a determination module 12, an update module 13 and a loop module 14. The input module 11 is used to input a training text into the large language model to generate an output text. The determination module 12 is used to determine a first loss value based on the output text, and to regularize the difference between the backup parameters and the training parameters of the large language model to determine a second loss value. The update module 13 is used to update the training parameters based on the total loss value determined by the first loss value and the second loss value, and to update the backup parameters based on the updated training parameters and the backup parameters in the previous iteration. The loop module 14 is used to re-enter the step of inputting the training text into the large language model to generate an output text until a preset training termination condition is reached.
[0085] The determination module 12 is specifically used to determine a first loss value according to a preset label of the training text and the output text; and to determine a second loss value according to a square root of a square of a difference between a backup parameter and a training parameter.
[0086] The updating module 13 is specifically used to determine the update value according to the preset momentum hyperparameter, the updated training parameter and the backup parameter in the previous iteration to update the backup parameter, and the size of the momentum hyperparameter is negatively correlated with the size of the update value.
[0087] The updating module 13 is specifically used to determine the gradient of the training parameters according to the total loss value; and quantitatively update the training parameters according to the gradient and a preset learning rate.
[0088] The above text describes the training device 10 for a large language model from the perspective of a functional module in conjunction with the accompanying drawings. The functional module can be implemented in hardware form, can be implemented by instructions in software form, or can be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit in the processor and / or the instructions in software form. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware coding processor for execution, or can be completed by a combination of hardware and software modules in the coding processor. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps in the above method embodiment in conjunction with its hardware.
[0089] See also Figure 7The computer device 100 of the embodiment of the present application includes a processor 20, a memory 30 and a computer program, wherein the computer program is stored in the memory 30 and executed by the processor 20, and the computer program includes instructions for executing the training method of the large language model of any of the above embodiments.
[0090] Optionally, the computer device 100 can be any device with image processing capabilities, such as a server or a terminal device (such as a mobile phone, a tablet computer, a display device, a laptop computer, a smart watch, a head-mounted display device, a game console, etc.).
[0091] Optionally, the computer device 100 can also be a combined system of a terminal device and a server, where the terminal device is used to obtain scene description information, the server is used to store the model library, and the large language model can be deployed to the server. After the terminal device obtains the scene description information, it sends it to the server. Then, after the server obtains the address of the corresponding target model file, it generates a scene code based on the large language model and sends the scene code to the terminal device. Then, the browser of the terminal device runs the scene code to implement 3D rendering to generate and display the 3D scene model.
[0092] It should be understood that the various components in the computer device 100 are connected via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.
[0093] See also Figure 8 The embodiment of the present application also provides a computer-readable storage medium 300 on which a computer program 310 is stored. When the computer program 310 is executed by the processor 20, the steps of the training method of a large language model of any of the above-mentioned embodiments are implemented. For the sake of brevity, they are not repeated here.
[0094] In the description of this specification, the descriptions with reference to the terms "certain embodiments", "in an example", "exemplarily", etc., mean that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0095] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0096] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A training method for a large language model, It is characterized in that include: Inputting training text into the large language model to generate output text; Determine a first loss value according to the output text, and perform regularization processing on the difference between the backup parameter and the training parameter of the large language model to determine a second loss value; updating the training parameter according to the total loss value determined by the first loss value and the second loss value, and updating the backup parameter according to the updated training parameter and the backup parameter in the previous iteration, wherein the backup parameter is updated by a sliding average method to limit the update amplitude of the backup parameter; Re-entering the step of inputting the training text into the large language model to generate the output text until a preset training termination condition is reached; The determining of the first loss value according to the output text and regularizing the difference between the backup parameter and the training parameter of the large language model to determine the second loss value includes: Determining the first loss value according to the preset label of the training text and the output text; Regularizing the difference between the backup parameter and the training parameter of the large language model by using an L2 norm, wherein the L2 norm refers to the sum of the squares of each element and then calculating the square root, and determining the second loss value according to the square root of the sum of the squares of the difference between the backup parameter and the training parameter; The total loss value is determined according to the first loss value, the second loss value and a weight factor corresponding to the second loss value.
2. The method for training a large language model according to claim 1, It is characterized in that Updating the backup parameters according to the updated training parameters and the backup parameters in the previous iteration includes: An update value is determined according to a preset momentum hyperparameter, an updated training parameter, and a backup parameter in a previous iteration to update the backup parameter, and a magnitude of the momentum hyperparameter is negatively correlated with a magnitude of the update value.
3. The method for training a large language model according to claim 1, It is characterized in that The updating of the training parameter according to the total loss value determined by the first loss value and the second loss value comprises: Determine the gradient of the training parameter according to the total loss value; The training parameters are updated according to the gradient and a preset learning rate.
4. The method for training a large language model according to claim 1, It is characterized in that The training parameter and the backup parameter have the same initial value.
5. A large language model training device, the large language model training device is used to execute the large language model training method according to any one of claims 1 to 4, It is characterized in that An input module, used for inputting training text into the large language model to generate output text; A determination module, configured to determine a first loss value according to the output text, and perform regularization processing on a difference between a backup parameter and a training parameter of the large language model to determine a second loss value; An updating module, configured to update the training parameters according to a total loss value determined by the first loss value and the second loss value, and to update the backup parameters according to the updated training parameters and the backup parameters in a previous iteration; and A loop module, used for re-entering the step of inputting the training text into the large language model to generate the output text until a preset training termination condition is reached; The determination module is specifically used to: determine the first loss value according to the preset label of the training text and the output text; Regularizing the difference between the backup parameter and the training parameter of the large language model by using an L2 norm, wherein the L2 norm refers to the sum of the squares of each element and then calculating the square root, and determining the second loss value according to the square root of the sum of the squares of the difference between the backup parameter and the training parameter; The total loss value is determined according to the first loss value, the second loss value and a weight factor corresponding to the second loss value.
6. A computer device, It is characterized in that include: Processor, memory; and A computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing the large language model training method according to any one of claims 1 to 4.
7. A non-volatile computer-readable storage medium containing a computer program, wherein when the computer program is executed by a processor, the processor executes the large language model training method described in any one of claims 1 to 4.
