Skip to content

[Triton/Gluon] [Bugfix] gfx1250 Gluon unified attention 2D: zero V rows past the sequence end - #7201

Closed
akao-amd wants to merge 6 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-gluon-ua2d-mask-stale-v
Closed

akao-amd wants to merge 6 commits into
ROCm:mainfrom
akao-amd:pr-gfx1250-gluon-ua2d-mask-stale-v

Conversation

@akao-amd

@akao-amd akao-amd commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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_len belong 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, yet 0 * 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_store needs 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's s_wait_dscnt 0 after s_barrier_signal at 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 a ds_read of 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 LLVM 941a04e69ee8 (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

  • 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.
  • Applied only where such rows can be: the last tile of the standard loop and the epilogue tiles of the reordered and sub-tile-split loops. Steady-state tiles, TDM loads, LDS and the output store are unchanged.
  • A select, not a branch around it: a branch was cheaper but moves a block boundary next to the softmax, where LLVM then contracts one more FMA and clean outputs change by an ulp. With the select, clean outputs are bitwise unchanged.
  • K needs nothing: a NaN in a K tail only poisons its score column, which the length mask replaces by -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):

Hardware Workload/configuration Before After Change
gfx1250 (MI450X, DPX partition) sliding-window decode, 4 req, ctx 1k 1.000 1.003 +0.3 %
sliding-window decode, 64 req, ctx 8k 1.000 1.002 +0.2 %
prefill 1000, ctx 0 1.000 1.013 +1.3 %
prefill 8192, ctx 0 1.000 1.045 +4.5 %
prefill chunk 16384, ctx 49152 1.000 1.028 +2.8 %
sliding-window prefill chunk 16384, ctx 49152 1.000 1.10 +10 %

The select is 128 v_cndmask_b16 per 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).

  • Poisoned repro: NaN in every KV slot no sequence owns, the requests' own K/V identical to a clean run; gpt-oss shapes, full and sliding window 127, decode 4/16/64 requests, prefill (one prompt; 16384 chunk with context; mixed batches), loop variants 0 and 2 from the tables and forced variants 1 (2 and 3 buffers) and 2 (3 buffers). Before: every request whose length is not a multiple of 64 returns NaN (all requests with forced variants 1/2). After: 0 NaN, bitwise equal to the clean run, in every case. NaN in K only: no effect before or after.
  • Clean inputs: 0 of 189 outputs differ (decode 1-128 requests, lengths multiple and not multiple of 64, prefill and mixed, all variants).
  • SGLang gpt-oss-120b W4A8, TP1, GSM8K 1319 after load: 0.9621, no !!!!.

Validated on the AITER tree of a gpt-oss gfx1250 recipe (base 2bb5491) with the image's Triton (76940ad + revert). Head f5b7dfe1 merges that change onto main 0a175694 (#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 is test_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.py at this head against merge-base 07ff5f318b8a: 2500 passed, 0 failed. The 5 new test_gfx1250_gluon_ua2d_ignores_poisoned_v_tail cases 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 in test_mha_varlen_large_kv.py and test_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

f5b7dfe1eb79e3c7fbcfd40ba92885558e6a44ca

Behavior 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 * NaN is 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_v zeroes 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_len is context_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 f5b7dfe1 merges main 0a175694, which includes #7100. That merge left the mask_v sites above in place. #7100's SPEC_DECODE path still sets cur_batch_query_len to SEQLEN_Q and returns before Q is read when the sequence length is 0. seq_len on that path is still context_len + cur_batch_query_len. Against this main the diff is still the kernel and test_gfx1250_gluon_ua2d_ignores_poisoned_v_tail.

Validation and unverified scope

gfx1250 only (MI450X, DPX partition). Recipe AITER 2bb549102, image Triton 76940ad plus its revert. Head f5b7dfe1 is that change merged onto main 0a175694. The gfx1250 poisoned-tail run was not repeated after the merge.

  • Poisoned KV: NaN in every slot no sequence owns, the requests' own K and V identical to a clean run. gpt-oss shapes, full attention and sliding window 127, decode at 4/16/64 requests, prefill (one prompt, a 16384 chunk with context, mixed batches). Loop variants 0 and 2 as the tables select them, plus forced variant 1 (2 and 3 buffers) and variant 2 (3 buffers). Before: every request whose length is not a multiple of 64 returns NaN, and every request does when variants 1 or 2 are forced. After: 0 NaN, bitwise equal to the clean run, in every case.
  • NaN in K only: no effect before or after.
  • Clean inputs: 0 of 189 outputs differ (decode 1–128 requests, lengths on and off a multiple of 64, prefill and mixed, all variants).
  • Kernel time, fix/original, median of 3 adjacent pairs, 64 q / 8 kv heads, head 64, bf16, GPU power-capped near 1 GHz (ratios only): sliding-window decode +0.2 to +0.3%, prefill +1.3 to +4.5%, sliding-window prefill chunk 16384 at context 49152 +10%.
  • Serving: gpt-oss-120b W4A8, SGLang, TP1, GSM8K 1319 after load, 0.9621, no !!!!.

