Natural language processing model training method and device and computer equipment
By combining different video memory optimization methods and optimizing the use of video memory, the problem that video memory cannot support large-scale natural language processing model training is solved, and efficient model training is achieved.
Patent Information
- Application Number
- CN202310398806.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-04
- Publication Date
- 2024-10-15
AI Technical Summary
In the existing technology, video memory cannot effectively support the training of large-scale natural language processing models, resulting in limited training speed.
By obtaining the target video memory and hardware environment required for the natural language processing model, combined with different video memory optimization methods (such as tensor parallel method, sequence parallel method, zero redundancy optimizer method, pipeline parallel method, video memory offloading method and activation recalculation method) combination, determine the target video memory optimization combination, optimize the use of video memory, and conduct model training.
It improves the training speed of natural language processing models, can support model training with hundreds of billions of parameters, reduces video memory usage, and improves training efficiency.
Smart Images

Figure CN118780282A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a natural language processing model training method, apparatus and computer equipment. Background Art
[0002] With the development of artificial intelligence technology, the scale of natural language processing models used in natural language processing (NLP) is getting larger and larger, and is growing rapidly. In some cases, the parameters of the model may even reach hundreds of billions. However, in the process of training such large-scale models, the bottleneck problem of video memory is becoming more and more obvious, making it difficult to support the training of large-scale natural language processing models. Summary of the invention
[0003] The embodiments of the present application provide a natural language processing model training method, apparatus, computer equipment, computer-readable storage medium, and computer program product, which can solve the problem of video memory being unable to support.
[0004] In a first aspect, the present application provides a natural language processing model training method. The method comprises:
[0005] Get the target video memory and hardware environment required by the natural language processing model;
[0006] Determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training;
[0007] In combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained.
[0008] In a second aspect, the present application also provides a natural language processing model training device. The device comprises:
[0009] The video memory requirement determination module is used to obtain the target video memory required by the natural language processing model and the hardware environment in which it is located;
[0010] A video memory optimization combination determination module, used to determine a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training;
[0011] The model training module is used to perform model training on the natural language processing model to be trained by combining various video memory optimization methods in the target video memory optimization combination.
[0012] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0013] Get the target video memory and hardware environment required by the natural language processing model;
[0014] Determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training;
[0015] In combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained.
[0016] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0017] Get the target video memory and hardware environment required by the natural language processing model;
[0018] Determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training;
[0019] In combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained.
[0020] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0021] Get the target video memory and hardware environment required by the natural language processing model;
[0022] Determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training;
[0023] In combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained.
[0024] The above-mentioned natural language processing model training method, apparatus, computer equipment, computer-readable storage medium and computer program product obtain the target video memory amount and the hardware environment required for the natural language processing model, determine the target video memory optimization combination from a plurality of candidate video memory optimization combinations obtained by combining different video memory optimization methods according to the target video memory amount and the hardware environment, and then perform model training on the natural language processing model to be trained in combination with various video memory optimization methods in the target video memory optimization combination. Video memory optimization can be performed during the model training process by using various video memory optimization methods in the target video memory optimization combination that meet the target video memory amount and the hardware environment, thereby solving the problem that the device's video memory cannot support the training of large-scale natural language processing models. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. 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 paying creative work.
[0026] Figure 1 is a flowchart of a natural language processing model training method in one embodiment;
[0027] Figure 2 is a schematic diagram of a tensor parallel method in one embodiment;
[0028] Figure 3 is a schematic diagram of a serial parallel method in one embodiment;
[0029] Figure 4 is a schematic diagram of a zero redundancy optimizer method in one embodiment;
[0030] Figure 5 is a schematic diagram of combining the pipeline parallel method and the tensor parallel method in one embodiment;
[0031] Figure 6 A schematic diagram of a functional module configuration in one embodiment;
[0032] Figure 7 A schematic diagram of the overall process of model training in one embodiment;
[0033] Figure 8 A schematic diagram of a process of reinforcement learning training in one embodiment;
[0034] Fig. 9 It is a model output result before model training in one embodiment;
[0035] Fig.10 The model output result after model training in one embodiment;
[0036] Fig.11 is a structural block diagram of a natural language processing model training device in one embodiment;
[0037] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0039] In some embodiments, Figure 1 As shown, a natural language processing model training method is provided. This embodiment uses the method applied to a server as an example. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. Among them, the terminal can be but is not limited to various personal computers, laptops, smart phones or tablet computers. The server can be implemented with an independent server or a server cluster composed of multiple servers. In this embodiment, the method includes the following steps:
[0040] Step 102, obtaining the target video memory required by the natural language processing model and the hardware environment in which it is located.
[0041] Among them, the natural language processing model is a model used for natural language processing. Natural language processing (NLP) is a process that uses computer technology to analyze, understand and process natural language with language as the object. The target video memory refers to the amount of storage space and processor required for model training of the natural language processing model to be trained. The hardware environment refers to the hardware environment of the server used for model training of the natural language processing model to be trained.
[0042] In some embodiments, the target amount of video memory may include at least one of the number of graphics processing units (GPUs) required for model training of the natural language processing model to be trained, the size of the video memory of the graphics processor, and the size of the memory of the central processing unit (CPU).
[0043] In some embodiments, the server may obtain a model structure of a natural language processing model to be trained, calculate a parameter quantity in the natural language processing model according to the model structure, and determine a target video memory quantity required for the natural language processing model according to the parameter quantity.
[0044] Step 104, determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during the model training process.
[0045] In some embodiments, the video memory optimization method may include at least one of a tensor parallel method, a serial parallel method, a zero-redundancy optimizer method, a pipeline parallel method, a video memory offloading method, and an activation recalculation method.
[0046] Among them, Tensor parallelism is a memory optimization method that divides specific operators in the model into different GPUs for model training in parallel. Sequence parallelism is a memory optimization method that divides the embedding layer in the model into different GPUs for model training in parallel. ZeRO optimizer is a memory optimization method that divides the optimizer state, gradient and model parameters in the model into different GPUs for model training in parallel. Pipeline parallelism is a memory optimization method that divides the layers in the model into different GPUs for model training. Memory offload is a memory optimization method that unloads the temporarily unsuitable model during model training and reloads it when it is used again. Activation recomputation is a memory optimization method that does not save the intermediate activation values during the forward propagation process and recalculates the intermediate activation values during the back propagation process during model training.
[0047] In some embodiments, various video memory optimization methods may be combined in advance to obtain multiple candidate video memory optimization combinations. Each candidate video memory optimization combination may include at least one video memory optimization method. Various video memory optimization methods may be combined arbitrarily.
[0048] In some embodiments, the user may select a candidate video memory optimization combination from multiple candidate video memory optimization combinations to set as the target video memory optimization combination based on the target video memory amount and the hardware environment. In other embodiments, the server may determine the target video memory optimization combination from multiple candidate video memory optimization combinations based on the target video memory amount and the hardware environment.
[0049] Step 106 , combining various video memory optimization methods in the target video memory optimization combination to perform model training on the natural language processing model to be trained.
[0050] In some embodiments, the server may combine various video memory optimization methods in the target video memory optimization combination to optimize the use of video memory during the model training of the natural language processing model to be trained.
[0051] The above-mentioned natural language processing model training method obtains the target video memory required by the natural language processing model and the hardware environment in which it is located, determines the target video memory optimization combination from a plurality of candidate video memory optimization combinations obtained by combining different video memory optimization methods according to the target video memory and the hardware environment, and then combines various video memory optimization methods in the target video memory optimization combination to perform model training on the natural language processing model to be trained, and can optimize video memory during the model training process by using various video memory optimization methods in the target video memory optimization combination that meet the target video memory and the hardware environment, thereby solving the problem that the video memory of the device cannot support the training of large-scale natural language processing models, and improving the training speed of the natural language processing model. Assuming that the number of parameters of the model is S, in traditional model training, the video memory of the Adam optimizer state occupies 12S bytes, the gradient occupies 2S bytes, and the model weight occupies 2S bytes, which occupies a total of 16S bytes of video memory. Using the mainstream A100 GPU card for training, a total of 80GB of video memory, if the video memory optimization combination provided in the natural language processing model training method in each embodiment of the present application is not used, then at most 80GB / 16B=5G (5 billion) of parameters can be trained. If the video memory optimization combination provided in the natural language processing model training method in each embodiment of the present application is used, it only takes 100G*16B / 80G=20 graphics cards to expand to 100 billion parameters in theory. In addition, in reinforcement learning, if the video memory optimization combination is not used, 3 models (i.e., incentive model, behavior prediction network, and evaluation network) need to be loaded in the GPU at the same time, then only 5 billion / 3=1.6 billion parameter models can be trained. In the case of using the video memory unloading method, only two models need to be loaded at the same time, and 20*2=40 cards can be used to complete the reinforcement learning training of the 100 billion model.
[0052] In some embodiments, a target video memory optimization combination is determined from a plurality of candidate video memory optimization combinations based on a target video memory amount and a hardware environment, including: determining a video memory restriction condition based on the hardware environment; removing, from each candidate video memory optimization combination, candidate video memory optimization combinations that do not satisfy the video memory restriction condition and the target video memory amount to obtain remaining candidate video memory optimization combinations; determining a training speed for the remaining candidate video memory optimization combinations; and determining the target video memory optimization combination from the remaining candidate video memory optimization combinations based on the training speed.
[0053] In some embodiments, the server may determine the video memory restriction condition according to its own hardware environment. The video memory restriction condition may include at least one of the maximum number of graphics processors that the server can provide, the size of the video memory of the graphics processor, and the size of the memory of the central processing unit.
[0054] In some embodiments, the server can determine the amount of video memory required for each candidate video memory optimization combination, and then compare the amount of video memory required for each candidate video memory optimization combination with the video memory restriction conditions and the target video memory amount, and remove the candidate video memory optimization combinations that do not meet the video memory restriction conditions and the target video memory amount from the candidate video memory optimization combinations to obtain the remaining candidate video memory optimization combinations.
[0055] In some embodiments, the server can perform preliminary model training based on each remaining candidate memory optimization combination to obtain the training speed of the remaining candidate memory optimization combination. It can be understood that preliminary model training refers to a short model training based on the remaining candidate memory optimization combination to test the training speed, rather than executing a complete model training process.
[0056] In some embodiments, the server may sort the remaining candidate video memory optimization combinations in order from large to small according to the required video memory amount, and then determine the training speeds corresponding to the remaining candidate video memory optimization combinations in the front preset number, and select the candidate video memory optimization combination with the largest training speed from the remaining candidate video memory optimization combinations in the front preset number according to the training speed as the target video memory optimization combination.
[0057] It can be understood that because the larger the amount of video memory required by the video memory optimization combination, the faster the training speed of the video memory optimization combination is likely to be, therefore, the remaining candidate video memory optimization combinations ranked in the front preset number are selected to determine the target video memory optimization combination.
[0058] In the above embodiment, candidate video memory optimization combinations that do not meet the video memory restriction condition and the target video memory amount are removed from each candidate video memory optimization combination, and then the training speeds of the remaining candidate video memory optimization combinations are determined, and the target video memory optimization combination is determined from the remaining candidate video memory optimization combinations based on the training speed, so that the target video memory optimization combination that the video memory can meet and has the fastest training speed can be automatically determined, thereby improving the efficiency of determining the target video memory optimization combination, solving the problem that the device's video memory cannot support the training of large-scale natural language processing models, and improving the training speed of natural language processing models.
[0059] In some embodiments, the target video memory optimization combination includes at least one of tensor parallelism, sequence parallelism, zero redundancy optimizer method, pipeline parallelism, video memory unloading method and activation recalculation method; in combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained, including at least one of the following: according to at least one of tensor parallelism, sequence parallelism, zero redundancy optimizer method and pipeline parallelism, the natural language processing model to be trained is divided into video memories corresponding to different graphics processors; through each graphics processor, based on the model part of the natural language processing model to be trained divided into the corresponding video memory, parallel model training is performed; during the model training process, according to the video memory unloading method, the model that is not used temporarily is unloaded, and reloaded when it is used again; according to the activation recalculation method, the intermediate activation value of the checkpoint is not saved during the forward propagation process, and the intermediate activation value of the checkpoint is recalculated during the backward propagation process.
[0060] In some embodiments, the server can divide the natural language processing model to be trained into video memories corresponding to different graphics processors according to at least one of tensor parallelism, serial parallelism, zero redundancy optimizer method and pipeline parallelism, and then perform parallel model training through each graphics processor based on the model part of the natural language processing model to be trained divided into the corresponding video memory.
[0061] In some embodiments, the segmented model part may include at least one of a target operator, an embedding layer, a layer, an optimizer state, a gradient, and a model parameter in a natural language processing model. The target operator is an operator that needs to be segmented in a preset natural language processing model.
[0062] In some embodiments, the server can unload the temporarily unused model according to the video memory unloading method during the model training process, and reload it when it is used again. For example, the server can load and use the incentive model in the process of evaluating the predicted answer result through the incentive model, and after use, unload the incentive model, and then optimize the behavior prediction network and the evaluation network. After optimization, reload the incentive model to evaluate the next predicted answer result.
[0063] In some embodiments, during the model training process, the server may follow the activation recalculation method, not save the intermediate activation values of the checkpoint during the forward propagation process, and recalculate the intermediate activation values of the checkpoint during the backward propagation process.
[0064] In some embodiments, the server can use the torch.utils.checkpoint package in pytorch (a machine learning library) to save checkpoints. Checkpoints in PyTorch are implemented by rerunning the forward propagation calculation of each checkpoint during the backpropagation process.
[0065] In some embodiments, the server can run the incoming function in torch.no_grad mode in the forward propagation, that is, the intermediate activation values are not saved, but the input tuple and function parameters are saved. In the reverse propagation, the saved input tuple and function parameters are retrieved, and the forward propagation is recalculated on the function, the intermediate activation values are tracked, and then the gradient is calculated based on the intermediate activation values to implement model training.
[0066] In the above embodiment, unlike the conventional method of saving all the intermediate activation values of the entire calculation graph for calculating the back propagation, the intermediate activation values of the detection points are not saved during the forward propagation process according to the activation recalculation method, and the intermediate activation values of the detection points are recalculated during the back propagation process, thereby avoiding excessive occupation of the video memory, achieving video memory optimization, and improving the model training speed. According to the video memory unloading method, the temporarily unused model is unloaded and reloaded when it is used again, thereby avoiding excessive occupation of the video memory, achieving video memory optimization, and improving the model training speed. The natural language processing model to be trained is divided into the video memories corresponding to different graphics processors, and each graphics processor is used to perform parallel model training based on the model part of the natural language processing model to be trained that is divided into the corresponding video memory, which can relieve the pressure of a single video memory and improve the model training speed.
[0067] In some embodiments, the natural language processing model to be trained is divided into video memories corresponding to different graphics processors according to at least one of tensor parallelism, serial parallelism, zero-redundancy optimizer method and pipeline parallelism, including at least one of the following: according to the tensor parallelism, the target operator in the natural language processing model to be trained is divided into video memories corresponding to different graphics processors in parallel; according to the serial parallelism, the embedding layer in the natural language processing model to be trained is divided into video memories corresponding to different graphics processors in parallel; according to the zero-redundancy optimizer method, the optimizer state, gradient and model parameters in the natural language processing model to be trained are divided into video memories corresponding to different graphics processors in parallel; according to the pipeline parallelism, the layers in the natural language processing model to be trained are divided into video memories corresponding to different graphics processors.
[0068] In some embodiments, the video memory corresponding to the image processor to which the image is divided may be at least two.
[0069] Figure 2 The figure schematically shows how to divide the target operator in the natural language processing model into parallel graphics memories corresponding to different graphics processors. The figure shows that the target operator is divided into parallel graphics memories corresponding to GPU1 and GPU2. It can also be divided into graphics memories corresponding to more GPUs.
[0070] Figure 3 The figure schematically shows how to divide the embedding layer in the natural language processing model into the video memory corresponding to different graphics processors in parallel. In the example in the figure, the data parallelism is 2 and the model parallelism is 2, that is, model1 and model2 are the same natural language processing models, and different training samples can be input to model1 and model2 in parallel to perform parallel model training and gradient synchronization. The various graphics in the figure represent the matrix parameters in the embedding layer of the natural language processing model, and the various matrix parameters in the embedding layer are divided into the video memory corresponding to different graphics processors, that is, the 8 matrix parameters in model1 are divided into GPU0, GPU1, GPU4, GPU5, GPU8, GPU9, GPU12 and GPU13 respectively, and the 8 matrix parameters in model2 are divided into GPU2, GPU3, GPU6, GPU7, GPU10, GPU11, GPU14 and GPU15 respectively. Figure 3 Every two identical graphs in is a data parallel group, for example Figure 3 The ☆1 and ☆2 in the figure are a set of data parallel groups, which are input into the embedding layers of model1 and model2 in parallel respectively.
[0071] In some embodiments, the server may further split the optimizer state, gradient, and model parameters of the model part in the data parallel group according to the zero-redundancy optimizer method. The zero-redundancy optimizer method includes three stages, the first stage is the segmentation of the optimizer state, the second stage is the segmentation of the gradient, and the third stage is the segmentation of the model parameters. Figure 4 As shown, P os Corresponding to the first stage, P os+g Corresponding to the second stage, P os+g+p Corresponding to the third stage, the optimizer state, gradients, and model parameters are finally split in parallel into the video memory of multiple GPUs.
[0072] like Figure 5 As shown, the layers in the natural processing model can be divided into the video memories corresponding to different graphics processors according to the pipeline parallel method, for example: the pipeline partition #1 in the figure is divided into the video memory of one graphics processor, and the pipeline partition #2 is divided into the video memory of another graphics processor. Then, at least one of the target operator, matrix parameter, optimizer state, gradient and model parameter in the layer can be further divided by combining at least one of the tensor parallel method, the sequence parallel method and the zero redundancy optimizer method. For example: Figure 5 The tensor parallel method is further used in the process to further divide the target operators in pipeline partition #1 and pipeline partition #2 into the video memories of different graphics processors, that is, the tensor partition #1 and tensor partition #2 in pipeline partition #1 and pipeline partition #2 are respectively divided into the video memories of different graphics processors.
[0073] In the above embodiment, the natural language processing model to be trained is divided into the video memories corresponding to different graphics processors, and the model part of the natural language processing model to be trained divided into the corresponding video memories is used for parallel model training, which can relieve the pressure of a single video memory and improve the model training speed. A variety of division methods can be combined arbitrarily to flexibly adapt to different application scenarios.
[0074] In some embodiments, the natural language processing model to be trained includes a behavior prediction network and an evaluation network; model training is performed on the natural language processing model to be trained, including: obtaining training samples, and a pre-trained basic model and excitation model; configuring the initial state of the behavior prediction network as the basic model, and configuring the initial state of the evaluation network as the excitation model; iteratively optimizing the behavior prediction network and the evaluation network according to the training samples, the evaluation results of the excitation model and the evaluation results of the evaluation network after each optimization until the training is completed, thereby obtaining the trained behavior prediction network and evaluation network; the evaluation result of the excitation model is the evaluation result of the answer result predicted by the behavior prediction network.
[0075] Among them, the reward model is a model used to evaluate the predicted answer results in reinforcement learning training to determine the evaluation results. The behavior prediction network is a network used to predict the answer results based on the sample prompt words in reinforcement learning training. The evaluation network is a network used to evaluate the sample prompt words in reinforcement learning training.
[0076] In some embodiments, the training samples, as well as the pre-trained base model and the excitation model, can be input into the controller (trainer). The server can configure the initial state of the behavior prediction network as the base model and the initial state of the evaluation network as the excitation model through the controller; according to the evaluation results of the training samples, the excitation model and the evaluation results of the evaluation network after each optimization, the behavior prediction network and the evaluation network are iteratively optimized until the training is completed, and the trained behavior prediction network and evaluation network are obtained. In some embodiments, the sample prompt words can be obtained from the file through the prompt word downloader as training samples. For example, the format of the training sample can be:
[0077] Prompt1: Thousands of ships pass by the sunken boat
[0078] Prompt2: Introduce Li Bai ...
[0080] The controller (trainer) is used to control the reinforcement learning process. The controller can provide a function interface, which is used to pass in training samples, pre-trained basic models and incentive models, and then the controller can start reinforcement learning training, shielding the implementation details of reinforcement learning.
[0081] For example, you can pass training samples, pre-trained base models and incentive models to the controller using the following code:
[0082] trainer=RLHFTrainer(
[0083] palm=staracc_model,
[0084] reward_model=reward_model,
[0085] prompt_token_ids=prompts,
[0086] config=config,
[0087] minibatch_size=20,
[0088] actor_lr=1e-6,
[0089] critic_lr=1e-4, )
[0091] like Figure 6 As shown in the figure, the architecture adopts a clear division of functional modules, which can easily pass data to the controller and start reinforcement learning training. Simply execute the shell file in the scripts folder to start distributed reinforcement learning training with one click.
[0092] In some embodiments, Figure 7 As shown, before obtaining the training sample, and the pre-trained basic model and the excitation model, the server can perform step 1: according to the first training sample, supervised model training is performed on the basic model to be trained to obtain a trained basic model. The first training sample may include multiple sample prompts and corresponding answer result labels.
[0093] In some embodiments, Figure 7 As shown, before obtaining the training samples, and the pre-trained basic model and excitation model, the server may perform step 2: according to the second training sample, supervised model training is performed on the excitation model to be trained to obtain a trained excitation model. The second training sample may include multiple groups of sample prompt words and sample answers, as well as corresponding evaluation result labels.
[0094] For example, the second training sample may be in the form of:
[0095] Seq1: Thousands of ships pass by the sunken boat, and thousands of trees bloom in front of the dead tree. Label1: 4
[0096] Seq2: Thousands of ships have passed by the sunken boat, and who will I take the shadow from? Labels2: 2
[0097] Among them, "A thousand sails pass by the side of the sunken boat" in Seq1 represents the sample prompt word, "A thousand trees bloom in front of the dead tree" represents the sample answer, and "4" represents the corresponding evaluation result label. "A thousand sails pass by the side of the sunken boat" in Seq2 represents the sample prompt word, "Who can I take the shadow of" represents the sample answer, and "2" represents the corresponding evaluation result label.
[0098] In some embodiments, a Reward Model dataloader may be used to load the second training sample. The Reward Model dataloader supports the data set format of the second training sample and supports multiple GPUs reading the data set for distributed parallel training.
[0099] In some embodiments, Figure 7As shown, the server can use the PPO algorithm (a policy-based reinforcement learning algorithm using two neural networks) to perform reinforcement learning training on the natural language processing model to be trained. The server can create a natural language processing model to be trained (actor-critic) based on the basic model and the incentive model, configure the initial state of the behavior prediction network as the basic model, and configure the initial state of the evaluation network as the incentive model. The obtained natural language processing model to be trained includes a behavior prediction network (actor network) and an evaluation network (critic network).
[0100] In some embodiments, Figure 8 As shown in the figure, during the model training process, the server can predict the answer result according to the sample prompt words in the training sample through the behavior prediction network, and then evaluate the predicted answer result through the incentive model to obtain the evaluation result. The current sample prompt word and the next sample prompt word in the training sample are evaluated through the evaluation network to obtain the evaluation result, and then the loss value of the behavior prediction network and the evaluation network is obtained according to the evaluation result and the evaluation result. The behavior prediction network and the evaluation network are iteratively optimized and adjusted according to each loss value until the iteration stop condition is met, and the trained behavior prediction network and the evaluation network are obtained. Figure 8 NN1 in the figure represents the behavior prediction network, NN2 represents the evaluation network, and env represents the incentive model.
[0101] In some embodiments, after the model training is completed, the server can generate multiple answer results based on the input prompt words through the trained behavior prediction network, and then evaluate each answer result through the pre-trained incentive model, and select the final answer result from the multiple answer results based on the evaluation results.
[0102] Fig. 9 This is the answer output by the natural language processing model for the prompt word "A thousand sails pass by the side of a sunken boat" before reinforcement learning training using the above method. Fig.10 This is the answer output by the natural language processing model for the prompt word "A thousand sails pass by the side of a sunken boat" after reinforcement learning training using the above method. It can be seen that after reinforcement learning training, the natural language processing model can more accurately output the next sentence of "A thousand sails pass by the side of a sunken boat" "A thousand trees bloom in front of a dead tree."
[0103] In the above embodiment, a complete process for reinforcement learning training of the natural language processing model is provided, which can achieve efficient and accurate natural language processing model training, and the user only needs to provide a basic model and training samples to perform model training, which is easy to operate.
[0104] In some embodiments, before obtaining training samples, and pre-trained basic models and excitation models, the method also includes: distinguishing the input sample prompt words and sample answers through an additional embedding layer in the excitation model to be trained, and adding the distinction result to the output result of the embedding layer in the excitation model to be trained, and inputting the addition result into the layer after the embedding layer; linearly processing the output result of the excitation model to be trained through the linear layer in the excitation model to be trained to obtain an evaluation result; iteratively optimizing the excitation model according to the difference between the evaluation result and the corresponding evaluation label until the training is completed to obtain a trained excitation model.
[0105] Among them, the additional embedding layer is a model layer used to distinguish the input sample prompt words and sample answers. The linear layer is a model layer used to perform linear processing on the model output results.
[0106] In some embodiments, an additional embedding layer may be added to the input side of the excitation model to be trained in advance, and a linear layer may be added after the Hidden States on the output side of the excitation model to be trained to obtain a constructed excitation model to be trained. Then, the sample prompt words and sample answers in the input second training sample are distinguished by the additional embedding layer in the constructed excitation model to be trained, and the distinguishing result is added to the output result of the embedding layer in the excitation model to be trained, and the added result is input to the layer after the embedding layer; the output result of the excitation model to be trained is linearly processed by the linear layer in the constructed excitation model to be trained to obtain an evaluation result; according to the difference between the evaluation result and the corresponding evaluation label, the excitation model is iteratively optimized until the training is completed to obtain a trained excitation model.
[0107] In the above embodiment, by adding an additional embedding layer to distinguish between sample prompt words and sample answers, the ability of the incentive model to accurately judge the answer can be enhanced, and the accuracy of the incentive model can be improved. By adding a linear layer, the probability is scored to obtain an evaluation result, and the model output result is simplified.
[0108] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0109] Based on the same inventive concept, the embodiment of the present application also provides a natural language processing model training device for implementing the natural language processing model training method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more natural language processing model training device embodiments provided below can refer to the limitations of the natural language processing model training method above, and will not be repeated here.
[0110] In one embodiment, Fig.11 As shown, a natural language processing model training device 1100 is provided, including: a video memory requirement determination module 1102, a video memory optimization combination determination module 1104 and a model training module 1106, wherein:
[0111] The video memory requirement determination module 1102 is used to obtain the target video memory required by the natural language processing model and the hardware environment in which it is located.
[0112] The video memory optimization combination determination module 1104 is used to determine a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to a target video memory amount and a hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during the model training process.
[0113] The model training module 1106 is used to perform model training on the natural language processing model to be trained by combining various video memory optimization methods in the target video memory optimization combination.
[0114] In some embodiments, the video memory optimization combination determination module 1104 is also used to determine the video memory restriction condition according to the hardware environment; remove the candidate video memory optimization combinations that do not meet the video memory restriction condition and the target video memory amount from each candidate video memory optimization combination to obtain the remaining candidate video memory optimization combinations; determine the training speed of the remaining candidate video memory optimization combinations; and determine the target video memory optimization combination from the remaining candidate video memory optimization combinations according to the training speed.
[0115] In some embodiments, the target video memory optimization combination includes at least one of tensor parallelism, sequence parallelism, zero redundancy optimizer method, pipeline parallelism, video memory unloading method and activation recalculation method; the model training module 1106 is also used to perform at least one of the following: according to at least one of tensor parallelism, sequence parallelism, zero redundancy optimizer method and pipeline parallelism, the natural language processing model to be trained is divided into video memories corresponding to different graphics processors; through each graphics processor, based on the model part of the natural language processing model to be trained divided in the corresponding video memory, parallel model training is performed. During the model training process, according to the video memory unloading method, the model that is not used temporarily is unloaded and reloaded when it is used again. According to the activation recalculation method, the intermediate activation value of the checkpoint is not saved during the forward propagation process, and the intermediate activation value of the checkpoint is recalculated during the reverse propagation process.
[0116] In some embodiments, the model training module 1106 is also used to perform at least one of the following: according to the tensor parallel method, the target operator in the natural language processing model to be trained is divided in parallel into the video memories corresponding to different graphics processors; according to the sequence parallel method, the embedding layer in the natural language processing model to be trained is divided in parallel into the video memories corresponding to different graphics processors; according to the zero-redundancy optimizer method, the optimizer state, gradient and model parameters in the natural language processing model to be trained are divided in parallel into the video memories corresponding to different graphics processors; according to the pipeline parallel method, the layers in the natural language processing model to be trained are divided into the video memories corresponding to different graphics processors.
[0117] In some embodiments, the natural language processing model to be trained includes a behavior prediction network and an evaluation network; the model training module 1106 is also used to obtain training samples, and a pre-trained basic model and an excitation model; the initial state of the behavior prediction network is configured as the basic model, and the initial state of the evaluation network is configured as the excitation model; according to the training samples, the evaluation results of the excitation model and the evaluation results of the evaluation network after each optimization, the behavior prediction network and the evaluation network are iteratively optimized until the training is completed, and the trained behavior prediction network and evaluation network are obtained; the evaluation result of the excitation model is the evaluation result of the answer result predicted by the behavior prediction network.
[0118] In some embodiments, the model training module 1106 is also used to distinguish the input sample prompt words and sample answers through an additional embedding layer in the excitation model to be trained, and add the distinction result to the output result of the embedding layer in the excitation model to be trained, and input the addition result into the layer after the embedding layer; linearly process the output result of the excitation model to be trained through the linear layer in the excitation model to be trained to obtain an evaluation result; iteratively optimize the excitation model according to the difference between the evaluation result and the corresponding evaluation label until the training is completed to obtain a trained excitation model.
[0119] The above-mentioned natural language processing model training device obtains the target video memory amount and the hardware environment required by the natural language processing model, determines the target video memory optimization combination from a plurality of candidate video memory optimization combinations obtained by combining different video memory optimization methods according to the target video memory amount and the hardware environment, and then performs model training on the natural language processing model to be trained in combination with various video memory optimization methods in the target video memory optimization combination. It can perform video memory optimization during the model training process by using various video memory optimization methods in the target video memory optimization combination that meet the target video memory amount and the hardware environment, thereby solving the problem that the device's video memory cannot support the training of large-scale natural language processing models, and improving the training speed of the natural language processing model.
[0120] Each module in the above-mentioned natural language processing model training device can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0121] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.12 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store training data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a natural language processing model training method is implemented.
[0122] Those skilled in the art will understand that Fig.12 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0123] The embodiment of the present application also provides a computer-readable storage medium. One or more non-volatile computer-readable storage media containing computer-executable instructions, when the computer-executable instructions are executed by one or more processors, the processors execute the steps of the natural language processing model training method.
[0124] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute a natural language processing model training method.
[0125] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0126] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0127] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A natural language processing model training method, characterized in that: include: Get the target video memory and hardware environment required by the natural language processing model; Determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training; In combination with various video memory optimization methods in the target video memory optimization combination, model training is performed on the natural language processing model to be trained.
2. The method according to claim 1, characterized in that The step of determining a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment includes: Determine a video memory restriction condition according to the hardware environment; From the candidate video memory optimization combinations, remove the candidate video memory optimization combinations that do not meet the video memory restriction condition and the target video memory amount, to obtain the remaining candidate video memory optimization combinations; Determining the training speed of the remaining candidate video memory optimization combinations; According to the training speed, a target video memory optimization combination is determined from the remaining candidate video memory optimization combinations.
3. The method according to claim 1, characterized in that The target video memory optimization combination includes at least one of a tensor parallel method, a sequence parallel method, a zero-redundancy optimizer method, a pipeline parallel method, a video memory offloading method, and an activation recalculation method; The combining various video memory optimization methods in the target video memory optimization combination to perform model training on the natural language processing model to be trained includes at least one of the following: According to at least one of the tensor parallel method, the sequence parallel method, the zero redundancy optimizer method and the pipeline parallel method, the natural language processing model to be trained is divided into video memories corresponding to different graphics processors; Performing parallel model training based on the model parts of the natural language processing model to be trained that are divided in the corresponding video memory by using respective graphics processors; During the model training process, unload the temporarily unused model according to the video memory unloading method, and reload it when it is used again; According to the activation recalculation method, the intermediate activation values of the checkpoint are not saved during the forward propagation process, and the intermediate activation values of the checkpoint are recalculated during the backward propagation process.
4. The method according to claim 3, characterized in that The method of dividing the natural language processing model to be trained into video memories corresponding to different graphics processors according to at least one of the tensor parallel method, the sequence parallel method, the zero redundancy optimizer method, and the pipeline parallel method includes at least one of the following: According to the tensor parallel method, the target operator in the natural language processing model to be trained is parallelly divided into video memories corresponding to different graphics processors; According to the serial parallel method, the embedding layer in the natural language processing model to be trained is parallelly divided into video memories corresponding to different graphics processors; According to the zero-redundancy optimizer method, the optimizer state, gradient and model parameters in the natural language processing model to be trained are parallelly divided into video memories corresponding to different graphics processors; According to the pipeline parallel method, the layers in the natural language processing model to be trained are divided into video memories corresponding to different graphics processors.
5. The method according to claim 1, characterized in that The natural language processing model to be trained includes a behavior prediction network and an evaluation network; and the model training of the natural language processing model to be trained includes: Obtain training samples, as well as pre-trained basic models and incentive models; Configuring the initial state of the behavior prediction network as the basic model, and configuring the initial state of the evaluation network as the excitation model; According to the training samples, the evaluation results of the excitation model and the evaluation results of the evaluation network after each optimization, the behavior prediction network and the evaluation network are iteratively optimized until the training is completed, thereby obtaining the trained behavior prediction network and evaluation network; the evaluation results of the excitation model are the evaluation results of the answer results predicted by the behavior prediction network.
6. The method according to claim 5, characterized in that Before obtaining the training samples, and the pre-trained basic model and excitation model, the method further includes: Using an additional embedding layer in the excitation model to be trained, the input sample prompt words and sample answers are distinguished, and the distinguishing result is added to the output result of the embedding layer in the excitation model to be trained, and the added result is input to the layer after the embedding layer; Performing linear processing on the output result of the excitation model to be trained through the linear layer in the excitation model to be trained to obtain an evaluation result; According to the difference between the evaluation result and the corresponding evaluation label, the incentive model is iteratively optimized until the training is completed to obtain a trained incentive model.
7. A natural language processing model training device, characterized in that: include: The video memory requirement determination module is used to obtain the target video memory required by the natural language processing model and the hardware environment in which it is located; A video memory optimization combination determination module, used to determine a target video memory optimization combination from a plurality of candidate video memory optimization combinations according to the target video memory amount and the hardware environment; the plurality of candidate video memory optimization combinations are obtained by combining different video memory optimization methods; the video memory optimization method is used to optimize the use of video memory during model training; The model training module is used to perform model training on the natural language processing model to be trained by combining various video memory optimization methods in the target video memory optimization combination.
8. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the computer program is executed by the processor, the processor performs the steps of the natural language processing model training method as described in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Electronic device and method for neural network model training processing, and medium
CN119046015A
Model training video memory optimization method and device
CN119205484A
Control method and device of training and pushing expansion card, storage medium and training and pushing all-in-one machine
CN120144294A
