An example: take four token probabilities near the top of a distribution.
In fp32, A is the most likely token. In bf16, A and B are the same number.
Near 0.3, bf16 values sit 0.00195 apart: 0.29883, 0.30078, 0.30273. So 0.30090 and 0.30103 both round to the same value, 0.30078.
bf16 keeps fp32's range and throws away most of its precision. Google's TPU docs say the two have the same dynamic range. Going from bf16 back to fp32 just pads 16 zeros onto the mantissa.
Here is why nearby numbers merge:
- A float is a mantissa times a power of two. The exponent bits set the range. The mantissa bits split each stretch from one power of two to the next into equal steps.
- fp32 stores 23 mantissa bits, and bf16 keeps 7. So bf16 has 27=128 steps per stretch.
- Between 0.25 and 0.5, neighboring bf16 values sit 0.25×2−7=0.00195 apart. Anything in between rounds to one of the two. On TPU the rounding is round to nearest even.
In the editor, write to_bf16(x), then run it on the four probabilities from the table. A and B should come out equal.