Distributed learning information compression method based on shared random projection
By using the shared random projection information compression method SEPARATE in large model distributed training, the compatibility and adaptability problems of the gradient compression method are solved, efficient communication and high-quality training are achieved, and large model training time is shortened. and improved model fine-tuning performance.
Patent Information
- Application Number
- CN202410906152.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-08
AI Technical Summary
It is difficult for the existing technology to take into account both training efficiency and quality in large model distributed training. The gradient compression method has information loss and compatibility issues, is difficult to be compatible with modern communication architecture, and is uncertain about its adaptability to the Adam optimizer.
A distributed learning information compression method SEPARATE based on shared random projection is proposed. By performing projection compression and reconstruction on the gradient vector, it ensures the unbiasedness and bounded variance of the reconstructed vector. It is suitable for any first-order optimizer and Communication architecture supports efficient communication and model training.
The SEPARATE method can achieve the same training accuracy as a full-precision optimizer without affecting training efficiency, shorten large model training time, improve model fine-tuning performance, support high compression ratios, and is suitable for a variety of communication architectures and optimizers.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical fields of machine learning, artificial intelligence, distributed training and neural network optimization, and in particular relates to a distributed learning information compression method based on shared random projection. Background Art
[0002] In recent years, deep learning (DL) technology has made significant progress in many fields such as image, text and video processing, and has been successfully applied in many fields including computer vision (e.g. image classification, object detection), natural language processing (e.g. language modeling, machine translation), etc. The key to the performance improvement of models trained by deep learning technology on most tasks lies in the substantial increase in the amount of training data and model size. Accordingly, with the increase in model size, the memory and computational overhead of training large models has exceeded the capabilities of a single computing device (e.g. GPU). Therefore, in recent years, distributed training of large models on large cluster devices (e.g. GPUs and TPUs) has become the mainstream technology for studying large models in academia and industry, and the distribution and communication of models and data across multiple devices have become key factors affecting the efficiency of large model training. One of the main strategies for distributed training is 3D parallel technology, which integrates data parallelism, pipeline parallelism and tensor parallelism to improve the efficiency of distributed training on GPU clusters.
[0003] The problem with 3D parallel training is that as the number of model parameters increases, the communication cost required to synchronize data between multiple GPUs becomes increasingly expensive. Therefore, a training strategy with efficient communication is crucial to improving the efficiency, scalability, and applicability of large model training. A commonly used technique to reduce communication costs is gradient compression, which compresses the original gradient vector during communication, thereby significantly improving the communication efficiency of vectors between GPUs. However, there are some problems with gradient compression technology, and the information loss that may occur during the compression process will reduce the quality of model training. Therefore, in order to balance training efficiency and quality, research on gradient compression methods often focuses on two key issues: how to ensure training performance after using compression technology, and how to design methods that are suitable for modern communication architectures. Existing commonly used information compression methods often find it difficult to balance the above two issues. Low-order quantization methods are often based on a master-server communication architecture, which is incompatible with the current advanced ring-based and tree-based communication architectures; low-rank methods introduce additional computational overhead, and it is not yet clear whether they are suitable for the default Adam type optimizer in deep learning. Furthermore, integrating these methods into existing full-precision optimizers often requires extensive modifications, requiring additional work to ensure compatibility and maintain performance.
[0004] Currently, how to achieve efficient training of large models remains a major challenge. The following key question needs to be solved: Is there a simple information compression method that can maintain high training quality and significant communication efficiency in distributed learning while being independent of the optimizer and communication framework? Summary of the invention
[0005] In order to overcome the deficiencies of the above-mentioned prior art and solve the problems in the efficient training of the above-mentioned large models, the present invention proposes a distributed learning information compression method based on shared random projection, and is named SEPARATE (Simple and generic Plug-in for gradient compRession in modern lArge-scale TrainingprocEss). SEPARATE can be used as a simple and universal plug-in compatible with common gradient-based optimizers (such as SGD and Adam) in various training frameworks. In the model training process of GPT-2-Medium, only half of the training time is used to achieve the same training accuracy as the full-precision Adam optimizer.
[0006] The technical solution provided by the present invention is as follows:
[0007] A distributed learning information compression method based on shared random projection comprises the following steps:
[0008] 1) Preprocess the text data to obtain text encoding for training;
[0009] 2) Build a large-scale language model trained with text data and initialize the parameters of the model to be trained:
[0010] 3) Model the training task as an optimization problem, select a gradient-based first-order optimizer to solve the optimization problem, and perform the following steps during the optimizer solution process:
[0011] 3-1) Use the selected optimizer to perform forward and backward propagation of the model parameters, and obtain the gradient information corresponding to the model parameters on each device n in the distributed cluster Where g represents the gradient information, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed;
[0012] 3-2) The gradient information obtained in this round The accumulated error stored on the current device Add together and get Where e represents the accumulated error value stored on the device, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed;
[0013] 3-3) Generate m independent and identically distributed Gaussian random vectors ξ1,…,ξ m ~N(0,I d ), and calculate The projections on these random vector directions [p 1,n ,…,p m,n ],in <·,·> represents the inner product operation between two vectors, [·] represents the result of these inner product operations is combined into a new vector, N(0,I d ) represents the d-dimensional standard normal distribution;
[0014] 3-4) For different devices n [p 1,n ,…,p m,n ] to conduct global communication and obtain
[0015] 3-5) On each device n The information is reconstructed as follows and use Update the optimizer state and model parameters as an estimate of the gradient vector;
[0016] 4) After a certain number of iterations, save the model and test and evaluate the trained model.
[0017] Furthermore, in step 2), if the model is pre-trained from scratch, the model parameters are initialized to zero; if the model is fine-tuned, the pre-trained model parameters are read from the specified path.
[0018] Furthermore, in step 4), if the model is pre-trained from scratch, the function value of its loss function after the iteration is completed is recorded; if the model is fine-tuned, the saved model is evaluated on the selected downstream task and the evaluation accuracy is recorded.
[0019] Compared with the prior art, the beneficial effects of the present invention include:
[0020] The core of the present invention is to design a universal information compression method that allows the gradient vector to be compressed to an arbitrary low-dimensional space before communication and then reconstructed after communication. The SEPARATE method proposed in the present invention can be directly deployed on any existing first-order optimizer, communication architecture and training framework, that is, the method can be regarded as a plug-in and can be simply implemented on the basis of the existing optimizer through a few lines of code. The present invention combines the landscape characteristics of the actual task and uses Gaussian random vectors shared between distributed system devices to project, compress and reconstruct the gradient information. The present invention can ensure the unbiasedness of the reconstructed vector and the boundedness of the variance, thereby maintaining the high quality of training in distributed learning. In addition, users can choose the compression ratio according to the settings of their own devices, and the compression ratio can exceed 32 (the compression ratio of the usual gradient quantization algorithm is up to 32). The SEPARATE method can achieve high-quality pre-training and fine-tuning tasks of large language models with efficient communication, and improve the training effect of distributed learning without affecting the training efficiency. Therefore, the specific technical advantages of the present invention include:
[0021] (i) This paper proposes a new gradient compression method called SEPARATE, which can be applied to existing gradient-based optimizers and training frameworks with just a few lines of code. Using a novel error feedback technique, SEPARATE maintains the same training results as the full-precision optimizer in theory and experiment. On this basis, users can freely choose the compression ratio according to the settings of their own devices, even exceeding 32. Compared with existing gradient compression methods, this paper has stronger versatility, more efficient training speed, better training results and simpler deployment methods.
[0022] (ii) The large model pre-training task based on the present invention can achieve the same training accuracy as the full-precision optimizer in a shorter time. Deploying the present invention on Adam can shorten the large model training time to half of the full-precision optimizer training.
[0023] (III) The large model fine-tuning task based on the present invention achieves higher evaluation accuracy than the full-precision optimizer in many downstream tasks. The distributed learning information compression algorithm proposed in the present invention can reduce the communication overhead by 16 to 32 times while improving the performance of the model after fine-tuning. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a flow chart of the information compression method based on shared random projection proposed by the present invention. DETAILED DESCRIPTION
[0025] The technical details of the present invention are further described below in conjunction with examples, but the scope of the present invention is not limited in any way.
[0026] The present invention provides the application process of SEPARATE and gives a detailed description of the implementation steps of SEPARATE in the actual application process.
[0027] The present invention constructs an information compression method applicable to all gradient-based first-order optimizers and communication frameworks, named SEPARATE. SEPARATE can be easily deployed in actual large-scale model training tasks as a plug-in. In the actual application process, the present invention describes the technical details of SEPARATE in deployment as follows. The specific implementation includes the following steps:
[0028] 1) Preprocess the text data to obtain text encoding for training;
[0029] 2) Build a large-scale language model trained with text data and initialize the parameters of the model to be trained:
[0030] 3) Approximately model the training task as an optimization problem, select a gradient-based first-order optimizer (usually Adam) to solve the optimization problem, and perform the following steps during the optimizer solution process:
[0031] 3-1) Use the selected optimizer to perform forward and backward propagation of the model parameters, and obtain the gradient information corresponding to the model parameters on each device n in the distributed cluster Where g represents the gradient information, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed;
[0032] 3-2) The gradient information obtained in this round The accumulated error stored on the current device Add together and get Where e represents the accumulated error value stored on the device, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed;
[0033] 3-3) Generate m independent and identically distributed Gaussian random vectors ξ1,…,ξ m ~N(0,I d ), and calculate The projections on these random vector directions [p 1,n ,…,p m,n ],in <·,·> represents the inner product operation between two vectors, [·] represents the result of these inner product operations is combined into a new vector, N(0,I d ) represents the d-dimensional standard normal distribution;
[0034] 3-4) For different devices n [p 1,n ,…,pm,n ] to conduct global communication and obtain The global communication method is based on the communication architecture adopted by the distributed cluster, which is generally a ring-based or tree-based communication architecture. The linear property of random projection ensures that the method can be deployed under any communication architecture.
[0035] 3-5) On each device n The information is reconstructed as follows and use As an estimate of the gradient vector, the optimizer state and model parameters are updated. The parameter update method is determined by the selected optimizer. The method proposed in the present invention compresses the gradient vector, so it can be deployed on any gradient-based first-order optimizer (such as SGD and Adam).
[0036] 3-6) Calculate the sliding average of the compression error and cumulative error in the current round as the new cumulative error and store it as follows:
[0037]
[0038] in It represents the accumulated error stored on device n in the k+1th iteration. β is the parameter of the sliding average, which can be adjusted as needed. After a certain number of iterations, the accumulated error is reset to zero.
[0039] 4) After a certain number of iterations, save the model and test and evaluate the trained model.
[0040] SEPARATE projects the local gradient information on different devices through a shared random vector, but only requires a small amount of additional computational cost. The reason is that the calculation process of projecting using m independent and identically distributed Gaussian random vectors can be expressed as the multiplication of the original gradient vector and a d×m Gaussian random matrix. This form is well supported in modern computing architectures (such as CUDA), and the additional computational overhead in actual applications is negligible compared to the forward propagation and backpropagation overhead in the deep learning training process.
[0041] The present invention further designs a computational parallel mechanism to achieve further acceleration in the actual application process. Through the hook mechanism in PyTorch, the present invention designs a parallel implementation of compression calculation and back propagation calculation. Through the hook mechanism, the present invention adds a "pendant" to the model back propagation process. Before the optimizer obtains the gradient vector of the next layer, that is, before calculating the gradient vector of the previous layer, the hook mechanism starts and completes the compression and communication of the gradient of the next layer, and at the same time the optimizer calculates the gradient vector of the previous layer in parallel. Therefore, by reasonably arranging the order of calculation and communication, the time cost of compressing the gradient can be hidden in the back propagation calculation process, thereby achieving the same calculation speed as the full-precision optimizer. Since SEPARATE greatly reduces the communication overhead, the training speed of the model (which can be regarded as the sum of the calculation and communication overhead) has been significantly improved.
[0042] The SEPARATE method naturally has a certain degree of versatility. SEPARATE can be applied to ring-based or tree-based communication architectures, which are usually based on reduce-scatter operations and have limited support for quantization methods. Unlike quantization methods, SEPARATE is not troubled by numerical anomalies such as overflow or underflow, so it supports reduce-scatter operations well. SEPARATE also supports the sharding strategy, which is commonly used when training large language models. Even if the gradients are separated to different nodes, the linear nature of random projection ensures the correctness of the SEPARATE results.
[0043] The present invention optimizes the memory overhead of SEPARATE. Due to error feedback and storage of random vectors, SEPARATE brings additional memory overhead to training. The present invention sets a random variable buffer, generates some Gaussian random vectors before training starts and stores them in the buffer for use in the initial stage of training, and updates and overwrites the random vectors in the buffer after use. By reusing this part of memory to store random vector streams, memory costs are reduced.
[0044] The present invention is used to pre-train a large model. Adam is used to train a large model (such as GPT-2-Medium) on a specified data set and the SEPARATE method is deployed to more efficiently obtain a pre-trained model with a specified accuracy.
[0045] The present invention uses the SEPARATE method to train a large model and obtains a faster training speed. The specific technical details are as follows:
[0046] The present invention trained the GPT-2-Medium model from scratch on an 8x NVIDIA 3090 24G GPU cluster. The present invention used the OpenWebtext dataset, ran a total of 300,000 iterations, and processed a total of 50 billion tokens. The present invention used the PyTorch DDP training framework without model and pipeline parallelization. The present invention set the model parameters as follows before training: the global batch size is 8x 512, the learning rate is set to 6.0e-4, and the learning rate decay strategy of cosine annealing is adopted. The present invention sets the first 2000 iterations as hot start during training, and decays the learning rate to a minimum of 6.0e-5 in the next 298,000 iterations. Gradient accumulation is used in training, and the gradient accumulation step is set to 4. Global gradient norm clipping is used in training, set to 1, and the dual parameters of the Adam optimizer are set to 0.9 and 0.95.
[0047] The present invention uses a common Adam optimizer and a SEPARATE-based Adam optimizer to train the GPT-2-Medium model. During the back propagation process, the present invention uses the SEPARATE method to compress and communicate the obtained layer gradients. Specifically, the present invention reads a random vector of a given size from a random vector buffer, reorganizes it into a random matrix of d×m dimensions, and multiplies it with the result obtained by adding the original gradient vector and the cumulative error vector stored on the device to obtain a compressed low-dimensional vector for communication, and updates the cumulative error and random vector buffer after the communication is completed. For the SEPARATE method, the present invention can set different compression ratios, that is, the ratio by which m is reduced compared to D. For the quantization method, the ratio has an upper bound of 32, while the SEPARATE method can be freely set according to demand. The present invention tested the SEPARATE training effect under different ratios, and compared the convergence speed of the iterative steps and the wall clock time, as shown in Table 1. All methods use the same training settings.
[0048] Table 1: Convergence speed of training GPT-2-Medium with the proposed method and the common Adam optimizer
[0049]
[0050] Table 1 shows that SEPARATE of the present invention can accelerate the training speed of GPT-2-Medium pre-training by 2 times by weighing the compression ratio and the single-step iteration cost. Therefore, the SEPARATE method can maintain training performance on the basis of improving communication and training efficiency. In addition, the present invention also tests the single-step time cost of ordinary Adam and SEPARATE with different compression ratios on GPT-2-Small and GPT-2-Meduim. As the model scale increases, the effect of SEPARATE is more significant, so SEPARATE is more effective when training large models. A higher compression ratio can still reduce the single-step time cost, but may cause more information loss, so setting an appropriate compression ratio is a trade-off in practice.
[0051] The present invention is used to fine-tune the large model. Adam is used to fine-tune the large model (such as LLaMA2-7B) on a specified data set and the SEPARATE method is deployed. The obtained model is evaluated on a specified downstream task and a fine-tuned model with better performance is obtained.
[0052] This paper uses the SEPARATE method to fine-tune large models and evaluate them on a large number of downstream tasks. The technical details are as follows:
[0053] The algorithm implementation steps are not much different from the training of GPT-2-Medium. For the experimental setting, the present invention fine-tuned the LLaMA2-7B model on the alpaca-gpt4 dataset within the PyTorch FSDP communication framework, and compared the compression method based on shared random projection proposed by the present invention with common quantization, low-rank and other methods. The present invention fine-tuned LLaMA2-7B for three epochs on an 8x NVIDIA A6000 48G GPU cluster. In order to adapt to the device, the data parallelism in fine-tuning is set to 4, the model parallelism is set to 2, no pipeline parallelization is used, the global batch size is set to 32, the learning rate is 2e-5, the gradient clipping is 2, and the gradient accumulation step is set to 8. The present invention selects a variety of benchmarks to evaluate the fine-tuned model, including common sense reasoning, world knowledge, mathematical calculations, and code generation, and the results are shown in Table 2. All methods use the same settings.
[0054] Table 2 Evaluation results of fine-tuning LLaMA2-7B by the present invention and existing compression methods on multiple benchmarks
[0055] Method TriQA GSM8K MBPP NQ WinoG Arc-e Arc-c PIQA HellaS Avg. Adam 49.39 15.69 19.40 3.07 46.09 72.31 53.90 57.07 26.45 38.15 PowerSGD 50.78 18.65 22.40 2.52 40.57 62.43 42.71 52.88 30.12 35.90 1-bit Adam 62.08 16.53 16.80 5.15 49.57 49.21 37.97 52.88 22.04 34.69 ZeRO++ 57.49 18.42 22.20 1.72 49.88 43.03 30.85 47.61 33.97 33.91 SEPARATE 57.18 20.17 21.40 4.18 49.25 72.66 49.83 52.99 29.73 39.72
[0056] The results in Table 2 show that the comprehensive performance of the present invention is better than other low-rank or quantized optimizers with error feedback and ZeRO++ optimizer in all downstream tasks, and even exceeds the performance of the baseline Adam optimizer without compression. Other gradient compressions are far inferior to SEPARATE and baseline Adam in performance, especially in common sense reasoning tasks. Because the error feedback based on the current iteration cannot handle the accumulated errors in the whole process, the present invention uses the sliding average of historical errors to stabilize the error and uses the error reset mechanism to eliminate useless information, so it has obvious advantages.
[0057] It should be noted that the purpose of publishing the embodiments is to help further understand the present invention, but those skilled in the art can understand that various substitutions and modifications are possible without departing from the scope of the present invention and the appended claims. Therefore, the present invention should not be limited to the contents disclosed in the embodiments, and the scope of protection claimed by the present invention shall be subject to the scope defined in the claims.
Claims
1. A distributed learning information compression method based on shared random projection, characterized in that: The steps include: 1) Preprocess the text data to obtain text encoding for training; 2) Build a large-scale language model trained with text data and initialize the parameters of the model to be trained: 3) Model the training task as an optimization problem, select a gradient-based first-order optimizer to solve the optimization problem, and perform the following steps during the optimizer solution process: 3-1) Use the selected optimizer to perform forward and backward propagation of the model parameters, and obtain the gradient information corresponding to the model parameters on each device n in the distributed cluster Where g represents the gradient information, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed; 3-2) The gradient information obtained in this round The accumulated error stored on the current device Add together and get Where e represents the accumulated error value stored on the device, the subscript n represents that the gradient is the local information obtained on the nth device, and k represents that the kth iteration is currently being performed; 3-3) Generate m independent and identically distributed Gaussian random vectors ξ1,…,ξ m ~N(0,I d ), and calculate The projections on these random vector directions [p 1,n ,…,p m,n ],in <·,·> represents the inner product operation between two vectors, [·] represents the result of these inner product operations is combined into a new vector, N(0,I d ) represents the d-dimensional standard normal distribution; 3-4) For different devices n [p 1,n ,…,p m,n ] to conduct global communication and obtain 3-5) On each device n The information is reconstructed as follows and use Update the optimizer state and model parameters as an estimate of the gradient vector; 4) After a certain number of iterations, save the model and test and evaluate the trained model.
2. The distributed learning information compression method based on shared random projection according to claim 1, characterized in that: The gradient-based first-order optimizer in step 3) is SGD or Adam.
3. The distributed learning information compression method based on shared random projection according to claim 1, characterized in that: The global communication method in step 3-4) is based on the communication architecture adopted by the distributed cluster, which is a ring-based communication architecture or a tree-based communication architecture.
4. The distributed learning information compression method based on shared random projection according to claim 1, characterized in that: In step 3), the sliding average of the compression error and the cumulative error in the current round is calculated as the new cumulative error and stored as follows: in It represents the accumulated error stored on device n in the k+1th iteration. β is the parameter of the sliding average. After a certain number of iterations, the accumulated error is reset to zero.
5. The distributed learning information compression method based on shared random projection according to claim 1, characterized in that: In step 2), if the model is pre-trained from scratch, the model parameters are initialized to zero; if the model is fine-tuned, the pre-trained model parameters are read from the specified path.
6. The distributed learning information compression method based on shared random projection according to claim 5, characterized in that: A random variable buffer is set up, and some Gaussian random vectors are generated and stored in the buffer before training starts. They are used in the initial stage of training, and the random vectors in the buffer are updated and overwritten after use.
7. The distributed learning information compression method based on shared random projection according to claim 1, characterized in that: In step 4), if the model is pre-trained from scratch, the function value of its loss function after the iteration is completed is recorded; if the model is fine-tuned, the saved model is evaluated on the selected downstream task and the evaluation accuracy is recorded.
Citation Information
Patent Citations
A gradient projection image reconstruction method based on a compressed sensing approximation L0 norm
CN109584330A
Multimedia data searching method and device, equipment and storage medium
CN113590850A
Data processing method and device, electronic equipment and computer readable storage medium
CN114330512A
Distributed machine learning model transmission compression method based on model decomposition
CN115470935A
Privacy protection personalized federal learning method with efficient communication
CN116862022A
Cited By
Image reconstruction method based on cross iteration back projection network
CN119809937A
Multi-source data fusion field large model adaptive fine tuning system and method
CN122616656A
Model acquisition method, apparatus, and chip
WO2026218698A1
