Accelerating Large Language Model Training with 4D Parallelism and Memory Consumption Estimator

Kazuki Fujii, Kohei Watanabe, Rio YokotaarXiv 2024 · DOI

Abstract

Training Large Language Models (LLMs) requires sophisticated parallelism strategies to manage memory and compute across distributed systems. However, finding optimal configurations often involves trial-and-error to avoid Out-of-Memory (OOM) errors. This paper presents a precise memory consumption estimator for Llama-style architectures utilizing "4D parallelism" (Data, Tensor, Pipeline, and Context Parallelism). By validating against 454 experiments on NVIDIA A100 and H100 GPUs, the authors establish an "80% safety rule" that reliably predicts training success and enables the identification of high-throughput configurations.

Introduction

The scale of modern LLMs, such as Llama-3.1, necessitates distributing model states and activations across hundreds of GPUs. Engineers typically employ 4D parallelism, combining Data Parallelism (DP), Tensor Parallelism (TP), Pipeline Parallelism (PP), and Context Parallelism (CP). While this approach offers flexibility, it introduces a complex optimization problem: maximizing training throughput (TFLOP/s) while staying within strict hardware memory limits. Over-parallelizing leads to excessive communication overhead, while under-parallelizing results in OOM crashes.

The Llama-style Transformer layer architecture modeled in this study, featuring GQA and SwiGLU.

Memory Estimation Methodology

The researchers derived mathematical formulas to account for three primary memory consumers in the Llama architecture:

  1. Model States: This includes parameters, gradients, and optimizer states. For the Adam optimizer with mixed-precision (BF16/FP32), the footprint is approximately 18 bytes per parameter.
  2. Activations: The model accounts for the sharding of activations across TP, PP, and CP, specifically focusing on FlashAttention 2, FFN layers, and RMSNorm.
  3. Empirical Safety Buffer: Theoretical formulas often overlook memory fragmentation or temporary buffers. Through extensive testing, the authors found that maintaining estimated usage below 80% of total VRAM acts as a reliable threshold for avoiding OOM errors.
Memory allocation breakdown for model states using mixed-precision training.

Key Insights and Results

The estimator was tested using Llama-3.1-8B and 70B models on NVIDIA A100 (40GB) and H100 (94GB) GPUs. Key findings include:

  • The Minimalist Strategy: The highest throughput is generally achieved by using the minimum amount of model parallelism ($TP \times CP \times PP$) necessary to fit the model in memory. On 256 A100 GPUs, a configuration of (TP=4, CP=1, PP=1) for Llama-3.1-8B reached approximately 201 TFLOP/s.
  • CP vs. TP Efficiency: For long sequences, Context Parallelism is often more efficient than Tensor Parallelism because it requires fewer communication operations (all-gather) compared to TP's multiple all-reduces.
  • Hardware Sensitivity: The estimator successfully accounted for differences in GPU memory capacity (e.g., 80GB vs 94GB H100s), preventing sub-optimal configurations that a generic rule might suggest.

Conclusion

The proposed memory estimator provides a robust framework for navigating the 4D parallelism space. By replacing "guess and check" with a predictable 80% safety threshold, researchers can rapidly deploy optimal training configurations for Llama-style models. Future work includes extending these formulas to Mixture of Experts (MoE) architectures and developing a user-friendly software library for the community.

Reference: Fujii, K., Watanabe, K., & Yokota, R. (2024). Accelerating Large Language Model Training with 4D Parallelism and Memory Consumption Estimator. arXiv:2411.06465v1.

Summary updated

BibTeX
@misc{fujii2024accelerating,
  author = {Kazuki Fujii and Kohei Watanabe and Rio Yokota},
  title = {{Accelerating Large Language Model Training with 4D Parallelism and Memory Consumption Estimator}},
  year = {2024},
  eprint = {2411.06465},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.06465},
}
Figure