Large language model alignment method and device, electronic equipment and storage medium

By dividing the large language model alignment process into multiple stages and adopting multiple strategies and parallel training methods, the problem of low alignment efficiency in the existing technology is solved, and more efficient alignment training and hardware resource utilization are achieved.

CN118780393AActive Publication Date: 2024-10-15TSINGHUA UNIVERSITY

Patent Information

Application Number
CN202410867620.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-15
Estimated Expiration
2044-06-28

AI Technical Summary

Technical Problem

Existing large language model alignment methods are inefficient and difficult to effectively improve the efficiency of the alignment process and hardware resource utilization.

Method used

The large language model alignment process is divided into multiple stages, and intra-stage strategies and inter-stage strategies are determined based on the workload characteristics and data dependencies of each stage, using sequential execution, single-module specific device strategy, multi-module specific device strategy and split The real-time execution strategy combines the parallel training methods of pipeline parallelism and tensor parallelism to optimize context switching and parallel training method conversion.

Benefits of technology

It significantly improves the efficiency of alignment training and the utilization of hardware resources, and improves the overall performance of large language model alignment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118780393A_ABST
    Figure CN118780393A_ABST
Patent Text Reader

Abstract

The invention relates to a large language model alignment method and device, electronic equipment and a storage medium. The method comprises the steps that the alignment process of a large language model is divided into a plurality of stages; sub-stages of the stages and intra-stage strategies corresponding to the stages are determined, and the intra-stage strategies represent hardware sharing strategies of the modules and the execution sequence of the modules during training; determining an inter-stage strategy, wherein the inter-stage strategy represents parallel training modes corresponding to different stages; and aligning a to-be-aligned model according to each intra-stage strategy and each inter-stage strategy to obtain a target model. In the alignment process, the corresponding intra-stage strategy and inter-stage strategy are determined for each stage, the possible efficiency optimization possibility in the context switching process and the possible efficiency optimization opportunity in the parallel training mode conversion process are considered, and the alignment training efficiency and the utilization rate of hardware resources are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a large language model alignment method and device, an electronic device, and a storage medium. Background Art

[0002] In recent years, large language models (LLMs) represented by OpenAI ChatGPT and GPT-4 have developed rapidly. In addition to demonstrating strong language capabilities, they are approaching human levels at an astonishing rate in many fields such as mathematics, reasoning, medicine, law, and programming.

[0003] What follows is widespread concern about the social and ethical risks of large language models themselves and the potential threat they pose to human survival.

[0004] Large language model alignment mainly refers to the alignment of large language models with human values, emphasizing the need for these advanced artificial intelligence systems to operate in an ethically responsible and socially beneficial manner. Currently, the main method to achieve this alignment process is through the reinforcement learning with human feedback (RLHF) method. Within the framework of this method, proximal policy optimization (PPO) as a recognized standard algorithm has significantly improved the reliability of large language models in many tasks, including natural language processing, text to image and other fields.

[0005] However, the efficiency of alignment on large language models needs to be improved. Summary of the invention

[0006] In view of this, the present disclosure proposes a large language model alignment solution.

[0007] According to one aspect of the present disclosure, a large language model alignment method is provided, comprising:

[0008] Divide the alignment process of large language models into multiple stages;

[0009] Determine the sub-stages of each stage and the intra-stage strategies corresponding to each stage, wherein the intra-stage strategies represent the modules' sharing strategies for hardware and the execution order of the modules during training;

[0010] Determine an inter-stage strategy, wherein the inter-stage strategy represents a parallel training method corresponding to different stages;

[0011] The models to be aligned are aligned according to the strategies within each stage and the strategies between each stage to obtain a target model.

[0012] In one possible implementation, the determining of the sub-stages of each stage, and the target stage strategies corresponding to each stage, includes: determining a combination of modules used for training in a single stage, wherein each combination corresponds to a sub-stage division method; based on each combination, determining to execute the tasks in the single stage according to the strategies in each stage, to obtain multiple first durations; and based on the multiple first durations, determining the target stage strategy and the target sub-stage division method.

[0013] In a possible implementation, the intra-stage strategies include: a sequential execution strategy, a single-module specific device strategy, and a multi-module specific device strategy; the sequential execution strategy indicates that the modules share all the hardware and the modules are executed sequentially; the single-module specific device strategy indicates that different hardware is assigned to the modules and the modules are executed in parallel; the modules include: a first group of modules and a second group of modules, and the hardware includes: a first group of hardware and a second group of hardware; the multi-module specific device strategy indicates that the first group of modules shares the first group of hardware, the modules in the first group of modules are executed sequentially, the modules in the second group of modules use and do not share the hardware in the second group of hardware, and the modules in the second group of modules are executed in parallel.

