TL;DR
Training massive Transformer models is a significant challenge due to their enormous memory and computational demands. This paper introduces H3T, a novel framework that automatically optimizes the integration of memory-saving techniques and parallelism strategies to accelerate Transformer training. H3T significantly outperforms existing toolkits, enabling the training of models like GPT-3-175B on a more accessible hardware configuration.
What Problem Does This Paper Address?
The success of Transformer models in various AI domains has led to an explosion in model size, with parameters reaching hundreds of billions. This presents a critical bottleneck for training, as storing model parameters, gradients, and intermediate activations requires vast amounts of GPU memory. While memory optimization techniques (like rematerialization and offloading) and parallelism strategies (like data and model parallelism) have been explored independently, their efficient integration for large-scale Transformer training remains a significant challenge. Existing approaches often focus on one aspect, leading to suboptimal memory usage or training efficiency. The paper aims to bridge this gap by proposing a unified framework that automatically finds the best combination of these techniques.
Methods
H3T tackles this problem by formalizing memory optimization and parallelism strategies into "optimization switches" that can be applied at each Transformer layer. The core of H3T is an automatic solver that searches for the optimal combination of these switches to minimize training runtime while staying within a given memory constraint.
The framework incorporates:
- Memory Optimization Switches:
- Activation-aspect: Rematerialization (recomputing intermediate activations when needed) and Offloading (moving activations to CPU RAM).
- Parameter-aspect: Offloading parameters and optimizer states to CPU RAM, parameter partitioning (distributing parameters across GPUs), and lazy-prefetching (fetching parameters just in time).
- Parallelism: The framework implicitly supports data and model parallelism, which are foundational to distributed training.
- Solver Algorithms: To navigate the vast search space of possible switch combinations, H3T employs three solvers:
- Random Solver: A baseline for comparison.
- Greedy Solver: Iteratively turns off switches to reduce memory.
- Dynamic Programming (DP) Solver: A more sophisticated approach inspired by the knapsack problem, which considers optimal sub-solutions for prefixes of the model. The DP solver is further optimized with pruning techniques to improve efficiency.
- Implementation: H3T is implemented on top of the BMTrain toolkit, leveraging concurrent streams for computation and communication to overlap operations.
Datasets
The paper uses standard Transformer-based models for experiments, including various sizes of BERT (1.8B, 6B, 13B, 100B) and GPT-3-175B. The experiments are conducted on simulated environments and actual hardware. For evaluating the end-to-end performance and correctness, tasks from the SuperGLUE benchmark are used.
Key Insights and Ideas
- The Power of Integration: The most significant insight is that the integration of memory optimization and parallelism is crucial for efficient large-scale Transformer training, rather than optimizing each in isolation.
- Automated Optimization is Key: Manually finding the optimal combination of techniques is extremely difficult and time-consuming. H3T's automated solver significantly simplifies this process and achieves better results.
- Layer-wise Customization: The ability to apply different optimization strategies to different layers of the Transformer allows for fine-grained control and better adaptation to specific hardware and model architectures.
- DP Solver's Effectiveness: The Dynamic Programming solver, despite its computational complexity, proves to be the most effective in finding optimal or near-optimal solutions, especially when combined with pruning techniques.
- Democratizing Large Model Training: H3T's ability to train massive models like GPT-3-175B on significantly less hardware than previously thought possible opens doors for more researchers and engineers.
Key Results
- Speedup: H3T outperforms Megatron-DeepSpeed by 1.2x to 4.3x in training speed.
- Memory Reduction: H3T reduces GPU memory overhead by 34.6% to 80.5% compared to Megatron-DeepSpeed.
- GPT-3 Training: H3T successfully trains GPT-3-175B using only 64 NVIDIA A100 GPUs, a feat that is very difficult for existing toolkits.
- Adaptability: The DP and greedy solvers demonstrate good adaptability to varying memory constraints and hardware environments.
- Energy Efficiency: H3T shows lower energy consumption compared to Megatron-DeepSpeed in most tested scenarios.
- Comparable Performance: End-to-end experiments on SuperGLUE tasks show that H3T achieves comparable results to PyTorch with APEX.
Limitations and Future Work
- Memory Estimation Accuracy: The paper acknowledges that GPU memory allocation doesn't perfectly equate to actual memory usage due to factors like fragmentation. This leaves room for improvement in the solver's memory estimation. The authors plan to develop an in-house memory pool management module for absolute control.
- CPU Memory Neglect: H3T primarily focuses on GPU memory. For extremely large models, CPU RAM can become a bottleneck. Future work will explore CPU memory management and offloading to secondary storage.
- Dynamic Model Structures: H3T is designed for models with fixed structures. It is not directly applicable to models with dynamic structures, where real-time optimization frameworks might be more suitable.
- Solver Efficiency: While the DP solver is efficient enough for practical purposes, further optimization (e.g., C++ implementation, multithreading) is planned to significantly improve its speed.
- Other Optimizations: The current implementation does not include advanced optimizations like tensor parallelism, pipeline parallelism, or FlashAttention. Future work will explore integrating these for even greater efficiency.
Summary updated