TL;DR
Merak is a new distributed training framework that automates 3D parallelism (combining data, pipeline, and tensor parallelism) for giant foundation models in PyTorch. By introducing an automatic model partitioner and a high-performance runtime engine, it achieves up to a 1.61x speedup over state-of-the-art baselines while requiring only minimal code changes from developers.
What Problem Does This Paper Address?
Training "giant" foundation models like GPT-3 is a monumental task that exceeds the memory and compute capacity of single GPUs. To handle this, researchers use 3D parallelism:
- Data Parallelism (DP): Distributing data across replicas.
- Pipeline Model Parallelism (PMP): Splitting model layers across different GPUs.
- Tensor Model Parallelism (TMP): Splitting individual layers (like large matrix multiplications) across GPUs.
However, existing frameworks like Megatron-LM and DeepSpeed suffer from two major hurdles. First, they lack generality and ease of use; developers often have to manually refactor their model code to fit specific library interfaces. Second, they are inefficient; they often leave GPU memory unutilized, suffer from "bubbles" (idle time) in pipeline schedules, and fail to overlap communication with computation in tensor parallelism.
Methods
Merak introduces two core modules to solve these issues:
1. Automatic Model Partitioner
To make 3D parallelism "transparent," Merak uses a proxy node-based graph. Instead of loading a massive model (which would cause an Out-of-Memory error on a single machine), it traces the model using metadata-only "proxy nodes." It then applies a graph-sharding algorithm to automatically slice the model into stages for pipeline parallelism and identify operators for tensor parallelism. This allows a standard Hugging Face-style script to run in a distributed environment with just a few lines of code.
2. High-Performance Runtime Engine
Merak optimizes resource utilization through three key techniques:
- Shifted Critical Path Schedule: It modifies the standard "1F1B" (one-forward-one-backward) pipeline schedule to reduce idle "bubble" time and better balance the workload of the final stage, which often contains heavy "head" layers.
- Stage-Aware Recomputation: Rather than recomputing all activations to save memory (which is slow), Merak dynamically uses "idle" memory in specific pipeline stages to store activations, reducing redundant calculations.
- Sub-pipelined TMP: Standard tensor parallelism often blocks computation while waiting for communication (AllReduce). Merak splits microbatches into even smaller sub-microbatches, allowing the GPU to compute one part of the batch while communicating the results of another.
Datasets
The authors evaluated Merak using GPT-like transformer models ranging from 1.4 billion to 20 billion parameters. The models were trained on the OpenWebText dataset with a fixed sequence length of 1024.
Key Insights and Ideas
- Democratizing Large-Scale Training: The "proxy tracing" approach is a clever workaround for the memory limits of a single master node. It allows developers to use community models (like those from Hugging Face) without needing to be experts in distributed systems.
- Memory is a Spectrum: Most frameworks treat activation recomputation as a binary toggle. Merak’s "stage-aware" approach recognizes that different stages in a pipeline have different memory pressures, allowing for a more nuanced and efficient trade-off between memory and speed.
- Communication Hiding: By sub-pipelining TMP, Merak addresses a major bottleneck in multi-node training where slow interconnects (like PCIe vs. NVLink) often leave GPUs idling during AllReduce operations.
Key Results
In head-to-head comparisons against Megatron-LM, DeepSpeed, and PaddlePaddle on 64 GPUs:
- Throughput Gains: Merak achieved speedups of 1.42x (1.5B model), 1.39x (2.5B model), 1.43x (8.3B model), and 1.61x (20B model) over the best-performing baselines.
- Scalability: Merak demonstrated excellent weak scaling. As the number of GPUs increased from 2 to 64, iteration times remained stable or even improved relative to linear scaling due to its advanced memory optimizations.
Limitations and Future Work
- Model Architecture: While the framework is designed to be general, the evaluation focused primarily on Transformer-based architectures.
- Scale: The experiments were conducted on up to 64 GPUs. Testing Merak at the scale of thousands of GPUs (where communication bottlenecks become even more severe) remains a future challenge.
- Orthogonal Optimizations: The authors note that techniques like ZeRO (optimizer state sharding) are orthogonal to Merak and could be integrated in the future to further enhance memory efficiency.
The code for Merak is open-sourced at https://github.com/hpdl-group/Merak.
Summary updated