[0014] In a possible implementation, the multi-model specific device strategy also includes: a time-sharing execution strategy; the time-sharing execution strategy represents that when the first group of modules share the first group of hardware, each module in the first group of modules is executed alternately and sequentially to reduce the idle time of the first group of hardware.

[0015] In a possible implementation, the parallel training mode includes: pipeline parallelism and tensor parallelism, and the determination of the inter-stage strategy includes: increasing the parallelism degree of the tensor parallelism of the previous stage, and reducing the parallelism degree of the pipeline parallelism of the previous stage, to obtain the parallel training mode of the current stage; and using the parallel training mode of the current stage as the inter-stage strategy of the current stage.

[0016] In a possible implementation, the parallelism of the tensor parallelism of the previous stage is increased, and the parallelism of the pipeline parallelism of the previous stage is reduced to obtain the parallel training mode of the current stage, including: determining the second duration of the task executed in the previous stage; executing the task executed in the current stage under various combinations of pipeline parallelism and tensor parallelism to obtain multiple third durations; determining the communication duration between the previous stage and the current stage corresponding to each of the combinations; and determining the combination with the smallest sum of the second duration, each of the third durations, and each of the communication durations as the parallel training mode of the current stage.

[0017] In a possible implementation, the determining of the inter-stage strategy further includes: determining whether the parallel training mode of the current stage needs to be adjusted; and determining the inter-stage strategy of the current stage when the parallel training mode of the current stage needs to be adjusted.

[0018] According to another aspect of the present disclosure, a large language model alignment system is provided, comprising:

[0019] The stage division unit is used to divide the alignment process of the large language model into multiple stages;

[0020] An intra-stage strategy determination unit, used to determine the sub-stages of each stage and the intra-stage strategy corresponding to each stage, wherein the intra-stage strategy represents the module's sharing strategy for hardware and the execution order of the modules during training;

[0021] An inter-stage strategy determination unit, used to determine an inter-stage strategy, wherein the inter-stage strategy represents a parallel training method corresponding to different stages;

[0022] The alignment unit is used to align the models to be aligned according to the strategies within each stage and the strategies between each stage to obtain a target model.

[0023] In a possible implementation, the intra-stage strategy determination unit includes:

[0024] A combination mode determining unit, used to determine a combination mode of modules used for training in a single stage, wherein a single combination mode corresponds to a sub-stage division mode;

[0025] A first duration determining unit is used to determine, based on each of the combination modes, respectively according to the strategies in each stage to execute the tasks in the single stage, so as to obtain a plurality of first durations;

[0026] The intra-stage strategy determination unit is further used to:

[0027] Based on the multiple first time lengths, the strategy within the target stage and the target sub-stage division method are determined.

[0028] In a possible implementation, the in-stage strategies include: sequential execution strategy, single-module specific device strategy, and multi-module specific device strategy;

[0029] The sequential execution strategy indicates that all modules share all hardware and the modules are executed sequentially;

[0030] The single-module specific device strategy indicates that each module is allocated different hardware, and each module is executed in parallel;

[0031] The modules include: a first group of modules and a second group of modules, and the hardware includes: a first group of hardware and a second group of hardware;

[0032] The multi-module specific device strategy represents that the first group of modules share the first group of hardware, the modules in the first group of modules are executed sequentially, the modules in the second group of modules use but do not share hardware in the second group of hardware, and the modules in the second group of modules are executed in parallel.

[0033] In a possible implementation, the multi-model specific device strategy further includes: a time-sharing execution strategy;

[0034] The time-sharing execution strategy indicates that when the first group of modules share the first group of hardware, the modules in the first group of modules are executed alternately and sequentially to reduce the idle time of the first group of hardware.

[0035] In a possible implementation, the parallel training mode includes: pipeline parallelism and tensor parallelism, and the inter-stage strategy determination unit is further used to:

[0036] Increase the parallelism of tensor parallelism in the previous stage, and reduce the parallelism of pipeline parallelism in the previous stage, to obtain the parallel training mode of the current stage;

[0037] The parallel training mode of the current stage is used as the inter-stage strategy of the current stage.

[0038] In a possible implementation, the step of increasing the parallelism of tensor parallelism in the previous stage and decreasing the parallelism of pipeline parallelism in the previous stage to obtain a parallel training mode in the current stage includes:

[0039] Determining a second duration of executing the task in the previous stage;

[0040] Under various combinations of pipeline parallelism and tensor parallelism, the tasks executed in the current stage are executed to obtain multiple third durations;

[0041] Determine the communication duration between the previous stage and the current stage corresponding to each of the collocation modes;

[0042] The combination mode in which the sum of the second duration, each of the third durations, and each of the communication durations is minimized is determined as the parallel training mode in the current stage.

[0043] In a possible implementation manner, the inter-stage strategy determination unit is further configured to:

