Bookmarks

BF16 — BF16 format

bfloat16

A 16-bit floating-point number format with the same range as FP32 but lower precision. It is used to store and compute neural network weights.

Also: brain floating point, BF16 format

checked 18 Nov

All terms

BF16 takes half the memory of FP32 while covering the same range of values. That is why training in it usually needs no loss scaling, which FP16 requires, and the weights of many open models are published in BF16.

What a number consists of

FormatSignExponentMantissaLargest value
FP321 bit8 bits23 bitsabout 3.40e38
BF161 bit8 bits7 bitsabout 3.39e38
FP161 bit5 bits10 bits65,504

The exponent sets the range; the mantissa sets the number of significant digits. BF16 has the same exponent as FP32, so very large and very small values do not overflow to infinity or underflow to zero. Its mantissa is shorter than that of FP16, giving a precision of roughly two to three decimal digits. Converting from FP32 to BF16 is essentially dropping the lower 16 bits with rounding.

Where it is used

In training, BF16 is used together with FP32: matrix multiplications run in BF16, while sum accumulation and the master copies of the weights stay in FP32. In inference, a BF16 model weighs about 2 bytes per parameter: a 9-billion-parameter model takes about 18 GB. Modern GPUs and processors support the format in hardware; in PyTorch it is torch.bfloat16.

Sources

the term is written from these pages

Verified 18 Nov

Not to be confused with

what it is mixed up with and how it differs

  • FP8 and FP4 formats

    FP8 and FP4 are even shorter than BF16 and are used for speed and compression, while BF16 remains the default working format.

In depth in the references

where the topic is covered in detail