Where in attention is FP32 still used, and what breaks if you push everything to FP16/BF16?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Matmuls run in FP16/BF16 to use tensor cores; softmax stays in FP32 (or uses running-max stabilization) because exp overflows FP16's ~65504 ceiling.
Imagine a tiny notebook that can only write numbers up to about 65,000. Most of the math in attention is fine, because you're adding lots of small numbers and the result stays in range. But one step asks you to write down e raised to a fairly big number. e to the 11 is already around 60,000. e to the 12 doesn't fit at all. So that one step either needs a bigger notebook with more room, or a clever trick where you shift every number down by the largest one before you write it. Picture using a regular pad for most work and pulling out a giant whiteboard only for that one tricky step.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Walk through which ops live in which precision, give the FP16 overflow numerics for exp, distinguish BF16 vs FP16, describe FlashAttention's online softmax with FP32 running stats, and note FP8 attention on H100 as the active frontier.
| Operation | Typical precision | Why |
|---|---|---|
| Q,K,V projections | FP16/BF16 (FP8 on H100) | Tensor core throughput; robust to element-wise error |
| QKᵀ matmul | FP16/BF16 inputs, FP32 accumulator | Tensor core throughput; accumulator preserves precision |
| Softmax exp + sum | FP32 (or stabilized online softmax) | Avoid exp overflow; preserve small probabilities |
| @V matmul | FP16/BF16 inputs, FP32 accumulator | Same as QKᵀ |
| Output projection | FP16/BF16 | Standard low precision matmul |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking the matmuls are the problem and softmax is fine. It's the opposite: matmuls are robust in FP16; softmax's exponential is what overflows.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.