In the bf16 post the starting point was a cap: GeForce runs fp16, bf16 and tf32 tensor-core matmuls with fp32 accumulation at half the rate the silicon can do. int8 accumulates in int32 and is not capped, which is how the block linears of my LoRA trainer ended up on int8 GEMMs. That left attention. Attention is the other big term in a DiT step, it is not a plain GEMM, and int8 attention is a different and much harder project. But the cap has a second loophole that needs no quantization at all: fp16 inputs accumulating into fp16 run at full rate. The throttle is on the fp32 accumulator, not on the 16-bit inputs.
bf16 cannot take that path. In CUTLASS's sm80 instruction set the only bf16 MMA is f32.bf16.bf16.f32; the fp16 atom f16.f16.f16.f16 exists and the bf16 one does not, because bf16 has three decimal digits of mantissa and nobody wanted a sum of 4000 terms in it. So "use the uncapped path" means two things at once: cast the inputs to fp16, which has three more mantissa bits than bf16 and a far narrower range, and accumulate in fp16, which no one does for a sequence-length sum.
The trick is that nobody has to. FlashAttention already loops over the sequence in tiles. Inside a tile the sum is 32 keys long and bounded; across tiles there is an accumulator that can be whatever precision you like. The whole patch is: run the MMA in fp16 into a per-tile fragment, then add the fragment into the fp32 accumulator once per tile.

This post is the record of building that into FlashAttention 2.8.3 for an RTX 5070 Ti (sm_120), of which GEMMs could take it and which could not, of the two scaling tricks that keep the small gradients out of fp16's subnormals, and of an ncu session that explained why a 2x instruction gives a 1.25x kernel. The result ships as a wheel (sorryhyun/flash-attention-fp16) and is what my trainer runs by default on 50-series cards.
Why FA2, after the FA4 post
In March I got FlashAttention 4 running on a 5060 Ti. This work is on FA2, for a reason that has nothing to do with which is faster: FA2's backward is a few hundred lines of CuTe C++ in which the MMA atom is a type alias. Swapping SM80_16x8x16_F32BF16BF16F32_TN for SM80_16x8x16_F16F16F16F16_TN on one GEMM is a local edit, and the per-tile drain is a 20-line device function. The same change in a DSL kernel that assumes an fp32 accumulator layout would be a rewrite. sm_120 also runs FA2's sm80 kernels unchanged; it is an SM80 execution model with a Blackwell badge, as the FA4 post found, and that is exactly what makes a 2020-era kernel the right one to patch.
There was a small free gain on the way in. run_mha_fwd_hdim128 picks its forward tile from the compute capability and has no option for it. Capability 12 is not 8.6 or 8.9, so it falls to the A100 / H100 branch, 128×64, although sm_120 has the ~100 KB of shared memory per block that sent the 8.6 / 8.9 cards to 128×32. One line (is_sm8x also true on cc_major == 12) gives 5.5% on the forward and 0.7% of a training step, at unchanged error. Not the post, but it is in the wheel.
Which GEMMs can accumulate in fp16
The backward has five GEMMs per tile: S = QKᵀ (recomputed, since FA stores only the logsumexp), dP = dO·Vᵀ, dV = Pᵀ·dO, dQ = dS·K and dK = dSᵀ·Q. Before touching CUDA I prototyped each one in Triton on 24 captured self-attention calls from Anima (real Q, K, V, dO at σ 0.1 / 0.5 / 0.9, blocks 0 to 27), scored against fp32 autograd, one arm per GEMM:
The part I feared was free. dQ = Σ dS·K and dK = Σ dSᵀ·Q are signed, near-cancelling sums, the textbook case for accumulator precision, and fp16 moves them by at most 1%. The part I had not thought about was the one that broke. QKᵀ in fp16 puts dK and dV at twice the error, not because the logits are wrong by much, but because the backward's logits no longer match the forward's logsumexp: P = exp(S − lse) is off by a rounding, and dS = P·(dP − δ) is a difference of near-equal terms that amplifies it. An fp16acc forward shares part of that rounding and takes it down to 1.7–1.9x, which passes my gate and is the fastest arm. I gave up 7% of its speed for a third of its error and left QKᵀ on fp32 accumulation, in the forward and the backward.

