Sub topic 2
Number formats: from FP32 to 4-bit
This chapter assumes you know what a model parameter is and can convert between bits, bytes and GB. It covers the number formats used to store those parameters, because the format sets the file size. The next chapters build on this.
Why the format matters
A model is a very large list of numbers called weights. Each weight is stored in a fixed number of bits. Fewer bits per weight means a smaller file and less memory to hold it. The cost is lower precision: each stored value is a coarser approximation of the original.
Common formats
Floating-point formats store a sign, an exponent (the scale) and a mantissa (the precision digits). The exponent size sets the range of values. The mantissa size sets the detail.
| Format | Bits | Bytes per weight | Notes |
|---|---|---|---|
| FP32 | 32 | 4 | Standard single precision. Common for training, rare for local inference. |
| FP16 | 16 | 2 | Half precision. Small range, so large values can overflow. |
| BF16 | 16 | 2 | Same range as FP32 with fewer mantissa bits. Common for released models. |
| INT8 | 8 | 1 | Integers with a scale factor. Needs quantisation. |
| 4-bit | 4 | 0.5 | Only 16 distinct levels per value, plus scale data. |
FP16 and BF16 use the same space but make different trade-offs. BF16 keeps FP32's exponent width, so it covers the same range of values. FP16 keeps more mantissa bits, so it is finer but overflows sooner.
Size from format
The file size is roughly the parameter count times the bits per weight, divided by 8. Here is that calculation for an 8-billion-parameter model.
formats = {"FP32": 32, "FP16": 16, "BF16": 16, "INT8": 8, "4-bit": 4}
params = 8e9
for name, bits in formats.items():
gib = params * bits / 8 / 2**30
print(f"{name:>5}: {gib:5.1f} GiB")The output is about 29.8, 14.9, 14.9, 7.5 and 3.7 GiB. Each halving of the bits halves the memory. A model that needs 15 GiB at 16 bits fits in under 4 GiB of weights at 4 bits, which is the difference between needing a large GPU and fitting on a laptop.
How the formats relate
Common errors
- Treating 4-bit as exactly 4 bits. Quantised formats store extra scale values alongside the weights. The real average is somewhat higher, often between 4.5 and 5 bits per weight. Later chapters cover this for GGUF files.
- Assuming FP16 and BF16 are interchangeable. Converting between them loses either range or precision, so use the format the model was released in.
- Forgetting that weights are not the whole footprint. The KV cache and runtime overhead come on top of the weights.
Exercise
A model has 70 billion parameters. How many GiB do its weights need in BF16, and in 4-bit (ignoring scale overhead)?
Show answer
BF16 uses 16 bits, so 70e9 × 16 / 8 = 140e9 bytes, which is about 130.4 GiB. At 4 bits, 70e9 × 4 / 8 = 35e9 bytes, which is about 32.6 GiB. Real 4-bit files are larger because of scale data.