A silent gradient bug in AMD's attention kernels
In deterministic mode, its default, AMD's AITER flash-attention backward on MI350X returned a query gradient as large as the gradient itself in error, with no crash and no warning. This paper records how the bug was found, measured against float64 and traced to one addressing limit, and the fix proposed upstream.
Abstract
aiter.flash_attn_func(..., deterministic=True) on an AMD Instinct MI350X (gfx950) returned a wrong dQ, the gradient with respect to the queries, in the backward pass. Its normwise error against a float64 reference was 1.0 to 4.4, as large as dQ itself; dK, dV and the non-deterministic mode were correct. Because deterministic=True is the default of that function, training code that does not set the flag would learn from that dQ.
The error appears exactly where one fp32 accumulation buffer, read by the kernel that sums dQ's partial results (convert_dq), spans more than bytes: that kernel reads it through buffer instructions with 32-bit offsets, so later partials are read from the wrong place. A newer memory layout on AITER's main branch fixed the originally reported shapes but not long sequences with few heads per GPU. The proposed fix steps from one partial to the next with a 64-bit pointer. On aiter main it brought the error from 1.0 to 0.0024 (bf16 rounding) in every failing case tested and left every already-correct case bit-identical. The report is ROCm/aiter#8420; the fix is ROCm/rocm-libraries#16563 with a regression test in ROCm/aiter#8511, both open, not merged, as of 30 November 2026.
The problem
Attention training needs three gradients from the backward pass: dQ, dK and dV. FlashAttention-style kernels compute dK and dV per block of keys and accumulate dQ across key blocks. Accumulating with atomics is fast but not deterministic: the order of floating-point additions changes from run to run, so results differ bit for bit. A deterministic backward instead writes one fp32 partial dQ per key block into a workspace, dq_accum, and a second kernel, convert_dq, sums the partials in a fixed order.
A wrong gradient does not crash anything. The loss still goes down for a while; the model just learns from a different gradient than the one it should. The only reliable way to see it is to compare against an independent reference computed in higher precision.
Method
How it was found
On 19 November 2026 Riptide's attention kernels for MI350X were timed against AITER in the same session; on 20 November a second run, which also timed AITER's non-deterministic mode, compared the gradients of the implementations element by element. Riptide's backward is bit-for-bit repeatable. At long sequences, AITER's deterministic dQ disagreed with Riptide's by up to 21.7 in absolute value, while AITER's non-deterministic dQ agreed with Riptide's to within bf16 rounding (at most 0.016). dK and dV agreed everywhere. Two independent implementations agreeing with each other pointed at the third.

The float64 check
- Reference: float64 attention gradients of one (batch, head), computed with plain
torchmatrix multiplies on the GPU (row-blocked for 65,536 tokens so it fits in memory). - Metric: normwise error for each of dQ, dK and dV. With bf16 inputs and outputs, rounding alone gives about .
- Inputs: bf16,
torch.randn, shaped (batch, sequence, heads, head dim); 32 heads and 16,384 tokens per batch for the released-version check; batch 1 and 1 head for the long sequences on main (plus 2 × 32 and 8 × 64 controls); full and causal masks. - Machine: one AMD Instinct MI350X (gfx950, 256 compute units) on RunPod; ROCm 10.2.0, PyTorch 2.15.0+rocm10.2.0.
- Software under test:
amd-aiter0.1.7.post2.dev18, the versionpip install amd-aiterinstalled at the time (20 November 2026); then aitermainatcf16a55built from source against Composable Kernel (CK)f93c029, aiter's pinned CK (23 November 2026). On gfx950 at these shapes,deterministic=Truetakes CK'smha_bwdpath.
Results
The released version
| head dim | sequence | batch | dq_accum view span | deterministic dQ error (full / causal) |
|---|---|---|---|---|
| 64 | 4,096 | 4 | 3.91 GiB | 2.4e-3 / 2.4e-3 |
| 64 | 8,192 | 2 | 7.94 GiB | 1.0 / 1.0 |
| 64 | 16,384 | 1 | 16.0 GiB | 1.8 / 2.9 |
| 128 | 2,048 | 8 | 3.78 GiB | 1.4e-2 / 2.4e-3 |
| 128 | 4,096 | 4 | 7.81 GiB | 1.0 / 1.0 |
| 128 | 8,192 | 2 | 15.9 GiB | 1.3 / 1.9 |
| 128 | 16,384 | 1 | 32.0 GiB | 1.7 / 4.4 |
At head dim 64, 16,384 tokens, causal, the largest elementwise dQ error was 7.41 against a largest reference value of 2.47. Riptide's own backward matched float64 to bf16 rounding (2.2–2.5e-3) for dQ, dK and dV at every shape in the table. The same failure reproduced two days later in a separate harness (errors 1.0–4.3 at head dim 64, 8,192 tokens and head dim 128, 4,096 and 8,192 tokens; batch 4, causal).


