FP8-LM: Training FP8 Large Language Models

Houwen Peng, Kan Wu, Yixuan Wei, Guoshuai Zhao, Yuxiang Yang, Ze Liu, Yifan Xiong, Ziyue Yang, Bolin Ni, Jingcheng Hu, Ruihang Li, Miaosen Zhang, Chen Li, Jia Ning, Ruizhe Wang, Zheng Zhang, Shuguang Liu, Joe Chau, Han Hu, Peng Cheng · OpenReview

Abstract

In this paper, we explore FP8 low-bit data formats for efficient training of large language models (LLMs). Our key insight is that most variables, such as gradients and optimizer states, in LLM training can employ low-precision data formats without compromising model accuracy and requiring no changes to hyper-parameters. Specifically, we propose a new FP8 automatic mixed-precision framework for training LLMs. This framework offers three levels of FP8 utilization to streamline mixed-precision and distributed parallel training for LLMs. Experiment results show that, during the training of GPT-175B model on H100 GPU platform, our FP8 mixed-precision training framework not only achieved a remarkable 42% reduction in real memory usage but also ran 64% faster than the widely adopted BF16 framework (i.e., Megatron-LM), surpassing the speed of Nvidia Transformer Engine by 17%.

Introduction: The Challenge of Scaling LLM Training

Training state-of-the-art Large Language Models (LLMs) like GPT-3 or PaLM is prohibitively expensive, requiring thousands of high-end GPUs and massive amounts of energy. While the industry has moved from 32-bit (FP32) to 16-bit (FP16/BF16) precision to save costs, the jump to 8-bit (FP8) has historically been "brittle."

FP8 has a much narrower dynamic range and lower precision than BF16, which often leads to training instability—numerical issues like overflows or underflows that cause the model to fail to learn. Previous solutions, like Nvidia’s Transformer Engine, only used FP8 for specific matrix multiplications (GEMM), leaving significant memory and communication efficiency on the table. FP8-LM aims to integrate FP8 into the entire training process: gradients, optimizer states, and distributed communication.

The FP8-LM Framework

The researchers from Microsoft introduced FP8-LM, a framework built on three core innovations to stabilize and optimize 8-bit training:

  1. Precision Decoupling: Not all variables are equally sensitive to precision. While master weights and second-order optimizer moments require 16-bit precision, gradients and first-order moments can thrive in FP8. This allows for significant memory reduction without sacrificing the fine-grained updates necessary for convergence.
  2. Automatic Scaling: To prevent data loss from the narrow FP8 range, an auto-scaling factor ($\mu$) adjusts on the fly. It decreases if values overflow and increases if they underflow.
  3. FP8 Distributed Parallelism: The framework extends FP8 to distributed strategies like Tensor, Pipeline, and Sequence parallelism. It also redesigns the ZeRO optimizer to handle FP8 tensors and their scaling factors using a "Greedy Distribution Algorithm" to balance memory across the cluster.
Figure 1: Integration of FP8 into distributed parallel training pipelines, showing the flow between sequence and tensor parallelism.

Experimental Validation

The framework was validated using a massive pre-training corpus and several fine-tuning benchmarks:

  • Pre-training: A 100-billion token subset of a diverse collection including CommonCrawl, C4, and Wikipedia.
  • Fine-tuning: Instruction-following data from ShareGPT and human preference data for RLHF using AlpacaFarm and Anthropic’s datasets.
  • Evaluation: Models were tested on zero-shot tasks (HellaSwag, Lambada) and compared against Davinci-003 using AlpacaEval and MT-Bench.

Performance and Accuracy

Benchmarks on Nvidia H100 GPUs show dramatic improvements over the industry-standard Megatron-LM (BF16):

  • Throughput: For a GPT-175B model, FP8-LM is 75% faster than the BF16 baseline and 37% faster than Nvidia’s Transformer Engine.
  • Memory Efficiency: Real memory usage was reduced by 39% for the 175B model. This allows for training significantly larger models on the same hardware footprint.
  • Accuracy: Across models from 7B to 175B parameters, training loss curves for FP8 and BF16 are virtually identical, with no significant degradation in zero-shot performance.
Figure 2: Comparison of model capacity across GPU counts. FP8-LM enables training much larger models (up to ~1.1T parameters on 128 GPUs) compared to the BF16 baseline.

Conclusion

FP8-LM demonstrates that the "direction" of gradients is more critical than exact magnitude for optimizer convergence, allowing first-order moments to be compressed to 8 bits. By moving to FP8 for "all-reduce" operations, communication overhead is reduced by up to 65%. As a drop-in replacement requiring no hyperparameter changes, FP8-LM offers a practical path to reducing the immense costs of foundation model training.

The FP8-LM framework is open-sourced at aka.ms/MS.AMP.

Summary updated

BibTeX
@misc{peng2023fp,
  author = {Houwen Peng and Kan Wu and Yixuan Wei and Guoshuai Zhao and Yuxiang Yang and Ze Liu and Yifan Xiong and Ziyue Yang and Bolin Ni and Jingcheng Hu and Ruihang Li and Miaosen Zhang and Chen Li and Jia Ning and Ruizhe Wang and Zheng Zhang and Shuguang Liu and Joe Chau and Han Hu and Peng Cheng},
  title = {{FP8-LM: Training FP8 Large Language Models}},
  year = {2023},
  eprint = {2310.18313},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.18313},
}
Figure