Re-evaluating the Memory-balanced Pipeline Parallelism: BPipe

Mincong Huang, Chao Wang, Chi Ma, Yineng Zhang, Peng Zhang, Lei Yu · DOI

Abstract

Pipeline parallelism is an essential technique in the training of large-scale Transformer models. However, it suffers from imbalanced memory consumption, leading to insufficient memory utilization. The BPipe technique was proposed to address this issue and has proven effective in the GPT-3 model. Nevertheless, our experiments have not yielded similar benefits for LLaMA training. Additionally, BPipe only yields negligible benefits for GPT-3 training when applying flash attention. We analyze the underlying causes of the divergent performance of BPipe on GPT-3 and LLaMA. Furthermore, we introduce a novel method to estimate the performance of BPipe.

Introduction

Training massive Transformer models requires Pipeline Parallelism (PP), where a model is split across multiple GPUs. The standard "1F1B" (one-forward, one-backward) schedule creates a "memory imbalance": the first GPU in the chain must store many more activations than the last one while waiting for the backward pass to begin. This imbalance forces engineers to use smaller micro-batch sizes ($b$), which often leads to poor GPU utilization, measured as low Model FLOPS Utilization (MFU).

BPipe was introduced to mitigate this by "evicting" activations from memory-heavy early stages and "accepting" them into memory-light later stages via high-speed interconnects like NVLink. This re-evaluation explores whether BPipe remains effective across different model architectures like LLaMA and modern optimization techniques like Flash Attention.

The BPipe Mechanism

The core of BPipe involves balancing memory by transferring activation tensors between pipeline stages. This process is integrated into the training timeline to minimize idle time.

  1. Activation Transfer: Moving activation tensors from "Evictor" stages (early in the pipeline) to "Acceptor" stages (late in the pipeline).
  2. Communication Overlap: Attempting to hide the time spent moving these tensors behind computation.
BPipe timeline showing evict and load operations during a training step.

The implementation of BPipe within the Megatron-LM framework requires specific mapping of pipeline stages to GPUs to leverage high-speed intra-node communication (NVLink). By pairing early stages with late stages on the same node, the system can efficiently transfer activations.

Mapping of pipeline stages to GPUs across two nodes, showing the pairing of evictor and acceptor stages.

Experimental Setup

The evaluation focused on two primary configurations on a cluster of 32 NVIDIA A100 (80GB) GPUs:

  • LLaMA 65B: 80 layers, 8192 hidden size, 64 heads.
  • GPT-3 96B: 80 layers, 9984 hidden size, 104 heads.

Key Insights: The Impact of Flash Attention

The study revealed that BPipe’s original success on GPT-3 was largely a "side effect" of triggering more efficient fused CUDA kernels in Megatron-LM by allowing larger micro-batch sizes.

  • Flash Attention Changes the Math: Flash Attention significantly reduces memory overhead and uses highly optimized kernels. When Flash Attention is active, the memory "room" created by BPipe doesn't translate into meaningful speedups because the system is no longer bottlenecked by the same memory constraints.
  • Negative Scaling in LLaMA: For LLaMA 65B, using BPipe actually decreased performance. The communication overhead of moving activations across the pipeline outweighed the marginal gains of a larger micro-batch.
  • Predictive Modeling: The authors introduced a mathematical method to estimate the upper bound of speedup from increasing micro-batch sizes. This model shows that the relationship between micro-batch size and MFU is the real driver of performance. If a single GPU stage doesn't get significantly faster with a larger batch, BPipe won't help the whole cluster.

Key Results

  • GPT-3 (Standard Recompute): BPipe showed a significant jump in MFU from 34.0% to 45.8% (~1.35x speedup), confirming original findings.
  • GPT-3 (Flash Attention 2): MFU dropped slightly from 52.0% to 51.7% with BPipe.
  • LLaMA 65B (Flash Attention 2): Performance dropped from 49.2% to 44.0% when enabling BPipe at a micro-batch size of 4.
  • Estimation Accuracy: The novel estimation method predicted a 1.39x speedup for GPT-3, closely matching the observed 1.35x.

Conclusion

While BPipe was effective for older training configurations, its benefits are highly dependent on the underlying software kernels. For modern architectures like LLaMA using Flash Attention, BPipe offers negligible or even negative performance gains. Future work may explore its utility for trillion-parameter models where memory imbalance might exceed the mitigation capabilities of Flash Attention.

Summary updated

Abstract

Pipeline parallelism is an essential technique in the training of large-scale Transformer models. However, it suffers from imbalanced memory consumption, leading to insufficient memory utilization. The BPipe technique was proposed to address this issue and has proven effective in the GPT-3 model. Nevertheless, our experiments have not yielded similar benefits for LLaMA training. Additionally, BPipe only yields negligible benefits for GPT-3 training when applying flash attention. We analyze the underlying causes of the divergent performance of BPipe on GPT-3 and LLaMA. Furthermore, we introduce a novel method to estimate the performance of BPipe.
BibTeX
@misc{huang2024re,
  author = {Mincong Huang and Chao Wang and Chi Ma and Yineng Zhang and Peng Zhang and Lei Yu},
  title = {{Re-evaluating the Memory-balanced Pipeline Parallelism: BPipe}},
  year = {2024},
  eprint = {2401.02088},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.02088},
}
Figure