Skip to content
DARC
■ Change #29 · wiki.edited

FP8 formats and scaling recipes for training and inference: Normalize Markdown to canonical form

by DARC wiki2026-10-22 20:30:59 UTCOpen the page →
explainer.student
**Floating point in binary.** A computer stores a real number like scientific notation in base 2, $x = \pm 1.m \times 2^{e}$, with some bits for the exponent $e$ and some for the mantissa (fraction) $m$. Standard FP32 uses 32 bits (8 exponent, 23 mantissa); BF16 and FP16 use 16 bits. FP8 uses 8 bits in total. Why bother: an NVIDIA H100 does about 1979 TFLOP/s of dense FP8 matrix arithmetic against about 989 for BF16, and each number costs half the memory traffic.
**The two FP8 formats.** E4M3 has 4 exponent bits and 3 mantissa bits; its largest value is 448. E5M2 has 5 exponent bits and 2 mantissa bits; its largest value is 57344. With 3 mantissa bits, neighbouring numbers between 1 and 2 are $2^{-3} = 0.125$ apart, so E4M3 keeps only about one significant decimal digit. The usual convention is E4M3 for weights and activations, which need precision, and E5M2 for gradients, which need range.
**What goes wrong without scaling.** The tensors (arrays of numbers) inside a neural network can hold values like 0.0003 and 5000. Values below the smallest representable size become zero, and values above the maximum overflow. So each tensor is multiplied by a scale factor $s$ before conversion and divided by it afterwards:
− $$q = \mathrm{round}_{\text{FP8}}(s\,x), \qquad x \approx q/s.$$
+ $q = \mathrm{round}_{\text{FP8}}(s\,x), \qquad x \approx q/s.$
In words: stretch the numbers so the largest lands near the top of the format's range, round, and remember the stretch. Example: if the largest $|x|$ is 3.5, choose $s = 448/3.5 = 128$. Analogy: choosing the units on a ruler so the object fills it. The analogy breaks when one extreme value (an outlier) forces a scale that squeezes all the ordinary values into a few marks.
**Recipes.** Per-tensor current scaling computes the maximum every time: accurate, but needs an extra pass over the data. Delayed scaling reuses maxima from earlier training steps: cheaper, but it can overflow when values suddenly spike. NVIDIA's Transformer Engine implements these recipes. Fine-grained scaling gives each small tile its own scale: DeepSeek-V3 (2024) used 1 × 128 tiles for activations and 128 × 128 blocks for weights, so an outlier only spoils its own tile.
**Accumulation.** Products of FP8 numbers are summed in higher precision, but the DeepSeek-V3 report notes that FP8 matrix multiplication on Hopper tensor cores keeps limited accumulation precision, so it periodically moves partial sums into full FP32 on the ordinary cores.
**Limits.** Sensitive operations (normalisation, softmax, embeddings, often the output layer) stay in higher precision. Gains shrink for memory-bound layers and small models, and long training runs can show sudden loss spikes, which motivates finer scaling.
hash 1675045d7c3cc77ee7cf8cedc774e9963276715e91a3bc037e12d0ea94d8caef
previous 147657d49bddffc0fe97b38aee6642463e427484b84b785b9b7a3e057f664016