Model training method and device
By calculating the local gradient of a single card on each chip during reverse calculation of the model and synchronizing it to the target chip for Reduce operation, the problem of high memory usage and large communication volume in neural network model training is solved, and the training efficiency is improved.
Patent Information
- Application Number
- CN202411098120.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-10-29
AI Technical Summary
In large-scale neural network model training, the existing distributed training framework has problems such as high memory usage and large communication volume during the reverse calculation process, resulting in low efficiency.
During the reverse calculation of the model, the local gradient of a single card is calculated on each chip, and the local gradient of a single card on the other chips is synchronized to the target chip. Reduce operations are only performed on the target chip, avoiding all chips from performing Reduce operations and reducing communication volume. , and release the temporary cache to reduce video memory usage.
It reduces video memory usage and communication data volume, improves training speed, reduces scatter operations, and optimizes model training efficiency.
Smart Images

Figure CN118863002A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a model training method and device. Background Art
[0002] With the rapid development of artificial intelligence technology, the training of large-scale neural network models faces the problems of high video memory usage and large communication volume. The existing distributed training framework aims to improve training efficiency and hardware resource utilization by optimizing gradient calculation and communication processes.
[0003] Specifically, currently most methods distribute training data to different hardware devices. During the reverse calculation process, each hardware device calculates the complete gradient of a single card for the assigned training data, and then synchronizes the complete gradient of a single card for all hardware devices to obtain the global gradient. The global gradient is then distributed to different hardware devices, and then the cache on the hardware device that does not need to be maintained for storing the complete gradient of a single card is released. However, this method has a large amount of communication and occupies a high amount of video memory. Summary of the invention
[0004] The present invention provides a model training method and device to solve the defects existing in the related technology.
[0005] The present invention provides a model training method, comprising the following steps: During the reverse calculation of the model, on each chip, based on the corresponding current training data on each chip, the single-card local gradient of the current training data on each chip is calculated, where the current training data is part of the batch training data on each chip; Take any chip as a target chip, and synchronize the single-card local gradients on the remaining chips to the target chip; On the target chip, determining a single-card global gradient of the model based on the single-card local gradients of all chips; Based on the single-card global gradient, model parameters are updated on the target chip.
[0006] According to a model training method provided by the present invention, the single-card local gradient of the current training data on each chip is calculated based on the current training data corresponding to each chip, and the method also includes: Allocate a temporary cache to the remaining chips, where the temporary cache is used to store the single-card local gradients of the remaining chips.
[0007] According to a model training method provided by the present invention, synchronizing the single-card local gradients on the remaining chips to the target chip also includes: releasing the temporary cache of the remaining chips.
[0008] According to a model training method provided by the present invention, synchronizing the local gradients of single cards on other chips to the target chip includes: A protocol communication operation is performed on the target chip to synchronize the single-card local gradients on the remaining chips to the target chip.
[0009] According to a model training method provided by the present invention, the single-card global gradient of the determined model further includes: Using the previous training data as the current training data, and using any chip among the remaining chips as the target chip; Return to execute based on the current training data corresponding to each chip, calculate the single-card local gradient of the current training data on each chip, synchronize the single-card local gradients on the remaining chips to the target chip, and determine the single-card global gradient of the model on the target chip based on the single-card local gradients of all chips.
[0010] According to a model training method provided by the present invention, the method further includes: If the target chip is the last chip, after updating the model parameters on the target chip, the model training of the current iteration is obtained, and the model training of the next iteration is entered.
[0011] The present invention also provides a model training device, comprising the following modules: A calculation unit, used for calculating, on each chip, a single-card local gradient of current training data on each chip based on current training data corresponding to each chip during reverse calculation of the model, wherein the current training data is part of the training data in the batch of training data on each chip; A synchronization unit, used to take any chip as a target chip and synchronize the single-card local gradients on the remaining chips to the target chip; A determination unit, configured to determine, on the target chip, a single-card global gradient of the model based on the single-card local gradients of all chips; An updating unit is used to update model parameters on the target chip based on the single-card global gradient.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the model training method described above is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the model training methods described above.
[0014] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the model training methods described above.
[0015] The model training method and device provided by the present invention, since the current training data is part of the batch training data, the calculated single-card local gradient is a part of the single-card complete gradient. Compared with the single-card complete gradient calculated by each chip based on the batch training data in the related art, the cache space occupied by the single-card local gradient is smaller, that is, the video memory occupancy is reduced. In addition, the present invention only needs to perform the Reduce operation on the target chip, and the remaining chips do not need to perform the Reduce operation, avoiding the problem of large communication volume caused by the Reduce operation of all chips. When performing the Reduce operation, the communication transmission is the single-card local gradient of the remaining chips, and the communication volume is smaller than the single-card complete gradient of the Reduce operation in the related art. In addition, since the present invention currently only needs to update the model parameters on the target chip, and does not need to update the model parameters on other chips, it is not necessary to perform the Scatter operation on the single-card global gradient, that is, the present invention reduces the Scatter operation, thereby reducing the amount of communication data. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is a flow chart of the model training method provided by the present invention.
[0018] Figure 2 It is a parallel schematic diagram of gradient calculation and parameter updating provided by the present invention.
[0019] Figure 3 It is a structural schematic diagram of the model training device provided by the present invention.
[0020] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0022] In order to facilitate understanding of the technical solution of the present invention, the terms involved in the present invention are first explained as follows: Reduce operation: a communication operation that is usually used to aggregate data distributed on multiple devices or nodes to generate a global summary result. For example, in neural network model training, each hardware device (such as an artificial intelligence chip) calculates its own single-card complete gradient. The Reduce operation aggregates these single-card complete gradients into a global gradient for use when updating model parameters globally.
[0023] Scatter operation: that is, distributed communication operation. Scatter operation is opposite to Reduce, and it distributes or disperses global data to various hardware devices. For example, in neural network model training, Scatter operation means distributing the global gradient obtained by the above aggregation to various hardware devices, and each hardware device uses the distributed global gradient to update the model parameters that it is responsible for.
[0024] Reduce-Scatter operation: Reduce-Scatter operation is to combine the Reduce and Scatter operations to effectively aggregate and distribute data in a distributed environment. For example, in neural network model training, the Reduce-Scatter operation first performs a Reduce operation, which aggregates the complete gradients of each hardware device's single card into a global gradient, and then performs a Scatter operation, which distributes the global gradient to each hardware device, so that each hardware device can use the global gradient to update the model parameters for which it is responsible.
[0025] Currently, most training data is distributed to different hardware devices. During the reverse calculation process, each hardware device needs to calculate the complete gradient of a single card corresponding to the distributed training data before it can perform the Reduce operation (i.e., aggregate the complete gradient of a single card into a global gradient), and then perform the Scatter operation (i.e., distribute the global gradient to each hardware device).
[0026] However, when performing Reudce operations, the communication volume of this solution is the complete gradient of a single card calculated by each hardware device, which is large. In addition, when each hardware device calculates the complete gradient of a single card, each hardware device needs to maintain the video memory corresponding to the complete gradient of the single card. If the number of parameters of the complete gradient of a single card is extremely large, it will cause a high video memory occupancy. In addition, this solution needs to wait until all hardware devices have completed the calculation of the corresponding complete gradient of the single card before aggregating the global gradient and updating the model parameters based on the global gradient, which is inefficient.
[0027] To facilitate understanding of the solution of the present invention, the following explanations are given for the gradient-related terms involved in the solution: Single-card full gradient: The gradient is calculated based on the reverse calculation of the batch training data on each hardware device.
[0028] Global gradient: The gradient obtained by aggregating the complete gradients of single cards on each hardware device.
[0029] Single card local gradient: the gradient after the single card complete gradient is split, that is, the single card local gradient can be understood as a part of the single card complete gradient. Figure 2 As shown, in a 2-card cluster, the local gradient of a single card is half of the complete gradient of a single card.
[0030] Single-card global gradient: The gradient obtained by aggregating the local gradients of single cards of each hardware device.
[0031] Figure 1 It is a flow chart of the model training method provided by the present invention, such as Figure 1 As shown, the method includes step 110, step 120, step 130 and step 140.
[0032] Step 110, during the reverse calculation of the model, on each chip, based on the corresponding current training data on each chip, the single-card local gradient of the current training data on each chip is calculated, and the current training data is part of the training data in the batch training data on each chip.
[0033] Generally, model training includes two steps: forward calculation and reverse calculation. Forward calculation refers to the step-by-step calculation and transmission of data through each layer of the model according to the input data until the final prediction result is output; reverse calculation refers to the calculation of the gradient of the model according to the prediction result obtained by the forward calculation, and the update of the model parameters according to the gradient until the pre-set training goal is reached (such as the number of training times reaches the preset number), and the trained model is obtained. Among them, the gradient refers to the partial derivative of the loss function with respect to the model parameters, and the loss function represents the difference between the prediction result and the true label.
[0034] The embodiment of the present invention mainly improves the reverse calculation of the model, reduces the memory usage, reduces the amount of communication data and improves the training speed. Specifically, in order to accelerate model training, the embodiment of the present invention can divide the original training data under the current iteration into multiple batches (i.e., multiple batches), and distribute the training data of each batch to the corresponding chip, that is, each chip corresponds to 1 batch of training data, so that each chip can perform parallel calculation to accelerate model training. Among them, the current iteration refers to the iteration round that the model is currently in when iterative training is performed.
[0035] Furthermore, on each chip, based on the current training data corresponding to each chip, a current prediction result corresponding to the current training data on each chip is obtained, and a single-card local gradient on each chip is calculated based on the current prediction result.
[0036] It should be noted that each chip calculates the local gradient of a single card of the current training data, and the current training data is part of the training data in the batch training data on each chip, and the local gradient of a single card calculated is part of the complete gradient of a single card. Compared with the complete gradient of a single card calculated by each chip based on the batch training data in the related art, the cache space occupied by the local gradient of a single card is smaller, that is, the memory usage is reduced.
[0037] Among them, the above-mentioned chip can be an artificial intelligence chip, and the artificial intelligence chip can include a graphics processing unit (GPU), a general-purpose graphics processing unit (GPGPU), a tensor processing unit (TPU), etc.
[0038] Optionally, if there are N chips, the current training data may be 1 / N batch training data. If the size of the cache space occupied by the complete gradient of a single card calculated by each chip in the related art is M, the size of the cache space occupied by the local gradient of a single card calculated by each chip in the embodiment of the present invention is M / N, which greatly reduces the memory usage.
[0039] Step 120: Use any chip as a target chip, and synchronize the single-card local gradients on the remaining chips to the target chip.
[0040] Step 130: On the target chip, determine the single-card global gradient of the model based on the single-card local gradients of all chips.
[0041] Specifically, after each chip calculates the corresponding single-card local gradient, any chip is used as the target chip, and the single-card local gradients on the remaining chips except the target chip are synchronized to the target chip, so that the target chip has the single-card local gradients of all chips. On this basis, the target chip can aggregate the single-card local gradients of all chips to obtain the single-card global gradient of the model.
[0042] For example, if there are two chips (i.e., chip 1 and chip 2), chip 2 can be used as the target chip first, and the single-card local gradient on chip 1 can be synchronized to chip 2. Then chip 2 can aggregate the single-card local gradient on chip 1 and the single-card local gradient on chip 2 to obtain the single-card global gradient.
[0043] It should be noted that the embodiment of the present invention synchronizes the local gradient of a single card on the remaining chips to the target chip, which can be understood as a Reduce operation. In the subsequent step 140, the embodiment of the present invention updates the model parameters on the target chip based on the global gradient of the single card, and there is no need to update the parameters on other chips. Therefore, the embodiment of the present invention only needs to perform the Reduce operation on the target chip, and the remaining chips do not need to perform the Reduce operation, thus avoiding the problem of large communication volume caused by the Reduce operation of all chips. In addition, when performing the Reduce operation, the communication transmission is the local gradient of the single card of the remaining chips, which is less than the complete gradient of the single card transmitted by the Reduce operation in the related art, and the communication volume is small.
[0044] Step 140: Update the model parameters on the target chip based on the single-card global gradient.
[0045] Specifically, the single-card global gradient is used to indicate the descent direction of the model's loss function under the current model parameters (that is, the direction in which the loss function is minimized), and the goal of model training is to minimize the loss function by adjusting the model parameters. Based on the single-card global gradient, it can be determined how to adjust the model parameters to minimize the loss function.
[0046] The model training method provided by the embodiment of the present invention, since the current training data is part of the batch training data, the calculated single-card local gradient is a part of the single-card complete gradient. Compared with the single-card complete gradient calculated by each chip based on the batch training data in the related art, the cache space occupied by the single-card local gradient is smaller, that is, the video memory occupancy is reduced. In addition, the embodiment of the present invention only needs to perform the Reduce operation on the target chip, and the remaining chips do not need to perform the Reduce operation, avoiding the problem of large communication volume caused by the Reduce operation of all chips. When performing the Reduce operation, the communication transmission is the single-card local gradient of the remaining chips, and the communication volume is smaller than the single-card complete gradient of the Reduce operation in the related art. In addition, since the embodiment of the present invention currently only needs to update the model parameters on the target chip, and does not need to update the model parameters on other chips, it is impossible to perform the Scatter operation on the single-card global gradient, that is, the embodiment of the present invention reduces the Scatter operation, thereby reducing the amount of communication data.
[0047] As an optional embodiment, the above model can be a text generation model, a text-image model, a computer vision model (such as an image classification model, a target detection model, a semantic segmentation model, etc.), etc. Taking the text generation model as an example, the current training data can be a sample text. After the model is trained using the above embodiment method, a text generation model is obtained, and the text generation model can obtain corresponding output text based on the input text.
[0048] Based on the above embodiment, based on the current training data corresponding to each chip, the single-card local gradient of the current training data on each chip is calculated, which also includes: Allocate temporary cache to the remaining chips, and use the temporary cache to store the local gradients of the single cards of the remaining chips.
[0049] Specifically, the temporary cache is used to store the local gradients of a single card calculated by the remaining chips, that is, after the remaining chips have calculated the local sub-gradients, they temporarily store them in the temporary cache. During the reverse calculation of the model, the gradients already exist on the target chip, that is, the gradient cache space already exists on the target chip, and thus the target chip does not need to allocate a temporary cache to store the gradients. Instead, it only needs to allocate a temporary cache for the remaining chips. The temporary cache can be a temporary buffer.
[0050] Based on any of the above embodiments, the local gradients of the single cards on the remaining chips are synchronized to the target chip, and then the method further includes: releasing the temporary caches of the remaining chips.
[0051] Specifically, after the local gradients of the single cards on the remaining chips are synchronized to the target chip, the target chip has the local gradients of the single cards of all chips. If the temporary cache is still occupied on the remaining chips, unnecessary memory usage will be caused. In this regard, the embodiment of the present invention releases the temporary cache of the remaining chips after synchronizing the local gradients of the single cards on the remaining chips to the target chip.
[0052] Optionally, after synchronizing the single-card local gradients on the remaining chips to the target chip, the target chip may send a synchronization success signal to the remaining chips. After receiving the synchronization success signal, the remaining chips may release corresponding temporary caches to avoid unnecessary memory usage.
[0053] Based on any of the above embodiments, synchronizing the local gradients of the single cards on the remaining chips to the target chip includes: The protocol communication operation is performed on the target chip to synchronize the local gradients of the single cards on the remaining chips to the target chip.
[0054] Optionally, the protocol communication operation (i.e., Reduce operation) refers to the target chip initiating a protocol request and specifying the data to be collected (i.e., the single-card local gradients on the remaining chips) and how to aggregate them (e.g., sum, average, etc.). After receiving the protocol request initiated by the target chip, the remaining chips send their respective single-card local gradients to the target chip. The target chip receives all single-card local gradients and aggregates all single-card local gradients into the single-card global gradient of the model.
[0055] Based on any of the above embodiments, determining the single card global gradient of the model, and then further comprising: The previous training data is used as the current training data, and any chip among the remaining chips is used as the target chip; Return to execute based on the corresponding current training data on each chip, calculate the single-card local gradient of the current training data on each chip, synchronize the single-card local gradients on the remaining chips to the target chip, and determine the single-card global gradient of the model on the target chip based on the single-card local gradients of all chips.
[0056] Specifically, after determining the single-card global gradient of the model, the cache space on each chip used to store the single-card local gradient can be released. In addition, after determining the single-card global gradient of the model, the model parameters need to be updated on the target chip. In order to maximize parallel computing, when updating the model parameters on the target chip, the embodiment of the present invention can synchronously perform Reduce operations on the remaining chips.
[0057] That is, the embodiment of the present invention uses the last training data of each chip as the current training data, and uses any chip among the remaining chips as the target chip, and returns to execute steps 110 to 130.
[0058] When the model parameters are updated on the target chip, the embodiment of the present invention can synchronously execute the Reduce operation on the remaining chips, that is, the gradient calculation and parameter update can be implemented in parallel, thereby improving the training speed of the model.
[0059] in, Figure 2 It is a parallel schematic diagram of gradient calculation and parameter updating provided by the present invention, such as Figure 2 As shown, assuming that the chip includes GPU1 and GPU2, the batch training data assigned to GPU1 is X1, and the batch training data assigned to GPU2 is X2. First, the single-card complete gradient of the model is split, GPU1 maintains half of the gradient in the single-card complete gradient (i.e., the single-card local gradient), which is represented by G11, and GPU2 maintains the other half of the gradient in the single-card complete gradient (i.e., the single-card local gradient), which is represented by G22, that is, G11 and G12 together constitute the single-card complete gradient on GPU1; similarly, G21 and G22 together constitute the single-card complete gradient on GPU2.
[0060] Secondly, when starting the reverse calculation, a temporary cache is requested on GPU1. Because GPU1 only maintains the first half of the gradient G11, a temporary cache for the second half of the gradient G12 needs to be created. At this time, GPU1 and GPU2 calculate the reverse gradient in parallel to obtain G12 and G22 respectively. At this point, the second half of the gradient on GPU1 and GPU2 are calculated and the parameter update operation can be performed immediately. The specific steps for parameter update are: Reduce G12 and G22 on GPU2 to obtain the single-card global gradient G22', and directly update G22' to the model parameters maintained by GPU2.
[0061] In addition, when the model parameters maintained by GPU2 are updated based on the single-card global gradient G22' on GPU2, GPU1 and GPU2 synchronously start to calculate the other half of the gradient. As mentioned above, only G11 is maintained on GPU1, and the gradient that needs to be calculated at this time is G11, so there is no need to create a temporary cache. Since GPU2 only maintains the second half of the gradient G22, but the first half of the gradient G21 needs to be calculated at this time, a temporary cache is created at this time to maintain G21. Then, when G11 is calculated on GPU1 and G21 is calculated on GPU2 (that is, the calculation of the first half of the gradient is completed), G11 and G21 are Reduced on GPU1 to obtain the single-card global gradient G11', and the model parameters maintained by GPU1 are updated on GPU1 based on the single-card global gradient G11'.
[0062] Based on any of the above embodiments, the method further includes: If the target chip is the last chip, after updating the model parameters on the target chip, the model training of the current iteration is obtained, and the model training of the next iteration is entered.
[0063] Specifically, if the target chip is the last chip, after updating the model parameters on the target chip, the aggregation of all gradients and the update of model parameters in the current iteration are completed, and the model training of the current iteration can be obtained. Then, the model training of the next iteration can be entered, and after multiple iterations of training, the trained model is finally obtained.
[0064] The model training device provided by the present invention is described below. The model training device described below and the model training method described above can be referenced to each other.
[0065] Based on any of the above embodiments, Figure 3 It is a structural schematic diagram of the model training device provided by the present invention, such as Figure 3 As shown, the device comprises: The calculation unit 310 is used to calculate the single-card local gradient of the current training data on each chip based on the current training data corresponding to each chip during the reverse calculation of the model, where the current training data is part of the batch training data on each chip; A synchronization unit 320 is used to take any chip as a target chip and synchronize the single-card local gradients on the remaining chips to the target chip; A determination unit 330 is used to determine a single-card global gradient of the model based on the single-card local gradients of all chips on the target chip; The updating unit 340 is used to update the model parameters on the target chip based on the single-card global gradient.
[0066] The model training device provided by the embodiment of the present invention has a partial gradient, and the local gradient of the single card calculated is a partial gradient. Compared with the complete gradient of the single card calculated by each chip based on the batch training data in the related art, the cache space occupied by the local gradient of the single card is smaller, that is, the video memory occupancy is reduced. In addition, the embodiment of the present invention only needs to perform the Reduce operation on the target chip, and the other chips do not need to perform the Reduce operation, avoiding the problem of large communication volume caused by the Reduce operation of all chips. When performing the Reduce operation, the communication transmission is the local gradient of the single card of the other chips, which is smaller than the complete gradient of the single card communicated and transmitted by the Reduce operation in the related art.
[0067] Based on any of the above embodiments, based on the current training data corresponding to each chip, the single-card local gradient of the current training data on each chip is calculated, and the above also includes: Allocate temporary cache to the remaining chips, and use the temporary cache to store the local gradients of the single cards of the remaining chips.
[0068] Based on any of the above embodiments, the local gradients of the single cards on the remaining chips are synchronized to the target chip, and then the method further includes: releasing the temporary caches of the remaining chips.
[0069] Based on any of the above embodiments, synchronizing the local gradients of the single cards on the remaining chips to the target chip includes: The protocol communication operation is performed on the target chip to synchronize the local gradients of the single cards on the remaining chips to the target chip.
[0070] Based on any of the above embodiments, determining the single card global gradient of the model, and then further comprising: The previous training data is used as the current training data, and any chip among the remaining chips is used as the target chip; Return to execute based on the corresponding current training data on each chip, calculate the single-card local gradient of the current training data on each chip, synchronize the single-card local gradients on the remaining chips to the target chip, and determine the single-card global gradient of the model on the target chip based on the single-card local gradients of all chips.
[0071] Based on any of the above embodiments, it also includes: If the target chip is the last chip, after updating the model parameters on the target chip, the model training of the current iteration is completed and the model training of the next iteration is entered.
[0072] Figure 4 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the model training method, which includes: when the model is reversely calculated, on each chip, based on the corresponding current training data on each chip, the single card local gradient of the current training data on each chip is calculated, and the current training data is part of the training data in the batch training data on each chip; any chip is used as a target chip, and the single card local gradients on the remaining chips are synchronized to the target chip; on the target chip, based on the single card local gradients of all chips, the single card global gradient of the model is determined; based on the single card global gradient, the model parameters are updated on the target chip.
[0073] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0074] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the model training method provided by the above methods, which method includes: when the model is reversely calculated, on each chip, based on the corresponding current training data on each chip, the single-card local gradient of the current training data on each chip is calculated, and the current training data is part of the training data in the batch training data on each chip; any chip is used as a target chip, and the single-card local gradients on the remaining chips are synchronized to the target chip; on the target chip, based on the single-card local gradients of all chips, the single-card global gradient of the model is determined; based on the single-card global gradient, the model parameters are updated on the target chip.
[0075] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the processor executes the model training method provided by the above methods, the method comprising: during model reverse calculation, on each chip, based on the corresponding current training data on each chip, calculating the single-card local gradient of the current training data on each chip, wherein the current training data is part of the training data in the batch training data on each chip; taking any chip as a target chip, and synchronizing the single-card local gradients on the remaining chips to the target chip; on the target chip, determining the single-card global gradient of the model based on the single-card local gradients of all chips; and updating the model parameters on the target chip based on the single-card global gradient.
[0076] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0077] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0078] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A model training method, characterized in that: include: During the reverse calculation of the model, on each chip, based on the current training data corresponding to each chip, the single-card local gradient of the current training data on each chip is calculated, where the current training data is part of the batch training data on each chip; Take any chip as a target chip, and synchronize the single-card local gradients on the remaining chips to the target chip; On the target chip, determining a single-card global gradient of the model based on the single-card local gradients of all chips; Based on the single-card global gradient, model parameters are updated on the target chip.
2. The model training method according to claim 1, characterized in that: The method further includes calculating the single-card local gradient of the current training data on each chip based on the current training data corresponding to each chip: Allocate a temporary cache to the remaining chips, where the temporary cache is used to store the single-card local gradients of the remaining chips.
3. The model training method according to claim 2, characterized in that: The method further comprises: synchronizing the local gradients of the single cards on the remaining chips to the target chip, and then releasing the temporary caches of the remaining chips.
4. The model training method according to any one of claims 1 to 3, characterized in that: The step of synchronizing the local gradients of the single cards on the remaining chips to the target chip includes: A protocol communication operation is performed on the target chip to synchronize the single-card local gradients on the remaining chips to the target chip.
5. The model training method according to any one of claims 1 to 3, characterized in that: The single-card global gradient of the determination model further includes: Using the previous training data as the current training data, and using any chip among the remaining chips as the target chip; Return to execute based on the current training data corresponding to each chip, calculate the single-card local gradient of the current training data on each chip, synchronize the single-card local gradients on the remaining chips to the target chip, and determine the single-card global gradient of the model on the target chip based on the single-card local gradients of all chips.
6. The model training method according to any one of claims 1 to 3, characterized in that: The method further comprises: If the target chip is the last chip, after updating the model parameters on the target chip, the model training of the current iteration is completed, and the model training of the next iteration is entered.
7. A model training device, characterized in that: include: A calculation unit, used for calculating, on each chip, a single-card local gradient of current training data on each chip based on current training data corresponding to each chip during reverse calculation of the model, wherein the current training data is part of the training data in the batch training data on each chip; A synchronization unit, used to take any chip as a target chip and synchronize the single-card local gradients on the remaining chips to the target chip; A determination unit, configured to determine a single-card global gradient of the model based on the single-card local gradients of all chips on the target chip; An updating unit is used to update model parameters on the target chip based on the single-card global gradient.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the model training method as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the model training method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, it implements the model training method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Model parameter updating method and device, equipment, storage medium and program product
CN117035045A
Model training method and device based on distributed parallel computing
CN117436514A
Small-gradient transmission neural network training method based on data parallelism
CN118014036A
Server and method for business model design for startup
KR1020250140860A