[0044] Determining whether the parallel training mode of the current stage is adjusted;

[0045] When the parallel training mode of the current stage needs to be adjusted, the inter-stage strategy of the current stage is determined.

[0046] According to another aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0047] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions implement the above method when executed by a processor.

[0048] According to another aspect of the present disclosure, a computer program product is provided, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above method.

[0049] In the embodiments of the present disclosure, possible efficiency optimization possibilities during context switching and possible efficiency optimization opportunities during parallel training mode conversion are taken into consideration, and corresponding intra-stage strategies and inter-stage strategies are determined for each stage, thereby improving the efficiency of alignment training and the utilization of hardware resources.

[0050] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.

[0052] Figure 1 A flowchart of a large language model alignment method provided in the present disclosure.

[0053] Figure 2 A schematic diagram of the combination of modules provided in the present disclosure.

[0054] Figure 3 A schematic diagram of the effects before and after using the time-sharing execution strategy provided by the present invention.

[0055] Figure 4 Schematic diagram of the conversion of parallel training methods between stages.

[0056] Figure 5 A schematic diagram of the acceleration effect of large language model alignment provided by the present invention.

[0057] Figure 6A schematic diagram of the structure of a large language model alignment system provided in the present disclosure.

[0058] Figure 7 A schematic diagram of the structure of an electronic device for large language model alignment provided by the present disclosure. DETAILED DESCRIPTION

[0059] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0060] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0061] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the main purpose of the present disclosure.

[0062] Figure 1 A flow chart of a large language model alignment method provided by the present disclosure. Figure 1 As shown, the method includes:

[0063] S11, divides the alignment process of the large language model into multiple stages.

[0064] The alignment of a large language model can be considered as a training process. A system for performing alignment training of a large language model may include multiple modules, such as a forward propagation module and a backward propagation module. Another example is an actor module, a critic module, a reference module, a reward module, etc. in reinforcement learning. The present disclosure does not limit the type of module.

[0065] In an embodiment of the present disclosure, the alignment process can be divided into multiple stages based on the workload characteristics and data dependencies of the system in the alignment process. The workload characteristics here can characterize the amount of hardware resources and network resources occupied, or characterize the amount of calculation. Data dependency can be reflected in the switching of execution tasks between modules during training. For ease of description, the present disclosure names the workload characteristics and modules as contexts. In other words, the alignment process can be divided into multiple stages based on the context. One or more modules may be used in each stage.

[0066] Exemplarily, the alignment process can be divided into a generation phase, an inference phase, and a learning phase. In the generation phase, the natural language data can be converted into vectors through forward propagation. In the inference phase, the inference process of the large language model can be completed. In the learning phase, the parameter adjustment process of the large language model can be completed based on the concept of reinforcement learning. The order of these three phases can be: first go through the generation phase, then go through the inference phase, and finally enter the learning phase. The three phases are repeated continuously in this order until the output of the large language model meets the preset stop alignment condition.

[0067] S12, determining the sub-stages of each stage and the intra-stage strategies corresponding to each stage, wherein the intra-stage strategies represent the modules' sharing strategies for hardware and the execution order of the modules during training.

[0068] A single stage may include one, two or more sub-stages. When a stage includes a sub-stage, it means that the stage itself is inseparable and the stage itself is a sub-stage. In the disclosed embodiment, a single stage may be divided into sub-stages according to the order of steps of tasks performed in the single stage; or a single stage may be divided according to the order of execution of modules used in the single stage.

[0069] A single stage can correspond to an intra-stage strategy. The same intra-stage strategy can be used in each sub-stage of the same stage. The intra-stage strategy can characterize the module's sharing strategy for hardware during training and the execution order of the modules. Therefore, in one example, after determining the sharing strategy, the execution order of the modules can be obtained, and then each sub-stage can be automatically obtained based on the execution order of the modules. The disclosed embodiment does not limit the method of dividing the sub-stages.

[0070] The intra-stage strategy can improve the execution efficiency and utilization of hardware resources while completing the established tasks of the entire stage.

[0071] For example, in the first stage, task A needs to be executed by three modules. Each model executes one step, and the output of the previous module is used as the input of the next module. Therefore, the three modules need to be executed sequentially. Since the sequential execution can share hardware resources, the first stage in this example is suitable for the intra-stage strategy in which the modules in the stage are executed sequentially and all share hardware resources.

[0072] For example, task B is executed in the second stage, and only one step is executed in the second stage, and the four modules are executed together. Each module is independent of each other in terms of input data and output data. Therefore, the four modules can be executed in parallel. Since parallel execution cannot share hardware resources, exclusive hardware resources should be allocated to each of the four modules. Therefore, the second stage in this example uses the intra-stage strategy in which the modules in the stage are executed sequentially and do not share hardware resources.

