Repository navigation
Conversation
The V tile goes TDM -> LDS -> registers whole, so the last page's slots past seq_len (which the sequence does not own) reach the PV WMMA, and so do the padded tiles the reordered loops (variants 1 and 2) run past the end when a program has fewer than 3 tiles (their block id is clamped to the table's last entry). P is 0 there, but 0 * a stale NaN/Inf = NaN. AttentionProgram keeps seq_len and gets mask_v(v, j), a select that zeroes the rows of tile j at or past seq_len, in registers after the LDS read. It is applied only where such rows can be: the last tile of loop variant 0, the three epilogue tiles of variants 1 and 2. Steady-state tiles, the TDM loads and the output store are unchanged. A plain select, not a branch around it: a branch moves the block boundary and the softmax next to it is contracted differently (one more FMA), which changes clean outputs by an ulp. With the select, clean inputs give bitwise the same output. Co-Authored-By: Claude <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
A gfx1250 regression test is still needed to detect missing or misplaced tail masks by poisoning unowned V rows with NaN/Inf across loop variants 0/1/2, including padded tiles, and checking finite outputs against a clean run.
1 open issue
What changed in this PR
This PR prevents stale NaN/Inf values in unused KV-cache rows from contaminating gfx1250 Gluon 2D unified-attention outputs. It applies the same protection as the companion fixes for other attention backends.
Changes:
- Retains the sequence length and adds a register-level V-row mask.
- Applies the mask to the standard loop’s final tile and both reordered loops’ epilogue tiles.
- Leaves steady-state tiles, memory transfers, and output stores unchanged.
| File | Description |
|---|---|
aiter/ops/triton/_gluon_kernels/gfx1250/attention/unified_attention_2d.py |
Zeros V rows at or past the sequence end before attention accumulation. |
Review effort: Balanced
A finite random cache does not catch a missing mask_v. Poison the slots past each sequence and check the 2D kernel, including the padded tiles of loop variants 1 and 2, against the same call on a clean cache. Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
The 11-03 02:53Z CI run failed Black: |
|
@ROCm/team_aiter @ROCm/triton_kernels_team Please take a look. Head The red check is Aiter Test shard 4. The step hit its 90-minute limit inside |
|
@azaidy Tagging you as a Gluon owner for the gfx1250 Gluon unified attention 2D V-row mask change in this PR. |
|
Updated the branch by merging main The branch was 205 commits behind A rerun of gfx1250 FFM tests stay opt-in. |
|
@ROCm/team_aiter @ROCm/triton_kernels_team @k50112113 @cagrikymk @azaidy Could you review this when you have a moment? Head is now The MI35X shard-4 failure on the previous head was the 90-minute cap in files this PR does not touch, so I've started a fresh Aiter Test run on the merged head: https://github.com/ROCm/aiter/actions/runs/42576317823 @azaidy you were tagged as the gfx1250 Gluon owner for the kernel change. The part I would most like checked is the |
…gluon-ua2d-mask-stale-v Keep the poisoned-V-tail test beside the spec-decode tests from ROCm#7100. Co-authored-by: Cursor <[email protected]>
…gluon-ua2d-mask-stale-v Conflicts with A8K4V8 (ROCm#7421): - unified_attention_2d.py: keep the mask_v calls; take main's softmax_part1(target_dtype=q.dtype) and compute_qk(k, k_scales). - test_unified_attention.py: both sides appended tests at the end; keep both. Co-Authored-By: Claude <[email protected]>
|
Head
The py3.10 wheel in the same run succeeded. Black, Ruff, and all five Triton MI35X shards passed. The Aiter Test Gate is red only because |

Summary
The gfx1250 Gluon 2D unified attention kernel zeroes V rows at or past the sequence length before P·V, so a stale NaN/Inf in a slot the sequence does not own can no longer turn its output into NaN. The gfx1250 sibling of #6475 (Triton 2D/3D, open) and #6755 (gfx950 Gluon, open); the same idea as #7092 (FlyDSL pa_decode, merged).
Motivation
The kernel copies each KV page whole (TDM -> LDS -> registers). In a sequence's last page the slots at or past
seq_lenbelong to nobody (a freed page of another request, a rejected draft token, uninitialized memory), but their V rows still enter the P·V WMMA. Their P is exactly 0, yet0 * NaN = NaN, so one non-finite value in a page tail makes the whole output row of every query reading that page NaN. The reordered loops (variants 1 and 2) are exposed a second way: with fewer than 3 tiles they run padded tiles past the end, whose block id is clamped to the table's last entry.Seen in serving (gpt-oss-120b on gfx1250, SGLang, aiter attention): after a separate bug wrote NaN into one request's KV, the page allocator spread it from request to request and the server degenerated to
!!!!and never recovered.Context (the same paragraph in the three companion gfx1250 PRs). Three defects and a compiler bug hit gpt-oss-120b on gfx1250 together and hid one another. (1) The TDM store of an LDS-staged output tile can ship stale LDS: the a8w4 MoE decode and unified attention 2D register-store PRs. The rule for when a TDM store may read LDS written by
ds_storeneeds an answer from the LLVM AMDGPU / hardware side. (2) The Gluon 2D attention turns one NaN in a KV page tail into NaN for every query that reads the page: the V-masking PR. (3) LLVM placed the workgroup release'ss_wait_dscnt 0afters_barrier_signalat the top of a loop. That made attention extend non-deterministic and looked like (1). It is fixed by llvm/llvm-project#220357, which is in Triton main's LLVM and known to the compiler team (ROCm/rocm-libraries#10893). In serving, (1) in the MoE made one token's row NaN and (2) spread it to the whole batch. GSM8K failed only at TP2 and only after load. At TP1 the same race stayed finite and passed every gate. Related gfx1250 TDM/LDS ordering reports: #5712 (a TDM load racing ads_readof the slot it overwrites), #4537 (TDM ring wait counts), the note in #4894's gfx1250 quant kernel ("fp8 TDM async_store corrupted data in tiles wider than 1024"), and LLVM941a04e69ee8(keep the TDM counter low), which lowers (1)'s rate to ~0.6x but not to 0. Other gfx1250 users of the Gluon MoE decode kernel may be exposed to (1): vLLM's gpt-oss Gluon MoE path (ROCm/vllm#1327) and ATOM's FlyDSL-prefill + Gluon-decode split.Changes
AttentionProgramkeepsseq_lenand getsmask_v(v, j): a select that zeroes the rows of tilejat or pastseq_len, in registers after the LDS read.-inf.Performance
Kernel time, fix / original, median of 3 adjacent pairs, 64 q / 8 kv heads, head 64, bf16 (the GPU was power-capped near 1 GHz: ratios only):
The select is 128
v_cndmask_b16per lane per masked tile and +20 VGPRs; short programs (sliding window, ~3 tiles) feel it most. A branch around it would be cheaper (1.008-1.022) but breaks bitwise equality on clean inputs.Test
gfx1250 only (gfx1250 kernel).
!!!!.Validated on the AITER tree of a gpt-oss gfx1250 recipe (base 2bb5491) with the image's Triton (76940ad + revert). Head
f5b7dfe1merges that change onto main0a175694(#7100). Against that main the diff is still the kernel and the poisoned-tail test. The gfx1250 run of the test was not repeated after the merge. The op test istest_gfx1250_gluon_ua2d_ignores_poisoned_v_tail. A gfx1250 run of that test is not run from this machine. Still unverified: the rest of AITER's attention op tests on gfx1250, and end-to-end speed.MI355X (gfx950), 2026-11-05, image
rocm/sgl-dev:v0.5.23-rocm10-mi35x-20261102, ROCm 10.0.0.pytest op_tests/triton_tests/attention/test_unified_attention.pyat this head against merge-base07ff5f318b8a: 2500 passed, 0 failed. The 5 newtest_gfx1250_gluon_ua2d_ignores_poisoned_v_tailcases skip with "gfx1250 Gluon 2D kernel only, not gfx950". No outcome change on the other cases. CI shard 4 is the same 26 files, in the same order, as the green #7202 run (79.4 min against a 90 min cap). The TSV estimates that shard at 37 min. The cap fired intest_mha_varlen_large_kv.pyandtest_gemm_a8w8_blockscale_cktile_aq_rowmajor.py, which this PR does not touch. On this box, after their one-time JIT, those two files take 42 s and 4 s.PR Self-Review
Reviewed revision
f5b7dfe1eb79e3c7fbcfd40ba92885558e6a44caBehavior and intent
The gfx1250 Gluon 2D kernel copies a whole KV page, then multiplies P·V. Rows at or past the sequence length have P exactly 0, and
0 * NaNis NaN, so one stale non-finite V value in a page tail turns the output row of every query that reads that page into NaN.mask_vzeroes those rows with a select after the LDS read, before P·V. K is left alone: a NaN in a K tail only poisons its score, and the length mask replaces that score with-inf.seq_leniscontext_len + cur_batch_query_len. The select runs only where a past-the-end row can be consumed: the last tile of the standard loop (tile_end - 1), and the three epilogue tiles of the reordered and sub-tile-split loops (tile_end - 3,epilogue_t_2,epilogue_t_3). Steady-state tiles, the TDM loads, LDS, and the output store are unchanged.Head
f5b7dfe1merges main0a175694, which includes #7100. That merge left themask_vsites above in place. #7100'sSPEC_DECODEpath still setscur_batch_query_lentoSEQLEN_Qand returns before Q is read when the sequence length is 0.seq_lenon that path is stillcontext_len + cur_batch_query_len. Against this main the diff is still the kernel andtest_gfx1250_gluon_ua2d_ignores_poisoned_v_tail.Validation and unverified scope
gfx1250 only (MI450X, DPX partition). Recipe AITER
2bb549102, image Triton76940adplus its revert. Headf5b7dfe1is that change merged onto main0a175694. The gfx1250 poisoned-tail run was not repeated after the merge.!!!!.The regression is
test_gfx1250_gluon_ua2d_ignores_poisoned_v_tailinop_tests/triton_tests/attention/test_unified_attention.py. A gfx1250 run of that test is not run from this machine. Still unverified: the rest of AITER's attention op tests on gfx1250, an end-to-end speed bracket, and a gfx1250 re-run of the poisoned-tail test on this merge.PR-specific question
The boundary the change adds is where
mask_vis called. It is not on every V load. A row at or pastseq_lenthat is consumed on a steady-state iteration is still unmasked, and would still produce NaN. The reordered loops are the sharp case: with fewer than 3 tiles they run padded tiles past the end and clamp the block id to the table's last entry, so those epilogue tiles re-read a real page.The poisoned-slot run is the coverage for that. NaN was written into every unowned slot, including page tails and the tiles variants 1 and 2 clamp onto. After the change every listed shape and loop variant is bitwise equal to the clean run. A missed call site would still return NaN. The clean suite (189 outputs, lengths that do and do not fill the last tile) is the coverage for the other direction:
seq_len = context_len + cur_batch_query_lendoes not zero a row the sequence owns.The select, rather than a branch around the tail, is what keeps that result bitwise. A branch is cheaper (about 1.008–1.022×) but moves a block boundary next to the softmax, LLVM contracts one more FMA, and clean outputs change by an ulp. The select costs 128
v_cndmask_b16per lane per masked tile and about 20 VGPRs; the +10% sliding-window prefill number is that cost on a program of ~3 tiles.Changed op tests
op_tests/triton_tests/attention/test_unified_attention.py—test_gfx1250_gluon_ua2d_ignores_poisoned_v_tail. The existing unified-attention tests fill V with finite random values, so a missing or misplacedmask_vstill passes. This test poisons unowned V slots with NaN and +Inf, forces loop variants 0, 1, and 2 (variant 1 is not in the bf16 table) including the padded tiles of variants 1 and 2, and requires the poisoned output to be finite and bitwise equal to the clean run. The clean run is also compared with the paged reference, so a mask that zeroes a row the sequence owns fails too. #6755 covers the gfx950 kernel, not this one.🤖 Generated with Claude Code