Large language model distributed pipeline parallel fine tuning method for heterogeneous GPU graphics card

Through the distributed pipeline parallel fine-tuning method, the problem of uneven resource allocation and model convergence speed in multi-task fine-tuning and large-scale model fine-tuning is solved, efficient GPU resource utilization and model convergence are achieved, and fine-tuning efficiency and effect are improved.

CN118796455APending Publication Date: 2024-10-18ZHEJIANG NEW INTERNET EXCHANGE CENT CO LTD +1
View PDF 0 Cites 14 Cited by

Patent Information

Application Number
CN202410772174.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-16
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing large language model fine-tuning technology has the problems of uneven resource allocation, low utilization of computing resources, and insufficient optimization of model convergence speed during multi-task fine-tuning and large-scale model fine-tuning. Especially in multi-GPU environments, it is difficult to achieve efficient task scheduling and Resource management.

Method used

Using the distributed pipeline parallel fine-tuning method, through efficient gradient descent methods and task scheduling strategies, we design model segmentation and vector parallel technology, combine overlapping computing and communication strategies, optimize model synchronization strategies, and develop early end estimation algorithms and task scheduling optimization algorithms. , achieving more efficient GPU resource utilization and model convergence.

Benefits of technology

It improves the fine-tuning efficiency and effect of large-scale pre-trained language models on specific tasks, maximizes computing resource utilization, reduces training costs, and achieves a more efficient, intelligent and high-quality fine-tuning process for large-scale models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796455A_ABST
    Figure CN118796455A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of natural language processing, and discloses a large language model distributed pipeline parallel fine tuning method for a heterogeneous GPU graphics card, which is characterized in that fine tuning is simultaneously realized on a plurality of LoRA models based on a multi-task fine tuning system; each LoRA model is segmented into a plurality of parts which are distributed on a corresponding number of GPUs, and the GPUs are sorted; generating a plurality of tasks through a task configuration module according to a user request, and dividing each task into a plurality of training batches; according to the training batch sequence of each task, generating a scheduling scheme through a task dynamic scheduler in combination with a dynamic scheduling strategy; according to the GPU positive sequence, the scheduling scheme is sent to a multi-task training module on the corresponding GPU, and all LoRA models are trained. According to the method, a fine model segmentation and distribution strategy, an assembly line optimization path and a task load balancing strategy are adopted, computing resources of a multi-machine and multi-card environment can be utilized more effectively, the overall efficiency of the fine adjustment process is improved, and resource waste is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of natural language processing, and relates to a large language model fine-tuning method, and in particular to a large language model distributed pipeline parallel fine-tuning method for heterogeneous GPU graphics cards. Background Art

[0002] In the field of natural language processing, fine-tuning of large language models (LLMs) is a critical task that aims to adapt pre-trained general models to specific tasks or domains. Traditional full-scale fine-tuning methods update all model parameters during the fine-tuning process, but due to the huge number of parameters of the LLM model and the particularity of the fine-tuning task, this method is cumbersome and computationally intensive. Therefore, the GPU memory and computation optimization issues during fine-tuning, especially the challenge of parameter-efficient fine-tuning techniques, have become the focus of current research.

[0003] Existing fine-tuning methods, such as LoRA technology, provide a parameter-efficient way of fine-tuning, which achieves model specialization and domain-specification by adjusting only some parameters, thereby reducing the demand for computing resources while maintaining the fine-tuning effect. However, when facing multi-task fine-tuning, especially on large-scale LLM models, there are still a series of challenges, including how to effectively allocate and utilize computing resources, and how to improve the efficiency of the overall training and fine-tuning process through dynamic task scheduling and distributed computing optimization algorithms.

[0004] There have been some studies on LLM fine-tuning optimization, such as S-LoRA and other systems. S-LoRA is a system dedicated to optimizing the efficiency of LLM service scenarios. Its core idea is to use heterogeneous batch processing to batch process different LoRA adapters, combined with efficient management of KV cache and other methods to improve system throughput. The system effectively manages computing resources when serving many LoRA adapters by sharing a pre-trained model. The S-LoRA system mainly focuses on the efficiency of LLM in service scenarios, optimizes system throughput through batch processing and resource management, and does not fully consider the training scenarios in the fine-tuning process. Especially in the case of multi-task fine-tuning and large model fine-tuning, its performance still needs to be further improved.

[0005] Therefore, the current large language model fine-tuning technology has the following main problems: (1) The complexity of multi-task fine-tuning is not fully considered, or there is a lack of efficient task scheduling algorithms and resource allocation strategies, resulting in a lack of flexibility and intelligence in resource allocation and task scheduling; (2) Due to the lack of dynamic resource allocation and task scheduling mechanisms, or due to hardware configuration mismatch, some GPUs may be idle while other GPUs are overloaded, failing to effectively solve the problem of unbalanced computing resource utilization in a multi-GPU environment; (3) Failure to design an efficient model synchronization strategy suitable for a multi-GPU environment, or failure to fully optimize the model convergence speed, may lead to inconsistent model convergence on different GPUs, affecting the fine-tuning effect. Summary of the invention

[0006] The purpose of the present invention is to address the deficiencies in the prior art and provide a distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards, thereby improving the efficiency and effect of fine-tuning a large-scale pre-trained language model on a specific task, while maximizing the utilization of computing resources and reducing training costs.