[0073] S13, determining an inter-stage strategy, where the inter-stage strategy represents a parallel training method corresponding to different stages.

[0074] Due to the context switching between stages, the parallel training modes between stages can be different. Of course, the parallel training modes between stages can also be the same.

[0075] The parallel training method can be a combination of at least two of the following: zero-redundancy optimizer parallelism, data parallelism, pipeline parallelism, and tensor parallelism. The specific combination method is related to the number of layers and nodes of the large language model. This will be described in detail later, so I will not elaborate on it here.

[0076] A single stage can correspond to an inter-stage strategy. The inter-stage strategies of adjacent stages can be the same or different. Determining the applicable inter-stage strategy for each stage can improve the overall execution efficiency of the adjacent stages as a whole when context switching occurs during stage changes.

[0077] For example, the inter-stage strategy corresponding to the current stage can be determined based on the goal of taking the current stage and the previous stage as a whole and executing the task in the shortest time.

[0078] S14, aligning the models to be aligned according to the strategies within each stage and the strategies between each stage to obtain a target model.

[0079] In the embodiments of the present disclosure, possible efficiency optimization possibilities during context switching and possible efficiency optimization opportunities during parallel training mode conversion are taken into consideration, and corresponding intra-stage strategies and inter-stage strategies are determined for each stage, thereby improving the efficiency of alignment training and the utilization of hardware resources.

[0080] In one possible implementation, the determining of the sub-stages of each stage, and the target stage strategies corresponding to each stage, includes: determining a combination of modules used for training in a single stage, wherein each combination corresponds to a sub-stage division method; based on each combination, determining to execute the tasks in the single stage according to the strategies in each stage, to obtain multiple first durations; and based on the multiple first durations, determining the target stage strategy and the target sub-stage division method.

[0081] In the disclosed embodiments, the combination of modules in a single stage can be determined based on the modules used in a single stage, data dependencies, etc. The combination method here can be a method of grouping modules in a stage. Modules in the same group can be executed in parallel, and modules in each group are executed in sequence. One or more initial combination methods can be determined based on the number of models, and then some initial combination methods can be screened out based on the data dependencies of each module to obtain the final combination method.

[0082] For example, the third stage performs Task C, using three modules in total. For ease of description, the three modules are named Module 1, Module 2, and Module 3. Part of the input data of Module 3 is the output data of Module 1, that is, in terms of data, Module 3 depends on Module 1. There are five possible initial combinations. Figure 2 Schematic diagram of the combination of modules provided by the present disclosure. Figure 2 As shown, the circular icon represents a module, and the number in the circular icon represents the module number. The square icon represents a group. The first type can be that module 1, module 2, and module 3 are each a group. The second type can be that module 1, module 2, and module 3 are a group together. The third type can be that module 1 and module 2 are a group, and module 3 is a separate group. The fourth type can be that module 1 is a separate group, and module 2 and module 3 are a group. The fifth type can be that module 1 and module 3 are a group, and module 2 is a separate group.

[0083] Since module 3 depends on module 1 in terms of data, module 3 and module 1 cannot be parallel, that is, they cannot be grouped in the same group. Therefore, the second and fifth combinations are excluded. The remaining three combinations (the first, third, and fourth) are used as the combination methods of each module in the third stage.

[0084] In the embodiment of the present disclosure, there may be multiple strategies within a stage. For each combination, the tasks to be performed in the stage may be performed according to the strategies within each stage, and the duration used to perform the tasks may be obtained respectively. For ease of description, the duration is named as the first duration. That is, multiple first durations may be obtained. Each first duration may correspond to a combination and a strategy within a stage.

[0085] In the embodiment of the present disclosure, the combination corresponding to the shortest first duration can be used as the target combination, the corresponding in-stage strategy can be used as the target in-stage strategy of the stage, and a single group in the target combination can be used as a sub-stage. Alternatively, the combination corresponding to the first duration that falls within the preset duration threshold range can be used as the target combination; the corresponding in-stage strategy can be used as the target in-stage strategy.

[0086] Still Figure 2For example, assuming that the fifth combination is the target combination, then this stage can be divided into two sub-stages. In the first sub-stage, module 1 runs, and in the second sub-stage, modules 2 and 3 run in parallel. The first sub-stage and the second sub-stage are executed sequentially.

[0087] In the disclosed embodiment, the combination of each module in the stage is first determined, and based on each combination, tasks are executed according to the strategies in each stage to obtain multiple first durations, and then the strategies in the target stage and the target sub-stage division method are determined based on the first durations. The strategies and sub-stages in the stage determined in this way can make the execution efficiency of the stage higher, and improve the execution efficiency in a single stage.