Root cause
In the released layout, dq_accum is [nsplits, B, S, H, D] in fp32, with one split per 128-key block, . The writer computes each split's offset as a 64-bit pointer offset. convert_dq instead builds one tensor view over all splits from a per-(batch, head) base pointer and reads it through AMD buffer instructions, whose byte offset is a 32-bit index_t. The view spans
Once that passes bytes, the offsets wrap and the reads for later splits land on earlier splits. The 4 GiB line separates the correct shapes from the wrong ones exactly (Table 1 and the span chart below).


dq_accum view. Every shape above 2³² bytes is wrong; below it, every shape is within bf16 rounding except one (Limits).The size of the error fits as well. If groups of splits alias onto one another, each group's slices are read times; with roughly independent partial sums the expected normwise error is
which is 1.0 for and 1.73 for . The measured errors were 1.0 and 1.0 at 8 GiB, and 1.8 and 1.3 at 16 GiB (full masks). At 32 GiB (g = 8, model 2.65) the measured 1.7 fits less well. Causal shapes deviate more, because masked splits are zero and the groups are no longer equal.

Current main
aiter's main branch had meanwhile moved to a compact per-(batch, head) layout, so each view is much smaller and the originally reported shapes no longer cross 4 GiB. The 32-bit buffer reads were unchanged, which predicts the failure would return for long sequences with few heads per GPU, a common case in long-context training with heads sharded across GPUs. On main the deterministic batch mode is persistent, so grows as batch × heads shrinks, up to 256 at batch = heads = 1.
cf16a55 with CK f93c029, MI350X, bf16, before and after the proposed fix. Deterministic dQ error against float64, full / causal. dK, dV and the non-deterministic dQ were 2.2–2.5e-3 in every row, before and after.| head dim | sequence | batch × heads | estimated splits | before | after |
|---|---|---|---|---|---|
| 64 | 8,192 | 2 × 32 | 4 | 2.4e-3 / 2.4e-3 | 2.4e-3 / 2.4e-3 (bit-identical) |
| 128 | 1,024 | 8 × 64 | 1 | not run | 2.4e-3 / 2.5e-3 |
| 128 | 16,384 | 1 × 1 | 128 | 2.4e-3 / 2.4e-3 | 2.4e-3 / 2.4e-3 (bit-identical) |
| 128 | 32,768 | 1 × 1 | 256 | 2.4e-3 / 2.4e-3 | 2.4e-3 / 2.4e-3 |
| 128 | 65,536 | 1 × 1 | 256 | 1.01 / 1.00 | 2.4e-3 / 2.4e-3 |
| 256 | 16,384 | 1 × 1 | 128–256 | 1.00 / 1.00 | 2.4e-3 / 2.5e-3 |
| 256 | 32,768 | 1 × 1 | 256 | 1.01 / 1.00 | 2.4e-3 / 2.4e-3 |

The fix
The proposed change touches two files in CK's FMHA backward, deterministic path only:
- The kernel's deterministic
dq_accview now covers one split, lengths(1, seqlen_q, hdim_q), and passes the split stride (already a 64-bitlong_index_t) to the pipeline. - The reduce-and-convert pipeline reaches split by moving the view's base pointer by the split stride, in 64-bit pointer arithmetic, so every buffer access stays inside one split.
- The loop reads exactly splits. The old loop loaded one split past the end; inside the old view that read was out of bounds and returned zero, but with a moving base pointer it would read past the allocation.
- The summation order is unchanged, so results are bit-identical to before wherever the old code was correct (the two "bit-identical" rows of Table 2).
Variable-length batches (flash_attn_varlen_func) were checked with the patched build: mixed lengths with padding to the tile size and single long sequences, worst deterministic dQ error 2.4e-3 to 2.9e-3, matching the non-deterministic mode in every case.
flash_attn_varlen_func, worst deterministic dQ error over every sequence and head, full / causal.| head dim | heads | sequence lengths | after |
|---|---|---|---|
| 128 | 4 | 4,096, 1,000, 2,500, 77 | 2.4e-3 / 2.9e-3 |
| 64 | 2 | 3,000, 8,192, 129 | 2.4e-3 / 2.6e-3 |
| 128 | 1 | 65,536 | 2.4e-3 / 2.4e-3 |
| 256 | 1 | 32,768 | 2.4e-3 / 2.5e-3 |