[0007] The inventive ideas of the present invention are as follows: (1) For fine-tuning of multiple LoRA tasks in a single-card environment: develop a more efficient gradient descent method and task scheduling strategy to maximize the utilization of a single GPU and improve task throughput and turnover rate; optimize the model fine-tuning process, make full use of the memory and computing power of the GPU, and improve the training speed and model performance; (2) For parallel fine-tuning of the LoRA model in a multi-machine and multi-card environment: design efficient model segmentation and vector parallel technology, make full use of the computing power and memory size of multiple GPUs to achieve efficient parallel fine-tuning; solve the problems of computational load balancing and communication overhead in pipeline parallelism, and design new overlapping computation and communication strategies to improve training efficiency and ensure model convergence; (3) The present invention also proposes two scheduling optimization algorithms for multi-LoRA fine-tuning tasks: ① Early termination estimation algorithm, develop an accurate task early termination estimation algorithm to predict the execution time of the task and release GPU resources in advance, thereby improving the overall throughput of the system; ② Task scheduling optimization algorithm: design an efficient task scheduling algorithm, optimize the batch fusion strategy in multi-task execution, reduce the idle time in the calculation process, and ensure efficient utilization and fair management of resources.

[0008] The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards provided by the present invention realizes fine-tuning of multiple LoRA models at the same time based on a multi-task fine-tuning system; each LoRA model is divided into multiple parts, distributed on a corresponding number of GPUs, and the GPUs are sorted; the multi-task fine-tuning system includes a task configuration module, an analyzer, a task dynamic scheduler, and multi-task training modules distributed on multiple GPUs; each multi-task training module is used to realize fine-tuning of the corresponding part of the LoRA model;

[0009] The large language model distributed pipeline parallel fine-tuning method comprises the following steps:

[0010] S1 generates multiple tasks through the task configuration module according to the user's request, and divides each task into several training batches;

[0011] S2 configures hyperparameters for each task through the analyzer;

[0012] S3 generates a scheduling plan based on the training batch order of each task through the task dynamic scheduler combined with the dynamic scheduling strategy;

[0013] S4 sends the scheduling plan to the multi-task training module on the first GPU in the positive order of the GPUs. The multi-task training module trains all LoRA models according to the training batches included in the scheduling plan. The training results are transmitted to the multi-task training module on the next GPU, and the above operations are repeated until the last GPU. Then, the loss function is determined based on the training results output by the last GPU, and the training results and loss function are fed back to the analyzer. At the same time, the loss function is back-propagated in the reverse order of the GPUs to optimize the parameters of the corresponding part of the LoRA model on the GPU.

[0014] The analyzer in S5 performs precision analysis based on the training results and the loss function to determine whether all tasks meet the training requirements; if all tasks meet the training requirements, the program ends; otherwise, the precision analysis results are fed back to the task dynamic scheduler and return to step S3.

[0015] The LoRA model is selected from LLaMA-7B, LLaMA-13B, ChatGLM2-6B, LLaMA2-7B or LLaMA2-13B, etc. The LoRA model can be segmented according to different dimensions, such as segmentation by layer or segmentation by parameter. In a preferred implementation, the LoRA model is segmented, for example, according to the head (HEAD), the middle (MID) and the tail (TAIL), the head (HEAD) and the tail (TAIL) are distributed on two GPUs, and the middle (MID) can be determined according to size whether it needs to be segmented again and distributed on more than one GPU.

[0016] In the above step S1, the user request includes task configuration (i.e., hyperparameter configuration of the model), training data, and scheduling goals. The scheduling goals include minimizing waiting time, reducing turnaround time, maximizing throughput, maximizing accuracy, and executing scheduling in sequence.

[0017] In the above step S3, the task dynamic scheduler sorts the task lengths in each batch and fills the task symbols in the scheduling scheme with tasks with the same or similar task lengths in the same batch; thus, the task dynamic scheduler adopts a near-optimal method to reduce the impact of padding symbols on training throughput. This means that it can effectively process input sequences of different lengths, thereby reducing the waste of computing resources caused by padding symbols.

[0018] The dynamic scheduling strategy includes:

[0019] ① No early stopping strategy: execute in the order of tasks;

[0020] ② Early stopping strategy: Initially, tasks are executed in order; during training, tasks with poor accuracy are terminated early based on the changing trend of the accuracy analysis results of the analyzer, and subsequent tasks are advanced;

[0021] ③ Early stopping strategy with prediction: First, a scheduling plan is generated based on more than one batch of data for all tasks, and step S4 is executed for pre-testing to obtain the prediction results, which are fed back to the analyzer; the analyzer performs precision analysis based on the prediction results and generates a scheduling plan for subsequent tasks; in the subsequent training process, based on the changing trend of the analyzer's precision analysis results, tasks with deteriorating precision are terminated in advance, and subsequent tasks are advanced.

[0022] According to the scheduling goal in the user request, one of the strategies ①, ②, and ③ is selected to generate the scheduling task; for example, when the scheduling goal is to minimize waiting time, reduce turnaround time, and maximize throughput, the task dynamic scheduler automatically selects strategy ② or ③ according to the prediction results; when the scheduling goal is to execute a series of tasks in sequence, the task dynamic scheduler automatically selects strategy ①. The task dynamic scheduler can effectively manage system resources and improve the overall system efficiency. It ensures that system resources are optimally allocated and utilized among various tasks through intelligent scheduling strategies. In particular, for the predicted early stopping strategy, a memory usage estimation model is implemented. This enables the scheduler to adaptively adjust the scheduling of jobs according to the current resource usage and task requirements to optimize memory utilization and avoid memory overflow. Then, the scheduler implements multi-objective optimization. Its goal is not only to reduce waiting time and turnaround time, but also to increase throughput while ensuring the priority and fairness of task execution. This means that high-priority tasks will be executed first, while following the first-come, first-served principle.

