Repository navigation
[ASM] [gfx1250] asm mha bf16 fwd: allow D64 without a sink - #7291
Conversation
🏷️ 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.
🔵 Needs a closer look
The new -inf sentinel’s numerical correctness and performance impact in precompiled gfx1250 D64 kernels remain unverified because the required GPU tests and benchmarks could not run in this review environment.
No open issues 🎉
What changed in this PR
This PR enables the gfx1250 D64 assembly attention wrappers to handle calls without a sink by supplying a per-head -inf tensor, which contributes zero to the softmax denominator.
Changes:
- Add shared fallback-sink handling for fixed-length and variable-length wrappers.
- Extend both op tests to exercise D64 without a sink through the wrappers.
- Clarify documentation while leaving public dispatcher routing unchanged.
| File | Description |
|---|---|
op_tests/test_fmha_fwd_with_sink_varlen_asm.py |
Add variable-length D64 coverage without a sink. |
op_tests/test_fmha_fwd_with_sink_asm.py |
Add fixed-length D64 coverage without a sink. |
aiter/ops/mha.py |
Supply fallback sinks in both wrappers and clarify sink behavior. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The sink behavior depends on gfx1250 binaries unavailable as source, and numerical and CUDA graph replay results lack an attached head-bound validation report, requiring human confirmation.
No open issues 🎉
Review effort: Balanced
1ee988a to
f6e610b
Compare
The gfx1250 D64 fwd kernels are built with ENABLE_SINK=1 and always read the per-head sink, so fmha_fwd_with_sink_asm / fmha_fwd_with_sink_varlen_asm handed them a null pointer when called without one. The wrappers now pass a -inf sink in that case: its softmax term exp(-inf) is 0, so the result is plain attention. Routing is unchanged: flash_attn_func / flash_attn_varlen_func still send D64 to the asm path only when the caller gives a sink. The op tests now also run D64 without a sink through the ops wrappers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f6e610b to
94f0d34
Compare
Add D64 cases with more queries than keys, through both ops wrappers, causal and non-causal, with and without a sink: - fixed-batch: shape (64, 64, 8, 300, 256, 2); - varlen: test_fmha_fwd_with_sink_varlen_asm_d64_qk, q [300, 300] and k [256, 256], so the q and k offsets differ. Causal rows that see no key are found by position (bottom-right aligned) and checked on every element: O = 0, and LSE = -inf without a sink or the sink logit with one. assertAllclose tolerates up to 5% mismatches, so a few NaN rows would otherwise pass. The fixed-batch public candidate keeps checking LSE only on rows that see a key, now by position too: with a sink the reference LSE is finite on every row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Human verification is needed because the source-only review could not confirm the precompiled gfx1250 D64 kernels’ handling of the -inf sink sentinel, especially for fully masked causal rows.
No open issues 🎉
1 resolved since last review
Review effort: Balanced


Summary
Let the gfx1250 BF16 D64 asm forward wrappers (
fmha_fwd_with_sink_asm,fmha_fwd_with_sink_varlen_asm) run without a sink. WhensinkisNoneand the head dim is 64, the wrappers now pass the kernel a per-head-infsink. Its softmax term isexp(-inf) = 0, so the result is plain attention.Motivation
The gfx1250 D64 forward kernels (
fmha_bf16_pertokenBf16_hd64_128x256*.co) are built withENABLE_SINK=1and always readsink[head]. Withsink=None, both wrappers forwarded a null pointer to them, which the D64 binaries dereference (the router comments inmha.pyalready note this). Callers that want plain attention on the D64 asm path had to build their own sink buffer, and the public routers avoid the issue only by sending D64 to asm when a sink is given.Changes
aiter/ops/mha.py_fmha_fwd_asm_sink(): for D64 withsink is None, returns a[q_head_num]fp32-inftensor; otherwise returnssinkunchanged.fmha_fwd_with_sink_asmandfmha_fwd_with_sink_varlen_asmcall it before launching; docstrings updated._flash_attn_forward/_flash_attn_varlen_forwardupdated. The routing logic is unchanged:flash_attn_func/flash_attn_varlen_funcstill send D64 to the asm path only when a sink is given.op_tests/test_fmha_fwd_with_sink_asm.py,op_tests/test_fmha_fwd_with_sink_varlen_asm.py: D64 correctness rows also run without a sink. In the fixed-batch test both candidates (asmthrough the ops wrapper,publicthroughflash_attn_func) are checked on those rows; the varlen test calls the ops wrapper for them. New D64 cases with more queries than keys (fixed-batch, and varlen with separate q / k offsets) check that causal rows without a key give exactly O = 0 and LSE = -inf.Impact: only D64 calls with
sink=Noneto the two ops wrappers change, from passing a null sink to a-infsink. Calls with a sink, D128, D192x128, D256, kernels, launch parameters and routing are unchanged. The-inftensor is allocated per call, likeout/lse, with no cached tensor, so CUDA graph capture behaves as for the existing buffers.Performance (if applicable)
No kernel or launch change; the only added work is one fill of
q_head_numfp32 values per D64 call without a sink. Measured on one shape (fwd only, interleaved windows: 2 s warm-up, 10 x 0.5 s, median; output checked against FP32 on 16 rows x 3 heads):fmha_fwd_with_sink_asm, D64, B 4, S 16000, H 128 (MHA), non-causal, BF16, BSHD. Before: the caller passes a-infsink (the only way to run the D64 asm kernel without a sink). After:sink=NoneFor reference, the public routers keep sending D64 without a sink to FlyDSL m32x8 (this PR does not change routing): on the same shape
flash_attn_functakes 21.03 ms andflash_attn_varlen_func20.69 ms (flydsl 0.4.1,ENABLE_CK=0).Testing
Tested on gfx1250 only; the changed code path is gfx1250-only (
require_gfx1250_asm). See "Validation and unverified scope".Documentation
Dependencies
Breaking Changes
None. D64 calls without a sink, which previously handed the kernel a null pointer, now compute plain attention; every other call behaves as before.
PR Self-Review
Reviewed revision
776e7f9
Behavior and intent
fmha_fwd_with_sink_asm(..., sink=None)andfmha_fwd_with_sink_varlen_asm(..., sink=None)with D64 forwarded a null sink pointer to kernels that always read it.-infsink, i.e. plain attention. The output is bit-identical to passing an explicit-infsink.Noneis still passed through), and the public routers.Validation and unverified scope
Hardware: gfx1250, single GPU. aiter via
PYTHONPATH, JIT modules rebuilt from the tested revision; torch 2.11. Items 1-5 ran on earlier revisions of this change (same code) with flydsl 0.4.1; items 6-8 with flydsl 0.4.2.python3 op_tests/test_fmha_fwd_with_sink_varlen_asm.py(all head dims): rc 0; 260/260checkAllclosepassed, including all 20 new D64 no-sink rows.python3 op_tests/test_fmha_fwd_with_sink_asm.py -d 64 128: the 42 rows before(64, 64, 8, 8192, 8192, 1)passed (84/84checkAllclose), including all 14 new D64 no-sink rows. That row then aborts with a GPU memory access fault inside the test's torch reference (run_torch, an fp32einsumover[1, 64, 8192, 8192]), which runs before the kernel. Running the reference alone on those inputs reproduces the fault, while the D64 asm kernel alone on the same tensors (20 launches) completes, so the fault is in the reference and independent of this change.sink=Noneis bit-identical to an explicit-infsink.-infsink those rows come out as 0 with no NaN/Inf, the same as with a real sink and as D128. The rows with keys match the torch reference (relative L2 ≤ 2.0e-3). LSE on those rows was not checked here; the op tests now check it (item 8).f6e610b72(this change stacked on [ASM] [HIP] [gfx1250] asm mha bf16 hd256: batch and varlen forward #7559's headb7aa8fae8), flydsl 0.4.2, torch GEMMs on rocBLAS (TORCH_BLAS_PREFER_HIPBLASLT=0 ROCBLAS_USE_HIPBLASLT=0, which avoids the hipBLASLt fault in the test's reference noted in 2):op_tests/test_fmha_fwd_with_sink_asm.py -d 64: 36 correctness rows, 144/144 checks passed, including all 18 D64 no-sink rows; gate and empty-input tables ran.op_tests/test_fmha_fwd_with_sink_varlen_asm.py -d 64 --dtype bf16: 40 correctness rows passed, including all 20 D64 no-sink rows; gate and perf tables ran. No failures, no faults.94f0d34735de(rebased onto main2ec8c26c9after [ASM] [HIP] [gfx1250] asm mha bf16 hd256: batch and varlen forward #7559 merged as5c003a5e3; the diff of this change is identical tof6e610b72), same environment as 6, each run under the node's GPU lock with no other process on the GPU:op_tests/test_fmha_fwd_with_sink_asm.py -d 64: 36 correctness rows, 144/144 checks passed (18 D64 no-sink rows).op_tests/test_fmha_fwd_with_sink_varlen_asm.py -d 64 --dtype bf16, run twice back to back: 40 correctness rows, 80/80 checks passed in each run (20 D64 no-sink rows).op_tests/test_fmha_fwd_with_sink_varlen_asm.py -d 128 192 256 --dtype bf16: 456/456 checks passed.op_tests/test_fmha_fwd_with_sink_asm.py -d 128 256: 50 correctness rows, 200/200 checks passed; gate, empty-input and perf tables ran.776e7f9a374a(adds the D64 cases with more queries than keys from review;mha.pyunchanged since 7), same environment, one GPU-lock run:op_tests/test_fmha_fwd_with_sink_asm.py -d 64 256: 304/304 checks passed. The new(64, 64, 8, 300, 256, 2)rows (causal and non-causal, with and without a sink, both candidates) all match the reference, and the exact checks on rows without a key pass, including the existing D256(1000, 300)rows.op_tests/test_fmha_fwd_with_sink_varlen_asm.py -d 64 --dtype bf16: 88/88 checks passed.test_fmha_fwd_with_sink_varlen_asm_d64_qk, causal: 88 rows without a key per case; O = 0 and LSE = -inf without a sink, LSE = the sink logit with one.Unverified:
out/lse).ENABLE_CK=0, so thevia="public"rows (D64 with a sink, D128) ran on FlyDSL / Triton rather than asm. The asm D64-with-sink path was covered through the ops wrapper in 3.4096correctness row and the perf table) did not run there; the D64 no-sink large shape is covered by 4.Oheld garbage (NaN, up to 3e35), on D64 varlen rows with and without a sink and on D128 fixed-batch rows (which this change does not touch); LSE stayed correct. The same tests passed on an idle GPU (the results in 7). Cause not investigated here.PR-specific question
What each changed op test would fail on before this PR, and why existing tests do not cover it: every new case calls an ops wrapper with
sink=Nonefor D64. Before this PR that passed a null sink pointer to D64 kernels that always read it, so these cases are expected to fault or return wrong results (not run on the base revision). Existing cases always pass a sink for D64, andflash_attn_func/flash_attn_varlen_funcnever send D64 without a sink to the asm path, so no existing test calls the D64 asm kernels without a sink. The new sq > sk cases also check the boundary this change creates: on causal rows that see no key, the-infsink meets a-infrow maximum, and the rows must still give O = 0 and LSE = -inf rather than NaN.Changed op tests
op_tests/test_fmha_fwd_with_sink_asm.py:test_fmha_fwd_with_sink_asmtakes ad64_sinkargument. D64 correctness shapes run with a sink (as before) and without one; on the no-sink rows theasmcandidate goes through the ops wrapper and thepubliccandidate throughflash_attn_func, both compared with the torch reference without a sink.(64, 64, 8, 300, 256, 2): causal, the first 44 rows of each batch see no key.asmcandidate, rows that see no key are checked exactly (O = 0, LSE = -inf), becauseassertAllclosetolerates up to 5% mismatching elements.sink=None, and of D64 rows without keys.op_tests/test_fmha_fwd_with_sink_varlen_asm.py:d64_sinkrows fortest_fmha_fwd_with_sink_varlen_asm(equal q and k lengths) through the varlen ops wrapper.test_fmha_fwd_with_sink_varlen_asm_d64_qk: D64 with separate q and k lengths (q[300, 300], k[256, 256], so the q and k offsets differ), causal and non-causal, with and without a sink, through the ops wrapper; compared with the torch reference, and the rows without a key are checked exactly as above.sink=None; the existing q > k cases (test_fmha_fwd_with_sink_varlen_asm_qk) cover D192x128 and D256 only.