English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

FP16 vs BF16: How Floating-Point Precision Quietly Breaks RL Fine-Tuning of LLMs

Forum topic · ✨步子哥 · 2025-11-27

Summary

A Sea AI Lab study reveals that the long-standing instability of reinforcement learning fine-tuning for large language models is not caused by algorithmic flaws but by training-inference numerical mismatch rooted in floating-point precision. Through offline analysis using DeepSeek-R1-Distill-Qwen-1.5B, the team shows BF16 produces probability distribution divergences up to 24x larger than FP16, and that mismatches grow exponentially with sequence length past 20,000 tokens. They construct a Perfectible Dataset on MATH (1,460 questions with 20-80% solve rate) as a Sanity benchmark, where vanilla GRPO, GRPO-Token-TIS, GRPO-Seq-MIS, PG-Seq-IS, and GSPO all collapse under BF16, while the identical algorithms under FP16 converge stably, achieve higher rewards, and eliminate the deployment gap. MoE (Qwen3-30B-A3B) and LoRA experiments confirm the same pattern. The fix is a single config change from bfloat16() to half(), combined with built-in dynamic loss scaling. The work reframes RL stability as a precision engineering problem rather than an algorithmic one.

Key Points

  • Training-inference mismatch is the root cause of RL fine-tuning collapse. Sea AI Lab shows that the forward (inference) and backward (training) engines in modern RL frameworks produce numerically divergent probability distributions due to kernel and parallel-strategy differences. On DeepSeek-R1-Distill-Qwen-1.5B in BF16, this divergence grows exponentially once sequences exceed 20,000 tokens.
  • BF16 is 24x worse than FP16 for RL fine-tuning. Measuring KL divergence between training-engine and inference-engine probabilities over matched rollouts, the authors report a roughly 24x mismatch under BF16 versus FP16. BF16 allocates 8 exponent bits and only 7 mantissa bits; FP16 uses 5 exponent bits and 10 mantissa bits, giving 2^10 / 2^7 = 8x finer resolution in the weight range relevant to fine-tuning.
  • The Perfectible Sanity Dataset isolates algorithmic flaws. From MATH, the team selects questions where the base model scores 20-80% across 40 sampled rollouts, yielding 1,460 "golden" questions for DeepSeek-R1-Distill-Qwen-1.5B. Failure to reach 95% on this set indicates a structural algorithmic defect rather than task difficulty.
  • All surveyed algorithms collapse under BF16. Vanilla GRPO tops out around 73-84% accuracy; GRPO-Token-TIS reaches 82-88% before collapsing (consistent with the bias identified by Liu et al.); GSPO stays stable longer but eventually hits a NaN gradient; only GRPO-Seq-MIS remains stable, but converges slowly to ~95% with a persistent deployment gap and 34% on AIME 2024.
  • FP16 restores stability for every algorithm tested. GRPO variants, GSPO, and a plain PG-Seq-IS all train smoothly under FP16, with PG-Seq-IS reaching 39% on AIME 2024, beating the best BF16 configuration. Sequence-level importance ratios become tightly concentrated, removing the need for token-level truncation or sequence-level masking patches.
  • The fix is a one-line config change. Switching model.bfloat16() to model.half() plus the dynamic loss scaling already shipped in PyTorch and DeepSpeed (originally popularized in 2017) is sufficient. No additional forward passes, no ~25% overhead from importance sampling, no architecture changes.
  • Deployment gap disappears under FP16. Because the training and inference distributions align, models trained under FP16 deploy without the post-training accuracy drop seen under BF16.
  • Generalizes to MoE and LoRA. On Qwen3-30B-A3B, FP16 yields higher training accuracy and validation reward across GRPO, GSPO, and other variants for the sparse-expert architecture, where top-k routing amplifies sensitivity to rounding error. LoRA-style low-rank updates show the same BF16-versus-FP16 gap.
  • Why pre-training prefers BF16 but fine-tuning prefers FP16. Pre-training weights traverse many orders of magnitude and benefit from BF16's wide dynamic range. RL fine-tuning operates on a stabilized weight distribution where small gradient updates must be resolved precisely; mantissa resolution, not range, becomes the bottleneck.

Practical Takeaway

For RL fine-tuning pipelines, default to FP16 (with dynamic loss scaling) instead of BF16. Algorithmic patches such as token-level truncated importance sampling (Yao et al.) and sequence-level masked importance sampling (Liu et al.) are largely workarounds for a precision mismatch that FP16 eliminates directly.

Tags

#reinforcement-learning#llm-fine-tuning#bf16#fp16#numerical-precision#training-inference-mismatch#sea-ai-lab#rlhf

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/176415030