Model training method and apparatus, and related device
By dividing the AI model into modules during training and updating some parameters in the forward computation stage, combined with dynamic adjustment of batch size and allocation strategy, the problem of high memory consumption in AI model training is solved, achieving efficient memory resource utilization and maintenance of training accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2025-02-06
- Publication Date
- 2026-06-23
AI Technical Summary
AI model training consumes a lot of memory resources, making it difficult to meet performance requirements.
By updating the parameters of the first part of the AI model during the forward computation phase and the parameters of the second part of the model during the backpropagation phase, combined with dynamic adjustment of batch size and allocation strategy, memory usage is optimized.
It effectively reduces the consumption of memory resources during AI model training, while maintaining or improving training accuracy and enhancing training performance.
Smart Images

Figure CN122264012A_ABST
Abstract
Description
[0001] This application claims priority to Russian patent application filed on December 23, 2024, with application number RU2024138916 and entitled “A User-Definable Progressive Replacement Backpropagation Acceleration Scheme for Large Model Training”, the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of artificial intelligence technology, and in particular to a model training method, apparatus and related equipment. Background Technology
[0003] With the development of artificial intelligence (AI) technology, the parameter scale of AI models is gradually increasing, and correspondingly, the training cost of AI models is also constantly rising. In practical applications, AI models can be pre-trained based on general datasets. However, the performance (such as inference accuracy) of the pre-trained AI model may often be insufficient to meet the inference requirements of a specific domain. Therefore, the AI model can be further trained based on training samples from that domain; this is called fine-tuning. For example, low-rank adaptation (LoRA) or other algorithms can be used to fine-tune the AI model. In this way, the fine-tuned AI model can learn domain-specific features, thereby improving its inference performance in that domain.
[0004] However, whether retraining or fine-tuning an AI model, the large number of parameters in an AI model usually means that training it requires significant memory resources. Summary of the Invention
[0005] This application provides a model training method aimed at reducing the memory resources consumed by AI models during training. Furthermore, this application also provides a model training apparatus, a computing device, a computer-readable storage medium, and a computer program product.
[0006] Firstly, this application provides a model training method, which can be executed by a corresponding model training device. Specifically, the model training device acquires memory data and performance data, wherein the memory data indicates the memory usage of the AI model during M rounds of training (e.g., the memory usage in one round of training or the average memory usage over multiple rounds), and the performance data indicates the performance of the AI model during M rounds of training (e.g., the loss value in one round of training or the average loss value over multiple rounds), where M is a positive integer. Then, the model training device determines a first set and a second set based on the memory data and performance data, wherein the first set includes a first part of the modules in the AI model, and the second set includes a second part of the modules in the AI model. Furthermore, during the Nth round of training of the AI model, the first part of the modules in the first set undergoes parameter updates during the forward computation phase, and the second part of the modules in the second set undergoes parameter updates during the backpropagation phase, where N is a positive integer greater than M.
[0007] Because the parameters of the first part of the AI model are updated during the forward computation phase of the Nth training round (e.g., fine-tuning the AI model), there is no need to consume memory resources to save the gradient data of the parameters in that first part of the module. Furthermore, it is also unnecessary to save the activation values generated by the parameters in that first part of the module during the forward computation phase. This effectively reduces the memory resources consumed by the AI model during the Nth training round. Simultaneously, based on the memory usage and performance of the AI model in at least one training round, the modules whose parameters are updated during the forward computation phase are determined, while the second part of the module is retained for parameter updates via backpropagation. This reduces the memory resources required for model training while ensuring that the training accuracy of the AI model still reaches a high level.
[0008] In one possible implementation, the model training device can also determine the batch size based on memory data and performance data, and the AI model performs the Nth round of training based on the batch size. Thus, by dynamically adjusting the batch size value, the training of the AI model can be accelerated by increasing the batch size value when the AI model is approaching convergence, and the convergence can be promoted by decreasing the batch size value when the AI model is in an oscillating state, thereby improving the training performance of the AI model.
[0009] In one possible implementation, when the model training device determines the first set and the second set based on memory data and performance data, it can specifically predict the performance of the AI model trained using each of a variety of allocation strategies, where the allocation strategy indicates the first part of the AI model that updates parameters during the forward computation phase and the second part that updates parameters during the backpropagation phase. Then, the model training device selects a target allocation strategy from the multiple allocation strategies and determines the first set and the second set based on the target allocation strategy, where the AI model trained using the target allocation strategy exhibits the highest performance. Thus, by selecting a target allocation strategy through performance prediction to determine the first set of parameters updated during the forward computation phase and the second set of parameters updated during the backpropagation phase, the model training device can achieve a high level of training performance for the AI model. For example, the performance of the AI model can be represented by precision or loss values.
[0010] In one possible implementation, when the model training device predicts the performance of the AI model trained using each of a variety of allocation strategies based on memory data and performance data, it may specifically determine the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase. Based on this ratio, it generates multiple allocation strategies. Thus, the model training device can predict the performance of the AI model trained using each of these allocation strategies based on both memory and performance data. In this way, the model training device can generate multiple selectable allocation strategies based on the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase, so that the allocation strategy that maximizes the performance of the AI model training can be subsequently determined from among these multiple allocation strategies.
[0011] In one possible implementation, when the model training device generates multiple allocation strategies based on a ratio, it can specifically generate multiple allocation strategies based on the ratio and expert rules. The expert rules are used to indicate the conditions that the first part of the AI model, which updates parameters during the forward computation phase, and the second part, which updates parameters during the backpropagation phase, must satisfy. In this way, the model training device generates multiple allocation strategies based on expert rules, which can introduce optimization-based protection boundaries based on expert experience, thereby helping to improve the training accuracy and reliability of the AI model.
[0012] For example, expert rules could be rules indicating which modules in an AI model must have their parameters updated during the forward computation phase and which modules must have their parameters updated during the backward computation phase. Alternatively, expert rules could be rules indicating the maximum ratio between the number of first-part modules whose parameters are updated during the forward computation phase and the number of second-part modules whose parameters are updated during the backward propagation phase (thus avoiding an excessively large proportion of first-part modules whose parameters are updated during the forward computation phase, which could negatively impact the training accuracy of the AI model).
[0013] In one possible implementation, the first set includes target modules, and the AI model includes frozen parameters corresponding to the target modules. These frozen parameters are not updated during the training of the AI model. The model training device can also acquire the output results obtained from the forward computation phase based on the frozen parameters and the input data. The target modules share input data with the frozen parameters, and the parameters in the target modules are updated according to the input data and the output results. In this way, the model training device can generalize the local learning rules for the target modules to a coarser-grained mode, thereby improving the accuracy of updating the parameters in the target modules, and thus improving the training accuracy of the AI model.
[0014] In one possible implementation, the model training device can also output an interactive interface and, in response to user configuration operations, obtain either a memory resource limit or expert rules. The memory resource limit restricts the maximum memory space that the AI model can use during training, while the expert rules indicate the conditions that the first part of the AI model, which updates parameters during the forward computation phase, and the second part, which updates parameters during the backpropagation phase, must satisfy. In this way, the model training device can support user-defined configuration of the memory resource limit or expert rules through the interactive interface, thereby improving the convenience of user control over AI model training.
[0015] In one possible implementation, during the forward computation phase, the execution order of the first part of the modules in the first set precedes the execution order of the second part of the modules in the second set; or, during the forward computation phase, the first part of the modules in the first set and the second part of the modules in the second set are executed alternately.
[0016] Secondly, this application provides a model training apparatus, comprising: an acquisition module for acquiring memory data and performance data, wherein the memory data indicates the memory usage of an artificial intelligence (AI) model during M rounds of training, and the performance data indicates the performance of the AI model during M rounds of training, where M is a positive integer; and a determination module for determining a first set and a second set based on the memory data and performance data, wherein the first set includes a first part of modules in the AI model, and the second set includes a second part of modules in the AI model; wherein, during the Nth round of training of the AI model, the first part of modules in the first set undergoes parameter updates during the forward computation phase, and the second part of modules in the second set undergoes parameter updates during the backpropagation phase, where N is a positive integer greater than M.
[0017] In one possible implementation, the determining module is further configured to determine the batch size based on memory data and performance data, and the AI model performs the Nth round of training based on the batch size.
[0018] In one possible implementation, a determining module is configured to: predict the performance of an AI model trained based on each of a plurality of allocation strategies, based on memory data and performance data, wherein the allocation strategies are used to indicate a first part of the AI model that updates parameters during the forward computation phase and a second part of the AI model that updates parameters during the backpropagation phase; select a target allocation strategy from the plurality of allocation strategies, wherein the AI model trained based on the target allocation strategy has the highest performance; and determine a first set and a second set based on the target allocation strategy.
[0019] In one possible implementation, a determining module is configured to: determine the ratio between the number of first-part modules that perform parameter updates during the forward computation phase and the number of second-part modules that perform parameter updates during the backpropagation phase in the AI model; generate multiple allocation strategies based on the ratio; and predict the performance of the AI model trained based on each of the multiple allocation strategies based on memory data and performance data.
[0020] In one possible implementation, a determining module is configured to: generate multiple allocation strategies based on proportions and expert rules, wherein the expert rules are used to indicate the conditions that the first part of the AI model, which performs parameter updates during the forward computation phase, and the second part of the AI model, which performs parameter updates during the backpropagation phase, must satisfy.
[0021] In one possible implementation, the first set includes a target module, and the AI model includes frozen parameters corresponding to the target module. The frozen parameters are not updated during the training process of the AI model. The acquisition module is also used to acquire the output results obtained by calculating the input data based on the frozen parameters during the forward computation phase. The target module and the frozen parameters share the input data. The model training device may also include a parameter update module, which is used to update the parameters in the target module according to the input data and the output results.
[0022] In one possible implementation, the model training apparatus further includes: an output module for outputting an interactive interface; and an acquisition module for acquiring a memory resource limit or expert rules in response to a user's configuration operation. The memory resource limit is used to restrict the maximum memory space that the AI model can use during training, and the expert rules are used to indicate the conditions that the first part of the AI model that updates parameters during the forward computation phase and the second part of the AI model that updates parameters during the backpropagation phase must meet.
[0023] In one possible implementation, during the forward computation phase, the execution order of the first part of the modules in the first set precedes the execution order of the second part of the modules in the second set; or, during the forward computation phase, the first part of the modules in the first set and the second part of the modules in the second set are executed alternately.
[0024] The model training device provided in the second aspect corresponds to the model training method provided in the first aspect. Therefore, the technical effects of the second aspect and any implementation thereof can be found in the relevant descriptions of the technical effects of the first aspect and the corresponding implementation thereof, and will not be repeated here.
[0025] Thirdly, this application provides a computing device including a processor and a memory; wherein the memory is used to store instructions, and the processor executes the instructions stored in the memory to perform the operational steps of the model training method described in the first aspect and any implementation thereof.
[0026] Fourthly, this application provides a computer-readable storage medium storing instructions that, when executed on a computing device, cause the computing device to perform the operational steps of the model training method described in the first aspect or any implementation thereof.
[0027] Fifthly, this application provides a computer program product containing instructions that, when run on a computing device, causes the computing device to perform the operational steps of the model training method described in the first aspect or any implementation thereof.
[0028] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0029] Figure 1 A schematic diagram of an exemplary computing cluster provided in this application;
[0030] Figure 2 A flowchart illustrating a model training method provided in this application;
[0031] Figure 3 A schematic diagram illustrating the configuration of low-rank matrices for network layers in an AI model, as provided in this application;
[0032] Figure 4 A schematic diagram illustrating the process of the training scheduler 200 provided in this application determining set 1 and set 2;
[0033] Figure 5 A schematic diagram of an exemplary interactive interface provided for this application;
[0034] Figure 6 A flowchart illustrating another model training method provided in this application;
[0035] Figure 7 A schematic diagram illustrating the results of testing various AI models for this application;
[0036] Figure 8 A schematic diagram of the structure of a model training device provided in this application;
[0037] Figure 9 This is a schematic diagram of the hardware structure of a computing device provided in this application. Detailed Implementation
[0038] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, various non-limiting embodiments of the present application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained based on the embodiments in this application and based on the above content are within the scope of protection of this application.
[0039] See Figure 1 The diagram illustrates the structure of a computing cluster. Figure 1 As shown, the computing cluster 10 may include multiple computing nodes and a training scheduler 200. Figure 1 The following example illustrates the use of computing cluster 10, which includes two computing nodes (compute node 101 and compute node 102).
[0040] In computing cluster 10, a computing node refers to a node with data computing capabilities, such as a server or other computing device. Each computing node may include one or more computing units. Figure 1 This example uses a single computing node comprising four computing units, such as computing node 1 including computing units 1 through 4. In practical applications, different computing units deployed within the same computing node can communicate via a bus, such as a compute express link (CXL) bus. Different computing nodes can also communicate via switches, such as electrical switches and optical switches.
[0041] The computing units in computing node 101 (and computing node 102) can be implemented using processors. Exemplarily, a processor can be any type of processor or any combination thereof, such as a central processing unit (CPU), an accelerator, an application-specific integrated circuit (ASIC), a programmable logic device (PLD), a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), a system-on-chip (SoC), a software-defined infrastructure (SDI) chip, an artificial intelligence (AI) chip, or a data processing unit (DPU). An accelerator can be, for example, a graphics processing unit (GPU), a neural network processing unit (NPU), or a tensor processing unit (TPU).
[0042] The computing cluster 10 can deploy AI models, such as different network layers of the AI model being deployed to different computing nodes. Furthermore, the computing cluster 10 can train the AI model, including fine-tuning or retraining it. For example, the AI model can be a large language model (LLM), a large language model meta AI (LLaMA), a bidirectional encoder representations from transformers (BERT), or a generative pre-trained transformer 3 (GPT-3) model, or other types of models such as GPT-4; there is no limitation on the specific type.
[0043] The training scheduler 200 can be used to execute corresponding scheduling processes during AI model training, such as specifying the update method of parameters in the AI model and adjusting the batch size used by the AI model in different rounds of training. Exemplarily, the training scheduler 200 can be implemented in software or hardware. When implemented in software, the training scheduler 200 can be program code running in a computing instance, such as a process or application. When implemented in hardware, the training scheduler 200 can be a processor or a computing device including a processor. This application does not limit the specific implementation of the training scheduler 200.
[0044] Furthermore, the computing cluster 10 can also provide a client 103, which can be program code deployed on a user-side terminal device, or a web browser, etc., without limitation. Users can also configure the client, such as configuring the maximum memory that can be used during model training, so that the computing cluster 10 can train the AI model based on this configuration.
[0045] Typically, each training round can include a forward computation phase and a backpropagation phase. In the forward computation phase, the AI model performs calculations based on the input data to obtain the calculation result (i.e., the inference result obtained during the current training round). In the backpropagation phase, computation nodes 101 and 102 calculate the loss value based on the difference between the calculated result and the actual result, and then calculate the gradient data for the parameter to be updated in the AI model based on the loss value, and update the parameter based on the calculated gradient data. It should be noted that the "updated parameter" mentioned in this application specifically refers to updating the value of the parameter.
[0046] In real-world applications, AI models often have a large parameter size, which means that training such a model using gradient data to update parameters requires significant memory consumption. Typically, during each training iteration, the following data needs to be stored in memory for each parameter to be updated: the parameter value to be updated, the activation value generated based on that parameter during the forward propagation phase (used to calculate gradient data during the backpropagation phase), the gradient data calculated for that parameter during the backpropagation phase, and the updated parameter value.
[0047] Based on this, in the computing cluster 10 provided in this application, the training scheduler 200 can update some parameters in the AI model during the forward computation stage, thereby ensuring that the training accuracy of the AI model reaches a high level while reducing the memory resources consumed by the AI model training.
[0048] In its implementation, the training scheduler 200 can acquire memory data and performance data. The acquired memory data indicates the memory usage of the AI model during M (M is a positive integer) training rounds, such as the amount of memory used (or the average memory usage). The acquired performance data indicates the performance of the AI model during these M training rounds, such as the loss value (or the average loss value). Then, based on this memory and performance data, the training scheduler 200 determines set 1 and set 2. Set 1 includes the first part of the AI model's modules (such as the low-rank matrix in a model fine-tuning scenario), and set 2 includes the second part of the AI model's modules. Multiple different modules of the AI model can be grouped into different sets. Therefore, during the Nth (N is an integer greater than M) training round of the AI model, the training scheduler 200 updates the parameters of the first part of the modules in set 1 during the forward computation phase and updates the parameters of the second part of the modules in set 2 during the backpropagation phase.
[0049] During the Nth round of training of the AI model, the training scheduler 200 updates the parameters of the first part of the AI model during the forward computation phase of the Nth round of training. This eliminates the need to consume memory resources to save the gradient data (and activation values) for the parameters of that first part of the module, effectively reducing the memory resources required by the AI model during the Nth round of training. Simultaneously, based on the memory usage and performance of the AI model during the Mth round of training, the training scheduler 200 determines the first module in the AI model whose parameters are updated during the forward computation phase, and retains the second part of the module for parameter updates during the backpropagation phase. That is, it uses the gradient data calculated during the backpropagation phase to update the parameters. This reduces the memory resources required for model training while ensuring that the training accuracy of the AI model still reaches a high level.
[0050] It is worth noting that the above Figure 1 The computing cluster 10 shown is merely an illustrative example and is not intended to limit the scope of the cluster. For instance, other possible computing clusters may include more or fewer computing nodes, and each computing node may contain a different number of computing units. Furthermore, different computing nodes may contain varying numbers of computing units. Additionally, other possible computing clusters may include nodes with other functionalities, such as nodes for managing multiple computing nodes.
[0051] For ease of understanding, the embodiments for quantizing AI models provided in this application are described below with reference to the accompanying drawings.
[0052] See Figure 2 , Figure 2 This is a flowchart illustrating an exemplary model training method provided in an embodiment of this application. Figure 2 The model training method shown can be applied to Figure 1 The computing cluster 10 shown can be applied to other possible computing clusters. For ease of understanding and description, the following description uses an application... Figure 1 The following explanation uses computing cluster 10 as an example. Computing cluster 10 deploys an AI model, and it can use computing nodes 101 and 102 to iteratively train the AI model.
[0053] like Figure 2 As shown, the model training method may specifically include the following steps.
[0054] S201: The training scheduler 200 acquires memory data and performance data. The memory data is used to indicate the memory usage of the AI model during the M rounds of training, and the performance data is used to indicate the performance of the AI model during the M rounds of training, where M is a positive integer.
[0055] In this embodiment, the AI model can be iteratively trained in the computing cluster 10, including fine-tuning the AI model or retraining the AI model. Since the model training process consumes a lot of memory resources in the computing cluster 10, the training scheduler 200 can monitor the memory consumption of the AI model during the iterative training process.
[0056] As an implementation example, the training scheduler 200 can access the memory of compute nodes 101 and 102 during the current round of training of the AI model (or any round of training that has already been executed) to obtain the memory usage of compute nodes 101 and 102, that is, to obtain the aforementioned memory data. This memory data can be, for example, memory occupancy rate or the size of the memory space occupied. In this case, the value of M can be 1.
[0057] In practical applications, the training scheduler 200 can fine-tune the AI model based on a low-rank matrix. Specifically, for the AI model to be fine-tuned, a corresponding low-rank matrix can be configured. Thus, the output of the AI model is the combined result of the output data of the AI model's own network layers and the output data of this low-rank matrix. Correspondingly, during the fine-tuning process, the parameters in the AI model's own network layers are not updated (i.e., the parameters in the network layers can be frozen); only the parameters in the configured low-rank matrix are updated.
[0058] For example, such as Figure 3 As shown, assuming the AI model includes 3 network layers, namely... Figure 3 The diagram shows network layers 1, 2, and 3. During fine-tuning of the AI model, a low-rank matrix can be configured for each network layer. The low-rank matrix for each network layer can include matrix A and matrix B. For example... Figure 3 As shown, the same data can be used as input data not only for network layer 1 but also for matrix A-1. Furthermore, the output of matrix A-1 can be used as input data for matrix B-1, thus integrating the output data of network layer 1 with the output data of matrix B-1. Figure 3(This example illustrates the summation of the output data of network layer 1 and the output data of matrix B-1.) The resulting data can then be used as the input data for network layer 2. Similarly, the same method can be applied to the remaining network layers and their corresponding low-rank matrices to complete the forward computation process in the AI model and obtain its output. Accordingly, during fine-tuning of the AI model, only the parameters in the low-rank matrices of each network layer (i.e., matrices A-1, A-2, A-3, B-1, B-2, and B-3) can be updated, while the parameters in network layers 1 through 3 remain unchanged (i.e., parameters are frozen). Typically, each network layer has a large number of parameters, while the low-rank matrices configured for that layer have a smaller number of parameters. Therefore, in model fine-tuning scenarios, updating only the parameters in the low-rank matrices not only allows the AI model to learn new knowledge but also effectively reduces the memory resources required for fine-tuning. In practical applications, some network layers in the AI model may also be configured with low-rank matrices.
[0059] With parameters frozen in the network layers of the AI model, the training scheduler 200 can obtain only the amount of memory resources consumed by the low-rank matrices in the AI model during training. For example, in practical applications, the AI model can be deployed on computing node 101 and run through multiple computing units in computing node 101. The low-rank matrices corresponding to each network layer in the AI model can be deployed on computing node 102 and run through one or more computing units in computing node 102. Thus, the training scheduler 200 can obtain only the memory consumption in computing node 102.
[0060] In other embodiments, when the memory usage of the AI model changes dynamically during multiple training rounds, the training scheduler 200 can also obtain the memory usage of the AI model during multiple training rounds (such as memory occupancy rate or the size of the memory space occupied), that is, the value of M can be greater than 1. In this case, the training scheduler 200 can calculate the average memory usage of the AI model during multiple training rounds and use this average value as the aforementioned memory data, etc., without limitation.
[0061] In addition to acquiring memory data, the training scheduler 200 can also acquire performance data, which indicates the performance of the AI model during the M rounds of training.
[0062] For example, performance data could be, for instance, the loss value of the AI model during training. A larger loss value indicates a greater deviation between the inference result calculated by the AI model in the forward computation phase and the actual result, thus indicating lower accuracy of the AI model's inference; conversely, a smaller loss value indicates higher accuracy of the AI model's inference. Therefore, the training scheduler 200 can obtain the loss value of the AI model during M training rounds to determine the performance of the AI model during those M rounds. Specifically, when M is 1, the training scheduler 200 can obtain the loss value of the AI model in the current round of training; when M is greater than 1, the training scheduler 200 can record the loss value of the AI model in each round of training and calculate the average of the loss values over the M rounds to obtain the aforementioned performance data. In other embodiments, other metrics can also be used to measure the performance of the AI model, such as the accuracy of the AI model's inference, etc., and this is not limited.
[0063] S202: The training scheduler 200 determines set 1 and set 2 based on memory data and performance data. Set 1 includes the first part of the AI model modules, and set 2 includes the second part of the AI model modules. During the Nth round of training of the AI model, the first part of the modules in set 1 updates its parameters during the forward computation phase, and the second part of the modules in set 2 updates its parameters during the backpropagation phase. N is a positive integer greater than M.
[0064] It is understandable that updating all the parameters to be trained in an AI model using gradients during the backpropagation phase would result in significant memory consumption during training. Therefore, in this embodiment, the training scheduler 200 divides the parameters to be trained in the AI model into multiple sets. Different sets can use different methods to update the parameters, thereby reducing the required memory resources. Each set can include some modules of the AI model, and each module includes at least one parameter of the AI model. Different sets can include different modules (i.e., different parameters of the AI model).
[0065] In scenarios where AI models are fine-tuned, the modules within the AI model can specifically be low-rank matrices (or adapters), and each module may include... Figure 3 The A matrix and / or B matrix shown are examples of such matrices.
[0066] In scenarios where AI models are retrained, the modules in the AI model can specifically be neurons, network layers, or Transformer blocks, or other constituent units at different granularities.
[0067] Then, since updating model parameters via backpropagation requires storing gradient data, activation values, and other information in memory, this consumes significant memory resources. Therefore, in some sets determined by the training scheduler 200, the modules in a subset are not updated during the backpropagation phase, but rather during the forward computation phase. This eliminates the need to store the corresponding gradient data and activation values in memory during the parameter update process for these modules, thereby reducing memory resource consumption.
[0068] The following example uses two sets out of multiple sets to illustrate the process by which the training scheduler 200 determines set 1 (for parameter updates during the forward computation phase) and set 2 (for parameter updates during the backpropagation phase).
[0069] In one possible implementation, such as Figure 4 As shown, the training scheduler 200 can first determine the upper limit of memory resources for the AI model, which is used to limit the maximum memory space that the AI model can use during training.
[0070] For example, the memory resource limit can be configured by the user via a client before training the AI model. For instance, the training scheduler 200 can output the following to the client: Figure 5 The interactive interface shown is presented to the user by the client. The user can then input a specific value for the maximum memory resource limit, such as 64GB (gigabytes), and the client will provide the user-specified memory resource limit to the training scheduler 200.
[0071] Alternatively, the memory resource limit can also be the maximum memory space that the computing cluster 10 can provide. For example, before training the AI model, the training scheduler 200 can detect the memory resources in the computing cluster 10 to determine the maximum memory space that the computing cluster 10 can provide, that is, to determine the memory resource limit.
[0072] Then, as Figure 4 As shown, the training scheduler 200 can determine the ratio between the number of modules that update parameters during the forward computation phase and the number of modules that update parameters during the backpropagation phase in the AI model, based on the memory resource limit. That is, it determines the ratio between the number of modules in the first part of set 1 and the number of modules in the second part of set 2. For ease of distinction and description, this ratio will be referred to as the target ratio below.
[0073] In practical implementation, the training scheduler 200 can first determine, through theoretical calculations, the memory resources required for each module in the AI model, including the parameters to be trained, to update parameters during the forward computation phase and the memory resources required for updating parameters during the backpropagation phase. Then, based on the memory resource limit and the memory resources occupied by each module when updating parameters using different methods, the training scheduler 200 can determine a target ratio between the number of modules updating parameters in the forward computation phase and the number of modules updating parameters in the backpropagation phase, provided that the total memory resource consumption does not exceed the memory resource limit.
[0074] In practical applications, the target ratio can also be specified by the user. For example, before training the AI model, the user can configure the target ratio on the interactive interface, and the client can provide the user-configured target ratio to the training scheduler 200. In this embodiment, the specific implementation method by which the training scheduler 200 determines the target ratio is not limited.
[0075] Next, as Figure 4 As shown, the training scheduler 200 can generate multiple allocation strategies based on the target ratio. Each allocation strategy is used to instruct the first part of the AI model to update parameters during the forward computation phase and the second part of the model to update parameters during the backward computation phase. The ratio of the number of modules in each allocation strategy can be the target ratio, or the ratio between the number of the first part of the module updating parameters during the forward computation phase and the number of the second part of the module updating parameters during the backward propagation phase can be greater than the target ratio.
[0076] Then, as Figure 4 As shown, the training scheduler 200 can predict the performance of an AI model trained based on each allocation strategy, based on memory data and performance data. For example, the training scheduler 200 can determine the performance of the AI model corresponding to each allocation strategy using an optimization algorithm, such as a Bayesian optimization algorithm. Specifically, taking the performance of the AI model as represented by the loss value as an example, for each allocation strategy, the training scheduler 200 can use the first part of the AI model's parameter update during the forward computation phase, the second part of the parameter update during the backpropagation phase, the loss value of the AI model during this round of training (or M rounds), and the allocation strategy as inputs to the optimization algorithm. It then uses this optimization algorithm to predict the loss value of the AI model trained based on that allocation strategy, that is, to predict the performance of the AI model trained based on that allocation strategy.
[0077] Thus, as Figure 4 As shown, the training scheduler 200 can determine the highest-performing allocation strategy from multiple allocation strategies based on the performance of the AI model when trained using each allocation strategy. For example, the training scheduler 200 can perform bubble sort (or use other sorting algorithms) on the loss values corresponding to multiple allocation strategies to determine the allocation strategy with the smallest loss value (i.e., the target). For ease of distinction and description, this will be referred to as the target allocation strategy below.
[0078] Finally, as Figure 4 As shown, the training scheduler 200 can determine set 1 and set 2 according to the target allocation strategy. Specifically, it can add the first part of the AI model that updates parameters in the forward computation stage to set 1, and add the second part of the AI model that updates parameters in the backpropagation stage to set 2, etc.
[0079] In a further possible implementation, the training scheduler 200 can also optimize the training process for the AI model based on expert rules. Specifically, in practical applications, the training scheduler 200 can also support user intervention in the training process of the AI model. In this case, the user can, for example... Figure 5 The interactive interface shown configures expert rules, which the client can then provide to the training scheduler 200. These expert rules instruct the conditions that must be met by the first part of the AI model whose parameters are updated during the forward computation phase and the second part whose parameters are updated during the backpropagation phase. For example, expert rules can specifically indicate which modules in the AI model must have their parameters updated during the forward computation phase and which modules must have their parameters updated during the backpropagation phase, thus introducing a protective boundary for optimization based on user experience (expert experience) to help improve the training accuracy and reliability of the AI model. Alternatively, expert rules can specifically indicate the maximum ratio between the number of the first part of the AI model whose parameters are updated during the forward computation phase and the number of the second part whose parameters are updated during the backpropagation phase, thereby preventing an excessively large proportion of modules whose parameters are updated during the forward computation phase from affecting the training accuracy of the AI model.
[0080] In this way, the training scheduler 200 can generate multiple allocation strategies based on the target ratio and the expert rules provided by the user. At this point, the first part of the module whose parameters are updated during the forward computation phase and the second part of the module whose parameters are updated during the backward computation phase, as indicated by each allocation strategy, both satisfy the expert rule, such as the ratio between these two parts of the module not exceeding the maximum ratio indicated by the expert rule. Therefore, the training scheduler 200 can determine the target allocation strategy from the multiple allocation strategies based on the above method, and determine set 1 and set 2 according to the target allocation strategy.
[0081] It should be noted that the above implementation describes the process by which the training scheduler 200 determines set 1 and set 2 based on the memory resource limit, memory data, and performance data, under the condition of limited memory resources. In other embodiments, the computing cluster 10 can train the AI model based on sufficient memory resources. In this case, the training scheduler 200 can also determine set 1 and set 2 based solely on memory data and performance data, thereby reducing (e.g., minimizing) the memory resources consumed during the AI model training process.
[0082] In the forward computation phase, the execution order of the first part of the modules in set 1 precedes the execution order of the second part of the modules in set 2. For example, in a scenario where the AI model is fine-tuned, the first part of the modules in set 1 may include... Figure 3 The A-1 matrix, B-1 matrix, A-2 matrix, and B-2 matrix in set 2, and the second part of the module may include... Figure 3 The A-3 matrix and B-3 matrix are used in the context of retraining the AI model. In the scenario of retraining the AI model, the first part of the modules in set 1 can be the first K consecutive modules (such as the first K network layers) in the AI model, and the second part of the modules in set 2 can be the (K+1)th to (K+L)th modules (such as the (K+1)th network layer to the last network layer) in the AI model. The AI model includes (K+L) modules.
[0083] Alternatively, during the forward computation phase, the first part of the modules in set 1 and the second part of the modules in set 2 are executed alternately (the two modules in set 2 can be separated by one or more modules from set 1). For example, in a scenario where the AI model is being fine-tuned, the first part of the modules in set 1 could include... Figure 3 The A-1 matrix, B-1 matrix, A-3 matrix, and B-3 matrix in set 2, and the second part of the module may include... Figure 3 The A-2 matrix and B-2 matrix are used in the AI model retraining scenario. In the scenario of retraining the AI model, the first part of the modules in set 1 can be the modules with odd positions in the AI model (such as the 1st network layer, the 3rd network layer, the 5th network layer, etc.), and the second part of the modules in set 2 can be the modules with even positions in the AI model (such as the 2nd network layer, the 4th network layer, the 6th network layer, etc.).
[0084] After determining set 1 and set 2, the training scheduler 200 can further guide the computing nodes in the computing cluster 10 to continue the training process for the AI model based on set 1 and set 2, thereby reducing the memory resources consumed by the AI model in subsequent training processes. Based on this, this embodiment may further include the following steps.
[0085] S203: The training scheduler 200 notifies multiple computing nodes of set 1 and set 2.
[0086] S204: During the Nth round of training of the AI model, multiple computing nodes update the parameters of the first part of the AI model belonging to set 1 in the forward computation phase, and update the parameters of the second part of the AI model belonging to set 2 in the backpropagation phase.
[0087] For example, during the Nth round of training, there can be multiple computing nodes (including...) Figure 1 The next round of training process to be executed by computing nodes 101 and 102 in the training process.
[0088] During the parameter update process in the backpropagation phase, computation node 101 and / or computation node 102 can calculate the gradient data corresponding to the parameters in the last module of the AI model based on the loss value of the AI model in the Nth round of training and the activation values of the parameters in the last module of the AI model (ordered according to the computation logic of the forward computation phase) (generated and stored in memory during the forward computation phase). Thus, computation node 101 and / or computation node 102 can use the gradient data to update the parameters in the last module (which belongs to set 2), or calculate the gradient data corresponding to the parameters of each module in set 2 of the AI model based on the gradient data according to the backpropagation rule, and use the gradient data corresponding to the parameters of that module to update the parameters.
[0089] Specifically, when the first part of the modules in set 1 and the second part of the modules in set 2 are executed concurrently during the forward computation phase, for one or more modules in the AI model located between the two modules in set 2, the activation values calculated by the parameters of these one or more modules during the forward computation phase can be stored in memory. This allows computation node 101 and / or computation node 102 to calculate the gradient data of the parameters of the corresponding module in set 2 based on these activation values. For example, for modules A and D in set 2, assuming that modules B and C in the AI model are separated from modules A and D during the forward computation phase, the activation values calculated by the parameters of modules B and C can be stored in memory during the forward computation phase. Accordingly, during the backpropagation phase, when computation node 101 and / or computation node 102 update the parameters of module A in set 2, they can calculate the gradient data for the parameters in module A based on the gradient data corresponding to the parameters of module D, the activation values calculated by the parameters in module C, the activation values calculated by the parameters in module B, and the activation values calculated by the parameters in module A, and update the parameters in module A based on the gradient data.
[0090] When updating parameters during the forward computation phase, compute node 101 and / or compute node 102 can update the parameters of each first part module in set 1 of the AI model based on localized rules.
[0091] As a first implementation example, compute node 101 and / or compute node 102 can perform localized learning based on Hebbian rules to update parameters. Specifically, for module Q in the AI model that belongs to set 1, compute node 101 and / or compute node 102 can update the parameters in module Q based on the following formulas (1) and (2).
[0092] Δw=x×y Formula (1)
[0093] w=w+η×Δw Formula (2)
[0094] Where x refers to the input data of module Q in the forward computation phase, y refers to the output data of module Q in the forward computation phase, η refers to the learning rate, and w refers to the parameters (weights) in module Q.
[0095] As a second implementation example, in scenarios such as fine-tuning the AI model, the modules in set 1 can be low-rank matrices, etc. In this case, the AI model includes the frozen parameters corresponding to that module. Frozen parameters refer to parameters that will not be updated during model training. For example, the modules in set 1 can include... Figure 3 The A-1 and B-1 matrices shown can be used as the freeze parameters for this module. Figure 3 The parameters included in network layer 1 (the parameters in network layer 1 are not updated during AI model training, but the parameters in matrices A-1 and B-1 are updated). The following example demonstrates updating the parameters of a module in set 1; for clarity, this module will be referred to as the target module.
[0096] Computation node 101 and / or computation node 102 can obtain the output results obtained by calculating the input data based on the frozen parameters corresponding to the target module during the forward computation stage. During the forward computation stage, the target module and the frozen parameters share the same input data. Therefore, computation node 101 and / or computation node 102 can update the parameters in the target module based on the input data and the output results of the frozen parameters. In this way, computation node 101 and / or computation node 102 can generalize the local learning rules for the module to a coarser-grained mode, thereby improving the accuracy of updating the parameters in the module, and thus improving the training accuracy of the AI model. For example, when the target module is a low-rank matrix and the frozen parameters are the parameters included in a network layer corresponding to the low-rank matrix, computation node 101 and / or computation node 102 can update the parameters in the low-rank matrix based on the input data and the output results of the network layer, thus generalizing the local learning rules for the low-rank matrix to the layer granularity.
[0097] For example, for module Q in set 1 of the AI model, computing node 101 and / or computing node 102 can update the parameters in module Q based on the following formula (3) and the above formula (2).
[0098]
[0099] Where x refers to the input data of module Q in the forward computation phase, y refers to the output data of the frozen parameters (network layer) of module Q in the forward computation phase, η refers to the learning rate, w refers to the parameters in module Q, and ||| refers to the L2 norm.
[0100] Furthermore, in the model fine-tuning scenario, during the second to Nth rounds of training of the AI model, the training scheduler 200, computing node 101, and computing node 102 can update some parameters in the AI model during the forward computation phase and update another part of the parameters in the AI model during the backward computation phase, based on the aforementioned method. During the first round of training of the AI model, the training scheduler 200 can determine the first part of the modules belonging to set 1 and the second part of the modules belonging to set 2 in the AI model based on a static allocation strategy.
[0101] In practical implementation, users can, for example... Figure 5The interactive interface shown configures a static allocation strategy. This strategy instructs which modules in the AI model update parameters during the forward computation phase and which update parameters during the backward computation phase. The client provides this static allocation strategy to the training scheduler 200. Thus, the training scheduler 200 can, according to this static allocation strategy, instruct computing nodes 101 and / or 102 to update user-specified parameters during the forward computation phase and user-specified parameters during the backward computation phase in the first round of model training. In subsequent training rounds 2 through N, the training scheduler 200 can, based on the above method, redetermine the first part of the modules belonging to set 1 and the second part of the modules belonging to set 2 in the AI model, and instruct computing nodes 101 and / or 102 to update parameters in subsequent model training processes based on the determined sets 1 and 2. In the training process from the 2nd to the Nth round, the ratio between the number of modules in the first part of set 1 and the number of modules in the second part of set 2 can remain constant (e.g., it can remain at the target ratio mentioned above), or it can change dynamically. For example, while the training scheduler 200 uses the optimization algorithm to determine set 1 and set 2, it can also determine the ratio between the number of modules in the first part of set 1 and the number of modules in the second part of set 2 (this ratio can increase during multiple iterations).
[0102] In other embodiments, the static allocation strategy can also be pre-configured in the training scheduler 200 by a technician, and this is not limited. Furthermore, in practical applications, in addition to configuring the aforementioned memory resource limits, expert rules, and static allocation strategies, users can also configure other information on the interactive interface. Figure 5 (Not shown in the text) For example, the termination conditions that must be met when the AI model ends fine-tuning, the upper limit of the training time of the AI model, etc. are not limited.
[0103] The above Figure 2 The illustrated embodiment uses updating some parameters in the AI model during the forward computation stage as an example. In other embodiments, the above... Figure 2 Based on the illustrated embodiment, the batch size used by the AI model during multiple training rounds can be dynamically adjusted to accelerate the training process or improve the training accuracy. The following section will discuss this further. Figure 6 This will be illustrated by example.
[0104] See Figure 6 This illustrates a flowchart of another model training method, such as... Figure 6 As shown, the method may specifically include the following steps.
[0105] S601: The training scheduler 200 acquires memory data and performance data. The memory data is used to indicate the memory usage of the AI model during the M rounds of training, and the performance data is used to indicate the performance of the AI model during the M rounds of training, where M is a positive integer.
[0106] For the specific implementation of step S601, please refer to the above. Figure 2 The relevant details of step S201 in the illustrated embodiment will not be repeated here.
[0107] S602: The training scheduler 200 determines set 1, set 2 and batch size based on memory data and performance data. Set 1 includes the first part of the AI model and set 2 includes the second part of the AI model.
[0108] The implementation of the training scheduler 200 for determining set 1 and set 2 can be found in the above. Figure 2 The relevant details of step S202 in the illustrated embodiment are not repeated here.
[0109] In this embodiment, the training scheduler 200 can not only determine set 1 and set 2 based on memory data and performance data, but also determine the batch size used by the AI model in the subsequent training process based on the memory data and performance data.
[0110] As an implementation example, the training scheduler 200 can obtain the maximum memory space that the AI model can use during training, i.e., the aforementioned memory resource limit. In the scenario of fine-tuning the AI model, this memory resource limit can specifically refer to the maximum memory space that can be used to store the relevant data of the low-rank matrix in the AI model (such as gradient data, parameter values, and activation values).
[0111] Then, the training scheduler 200 can determine allocation strategies corresponding to various batch sizes based on the memory resource limit. Specifically, for each batch size, the training scheduler 200 can determine the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase in the AI model, such as by referring to the theoretical calculation method mentioned above. In this way, the amount of memory resources required by computing nodes 101 and 102 to subsequently train the AI model based on this ratio will not exceed the memory resource limit. For example, suppose the batch size used by the AI model in the current training process is 1, and the training scheduler 200 can theoretically calculate that the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase is 1:9. Then, the training scheduler 200 can determine various allocation strategies with a 1:9 module ratio, and the first-part modules used for parameter updates during the forward computation phase will differ depending on the allocation strategy. Furthermore, the training scheduler 200 can also calculate, through theoretical calculations and other methods, the ratio between the number of the first part of modules that perform parameter updates during the forward computation phase and the number of the second part of modules that perform parameter updates during the backpropagation phase, assuming this ratio is 1:2, when the batch size is 2. Therefore, the training scheduler 200 can determine multiple allocation strategies with a 1:2 ratio for these two parts of modules when the batch size is 2. Different allocation strategies indicate different uses of the first part of modules that perform parameter updates during the forward computation phase.
[0112] Next, the training scheduler 200 can predict the performance of the AI model when trained based on each allocation strategy, based on memory data and performance data. For example, performance can be predicted using optimization algorithms such as Bayesian optimization. In this way, the training scheduler 200 can determine the highest-performing target allocation strategy from the allocation strategies corresponding to various batch sizes, and determine set 1, set 2, and batch size based on the target allocation strategy.
[0113] In a further possible implementation, the training scheduler 200 can also optimize the process of generating allocation strategies based on expert rules. Specifically, the training scheduler 200 can determine the allocation strategies corresponding to various batch sizes based on the memory resource limit and expert rules, so that each allocation strategy can meet the constraints indicated by the expert rule.
[0114] S603: The training scheduler 200 notifies multiple computing nodes of set 1, set 2, and batch size.
[0115] S604: Multiple computing nodes perform the Nth round of training on the AI model based on the batch size. During the Nth round of training on the AI model, the parameters of the first part of the AI model belonging to set 1 are updated in the forward computation phase, and the parameters of the second part of the AI model belonging to set 2 are updated in the backpropagation phase.
[0116] The batch size determined by the training scheduler 200 may be the same as or different from the batch size used by the AI model in the (N-1)th round of training (details omitted).
[0117] When the batch size determined by the training scheduler 200 is greater than the batch size used by the AI model in the (N-1)th training round, the number of training samples used in the Nth training round increases. This leads to an increase in the memory resources required for model training. However, the proportion of parameters updated in the forward computation phase of the AI model can increase (i.e., the number of modules belonging to the first part of set 1 increases), which reduces the memory resources required to store gradient data, activation values, and other information. This ensures that the overall memory consumption of the AI model in the Nth training round still does not exceed the memory resource limit. Thus, by increasing the batch size used by the AI model in the Nth training round, the convergence of the AI model can be accelerated without exceeding the memory consumption limit, thereby speeding up the training of the AI model and improving training efficiency.
[0118] When the batch size determined by the training scheduler 200 is smaller than the batch size used by the AI model in the (N-1)th training round, the number of training samples used in the Nth training round can be reduced, which leads to a reduction in the memory resources required for model training. In this case, the proportion of parameters updated during the forward computation phase can be reduced (i.e., the number of modules belonging to the first part of set 1 can be reduced), and correspondingly, the proportion of parameters updated during the backpropagation phase can be increased (i.e., the number of modules belonging to the second part of set 2 can be increased). Therefore, by appropriately reducing the batch size and increasing the proportion of parameters updated during the backpropagation phase, the training accuracy of the AI model can be improved.
[0119] Based on the above Figure 6The training process shown trains the AI model. With limited memory resources, not only does the trained AI model achieve a high level of accuracy, but dynamically increasing the batch size also improves training efficiency and throughput. In actual test scenarios, with limited memory resources, fine-tuning two LLaMA-2 models and four Qwen1.5 models (retraining the parameters in the low-rank matrix) yields the following results compared to updating all parameters in the AI model during the backpropagation phase (using the LoRA algorithm for model fine-tuning): Figure 7 The training results are shown. Here, B represents one billion. The Qwen1.5-0.5B model means that the model includes 500 million (i.e., 0.5 * 1 billion) parameters; other models are similar. At this point, the above... Figure 5 The model training method shown can be called the Localized Update LoRA (LU-LoRA) algorithm. Figure 7 As shown, the training accuracy of the AI model can be improved. Training accuracy can be measured by perplexity (PPL), where lower perplexity indicates higher training accuracy. Furthermore, the throughput of the AI model can be improved, while the required memory resources are reduced.
[0120] It is worth noting that other reasonable combinations of steps that can be conceived by those skilled in the art based on the above description also fall within the scope of protection of this application. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to this application.
[0121] The above combination Figures 1 to 7 The model training method provided in the embodiments of this application will be introduced. Next, the structure of the model training device and computing device provided in the embodiments of this application will be described with reference to the accompanying drawings.
[0122] See Figure 8 The diagram shows a schematic of a model training device 800, which includes:
[0123] The acquisition module 801 is used to acquire memory data and performance data. The memory data is used to indicate the memory usage of the AI model during the M rounds of training, and the performance data is used to indicate the performance of the AI model during the M rounds of training, where M is a positive integer.
[0124] The determination module 802 is used to determine a first set and a second set based on memory data and performance data. The first set includes the first part of the modules in the AI model, and the second set includes the second part of the modules in the AI model.
[0125] In the Nth round of training of the AI model, the first part of the first set of modules updates its parameters during the forward computation phase, and the second part of the second set of modules updates its parameters during the backpropagation phase, where N is a positive integer greater than M.
[0126] In one possible implementation, the determining module 802 is further configured to determine the batch size based on memory data and performance data, and the AI model performs the Nth round of training based on the batch size.
[0127] In one possible implementation, the determining module 802 is configured to:
[0128] Based on memory data and performance data, predict the performance of the AI model trained on each of a variety of allocation strategies. The allocation strategy is used to indicate the first part of the AI model that updates parameters during the forward computation phase and the second part of the AI model that updates parameters during the backpropagation phase.
[0129] Among multiple allocation strategies, the AI model trained based on the target allocation strategy exhibits the highest performance.
[0130] The first set and the second set are determined based on the target allocation strategy.
[0131] In one possible implementation, the determining module 802 is configured to:
[0132] Determine the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase in the AI model.
[0133] Based on the proportion, multiple allocation strategies can be generated;
[0134] Based on memory and performance data, predict the performance of the AI model trained using each of the various allocation strategies.
[0135] In one possible implementation, the determining module 802 is configured to:
[0136] Based on the proportions and expert rules, multiple allocation strategies are generated. The expert rules are used to indicate the conditions that the first part of the AI model, which updates parameters during the forward computation phase, and the second part of the AI model, which updates parameters during the backpropagation phase, must satisfy.
[0137] In one possible implementation, the first set includes target modules, and the AI model includes frozen parameters corresponding to the target modules. The frozen parameters are not updated during the training of the AI model.
[0138] The acquisition module 801 is also used to acquire the output results obtained by calculating the input data based on the frozen parameters during the forward calculation stage. The target module and the frozen parameters share the input data.
[0139] The model training device 800 also includes a parameter update module 803, which is used to update the parameters in the target module based on the input data and the output results.
[0140] In one possible implementation, the model training device 800 further includes:
[0141] Output module 804 is used to output the interactive interface;
[0142] The acquisition module 801 is also used to respond to the user's configuration operation to acquire the memory resource limit or expert rules. The memory resource limit is used to limit the maximum memory space that the AI model can use during training. The expert rules are used to indicate the conditions that the first part of the AI model that updates parameters in the forward computation phase and the second part of the AI model that updates parameters in the backpropagation phase must meet.
[0143] In one possible implementation, during the forward computation phase, the execution order of the first part of the modules in the first set precedes the execution order of the second part of the modules in the second set; or, during the forward computation phase, the first part of the modules in the first set and the second part of the modules in the second set are executed alternately.
[0144] because Figure 8 The model training device 800 shown corresponds to the above. Figure 2 The training scheduler 200 in the illustrated embodiment, therefore Figure 8 For the specific implementation of the model training device 800 shown and its technical effects, please refer to the above. Figure 2 The relevant details in the illustrated embodiments are described in detail here, and will not be repeated here.
[0145] Exemplarily, the model training device 800 described above can be implemented in software or hardware. In the first example, the model training device 800 can be implemented in software, specifically as code running on a computing instance, such as code running in a physical device, virtual machine, or container. In the second example, when implemented in hardware, the model training device 800 can be implemented using a processor, or as a physical device including a processor, such as a server. The processor can be a CPU, ASIC, PLD, CPLD, FPGA, GAL, SoC, SDI chip, AI chip, or DPU, or any combination of the above processors. Furthermore, the number of processors included in the model training device 800 can be one or more, and the types of processors can be one or more. The specific number and types of processors can be set according to the actual application's business requirements; this embodiment does not limit this.
[0146] Figure 9 This application provides a schematic diagram of the hardware structure of a computing device 900, which, for example, can implement the above-described... Figure 2 The training scheduler 200 in the illustrated embodiment, etc.
[0147] like Figure 9 As shown, the computing device 900 includes a processor 901, a memory 902, and a communication interface 903. The processor 901, memory 902, and communication interface 903 communicate via a bus 904, or via other means such as wireless transmission. The memory 902 stores instructions, and the processor 901 executes the instructions stored in the memory 902. Further, the computing device 900 may also include a memory unit 905, which is connected to the processor 901, the storage medium 902, and the communication interface 903 via the bus 904. The memory 902 stores program code, and the processor 901 can read the program code stored in the memory 902 into the memory unit 905 and execute the program code in the memory unit 905 to perform the following operations:
[0148] Obtain memory data and performance data. Memory data is used to indicate the memory usage of the AI model during M rounds of training, and performance data is used to indicate the performance of the AI model during M rounds of training, where M is a positive integer.
[0149] Based on memory data and performance data, a first set and a second set are determined. The first set includes the first part of the modules in the AI model, and the second set includes the second part of the modules in the AI model.
[0150] In the Nth round of training of the AI model, the first part of the first set of modules updates its parameters during the forward computation phase, and the second part of the second set of modules updates its parameters during the backpropagation phase, where N is a positive integer greater than M.
[0151] It should be understood that in this embodiment, the processor 901 can be a CPU, but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete device assemblies, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0152] The memory 902 may include read-only memory and random access memory, and provides instructions and data to the processor 901. The memory 902 may also include non-volatile random access memory.
[0153] The memory 902 can be volatile memory or non-volatile memory, or it can include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0154] The communication interface 903 is used to communicate with other devices connected to the computing device 900. The bus 904 may include a data bus, a power bus, a control bus, and a status signal bus, etc. However, for clarity, all buses are labeled as bus 904 in the figure.
[0155] It should be understood that the computing device 900 in this application embodiment can correspond to executing the functions according to the embodiments of this application. Figure 2 The methods executed by the training scheduler 200 in the illustrated method, and the aforementioned and other operations and / or functions implemented by the computing device 900, are respectively for the purpose of implementing... Figure 2 The process of the corresponding methods in [the document] will not be elaborated here for the sake of brevity.
[0156] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium capable of being stored by a computing device, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the aforementioned model training method.
[0157] This application also provides a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computing device, all or part of the processes or functions described in this application are generated.
[0158] The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, or data center to another website, computer, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means.
[0159] The computer program product can be a software installation package. When any of the aforementioned model training methods is required, the computer program product can be downloaded and executed on a computing device.
[0160] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.
[0161] The terminology used in the above embodiments is for the purpose of describing specific embodiments only and is not intended to be a limitation of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the embodiments of this application, “one or more” refers to one, two, or more; the character “ / ” generally indicates that the preceding and following objects are in an “or” relationship. In the embodiments of this application, “simultaneously” means within the same time period, including situations where they are at the same moment. The terms “first,” “second,” etc., in the specification, claims, and drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate, and this is merely a way of distinguishing objects with the same attributes in the embodiments of this application.
[0162] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0163] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A model training method, characterized in that, The method includes: Acquire memory data and performance data, wherein the memory data is used to indicate the memory usage of the AI model during M rounds of training, and the performance data is used to indicate the performance of the AI model during the M rounds of training, where M is a positive integer; Based on the memory data and the performance data, a first set and a second set are determined, wherein the first set includes a first part of the modules in the AI model, and the second set includes a second part of the modules in the AI model; In the Nth round of training of the AI model, the first part of the modules in the first set updates the parameters during the forward computation phase, and the second part of the modules in the second set updates the parameters during the backpropagation phase, where N is a positive integer greater than M.
2. The method according to claim 1, characterized in that, The method further includes: Based on the memory data and the performance data, the batch size is determined, and the AI model performs the Nth round of training based on the batch size.
3. The method according to claim 1 or 2, characterized in that, The step of determining the first set and the second set based on the memory data and the performance data includes: Based on the memory data and the performance data, predict the performance of the AI model trained using each of the multiple allocation strategies, wherein the allocation strategy is used to indicate the first part of the AI model that updates parameters during the forward computation phase and the second part of the AI model that updates parameters during the backpropagation phase. The AI model trained based on the selected target allocation strategy among the various allocation strategies exhibits the highest performance. The first set and the second set are determined according to the target allocation strategy.
4. The method according to claim 3, characterized in that, The step of predicting the performance of the AI model trained based on each of a variety of allocation strategies, using the memory data and the performance data, includes: Determine the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase in the AI model. Based on the stated ratio, the various allocation strategies are generated; Based on the memory data and the performance data, predict the performance of the AI model when trained using each of the multiple allocation strategies.
5. The method according to claim 4, characterized in that, The generation of the multiple allocation strategies based on the ratio includes: Based on the ratio and expert rules, the various allocation strategies are generated. The expert rules are used to indicate the conditions that the first part of the AI model, which updates parameters during the forward computation phase, and the second part of the AI model, which updates parameters during the backpropagation phase, need to satisfy.
6. The method according to any one of claims 1 to 5, characterized in that, The first set includes a target module, and the AI model includes frozen parameters corresponding to the target module. The frozen parameters are not updated during the training of the AI model. The method further includes: The output result obtained by the forward calculation stage based on the frozen parameters on the input data is obtained, and the target module shares the input data with the frozen parameters; The parameters in the target module are updated based on the input data and the output results.
7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Output the interactive interface; In response to the user's configuration operation, the upper limit of memory resources or expert rules are obtained. The upper limit of memory resources is used to limit the maximum memory space that the AI model can use during training. The expert rules are used to indicate the conditions that the first part of the AI model that updates parameters in the forward computation phase and the second part of the AI model that updates parameters in the backpropagation phase must meet.
8. The method according to any one of claims 1 to 7, characterized in that, In the forward computation phase, the execution order of the first part of the modules in the first set is before the execution order of the second part of the modules in the second set; Alternatively, during the forward computation phase, the first part of the modules in the first set and the second part of the modules in the second set are executed interchangeably.
9. A model training device, characterized in that, The device includes: The acquisition module is used to acquire memory data and performance data. The memory data is used to indicate the memory usage of the artificial intelligence (AI) model during the M rounds of training, and the performance data is used to indicate the performance of the AI model during the M rounds of training, where M is a positive integer. The determining module is used to determine a first set and a second set based on the memory data and the performance data, wherein the first set includes a first part of the modules in the AI model, and the second set includes a second part of the modules in the AI model; In the Nth round of training of the AI model, the first part of the modules in the first set updates the parameters during the forward computation phase, and the second part of the modules in the second set updates the parameters during the backpropagation phase, where N is a positive integer greater than M.
10. The apparatus according to claim 9, characterized in that, The determining module is further configured to determine the batch size based on the memory data and the performance data, and the AI model performs the Nth round of training based on the batch size.
11. The apparatus according to claim 9 or 10, characterized in that, The determining module is used for: Based on the memory data and the performance data, predict the performance of the AI model trained using each of the multiple allocation strategies, wherein the allocation strategy is used to indicate the first part of the AI model that updates parameters during the forward computation phase and the second part of the AI model that updates parameters during the backpropagation phase. The AI model trained based on the selected target allocation strategy among the various allocation strategies exhibits the highest performance. The first set and the second set are determined according to the target allocation strategy.
12. The apparatus according to claim 11, characterized in that, The determining module is used for: Determine the ratio between the number of first-part modules that update parameters during the forward computation phase and the number of second-part modules that update parameters during the backpropagation phase in the AI model. Based on the stated ratio, the various allocation strategies are generated; Based on the memory data and the performance data, predict the performance of the AI model when trained using each of the multiple allocation strategies.
13. The apparatus according to claim 12, characterized in that, The determining module is used for: Based on the ratio and expert rules, the various allocation strategies are generated. The expert rules are used to indicate the conditions that the first part of the AI model, which updates parameters during the forward computation phase, and the second part of the AI model, which updates parameters during the backpropagation phase, need to satisfy.
14. The apparatus according to any one of claims 9 to 13, characterized in that, The first set includes a target module, and the AI model includes frozen parameters corresponding to the target module. The frozen parameters are not updated during the training of the AI model. The acquisition module is further configured to acquire the output result obtained by the forward calculation stage based on the frozen parameters to calculate the input data, and the target module shares the input data with the frozen parameters; The device further includes a parameter update module, used to update the parameters in the target module based on the input data and the output result.
15. The apparatus according to any one of claims 9 to 14, characterized in that, The device further includes: The output module is used to output the interactive interface; The acquisition module is further configured to acquire, in response to the user's configuration operation, a memory resource limit or expert rules. The memory resource limit is used to restrict the maximum memory space that the AI model can use during training. The expert rules are used to indicate the conditions that the first part of the AI model that updates parameters during the forward computation phase and the second part of the AI model that updates parameters during the backpropagation phase must meet.
16. The apparatus according to any one of claims 9 to 15, characterized in that, In the forward computation phase, the execution order of the first part of the modules in the first set is before the execution order of the second part of the modules in the second set; Alternatively, during the forward computation phase, the first part of the modules in the first set and the second part of the modules in the second set are executed interchangeably.
17. A computing device, characterized in that, The computing device includes a processor and memory. The memory is used to store instructions, and the processor executes the instructions stored in the memory to cause the computing device to perform the method as described in any one of claims 1 to 8.
18. A computer-readable storage medium, characterized in that, Includes instructions that, when executed on a computing device, cause the computing device to perform the method as described in any one of claims 1 to 8.
19. A computer program product containing instructions, characterized in that, When it is run on at least one computing device, it causes the at least one computing device to perform the method as described in any one of claims 1 to 8.