3.5Mixed precision: FP32, BF16, FP8
How a number is stored in 32, 16 or 8 bits, why training moved from FP32 to BF16 to FP8, and the tricks (master weights, loss scaling, block scaling) that keep it stable.
Why bits matter
Every number in a neural network, whether weight, activation or gradient, is stored in some floating-point format. Fewer bits per number pays off three ways. Memory: a 70B-parameter model’s weights take 280 GB in FP32, 140 GB in 16-bit and 70 GB in 8-bit. Bandwidth: moving data between GPU memory and compute units is often the real bottleneck, and half the bits means half the traffic. And speed: GPU tensor cores roughly double their throughput each time the format halves. An H100, for instance, is rated for about twice as many dense FP8 operations per second as BF16.
But fewer bits means coarser numbers. Training involves adding tiny updates to weights, gradients spanning many orders of magnitude, and long sums that accumulate rounding error. Push precision too low, carelessly, and training silently stalls or blows up with NaNs. This lesson is about how far you can push it, and the tricks that make it work. In the previous lesson you met the 16 bytes per parameter of mixed-precisionMixed-precision trainingDoing most math in a low-precision format (FP16, BF16 or FP8) while keeping a high-precision (FP32) master copy of the weights and sensitive operations. training; now you’ll see where each of those bytes comes from.
Imagine writing every number in scientific notation, like , but your notebook only has room for a few characters. You can spend them on the exponent (how big or small a number you can write at all) or on the digits (how precisely you can write it). Write "" and you lose precision; allow only one exponent digit and you can’t write at all.
The exponent digits are the exponent bits that set a format’s range. The digits before the "" are the mantissa bits that set its precision. BF16 is a notebook that spends generously on the exponent; FP16 spends more on digits; FP8 has almost no room for either.
Anatomy of a float
A floating-point number has three fields: a sign bit, an exponent and a mantissa (or fraction) . For normal numbers the value is
The leading “1.” is implicit, so it’s free. The exponent field picks a power of two, setting the scale; the mantissa picks one of evenly spaced values between that power of two and the next. So the relative spacing between neighboring numbers is about everywhere: a format with 7 mantissa bits has roughly 2–3 significant decimal digits, wherever the number sits in its range. When the exponent field is all zeros you get subnormals, which trade precision for a gentle underflow toward zero.
| format | sign / exponent / mantissa | max | smallest normal | rel. precision |
|---|---|---|---|---|
| FP32 | 1 / 8 / 23 | |||
| FP16 | 1 / 5 / 10 | 65,504 | ||
| BF16BF16 (bfloat16)A 16-bit floating-point format with the same exponent range as FP32 but less precision, widely used for training. | 1 / 8 / 7 | |||
| FP8FP88-bit floating-point formats (E4M3, E5M2) used to speed up training and inference on recent GPUs. E4M3 | 1 / 4 / 3 | 448 | 0.125 | |
| FP8 E5M2 | 1 / 5 / 2 | 57,344 | 0.25 |
Look at FP16 versus BF16. Both use 16 bits, but FP16 can’t represent anything above 65,504 or (normally) below about , while BF16 has FP32’s entire range, because it is literally the top 16 bits of an FP32 number. BF16 pays with precision: 7 mantissa bits instead of 10.
■ sign · ■ exponent · ■ mantissa. Click any bit to flip it. Values are rounded to nearest (ties to even).
Things to try:
- 0.1 is not exactly representable in any binary format. FP32 is off by about ; BF16 by ; FP8 E4M3 lands on 0.1016.
- 70000 overflows FP16 to infinity but is fine in BF16 (rounded to 70,144). 500 overflows E4M3 (which has no infinity, so the cast produces NaN) but fits E5M2.
- 1e-8 underflows to zero in FP16 and both FP8 formats. Now choose ×2¹⁶: the scaled number survives in FP16, and dividing back recovers it. That’s loss scaling in one click.
- Flip the top exponent bit of a BF16 number and watch it jump by a factor of . Flip the lowest mantissa bit and it barely moves.
Mixed-precision training
The 2017 paper “Mixed Precision Training” (Micikevicius et al.) established the recipe that still underlies everything:
Compute in low precision, keep a master copy in FP32. Forward and backward matrix multiplications run in 16-bit, but the optimizer updates an FP32 copy of every weight. Why? Updates are tiny relative to weights. In BF16 the gap between 1.0 and the next representable number is , so adding an update of 0.001 to a weight of 1.0 rounds straight back to 1.0. Thousands of such updates would vanish without a trace. In FP32 they accumulate correctly, and the 16-bit working copy is refreshed from the master after each step.
Accumulate in FP32. A matrix multiplication sums thousands of products. Tensor cores multiply low-precision inputs but accumulate the sums in FP32. Numerically sensitive operations such as softmax, normalization layers, the loss and large reductions also run in FP32.
Scale the loss (for FP16). Many gradient values are smaller than FP16’s smallest normal number () and underflow to zero. Loss scalingLoss scalingMultiplying the loss by a large factor before backpropagation so tiny FP16 gradients don't underflow to zero, then dividing the gradients back before the update. multiplies the loss by a large factor (say ) before backpropagation; by the chain rule every gradient is multiplied by too, lifting them into FP16’s range. Before the optimizer step, the gradients are divided by in FP32. Dynamic loss scaling starts with a large , halves it (and skips the step) whenever an overflow produces Inf or NaN, and slowly increases it again otherwise.
BF16 made life simpler. With FP32’s range, gradients rarely underflow, so loss scaling is unnecessary, and BF16 has become the default training format on hardware that supports it (Google TPUs, NVIDIA from the A100 onward). Its lower precision turned out to matter less than FP16’s limited range, as long as master weights and accumulations stay in FP32.
FP8: the next halving
FP8 doubles tensor-core throughput again, but with only 8 bits the range problem returns with a vengeance. E4M3 covers roughly to 448 (including subnormals); E5M2 trades a mantissa bit for range up to 57,344. A common recipe uses E4M3 for weights and activations in the forward pass and E5M2 for gradients, whose values span a wider range.
The key trick is scaling. Before casting a tensor to FP8, divide it by a scale factor so its largest value lands near the format’s maximum, and remember the scale to undo it after the matmul. With a single scale per tensor, though, one outlier ruins everything. LLM activations famously contain a few channels with values hundreds of times larger than the rest. The per-tensor scale has to accommodate the outlier, which pushes all the ordinary values down toward zero, where FP8 has almost no precision.
Where the bytes go
Putting it together, here’s where each number in a BF16 mixed-precision run lives. The working weights are BF16 (2 bytes per parameter) and feed the matmuls. Activations saved for the backward pass are mostly BF16, and FP8 recipes store some of them in FP8 too. Gradients come out of the backward pass in BF16 (2 bytes), sometimes accumulated in FP32 across micro-batches. The optimizer holds the FP32 master weights (4 bytes) and Adam’s two FP32 moments (4 + 4 bytes). That’s the 16 bytes per parameter from the distributed training lesson.
Notice what FP8 does and doesn’t change. It speeds up the matrix multiplications and shrinks some activations and communication, but the optimizer state still dominates memory. That’s why labs also shrink the optimizer state, for example by keeping Adam’s moments in BF16 (as DeepSeek-V3 did) or in 8-bit formats, and why an optimizer with a single momentum buffer (like Muon) is attractive. Precision is a budget you spend tensor by tensor: aggressive where errors average out (big matmuls), conservative where they accumulate (weight updates, long sums, normalization statistics).
A final practical note: low precision rarely fails gracefully. A run that works for a week can hit a single overflow that propagates NaNs through the whole network, or a slow drift that only shows up as worse loss. That’s why large runs monitor gradient norms and loss spikes closely, and keep frequent checkpoints to roll back to.
Below 8 bits: MXFP4 and NVFP4
The block-scaling idea is now built into hardware formats. The Open Compute Project’s microscaling (MX) formats group values into blocks of 32 that share one 8-bit power-of-two scale. MXFP4 stores each element as a 4-bit float (E2M1: 1 sign, 2 exponent and 1 mantissa bit, so the only magnitudes are 0, 0.5, 1, 1.5, 2, 3, 4 and 6). NVIDIA’s NVFP4 uses smaller blocks of 16 elements with a more precise FP8 (E4M3) block scale, plus a second FP32 scale per tensor. Recent GPUs such as NVIDIA’s Blackwell generation support these formats natively.
So far, 4-bit formats are mostly used for inference: OpenAI’s open-weight gpt-oss models, for example, ship their MoE weights in MXFP4 (see the quantization lesson). Training in FP4 is an active research area: NVIDIA, for example, has reported pretraining a 12B-parameter model on 10 trillion tokens with NVFP4 (arXiv 2509.25149). Treat such results as early and provisional.
MATH CORNER · optionalEncoding 0.1 by hand, and why updates vanish
Encode 0.1 in BF16 (bias 127, 7 mantissa bits).
- Normalize: . Sign bit 0.
- Exponent field: .
- Mantissa: , which rounds to .
- Decode: .
| format | exponent field | mantissa | stored value | relative error |
|---|---|---|---|---|
| BF16 | 0.1000977 | 0.098% | ||
| FP8 E4M3 | 0.1015625 | 1.6% |
Swamping. Adding in a format with mantissa bits loses entirely when (half the spacing between neighbors). For BF16 at : anything below disappears. A typical update to is well below that, which is why the master weights must be FP32 (whose threshold at is about ).
Block scaling for FP8. For a block , pick , store and the scalar . A matmul of two scaled blocks becomes , with computed on FP8 tensor cores and accumulated in higher precision. Smaller blocks mean each scale fits its values more tightly.
In code
In PyTorch, BF16 mixed precision is one context manager; FP16 adds a gradient scaler:
import torch
model = model.cuda() # parameters (the master weights) stay FP32
opt = torch.optim.AdamW(model.parameters(), lr=3e-4)
# BF16: autocast runs matmuls in bf16, keeps sensitive ops in fp32. No scaling needed.
with torch.autocast(device_type="cuda", dtype=torch.bfloat16):
loss = model(x, y)
loss.backward(); opt.step(); opt.zero_grad()
# FP16: same, plus dynamic loss scaling
scaler = torch.amp.GradScaler("cuda")
with torch.autocast(device_type="cuda", dtype=torch.float16):
loss = model(x, y)
scaler.scale(loss).backward() # gradients are multiplied by S
scaler.step(opt) # unscales; skips the step on Inf/NaN
scaler.update() # adjusts S for next time
opt.zero_grad()
FP8 training needs library support beyond plain PyTorch, for example NVIDIA’s Transformer Engine or torchao, which manage the per-tensor or per-block scales for you.
- “BF16 is just a less accurate FP16.” BF16 has less precision than FP16 (7 vs 10 mantissa bits) but vastly more range (the same as FP32). For training, range matters more, which is why BF16 rarely needs loss scaling.
- “Mixed precision means the model is stored in 16 bits.” During training, an FP32 master copy of the weights, and FP32 optimizer states, are kept; 16-bit copies are used for the heavy compute. That’s why training state is ~16 bytes per parameter.
- “FP8 training just casts everything to 8 bits.” It casts the big matrix multiplications, with carefully managed scale factors (per tensor or per block), higher-precision accumulation, and sensitive layers left in BF16/FP32.
- “Loss scaling changes what the model learns.” Gradients are divided by the same factor before the update, so the math is unchanged; the scaling only protects small values from underflowing while they’re in FP16.
Check your understanding
Q1.FP16 and BF16 both use 16 bits. What's the key trade-off between them?
Q2.Why does mixed-precision training keep an FP32 master copy of the weights?
Q3.What does loss scaling protect against in FP16 training?
Q4.Why did DeepSeek-V3 use 1×128 tile and 128×128 block scales for FP8 instead of one scale per tensor?
Q5.A value of 500 is cast to FP8 E4M3 without scaling. What happens?
Further reading
- paperMixed Precision Training (Micikevicius et al., 2017) — The original recipe: FP16 compute, FP32 master weights and loss scaling.
- paperFP8 Formats for Deep Learning — NVIDIA, Arm and Intel define E4M3 and E5M2.
- paperDeepSeek-V3 Technical Report — Section 3.3 describes fine-grained FP8 training at 671B scale.
- paperMicroscaling Data Formats for Deep Learning — The MX block-scaled formats, including MXFP4.
- docsPyTorch automatic mixed precision — Official docs for autocast and GradScaler.