RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Whitepapers · AMD Instinct · Correctness case study

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.

Version
1
Date
30 November 2026
Author
Samario Torres, Riptide
Software
amd-aiter 0.1.7.post2.dev18 and aiter main cf16a55 (Composable Kernel f93c029), ROCm 10.2.0, PyTorch 2.15.0
Download PDFOpen in new tabriptidecompute.com/whitepapers/amd-attention-gradient-bug

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.

Log-scale paired bars of maximum dQ difference from Riptide for AITER deterministic and non-deterministic modes across shapes; deterministic reaches 0.4 to 21.7 at long sequences
Figure 1. How it was noticed (20 November): the largest dQ difference from Riptide’s gradients. AITER’s non-deterministic mode agrees with Riptide to bf16 rounding; its deterministic mode does not at long sequences.

The float64 check

  • Reference: float64 attention gradients of one (batch, head), computed with plain torch matrix 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-aiter 0.1.7.post2.dev18, the version pip install amd-aiter installed at the time (20 November 2026); then aiter main at cf16a55 built from source against Composable Kernel (CK) f93c029, aiter's pinned CK (23 November 2026). On gfx950 at these shapes, deterministic=True takes CK's mha_bwd path.

Results

The released version

Table 1. amd-aiter 0.1.7.post2.dev18 on MI350X, bf16, 32 heads, 16,384 tokens per batch. dQ normwise error against float64, deterministic mode, full / causal. dK, dV and the non-deterministic dQ were 2.2–2.5e-3 in every row.
head dimsequencebatchdq_accum view spandeterministic dQ error (full / causal)
644,09643.91 GiB2.4e-3 / 2.4e-3
648,19227.94 GiB1.0 / 1.0
6416,384116.0 GiB1.8 / 2.9
1282,04883.78 GiB1.4e-2 / 2.4e-3
1284,09647.81 GiB1.0 / 1.0
1288,192215.9 GiB1.3 / 1.9
12816,384132.0 GiB1.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).

Two log-scale panels of dQ error against sequence length; AITER deterministic jumps from 2.4e-3 to about 1 and above, the other implementations stay in the bf16 band
Figure 2. dQ error against float64 by sequence length, amd-aiter 0.1.7.post2.dev18 on MI350X. The grey band is bf16 rounding; solid lines full mask, dashed causal.
Log-scale grouped bars of dQ, dK and dV error in deterministic mode; only dQ rises above bf16 rounding
Figure 3. Deterministic mode, full mask: dK and dV stay at bf16 rounding at every shape; only dQ is wrong.

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).

Diagram of eight splits in the dq_accum buffer with a 4 GiB line after split 3; arrows show splits 4 to 7 read from the positions of splits 0 to 3
Figure 4. Why later partial results are read from the wrong place: with one 32-bit-addressed view over every split, offsets past 4 GiB wrap onto earlier splits. The fix moves a one-split view by a 64-bit pointer step.
Log-log scatter of deterministic dQ error against bytes spanned by the dq_accum view, with a dashed line at 4 GiB; every point right of the line is wrong
Figure 5. Deterministic dQ error against the bytes spanned by the 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.

Curve of the expected error against the number of aliased groups g, with measured points at g = 2 and g = 4
Figure 6. The aliasing model against the measured full-mask errors at 8 GiB (g = 2) and 16 GiB (g = 4) views.

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.

Table 2. aiter main 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 dimsequencebatch × headsestimated splitsbeforeafter
648,1922 × 3242.4e-3 / 2.4e-32.4e-3 / 2.4e-3 (bit-identical)
1281,0248 × 641not run2.4e-3 / 2.5e-3
12816,3841 × 11282.4e-3 / 2.4e-32.4e-3 / 2.4e-3 (bit-identical)
12832,7681 × 12562.4e-3 / 2.4e-32.4e-3 / 2.4e-3
12865,5361 × 12561.01 / 1.002.4e-3 / 2.4e-3
25616,3841 × 1128–2561.00 / 1.002.4e-3 / 2.5e-3
25632,7681 × 12561.01 / 1.002.4e-3 / 2.4e-3
Log-scale paired bars per shape on aiter main: before the fix, three shapes (six bars, full and causal) at error 1.0 in red; after, every shape at 2.4e-3
Figure 7. aiter main on MI350X with batch × heads small, before (red where wrong, grey where correct) and after the fix.

The fix

The proposed change touches two files in CK's FMHA backward, deterministic path only:

  • The kernel's deterministic dq_acc view now covers one split, lengths (1, seqlen_q, hdim_q), and passes the split stride (already a 64-bit long_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.

Table 3. Patched build, flash_attn_varlen_func, worst deterministic dQ error over every sequence and head, full / causal.
head dimheadssequence lengthsafter
12844,096, 1,000, 2,500, 772.4e-3 / 2.9e-3
6423,000, 8,192, 1292.4e-3 / 2.6e-3
128165,5362.4e-3 / 2.4e-3
256132,7682.4e-3 / 2.5e-3
Bars of worst deterministic dQ error for eight variable-length configurations with the fix, all between 2.37e-3 and 2.94e-3
Figure 8. Variable-length batches with the fix: worst deterministic dQ error over every sequence and head.

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=False gave 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_dv pipeline, 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_dq was not benchmarked.

Reproduction notes

  • Released version. pip install amd-aiter, set ROCM_PATH to the pip ROCm SDK (AITER's JIT needs it), then run the repro.py attached to ROCm/aiter#8420: python3 repro.py 64 8192 is 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) and check_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

Timeline from 19 to 30 November 2026: timing comparison, float64 check, report filed, second harness, fix and test opened, fix still open
Figure 9. Timeline of the finding, the report and the fix.
Table 4. Public record, all dates 2026 (UTC).
datestep
19–20 NovTiming comparison on MI350X; deterministic dQ disagrees with two other implementations at long sequences
20 Novfloat64 gradient check confirms a wrong dQ in amd-aiter 0.1.7.post2.dev18
21 NovReport filed: ROCm/aiter#8420, at the request of a Composable Kernel developer
22 NovReproduced in a second, independent harness
23 Novaiter main checked: original shapes fixed by the new layout, long sequences still wrong
23 NovFix ROCm/rocm-libraries#16563 and test ROCm/aiter#8511 opened
23 NovConfirmation 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.