[0088] In a possible implementation, the intra-stage strategies include: a sequential execution strategy, a single-module specific device strategy, and a multi-module specific device strategy; the sequential execution strategy indicates that the modules share all the hardware and the modules are executed sequentially; the single-module specific device strategy indicates that different hardware is assigned to the modules and the modules are executed in parallel; the modules include: a first group of modules and a second group of modules, and the hardware includes: a first group of hardware and a second group of hardware; the multi-module specific device strategy indicates that the first group of modules shares the first group of hardware, the modules in the first group of modules are executed sequentially, the modules in the second group of modules use and do not share the hardware in the second group of hardware, and the modules in the second group of modules are executed in parallel.

[0089] As mentioned above, there can be multiple intra-stage strategies. In the disclosed embodiment, the intra-stage strategies may include: sequential execution strategy, single-module specific device strategy, and multi-module specific device strategy. These three strategies are respectively limited in terms of the degree of hardware sharing and the order of module execution. The execution efficiency of the same task may be different for different module combinations and different intra-stage strategies, and the hardware utilization may also be different. Therefore, the combination and intra-stage strategy with the best execution efficiency and hardware utilization can be selected. It helps to improve the execution efficiency and hardware utilization of a single stage.

[0090] In the embodiment of the present disclosure, after the initial combination mode is determined, the initial stage strategy can be screened out according to whether the initial combination mode is compatible with the stage strategy.

[0091] Still Figure 2 For example, illustratively, the second combination method indicates that the stage itself is a sub-stage, and modules 1, 2, and 3 are executed in parallel, so the sequential execution strategy is not suitable for the second combination method. Therefore, when determining the first duration, the second combination method can be used without executing the task in a sequential manner.

[0092] For another example, the third combination method indicates that module 1 and module 2 are executed in parallel, and the sequential execution strategy is not suitable for the third combination method. Therefore, when determining the first duration, the task can be executed without following the sequential execution strategy for the third combination method.

[0093] For another example, the first combination method indicates that module 1, module 2, and module 3 are executed sequentially, so at least part of the hardware can be shared. In order to improve hardware utilization, when determining the first duration, the task can be executed for the first combination method without following the single-module specific device strategy.

[0094] The above is only an example, and the disclosed embodiment does not limit the method for selecting the strategies in the initial stage. In this way, the number of executions can be reduced and the efficiency of determining the strategies and sub-stages in the stage can be improved.

[0095] In a possible implementation, the multi-model specific device strategy also includes: a time-sharing execution strategy; the time-sharing execution strategy represents that when the first group of modules share the first group of hardware, each module in the first group of modules is executed alternately and sequentially to reduce the idle time of the first group of hardware.

[0096] In order to further improve the execution efficiency within the stage and improve the utilization of hardware resources, a time-sharing execution strategy is further designed when executing the multi-model specific device strategy. The time-sharing execution strategy is mainly aimed at the situation where some modules (the first group of modules) share hardware within the stage. The first group of modules share hardware, so the modules in the first group of modules are executed sequentially. There may be idle and usable time during the execution of each module and the switching of each module. The time-sharing execution strategy can enable each module to execute alternately while retaining the sequential execution between modules, effectively utilizing this part of the idle and usable time, shortening the execution time within the stage, and improving the execution efficiency within the stage.

[0097] Figure 3 This is a schematic diagram of the effects before and after using the time-sharing execution strategy provided by the present disclosure. Figure 3 As shown, the upper part shows the situation without using the time-sharing execution strategy; the lower part shows the situation after using the time-sharing execution strategy.

[0098] There is idle and usable time when switching between modules (context switching) in the first group of modules. For the convenience of description, this idle and usable time is named as idle time. Figure 3 Idle time is represented by dark grey rectangles.

[0099] like Figure 3As shown, when the time-sharing execution strategy is not used, module 2 starts to execute forward traversal after module 1 completes backward traversal. However, idle time occurs during the process of module 1 executing backward traversal and between module 1 executing backward traversal and module 2 executing forward traversal. Moreover, when the time-sharing execution strategy is not used, the storage unit is occupied for a long time; the consumption of storage units per unit time is uneven, and the storage units are not efficiently utilized. However, after the time-sharing execution strategy is used, the backward traversal performed by module 1 and module 2 are performed alternately, so that the idle time is effectively utilized, the storage unit is consumed evenly per unit time, the occupation time of the storage unit is shortened, and the utilization rate of the storage unit is improved.

[0100] Therefore, in the embodiment of the present disclosure, when using a multi-module specific device strategy, further using a time-sharing execution strategy can further improve the execution efficiency within the stage, improve the utilization rate of the hardware, and reduce the occupation time of shared hardware resources.

[0101] In a possible implementation, the parallel training mode includes: pipeline parallelism and tensor parallelism, and the determination of the inter-stage strategy includes: increasing the parallelism degree of the tensor parallelism of the previous stage, and reducing the parallelism degree of the pipeline parallelism of the previous stage, to obtain the parallel training mode of the current stage; and using the parallel training mode of the current stage as the inter-stage strategy of the current stage.

