Why train in fewer bits
Every number in a network is stored in some floating-point format, and the narrower the format the cheaper it is. Half the bits means half the memory traffic, tensor cores multiply 16-bit numbers several times faster than 32-bit ones, and 8-bit ones faster again. Mixed-precision training runs the expensive arithmetic, the matmuls of the forward and backward passes, in a narrow format while keeping in float32 what must not drift. The question is what the narrow formats lose and how training survives it.
The page trains the AdamW tab's 2,000-step cosine run four ways from the same seed and batches: in float32, in bfloat16 and float16 under autocast, and with FP8 matmuls. In all four the weights, their gradients and AdamW's two moments are float32. This float32 master copy is the first rule of mixed precision. An update of relative to a weight is below bfloat16's resolution, so weights stored in bfloat16 would stop changing.
Number formats
A floating-point number is a sign, an exponent and a mantissa: . The exponent bits set the range, how many binades (factors of two) the format spans. The mantissa bits set the precision, how finely each binade is divided. The Number formats panel lines them up:
- float32: 8 exponent bits, 23 mantissa bits
- bfloat16: 8 and 7, float32's range with far less precision
- float16: 5 and 10, more precision than bfloat16 but a range from about (its smallest subnormal) to 65,504
- FP8 e4m3: 4 and 3, from to 448
- FP8 e5m2: 5 and 2, float16's range with two mantissa bits
Rounding to a format with mantissa bits moves a number in range by at most half its spacing, a relative error of . The Rounding it panel measures this on real tensors of the run. On the gradient flowing into block 1's MLP at step 2,000, the median relative error is 0.14 % in bfloat16, 3.6 % in e4m3 and 4.6 % in e5m2.
bfloat16: same range, less precision
Under bfloat16 autocast each matmul casts its inputs to bfloat16, multiplies, and accumulates in float32; softmax, normalisation and the loss stay float32. Because bfloat16 keeps float32's exponent, nothing overflows or underflows that would not in float32, and no extra machinery is needed. The cost is precision, about three significant digits, and training tolerates it: each rounding error is small, unbiased and averaged over the many terms of a sum. One matmul of the run, block 1's MLP input, comes out with an RMS error of 0.08 % against float64. The bfloat16 run ends at 1.890, against float32's 1.908.
float16 and loss scaling
float16 has three more mantissa bits than bfloat16, but its range ends near . Backpropagated gradients are often smaller than that, and they flush to zero. The Loss scaling panel shows this on all 24 block matmuls' incoming gradients at step 2,000: in plain float16 only 0.4 % of them stay normal numbers, 72.7 % become subnormals with few bits left and 26.9 % flush to zero.
Loss scaling (Micikevicius et al.) multiplies the loss by a large before the backward pass, which shifts every gradient up by into float16's range. The weights' gradients are divided by again in float32 before the update:
At the run's scale of , 93.1 % of those gradients are normal numbers and 1.9 % flush. Too large an overflows instead. Dynamic loss scaling starts at , halves and skips the step whenever a gradient comes out infinite, and doubles it after 200 clean steps in a row. Here it climbed to and skipped 5 of the 2,000 steps; the float16 run ends at 1.903.
FP8 matmuls
Eight bits leave too little range for one tensor's values, let alone all of them. FP8 training therefore uses two formats, as Micikevicius et al. proposed in 2022: e4m3 for weights and activations, which need precision, and e5m2 for gradients, which need range. It also scales each tensor before the cast, multiplying by , rounding, and dividing by again, so the rounding is relative to the tensor's own range:
Without the scale, e4m3 would flush every entry of that late gradient to zero. The One matmul panel follows block 1's MLP input through : both inputs are rounded to e4m3 and the product is summed in float32, an RMS error of 1.3 %. In the backward pass the incoming gradient is rounded to e5m2 before both of its products. Only the 24 linear layers of the four blocks use FP8 here. The embeddings, the tied output head, LayerNorm and attention's softmax stay float32, as in real FP8 recipes.
Four runs, one recipe
The Four runs, one recipe panel puts the validation losses together. bfloat16 and float16 end 0.018 and 0.004 below float32, no worse. On this GPU even two float32 runs of the same model differ by about 0.01, because the GPU does not add a gradient up in the same order every time. FP8 trails from the start, 0.35 behind at step 100, and is still 0.098 behind at step 2,000. Its inputs are rounded with a median error of 2.2 % and its gradients with 4.6 %, against bfloat16's 0.14 %, and with one scale per tensor 5.1 % of the late gradient's entries still flush to zero in e5m2.
None of this is faster here. The Mac's GPU has no FP8 type, so the casts are emulated on the CPU at 2.42 s per step. Even autocast does not pay on it: 0.51 s per step in bfloat16 and 0.57 s in float16, against 0.42 s in float32, measured while other jobs shared the machine. The savings need hardware with narrow tensor cores.
Where it came from
Micikevicius et al. (2018) set out the float16 recipe still used: a float32 master copy, loss scaling and float32 accumulation. Kalamkar et al. (2019) argued for bfloat16, whose float32 range removes the need to scale, and it became the usual choice. Micikevicius et al. (2022) defined the e4m3 and e5m2 formats that recent GPUs implement. FP8-LM (Peng et al., 2023) pushed FP8 into gradients and optimiser state. DeepSeek-V3 (2024) trained a 671-billion-parameter model with FP8 matmuls, scaling each small block of a tensor separately instead of the whole tensor at once. The FP8 tab of the Efficiency Explainer shows the same formats used for inference.
Papers
- Mixed Precision Training Introduces float16 training with a float32 master copy of the weights and loss scaling, the recipe of this tab's fp16 run.
- A Study of BFLOAT16 for Deep Learning Training Shows that bfloat16, with float32's exponent range, trains without loss scaling.
- FP8 Formats for Deep Learning Defines the e4m3 and e5m2 formats and their use for weights and activations, and for gradients.
- FP8-LM: Training FP8 Large Language Models Trains GPT-style models with FP8 matmuls and per-tensor scaling, and FP8 gradients and optimizer state.
- DeepSeek-V3 Technical Report Trains a 671B-parameter model with FP8 matmuls, scaling each small tile and block instead of each tensor.