[0023] In the above step S4, the multi-task training module merges the training data of multiple tasks into one training set; in each iteration, multiple LoRA models share one pre-trained model.

[0024] Given the input sequence x of the i-th task i , the output data will be h i The fusion input matrix is ​​represented as X = Fusion(x1,...,x n ). It will be multiplied by the pre-trained weights and all LoRA model weights, and then the results are added together to produce the final output H. The complete calculation formula is as follows:

[0025] H = Concat(h1, ..., h n )=W0X+[ΔW1x1,...,ΔW n x n ]

[0026] =W0X+[B1A1x1,...,B n A n x n ]

[0027] Among them, W0∈R d×k represents the shared pre-trained weights, d and k represent (row and column sizes of the matrix); ΔW i =B i A i represents the weight of the LoRA model trained for the i-th task, and They are low-rank decomposition matrices, rank r i < <min(d,k)。

[0028] In the above step S5, based on the loss function value, the analyzer performs statistics on the loss function value obtained after each batch of training for each task; the loss function value can also be further fitted. In addition, based on the training results, the analyzer can also perform statistics and fit on the accuracy rate obtained after each batch of training for each task. The accuracy analysis results include the change of the loss function value with the number of iterations, and also include the change of the accuracy rate with the number of iterations.

[0029] Compared with the prior art, the distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards provided by the present invention has the following beneficial effects:

[0030] (1) The present invention can implement efficient GPU memory management and optimization strategies through a multi-task scheduling system, including memory allocation, sharing mechanism and dynamic scheduling, so as to achieve concurrent execution of more fine-tuning tasks and improve the utilization of GPU memory, thereby improving the overall performance of the system;

[0031] (2) The present invention adopts a sophisticated model segmentation and allocation strategy, pipeline optimization path and task load balancing strategy, which can more effectively utilize the computing resources of a multi-machine and multi-card environment, improve the overall efficiency of the fine-tuning process, and reduce resource waste;

[0032] (3) The present invention designs an intelligent task scheduling mechanism and a dynamic early stopping strategy, which can adjust the task execution order and priority in real time according to the task performance indicators and system load conditions, reduce unnecessary computing overhead, and maximize the overall throughput and resource utilization of the system; by optimizing algorithms and resource management, the present invention can ensure the performance and quality of the fine-tuning model while ensuring the fine-tuning efficiency, thereby improving the performance and application effect of the model on specific tasks.

[0033] In summary, the technical solution of the present invention will bring about a more efficient, smarter and higher-quality large-scale model fine-tuning process. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 Fine-tune the multi-card model segmentation strategy for LoRA scenarios;

[0035] Figure 2 It is a schematic diagram of the parallel principle of different pipelines;

[0036] Figure 3 This is a schematic diagram of the principle of a multi-task scheduling system;

[0037] Figure 4 This is a task scheduling diagram;

[0038] Figure 5 It is a schematic diagram of an adaptive job scheduling example;

[0039] Figure 6 (a) is the traditional LoRA model training; Figure 6 (b) is a schematic diagram of the principle of multi-task training (m-LoRA model training);

[0040] Figure 7 A schematic flow chart of a distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards provided by an embodiment of the present invention;

[0041] Figure 8is the throughput of the large language model under different fine-tuning methods; where Alpaca-Seq and Alpaca-Parallel are both Alpaca-LoRA methods (see Eric Wang. Alpaca-lora. https: / / github.com / tloen / alpaca-lora, 2023); Alpaca-Seq: trains models sequentially on a single GPU; Alpaca-Parallel: trains multiple models simultaneously on a single GPU; ASPEN represents the experimental results of the present invention on a single GPU; (a) represents the throughput comparison of different models; (b) represents the throughput comparison of different parameters and model versions of the same model; (c) represents the throughput comparison using different hardware;

[0042] Fig. 9 The GPU memory usage of Alpaca-LoRA and ASPEN methods using NVIDIA A100 80GB. Batch size indicates the number of tasks in the same batch. OOM indicates out of memory. DETAILED DESCRIPTION

[0043] The specific implementation modes of the present invention are described below so that those skilled in the art can understand the present invention. However, it should be clear that the present invention is not limited to the scope of the specific implementation modes. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the attached claims, these changes are obvious, and all inventions and creations utilizing the concept of the present invention are protected.

[0044] Example

[0045] The purpose of this invention is to study how to reduce the demand for computing resources while maintaining the fine-tuning effect, how to effectively allocate and utilize computing resources in different hardware environments, and how to improve the efficiency of the overall training and fine-tuning process through dynamic task scheduling and distributed computing optimization algorithms.

[0046] This embodiment explains in detail the large language model distributed pipeline parallel fine-tuning method for heterogeneous GPU graphics cards provided by the present invention.

[0047] (I) Fine-tuning optimization based on pipeline parallelism

[0048] In large model fine-tuning scenarios (computing devices include GPU cards and CPU cards), a major challenge is that the model size is too large and exceeds the capacity of a single GPU memory, so the LoRA model needs to be split and fine-tuned on multiple GPU cards.

