liveBook · Manning

Numerical overflow

As explained in GPU Programming with Triton

A numerical condition in which a computed value exceeds the range representable by its number format.

Numerical overflow occurs when a computed value exceeds the finite range of its number format. In float32, exp(88.7) is already about 3.3 × 10³⁸; in float16, exp(12) overflows. Infinities can propagate into NaNs and destabilize training or inference. section 4.2.1

Softmax avoids this problem by subtracting the vector maximum before exponentiation. Because adding the same constant to every input leaves softmax unchanged, this shift preserves the result while making the largest exponent exp(0) = 1. The maximum is found by a reduction, then broadcast across the vector. section 4.2.1 section 4.1.1

Figure 4.7 (Left) Dynamic range and precision comparison between FP32 and FP16. FP32 covers a far wider range with finer spacing between representable values. (Right) Bit-level breakdown showing how both formats encode the same number, with FP16 producing a less precise result due to its shorter mantissa.
CH04 F07 Fartale

Compare the dynamic range and precision of FP32 and FP16, which affect how readily computations overflow. section 4.2.1

How GPU Programming with Triton covers it

How deep it goes
Quantifies float32 and float16 overflow thresholds and derives max-shifted softmax, while deferring its kernel implementation.
Examples
Uses exp(88.7) in float32, exp(12) in float16, and logits or attention scores as examples.
What you can do after
Apply max-shifted softmax to prevent exponential overflow while preserving the normalized result.
How it connects
Connects overflow to softmax, reductions, floating-point precision, and attention scores.

Also explained in

Compare how 8 books explain numerical overflow →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GPU Programming with Triton. The section links point to the parts of the book it draws on.