Explore the research collection
2 entries · Follow this search
- Paper
Broken Symmetry in BF16 Attention: Why FlashAttention Gradients Blow Up Late in Training
Diagnoses a late-training blow-up training a 450M transformer on 50B tokens with FlashAttention-3 in BF16: healthy for 25B tokens, then gradient norm grows 1000x and loss ends 0.2 nats above FP32 attention — with no NaNs at all. Recomputing just two layers' attention backward in FP32 removes almost all excess gradient. Part of the cause is known (a fused multiply-add in the forward softmax, never fixed in FA3); repairing it stops the blow-up but leaves the query gradient wrong by more than its own size (219% median error). The deeper cause is a broken conservation law: the softmax score gradient dS sums to zero along every row, making dQ blind to where the keys sit as a group; rounding dS to BF16 leaves a small nonzero sum that leaks the mean key into dQ — and the leak grows exactly as late training makes keys large and attention sharp. Fix: GProj (gauge projection), which restores the zero row sum after the cast with two rank-one corrections per row — cuts median dQ/dK errors from 219%/13% to 0.34%/0.37% (FP32-attention level) for 4.7% more step time; in matched from-scratch runs it reaches the same loss as FP32 attention while FA3 and key smoothing destabilize. KohakuBlueleaf replied on the thread reporting the same class of precision bug in FA4/cuDNN/flex attention and their KohakuFA fix. If a BF16 run blows up late with no NaNs, check the attention backward. Directly relevant to the user's LLM training-run debugging work.
- Paper
You Need Better Attention Priors
Generalizes attention through the lens of Entropic Optimal Transport (EOT): standard attention corresponds to a transport problem regularized by an implicit uniform prior. GOAT (Generalized Optimal Transport Attention with Trainable priors) replaces that naive assumption with a learnable, continuous prior that decouples spatial geometry from token semantics — standard positional encodings (e.g., RoPE) entangle position with meaning and corrupt semantic representations when forced to handle structural biases like attention sinks. The prior maintains full compatibility with optimized kernels like FlashAttention (zero compute overhead). GOAT also provides an EOT-based explanation of attention sinks and a solution that avoids standard attention's representational trade-offs. By absorbing spatial information into the core attention computation, GOAT learns an extrapolatable prior combining the flexibility of learned positional embeddings with the length generalization of fixed encodings — strong long-context extrapolation beyond training length.