Model training method and device, electronic equipment and storage medium
By converting the model training framework of the second GPU and adapting to the model training framework of the first GPU, the problem of low GPU resource utilization when training large language models in the prior art is solved, and an efficient model pre-training and scalability training framework is realized.
Patent Information
- Application Number
- CN202411975054.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
AI Technical Summary
The existing technology requires expensive multi-card multi-node GPU clusters when training large language models, and the training efficiency of existing open source systems is low on machine utilization, making it difficult to effectively utilize model training frameworks such as DeepSpeed.
By performing parameter conversion on the second model training framework adapted to the second GPU, the first model training framework adapted to the first GPU is determined, and based on this framework, the first GPU is called to perform model pre-training, so that the first GPU has the ability to pre-train large models.
It implements the adaptation of model training framework on GPUs configured in different types of architectures, which improves the efficiency and scalability of model training and reduces training costs.
Smart Images

Figure CN119902886A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a model training method and device, an electronic device, and a storage medium. Background Art
[0002] In recent years, large language models have set off a trend in the field of artificial intelligence, and many companies want to train and deploy their own large language models more easily, quickly, and economically. However, as the models become larger, the training cost increases. Training such large models requires expensive multi-card multi-node GPU clusters, and hardware resources are expensive. Even with a GPU cluster, the training efficiency of existing open source systems is low in machine utilization. DeepSpeed is an open source deep learning optimization library designed to improve the efficiency and scalability of large-scale model training. At present, there is an urgent need for a model training method that can use a model training framework such as DeepSpeed to adapt to its own GPU cluster to achieve large model training. Summary of the invention
[0003] The present invention provides a technical solution of a model training method and device, an electronic device and a storage medium.
[0004] According to one aspect of the present disclosure, a model training method is provided, including: determining a first model training framework, wherein the first model training framework is a model training framework that calls a first GPU for model training, the first model training framework is obtained after parameter conversion of a second model training framework, the second model training framework is a model training framework that calls a second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations; based on the first model training framework, calling the first GPU for model pre-training.
[0005] In one possible implementation, determining the first model training framework includes: performing parameter conversion on a first source code corresponding to the second model training framework to obtain a second source code corresponding to the first model training framework; calling a compiler corresponding to the first GPU to perform a code compilation operation on the second source code to obtain a target executable file corresponding to the first model training framework.
[0006] In one possible implementation, the first model training framework includes: a first type of application programming interface API, a first type of header file, and a first type of communication library adapted to a first software stack corresponding to the first GPU; the parameter conversion of the first source code corresponding to the second model training framework to obtain the second source code corresponding to the first model training framework includes: in the first source code, performing an interface conversion operation on the second type API to obtain the first type API, wherein the second type API is an API adapted to the second software stack corresponding to the second GPU; in the first source code, performing a replacement operation on the second type header file to obtain the first type header file, wherein the second type header file is a header file adapted to the second software stack; in the first source code, performing a replacement operation on the second type communication library to obtain the first type communication library, wherein the second type communication library is a communication library adapted to the second software stack.
[0007] In a possible implementation, the first model training framework includes: a first type of accelerator adapted to the first software stack; the method further includes: in the first source code, based on an accelerator base class, determining and configuring the first type of accelerator.
[0008] In a possible implementation, the method further includes: in the first source code, screening non-essential functions, and setting comment tags for the non-essential functions, wherein the non-essential functions are functions that are not related to model training, and the comment tags are used to indicate that the non-essential functions are not run.
[0009] In a possible implementation, the calling of the compiler corresponding to the first GPU, performing a code compiling operation on the second source code, and obtaining a target executable file corresponding to the first model training framework includes: in the second source code, performing a file type conversion operation on a kernel function file of a first file type, and obtaining a kernel function file of a second file type, wherein the first file type is a file type adapted to the compiler corresponding to the second GPU, and the second file type is a file type adapted to the compiler corresponding to the first GPU; calling the compiler corresponding to the first GPU, performing a code compiling operation on a third source code obtained after performing the file type conversion operation, and obtaining the target executable file.
[0010] In a possible implementation, calling a compiler corresponding to the first GPU to perform a code compiling operation on a third source code obtained after performing a file type conversion operation to obtain the target executable file includes: calling a compiler corresponding to the first GPU to perform a code compiling operation on the third source code to obtain a compilation result; and obtaining the target executable file according to the compilation result when no compilation error item exists in the compilation result.
[0011] In a possible implementation, the method further includes: when there is a compilation error item in the compilation result, adapting the code related to the compilation error item in the third source code to obtain the updated third source code; calling the compiler corresponding to the first GPU to perform a code compilation operation on the updated third source code to obtain the target executable file.
[0012] According to one aspect of the present disclosure, a model training device is provided, including: a training framework determination module, used to determine a first model training framework, wherein the first model training framework is a model training framework for calling a first GPU for model training, the first model training framework is obtained after parameter conversion of a second model training framework, the second model training framework is a model training framework for calling a second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations; a pre-training module, used to call the first GPU for model pre-training based on the first model training framework.
[0013] According to one 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 call the instructions stored in the memory to execute the above method.
[0014] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.
[0015] In the embodiment of the present disclosure, by performing parameter conversion on the second model training framework adapted to the second GPU, a first model training framework adapted to the first GPU is determined, and then based on the first model training framework, the first GPU can be called to perform model pre-training, thereby effectively enabling the first GPU to have the ability to perform large model pre-training based on the first model training framework.
[0016] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and do not limit the present disclosure. Other features and aspects of the present disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.
[0018] Figure 1 A flowchart of a model training method according to an embodiment of the present disclosure is shown.
[0019] Figure 2 A block diagram of a model training device according to an embodiment of the present disclosure is shown.
[0020] Figure 3 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0021] 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.
[0022] 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.
[0023] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.
[0024] 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 subject matter of the present disclosure.
[0025] Figure 1A flow chart of a model training method according to an embodiment of the present disclosure is shown. The method can be executed by an electronic device such as a terminal device or a server. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable instruction stored in a memory. Alternatively, the method can be executed by a server. Figure 1 As shown, the method includes:
[0026] In step S11, a first model training framework is determined, wherein the first model training framework is a model training framework that calls the first GPU for model training, the first model training framework is obtained after parameter conversion of the second model training framework, and the second model training framework is a model training framework that calls the second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations.
[0027] The model training framework in the disclosed embodiment may be a DeepSpeed framework developed based on the Pytorch framework, which can perform model pre-training of large-scale models (e.g., large language models) to improve model training efficiency and scalability. The first model training framework is a first DeepSpeed framework adapted to the first GPU, and the second model training framework is a second DeepSpeed framework adapted to the second GPU. The first GPU and the second GPU may be GPUs produced by different GPU manufacturers, that is, the first GPU and the second GPU are GPUs configured with different types of architectures.
[0028] The second model training framework can be a model training framework that has been maturely used in related technologies. On the basis of the second model training framework, in order to enable the model training framework to adapt to the new GPU: the first GPU, the first model training framework adapted to the first GPU can be quickly obtained by performing parameter conversion on the second model training framework.
[0029] The specific process of how to determine the first model training framework will be described in detail later in conjunction with possible implementation methods of the present disclosure, and will not be elaborated here.
[0030] In step S12, based on the first model training framework, the first GPU is called to perform model pre-training.
[0031] After obtaining the first model training framework adapted to the first GPU, a large-scale model can be pre-trained on the first GPU based on the first model training framework, making full use of the powerful computing power of the first GPU to improve model training efficiency and scalability.
[0032] Among them, the large-scale model targeted by model pre-training can be flexibly set according to actual conditions, for example, a large language model, and this disclosure does not make specific limitations on this.
[0033] In the embodiment of the present disclosure, by performing parameter conversion on the second model training framework adapted to the second GPU, a first model training framework adapted to the first GPU is determined, and then based on the first model training framework, the first GPU can be called to perform model pre-training, thereby enabling the first GPU to have the ability to perform large model pre-training based on the first model training framework.
[0034] In one possible implementation, determining a first model training framework includes: performing parameter conversion on a first source code corresponding to a second model training framework to obtain a second source code corresponding to the first model training framework; calling a compiler corresponding to the first GPU to perform a code compilation operation on the second source code to obtain a target executable file corresponding to the first model training framework.
[0035] Since the second model training framework is adapted to the second GPU, the working parameters of the second GPU and the first GPU may be different. Therefore, parameter conversion is performed on the first source code corresponding to the second model training framework, and the parameters adapted to the first GPU in the first source code are converted into parameters adapted to the second GPU. The second source code obtained after the conversion is the source code corresponding to the first model training framework.
[0036] In one example, the relevant parameters in the first source code can be screened and converted based on a parameter conversion tool. The specific form of the parameter conversion tool can be flexibly set based on actual conditions, and the present disclosure does not specifically limit this.
[0037] After the parameter conversion is performed at the source code level, in order to ensure that the second source code can run smoothly, the compiler corresponding to the first GPU is called to perform a code compilation operation on the second source code to obtain a target executable file corresponding to the first model training framework.
[0038] Among them, the source code is a text file written in a certain programming language, which contains the logic and instructions of the program; the executable file is a binary file compiled from the source code, which contains instructions that the computer can directly execute.
[0039] In the case where the second model training framework is the second DeepSpeed framework, the second DeepSpeed framework is developed based on the Pytorch framework, and the first software stack corresponding to the first GPU includes the torch_aaa component, which is a plug-in for the Pytorch framework, allowing the Pytorch framework to perform model training and reasoning on the first GPU, where aaa is the identifier of the first software stack. Therefore, the first software stack can be registered in the second DeepSpeed framework as a custom backend, and then the parameters of the second software stack corresponding to the second GPU in the first source code corresponding to the second DeepSpeed framework are adapted to perform parameter conversion operations to obtain parameters adapted to the first software stack, so that the call of the second DeepSpeed framework to the second software stack is converted into the call of the first DeepSpeed framework to the first software stack.
[0040] In one possible implementation, the first model training framework includes: a first type of application programming interface (API), a first type of header file, and a first type of communication library adapted to a first software stack corresponding to a first GPU; parameter conversion is performed on a first source code corresponding to a second model training framework to obtain a second source code corresponding to the first model training framework, including: in the first source code, an interface conversion operation is performed on a second type of API to obtain a first type of API, wherein the second type of API is an API adapted to a second software stack corresponding to a second GPU; in the first source code, a replacement operation is performed on a second type of header file to obtain a first type of header file, wherein the second type of header file is a header file adapted to the second software stack; in the first source code, a replacement operation is performed on a second type of communication library to obtain a first type of communication library, wherein the second type of communication library is a communication library adapted to the second software stack.
[0041] By performing parameter conversion on the second type API, the second type header file, and the second type communication library adapted to the second GPU in the first source code corresponding to the second model training framework, the second source code corresponding to the first model training framework adapted to the first GPU can be obtained after conversion.
[0042] In the second model training framework, a large number of interactions with the second GPU backend are usually involved. Therefore, in the first source code corresponding to the second model training framework, the second software stack corresponding to the second GPU is used as the default backend, that is, the second type API in the first source code is an API adapted to the second software stack. Therefore, in the first source code, an interface conversion operation is performed on the second type API to obtain a first type API adapted to the first software stack corresponding to the first GPU.
[0043] In one example, API adaptation may include setting the device, setting the synchronization interface, setting the stream, modifying the data type, determining whether the backend is available, modifying the C++ code interface, etc., and may also include other API adaptations, which are not specifically limited in this disclosure.
[0044] For example, in setting device, in the first source code, the second software stack is set as the GPU backend through the interface parameter torch.device('bbb:{}), where bbb is the identifier of the second software stack. The first source code is subjected to an interface conversion operation to obtain the second source code. In the second source code, the first software stack is set as the GPU backend through the interface parameter torch.device('aaa:{}), where aaa is the identifier of the first software stack.
[0045] For example, to set a synchronization interface, in the first source code, the synchronization interface parameter is torch.bbb.synchronize(). The first source code is converted to obtain a second source code. In the second source code, the synchronization interface parameter is: torch.aaa.synchronize().
[0046] For example, to set stream, in the first source code, the stream parameter is: stream(torch.bbb). The first source code is subjected to an interface conversion operation to obtain a second source code. In the second source code, the stream parameter is: stream(torch.aaa).
[0047] For example, modify the data type. In the first source code, the data type parameters are: HalfTensor.format, FloatTensor.format, DoubleTensor.format, BFloat16Tensor.format. When the second model training framework provides support for custom data types: privateuseone, and the first software stack also supports the reuse of this keyword, the first source code is converted to obtain the second source code. In the second source code, the data type parameters are: privateuseone.HalfTensor, privateuseone.FloatTensor, privateuseone.DoubleTensor, privateuseone.BFloat16Tensor.
[0048] For example, to determine whether the backend is available, in the first source code, the parameter for determining whether the backend is available is: torch.bbb.is_available:Cannot use fp16 without BBB. The first source code is subjected to an interface conversion operation to obtain a second source code. In the second source code, the parameter for determining whether the backend is available is: torch.aaa.is_available():Cannot use fp16 without AAA.
[0049] In one example, the first source code includes a lot of C++ codes. For the second type API adapted to the second software stack included in this part, parameter conversion also needs to be performed to obtain the first type API adapted to the first software stack.
[0050] For example, the first source code includes a C++ parameter: bbbMallocHost((void**). An interface conversion operation is performed on the first source code to obtain a second source code. The second source code includes a C++ parameter: aaaMallocHost((void**).
[0051] The first source code corresponding to the second model training framework usually includes many second-type header files (for example, some C++ header files) that are adapted to the second software stack. Therefore, in order to adapt to the first software stack, it is necessary to perform a replacement operation on the second-type header files to obtain the first-type header files that are adapted to the first software stack.
[0052] For example, the first source code includes the second type header file:<bbb_fp16.h> ,<bbb_runtime_api.h> , "bbb.h". Perform a replacement operation on the first source code to obtain a second source code. The second source code includes the first type header file:<aaa_fp16.h> ,<aaa_runtime_api.h> , "aaa.h".
[0053] In the second model training framework, a second type of communication library adapted to the second software stack is used as a distributed communication library for the second GPU backend. In order to adapt to the first software stack, it is necessary to perform a replacement operation on the second type of communication library in the second model training framework to obtain the first type of communication library, so that the first model training framework can use the first type of communication library adapted to the first software stack as a distributed communication library for the first GPU backend.
[0054] In a possible implementation, the first model training framework includes: a first type of accelerator adapted to the first software stack; the method also includes: in the first source code, based on the accelerator base class, determining and configuring the first type of accelerator.
[0055] When the model training framework is DeepSpeed, DeepSpeed defines an abstract base class: DeepSpeedAccelerator, which is the base class of the accelerator backend. The accelerator backend mainly defines the communication backend, the compilation path and configuration of the op, and the interface for isolating the frontend and backend.
[0056] First, create an accelerator class adapted to the first GPU: aaa_Accelerator, then inherit the DeepSpeedAccelerator class and implement interfaces such as __init__, set_device, and synchronize. Then, register the accelerator class aaa_Accelerator in the get_accelerator function in the real_accelerator.py file. When the first GPU is used as an accelerator, initialize the accelerator class aaa_Accelerator as an accelerator instance of the target platform.
[0057] In a possible implementation, the method further includes: in the first source code, screening non-essential functions, and setting comment tags for the non-essential functions, wherein the non-essential functions are functions that are not related to model training, and the comment tags are used to indicate that the non-essential functions are not run.
[0058] For non-essential functions in the second model training framework that are not related to model training and are not compatible with the first software stack, comment tags can be set to indicate that non-essential functions will not be run in the first model training framework, and this will not affect the function of model training based on the first model training framework.
[0059] For example, determine that the see_memory_usage function in the first source code is a non-essential function. The see_memory_usage function is mainly used to view the usage of video memory during training and can be used as a debugging tool. It has no effect on the functionality of the model training framework. Moreover, the see_memory_usage function is implemented by calling the underlying interface of the second software stack. The first software stack does not support the corresponding function. Therefore, in the first source code, a comment tag is set for the see_memory_usage function so that the see_memory_usage function is not executed during the model training process based on the first model training framework.
[0060] For example, it is determined that the gemm_test function in the first source code is a non-essential function. There are multiple gemm_test functions in the second model training framework, which are mainly used to test the functions and performance of the framework and have no effect on the functionality of the framework. Moreover, the implementation of the gemm_test function requires calling the interface of the second software stack: aaa_gemm_ex, which has not been implemented in the first software stack. Therefore, in the first source code, a comment label is set for the gemm_test function so that the gemm_test function is not executed during the model training process based on the first model training framework.
[0061] In addition to the above examples, non-essential functions may also include other functions according to actual conditions, and the present disclosure does not make specific limitations on this.
[0062] For other interfaces in the first source code that are not compatible with the first software stack, adaptability conversion is also required.
[0063] For example, two preset values are directly initialized in the first source code, and then the __half2 data type is returned to implement the second model training framework to support the half2_raw data type. However, this code writing method is only adapted to the second software stack and cannot be adapted to the first software stack. At this time, the relevant code segments in the first source code need to be converted. Since the first software stack supports the initialization of the half_raw data type, for the relevant code segments in the first source code, a half_raw type of data is initialized, and then the return type of half2 is created through the half2 interface.
[0064] In one possible implementation, a compiler corresponding to the first GPU is called to perform a code compilation operation on the second source code to obtain a target executable file corresponding to the first model training framework, including: in the second source code, a file type conversion operation is performed on a kernel function file of a first file type to obtain a kernel function file of a second file type, wherein the first file type is a file type adapted to the compiler corresponding to the second GPU, and the second file type is a file type adapted to the compiler corresponding to the first GPU; and the compiler corresponding to the first GPU is called to perform a code compilation operation on the third source code obtained after performing the file type conversion operation to obtain the target executable file.
[0065] The second model training framework includes some custom kernel functions for computational acceleration. In order to adapt to the compiler corresponding to the second GPU, the file type of these custom kernel function files is the first file type. Since the compiler corresponding to the first GPU cannot recognize the first file type, in the second source code obtained after the parameter conversion is performed, the file type conversion operation is performed on the kernel function file of the first file type to obtain the third source code including the kernel function file of the second file type after the file type conversion operation is performed.
[0066] The compiler corresponding to the first GPU can recognize the second file type. Therefore, the compiler corresponding to the first GPU is called to perform code compilation operations on the third source code to obtain the target executable file of the first model training framework, thereby effectively realizing the smooth operation of the first model training framework.
[0067] In a possible implementation, calling a compiler corresponding to the first GPU, performing a code compiling operation on a third source code obtained after performing a file type conversion operation, and obtaining a target executable file includes: calling a compiler corresponding to the first GPU, performing a code compiling operation on the third source code, and obtaining a compilation result; and obtaining the target executable file according to the compilation result when no compilation error item exists in the compilation result.
[0068] The compiler corresponding to the first GPU is called to perform a code compiling operation on the third source code to obtain a compilation result. Only when there is no erroneous compilation item in the compilation result, it indicates that the third source code is compiled successfully and the corresponding target executable file can be obtained.
[0069] In a possible implementation, the method further includes: when there is a compilation error item in the compilation result, adapting the code related to the compilation error item in the third source code to obtain an updated third source code; calling the compiler corresponding to the first GPU to perform a code compilation operation on the updated third source code to obtain a target executable file.
[0070] A compiler corresponding to the first GPU is called to perform a code compiling operation on the third source code. When there are erroneous compilation items in the compilation result, it indicates that the compilation of the third source code fails and the erroneous compilation items need to be corrected.
[0071] For the compilation error items in the compilation result, the relevant codes of the compilation error items in the third source code are adapted to obtain the updated third source code. The adaptation operation can be a preset adaptation strategy based on the error category, which can be flexibly set according to the actual situation, and the present disclosure does not make specific restrictions on this.
[0072] For example, the erroneous compilation item is the quantize function, and the error category corresponding to the erroneous compilation item is the modulo (abs) function that does not support the FP16 data type in the compiler corresponding to the first GPU. Therefore, adaptation is performed based on the preset adaptation strategy: bbb_fabsf16 in the third source code is converted to aaa_fabs_h that is adapted to the first software stack, and a code compilation operation is performed on the updated third source code to achieve successful compilation of the erroneous compilation item and obtain the target executable file.
[0073] For example, the erroneous compilation item is the dequantize function, and the error category corresponding to the erroneous compilation item is that the bbb_int2float_rn function is called when the dequantize function is executed by the first model training framework, but the compiler corresponding to the first GPU cannot implement the corresponding function. Therefore, adaptation is performed based on the preset strategy: first, the aaa_int2float_rn function is implemented in the compiler corresponding to the first GPU, and then the code calling bbb_int2float_rn in the third source code is converted to aaa_int2float_rn, and the code compilation operation is performed on the updated third source code to achieve successful compilation of the erroneous compilation item and obtain the target executable file.
[0074] For example, the error compilation item is rand type not found, and the error category corresponding to the error compilation item is that the rand library call interface cannot be adapted. Therefore, adaptation is performed based on the preset strategy: the bbb_rand interface that calls the bbb_rand library in the third source code is converted to aaa_rand, and the code compilation operation is performed on the updated third source code to achieve successful compilation of the error compilation item and obtain the target executable file.
[0075] For example, the error compilation item is half type not found, and the error category corresponding to the error compilation item is compiler incompatibility. Since the relevant source file in the third source code is the pt_binding.cpp file, the compiler used by the first model training framework for the .cpp file does not support the half type of the first GPU. Therefore, adaptation is performed based on the preset strategy: the relevant code in the third source code is adapted to compile the .cpp file based on the compiler corresponding to the first GPU, and the code compilation operation is performed on the updated third source code to achieve successful compilation of the error compilation item and obtain the target executable file.
[0076] In addition to the above examples, the error compilation items may also include other specific error compilation items according to the actual compilation situation, and the present disclosure does not make specific limitations on this.
[0077] After successfully compiling to obtain the target executable file of the first model training framework, the first model training framework can be successfully run based on the target executable file.
[0078] The first model training framework includes a series of unit tests for comprehensively testing the functions and performance of the first model training framework. If all the unit tests are passed, it can be effectively verified that the first model training framework has been successfully adapted to the first GPU.
[0079] In addition, in order to make the first model training framework run more stably on the first GPU based on the first software stack, distributed communication unit tests, end-to-end tests, etc. can be added after all existing unit tests of the first model training framework itself have passed.
[0080] Since the first type of communication library adapted to the first software stack in the first model training framework is obtained by converting the second type of communication library adapted to the second software stack in the second model training framework, a distributed communication unit test is added to the first model training framework to verify whether the communication function and performance meet expectations. For example, the commonly used allreduce collection communication operator can be used for distributed communication units.
[0081] Since the purpose of adapting the first model training framework on the first software stack is to pre-train the large model on the first GPU, an end-to-end model training unit test is added to the first model training framework to verify whether the distributed training function and performance meet expectations. For example, a simple multi-layer perceptron is defined as a test model, and then the first model training framework is used to start cross-node training to complete the end-to-end model training unit test.
[0082] In the embodiment of the present disclosure, by performing parameter conversion on the second model training framework adapted to the second GPU, a first model training framework adapted to the first GPU is determined, and then based on the first model training framework, the first GPU can be called to perform model pre-training, thereby effectively enabling the first GPU to have the ability to perform large model pre-training based on the first model training framework.
[0083] When the first GPU is called based on the first model training framework to perform large model pre-training, there may be a relatively large performance loss. End-to-end pre-training requires a lot of resources and is very time-consuming, resulting in very high pre-training costs. Therefore, the disclosed embodiment further analyzes the performance issues of the first software stack in the process of calling the first GPU for large model pre-training based on the first model training framework, so as to reduce the resources required for large model pre-training and reduce time consumption.
[0084] In one example, performance analysis is performed at the component level (torch) of the model training framework.
[0085] First, based on the first model training framework, the first GPU is called to perform large model training, and first performance data is captured during the large model training process;
[0086] Then, based on the second model training framework, the second GPU is called to perform large model training, and the second performance data is captured during the large model training process;
[0087] Finally, by analyzing the first performance data and the second performance data, the first model training framework and the first software stack are improved.
[0088] In one example, by analyzing the first performance data, the first time consumption of multiple target operators in the process of the first model training framework calling the first GPU to perform large model training is determined; by analyzing the second performance data, the second time consumption of multiple target operators in the process of the second model training framework calling the second GPU to perform large model training is determined; by comparing the first time consumption and the second time consumption, the first software stack is improved.
[0089] In one example, by comparing the first time consumption and the second time consumption, it can be determined that the problem that the second time consumption is higher than the first time consumption is caused by the incompatibility of the first software stack operator.
[0090] By comparing the first time consumption and the second time consumption, it is determined that operators such as masked_fill, index_put, and layer_norm are not adapted in the first software stack, resulting in unreasonable data copies of these operators on the first GPU, causing the first time consumption of these operators to be higher than the second time consumption.
[0091] The following uses the index_put operator as an example to analyze how to improve the first software. Other operators are similar.
[0092] In the second GPU, the index_put operator is called when the index is assigned.
[0093] However, in the first GPU, since the first software stack is not adapted to the index_put operator, the index_put operator will copy the data to the CPU, and then call the pytorch implementation on the CPU, and copy it to the first GPU after the operation is completed. This will result in two data copies, resulting in a high time consumption.
[0094] Therefore, the index_put operator is adapted in the first software stack to achieve that in the first GPU, the index_put operator is called when the index is assigned, and only one data copy takes time.
[0095] In one example, by comparing the first time consumption with the second time consumption, it can be determined that there are multiple consecutive data copies in the forward process, resulting in the second time consumption being longer than the first time consumption.
[0096] The first data copy is not far from the lt operator on the left. The corresponding code is determined to be the index assignment part in the build_mask_matrix function. There are multiple clone copies later. The last clone has several operators such as ge, is_nonzero, lt, and sub. It is determined that these operators have entered Vocab Parallel Embedding, so this part should be to convert the model input from float32 to float16. The corresponding code location is: GPT Model Pipe. This part will bring a large number of small operator data copies, and the calculation density and memory access utilization are relatively low, resulting in multiple consecutive data copies in the forward process, which is time-consuming.
[0097] Therefore, the first software stack is optimized to fuse this part of the code into a larger fusion operator, thereby improving memory access efficiency and overall performance, thereby effectively reducing time consumption.
[0098] In one example, by comparing the first time consumption and the second time consumption, it can be determined that there are many small operators in the forward process, which causes the second time consumption to be higher than the first time consumption.
[0099] Analysis found that there are a large number of small operators with short functions in the forward process of the second software stack. Since these small operators are in front of the build_single_mask position, they are mainly in the data preprocessing part. Then these operators are called in a loop in the select-gt-select-is_nonzero-mul mode. The judgment position is: _build_key_size_numel_dictionaries. By analyzing the code, it is found that this continuous operation is run on the CPU, and the total time is about 1ms.
[0100] Therefore, the first software stack is optimized to put these small operator operations on the first GPU, reducing the time consumption from 1 ms to 0.17 ms, which is effectively lower.
[0101] In one example, performance analysis is performed at the kernel function level of the model training framework.
[0102] First, based on the first model training framework, the first GPU is called to perform large model training, and during the large model training process, a roofline curve is determined. The roofline curve is used to evaluate the relationship between computing performance and hardware resource utilization;
[0103] Then, according to the roofline curve, the throughput is calculated to optimize the computation-intensive kernel function, and the memory access efficiency is calculated to optimize the memory access-intensive kernel function.
[0104] In one example, it is determined based on the throughput calculated by the roofline curve that the computational efficiency of a certain computationally intensive kernel function at certain sizes is lower than expected. In this case, the performance of the computationally intensive kernel function at these sizes may be optimized.
[0105] In one example, according to the memory access efficiency calculated by the roofline curve, it is determined that the memory access efficiency of a certain memory-intensive kernel function (for example, unary kernel function, gelu, etc.) is lower than expected. The reason is that the input data of these kernel functions has a transposition operation, which makes the non-continuous torch call the Contiguous function to make the input data continuous before calling the DNN operator for calculation, while the unary kernel function calculation is performed element by element, and there is no need to make the input data continuous.
[0106] Therefore, the Contiguous function can be removed, and CreateMUTensor that supports stride transfer can be used when creating a Tensor. The stride attribute of the input data can be passed in together, and then the unary kernel function of the DNN operator can be directly called for calculation, so that the memory access efficiency meets expectations.
[0107] In the process of calling the first GPU to perform large model pre-training based on the first model training framework, the performance issues of the first software stack can also be analyzed from other aspects according to actual needs, and the present disclosure does not make specific limitations on this.
[0108] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.
[0109] In addition, the present disclosure also provides a model training device, an electronic device, a computer-readable storage medium, and a program, all of which can be used to implement any model training method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method part and will not be repeated here.
[0110] Figure 2 A block diagram of a model training device according to an embodiment of the present disclosure is shown. Figure 2 As shown, the device 20 includes:
[0111] The training framework determination module 21 is used to determine a first model training framework, wherein the first model training framework is a model training framework that calls the first GPU for model training, the first model training framework is obtained after parameter conversion of the second model training framework, and the second model training framework is a model training framework that calls the second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations;
[0112] The pre-training module 22 is used to call the first GPU to perform model pre-training based on the first model training framework.
[0113] In a possible implementation, the training framework determination module 21 is specifically configured to:
[0114] Performing parameter conversion on the first source code corresponding to the second model training framework to obtain the second source code corresponding to the first model training framework;
[0115] Call the compiler corresponding to the first GPU, perform a code compilation operation on the second source code, and obtain a target executable file corresponding to the first model training framework.
[0116] In a possible implementation, the first model training framework includes: a first type API, a first type header file, and a first type communication library adapted to a first software stack corresponding to the first GPU;
[0117] The training framework determination module 21 is specifically used for:
[0118] In the first source code, an interface conversion operation is performed on the second type API to obtain the first type API, wherein the second type API is an API adapted to a second software stack corresponding to the second GPU;
[0119] In the first source code, a replacement operation is performed on the second type header file to obtain the first type header file, wherein the second type header file is a header file adapted to the second software stack;
[0120] In the first source code, a replacement operation is performed on the second type communication library to obtain the first type communication library, wherein the second type communication library is a communication library adapted to the second software stack.
[0121] In a possible implementation, the first model training framework includes: a first type of accelerator adapted to a first software stack;
[0122] The training framework determination module 21 is specifically used for:
[0123] In the first source code, based on the accelerator base class, a first type accelerator is determined and configured.
[0124] In a possible implementation, the training framework determination module 21 is specifically configured to:
[0125] In the first source code, non-essential functions are screened, and comment labels are set for the non-essential functions, wherein the non-essential functions are functions irrelevant to model training, and the comment labels are used to indicate that the non-essential functions are not run.
[0126] In a possible implementation, the training framework determination module 21 is specifically configured to:
[0127] In the second source code, a file type conversion operation is performed on a kernel function file of the first file type to obtain a kernel function file of the second file type, wherein the first file type is a file type adapted to a compiler corresponding to the second GPU, and the second file type is a file type adapted to a compiler corresponding to the first GPU;
[0128] A compiler corresponding to the first GPU is called to perform a code compiling operation on the third source code obtained after the file type conversion operation is performed, so as to obtain a target executable file.
[0129] In a possible implementation, the training framework determination module 21 is specifically configured to:
[0130] Calling a compiler corresponding to the first GPU to perform a code compiling operation on the third source code to obtain a compilation result;
[0131] When there is no compilation error in the compilation result, a target executable file is obtained according to the compilation result.
[0132] In a possible implementation, the training framework determination module 21 is specifically configured to:
[0133] When there is a compilation error item in the compilation result, adapt the code related to the compilation error item in the third source code to obtain an updated third source code;
[0134] A compiler corresponding to the first GPU is called to perform a code compiling operation on the updated third source code to obtain a target executable file.
[0135] This method has a specific technical connection with the internal structure of the computer system, and can solve the technical problem of how to improve the hardware computing efficiency or execution effect (including reducing the amount of data storage, reducing the amount of data transmission, increasing the hardware processing speed, etc.), thereby obtaining the technical effect of improving the internal performance of the computer system in accordance with the laws of nature.
[0136] 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.
[0137] 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.
[0138] 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 call the instructions stored in the memory to execute the above method.
[0139] 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.
[0140] The electronic device may be provided as a terminal, a server, or a device in other forms.
[0141] Figure 3 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. Figure 3 , the electronic device 1900 can be provided as a server or a terminal device. Figure 3 , 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.
[0142] 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. The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as a Microsoft Server operating system (Windows Server 2003). TM ), a graphical user interface operating system launched by Apple (Mac OS X TM ), a multi-user, multi-process computer operating system (Unix TM), a free and open source Unix-like operating system (Linux TM ), an open source Unix-like operating system (FreeBSD TM ) or similar.
[0143] 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.
[0144] 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.
[0145] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can 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 thereof. More specific examples (non-exhaustive list) of computer readable storage medium 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, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.
[0146] 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.
[0147] 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.
[0148] 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.
[0149] 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.
[0150] 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.
[0151] 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.
[0152] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.
[0153] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0154] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0155] If the technical solution of this application involves personal information, the product using the technical solution of this application has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using the technical solution of this application has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, the personal information processing rules are notified by obvious signs / information, and the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
[0156] 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 improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A model training method, characterized in that: include: Determine a first model training framework, wherein the first model training framework is a model training framework that calls a first GPU for model training, the first model training framework is obtained after parameter conversion of a second model training framework, the second model training framework is a model training framework that calls a second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations; Based on the first model training framework, call the first GPU to perform model pre-training.
2. The method according to claim 1, characterized in that The determining of the first model training framework includes: Performing parameter conversion on the first source code corresponding to the second model training framework to obtain the second source code corresponding to the first model training framework; Call the compiler corresponding to the first GPU, perform a code compilation operation on the second source code, and obtain a target executable file corresponding to the first model training framework.
3. The method according to claim 2, characterized in that The first model training framework includes: a first type of application programming interface API, a first type of header file, and a first type of communication library adapted to a first software stack corresponding to the first GPU; The performing parameter conversion on the first source code corresponding to the second model training framework to obtain the second source code corresponding to the first model training framework includes: In the first source code, performing an interface conversion operation on a second type API to obtain the first type API, wherein the second type API is an API adapted to a second software stack corresponding to the second GPU; In the first source code, a replacement operation is performed on a second type header file to obtain the first type header file, wherein the second type header file is a header file adapted to the second software stack; In the first source code, a replacement operation is performed on a second type of communication library to obtain the first type of communication library, wherein the second type of communication library is a communication library adapted to the second software stack.
4. The method according to claim 3, characterized in that The first model training framework includes: a first type of accelerator adapted to the first software stack; The method further comprises: In the first source code, the first type of accelerator is determined and configured based on the accelerator base class.
5. The method according to claim 3, characterized in that: The method further comprises: In the first source code, non-essential functions are screened, and comment tags are set for the non-essential functions, wherein the non-essential functions are functions irrelevant to model training, and the comment tags are used to indicate that the non-essential functions are not run.
6. The method according to claim 2, characterized in that The calling of the compiler corresponding to the first GPU to perform a code compiling operation on the second source code to obtain a target executable file corresponding to the first model training framework includes: In the second source code, a file type conversion operation is performed on a kernel function file of a first file type to obtain a kernel function file of a second file type, wherein the first file type is a file type adapted to a compiler corresponding to the second GPU, and the second file type is a file type adapted to a compiler corresponding to the first GPU; A compiler corresponding to the first GPU is called to perform a code compiling operation on the third source code obtained after the file type conversion operation is performed, so as to obtain the target executable file.
7. The method according to claim 6, characterized in that The calling of the compiler corresponding to the first GPU to perform a code compiling operation on the third source code obtained after performing the file type conversion operation to obtain the target executable file includes: Calling a compiler corresponding to the first GPU to perform a code compiling operation on the third source code to obtain a compilation result; When there is no compilation error item in the compilation result, the target executable file is obtained according to the compilation result.
8. The method according to claim 7, characterized in that The method further comprises: In the case where there is a compilation error item in the compilation result, adapting the code related to the compilation error item in the third source code to obtain an updated third source code; A compiler corresponding to the first GPU is called to perform a code compiling operation on the updated third source code to obtain the target executable file.
9. A model training device, characterized in that: include: a training framework determination module, used to determine a first model training framework, wherein the first model training framework is a model training framework for calling a first GPU for model training, the first model training framework is obtained after parameter conversion of a second model training framework, the second model training framework is a model training framework for calling a second GPU for model training, wherein the first GPU and the second GPU are GPUs with different types of architecture configurations; A pre-training module is used to call the first GPU to perform model pre-training based on the first model training framework.
10. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 8.
11. A 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 8 is implemented.
Citation Information
Cited By
Programming framework adaptation method, device, storage medium and program product
CN122527017A