Skip to content

fix(mha): select sink kernel when only sink_ptr is provided - #4976

Merged
valarLip merged 1 commit into
ROCm:mainfrom
kkHuang-amd:fix/mha_batch_prefill
Aug 25, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
kkHuang-amd:fix/mha_batch_prefill

Conversation

@kkHuang-amd

Copy link
Copy Markdown
Contributor

mha_batch_prefill_func aborts with "no matching kernel found" for any caller that supplies a learned per-head sink logit via sink_ptr without also setting sink_size (e.g. gpt-oss on SGLang's AITER backend):

RuntimeError: invalid argument for batch_prefill: no matching kernel
found. page_size=1, num_pages=6, dtype=bf16.

The message blames KV-cache size and GPU generation; neither is the cause. Two bugs combine:

  1. cmdGenFunc_mha_batch_prefill's trailing parameters were ordered sink_ptr, gen, kv_last_page_lens, block_table, seqlen_k, while _mha_batch_prefill invokes the op all-positionally as kv_last_page_lens, block_table, seqlen_k, sink_ptr, gen. compile_ops forwards that same tuple to the generator, so it read kv_last_page_lens as sink_ptr and never saw a sink.

  2. has_effective_sink tested sink_size > 0 only, while the C++ side (csrc/cpp_itfs/mha_fwd_batch_prefill.cu:52) uses has_sink = args.sink_size > 0 || args.sink_ptr != nullptr.

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

mha_batch_prefill_func aborts with "no matching kernel found" for any
caller that supplies a learned per-head sink logit via sink_ptr without
also setting sink_size (e.g. gpt-oss on SGLang's AITER backend):

  RuntimeError: invalid argument for batch_prefill: no matching kernel
  found. page_size=1, num_pages=6, dtype=bf16.

The message blames KV-cache size and GPU generation; neither is the
cause. Two bugs combine:

1. cmdGenFunc_mha_batch_prefill's trailing parameters were ordered
   sink_ptr, gen, kv_last_page_lens, block_table, seqlen_k, while
   _mha_batch_prefill invokes the op all-positionally as
   kv_last_page_lens, block_table, seqlen_k, sink_ptr, gen. compile_ops
   forwards that same tuple to the generator, so it read
   kv_last_page_lens as sink_ptr and never saw a sink.

2. has_effective_sink tested sink_size > 0 only, while the C++ side
   (csrc/cpp_itfs/mha_fwd_batch_prefill.cu:52) uses
   has_sink = args.sink_size > 0 || args.sink_ptr != nullptr.
@kkHuang-amd
kkHuang-amd requested review from a team and a lite review from Copilot August 25, 2026 02:02
@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; main branch always runs both MI35X and MI300X
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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 4976 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

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.

Pull request overview

Fixes mha_batch_prefill_func dispatch failures (“no matching kernel found”) when callers provide a learned per-head sink logit via sink_ptr without also setting sink_size, by aligning generator argument ordering and improving sink-kernel selection.

Changes:

  • Reordered trailing parameters in cmdGenFunc_mha_batch_prefill to match the positional calling convention used by the compiled op path.
  • Updated sink detection so sink_ptr participates in sink-kernel selection (in addition to sink_size).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/ops/mha.py
Comment on lines 1596 to 1600
# Sink only applies when there is a causal/window mask; full attention
# (window_size_left==-1 and window_size_right==-1) ignores sink_size.
has_effective_sink = sink_size > 0 and (
has_effective_sink = (sink_size > 0 or sink_ptr is not None) and (
causal or not (window_size_left == -1 and window_size_right == -1)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants