Skip to content

FP8-LM: Training FP8 Large Language Models

Skip →MoE Training Handbook (HF)
Pretraining stage 2 #9extendedfrontierpaperrubric 8/122023 · ~20 min

Houwen Peng, Kan Wu, Yixuan Wei, …, Peng Cheng

Status

TL;DR. On H100s, FP8 was first used only for matrix multiplies (Nvidia Transformer Engine). FP8-LM also uses FP8 for gradients, optimizer states and distributed communication. The key choices are which tensors can be stored in 8 bits (“precision decoupling”) and how to scale FP8 values so they do not underflow or overflow during all-reduce. GPT-style models from 7B to 175B trained this way match BF16 accuracy in pretraining and downstream tasks.

Three FP8 components are added in stages:

  1. FP8 gradients and all-reduce. An adaptive factor μ\mu scales gradients: it is halved when more than 0.001% of values reach the FP8 maximum and grown slowly otherwise. Each gradient tensor uses a single scale shared across GPUs (the minimum over GPUs), so a standard NCCL all-reduce works.
  2. FP8 optimizer. Adam state drops from 16 to 6 bytes per parameter:
2⏟FP16 master+1⏟FP8 grad+1⏟FP8 m+2⏟FP16 v=6 bytes.\underbrace{2}_{\text{FP16 master}} + \underbrace{1}_{\text{FP8 grad}} + \underbrace{1}_{\text{FP8 } m} + \underbrace{2}_{\text{FP16 } v} = 6\ \text{bytes}.

Master weights use FP16 with tensor scaling. The second moment stays at 16 bits because squared gradients underflow in FP8. 3. FP8 distributed training. Tensor and sequence parallelism send FP8 activations. FP8 ZeRO assigns whole tensors, with their scale factors, to GPUs greedily by size instead of splitting tensors.

Results. For GPT-175B on H100s, FP8-LM uses 39% less memory and runs 75% faster than BF16 Megatron-LM, and is 37% faster than Transformer Engine. Across sizes, real memory use falls by 29–39% and weight-related communication by 63–65%. Pretraining loss and downstream accuracy match BF16. FP8 SFT matches BF16 on AlpacaEval and MT-Bench while training 27% faster, and FP8 in AlpacaFarm-style RLHF reduces memory for the several models that must be loaded.

  • DeepSeek-V3 — FP8 training at frontier scale with finer-grained (tile and block) scaling.
  • AdamW — the optimizer whose state FP8-LM compresses.
  • FlashAttention — another systems approach to fitting longer contexts and larger models in GPU memory.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Standard mixed-precision Adam stores 4 bytes each for master weights, gradients, first moment and second moment. FP8-LM stores FP16 master weights, FP8 gradients, an FP8 first moment and an FP16 second moment. Compute bytes per parameter for both, the reduction factor, and the optimizer-state memory for a 7B model.

    What a strong answer covers
    • Baseline 4 + 4 + 4 + 4 = 16 bytes per parameter; FP8-LM 2 + 1 + 1 + 2 = 6 bytes.
    • 16 / 6 ≈ 2.67, which the paper reports as a 2.6× reduction.
    • 7B × 16 B = 112 GB versus 7B × 6 B = 42 GB, before activations and before sharding across GPUs.
    • The reduction in total GPU memory is smaller (29% for 7B, 39% for 175B) because activations and other buffers are not reduced in the same way.
  2. Mechanism

    Explain why FP8-LM keeps Adam's second moment and master weights at 16 bits while allowing the first moment and gradients in FP8, and why both pre-scaling and post-scaling fail for an FP8 all-reduce across N GPUs.

    What a strong answer covers
    • The second moment is a mean of squared gradients; squaring small gradients underflows in FP8, and v sets the step size through 1/√v, so errors there change step sizes.
    • The first moment mainly gives the direction of the update, which tolerates quantisation error when tensor scaling is used.
    • Master weights receive tiny updates each step; at low precision those updates round to zero, so they need higher precision.
    • Pre-scaling divides each gradient by N before summing and underflows for large N; post-scaling sums first and overflows. FP8-LM uses an adaptive factor μ (halved when more than 0.001% of values hit the FP8 maximum) and one shared global-minimum scale for each gradient tensor across GPUs.
  3. Design

    You are adding FP8 to an existing BF16 Megatron-style pretraining stack for a 70B model and can only roll out one component at a time. Order the steps (FP8 matmuls, FP8 gradients and all-reduce, FP8 optimizer, FP8 ZeRO), and say what you would monitor at each step to catch divergence early.

    What a strong answer covers
    • Start with FP8 matmuls (as in Transformer Engine), the best-tested part, and compare loss curves with a BF16 run over the first few thousand steps.
    • Add FP8 gradients and communication next, with automatic scaling; monitor the fraction of saturated or zero gradient values and the gradient norm.
    • Then the FP8 optimizer, keeping the second moment and master weights at 16 bits; monitor update and weight norms per layer.
    • FP8 ZeRO last, because whole tensors with their scale factors must be assigned to GPUs (greedy by size); check memory balance across ranks and that results match the non-sharded run.

Done with this page?

Status