The regression is test_gfx1250_gluon_ua2d_ignores_poisoned_v_tail in op_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_v is called. It is not on every V load. A row at or past seq_len that 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_len does 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_b16 per 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 misplaced mask_v still 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

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]>
@akao-amd
akao-amd requested a review from a team October 30, 2026 06:59
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7201 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 7242b6814828 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@akao-amd akao-amd changed the title [Triton/Gluon] [Bugfix] gfx1250 unified attention 2D: store decode outputs from registers [Triton/Gluon] [Bugfix] gfx1250 Gluon unified attention 2D: zero V rows past the sequence end Oct 30, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot October 30, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@zufayu
zufayu requested review from a team and vgokhale November 2, 2026 01:23
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]>
@github-actions github-actions Bot changed the title [Triton/Gluon] [Bugfix] gfx1250 Gluon unified attention 2D: zero V rows past the sequence end [Triton/Gluon] [Bugfix] gfx1250 Gluon unified attention 2D: zero V rows past the sequence end Nov 3, 2026
@akao-amd

akao-amd commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

The 11-03 02:53Z CI run failed Black: test_unified_attention.py ended with two blank lines. The new commit removes them; black --check (26.10.1, the version psf/black@stable installs) and ruff check pass on both changed files. The Aiter Test Gate and Triton Test Results jobs of that run ended within about a minute together with Black, so I expect them to pass on the new head (their logs are not visible to me without a login).

@akao-amd

akao-amd commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@ROCm/team_aiter @ROCm/triton_kernels_team Please take a look. Head e2697cc adds the poisoned-V-tail regression and the Black fix for it.

The red check is Aiter Test shard 4. The step hit its 90-minute limit inside op_tests/test_gemm_a8w8_blockscale_cktile_aq_rowmajor.py, after test_mha_varlen_large_kv.py had passed. The other shards passed. https://github.com/ROCm/aiter/actions/runs/41592120162

@akao-amd

akao-amd commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@azaidy Tagging you as a Gluon owner for the gfx1250 Gluon unified attention 2D V-row mask change in this PR.

@akao-amd

akao-amd commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated the branch by merging main a0c4b69c into e2697cce. New head: 888e2442.

The branch was 205 commits behind 07ff5f318 (2026-10-29). Both files this PR edits have moved on main: unified_attention_2d.py in #6767, and test_unified_attention.py in #6594, #6889, #6983 and #7472. The merge is clean. Against current main the diff is still only this change, +23 in the kernel and +148 in the test. Reviewed revision in the description is now 888e2442; the answers under it are unchanged because the patch is.

A rerun of e2697cce would not have been the right CI. The MI35X shard-4 failure on that head (https://github.com/ROCm/aiter/actions/runs/41592120162) is the 90-minute cap in test_mha_varlen_large_kv.py and test_gemm_a8w8_blockscale_cktile_aq_rowmajor.py, which this PR does not touch. The same 26-file shard finished on #7202 in 79.4 min. The 2026-11-05 Aiter Test run on that head skipped the shards and still reported the gate green. Main has since replaced .github/split-test-times/aiter.tsv and .github/scripts/split_tests.sh, so the suite CI runs now is not that shard list. This merge starts it: https://github.com/ROCm/aiter/actions/runs/42576317823

gfx1250 FFM tests stay opt-in. ffm-bringup.yaml runs only when ci:gfx1250-ffm-triton is applied to a same-repo head. This PR is from akao-amd/aiter, so the label already on it does not start that workflow.

@akao-amd

akao-amd commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@ROCm/team_aiter @ROCm/triton_kernels_team @k50112113 @cagrikymk @azaidy

Could you review this when you have a moment? Head is now 888e2442, which is current main merged in. The diff against main is unchanged: a V-row mask in the gfx1250 Gluon 2D unified attention kernel, plus the poisoned-V-tail regression test.

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 mask_v call sites in the reordered and subtile-split loops.

…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]>
k50112113
k50112113 previously approved these changes Nov 10, 2026

@k50112113 k50112113 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

…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]>
@akao-amd

Copy link
Copy Markdown
Contributor Author

Head 7242b681. The red Aiter Test run is not this PR.

build_aiter_wheels for rocm/pytorch:rocm7.2.4_ubuntu24.04_py3.12_pytorch_release_2.10.0 failed before the wheel build started. Docker Hub returned 429 on all 5 pulls of that image, and the digest check against Docker Hub also returned 429, so the job discarded the copy it had already pulled from mirror.gcr.io. https://github.com/ROCm/aiter/actions/runs/42939432259/job/130258303428

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 build_aiter_wheels failed and split_aiter_tests / Standard Tests were skipped after that. This PR still changes only unified_attention_2d.py and test_unified_attention.py; neither is involved in the image pull.

@akao-amd

Copy link
Copy Markdown
Contributor Author

Closing: the NaN source is the TDM store fixed in #7202, and the decode output store fixed in #7203. With those in, the V-row mask here is not needed for accuracy and costs up to +10% on some prefill shapes. The unmasked V-tail path stays latent; reopen if a non-finite tail shows up in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants