Repository navigation
[CK] [Bugfix] Preserve virtual sinks in single-query batch prefill - #6760
Conversation
Keep causal dispatch when a virtual sink is present. CK does not generate no-mask sink specializations, so clearing the causal flag for a single query selects an unsupported kernel configuration. Apply the same guard to Python specialization selection and the C++ entry point. Cover full and sliding windows, multiple queries, and a no- sink control with numerical regression tests. Signed-off-by: Yuedong Wu <[email protected]>
🏷️ 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.
🟢 Approval recommended
The narrow, matching dispatch guards address the failure with focused regression coverage and no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes single-query causal batch prefill with virtual sinks by preserving sink-enabled CK dispatch, completing the earlier sink-detection fix.
Changes:
- Align Python and C++ guards to retain causal dispatch when a virtual sink is present.
- Add five numerical regression cases while preserving the no-sink optimization.
| File | Description |
|---|---|
op_tests/test_batch_prefill.py |
Adds virtual-sink and control cases for pytest and standalone execution. |
csrc/py_itfs_ck/mha_batch_prefill_kernels.cu |
Preserves causal dispatch for virtual sinks. |
aiter/ops/mha.py |
Applies the matching Python specialization guard. |
Review effort: Balanced
|
Hi @valarLip, may I request your review on this fix? CI is passing. Thanks in advance. |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time. |
[ROCm/aiter] PR #6760 — [CK] [Bugfix] Preserve virtual sinks in single-query batch prefillThe single-query "causal≡non-causal" optimization in batch prefill no longer clears causal when a virtual attention sink (sink_ptr) is present, so those calls dispatch to the existing sink-enabled CK kernel instead of failing with "no matching kernel found". Review (advisory): 🔴 HIGH RISK 🔴 [verified] aiter/ops/mha.py:1548 changes the default dispatch of the public mha_batch_prefill_func for single-query calls with a virtual sink — previously a loud TORCH_CHECK "no matching kernel found", now a causal+sink kernel launch — and the PR's own motivation says SGLang's AITER NHD attention path consumes this API, yet the PR carries no ci:* label, so every downstream job (ci:sglang/vllm/atom) is skipped and a semantic mismatch in the newly-routed kernel would surface only after merge. Author must add ci:all (the activation cannot be traced to one specific labeled model from this repo) and require it green before merge. 🔴 [verified] aiter/ops/mha.py is a stable downstream-facing dispatch contract whose behavior this diff changes (error → kernel launch for qlen==1+sink calls), but the de-facto owner by commit count — slippedJim, 23 commits on the file vs valarLip's 3 — has not been asked to sign off; the author's review request went to valarLip. Reviewer should ask slippedJim (top committer of the path) for explicit sign-off on the dispatch change before merge, or confirm valarLip owns this path. 📝 [verified] Explicitly non-causal calls with sink_ptr still raise "no matching kernel found" (the CK batch_prefill codegen emits no no-mask+sink instance), and for non-causal + sink + window_size_left ≥ max_seqlen_k the Python side of aiter/ops/mha.py selects _mask+_sink blobs while the C++ entry decodes no-mask after its unconditional window normalization — a loud, pre-existing, author-documented out-of-scope failure. Reviewer should ask the author to confirm SGLang's virtual-sink calls are always causal, or to file the non-causal case as a follow-up. |
|
Following the bot review, I checked the referenced SGLang call site and ran an additional warmed-up, long-KV latency check. The SGLang batch-prefill call explicitly passes both On MI355X, using BF16/page1, batch=1, qlen=1, KV=4096 and Q8/KV1, all four patched cases passed numerical checks. After 30 warm-up calls, median eager API timings over 9 groups of 100 calls were:
JIT compilation and input preparation are excluded. Head dim 64 matches GPT-OSS TP8 per-rank dimensions; this is a single-GPU operator check, not an end-to-end serving test. The local-window controls showed small differences (+0.92% / +2.27%) in this run. The full-window cases have no working base baseline, so their absolute timings do not establish a performance regression or serving-level performance acceptance. |
shay-li77
left a comment
There was a problem hiding this comment.
Thanks for the fix! I verified it on MI355X (gfx950, ROCm 10.1, torch 2.14) and it looks correct. Approving; the comments below are non-blocking.
What I checked
I ran 15 cases through mha_batch_prefill_func on base (45d7ef3) and on this PR (21472a9), comparing against an fp32 reference. Inputs: random Q/K/V, batch=2 with different kv lengths (37 and 100), GQA 8:2, a different sink logit per head, shuffled page indices.
- The target case (qlen=1,
causal=True,sink_ptr) fails on base withno matching kernel foundand passes with this PR. Max abs error vs fp32 is ≤ 0.004. - No regressions. Every other case gives the same result on base and on this PR. The only previously working call whose path changes is qlen=1 +
sink_ptr+ a finite left window. It now goes through the causal mask instead of the local mask, and it is still numerically correct. - The 5 new tests pass.
Pre-existing failures nearby (not introduced by this PR)
These fail with no matching kernel found on both base and this PR:
| case | base | this PR |
|---|---|---|
qlen=1, causal=False, window (-1,-1), sink_ptr |
❌ | ❌ |
qlen=4, causal=False, window (-1,-1), sink_ptr |
❌ | ❌ |
qlen=4, causal=False, window (4096,-1) / (-1,4096) / (4096,4096), max_seqlen_k=100, no sink |
❌ | ❌ |
qlen=1, causal=False, window (4096,-1), sink_ptr |
❌ | ❌ |
The first row is mathematically identical to the case this PR fixes, because qlen=1 causal is full attention, but it still fails. The error hint about page_size and the 2GB KV cache is also misleading here. Root causes and a suggested single-point fix are in the inline comments. Happy for this to land as a follow-up.
Use random Q/K/V, unequal request lengths, shuffled pages, and distinct per-head sink logits with the existing BF16 tolerances. Run the cases from the existing sink script entry point. Signed-off-by: Yuedong Wu <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The five regression cases need GPU validation on the exact PR head to confirm Python/CK specialization agreement and numerical behavior, since the supplied MI355X results were not independently verified.
No open issues 🎉
Review effort: Balanced
Motivation
Single-query causal batch prefill with a virtual attention sink fails with
no matching kernel found. The qlen=1 optimization clearscausal, selecting a no-mask specialization that CK does not generate with sink support. SGLang's AITER NHD attention path uses this API with virtual sinks.This addresses the remaining single-query case after #4976, which corrected argument binding and sink detection. Virtual sink semantics were introduced in #2794.
Technical Details
Keep causal dispatch when
sink_ptris present, in both Python specialization selection and the C++ entry point. This uses the existing sink-enabled CK path; no kernel arithmetic, dependency or API changes. The no-sink optimization is unchanged. Explicitly noncausal virtual-sink support is outside this fix.Test Plan
Five numerical cases reuse the existing reference: single-query sinks with unlimited/covering-full/local windows, a multi-query sink control, and a no-sink control. They participate in pytest and the existing standalone CI script.
Focused reproduction:
Test Result
MI355X, BF16/page1, head dimension 128; PyTorch
2.9.1+rocm7.2.0.git7e1940d4, HIP7.2.26015-fc0010cf6a, CK96afae1d54fc. Identical tests and separate fresh JIT builds: base2dff26579a17has two expected dispatch failures and three passing controls; patched passes all five numerical checks, zero skips.Patched GPU log, seconds include JIT, not performance measurements
{"case": [1, -1, true], "status": "pass", "seconds": 106.14433819055557} {"case": [1, 8, true], "status": "pass", "seconds": 0.019419414922595024} {"case": [1, 1, true], "status": "pass", "seconds": 0.0009224573150277138} {"case": [2, -1, true], "status": "pass", "seconds": 0.0010075466707348824} {"case": [1, -1, false], "status": "pass", "seconds": 101.00728063751012}Submission Checklist
Disclosure: Found by Hyperloom session analysis, reviewed and validated by human.