[0049] When fine-tuning multiple cards, two key factors need to be considered: 1) whether the GPU cards are of the same type; 2) how the GPU cards are connected. This implementation lists two existing scenarios: one is a fine-tuning environment where all GPU cards are of the same type; the other is a fine-tuning environment where the GPU cards are of different types and connected via PCIe. This embodiment aims to explore how to improve the computational efficiency during the fine-tuning process by splitting the model and using pipeline parallelism (pipeline) technology.

[0050] Model sharding refers to splitting a large language model into multiple smaller parts that can be distributed across multiple computing nodes (such as GPUs). This approach allows each node to process only a portion of the model, thereby reducing the demand on a single node's memory and computing resources. Model sharding can be done along different dimensions, such as by layer or by parameter, and each method has its advantages and limitations.

[0051] Pipeline parallelism (also called Pipeline parallelism) is a special parallel computing method that allows different model parts (or layers) to process different data simultaneously on different computing nodes.

[0052] The combination of model slicing and pipeline parallelism makes it possible to process large language models, but it also brings new challenges: how to efficiently synchronize and coordinate the computations between different nodes, and how to minimize the delays caused by data transmission and waiting. Solving these challenges is crucial to achieving efficient fine-tuning training and inference of large language models. In pipeline parallel processing, the low utilization of computing resources is a significant problem. At any given point in time, usually only one computing device is executing tasks, while the other devices are idle. Ignoring the communication time, if there are N computing devices, the total time utilization is only 1 / N. As the number of computing devices increases, the utilization of each device will further decrease. Therefore, in order to improve the utilization of computing devices, tasks need to be assigned to currently idle devices. This phenomenon, that is, the situation where downstream devices need to wait for a long time for upstream devices to complete the computation before they can start working, is called "bubble". In addition, the sequential execution of computation and communication is also a problem that leads to resource waste. When the intermediate results of forward computation and the gradients of backpropagation are transmitted between different devices, no computing device is performing computational tasks. Therefore, the computation and communication processes need to be carefully designed to improve the efficiency of device utilization. Moreover, the way the model layers are divided has a significant impact on computing performance. Since different layers of the model need to be assigned to different computing devices, different division strategies may lead to significant differences in performance. Therefore, how to effectively divide the model layers is also a key factor affecting the performance of pipeline parallel processing.

[0053] This embodiment adopts the mode of layer segmentation, and changes the model segmentation strategy according to the load elasticity of different GPUs. Figure 1 As shown, in this embodiment, the LoRA model is divided into three parts according to the head (HEAD), the middle part (MID) and the tail (TAIL). The head (HEAD) and the tail (TAIL) are distributed on two GPUs, which can be defined as the first GPU (GPU0) and the last GPU (GPU2) through which the task training forward propagation passes; and the middle part (MID) can be determined according to the size to determine whether it needs to be split again and distributed on one or more GPUs (GPU1). Figure 1 As shown, on the computing node where the GPU is located, the CPU receives the forward propagation or reverse propagation information and then sends it to the GPU for processing. The processing result of the GPU is then propagated out through the CPU.

[0054] Figure 2 The computational pipeline optimization for model fine-tuning in homogeneous and heterogeneous card scenarios is demonstrated.

[0055] In the homogeneous card scenario, the traditional pipeline parallel computing method is that several tasks pass through each computing device in turn to train each part of the model.

[0056] In the heterogeneous card scenario, the traditional pipeline parallel computing method is to divide several tasks into several batches. The first batch of tasks passes through each computing device in turn to train each part of the model; after all tasks in the first batch are trained, the second batch, the third batch, and other tasks are trained in turn.

[0057] In the pipeline parallelism of this embodiment (m-LoRA pipeline parallelism), the input data is divided into multiple small batches (micro-batches), which are sequentially passed through different parts of the model located on different GPUs. When a batch of data passes through one part of the model, it is immediately passed to the next part, and the GPU of that part starts processing the next batch of data at the same time. This method can significantly improve the utilization of computing resources and the overall processing speed. Figure 2 As shown in (c), blue represents forward propagation, green represents back propagation, and different shades of the same color represent different training batches. In the same computing device, tasks are processed in time sequence, and back propagation is processed first.

[0058] Therefore, compared with the parallel processing of homogeneous and heterogeneous pipelines, the parallel processing method for m-LoRA provided by the present invention can achieve a "Bubble" of 0, greatly improving the utilization rate of computing resources.

[0059] (II) Multi-task Scheduling System

[0060] The multi-task scheduling system provided in this embodiment is used to implement training of multiple LoRA models (m-LoRA models) at the same time.

[0061] The multi-task fine-tuning system provided in this embodiment is as follows: Figure 3 As shown in the figure, it includes a task configuration module, an analyzer, a task dynamic scheduler, and a multi-task training module. The number of multi-task training modules is the same as the number of LoRA model segments, and they are distributed on the corresponding GPUs at the same time. The task configuration module, analyzer, and task dynamic scheduler can be set on the first GPU.

[0062] like Figure 3 As shown in the figure, the user initiates a request to the multi-task scheduling system, providing task configuration (i.e., hyperparameter configuration of the model), training data, and scheduling goals, including minimizing waiting time, reducing turnaround time, maximizing throughput, and executing in sequence. Subsequently, the task configuration module generates multiple candidate jobs (JOBs) based on this information, and configures the estimated basic hyperparameters for each job in the profiler when the system is initialized. Once the system is initialized, the task dynamic scheduler (Scheduler) selects a portion of the work from the candidate jobs and selects the most appropriate strategy to align them with the user-defined scheduling goals to achieve adaptive job scheduling. The m-LoRA model is then trained through the multi-task training module.

