← Contents Volume VIII · Lecture 17

Volume VIII · The Precision of Memory

17

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.

Decoding a normal number value = (−1)s × 2e − bias × (1 + m / 2M)
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.

ONE SLOT = ONE BIT FP32 8 23 4 B BF16 8 7 2 B FP16 5 10 2 B FP8 E4M3 4 3 1 B FP8 E5M2 5 2 1 B FP4 E2M1 2 1 ½ B sign exponent — how far mantissa — how finely
Figure 17a Six formats on one ruler. FP16 and BF16 both cost two bytes and both spend fifteen bits on the same two fields — they simply cut the line in different places. The vermilion block, the exponent, is the part of this lecture that matters most.

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.

SMALLEST NONZERO → LARGEST · LOG₂ AXIS LARGEST FP32 277 binades 3.4×10³⁸ BF16 261 binades 3.4×10³⁸ FP16 40 65504 FP8 E5M2 32 57344 FP8 E4M3 18 448 FP4 E2M1 3.6 6 2^-126 1 2^128
Figure 17b Each bar runs from the format's smallest nonzero magnitude to its largest, with the count of powers of two (binades) it covers beside it. BF16 inherits FP32's reach to within a rounding of the bar. FP16 is a sliver — the 3 mantissa bits it gained over BF16 were paid for in 221 powers of two of range.
The formats in this volume, by what each field bought
FormatSign / exp / mantissaBiasLargestSmallest normalGap just above 1
FP321 / 8 / 23127≈ 3.4×10³⁸≈ 1.2×10⁻³⁸2⁻²³ ≈ 1.2×10⁻⁷
BF161 / 8 / 7127≈ 3.4×10³⁸≈ 1.2×10⁻³⁸2⁻⁷ ≈ 0.0078
FP161 / 5 / 101565 5042⁻¹⁴ ≈ 6.1×10⁻⁵2⁻¹⁰ ≈ 0.00098
FP8 E5M21 / 5 / 21557 3442⁻¹⁴ ≈ 6.1×10⁻⁵2⁻² = 0.25
FP8 E4M31 / 4 / 374482⁻⁶ ≈ 0.01562⁻³ = 0.125
FP4 E2M11 / 2 / 1161 (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.

Loss scaling, in one line ∇(S · loss) = S · ∇loss  →  backward in FP16  →  divide by S in FP32, then update
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.

Plate 17.1 Pick a format and drag the model size. At the default, DeepSeek-V3's 671B parameters need about sixteen 80 GB cards for weights alone at BF16 and about eight at FP8 — before a single KV cache entry. Watch the ruler as you step down: the first cut, from FP32 to BF16, takes mantissa bits only and leaves the exponent alone, and by FP4 the exponent is down to two bits of range. The plate counts element bits only. The scale factors that make the narrow formats usable add a fraction of a bit per value on top, and that is what Lecture 18 is for.

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.

ONE SCALE FOR THE WHOLE TENSOR 4000 s = 4000 / 448 ≈ 8.9 every value under ≈ 0.009 becomes 0 ONE SCALE PER TILE 4000 s1 s2 s3 the outlier spoils one tile, not all
Figure 17c Scale granularity, drawn with twelve cells. A single shared scale is set by the largest value in the tensor, so one outlier decides the resolution of every neighbour. Shrink the group that shares a scale and the damage is confined to the group that contains it.

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.

ACTIVATIONS · TOKENS × K WEIGHTS · K × N × 1 × 128 tile one scale per token, per 128 channels 128 × 128 block one scale per block FP8 products add up inside the tensor core; every 128 steps along K the partial sum moves to FP32 and gets its scales
Figure 17d Where DeepSeek-V3's scales live. Both groupings run along the inner dimension K, so the scales for a stretch of the dot product are known together and can be multiplied in when the partial sum is promoted — the dequantization costs almost nothing extra.

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.

DeepSeek-V3's precision map, as the technical report describes it
ComponentPrecisionWhy
Linear-layer GEMMs (forward, input-gradient, weight-gradient)FP8 E4M3The bulk of the FLOPs and the bulk of the bytes
ScalesPer 1×128 tile (activations), per 128×128 block (weights)An outlier damages one group, not the tensor
AccumulationPromoted to FP32 every 128 elementsTensor-core accumulators are narrow
Embedding, output head, MoE gating, normalization, attention operatorsOriginal precision (BF16 or FP32)Small share of the FLOPs; the report keeps them wide for numerical stability
Master weights and weight gradientsFP32Small updates must survive being added to large weights
AdamW momentsBF16Reported to cost no observable degradation
MoE dispatch / combineFP8 / BF16A 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

❦