[0102] Different combinations of tensor parallelism and pipeline parallelism can have a certain impact on the execution efficiency between stages, so the correct choice of the combination of tensor parallelism and pipeline parallelism can bring about the possibility of improving the efficiency of alignment training. It is also found that after the stage switch, in the current stage, according to the principle of adjusting from higher pipeline parallelism (and lower tensor parallelism) to lower pipeline parallelism (and higher tensor parallelism), the parallel training method is converted, which can greatly improve the overall execution efficiency of the previous stage and the current stage. It is especially suitable for embodiments in which the generation stage, reasoning stage, and learning stage are executed sequentially and reciprocally.

[0103] In the disclosed embodiment, the parallel training mode of the previous stage can be obtained, including: the parallel degree of tensor parallelism and the parallel degree of pipeline parallelism of the previous stage. The pipeline parallelism can be represented by the number of layers executed in parallel in the module, and the tensor parallelism can be represented by the number of parameter tensors executed in parallel in the module. Based on the above-mentioned principles, the number of layers executed in parallel in the module is increased, and the number of parameter tensors executed in parallel is reduced to determine the parallel training mode of the current stage.

[0104] Figure 4 This is a schematic diagram of the conversion of parallel training modes between stages. Figure 4 As shown in the figure, the rectangle filled with lines represents a tensor. For the sake of distinction, the filling forms of the four tensors are different. In the previous stage, the parallelism of pipeline parallelism was 4, and the parallelism of tensor parallelism was 1, which is simply expressed as (4,1). Based on the above principles, in the current stage, the parallelism of pipeline parallelism is reduced and the parallelism of tensor parallelism is increased. Therefore, after adjustment, the parallelism of pipeline parallelism is 2, and the parallelism of tensor parallelism is 2, which is simply expressed as (2,2). The parallel training mode is converted from (4,1) to (2,2) as the inter-stage strategy of the current stage. Here, other parallel training modes (data parallelism, zero-redundancy optimizer parallelism) are not shown, indicating that other parallel training modes remain consistent in the two stages.

[0105] In the disclosed embodiment, the current stage and the previous stage are considered as a whole. Compared with the previous stage, the parallelism of tensor parallelism is increased and the parallelism of pipeline parallelism is decreased to improve the overall execution efficiency, which helps to improve the efficiency of alignment training.

[0106] In a possible implementation, the parallelism of the tensor parallelism of the previous stage is increased, and the parallelism of the pipeline parallelism of the previous stage is reduced to obtain the parallel training mode of the current stage, including: determining the second duration of the task executed in the previous stage; executing the task executed in the current stage under various combinations of pipeline parallelism and tensor parallelism to obtain multiple third durations; determining the communication duration between the previous stage and the current stage corresponding to each of the combinations; and determining the combination with the smallest sum of the second duration, each of the third durations, and the communication duration as the parallel training mode of the current stage.

[0107] There are many ways to match pipeline parallelism and tensor parallelism. Different third durations may be required to perform the tasks of the current stage in different combinations. Moreover, the communication durations between modules may be different for different combinations. In order to improve the overall efficiency of the current stage and the previous stage, the combination that makes the total duration of these two stages the shortest can be used as the parallel training method for the current stage. Therefore, the second duration, the third duration corresponding to each combination, and the communication duration can be summed, and the combination with the smallest value and corresponding to it can be used as the parallel training method for the current stage, that is, as the inter-stage strategy for the current stage.

[0108] By using the method of the embodiment of the present disclosure, an inter-stage strategy for improving the efficiency of alignment training can be effectively determined.

[0109] In a possible implementation, the determining of the inter-stage strategy further includes: determining whether the parallel training mode of the current stage needs to be adjusted; and determining the inter-stage strategy of the current stage when the parallel training mode of the current stage needs to be adjusted.

[0110] In the disclosed embodiment, the user can determine and indicate whether to adjust the parallel training mode of the current stage through the human-computer interaction interface. Or it can be automatically determined whether to adjust the current parallel training mode. If it is determined that adjustment is required, the inter-stage strategy of the current stage is determined. In this way, in the scenario where it is obviously not necessary to adjust the parallel training mode between stages, the process of determining the inter-stage strategy is eliminated, thereby improving the efficiency of alignment training. Moreover, the inter-stage strategy can be temporarily increased or decreased according to different scenarios, thereby improving flexibility.