[0063] 1. Task configuration module

[0064] The task configuration module is used to generate multiple tasks based on user requests and divide each task into several training batches.

[0065] The task configuration module divides the training data into multiple tasks (Job1, Job2, ..., Job n ). Then, each task is divided according to the set training batches.

[0066] 2. Analyzer

[0067] The analyzer is used to configure the estimated basic hyperparameters for each task during system initialization and distribute them to the m-LoRA model on each GPU for initialization.

[0068] During the training process, after the training of the previous batch of tasks is completed, the analyzer counts the loss values ​​obtained after each batch of training of each task based on the received loss function value, and obtains the changing trend of the loss value with the number of iterations. The loss value can also be further fitted to predict the changing trend of the loss value with the number of iterations.

[0069] In addition, based on the received training results, the analyzer also counts the accuracy obtained after each batch of training for each task, obtains the changing trend of the accuracy with the number of iterations, and can further fit the accuracy and predict the changing trend of the accuracy with the number of iterations.

[0070] Therefore, the accuracy analysis results include the change of loss function value with the number of iterations, and the change of accuracy with the number of iterations.

[0071] When the loss function value or accuracy tends to be stable, the m-LoRA model is judged to have converged; the loss function value can also be used as a model convergence condition when it is less than the set threshold; or the m-LoRA model is judged to have converged based on whether the set number of iterations reaches the upper limit. When the model converges, the training goal (i.e. the scheduling goal mentioned above) is achieved.

[0072] 3. Task Dynamic Scheduler

[0073] The task dynamic scheduler, a key component of the multi-task scheduling system, is responsible for collecting task metrics and accurately estimating model performance and resource utilization.

[0074] The task dynamic scheduler is used to combine dynamic scheduling strategies, fuse multiple tasks to generate a scheduling plan, and send it to the multi-task training module.

[0075] The task dynamic scheduler sorts the task lengths in each batch and fills the task symbols in the scheme with tasks of the same or similar length in the same batch; thus, the task dynamic scheduler adopts a near-optimal method to reduce the impact of padding symbols on training throughput. This means that it can effectively process input sequences of different lengths, thereby reducing the waste of computing resources caused by padding symbols. Figure 4 As shown in the figure, the traditional scheduling method is to fill the scheduling scheme with task symbols according to the first-in-first-out strategy, and merge the two tasks JOB1 and JOB2. In this embodiment, the task fusion is performed according to the minimum difference in the number of filling symbols of the two tasks; comparing the three tasks JOB1, JOB2, and JOB3, the length of each batch of the two tasks JOB1 and JOB3 is the closest, so the two tasks are merged.

[0076] Dynamic scheduling strategies include:

[0077] ① No early stopping strategy: execute in the order of tasks;

[0078] ② Early stopping strategy: Initially, tasks are executed in order; during training, tasks with deteriorating accuracy are terminated early based on the changing trend of the accuracy analysis results of the analyzer, and subsequent tasks are advanced; deteriorating accuracy includes a gradual increase in the loss function value or a gradual decrease in accuracy;

[0079] ③ Early stopping strategy with prediction: First, a scheduling plan is generated based on more than one batch of data for all tasks, and step S4 is executed for pre-testing to obtain the prediction results, which are fed back to the analyzer; the analyzer performs precision analysis based on the prediction results and generates a scheduling plan for subsequent tasks; in the subsequent training process, based on the changing trend of the analyzer's precision analysis results, tasks with deteriorating precision are terminated in advance, and subsequent tasks are advanced.

[0080] Figure 5 An example of adaptive job scheduling is presented, which shows how the task dynamic scheduler uses prediction and early stopping strategies to dynamically adjust resource allocation and task execution order according to the requirements of different tasks and system status. In this way, the task dynamic scheduler can meet the performance requirements of different tasks while ensuring high efficiency. Figure 5 (Left side) corresponds to the accuracy analysis result of the analyzer. Figure 5 (Right) The corresponding dynamic scheduling strategy and example, A, B, C, D, E, and F represent training batches respectively. Here we take four jobs (J1-J4) as an example. Through testing, it is found that when strategy ① is adopted, J1-J2 is executed first, and then J3-J4 is executed, the turnaround time is 36 hours, and the throughput is 0.33 tasks / hour; when strategy ② is adopted, after executing A, B, and C of J2, J2 stops early and is replaced by J3; after executing J1, J3 is also executed; then J4 is executed, so the turnaround time is 27 hours, and the throughput is 0.33 tasks / hour; when strategy ③ is adopted, a small part of J1, J2, J3, and J4 (part A of J1-J4) is first used for warming up, that is, pre-testing, and the best scheduling and early stopping scheme is obtained according to the prediction results; that is, J2-J3 is executed at the same time first, and then J2-J3 is stopped early at the same time (due to the deterioration of prediction accuracy); then J1-J4 is executed at the same time, so the turnaround time is 26 hours, and the throughput is 0.44 tasks / hour;

[0081] like Figure 5 As shown in Figure 2, according to the loss value trend or the accuracy trend, J2 and J3 should be terminated as early as possible, because continuing to run these jobs with minimal benefits will consume precious computing resources without bringing significant benefits, so the early stopping strategy is necessary. Figure 4 The turnaround time and throughput of the three strategies are listed, and it is found that the early stopping strategy with prediction is the best for this job scheduling.

[0082] Therefore, the optimization features of the task dynamic scheduler provided by the present invention include the following aspects:

[0083] (1) It adopts a near-optimal approach to reduce the impact of padding symbols (i.e., task symbol padding) on ​​training throughput. This means that it can effectively process input sequences of different lengths, thereby reducing the waste of computational resources caused by padding symbols.

[0084] (2) A memory usage estimation model is implemented by combining early stopping prediction and GPU memory performance information. This enables the scheduler to adaptively adjust job scheduling based on current resource usage and task requirements to optimize memory utilization and avoid memory overflow.

[0085] (3) Multi-objective optimization is achieved. Its goal is not only to reduce waiting time and turnaround time, but also to increase throughput while ensuring the priority and fairness of task execution. This means that high-priority tasks will be executed first while following the first-come, first-served principle.

[0086] (4) It can effectively manage system resources and improve overall system efficiency. It ensures that system resources are optimally allocated and utilized among various tasks through intelligent scheduling strategies.

[0087] 4. Multi-task training module

[0088] The premise of the multi-task training module (Multi-LoRA Trainer) is batch fusion, and its core purpose is to achieve efficient sharing of pre-trained models so that multiple LoRA model fine-tuning tasks can be trained simultaneously.

[0089] Batch fusion adopts a parallel training iteration strategy to fuse the training data of multiple tasks in the same batch into one training set, so that in each iteration, multiple LoRA models can share the same pre-trained model. This method not only improves training efficiency, but also allows these modules to participate in training in parallel, rather than sequentially or individually. The multi-task training module based on batch fusion supports the execution of multiple fine-tuning tasks in parallel on the same GPU. This is crucial to improving the utilization of GPU resources and accelerating the training process.

[0090] In this embodiment, the pre-trained model refers to a pre-trained language model, such as LLaMA-7B / 13B, ChatGLM2-6B, and LLaMA2-7B / 13B.

[0091] Figure 6 (a) shows the schematic diagram of traditional LoRA model training, and (b) shows the schematic diagram of multiple LoRA models participating in parallel training. Consider multiple LoRA fine-tuning tasks, J1,...,J n Each task J i The fine-tuning input data involved is denoted as x i .

[0092] The i-th task (J i ) is labeled as A i and B i . It is worth noting that all these tasks share the same pre-trained weights, denoted by W0. Fusion is used to represent the batch fusion process, and Concat represents the matrix concatenation operation; the Fusion operation is similar to matrix concatenation, but the present invention adds additional padding tokens to ensure dimension alignment, as well as additional information to identify which LoRA model the input data belongs to. Therefore, given the input sequence x of the i-th task i , the output data will be h i The fusion input matrix is ​​X = Fusion(x1,...,x n ), which will be multiplied by the pre-trained weights and all LoRA module weights, and then the individual results will be added together to produce the final output H. The complete calculation formula is as follows:

[0093] H = Concat(h1, ..., h n )=W0X+[ΔW1x1,...,ΔW n x n ]

[0094] =W0X+[B1A1x1,...,B n A n x n ] (1)

[0095] Among them, W0∈R d×k represents the shared pre-trained weights, d and k represent (row and column sizes of the matrix); ΔW i =B i A i represents the weight of the LoRA module trained for the i-th task, and is a low-rank decomposition matrix, rank r i < <min(d,k)。

[0096] The computational cost of the multi-task training module and the widely used fine-tuning library PEFT is analyzed. Assume that there are k LoRA fine-tuning tasks, each with a different training dataset. The input sequence in each iteration can be represented as x1,...,x k , the fusion input matrix X = Fusion(x1,...,x k ). When running these k LoRA fine-tuning tasks on a single GPU, the computational cost mainly includes the kernel execution cost and the kernel startup cost. According to formula (1) and the following formula (2):

[0097] h = W0x + ΔWx = W0x + BAx (2)

[0098] The main kernel execution costs involve matrix multiplication and addition operations. Since m-LoRA does not introduce additional computations, it should have the same computational complexity as PEFT. Therefore, it is considered that batch fusion has the same kernel execution cost in m-LoRA and existing PEFT methods. Since the fused input matrix X consists of multiple input sequences x i which, so r(x i ) < r(X). In computational operations involving matrix multiplication and addition, each operation launches a kernel. As mentioned before, for small kernels, i.e., kernels for low-rank matrix computations, the kernel launch overhead is particularly significant. Referring to equations (1) and (2), the PEFT method needs to launch 4k small kernels for k fine-tuning tasks, with each task involving three multiplication and one addition operations. In contrast, the batch fusion method reduces the number of small kernel launches to 2k, with each operation only involving one multiplication operation. Additionally, it introduces two large kernel launches, including one addition and one multiplication operation. Since the kernel launch overhead for kernels for high-rank matrix computations (i.e., large kernels) is similar to that of small kernels, it is inferred that the total time spent on kernel launches is proportional to the number of launches. Therefore, the proposed batch fusion method effectively reduces the theoretical kernel launch cost and can save (k - 1)WpGB of GPU memory. It is analyzed that batch fusion can reduce the theoretical kernel launch cost by 30% to 50%, thus further optimizing the utilization efficiency of GPU resources.

[0099] In summary, batch fusion significantly reduces the overhead of model switching. By avoiding frequent switching between different fine-tuning tasks, it reduces the time and resource consumption caused by model switching. Batch fusion also achieves more efficient use of GPU resources by reducing the kernel launch cost. Therefore, as a key technology in m-LoRA, batch fusion significantly improves the efficiency and effectiveness of multi-task fine-tuning through parallel processing, reducing switching overhead, and optimizing resource utilization.

