Distributed training system, method and device, medium and computer program product
By combining model parallelism and data parallelism in a distributed system, the gradient data synchronization of the convolutional neural network is optimized, which solves the problem of low gradient synchronization communication efficiency and improves the training efficiency and effect.
Patent Information
- Application Number
- CN202410853489.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-06-28
AI Technical Summary
In the existing distributed convolutional neural network training method, the gradient data synchronization communication efficiency is low, which affects the training efficiency.
Using a method that combines model parallelism and data parallelism, through the ring connection between the first computing node and the second computing node, the convolutional layer and the fully connected layer are trained respectively, optimizing the gradient data synchronization process, reducing the amount of data transmission, and improving training efficiency. .
It improves the training efficiency and effect of the convolutional neural network, adapts the computing and memory resources required for each layer, and reduces the time required for gradient synchronization.
Smart Images

Figure CN118396048B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a distributed training system, method and device, medium and computer program product. Background Art
[0002] Convolutional Neural Network (CNN) is particularly suitable for processing data with spatial structure, such as images, videos and sequence data. Due to its good feature extraction ability and effective processing ability for image data, it is widely used in image processing, computer vision, natural language processing and other fields. However, in recent years, the model size has become larger and larger. This growth makes efficient model training more important, and distributed training has emerged. There are two methods for distributed model training at present: data parallelism and model parallelism. For the training of CNN models, the most widely used method is data parallelism. In the data parallelism method, a complete network model is stored on each computing node. It divides the training data set into multiple small batches, trains on multiple computing nodes simultaneously, then synchronizes the gradient data between the computing nodes, and finally uses the synchronized gradient data to update the shared model parameters. As the model scale and the scale of distributed systems become larger and larger, the proportion of gradient data synchronization communication in synchronous data parallel training in the entire training process is increasing, resulting in low synchronization efficiency between computing nodes, which in turn affects the training efficiency of convolutional neural networks.
[0003] Therefore, how to improve the training efficiency of convolutional neural networks is a technical problem that technicians in this field need to solve. Summary of the invention
[0004] The object of the present invention is to provide a distributed training method, apparatus and equipment, storage medium and computer program product, which improve the training efficiency of convolutional neural networks.
[0005] To achieve the above object, the present invention provides a distributed training system, comprising I first computing nodes and J second computing nodes, wherein the first computing node comprises a local memory, the second computing node comprises a local memory and an extended memory expanded by a computing fast link memory expander, the I first computing nodes are connected in a ring, the J second computing nodes are connected in a ring, the i-th first computing node is connected to the j-th second computing node, Second computing node connection, n= ;
[0006] The first computing node and the connected second computing node train a convolutional neural network in a model parallel manner, wherein the convolutional neural network includes multiple convolutional layers and multiple fully connected layers connected in sequence, and I first computing nodes train the convolutional layers in the convolutional neural network in a data parallel manner. The first computing node sends activation data of the last convolutional layer obtained by forward calculation to the connected second computing node, and the gradient data of the convolutional layer is synchronized between the I first computing nodes. The J second computing nodes train the fully connected layer in the convolutional neural network in a data parallel manner, and the second computing node sends the synchronized gradient data of the last convolutional layer obtained by reverse calculation to the connected first computing node, and the J second computing nodes synchronize the gradient data of the fully connected layer and the gradient data of the last convolutional layer.
[0007] Wherein, the first computing node includes a processor and a local memory connected to the processor;
[0008] The second computing node includes a processor, a local memory connected to the processor, a root complex connected to the processor, a computing fast link memory expander connected to the root complex, and an extended memory connected to the computing fast link memory expander.
[0009] Among them, the process of the first computing node training the convolutional layer in the convolutional neural network includes: performing forward calculation on each convolutional layer in the convolutional neural network based on local training data to obtain activation data of the last convolutional layer, and sending the activation data to the corresponding second computing node; when receiving the average gradient data of the last convolutional layer calculated by the corresponding second computing node, performing reverse calculation on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain gradient data of each convolutional layer except the last convolutional layer; wherein, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
[0010] The process of the second computing node training the fully connected layer in the convolutional neural network includes:
[0011] Receive the activation data of the last convolutional layer sent by the corresponding first computing node, perform forward calculation on each fully connected layer in the convolutional neural network based on the activation data and local training data, and perform reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after obtaining the gradient data of each fully connected layer or the last convolutional layer, synchronize the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes to obtain average gradient data, and update the parameters of the fully connected layer or the last convolutional layer based on the average gradient data; send the average gradient data of the last convolutional layer to the first computing node.
[0012] To achieve the above object, the present invention provides a distributed training method, which is applied to a first computing node in the above distributed training system, and the method includes:
[0013] Acquire local training data, perform forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtain activation data of the last convolutional layer, and send the activation data to the corresponding second computing node;
[0014] When receiving the average gradient data of the last convolutional layer calculated by the corresponding second computing node, reversely calculating each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer;
[0015] Among them, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
[0016] Among them, obtaining local training data includes:
[0017] The main thread obtains local training data and starts the auxiliary thread;
[0018] Accordingly, forward calculation is performed on each convolutional layer in the convolutional neural network based on the local training data to obtain activation data of the last convolutional layer, and the activation data is sent to the corresponding second computing node, including:
[0019] The main thread performs forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtains activation data of the last convolutional layer, and sends the activation data to the corresponding second computing node;
[0020] Correspondingly, when the average gradient data of the last convolutional layer calculated by the corresponding second computing node is received, each convolutional layer except the last convolutional layer in the convolutional neural network is reversely calculated based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer, including:
[0021] When the main thread receives the average gradient data of the last convolutional layer calculated by the corresponding second computing node, reverse calculation is performed on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer;
[0022] Correspondingly, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer, including:
[0023] After obtaining the gradient data of each convolution layer, the auxiliary thread synchronizes the gradient data of the convolution layer calculated by I first computing nodes to obtain the average gradient data of the convolution layer, and updates the parameters of the convolution layer based on the average gradient data of the convolution layer.
[0024] Among them, after obtaining the gradient data of each convolution layer, it also includes:
[0025] The main thread sets the first flag bit of the convolutional layer to a first preset value;
[0026] Correspondingly, the auxiliary thread synchronizes the gradient data of the convolution layer calculated by the I first computing nodes to obtain the average gradient data of the convolution layer, and updates the parameters of the convolution layer based on the average gradient data of the convolution layer, including:
[0027] When the auxiliary thread detects that the first flag bit of the convolution layer is a first preset value, the first flag bit is set to a second preset value, the second flag bit of the convolution layer is set to the second preset value, the gradient data of the convolution layer calculated by I first computing nodes is synchronized to obtain the average gradient data of the convolution layer, the parameters of the convolution layer are updated based on the average gradient data of the convolution layer, and the second flag bit of the convolution layer is set to the first preset value.
[0028] Among them, it also includes:
[0029] When the main thread detects that the second flag bit of the first convolutional layer is a first preset value, determining whether a training end condition is met;
[0030] If yes, the training is considered complete;
[0031] If not, the process re-enters the step of performing forward calculation on each convolutional layer in the convolutional neural network based on the local training data.
[0032] To achieve the above object, the present invention provides a distributed training method, which is applied to the second computing node in the above distributed training system, and the method includes:
[0033] Receive the activation data of the last convolutional layer sent by the corresponding first computing node, perform forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and perform reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after each gradient data of a fully connected layer or the last convolutional layer is obtained, synchronize the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes to obtain average gradient data, and update the parameters of the fully connected layer or the last convolutional layer based on the average gradient data;
[0034] The average gradient data of the last convolutional layer is sent to the first computing node.
[0035] Among them, obtaining local training data includes:
[0036] Start k main threads, each of which starts a corresponding auxiliary thread; wherein k is the number of first computing nodes connected to the second computing node;
[0037] Correspondingly, forward calculation is performed on each fully connected layer in the convolutional neural network based on the activation data, and reverse calculation is performed on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer, including:
[0038] The main thread performs forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and performs reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer;
[0039] Correspondingly, after each gradient data of a fully connected layer or the last convolutional layer is obtained, the gradient data of the fully connected layer or the last convolutional layer calculated by the J second computing nodes are synchronized to obtain average gradient data, and the parameters of the fully connected layer or the last convolutional layer are updated based on the average gradient data, including:
[0040] After obtaining the gradient data of each fully connected layer or the last convolutional layer, each auxiliary thread synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain a local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data; wherein the target auxiliary thread is one of the k auxiliary threads in the second computing node.
[0041] Among them, after obtaining the gradient data of each fully connected layer or the last convolutional layer, it also includes:
[0042] The main thread sets the first flag bit of the fully connected layer or the last convolutional layer to a first preset value;
[0043] Correspondingly, each of the auxiliary threads synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain a local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, including:
[0044] When each of the auxiliary threads detects that the first flag bit of the fully connected layer or the last convolutional layer is a first preset value, the first flag bit is set to a second preset value, the second flag bit of the fully connected layer or the last convolutional layer is set to the second preset value, the k gradient data of the fully connected layer or the last convolutional layer calculated locally are synchronized to obtain a local average gradient, the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, and sets the second flag bit of the fully connected layer or the last convolutional layer to the first preset value.
[0045] Among them, it also includes:
[0046] When the main thread detects that the second flag bit of the last convolutional layer is a first preset value, determining whether a training end condition is met;
[0047] If yes, the training is considered complete;
[0048] If not, re-enter the step of receiving the activation data of the last convolutional layer sent by the corresponding first computing node.
[0049] To achieve the above object, the present invention provides an electronic device, comprising:
[0050] Memory for storing computer programs;
[0051] A processor is used to implement the steps of the above-mentioned distributed training method when executing the computer program.
[0052] To achieve the above objectives, the present invention provides a non-volatile storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned distributed training method are implemented.
[0053] To achieve the above objectives, the present invention provides a computer program product, including a computer program, which implements the steps of the above distributed training method when executed by a processor.
[0054] It can be seen from the above scheme that a distributed training system provided by the present invention includes I first computing nodes and J second computing nodes, the first computing node includes a local memory, the second computing node includes a local memory and an extended memory expanded by a computing fast link memory expander, the I first computing nodes are connected in a ring, the J second computing nodes are connected in a ring, the i-th first computing node is connected to the i-th second computing node Second computing node connection, n= The first computing node and the connected second computing node train a convolutional neural network in a model parallel manner, wherein the convolutional neural network includes a plurality of convolutional layers and a plurality of fully connected layers connected in sequence, and I first computing nodes train the convolutional layers in the convolutional neural network in a data parallel manner, and the first computing node sends the activation data of the last convolutional layer obtained by forward calculation to the connected second computing node, and the gradient data of the convolutional layer is synchronized between the I first computing nodes, and the J second computing nodes train the fully connected layer in the convolutional neural network in a data parallel manner, and the second computing node sends the synchronized gradient data of the last convolutional layer obtained by reverse calculation to the connected first computing node, and the J second computing nodes synchronize the gradient data of the fully connected layer and / or the gradient data of the last convolutional layer.
[0055] The beneficial effects of the present invention are as follows: the distributed training system provided by the present invention uses a first computing node with a large amount of computing resources and a small amount of memory resources to train the convolutional layer, and uses a second computing node with a small amount of computing resources and a large amount of memory resources to train the fully connected layer, which is adapted to the training resources required for each layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the present invention, the data transmitted between the first computing node and the second computing node are the activation data and synchronized gradient data of the last convolutional layer, and the data transmitted between each first computing node and each second computing node are the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network. The present invention also discloses a distributed training device, an electronic device, a non-volatile storage medium and a computer program product, which can also achieve the above-mentioned technical effects.
[0056] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. The drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific implementation methods, they are used to explain the present disclosure, but do not constitute a limitation to the present disclosure. In the drawings:
[0058] Figure 1 A schematic diagram of the training process on each computing node in the related art;
[0059] Figure 2 is a structural diagram of a distributed training system according to an exemplary embodiment;
[0060] Figure 3 is an architecture diagram of a first computing node according to an exemplary embodiment;
[0061] Figure 4 is an architecture diagram of a second computing node according to an exemplary embodiment;
[0062] Figure 5 is a flow chart of a distributed training method according to an exemplary embodiment;
[0063] Figure 6is a schematic diagram of a training scheduling process in a first computing node according to an exemplary embodiment;
[0064] Figure 7 is a flow chart of another distributed training method according to an exemplary embodiment;
[0065] Figure 8 is a schematic diagram of a training scheduling process in a second computing node according to an exemplary embodiment;
[0066] Fig. 9 The figure is a structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0067] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments in 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. In addition, in the embodiments of the present invention, "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0068] In related technologies, CNN model distributed training solutions mostly use data parallel methods, using PS architecture (Parameter Server Architecture) or decentralized architecture to synchronize model parameters of each computing node in the training cluster. The training process on each computing node is as follows: Figure 1 The specific description is as follows:
[0069] Step 1: Each computing node obtains input training data, performs forward calculations, and obtains the loss value;
[0070] Step 2: Each computing node performs reverse calculation to obtain the gradient;
[0071] Step 3: Use PS architecture or decentralized architecture (such as ring architecture) to synchronize data of each computing node, obtain the gradient mean, and use the gradient mean to update the model parameters:
[0072] Step 4: Determine whether the training is finished. If so, end the process. If not, return to step 1 and start the next iterative training.
[0073] Whether using the PS architecture or the decentralized architecture, the gradient data synchronization process is inevitable. The gradient data synchronization process here is the process of aggregating and averaging the data of the entire network model. When the model scale is large, gradient data synchronization will affect the training efficiency of the convolutional neural network.
[0074] Therefore, in the present invention, a first computing node with a large amount of computing resources and a small amount of memory resources is used to train the convolutional layer, and a second computing node with a small amount of computing resources and a large amount of memory resources is used to train the fully connected layer, which is adapted to the training resources required for each layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the present invention, the data transmitted between the first computing node and the second computing node is the activation data of the last convolutional layer and the synchronized gradient data, and the data transmitted between each first computing node and each second computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the efficiency of gradient synchronization, thereby improving the training efficiency of the convolutional neural network.
[0075] This embodiment discloses a distributed training system. Figure 2 As shown, it includes I first computing nodes and J second computing nodes, the first computing node includes a local memory, the second computing node includes a local memory and an extended memory expanded by a computing fast link memory expander, the I first computing nodes are connected in a ring, the J second computing nodes are connected in a ring, and the i-th first computing node is connected to the i-th second computing node. Second computing node connection, n= ;
[0076] The first computing node and the connected second computing node train a convolutional neural network in a model parallel manner, wherein the convolutional neural network includes multiple convolutional layers and multiple fully connected layers connected in sequence, and I first computing nodes train the convolutional layers in the convolutional neural network in a data parallel manner. The first computing node sends activation data of the last convolutional layer obtained by forward calculation to the connected second computing node, and the gradient data of the convolutional layer is synchronized between the I first computing nodes. The J second computing nodes train the fully connected layer in the convolutional neural network in a data parallel manner, and the second computing node sends the synchronized gradient data of the last convolutional layer obtained by reverse calculation to the connected first computing node, and the J second computing nodes synchronize the gradient data of the fully connected layer and the gradient data of the last convolutional layer.
[0077] In this embodiment, the convolutional neural network can be applied to tasks such as image classification, speech classification, and video classification, and the corresponding training data can be image data, speech data, and video data.
[0078] In this embodiment, the first computing node uses an ordinary computing system without expanded memory, and the second computing node uses a computing system with expanded memory based on CXL (Compute Express Link) technology. The second computing node and the first computing node are in a one-to-many relationship, that is, the second computing node is directly connected to multiple first computing nodes through Ethernet. Each second computing node is connected to each other through Ethernet to form a ring, and each first computing node is also connected to each other through Ethernet to form a ring. When building a distributed training system, first determine the number of first computing nodes I and the number of second computing nodes J, and then divide the first computing nodes into J groups, and the first computing nodes in the same group are connected to the same second computing node.
[0079] As a feasible implementation, the first computing node includes a processor and a local memory connected to the processor; the second computing node includes a processor, a local memory connected to the processor, a root complex connected to the processor, a computing fast link memory expander connected to the root complex, and an extended memory connected to the computing fast link memory expander.
[0080] The architecture of the first computing node is as follows Figure 3 As shown, the architecture of the second computing node includes a processor and a local memory connected to the processor. Figure 4 As shown, in addition to the processor and local memory, a large block of extended memory is extended through the root complex and the compute fast link memory expander.
[0081] Convolutional neural networks are mainly composed of two basic building blocks: convolutional layers (CONV) and fully connected layers (FC). Among them, the CONV layer is essentially a small filter that extracts features by convolution of the training data. They usually have a very small number of parameters (<10%), but require a large amount of calculation (>90%), that is, the convolution layer requires a small amount of memory resources and a large amount of computing resources. The FC layer has full connectivity between layers to perform high-level reasoning. They usually use most of the parameters in the model, but only require a small amount of calculation, that is, the FC layer requires a large amount of memory resources and a small amount of computing resources. In view of the different characteristics of these two building blocks, this embodiment uses different training strategies to train them separately. Since each first computing node in the cluster has the complete computing resources of the processor and the local memory that is not large enough but sufficient, this is just adapted to the convolution layer training that requires a large amount of computing resources and less memory resources. Therefore, the first computing node in the cluster is used to train each convolution layer, and each first computing node stores a complete set of CONVs networks, and each first computing node is trained in a data parallel manner. Since each second computing node in the cluster has a massive amount of extended memory, which is just compatible with the large amount of memory resources and less memory resources required for fully connected layer training, the second computing nodes in the cluster are used to train each fully connected FCs layer. Each second computing node stores k sets (k is the number of first computing nodes corresponding to the second computing node) of the last convolution layer and the complete FCs network. These k sets of networks share the computing resources and massive memory resources of the processor. Each set of networks corresponds to a first computing node connected to it. The second computing nodes are trained in a data parallel manner, while the second computing nodes and the first computing nodes use a model parallel training strategy.
[0082] As a feasible implementation manner, the process of the first computing node training the convolutional layer in the convolutional neural network includes: performing forward calculation on each convolutional layer in the convolutional neural network based on local training data to obtain activation data of the last convolutional layer, and sending the activation data to the corresponding second computing node; when receiving the average gradient data of the last convolutional layer calculated by the corresponding second computing node, performing reverse calculation on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain gradient data of each convolutional layer except the last convolutional layer; wherein, after obtaining the gradient data of each convolutional layer, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
[0083] In the specific implementation, a process is started in each first computing node, and each process has two threads. The main thread is responsible for the forward and reverse calculation of each convolution layer and the data transmission between the upper and lower nodes, and the auxiliary thread is used for the gradient data synchronization of each convolution layer between each first computing node. In each iteration, the training scheduling process in the first computing node is: each first computing node obtains the training data to perform forward calculations on each layer of the CONVs network, and sends the activation data of the last convolution layer to the corresponding process in the corresponding second computing node after obtaining it. Then wait for the average gradient data of the last convolution layer from the corresponding process of the second computing node. Once received, immediately start to perform reverse calculations of each convolution layer except the last convolution layer layer by layer. Each time a layer of calculation results is obtained, notify the auxiliary thread to start executing the global gradient synchronization operation between each first computing node, and at the same time, the main thread starts to perform the reverse calculation of the next convolution layer until all the reverse calculations and gradient synchronization of all convolution layers are completed. Here, the calculation operation and communication operation are performed simultaneously in different threads. The main thread is used for forward calculation and reverse calculation, and the auxiliary thread is used for the communication of gradient data.
[0084] As a feasible implementation manner, the process of the second computing node training the fully connected layer in the convolutional neural network includes: receiving the activation data of the last convolutional layer sent by the corresponding first computing node, performing forward calculations on each fully connected layer in the convolutional neural network based on the activation data and local training data, and performing reverse calculations on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after obtaining the gradient data of each fully connected layer or the last convolutional layer, the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes are synchronized to obtain average gradient data, and the parameters of the fully connected layer or the last convolutional layer are updated based on the average gradient data; and the average gradient data of the last convolutional layer is sent to the first computing node.
[0085] In a specific implementation, k processes are started in each second computing node, each process corresponds to a first computing node, and two threads are started in each process: the main thread is used to calculate the forward and reverse calculations of each fully connected layer and the communication with the second computing node, and the auxiliary thread is used to calculate the local gradient synchronization of each fully connected layer and the last convolutional layer and the global gradient synchronization between each second computing node. In each iteration, the training scheduling process in each process in the second computing node is as follows: in each process of each second computing node, the main thread of each process waits for the activation data of the last convolutional layer, and after receiving the data, notifies the main thread to perform the forward calculation process of each fully connected layer (the forward calculation does not include the last convolutional layer), the reverse calculation process of each fully connected layer and the last convolutional layer, and obtains the gradient data of each fully connected layer and the last convolutional layer. After obtaining the gradient data of each layer of the network, the auxiliary thread is notified to start the gradient synchronization operation. Each auxiliary thread first performs local gradient synchronization to obtain the local average gradient, and then the auxiliary thread in the target process on each second computing node performs the global gradient synchronization operation to obtain the global gradient data and then broadcast it to other local processes. While the communication threads are communicating, the main threads continue to perform reverse calculations on the next layer of the network, that is, the calculation and communication operations are performed simultaneously. After the main thread calculates the average gradient data of the last convolutional layer, it sends it to the corresponding first computing node.
[0086] The entire distributed training process is described as follows:
[0087] Step 1: Each first computing node starts an auxiliary thread and obtains training data to perform forward calculations on each layer of the CONVs network. After obtaining the activation data of the last convolutional layer, it sends it to the corresponding process in the corresponding second computing node;
[0088] Step 2: Each process in the second computing node starts an auxiliary thread and waits to receive the activation data of the last convolutional layer from the corresponding second computing node. Once received, it immediately starts to perform the forward calculation of each layer of the FCs network to obtain the loss value;
[0089] Step 3.1: The main thread of each process in the second computing node performs reverse calculations on each layer of the FCs network and the last convolutional layer layer by layer. Each time a reverse calculation result is obtained, the first flag is set to true, indicating that the reverse calculation of the layer is completed and gradient synchronization can be started. Then, the reverse calculation of the next layer is performed until the reverse calculation of the last convolutional layer is completed. The reverse calculation result of the last convolutional layer, i.e., the average gradient data, is sent to the corresponding first computing node.
[0090] Step 3.2: The auxiliary thread of each process in the second computing node checks whether the first flag is set to true. Once it detects that its value is true, it sets the first flag to false and resets the second flag to false (indicating that the gradient synchronization process of this layer is in progress), and starts to execute the local ring-allreduce gradient synchronization operation to obtain the local average gradient. Then determine whether the current process is the target process. If so, execute the global ring-allreduce gradient synchronization process to obtain the global average gradient, and broadcast it to other processes in the current second computing node, update the model parameters of this layer, and set the second flag to true (indicating that the gradient synchronization of this layer is completed); if the current process is not the target process, wait to receive the global average gradient from the target process, update the model parameters, and set the second flag to true. Repeat step 3.2 to synchronize the gradient data of each layer.
[0091] It should be noted that the above steps 3.1 and 3.2 are the training processes in the main thread and the auxiliary thread in each process in the second computing node, and steps 3.1 and 3.2 are performed simultaneously.
[0092] Step 4: In each process of the second computing node, when the reverse calculation of the last convolutional layer is completed and the second flag is true, it means that the calculation and communication processes in the process have been completed. At this time, it can be determined whether the training end condition is met. If so, the process is terminated; if not, return to step 2 for the next iterative training.
[0093] Step 5.1: The main thread of the first computing node performs reverse calculations on each convolutional layer except the last one. After each calculation result is obtained, the first flag is set to true (indicating that the reverse calculation of this layer is completed and gradient synchronization can be started), and then starts to perform reverse calculations on the next convolutional layer until the reverse calculation of the first convolutional layer is completed.
[0094] Step 5.2: The auxiliary thread of the first computing node periodically checks whether the first flag is true. Once it is true, it immediately resets the first flag to false, sets the second flag to false, and executes the ring-allreduce gradient synchronization process. After obtaining the average gradient data, it uses the average gradient data to update the model parameters of this layer, and sets the second flag to true (indicating that the gradient synchronization process of this layer is completed).
[0095] It should be noted that the above steps 5.1 and 5.2 are the training processes in the main thread and the auxiliary thread in the first computing node, and steps 5.1 and 5.2 are performed simultaneously.
[0096] Step 6: In the first computing node, when the reverse calculation of the first convolutional layer is completed and the second flag is true, it means that the calculation and communication processes in the computing node have been completed. At this time, it can be determined whether the training end condition is met. If so, the process is terminated; if not, return to step 1 for the next iterative training.
[0097] The communication processes in the above training scheduling are: ① the process of executing ring-allreduce between each first computing node to obtain the average gradient data; ② the process of executing ring-allreduce between each process in each second computing node to obtain the local average gradient; ③ the process of executing ring-allreduce between each second computing node to obtain the global average gradient; ④ the process of transmitting the activation data and gradient data of the last convolutional layer between the first computing node and the second computing node. Among them, ④ only transmits the activation data and gradient data of the last convolutional layer, and the data volume is very small; ① performs the synchronization of the gradient data of each convolutional layer, and the data volume is also very small, which will not form a training bottleneck; ② is the data output between each process in the second computing node, and the data transmission rate within the node is very high, and it will not form a training bottleneck; ③ transmits the gradient data of each fully connected layer between each second computing node, and the data volume is large, but because the number of second computing nodes is very small, the time required for gradient synchronization is greatly reduced, and the efficiency of gradient synchronization is improved.
[0098] The distributed training system provided by the embodiment of the present invention uses a first computing node with a large amount of computing resources and a small amount of memory resources to train the convolutional layer, and uses a second computing node with a small amount of computing resources and a large amount of memory resources to train the fully connected layer, which is adapted to the training resources required for each layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the embodiment of the present invention, the data transmitted between the first computing node and the second computing node is the activation data and gradient data of the last convolutional layer, and the data transmitted between each first computing node and each second computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network.
[0099] The embodiment of the present invention discloses a distributed training method, which improves the training efficiency of a convolutional neural network.
[0100] See also Figure 5 , a flowchart of a distributed training method according to an exemplary embodiment is shown, such as Figure 5 As shown, including:
[0101] S101: Acquire local training data, perform forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtain activation data of the last convolutional layer, and send the activation data to the corresponding second computing node;
[0102] The executor of this embodiment is the first computing node in the above-mentioned distributed training system. In the specific implementation, the first computing node starts the main thread, the main thread obtains local training data, and starts the auxiliary thread. The main thread performs forward calculations on each convolutional layer in the convolutional neural network based on the local training data, obtains the activation data of the last convolutional layer, and sends the activation data to the corresponding second computing node.
[0103] S102: When the average gradient data of the last convolutional layer calculated by the corresponding second computing node is received, each convolutional layer except the last convolutional layer in the convolutional neural network is reversely calculated based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer; wherein, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
[0104] In a specific implementation, when the main thread receives the average gradient data of the last convolutional layer calculated by the corresponding second computing node, the convolutional layers except the last convolutional layer in the convolutional neural network are reversely calculated based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer. After obtaining the gradient data of each convolutional layer, the main thread sets the first flag of the convolutional layer to the first preset value, and when the auxiliary thread detects that the first flag of the convolutional layer is the first preset value, the auxiliary thread sets the first flag to the second preset value, sets the second flag of the convolutional layer to the second preset value, synchronizes the gradient data of the convolutional layers calculated by the I first computing nodes to obtain the average gradient data of the convolutional layer, updates the parameters of the convolutional layer based on the average gradient data of the convolutional layer, and sets the second flag of the convolutional layer to the first preset value.
[0105] When the main thread detects that the second flag of the first convolutional layer is the first preset value, it determines whether the training end condition is met; if so, it determines that the training is completed; if not, it re-enters the step of performing forward calculations on each convolutional layer in the convolutional neural network based on the local training data. The training end condition may be reaching a preset number of training times or training accuracy.
[0106] As a feasible implementation, the gradient data of the convolution layer calculated by I first computing nodes are synchronized to obtain average gradient data, including: selecting an initial first computing node, the initial first computing node transmits its own gradient data to the next first computing node connected to the initial first computing node, the next first computing node calculates the average gradient data of the received gradient data and its own gradient data, and continues to transmit the calculated average gradient data to the next first computing node until the initial first computing node calculates the final average gradient data. It can be seen that only one gradient data needs to be transmitted between adjacent first computing nodes, and the transmitted gradient data is small, thereby improving the training efficiency of the entire convolutional neural network.
[0107] As another feasible implementation, the gradient data of the convolution layer calculated by I first computing nodes are synchronized to obtain average gradient data, including: selecting an initial first computing node, the initial first computing node transmits its own gradient data to the next first computing node connected to the initial first computing node, the next first computing node continues to transmit the received gradient data and its own gradient data to the next first computing node, until the last first computing node transmitted, the last first computing node calculates the average gradient data of the gradient data of all first computing nodes. It can be seen that only the last first computing node needs to calculate the average value of the gradient data, and the other first computing nodes only need to perform simple data transmission, which improves the training efficiency of the entire convolutional neural network.
[0108] The training scheduling process in the first computing node in this embodiment is as follows: Figure 6 As shown, the following steps are included:
[0109] Step 1: Each first computing node starts an auxiliary thread, obtains training data, performs forward calculations on each convolutional layer, obtains the activation data of the last convolutional layer, and sends it to the corresponding process in the corresponding second computing node;
[0110] Step 2.1: The main thread of the first computing node periodically checks whether it has received the average gradient data of the last convolutional layer. Once received, it immediately starts to perform reverse calculations on each convolutional layer except the last one. After each calculation result is obtained, the first flag is set to true (indicating that the reverse calculation of this layer is completed and gradient synchronization can be started), and then starts to perform reverse calculations on the next convolutional layer until the reverse calculation of the first convolutional layer is completed.
[0111] Step 2.2: The auxiliary thread of the first computing node periodically checks whether the first flag is true. Once it is true, it immediately resets the first flag to false, sets the second flag to false, and executes the ring-allreduce gradient synchronization process. After obtaining the average gradient data, it uses the average gradient data to update the model parameters of this layer and sets the second flag to true (indicating that the gradient synchronization process of this layer is completed).
[0112] It should be noted that the above steps 2.1 and 2.2 are the training processes in the main thread and the auxiliary thread in the first computing node, and steps 2.1 and 2.2 are performed simultaneously.
[0113] Step 3: In the first computing node, when the reverse calculation of the first convolutional layer is completed and the second flag is true, it means that the calculation and communication processes in the computing node have been completed. At this time, it can be determined whether the training end condition is met. If so, the process is terminated; if not, return to step 1 for the next iterative training.
[0114] It can be seen that this embodiment uses a first computing node with a large amount of computing resources and a small amount of memory resources to train the convolutional layer, which is adapted to the training resources required for the convolutional layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the embodiment of the present invention, the data transmitted between the first computing node and the second computing node is the activation data of the last convolutional layer and the synchronized gradient data, and the data transmitted between each first computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network.
[0115] The embodiment of the present invention discloses a distributed training method, which improves the training efficiency of a convolutional neural network.
[0116] See also Figure 7 , a flowchart of another distributed training method according to an exemplary embodiment is shown, such as Figure 7 As shown, including:
[0117] S201: receiving the activation data of the last convolutional layer sent by the corresponding first computing node, performing forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and performing reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after obtaining the gradient data of each fully connected layer or the last convolutional layer, synchronizing the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes to obtain average gradient data, and updating the parameters of the fully connected layer or the last convolutional layer based on the average gradient data;
[0118] The executor of this embodiment is the second computing node in the above-mentioned distributed training system. In the specific implementation, k main threads are started, each main thread starts a corresponding auxiliary thread, and k is the number of first computing nodes connected to the second computing node.
[0119] In the specific implementation, the main thread performs forward calculations on each fully connected layer in the convolutional neural network based on the activation data and local training data, and performs reverse calculations on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain the gradient data of each fully connected layer and the gradient data of the last convolutional layer. After obtaining the gradient data of each fully connected layer or the last convolutional layer, the main thread sets the first flag of the fully connected layer or the last convolutional layer to the first preset value. When each auxiliary thread detects that the first flag of the fully connected layer or the last convolutional layer is the first preset value, it sets the first flag to the second preset value, sets the second flag of the fully connected layer or the last convolutional layer to the second preset value, synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain the local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain the average gradient data, and broadcasts the average gradient data to other auxiliary threads in the second computing node. Each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, and sets the second flag of the fully connected layer or the last convolutional layer to the first preset value; wherein, the target auxiliary thread is one of the k auxiliary threads in the second computing node, and there are a total of J target auxiliary threads in the J second computing nodes.
[0120] The target auxiliary thread determination method may be: determining the remainder of dividing the process identifier by k, and determining the auxiliary process corresponding to the process identifier having a remainder of 0 as the target auxiliary thread.
[0121] S202: Send the average gradient data of the last convolutional layer to the first computing node.
[0122] In a specific implementation, the main thread sends the average gradient data of the last convolutional layer to the corresponding first computing node.
[0123] When the main thread detects that the second flag bit of the last convolutional layer is the first preset value, it determines whether the training end condition is met; if so, it determines that the training is completed; if not, it re-enters the step of receiving the activation data of the last convolutional layer sent by the corresponding first computing node. The training end condition can be reaching a preset number of training times or training accuracy.
[0124] As a feasible implementation method, the gradient data of the fully connected layer or the last two convolutional layers calculated by J second computing nodes are synchronized to obtain average gradient data, including: selecting an initial second computing node, the initial second computing node transmits its own gradient data to the next two second computing nodes connected to the initial second computing node, the next two second computing nodes calculate the average gradient data of the received gradient data and their own gradient data, and continue to transmit the calculated average gradient data to the next two second computing nodes until the initial second computing node calculates the final average gradient data. It can be seen that only two gradient data need to be transmitted between adjacent second computing nodes, and the transmitted gradient data is small, thereby improving the training efficiency of the entire convolutional neural network.
[0125] As another feasible implementation, the gradient data of the fully connected layer or the last two convolutional layers calculated by J second computing nodes are synchronized to obtain average gradient data, including: selecting the initial second computing node, the initial second computing node transmits its own gradient data to the next two second computing nodes connected to the initial second computing node, the next two second computing nodes continue to transmit the received gradient data and their own gradient data to the next two second computing nodes, until the last two second computing nodes transmitted, the last two second computing nodes calculate the average gradient data of the gradient data of all second computing nodes. It can be seen that only the last two second computing nodes need to calculate the average value of the gradient data, and the other second computing nodes only need to perform simple data transmission, which improves the training efficiency of the entire convolutional neural network.
[0126] During each iteration, the training scheduling process in each process in the second computing node is as follows: Figure 8 As shown, the following steps are included:
[0127] Step 1: Each process in the second computing node starts an auxiliary thread and periodically checks whether the activation data of the last convolutional layer is received. Once received, it immediately starts to perform the forward calculation of each fully connected layer to obtain the loss value;
[0128] Step 2.1: The main thread of each process in the second computing node performs reverse calculations on each fully connected layer and the last convolutional layer layer by layer. Each time a reverse calculation result is obtained, the first flag is set to true, indicating that the reverse calculation of the layer is completed and gradient synchronization can be started. Then, the reverse calculation of the next layer is performed until the reverse calculation of the last convolutional layer is completed. The reverse calculation result of the last convolutional layer, i.e., the average gradient data, is sent to the corresponding first computing node.
[0129] Step 2.2: The auxiliary thread of each process in the second computing node checks whether the first flag is set to true. Once the value is detected to be true, the first flag is set to false, and the second flag is reset to false (indicating that the gradient synchronization process of this layer is in progress), and the local ring-allreduce gradient synchronization operation is started to obtain the local average gradient. Then determine whether the current process is the target process. If so, the global ring-allreduce gradient synchronization process is executed to obtain the global average gradient, and broadcast it to other processes in the current second computing node, update the model parameters of this layer, and set the second flag to true (indicating that the gradient synchronization of this layer is completed); if the current process is not the target process, it periodically checks whether the global average gradient from the target process is received. Once received, the model parameters are updated and the second flag is set to true. Repeat step 2.2 to synchronize the gradient data of each layer.
[0130] It should be noted that the above steps 2.1 and 2.2 are the training processes in the main thread and the auxiliary thread in each process in the second computing node, and steps 2.1 and 2.2 are performed simultaneously.
[0131] Step 3: In each process of the second computing node, when the reverse calculation of the last convolutional layer is completed and the second flag is true, it means that the calculation and communication processes in the process have been completed. At this time, it can be determined whether the training end condition is met. If so, the process is terminated; if not, return to step 1 for the next iterative training.
[0132] It can be seen that this embodiment uses a second computing node with a small amount of computing resources and a large amount of memory resources to train the fully connected layer, which is adapted to the training resources required for the fully connected layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the embodiment of the present invention, the data transmitted between the first computing node and the second computing node is the activation data and gradient data of the last convolutional layer, and the data transmitted between each second computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network.
[0133] A distributed training device provided by an embodiment of the present invention is introduced below. The distributed training device described below and the distributed training method on the first computing node side described above can be referred to each other, and specifically include:
[0134] A first computing module is used to obtain local training data, perform forward computing on each convolutional layer in the convolutional neural network based on the local training data, obtain activation data of the last convolutional layer, and send the activation data to the corresponding second computing node;
[0135] A second calculation module is used for, when receiving the average gradient data of the last convolutional layer calculated by the corresponding second calculation node, performing reverse calculation on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer, to obtain gradient data of each convolutional layer except the last convolutional layer;
[0136] Among them, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
[0137] Based on this embodiment, as a preferred implementation, the first computing module is specifically used for: the main thread obtains local training data and starts the auxiliary thread; the main thread performs forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtains the activation data of the last convolutional layer, and sends the activation data to the corresponding second computing node;
[0138] Correspondingly, the second calculation module is specifically used to: when the main thread receives the average gradient data of the last convolutional layer calculated by the corresponding second calculation node, perform reverse calculation on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer;
[0139] Correspondingly, after obtaining the gradient data of each convolution layer, the auxiliary thread synchronizes the gradient data of the convolution layer calculated by I first computing nodes to obtain the average gradient data of the convolution layer, and updates the parameters of the convolution layer based on the average gradient data of the convolution layer.
[0140] On the basis of this embodiment, as a preferred implementation manner, after obtaining the gradient data of each convolution layer, the main thread sets the first flag bit of the convolution layer to a first preset value; when the auxiliary thread detects that the first flag bit of the convolution layer is the first preset value, the first flag bit is set to a second preset value, the second flag bit of the convolution layer is set to a second preset value, the gradient data of the convolution layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolution layer, the parameters of the convolution layer are updated based on the average gradient data of the convolution layer, and the second flag bit of the convolution layer is set to the first preset value.
[0141] Based on this embodiment, as a preferred implementation, it also includes:
[0142] The first judgment module is used to judge whether the training end condition is met when the main thread detects that the second flag bit of the first convolutional layer is a first preset value; if so, determine that the training is completed; if not, restart the workflow of the first calculation module.
[0143] It can be seen that this embodiment uses a first computing node with a large amount of computing resources and a small amount of memory resources to train the convolutional layer, which is adapted to the training resources required for the convolutional layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the embodiment of the present invention, the data transmitted between the first computing node and the second computing node is the activation data of the last convolutional layer and the synchronized gradient data, and the data transmitted between each first computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network.
[0144] A distributed training device provided by an embodiment of the present invention is introduced below. The distributed training device described below and the distributed training method on the second computing node side described above can be referred to each other, and specifically include:
[0145] A third computing module is used to receive the activation data of the last convolutional layer sent by the corresponding first computing node, and perform forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and perform reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after each gradient data of a fully connected layer or the last convolutional layer is obtained, the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes are synchronized to obtain average gradient data, and the parameters of the fully connected layer or the last convolutional layer are updated based on the average gradient data;
[0146] A sending module is used to send the average gradient data of the last convolutional layer to the first computing node.
[0147] Based on this embodiment, as a preferred implementation, the acquisition module is specifically used to: start k main threads, each of which starts a corresponding auxiliary thread; wherein k is the number of first computing nodes connected to the second computing node;
[0148] Correspondingly, the third computing module is specifically used for: the main thread performs forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and performs reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain the gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after obtaining the gradient data of each fully connected layer or the last convolutional layer, each auxiliary thread synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain the local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain the average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data; wherein, the target auxiliary thread is one of the k auxiliary threads in the second computing node.
[0149] On the basis of this embodiment, as a preferred implementation manner, after each gradient data of a fully connected layer or the last convolutional layer is obtained, the main thread sets the first flag bit of the fully connected layer or the last convolutional layer to a first preset value; when each of the auxiliary threads detects that the first flag bit of the fully connected layer or the last convolutional layer is the first preset value, the first flag bit is set to a second preset value, the second flag bit of the fully connected layer or the last convolutional layer is set to a second preset value, the k gradient data of the fully connected layer or the last convolutional layer calculated locally are synchronized to obtain a local average gradient, the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, and sets the second flag bit of the fully connected layer or the last convolutional layer to the first preset value.
[0150] Based on this embodiment, as a preferred implementation, it also includes:
[0151] The second judgment module is used to judge whether the training end condition is met when the main thread detects that the second flag bit of the last convolutional layer is a first preset value; if so, determine that the training is completed; if not, restart the workflow of the third calculation module.
[0152] It can be seen that this embodiment uses a second computing node with a small amount of computing resources and a large amount of memory resources to train the fully connected layer, which is adapted to the training resources required for the fully connected layer in the convolutional neural network, and optimizes the training efficiency and effect of the convolutional neural network. In addition, in the embodiment of the present invention, the data transmitted between the first computing node and the second computing node is the activation data and gradient data of the last convolutional layer, and the data transmitted between each second computing node is the gradient data of each layer. The amount of data transmitted between the computing nodes is small, which improves the gradient synchronization efficiency, thereby improving the training efficiency of the convolutional neural network.
[0153] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0154] Based on the hardware implementation of the above program modules and in order to implement the method of the embodiment of the present invention, the embodiment of the present invention further provides an electronic device, Fig. 9 FIG. 1 is a structural diagram of an electronic device according to an exemplary embodiment. Fig. 9 As shown, the electronic equipment includes:
[0155] Communication interface 1, capable of exchanging information with other devices such as network devices;
[0156] The processor 2 is connected to the communication interface 1 to implement information exchange with other devices, and is used to execute the distributed training method provided by one or more technical solutions when running a computer program. The computer program is stored in the memory 3.
[0157] Of course, in actual application, the various components in the electronic device are coupled together through the bus system 4. It can be understood that the bus system 4 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 4 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Fig. 9 Various buses are labeled as bus system 4.
[0158] The memory 3 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program used to operate on the electronic device.
[0159] It can be understood that the memory 3 can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), and direct RAMbus random access memory (DRRAM, Direct Rambus Random Access Memory).The memory 3 described in the embodiments of the present invention is intended to include but is not limited to these and any other suitable types of memories.
[0160] The method disclosed in the above embodiment of the present invention can be applied to the processor 2, or implemented by the processor 2. The processor 2 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 2 or the instruction in the form of software. The above processor 2 can be a general-purpose processor, a DSP, or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 2 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present invention. The general-purpose processor can be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present invention, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 3. The processor 2 reads the program in the memory 3 and completes the steps of the above method in combination with its hardware.
[0161] When the processor 2 executes the program, the corresponding processes in the various methods of the embodiments of the present invention are implemented, which will not be described here for the sake of brevity.
[0162] In an exemplary embodiment, the embodiment of the present invention further provides a non-volatile storage medium storing a computer program, which can be executed by the processor 2 to complete the steps of the aforementioned method.
[0163] In an exemplary embodiment, the present invention further provides a computer program product, including a computer program, which is executed by the processor 2 to complete the steps of the aforementioned method.
[0164] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to computer program instructions, and the aforementioned computer program can be stored in a non-volatile storage medium. When the computer program is executed, it executes the steps of the above method embodiments. Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the embodiment of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a non-volatile storage medium and includes a number of instructions for an electronic device (which can be a personal computer, a server, a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention.
[0165] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. A distributed training system, characterized in that: The invention comprises I first computing nodes and J second computing nodes, wherein the first computing node comprises a local memory, the second computing node comprises a local memory and an extended memory extended by a computing fast link memory expander, the I first computing nodes are connected in a ring, the J second computing nodes are connected in a ring, and the i-th first computing node is connected to the i-th second computing node. Second computing node connection, n= ; The first computing node and the connected second computing node train a convolutional neural network in a model parallel manner, wherein the convolutional neural network includes a plurality of convolutional layers and a plurality of fully connected layers connected in sequence, and I first computing nodes train the convolutional layers in the convolutional neural network in a data parallel manner, the first computing node sends activation data of the last convolutional layer obtained by forward calculation to the connected second computing node, and the I first computing nodes synchronize the gradient data of the convolutional layer, and J second computing nodes train the fully connected layer in the convolutional neural network in a data parallel manner, and the second computing node sends the synchronized gradient data of the last convolutional layer obtained by reverse calculation to the connected first computing node, and the J second computing nodes synchronize the gradient data of the fully connected layer and the gradient data of the last convolutional layer; The process of the first computing node training the convolutional layer in the convolutional neural network in a data parallel manner includes: performing forward calculation on each convolutional layer in the convolutional neural network based on local training data to obtain activation data of the last convolutional layer, and sending the activation data to the corresponding second computing node; when receiving the average gradient data of the last convolutional layer calculated by the corresponding second computing node, performing reverse calculation on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain gradient data of each convolutional layer except the last convolutional layer; after obtaining the gradient data of each convolutional layer, synchronizing the gradient data of the convolutional layer calculated by I first computing nodes to obtain the average gradient data of the convolutional layer, and updating the parameters of the convolutional layer based on the average gradient data of the convolutional layer; Among them, the process of the second computing node training the fully connected layer in the convolutional neural network in a data parallel manner includes: receiving the activation data of the last convolutional layer sent by the corresponding first computing node, performing forward calculations on each fully connected layer in the convolutional neural network based on the activation data and local training data, and performing reverse calculations on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after obtaining the gradient data of each fully connected layer or the last convolutional layer, the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes are synchronized to obtain average gradient data, and the parameters of the fully connected layer or the last convolutional layer are updated based on the average gradient data; and the average gradient data of the last convolutional layer is sent to the first computing node.
2. The distributed training system according to claim 1, characterized in that: The first computing node includes a processor and a local memory connected to the processor; The second computing node includes a processor, a local memory connected to the processor, a root complex connected to the processor, a computing fast link memory expander connected to the root complex, and an extended memory connected to the computing fast link memory expander.
3. A distributed training method, characterized in that: Applied to a first computing node in a distributed training system as claimed in claim 1 or 2, the method comprises: Acquire local training data, perform forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtain activation data of the last convolutional layer, and send the activation data to the corresponding second computing node; When receiving the average gradient data of the last convolutional layer calculated by the corresponding second computing node, reversely calculating each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer; Among them, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer.
4. The distributed training method according to claim 3, characterized in that: Get local training data, including: The main thread obtains local training data and starts the auxiliary thread; Accordingly, forward calculation is performed on each convolutional layer in the convolutional neural network based on the local training data to obtain activation data of the last convolutional layer, and the activation data is sent to the corresponding second computing node, including: The main thread performs forward calculation on each convolutional layer in the convolutional neural network based on the local training data, obtains activation data of the last convolutional layer, and sends the activation data to the corresponding second computing node; Correspondingly, when the average gradient data of the last convolutional layer calculated by the corresponding second computing node is received, each convolutional layer except the last convolutional layer in the convolutional neural network is reversely calculated based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer, including: When the main thread receives the average gradient data of the last convolutional layer calculated by the corresponding second computing node, reverse calculation is performed on each convolutional layer except the last convolutional layer in the convolutional neural network based on the average gradient data of the last convolutional layer to obtain the gradient data of each convolutional layer except the last convolutional layer; Correspondingly, after each gradient data of a convolutional layer is obtained, the gradient data of the convolutional layer calculated by I first computing nodes are synchronized to obtain the average gradient data of the convolutional layer, and the parameters of the convolutional layer are updated based on the average gradient data of the convolutional layer, including: After obtaining the gradient data of each convolution layer, the auxiliary thread synchronizes the gradient data of the convolution layer calculated by I first computing nodes to obtain the average gradient data of the convolution layer, and updates the parameters of the convolution layer based on the average gradient data of the convolution layer.
5. The distributed training method according to claim 4, characterized in that: After obtaining the gradient data of each convolutional layer, it also includes: The main thread sets the first flag bit of the convolutional layer to a first preset value; Correspondingly, the auxiliary thread synchronizes the gradient data of the convolution layer calculated by the I first computing nodes to obtain the average gradient data of the convolution layer, and updates the parameters of the convolution layer based on the average gradient data of the convolution layer, including: When the auxiliary thread detects that the first flag bit of the convolution layer is a first preset value, the first flag bit is set to a second preset value, the second flag bit of the convolution layer is set to the second preset value, the gradient data of the convolution layer calculated by I first computing nodes is synchronized to obtain the average gradient data of the convolution layer, the parameters of the convolution layer are updated based on the average gradient data of the convolution layer, and the second flag bit of the convolution layer is set to the first preset value.
6. The distributed training method according to claim 5, characterized in that: Also includes: When the main thread detects that the second flag bit of the first convolutional layer is a first preset value, determining whether a training end condition is met; If yes, the training is considered complete; If not, the process re-enters the step of performing forward calculation on each convolutional layer in the convolutional neural network based on the local training data.
7. A distributed training method, characterized in that: Applied to a second computing node in the distributed training system according to claim 1 or 2, the method comprises: Receive the activation data of the last convolutional layer sent by the corresponding first computing node, perform forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and perform reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; wherein, after each gradient data of a fully connected layer or the last convolutional layer is obtained, synchronize the gradient data of the fully connected layer or the last convolutional layer calculated by J second computing nodes to obtain average gradient data, and update the parameters of the fully connected layer or the last convolutional layer based on the average gradient data; The average gradient data of the last convolutional layer is sent to the first computing node.
8. The distributed training method according to claim 7, characterized in that: Also includes: Start k main threads, each of which starts a corresponding auxiliary thread; wherein k is the number of first computing nodes connected to the second computing node; Correspondingly, forward calculation is performed on each fully connected layer in the convolutional neural network based on the activation data, and reverse calculation is performed on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer, including: The main thread performs forward calculation on each fully connected layer in the convolutional neural network based on the activation data, and performs reverse calculation on each fully connected layer and the last convolutional layer in the convolutional neural network to obtain gradient data of each fully connected layer and the gradient data of the last convolutional layer; Correspondingly, after each gradient data of a fully connected layer or the last convolutional layer is obtained, the gradient data of the fully connected layer or the last convolutional layer calculated by the J second computing nodes are synchronized to obtain average gradient data, and the parameters of the fully connected layer or the last convolutional layer are updated based on the average gradient data, including: After obtaining the gradient data of each fully connected layer or the last convolutional layer, each auxiliary thread synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain a local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data; wherein the target auxiliary thread is one of the k auxiliary threads in the second computing node.
9. The distributed training method according to claim 8, characterized in that: After obtaining the gradient data of each fully connected layer or the last convolutional layer, it also includes: The main thread sets the first flag bit of the fully connected layer or the last convolutional layer to a first preset value; Correspondingly, each of the auxiliary threads synchronizes the k gradient data of the fully connected layer or the last convolutional layer calculated locally to obtain a local average gradient, and the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, and each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, including: When each of the auxiliary threads detects that the first flag bit of the fully connected layer or the last convolutional layer is a first preset value, the first flag bit is set to a second preset value, the second flag bit of the fully connected layer or the last convolutional layer is set to the second preset value, the k gradient data of the fully connected layer or the last convolutional layer calculated locally are synchronized to obtain a local average gradient, the J target auxiliary threads in the J second computing nodes synchronize the local average gradient of the fully connected layer or the last convolutional layer calculated by the J second computing nodes to obtain average gradient data, and broadcast the average gradient data to other auxiliary threads in the second computing node, each auxiliary process in the second computing node updates the parameters of the fully connected layer or the last convolutional layer based on the average gradient data, and sets the second flag bit of the fully connected layer or the last convolutional layer to the first preset value.
10. The distributed training method according to claim 9, characterized in that: Also includes: When the main thread detects that the second flag bit of the last convolutional layer is a first preset value, determining whether a training end condition is met; If yes, the training is considered complete; If not, re-enter the step of receiving the activation data of the last convolutional layer sent by the corresponding first computing node.
11. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the distributed training method as claimed in any one of claims 3 to 10 when executing the computer program.
12. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, which, when executed, implements the steps of the distributed training method according to any one of claims 3 to 10.
13. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the steps of the distributed training method according to any one of claims 3 to 10.
