Broken Symmetry in BF16 Attention: Why FlashAttention Gradients Blow Up Late in Training
Organizations: Rutgers University · Carnegie Mellon University · Oracle · New York University · MBZUAI
Abstract
BF16 is now standard in large-scale pretraining, including in fused attention kernels such as FlashAttention, and these kernels are widely trusted. When we used FlashAttention-3 to pretrain a 450M-parameter transformer on 50B tokens, however, we ran into a problem: training was healthy for 25B tokens, then the gradient norm grew a thousandfold and the loss ended 0.2 nats above FP32 attention, without a single NaN. Recomputing the attention backward of just two layers in FP32 removes almost all of the excess gradient. Part of the cause is known: a fused multiply-add in the forward softmax, so far treated as an extreme-input NaN case and never fixed in FlashAttention-3. Repairing it stops the blow-up, but the query gradient is still wrong by more than its own size, and training still drives attention logits to thousands of times their size under accurate gradients. The remaining error comes from a broken conservation law. The softmax score gradient sums to zero along every row, which makes the query gradient blind to where the keys sit as a group; rounding it to BF16 leaves a small nonzero sum that leaks the mean key into the gradient, and the leak grows exactly as late training makes keys large and attention sharp. We introduce GProj (gauge projection), which restores the zero sum after the cast with two rank-one corrections per row. It cuts the remaining median query/key gradient errors from 219%/13% to 0.34%/0.37%, on par with FP32 attention, for 4.7% more time per training step. In matched from-scratch runs it trains to the same loss as FP32 attention, while FlashAttention-3 and key smoothing both destabilize.
Figures & tables
| Input: BF16 ; FP32 ; scale ; key tiles , query tiles . | |
| Output: BF16 . Accumulators and row statistics are FP32. | |
| 1 | ; ; , , |
| 2 | for each key tile in parallel do |
| 3 | Load ; , |
| 4 | for each query tile that attends to tile do |
| 5 | Load ; ; (masked) |
| Method | (%) | (%) | (%) |
|---|---|---|---|
| FA3 | 773 | 85.6 | 0.369 |
| QY-shift (source-faithful) ‡ | 1307 | 264 | 80.5 |
| FA3-SBS | 219 | 13.3 | 0.334 |
| GProj-Q | 0.342 | 13.3 | 0.334 |
| GProj | 0.342 | 0.371 | 0.334 |
| FP32 attention (eager) † | 0.384 | 0.371 | 0.165 |
| Method | |||
|---|---|---|---|
| FA3 | 0.2601 / 4794.33 | 0.2537 / 4.1051 | 0.2239 / 0.7657 |
| FA3-SBS | 0.2601 / 4794.53 | 0.2535 / 4.1050 | 0.2239 / 0.7657 |
| GProj | 0.2238 / 2.4938 | 0.2219 / 2.7565 | 0.2239 / 0.7657 |
| Run (tokens) | Layers with logit scale | Logit scale L5 / L11 | Layer 11 rms / | Layer 11 rows | Layer 11 error FA3 / cuDNN |
|---|---|---|---|---|---|
| FA3 (23.1B) | 5, 11 | 5,436 / 5,519 | 71 / 78 | 86% | 4.5 / 2.2 |
| FA3 (33.6B) | 5, 11 | 12,843 / 51,057 | 213 / 240 | 99.4% | 253 / 5.6 |
| FA3-SBS (33.6B) | 4, 5, 11 | 39,205 / 49,158 | 216 / 227 | 99.6% | 85 / 2.5 |
| Key smoothing (33.6B) | 5, 11 | 10,905 / 17,272 | 124 / 139 | 74% | 30 / 1.1 |
| GProj (33.6B) | none (max 26) | 8 / 7 | 2 / 3 | 0% | 0.12 / 0.12 |
| FP32 attention (33.6B) | none (max 27) | 7 / 7 | 2 / 3 | 0% | 0.13 / 0.13 |
| Method | ms/update | vs. FA3 | peak GiB |
|---|---|---|---|
| (1) GProj comparison | |||
| FA3 | 227.357 | +0.00% | 9.191 |
| FP32 attention (eager) | 719.420 | +216.43% | 9.182 |
| GProj | 238.120 | +4.73% | 9.191 |
| (2) optimized FP32 comparison | |||
| FA3 | 231.031 | +0.00% | 9.191 |
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Method | Forward | Backward | Saved output |
|---|---|---|---|
| FA3 | BF16 FA3 | Native mixed precision | BF16 |
| FA3-SBS | Subtract-before-scale FA3 | Native mixed precision | BF16 |
| Key smoothing | FA3 on mean-subtracted keys | Native mixed precision | BF16 |
| QY-shift | Author-source dynamic shift | Author-source BF16 arithmetic | BF16 |
| GProj | Subtract-before-scale FA3 | Dense query/key projection | BF16 |
| FP32 attention | FP32 attention | FP32 attention | See below |
| Capture | GProj | FP32 | ||||
|---|---|---|---|---|---|---|
| 0 | 0.3223 | 0.2942 | 0.1699 | 0.4203 | 0.3290 | 0.1592 |
| 1 | 0.2504 | 0.2397 | 0.1924 | 0.2245 | 0.2216 | 0.1648 |
| 2 | 0.2669 | 0.3183 | 0.1734 | 0.2799 | 0.3411 | 0.1603 |
| 3 | 0.2668 | 0.2855 | 0.1966 | 0.4146 | 0.3760 | 0.1639 |
| 4 | 1.2604 | 1.8577 | 1.0888 | 1.0951 | 2.7637 | 0.1771 |
| 5 | 0.4158 | 0.5350 | 0.4715 | 0.3552 | 0.3657 | 0.1648 |
| Capture | Checkpoint | Layer | Document |
|---|---|---|---|
| 0 | 5500 | 11 | P |
| 1 | 5500 | 5 | P |
| 2 | 5500 | 11 | D |
| 3 | 5500 | 5 | D |
| 4 | 8000 | 11 | P |
| 5 | 8000 | 5 | P |
| Tokens (B) | FA3 | FA3-SBS | GProj | Key smoothing | FP32 attention |
|---|---|---|---|---|---|
| 0.8 | 4.624 / 0.827 | 4.635 / 0.790 | 4.623 / 0.918 | 4.618 / 0.804 | 4.625 / 0.852 |
| 12.6 | 1.870 / 0.406 | 1.871 / 0.360 | 1.869 / 0.312 | 1.870 / 0.373 | 1.869 / 0.372 |
| 23.1 | 1.783 / 0.358 | 1.779 / 0.375 | 1.773 / 0.403 | 1.776 / 0.329 | 1.772 / 0.359 |
| 29.4 | 1.909 / 3.871 | 1.783 / 0.325 | 1.773 / 0.385 | 1.790 / 0.355 | 1.773 / 0.288 |
| 33.6 | 2.122 / 375.508 | 1.780 / 0.364 | 1.769 / 0.396 | 1.937 / 7.381 | 1.769 / 0.354 |
| 37.7 | 2.107 / 446.931 | 1.753 / 0.279 | 1.740 / 0.324 | 1.932 / 4.789 | 1.740 / 0.375 |
| Setting | Configuration |
|---|---|
| Parameters | 449,465,344; referred to as 450M in the main text |
| Transformer | 24 layers, hidden width 1024 |
| Attention | 16 query heads, four key/value heads, head dimension 64 |
| Vocabulary | 64,256; untied input and output embeddings |
| Sequence length | 4096 tokens |
| Attention backend | Native BF16 FlashAttention-3 |
| After saved | |||||||
|---|---|---|---|---|---|---|---|
| Ckpt. | Layer | rel. err. | Resid. frac. | Err. cos. | Saved- red. | rel. err. | cos. |
| 5500 | 5 | 6.517 | 0.0055 | 1.0000 | 2.98 | 2.165 | 0.419 |
| 5500 | 11 | 6.120 | 0.0060 | 1.0000 | 2.45 | 2.496 | 0.366 |
| 8000 | 5 | 17.889 | 0.0067 | 1.0000 | 15.73 | 1.055 | 0.686 |
| 8000 | 11 | 411.104 | 0.0197 | 0.9999 | 72.02 | 5.988 | 0.156 |
| Backward intervention at layers 5 and 11 | 6500 | 8000 |
|---|---|---|
| Native | 36.653 | 5353.856 |
| Replace saved , first row only | 36.402 | 5353.857 |
| Exact first-row VJP only | 36.402 | 5353.857 |
| Replace saved , all rows | 2.450 | 19.746 |
| FP32 VJP, all rows | 2.258 | 18.185 |
| Saved | Saved LSE | error reduction | error reduction |
|---|---|---|---|
| FA3-SBS | FA3 | – | – |
| FA3 | FA3-SBS | – | – |
| FA3-SBS | FA3-SBS | – | – |
| Backend | error | error | cosine | Late L11 error | One-key violations |
|---|---|---|---|---|---|
| FA3 | 7.729 | 0.8555 | 0.131 | 162.3 | 6/96 |
| FA3-SBS | 2.187 | 0.1327 | 0.414 | 4.12 | 0/96 |
| FA2, 2.8.3.post1 | 7.729 | 0.8555 | 0.131 | 162.3 | 6/96 |
| SDPA cuDNN | 2.206 | 0.1287 | 0.412 | 4.16 | 0/48 |
| SDPA flash | 2.217 | 0.1289 | 0.410 | 3.90 | 0/96 |
| SDPA efficient, KV expanded | 2.147 | 0.1271 | 0.422 | 4.04 | 0/96 |
| Seed | LR | Rel. err. 0 | Rel. err. 250 | Rel. err. 500 | Abs. err. 500 | Cosine 500 |
|---|---|---|---|---|---|---|
| 2026 | 1 | 0.00177832 | 0.00187079 | 0.00261074 | 0.00498338 | 0.999996597 |
| 2026 | 4 | 0.00177832 | 0.00340782 | 0.0243191 | 0.0514253 | 0.999706727 |
| 2027 | 1 | 0.00193911 | 0.00194124 | 0.00264846 | 0.00479022 | 0.999996495 |
| 2027 | 4 | 0.00193911 | 0.00345874 | 0.0156458 | 0.0314603 | 0.999878256 |
| 2028 | 1 | 0.00186521 | 0.00200166 | 0.0026835 | 0.00528956 | 0.999996407 |
| 2028 | 4 | 0.00186521 | 0.00360284 | 0.015028 | 0.0348366 | 0.999897825 |
| Seed | Peak step | Native norm | Reference norm | Rel. error | Cosine |
|---|---|---|---|---|---|
| 2026 | 5054 | 4913.875 | 4988.690 | 0.018294 | 0.999944 |