[0100] Based on the above analysis, the large language model distributed pipelined parallel fine-tuning method for heterogeneous GPU graphics cards provided in this embodiment fine-tunes multiple LoRA models simultaneously based on a multi-task fine-tuning system; each LoRA model is divided into multiple parts, distributed on the corresponding number of GPUs, and the GPUs are sorted; the multi-task fine-tuning system includes a task configuration module, an analyzer, a task dynamic scheduler, and multi-task training modules distributed on multiple GPUs; each multi-task training module is used to implement the fine-tuning of the corresponding part of the LoRA model:

[0101] The large language model distributed pipelined parallel fine-tuning method, as Figure 7As shown, the following steps are included:

[0102] S1 generates multiple tasks through the task configuration module according to user requests, and divides each task into several training batches.

[0103] S2 configures hyperparameters for each task through a profiler.

[0104] The analyzer estimates the basic hyperparameters for each task configuration during system initialization and distributes them to the m-LoRA model on each GPU for initialization.

[0105] S3 generates a scheduling plan according to the training batch order of each task through the task dynamic scheduler combined with the dynamic scheduling strategy.

[0106] According to the scheduling goal in the user request, one of the strategies ①, ②, and ③ is selected to generate the scheduling task; for example, when the scheduling goal is to minimize waiting time, reduce turnaround time, and maximize throughput, the task dynamic scheduler automatically selects strategy ③; when the scheduling goal is to execute a series of tasks in sequence, the task dynamic scheduler automatically selects strategy ①.

[0107] S4 sends the scheduling plan to the multi-task training module on the first GPU in the positive order of the GPUs. The multi-task training module trains all LoRA models according to the training batches included in the scheduling plan; and transmits the training results to the multi-task training module on the next GPU. The above operation is repeated until the last GPU; then the loss function is determined based on the training results output by the last GPU, and the training results and loss function are fed back to the analyzer; at the same time, the loss function is back-propagated in the reverse order of the GPUs to optimize the LoRA model parameters of the corresponding part on the GPU.

[0108] The specific implementation of the multi-task training module is as described above and will not be explained in detail here.

[0109] During the back-propagation process, according to the loss function, the GPU optimizes the parameters of the corresponding parts of each LoRA model based on the gradient descent optimization algorithm.

[0110] After the training of the previous batch of tasks is completed, the analyzer optimizes and updates the hyperparameters based on the received back-propagation gradient information. At the same time, the analyzer counts the obtained loss values ​​to obtain the trend of the loss values ​​changing with the number of iterations; it also counts the obtained accuracy to obtain the trend of the accuracy changing with the number of iterations. The accuracy analysis results include the change of loss values ​​with the number of iterations, and also include the change of prediction accuracy with the number of iterations.

[0111] The S5 analyzer performs precision analysis based on the training results and loss function to determine whether all tasks meet the training requirements; if all tasks meet the training requirements, the program ends; otherwise, the precision analysis results are fed back to the task dynamic scheduler and return to step S3.

[0112] In this step, the analyzer counts the loss function values ​​obtained after each batch of training for each task based on the received loss function values ​​and training results, and obtains the trend of the loss value changing with the number of iterations; it also counts the obtained accuracy rate, and obtains the trend of the accuracy rate changing with the number of iterations. The accuracy analysis results include the change of the loss value with the number of iterations, and also include the change of the prediction accuracy with the number of iterations.

[0113] Repeat the above operation for each training batch until all LoRA models converge. When the loss function value or accuracy tends to be stable, the m-LoRA model is judged to be converged; the loss function value can also be used as a model convergence condition when it is less than the set threshold; or the m-LoRA model is judged to be converged based on whether the set number of iterations reaches the upper limit. When the model converges, the training goal (i.e. the scheduling goal mentioned above) is achieved.

[0114] In order to verify the effect of the fine-tuning method provided by the present invention, fine-tuning experiments on models such as LLaMA-7B / 13B, ChatGLM2-6B and LLaMA2-7B / 13B were conducted to prove the effectiveness of m-LoRA in optimizing the use of single GPU resources, memory usage and training throughput. Figure 8 and Fig. 9 m-LoRA demonstrates significant optimizations in GPU utilization, memory usage, and training throughput in a single GPU setting. Compared to Huggingface’s PEFT, a leading parameter-efficient fine-tuning library, m-LoRA achieves 53% savings in GPU memory usage, especially when training multiple LLaMA-7B models on an NVIDIA A100 80GB GPU. Fig. 9 As shown. Figure 8 As shown, m-LoRA has significant improvements in total training throughput and effective throughput compared to baselines, and its training throughput on various pre-trained models is about 17% higher than that of existing methods. m-LoRA's adaptive scheduling algorithm reduces the overall turnaround time and end-to-end training delay. Experimental results show that m-LoRA achieves a 12% reduction in end-to-end training delay and a 24% reduction in overall turnaround time. The experimental results reflect the advantages of m-LoRA in system efficiency and performance. As Figure 8As shown in the figure, by effectively utilizing computing resources, the m-LoRA model has a higher accuracy, and not only improves the training throughput, but also reduces the training delay, which is more efficient than the existing LoRA training system.

[0115] Therefore, the distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards provided by the present invention has the following advantages:

