Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
There was a problem hiding this comment.
🟡 Changes recommended
The regression test admits an unfixed gfx1250 path and misses native FP8 Gluon and decode-fast-path coverage.
3 open issues
What changed in this PR
This PR prevents stale NaN/Inf values beyond the KV sequence end from corrupting unified attention output.
Changes:
- Mask unused V rows in Triton 2D and 3D kernels.
- Clear unused V rows in gfx950 Gluon shared memory.
- Add regression tests with poisoned KV cache tails.
| File | Description |
|---|---|
| op_tests/triton_tests/attention/test_unified_attention.py | Add poisoned-tail regression coverage. |
| aiter/ops/triton/_triton_kernels/attention/unified_attention.py | Mask V loads past the sequence end. |
| aiter/ops/triton/_gluon_kernels/gfx950/attention/unified_attention.py | Clear V tails before shared-memory reads. |
Review effort: Balanced
|
@WhatGhost Can you look into #6475 ? Potential solutions:
|
769e794 to
11671b8
Compare
@cagrikymk Thanks for the pointer. #6475 fixes the same V tail in the Triton kernels, so I took option 2. This PR now changes only the gfx950 Gluon kernel. The Triton kernel change is removed, and the test runs only the Gluon backend on gfx950. The two PRs no longer overlap. |
I did some benchmarking:
Unfortunately, there are some cases this PR regresses perf. (SWA + prefill, which makes the epilogue masking overhead very visible). Honestly, most correct solution would be to stop kv cache having NaN values. Not sure how those slip into the kv cache. However, I assume that is a lot trickier to handle correctly than masking NaNs here. I tried also doing a masked load instead of LDS roundtrip but that causes register spill for some cases. Unless we know what causes NaNs in kv cache, I think we can merge this PR. I will look into this further and see if we can handle NaNs without any visible perf. effect. |
|
@WhatGhost Is it possible for you to take a closer look at the cases with perf. regression? And see if they can be improved? |
@cagrikymk Thanks for your review and test! I'll take a look . |
|
@cagrikymk Thanks for the benchmark. I reproduced it on MI355X with block size 64 and found two causes. Both are fixed in the two new commits. 1. The zeroing ran for most prefill programs. The kernel compared the tail against 2. The zeroing code pushed one config over an occupancy boundary. For head size 64, 64/8 heads, bf16 and a sliding window ( Results (gfx950, block size 64, median of 5, 2 alternating runs, change against
The cost that stays is in short kernels. In decode, the last tile always ends at the sequence end, so the step must run. That is about 1 us on the 8 us decode_short kernel.
I agree that the best fix is to keep NaN out of the KV cache. |
|
No activity for 15 days, so this is now labelled |
|
@cagrikymk Hi, could you please help to review this PR again , thanks very much! |
… the sequence end
c052d5d to
5b63ca9
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |

[Triton/Gluon] gfx950 Gluon unified attention: mask stale V rows past the sequence end
Motivation
The last KV tile can load cache slots past
seqused_k. Their scores are masked, sopis 0, but their V values go into the PV dot. These slots can hold stale NaN/Inf, and0 * NaN = NaNmakes the full output row NaN.The gfx950 Gluon kernel does not mask V. The Triton 2D/3D kernels have the same problem. #6475 fixes them, so this PR changes only the Gluon kernel.
Technical details
zero_v_tail()sets the V rows at or pastkv_lento 0 in shared memory, after the V copy and before the V read.blocked_vlayout).attn_2dD_LEQ_64.SWconfig setswaves_per_eu: 3. The zeroing code adds VGPRs, and without this value the head size 64 sliding-window kernel drops from 3 to 2 waves per SIMD.Test plan
test_gluon_unified_attn_ignores_kv_tail(gfx950 only):ALL_DECODE) and prefill (2D grid, 4 warps). Also head size 64/128/256, block size 16/64, and bf16 and fp8 (Q and KV in the same dtype).NUM_BUFFERS=1and forcednum_warps1/2/4. Current configs do not select 1 buffer.test_unified_attention.py.Test results
gfx950 (MI355X), ROCm 7.2.4, Triton 3.8.0. Rebased onto
main0e995f195.main. All 72 pass with this PR.NUM_BUFFERS=1and forcednum_warps1/2/4: all cases pass.test_unified_attention.py: 2866 passed, 2963 skipped, 0 failed.Kernel time change against
main(backend="gluon", block size 64, median of 5, 2 alternating runs):Kernel time change against
mainon the spec-decode verify shapes of #6594 (16/2 heads, head size 64, sliding window 2048, kv 8704, q 2/4/8, batch 1–256, block size 64, median of 5, 2 alternating runs). The matchedattn_2dkey is from the config lookup of each call:attn_2dkeyD_LEQ_64.Q_LEQ_{2,4,8}.P_LEQ_8.SW.DT_bf16_bf16(#6594)D_LEQ_64.SW(this PR)The cost is in short kernels. In decode, the last tile always ends at the sequence end, so the zeroing must run (about 1 us on decode_short). Block size 16 gives the same pattern.
Tested only on gfx950.
PR Self-Review
Reviewed revision
5b63ca9
Behavior and intent
pis 0, but stale NaN/Inf in these cache slots makes0 * NaN = NaN, and the full output row becomes NaN.attn_2dconfigD_LEQ_64.SWsetswaves_per_eu: 3. The zeroing code adds VGPRs, and this value keeps that kernel at 3 waves per SIMD.Validation and unverified scope
Hardware: MI355X (gfx950), ROCm 7.2.4, Triton 3.8.0. Base:
main0e995f195.pytest op_tests/triton_tests/attention/test_unified_attention.py -k ignores_kv_tail: 72 passed. Onmain: 48 failed, 24 passed.NUM_BUFFERS=1and forcednum_warps1/2/4: all cases passed.pytest op_tests/triton_tests/attention/test_unified_attention.py: 2866 passed, 2963 skipped, 0 failed.main: see the tables in Test results.Unverified:
PR-specific question
The config change is one value:
attn_2dkeyD_LEQ_64.SWinconfigs/gfx950/gluon/attention/unified_attention/DEFAULT.json,waves_per_eu0 -> 3. Only gfx950 Gluonattn_2dcalls with head size <= 64 and a sliding window can use it, and only when no more specific key matches. The more specificD_LEQ_64.Q_LEQ_{2,4,8,16}.P_LEQ_8.SW.DT_bf16_bf16keys of #6594 stay first, so short spec-decode verify batches keep their own configs.Evidence: the JSON diff changes no other key, so calls that match other keys keep their previous config. In the #6594-shape benchmark, I recorded the matched key of each call. bf16 batch 64–256 (except q 8, batch 256) matched the #6594 keys: -0.6% to +3.8%, from the zeroing step only. fp8 batch 64–256 and bf16 q 8, batch 256 matched
D_LEQ_64.SW: 1.9% to 10.9% faster.Changed op tests
op_tests/triton_tests/attention/test_unified_attention.py: addstest_gluon_unified_attn_ignores_kv_tail. It writes NaN into the unused K/V cache slots (the tail of the last block and the unused blocks), asserts that each case runs on the gfx950 Gluon kernel, and compares the output with the reference. No existing test puts NaN into unused KV cache slots: the existing NaN uses only pre-fill the output buffer or run on gfx1250. Onmain, 48 of 72 cases fail.