[0111] Figure 5 A schematic diagram of the acceleration effect of large language model alignment provided by the present disclosure. Figure 5 As shown in the figure, the alignment efficiency of DS-Chat, PUZZLE-Base, and the system in the present disclosure are compared on the two platforms of NVIDIA-A100-PCIe and NVIDIA-A100-NVLink. Among them, the horizontal axis represents the parameter amount of each in the actor module and the critic module in the PPO algorithm (the parameter amount of the establishment module and the critic module is the same, not shown in the figure); the vertical axis represents the acceleration multiple. It can be seen from the figure that on both platforms, the system in the present disclosure improves the alignment efficiency compared with the two systems (DS-Chat, PUZZLE-Base). Especially on the NVIDIA-A100-PCIe platform, the system in the present disclosure has achieved outstanding acceleration effect.

[0112] Figure 6 This is a schematic diagram of the structure of the large language model alignment system provided by the present disclosure. Figure 6 As shown, the system 200 includes:

[0113] A stage division unit 201, used to divide the alignment process of the large language model into multiple stages;

[0114] An intra-stage strategy determination unit 202, used to determine the sub-stages of each stage and the intra-stage strategy corresponding to each stage, wherein the intra-stage strategy represents the module's hardware sharing strategy and the execution order of the modules during training;

[0115] An inter-stage strategy determination unit 203, configured to determine an inter-stage strategy, wherein the inter-stage strategy represents a parallel training method corresponding to different stages;

[0116] The alignment unit 204 is used to align the models to be aligned according to the intra-stage strategies and the inter-stage strategies to obtain a target model.

[0117] In the disclosed embodiment, the alignment algorithm and the model structure may be input into the system 200. The alignment algorithm may include: Proximal Policy Optimization (PPO); the model structure may be the structure of a large language model to be aligned, which may include: various layers, nodes, weights, connections and other elements of the model, as well as their layout and organization.

[0118] The stage division unit 201 can automatically determine the hardware configuration of the system, for example, the number of GPUs. The stage division unit 201 divides the alignment process into multiple stages based on the alignment algorithm, model structure and hardware configuration. Based on the division results of each stage, the intra-stage strategy determination unit 202 can determine the intra-stage strategy for each stage; based on the division results of each stage, the inter-stage strategy determination unit 203 can determine the inter-stage strategy for each stage. The alignment unit 204 aligns the models to be aligned according to the intra-stage strategies and inter-stage strategies until the preset stop condition is met, stops the alignment, and obtains the target model.

[0119] In a possible implementation, the intra-stage strategy determination unit includes:

[0120] A combination mode determining unit, used to determine a combination mode of modules used for training in a single stage, wherein a single combination mode corresponds to a sub-stage division mode;

[0121] A first duration determining unit is used to determine, based on each of the combination modes, respectively according to the strategies in each stage to execute the tasks in the single stage, so as to obtain a plurality of first durations;

[0122] The intra-stage strategy determination unit is further used to:

[0123] Based on the multiple first time lengths, the strategy within the target stage and the target sub-stage division method are determined.

[0124] In a possible implementation, the in-stage strategies include: sequential execution strategy, single-module specific device strategy, and multi-module specific device strategy;

[0125] The sequential execution strategy indicates that all modules share all hardware and the modules are executed sequentially;

[0126] The single-module specific device strategy indicates that each module is allocated different hardware, and each module is executed in parallel;

[0127] The modules include: a first group of modules and a second group of modules, and the hardware includes: a first group of hardware and a second group of hardware;

[0128] The multi-module specific device strategy represents that the first group of modules share the first group of hardware, each module in the first group of modules is executed sequentially, each module in the second group of modules uses and does not share hardware in the second group of hardware, and each module in the second group of modules is executed in parallel.

[0129] In a possible implementation, the multi-model specific device strategy further includes: a time-sharing execution strategy;

[0130] The time-sharing execution strategy indicates that when the first group of modules share the first group of hardware, the modules in the first group of modules are executed alternately and sequentially to reduce the idle time of the first group of hardware.

[0131] In a possible implementation, the parallel training mode includes: pipeline parallelism and tensor parallelism, and the inter-stage strategy determination unit is further used to:

[0132] Increase the parallelism of tensor parallelism in the previous stage, and reduce the parallelism of pipeline parallelism in the previous stage, to obtain the parallel training mode of the current stage;

[0133] The parallel training mode of the current stage is used as the inter-stage strategy of the current stage.

[0134] In a possible implementation, the step of increasing the parallelism of tensor parallelism in the previous stage and decreasing the parallelism of pipeline parallelism in the previous stage to obtain a parallel training mode in the current stage includes:

[0135] Determining a second duration of executing the task in the previous stage;

[0136] Under various combinations of pipeline parallelism and tensor parallelism, the tasks executed in the current stage are executed to obtain multiple third durations;

[0137] Determine the communication duration between the previous stage and the current stage corresponding to each of the collocation modes;

[0138] The combination mode in which the sum of the second duration, each of the third durations, and each of the communication durations is minimized is determined as the parallel training mode in the current stage.