[0116] (1) The prior art has a relatively simple strategy in memory management, which fails to fully consider the memory sharing and dynamic scheduling between different tasks, resulting in low GPU memory resource utilization. The present invention is more intelligent and flexible in memory management and optimization, and can dynamically adjust according to real-time task requirements and GPU memory usage to improve GPU memory utilization and fine-tune the concurrent execution capability of tasks.

[0117] (2) The existing technology fails to fully consider the uneven computing power and communication overhead between different GPUs in model segmentation and distribution, resulting in low efficiency of parallel distributed fine-tuning. The present invention adopts a more intelligent and flexible model segmentation and distribution strategy, combined with pipeline optimization and load balancing technology, which can more effectively utilize the computing resources of a multi-machine and multi-card environment and improve the overall efficiency of the fine-tuning process.

[0118] (3) The existing technologies are relatively basic in terms of task scheduling and early stopping strategies, and fail to fully consider the priorities and dependencies between tasks, as well as the impact of early stopping on the overall performance of the system. The present invention designs a more intelligent and flexible task scheduling mechanism and dynamic early stopping strategy, which can adjust the task execution order and priority in real time according to task performance indicators and system load conditions, so as to maximize the overall throughput and resource utilization of the system.

[0119] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0120] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0121] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0122] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

[0123] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.

Claims

1. A distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards, characterized in that: Based on the multi-task fine-tuning system, multiple LoRA models are fine-tuned at the same time; each LoRA model is divided into multiple parts, distributed on a corresponding number of GPUs, and the GPUs are sorted; the multi-task fine-tuning system includes a task configuration module, an analyzer, a task dynamic scheduler, and a multi-task training module distributed on multiple GPUs; each multi-task training module is used to fine-tune the corresponding part of the LoRA model; The large language model distributed pipeline parallel fine-tuning method comprises the following steps: S1 generates multiple tasks through the task configuration module according to the user's request, and divides each task into several training batches; S2 configures hyperparameters for each task through the analyzer; S3 generates a scheduling plan based on the training batch order of each task through the task dynamic scheduler combined with the dynamic scheduling strategy; S4 sends the scheduling plan to the multi-task training module on the first GPU in the positive order of the GPUs. The multi-task training module trains all LoRA models according to the training batches included in the scheduling plan. The training results are transmitted to the multi-task training module on the next GPU, and the above operations are repeated until the last GPU. Then, the loss function is determined based on the training results output by the last GPU, and the training results and loss function are fed back to the analyzer. At the same time, the loss function is back-propagated in the reverse order of the GPUs to optimize the parameters of the corresponding part of the LoRA model on the GPU. The analyzer in S5 performs precision analysis based on the training results and the loss function to determine whether all tasks meet the training requirements; if all tasks meet the training requirements, the program ends; otherwise, the precision analysis results are fed back to the task dynamic scheduler and return to step S3.

2. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 1 is characterized in that: In step S3, the task dynamic scheduler sorts the task lengths in each batch, and uses the tasks with the same or similar task lengths in the same batch to complete the task symbol filling in the scheduling scheme.

3. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 1 or 2, characterized in that: The dynamic scheduling strategy includes: ① No early stopping strategy: execute in the order of tasks; ② Early stopping strategy: Initially, tasks are executed in order; during training, tasks with poor accuracy are terminated early based on the changing trend of the accuracy analysis results of the analyzer, and subsequent tasks are advanced; ③ Early stopping strategy with prediction: First, a scheduling plan is generated based on more than one batch of data for all tasks, and step S4 is executed for pre-testing to obtain the prediction results, which are fed back to the analyzer; the analyzer performs precision analysis based on the prediction results and generates a scheduling plan for subsequent tasks; in the subsequent training process, based on the changing trend of the analyzer's precision analysis results, tasks with deteriorating precision are terminated in advance, and subsequent tasks are advanced.

4. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 1, characterized in that: In step S4, the multi-task training module merges the training data of multiple tasks into one training set; In each iteration, multiple LoRA models share a pre-trained model.

5. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 4 is characterized in that: Given the input sequence x of the i-th task i , the output data will be h i ; The fused input matrix is ​​represented as X = Fusion(x1, ..., x n ); it will be multiplied by the pre-trained weights and all LoRA model weights, and then the results are added together to produce the final output H. The complete calculation formula is as follows: H=Concat(h1,…,h n )=W0X+[ΔW1x1,…,ΔW n x n ] =W0X+[B1A1x1,…,B n A n x n ] Among them, W0∈R d×k represents the shared pre-trained weights, d and k represent (row and column sizes of the matrix); ΔW i =B i A i represents the weight of the LoRA model trained for the i-th task, and are low-rank decomposition matrices respectively.

6. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 1, characterized in that: Based on the loss function value, the analyzer collects statistics on the loss function value obtained after each batch of training for each task, and further fits the loss function value.

7. The distributed pipeline parallel fine-tuning method for a large language model for heterogeneous GPU graphics cards according to claim 1 or 6, characterized in that: Based on the training results, the analyzer counts and fits the accuracy obtained after each batch of training for each task.

Citation Information

Cited By

  • Model training and business execution method and device, storage medium and equipment

    CN119150804A

  • Image-text interaction thinking machine control system and method

    CN119376957A

  • Power question query method based on multi-model fusion

    CN119988443A

  • Model fine tuning method based on intelligent calculation platform and intelligent calculation platform

    CN120069000A

  • Data analysis method and system based on large language model

    CN120258110A