Confirmation by a second contributor
On the same issue, a second contributor reproduced the limit on an MI355X (also gfx950) with aiter releases v0.1.23 and v0.1.28.post1, which use the compact layout: dQ was correct at the originally reported shapes and wrong again (error 1.0) once a single (batch, head) view passed 4 GiB, at head dim 64 and 128 with 65,536 tokens and head dim 256 with 32,768. They added one detail to the root cause: the buffer's range field is the view's byte size truncated to 32 bits, so reads at or past it return zero. They applied the same fix to the CK vendored in 0.1.7.post2.dev18 and reported 24 of 24 over-the-line trials wrong without it and 0 of 24 with it. They also traced the 1.4e-2 case at head dim 128, 2,048 tokens to a separate run-to-run race in a different backward pipeline (Limits, below).
Limits and open points
- Upstream status. The fix (ROCm/rocm-libraries#16563) and the regression test (ROCm/aiter#8511) were open, not merged and not yet reviewed on 30 November 2026 (the fix PR is labelled "Not ready to Review" pending a description check). Until a fixed release is published,
deterministic=Falsegave a correct dQ at every affected shape tested, at the cost of bit-for-bit repeatability. - One architecture. Only gfx950 (MI350X) was run for the fix. gfx942 (MI300X) was not tested.
- The 1.4e-2 case. At head dim 128, 2,048 tokens, full mask, the released version's dQ error was 1.4e-2 (about 6× bf16 rounding) with a view below 4 GiB. It is not explained by the addressing limit; the second contributor attributes it to a run-to-run race in the gfx950
dq_dk_dvpipeline, which this fix does not touch. - Split counts on main were estimated from the workspace code, not read from the kernel, so they may be wrong: the head-dim-256, 16,384-token shape failed on main although its view is estimated at 4 GiB or less, and the second contributor measured 171 splits (2.7 GiB), not 256, for head dim 128, 32,768 tokens on releases.
- Not distinguished. The norm of the wrong dQ was not recorded, so "zero reads" and "aliased sums" were not separated on main (the second contributor's range-field finding covers that).
- Variable-length mode was run only with the patch, not before it.
- Throughput of the patched
convert_dqwas not benchmarked.
Reproduction notes
- Released version.
pip install amd-aiter, setROCM_PATHto the pip ROCm SDK (AITER's JIT needs it), then run therepro.pyattached to ROCm/aiter#8420:python3 repro.py 64 8192is the smallest failing case. The first call to each backward variant JIT-compiles for about two minutes. - Main, before and after.
check_main.py D S [B H](one shape per process, float64 reference in row blocks) andcheck_varlen.py, with the raw before/after JSON lines, are in a gist linked from the fix. - Cost. Each check ran on one rented MI350X: the float64 gradient check took 15 minutes of pod time, the main-branch check about 20 minutes.
Timeline

| date | step |
|---|---|
| 19–20 Nov | Timing comparison on MI350X; deterministic dQ disagrees with two other implementations at long sequences |
| 20 Nov | float64 gradient check confirms a wrong dQ in amd-aiter 0.1.7.post2.dev18 |
| 21 Nov | Report filed: ROCm/aiter#8420, at the request of a Composable Kernel developer |
| 22 Nov | Reproduced in a second, independent harness |
| 23 Nov | aiter main checked: original shapes fixed by the new layout, long sequences still wrong |
| 23 Nov | Fix ROCm/rocm-libraries#16563 and test ROCm/aiter#8511 opened |
| 23 Nov | Confirmation on MI355X by a second contributor posted to the issue |
Date and version
Version 1, 30 November 2026. Measurements from 20 and 23 November 2026. This page will be updated when the fix is reviewed or merged.
Working with Riptide
Riptide works with a small number of teams. Each engagement starts with 4 weeks inside your systems, learning how your models, data and infrastructure work. Only then does Riptide apply its software to them. Contact samario@riptidecompute.com or riptidecompute.com/evaluate.