[0139] In a possible implementation manner, the inter-stage strategy determination unit is further configured to:

[0140] Determining whether the parallel training mode of the current stage is adjusted;

[0141] When the parallel training mode of the current stage needs to be adjusted, the inter-stage strategy of the current stage is determined.

[0142] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0143] The embodiment of the present disclosure also provides a computer-readable storage medium on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.

[0144] An embodiment of the present disclosure further proposes an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0145] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above method.

[0146] Figure 7 A schematic diagram of the structure of an electronic device for large language model alignment provided by the present disclosure. For example, the electronic device 1900 can be provided as a server or a terminal device. Figure 7 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0147] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM or similar.

[0148] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.

[0149] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0150] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.

[0151] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0152] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0153] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0154] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0155] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0156] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0157] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A large language model alignment method, characterized in that: include: Divide the alignment process of large language models into multiple stages; Determine the sub-stages of each stage and the intra-stage strategies corresponding to each stage, wherein the intra-stage strategies represent the modules' sharing strategies for hardware and the execution order of the modules during training; Determine an inter-stage strategy, wherein the inter-stage strategy represents a parallel training method corresponding to different stages; The models to be aligned are aligned according to the strategies within each stage and the strategies between each stage to obtain a target model.

2. The method according to claim 1, characterized in that The determining of the sub-stages of each stage and the target stage strategies corresponding to each stage includes: Determine a combination method of modules used for training in a single stage, wherein each combination method corresponds to a sub-stage division method; Based on the respective combination modes, determining to execute the tasks in the respective single stages according to the strategies in the respective stages, and obtaining a plurality of first durations; Based on the multiple first time lengths, the strategy within the target stage and the target sub-stage division method are determined.

3. The method according to claim 1, characterized in that The strategies within the stage include: sequential execution strategy, single module specific device strategy, and multi-module specific device strategy; The sequential execution strategy indicates that all modules share all hardware and the modules are executed sequentially; The single-module specific device strategy indicates that each module is allocated different hardware, and each module is executed in parallel; The modules include: a first group of modules and a second group of modules, and the hardware includes: a first group of hardware and a second group of hardware; The multi-module specific device strategy represents that the first group of modules share the first group of hardware, each module in the first group of modules is executed sequentially, each module in the second group of modules uses and does not share hardware in the second group of hardware, and each module in the second group of modules is executed in parallel.

4. The method according to claim 3, characterized in that The multi-model specific device strategy also includes: a time-sharing execution strategy; The time-sharing execution strategy indicates that when the first group of modules share the first group of hardware, the modules in the first group of modules are executed alternately and sequentially to reduce the idle time of the first group of hardware.

5. The method according to claim 1, characterized in that The parallel training mode includes: pipeline parallelism and tensor parallelism, and the inter-stage strategy determination includes: Increase the parallelism of tensor parallelism in the previous stage, and reduce the parallelism of pipeline parallelism in the previous stage, to obtain the parallel training mode of the current stage; The parallel training mode of the current stage is used as the inter-stage strategy of the current stage.

6. The method according to claim 5, characterized in that The parallelism degree of tensor parallelism in the previous stage is increased, and the parallelism degree of pipeline parallelism in the previous stage is reduced to obtain the parallel training mode in the current stage, including: Determining a second duration of executing the task in the previous stage; Under various combinations of pipeline parallelism and tensor parallelism, the tasks executed in the current stage are executed to obtain multiple third durations; Determine the communication duration between the previous stage and the current stage corresponding to each of the collocation modes; The combination mode in which the sum of the second duration, each of the third durations, and each of the communication durations is minimized is determined as the parallel training mode in the current stage.

7. The method according to claim 6, characterized in that The determining of the inter-stage strategy further includes: Determining whether the parallel training mode of the current stage is adjusted; When the parallel training mode of the current stage needs to be adjusted, the inter-stage strategy of the current stage is determined.

8. A large language model alignment system, characterized in that: include: The stage division unit is used to divide the alignment process of the large language model into multiple stages; An intra-stage strategy determination unit, used to determine the sub-stages of each stage and the intra-stage strategy corresponding to each stage, wherein the intra-stage strategy represents the module's sharing strategy for hardware and the execution order of the modules during training; An inter-stage strategy determination unit, used to determine an inter-stage strategy, wherein the inter-stage strategy represents a parallel training method corresponding to different stages; The alignment unit is used to align the models to be aligned according to the strategies within each stage and the strategies between each stage to obtain a target model.

9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to implement the method described in any one of claims 1 to 7 when executing the instructions stored in the memory.

10. A non-volatile computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • System, method for executing automatic machine learning scheme and electronic equipment

    CN110728371A

  • Large model correction method

    CN118245752A

Cited By

  • Dynamic parallelism mode switching for operating artificial intelligence model

    US12737224B1