The one real failure in the no_s arm was dV's worst call, 3.74x, and all five worst calls were block 0. There P·dO is small enough that fp16 loses it: P is a softmax weight, dO in a diffusion model is around 1e-7 before any scaling, and the product goes subnormal. A per-row scale fixed it for 0.21 ms. A fixed gain fixed it for nothing: store P × 256. With P ≤ 1 and |dO| ≤ 1 a 64-query tile stays under 16384, and dS and dV divide the gain back out.
Two scales to stay inside fp16
That |dO| ≤ 1 is the other half of the range problem. bf16 has fp32's exponent; fp16's normal range starts at 6.1e-5 and ends at 65504. Captured dO sits around 1e-7, which is already in fp16's subnormals before anything is multiplied by it. So the pre-kernel that FA2 already runs (it computes δ = Σ dO·O per row) also takes amax(|dO|) per (batch, head), divides dO by it and stores the fp16 copy. dQ, dK and dV come out scaled and are multiplied back on the way out, as bf16 through the same 16-bit paths as stock. The scale has to be per (batch, head), not per row: dK and dV sum over rows, and a per-row factor cannot be undone after the sum.

The top end is a check rather than a trick. Q, K and V are cast to fp16 with no clamp, so anything past 65504 is a NaN, which is the right failure mode: loud, not a quiet bias. On 24 real MOSS-Image steps, 91 sampled calls, |V| peaks at 304 and Q and K at 77; Σ|V| per row, the bound on |dP|, is 9075, 7.2x under the limit, and the values rebuilt in fp32 sit further under it. Both models I train use QK-norm. A model without it, or with a V outlier channel, could sit elsewhere, and the wheel does not check.
What this leaves as a known weak spot is dS. It is stored in fp16 with no gain, because its range depends on dP, and when dP is small (small V, or a head whose dO rows are far below its largest one) and attention is spread over many keys, dS falls into the subnormals and dQ and dK lose precision. On a synthetic grid, L 8192, uniform attention, V scaled to 0.01 and one dO row ×1000, dQ and dK reach 38–48x stock's error; on every real call of both models they stay under it. The stock fp16 kernel on fp16 inputs has the same weak spot, since it stores dS the same way. The stock bf16 kernel does not.
The CUDA port
The patch is one new translation unit, flash_bwd_hdim128_fp16acc_sm80.cu, with a kernel-traits struct on the fp16 kernel and the four fp16 MMA atoms, and a dispatch in mha_bwd that takes it for bf16 input at head dim 128 with no dropout, causal mask, window, alibi, softcap or deterministic, and num_heads_k == num_heads. Anything else takes stock. FLASH_ATTN_FP16ACC=0 forces stock in-process, which is how every A/B below was run: the same build, flag off and on.
Per call on the 5070 Ti, ms:
Cross-attention loses 2%: with 512 keys there are eight tiles, and the three fp16 casts of Q, K and V plus the dO reduction cost more than eight tiles' worth of HMMA saves. It is 0.19 ms of a 430 ms step and not worth a second dispatch rule.
Error against fp32 on 48 captured calls, as a multiple of stock FA2's, dQ / dK / dV:
Below one everywhere, worst single call 1.05x. That reads as a paradox until the baseline is named: the comparison is to the stock bf16 kernel, the path these calls would otherwise take, which stores P and dS in bf16 between its GEMMs. fp16 storage of P and dS gains more than fp16 accumulation loses. Against the stock fp16 kernel on fp16-cast inputs with fp32 accumulation, this backward is 4.4–5.5x further from fp32. So the honest statement is: on a bf16 model, this is a faster backward that is also slightly more accurate; on an fp16 model, it would be a faster backward that is less accurate.
Real steps, same build, flag off and on, on the trainer's default plan (int8 base, fp32 stream, torch.compile, activation budget 0.3):
MOSS's LoRA gradient keeps its distance from fp32 (1.000–1.005x). Renders of the two 240-step LoRAs show no artifact on either side, and I did not score them: FA2 is non-deterministic, stock against itself already differs, and there is no floor to read a pixel difference against.
The forward, with a gate
The forward has two GEMMs, QKᵀ and PV, and with QKᵀ settled the only candidate is PV. The same drain pattern applies: P and V in fp16, the MMA into an fp16 fragment per 32-key tile, added into the fp32 O. The forward call runs 1.15–1.17x on the self-attention shapes, O lands at 0.96–1.00x stock's error, and a 1024² MOSS-Image render (50 steps, CFG 3) goes from 10.6–10.9 s to 10.3 s. Putting QKᵀ in fp16 too (FLASH_ATTN_FP16ACC_FWD=all) gives 1.35x on the forward and is fine for generation on its own, but training through it brings back the dK / dV cost from the Triton table (1.5–1.7x), so it stays opt-in.
The decision in the forward was the gate. The casts are a fixed cost per call and the HMMA saving is per tile, so there is a key count under which the patch loses:

