Zubnet AI学习Wiki › Mixed Precision Training
Training

Mixed Precision Training

FP16, BF16, Half Precision
训练神经网络时大多数计算用较低精度数字格式(16-bit 而不是 32-bit),同时把关键操作保持在全精度。这使 GPU 的有效内存容量和计算速度翻倍,对模型质量影响最小。BF16(bfloat16)是 LLM 训练的标准;FP16 用于推理。

为什么重要

Mixed precision 就是为什么我们能训练像现在这么大的模型。一个 FP32 的 70B 参数模型光权重就要 280 GB — 任何单 GPU 都不可能。在 BF16 下,只需要 140 GB,能分摊到几个 GPU 上。mixed precision 实际上免费把 AI 产业的算力翻了一倍,只是通过用更聪明的数字格式。

Deep Dive

The key insight: most neural network computations don't need 32 bits of precision. The weights, activations, and gradients can be represented in 16 bits without meaningful quality loss. But some operations (loss computation, weight updates) need higher precision to avoid numerical instability. Mixed precision keeps a master copy of weights in FP32 for updates, while using FP16/BF16 for the forward and backward passes.

BF16 vs. FP16

FP16 (IEEE half-precision) has 5 exponent bits and 10 mantissa bits. BF16 (Brain Float 16) has 8 exponent bits and 7 mantissa bits. BF16's wider exponent range means it can represent the same range of values as FP32 (avoiding overflow/underflow), while FP16's narrower range requires loss scaling to prevent gradients from underflowing to zero. For training, BF16 is simpler and more stable. For inference, FP16 sometimes offers slightly better precision for the same memory cost.

FP8 and Beyond

The latest GPUs (NVIDIA H100, H200) support FP8 (8-bit floating point) for even faster computation. FP8 halves memory and doubles throughput compared to FP16, but requires careful handling to avoid quality degradation. Current practice: train in BF16, serve in FP16 or FP8, and quantize to INT4/INT8 for edge deployment. Each step down in precision trades a tiny amount of quality for significant speed and memory gains.

相关概念

← 所有术语
← Mistral AI Mixture of Experts →