Volume VIII · The Precision of Memory
The Anatomy of a Number
Every weight in a 671-billion-parameter model is a number, and every number costs bytes. Store each one in 32 bits and the weights alone fill 2.7 terabytes. Store each in 8 and they fill 671 gigabytes. The model is the same in both cases. What differs is which bits someone decided the model could do without.
The mental model
A number format is a budget of bits spent on two questions: how far can it reach, and how finely can it say where it landed. Exponent bits buy reach and mantissa bits buy resolution. The recent history of training is the discovery that reach can be bought somewhere cheaper — in a scale factor that sits beside a group of numbers rather than inside each one.
Three fields and a bias
A floating-point number is scientific notation in base two. Write 0.15625 as 1.25 × 2⁻³ and the whole idea is on the page: a sign, a power of two, and a fractional part that scales it. The hardware stores those as three bit-fields packed side by side — the sign, the exponent and the mantissa — and a format is nothing more than the decision of how many bits each field gets.
For a normal number, the stored exponent e is read with a fixed offset called the bias, so that negative powers need no sign of their own. The mantissa m is read as a fraction with an implicit leading one, which is why it costs no bit. Two exponent patterns are reserved. All zeros marks zero and the subnormals — tiny numbers that drop the implicit one to fill the gap down to zero. In the IEEE formats, all ones marks infinity and NaN.
bias = 2E−1 − 1 → 127 for 8 exponent bits · 15 for 5 · 7 for 4 · 1 for 2
Run it on the 0.15625 above. The sign is 0. The exponent is −3, stored as −3 + 127 = 124,
which is 01111100. The fraction .25 is 0.01 in binary. In FP32
the 23 mantissa bits read 01000000000000000000000 and the whole word is
0x3E200000. BF16 keeps the same sign, the same eight exponent bits and only
the first seven mantissa bits, 0100000, giving 0x3E20 — which is
exactly the top half of the FP32 word. Real converters round to nearest rather than chop,
but the layout is the point. BF16 is FP32 with the bottom sixteen bits sheared off, and
§ 17.3 is about why that turned out to be the right shear.
Range is the exponent, precision is the mantissa
A format answers two independent questions. The first is range: how large and how small a magnitude can it hold. The exponent field sets it. The second is precision: how closely can it tell apart two neighbouring values. The mantissa field sets that.
The spacing is not uniform, and the pattern is worth holding in mind. Inside every power-of-two interval there are exactly 2M evenly spaced values, so the gap between neighbours is a fixed fraction of the value — between 2−M and half that. BF16 resolves a number to roughly 0.4–0.8%. FP16 is eight times finer, at roughly 0.05–0.1%. E4M3 resolves to roughly 6–12%. Floats trade absolute accuracy for a relative accuracy that holds from the tiniest value to the largest. That is the right trade for a network whose weights span many orders of magnitude.
| Format | Sign / exp / mantissa | Bias | Largest | Smallest normal | Gap just above 1 |
|---|---|---|---|---|---|
| FP32 | 1 / 8 / 23 | 127 | ≈ 3.4×10³⁸ | ≈ 1.2×10⁻³⁸ | 2⁻²³ ≈ 1.2×10⁻⁷ |
| BF16 | 1 / 8 / 7 | 127 | ≈ 3.4×10³⁸ | ≈ 1.2×10⁻³⁸ | 2⁻⁷ ≈ 0.0078 |
| FP16 | 1 / 5 / 10 | 15 | 65 504 | 2⁻¹⁴ ≈ 6.1×10⁻⁵ | 2⁻¹⁰ ≈ 0.00098 |
| FP8 E5M2 | 1 / 5 / 2 | 15 | 57 344 | 2⁻¹⁴ ≈ 6.1×10⁻⁵ | 2⁻² = 0.25 |
| FP8 E4M3 | 1 / 4 / 3 | 7 | 448 | 2⁻⁶ ≈ 0.0156 | 2⁻³ = 0.125 |
| FP4 E2M1 | 1 / 2 / 1 | 1 | 6 | 1 (0.5 is subnormal) | 2⁻¹ = 0.5 |
Why BF16 beat FP16
FP16 was the first reduced format to train a serious network, and it came with a complication that the 2017 mixed-precision recipe spelled out. Gradients are small. FP16's smallest nonzero value is about 6×10⁻⁸, so a gradient of 10⁻⁸ does not round to something imprecise — it rounds to exactly zero, and the signal it carried is gone. The recipe's answer was loss scaling: multiply the loss by a constant before backpropagation so every gradient arrives that many times larger, then divide it back out in FP32 before the weight update. The same recipe kept an FP32 master copy of the weights so that small updates did not vanish when added to large weights.
too small an S and gradients underflow · too large and they overflow past 65 504
It worked, and it left a standing chore. The scale had to sit between underflow and overflow, and the safe interval moved as training progressed. Frameworks eventually automated it as dynamic loss scaling — grow the scale while steps stay clean, halve it and skip the step when an infinity appears — but a failed step is a symptom of a format whose range is narrow enough to be hit by an ordinary training run.
BF16 removes the chore by removing the cause. Conceived at Google Brain and first built into its TPUs, it keeps FP32's eight exponent bits and spends the savings by cutting the mantissa to seven. Google's stated reasoning was that neural networks are far more sensitive to exponent size than to mantissa size. Because the range matches FP32, the underflow and overflow behaviour matches too: no loss scaling, and conversion to and from FP32 is a bit-slice. The TPU's matrix unit multiplies in BF16 and accumulates in FP32, so the coarse values never get summed coarsely. The 2019 empirical study of the format (Kalamkar and colleagues) found it reached the same results as FP32, in the same number of iterations, without changing hyperparameters, across image, speech, language and recommendation models. NVIDIA's Ampere generation then put BF16 into mainstream GPU tensor cores, and it became the working precision of large-model pretraining.
BF16 is also the baseline everything after it is measured against. When DeepSeek validated FP8 training, the claim was stated as an error relative to a BF16 run, not to FP32. The rest of this lecture and the whole of the next are the story of what that baseline cost, and how much of it could be given back.
The bill, in cards
Precision is the cheapest lever on memory because it multiplies everything. DeepSeek-V3 has 671 billion parameters. At FP32 that is 2.7 TB of weights, at BF16 1.34 TB, at FP8 671 GB. Lecture 2 priced the KV cache at two bytes per value for this reason: BF16 is the unit this whole course has been counting in. The plate below does the same multiplication for any model size and any format.
Eight bits, and the outlier
The next halving was proposed in 2022 as a pair of formats, and the pair encodes the same lesson as BF16. E4M3 has four exponent and three mantissa bits — more resolution, less reach, a largest value of 448. E5M2 has five and two — a reach that matches FP16's, and a resolution coarse enough that it was proposed for the one tensor that needs reach most. The recipe was a hybrid: E4M3 for weights and activations on the forward pass, E5M2 for gradients on the backward pass. Hopper-generation tensor cores multiply FP8 natively, which is the capability Lecture 12 met in FlashAttention-3.
Eight bits do not leave room for the exponent field to cover a real tensor. E4M3 spans about 18 powers of two (Figure 17b); a tensor with outliers spans more than that. The remedy is a scale factor: pick a number s, store q = E4M3(x / s), and reconstruct x ≈ q · s. The scale slides the format's 18-binade window to wherever the tensor lives. The obvious choice is one scale per tensor, set so the largest magnitude lands on 448.
That choice has a failure mode, and it is the one a single outlier produces. Take a tensor whose largest entry is 4000 — a hypothetical figure, but exactly the kind of outlier the fine-grained scheme below is built to contain. The scale becomes 4000 / 448 ≈ 8.9. The smallest E4M3 subnormal is 2⁻⁹, so anything below half of it, 2⁻¹⁰, rounds to zero — which after rescaling means every value below roughly 0.009. One outlier has erased every small activation in the tensor.
How DeepSeek-V3 did it
DeepSeek-V3, the 671B-total, 37B-active mixture-of-experts model of Volume VII, was pretrained on 14.8 trillion tokens with most of its matrix multiplications in FP8. The technical report is the most complete public account of how that was made safe, and the recipe reads as a sequence of answers to the failure in Figure 17c.
Fine-grained scaling. Activations are scaled per 1 × 128 tile — one scale for each token's block of 128 channels. Weights are scaled per 128 × 128 block. The report's stated reason is that per-tensor low-precision training is highly sensitive to activation outliers, and that smaller groups let the scale follow local magnitudes. The scales are computed online, from the maximum of the tile or block in front of the kernel, rather than inferred from the history of earlier steps.
E4M3 on every tensor. The hybrid of § 17.5 put E5M2 on gradients to cover their range. DeepSeek-V3 used E4M3 for the forward pass and for both backward matrix multiplications. With a scale per small group, the range comes from the scale, and the exponent bits can be spent on resolution. It is the first appearance of this volume's theme: reach moved out of the element.
Accumulation precision. The report measured that the tensor core's accumulator holds roughly 14 bits, enough to produce nearly 2% maximum relative error on a dot product of length 4096. The fix is to let the tensor core accumulate a short stretch, then promote the partial result into an FP32 register on the CUDA cores every 128 elements — about four warp-group matrix instructions — and carry on summing there. A long sum in a narrow accumulator loses small terms once the running total is large. Short sums, widened early, do not.
A deliberate list of exceptions. Some operations stay in higher precision because they are cheap and fragile. The report names the embedding, the output head, the MoE gating, the normalization operators and the attention operators. The master weights, the weight gradients and the optimizer states are kept wide too, so "FP8 training" names the precision of the large matrix multiplications — not of the whole run.
| Component | Precision | Why |
|---|---|---|
| Linear-layer GEMMs (forward, input-gradient, weight-gradient) | FP8 E4M3 | The bulk of the FLOPs and the bulk of the bytes |
| Scales | Per 1×128 tile (activations), per 128×128 block (weights) | An outlier damages one group, not the tensor |
| Accumulation | Promoted to FP32 every 128 elements | Tensor-core accumulators are narrow |
| Embedding, output head, MoE gating, normalization, attention operators | Original precision (BF16 or FP32) | Small share of the FLOPs; the report keeps them wide for numerical stability |
| Master weights and weight gradients | FP32 | Small updates must survive being added to large weights |
| AdamW moments | BF16 | Reported to cost no observable degradation |
| MoE dispatch / combine | FP8 / BF16 | A split: only the dispatch half is quantized |
The result, in the report's own validation against a BF16 baseline on DeepSeek-V2-class models, was a relative loss error consistently below 0.25%. That is a measurement on smaller models than V3 itself, and the report is the only primary source for the full run. What it establishes is that frontier-scale pretraining in eight bits is a solved recipe rather than an experiment, and that the recipe's load-bearing idea is the small group.
The same recipe, three times
Operands in a narrow format, a scale for each small group, accumulation in a wide register, and a short list of operations that never leave higher precision. DeepSeek implemented the scales in software, on tiles it chose. The next lecture is about what happens when the scale is written into the number format itself — and then the element is cut from eight bits to four.
Eight bits roughly halved the bill. Four will halve it again, but E2M1 leaves a mere two bits of exponent, so the scale has to do almost all of the work. Lecture 18 takes up that case: the micro-scaled 4-bit formats, quantization that is built into training, and the arithmetic that puts a 120-billion-parameter model on one card.
Read the primary source
- DeepSeek-V3 Technical Report — DeepSeek-AI, 2024.
- FP8 Formats for Deep Learning — Micikevicius et al., 2022.
- Mixed Precision Training — Micikevicius et al., 2017.
- A Study of BFLOAT16 for Deep Learning Training — Kalamkar et al., 2019.
- BFloat16: The secret to high performance on Cloud TPUs — Google Cloud, 2019.
- FlashAttention-3 — Shah et al., 2024.