The crossover is between 768 and 1024 keys on both shapes, so calls with fewer than 1024 keys keep the bf16 forward. Anima's cross-attention over 512 text tokens is the main one that stays. The threshold is this card's; I did not re-tune it per device.
Where the 2x went
A reviewer asked the right question: fp16-accumulate HMMA is 2x on GeForce, so why is the backward 1.24x? ncu with locked clocks on the MOSS self shape, kernel alone:

The HMMA did halve: tensor-busy time went 7.5 → 4.3 ms, against 4.5 expected with QKᵀ left on fp32. What is exposed is the drain. Each tile's four fp16 fragments are converted and added into fp32, 28672 elements per tile, and 72 × 72 tiles × 24 heads × 28672 is 3.57 G, which is the cvt count to three digits. With two warps per scheduler that work does not hide behind the tensor pipe, and the kernel's non-tensor time goes 0.7 → 1.5 ms.
The obvious fix is to drain less often. Only dK and dV live across the query loop (dP is consumed into dS within the tile and dQ goes out through an atomic add), and two tiles keep dV under 2 × 64 × 256 < 65504, so their fp16 partials can be kept across two tiles and drained every second one. That cut FMA-pipe instructions 318 → 253 M and total warp instructions 5.6%, and the kernel ran 5.5% slower, 6.13 ms. With a runtime if (drain) the ALU pipe took 54 M extra moves; with the loop body unrolled into (no drain, drain) pairs those went away and it was still 6.13 ms, tensor pipe 72%. The partial kept across tiles chains each tile's first HMMA on the previous tile's last. The per-tile clear() I was trying to remove is what had left the tiles independent for ptxas to overlap, and the overlap was worth more than the adds. Double-buffering the partials would need 32 more registers at 245. I left the kernel as it is.
The other thing I tried and dropped was outside the kernel. The three fp16 casts and the abs temporary cost 0.34 ms of the 5.6 ms backward, so I had the forward return its fp16 copies of Q, K and V and the backward take them with no cast: forward + backward 7.95 → 7.73 ms per call, bitwise the same gradients. On a real training step it was 55 ms slower and 0.16 GB higher at the peak. Three extra tensors saved per attention call changed what torch.compile's activation budget keeps and what it recomputes, and the recompute was worth more than the casts. It was released for one day and reverted. Per-call benchmarks do not see the autograd graph.
Shipping it
The wheel builds on torch's stable ABI (TORCH_TARGET_VERSION 2.12), so one cp310-abi3 file loads on every torch from 2.12 up for the CUDA major it was built with, instead of one wheel per torch minor. The one thing the stable ABI cannot do is dropout, which needs a generator, so dropout raises. The build holds sm_120 only and head dims 64 and 128 (MOSS-Image's attention and Anima's llm_adapter); any other head dim raises rather than falling to a kernel that is not there. Patches, build.sh (about 11 minutes at MAX_JOBS=6), the smoke test and the error grid are in the repo. In my trainer uv sync --no-default-groups --group fa2-sm120 installs it; everything else on the venv, ComfyUI included, gets it too.
What I would check before using it on another model: the |V| and Σ|V| bounds above, since a V outlier past a few thousand gives NaN and the kernel will not tell you why; and whether the model has heads with a dO row far above the rest, which is the dS underflow case. grid.py measures both against fp32 in a minute. On a bf16 diffusion model with QK-norm, which is most of them now, it is 5% of a step for nothing.
What it adds up to
The bf16 post ended with the observation that precision belongs where it is cheap, and found a place where bf16 was costing accuracy that fp32 bought back for 1.5% of the time. This is the mirror image. Inside a 32-key tile, fp16 accumulation costs no accuracy that anyone can measure on a real call, and fp16 storage of P and dS between the GEMMs actually buys some, because fp16 has the mantissa bits bf16 gave away for range that the tile never uses. The range lives across tiles, in the fp32 accumulator, where the add is cheap. The one GEMM that refused is the one whose output has to agree bit-for-bit with a number computed somewhere else, the forward's logsumexp, and that is a consistency constraint, not a precision one.
The 2x on the instruction became 1.25x on the kernel and 5% on the step, which is about what an honest accounting of Amdahl predicts and less than I hoped. The drain that eats the difference is the price of keeping the fp32 sum, and the one attempt to pay less for it ran slower for a reason that only ncu could show. I will take the 5%.
Environment: RTX 5070 Ti, CUDA 13.2, PyTorch 2.14, FlashAttention 2.8.3 + patches, MOSS-Image (5B DiT, 24 heads × 128) and Anima (16 heads × 128).