Skip to content

[Build] [MHA] Stop flash_attn_varlen_func from dropping sequences with seqlen_q <= min_seqlen_q - #7473

Open
AndreasKaratzas wants to merge 4 commits into
mainfrom
akaratza_varlen_min_seqlen_q_no_skip
Open

AndreasKaratzas wants to merge 4 commits into
mainfrom
akaratza_varlen_min_seqlen_q_no_skip

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2229. flash_attn_varlen_func now computes every sequence on every backend, whatever min_seqlen_q is. Before this change, any sequence with seqlen_q <= min_seqlen_q was skipped on the CK path, and its out/lse rows were left uninitialized.

Motivation

The FP16 decode error in #2229 isn't a numerics problem. Those rows were never written. With min_seqlen_q != 0, the CK varlen path builds the _skip variant, and CK returns early for every sequence with seqlen_q <= min_seqlen_q (added in ROCm/composable_kernel#2221 so vLLM's old backend could hand decodes to paged attention). The output then keeps whatever torch.empty left there.

The asm v3 and opus kernels ignore the argument. So the same call is right when it lands on v3 (bf16 hd128/192, or hd256 on gfx950 MHA, without sink/SWA/softcap) and wrong on CK: fp16 at any head size, bf16 hd64, and bf16 with sinks or a sliding window.

Every current caller passes the argument as a lower bound, which is how the name and docstring read (see also #1368). vLLM #25763 lost Qwen3-32B accuracy by passing the true minimum, and #28670 hard-coded 1. With 1, vLLM still drops a 1-token prompt that is batched with a longer prefill (verified at kernel level with vLLM's own batch split). ATOM passes 0 on its prefill paths and min(extend_lens) in the Kimi bridge. I found no caller that relies on the skip.

cc @Zzz9990 @fsx950223, since this changes the meaning of the parameter you added.

Changes

  • _flash_attn_varlen_forward passes min_seqlen_q=0 to the CK and asm v3 varlen kernels, and the gfx950 hd256 mha_v4 THD route ([MHA] Route flash_attn_varlen_func gfx950 hd256 BF16 THD forward to mha_v4 #8704) no longer requires min_seqlen_q == 0. This covers flash_attn_varlen_func, its autograd path and flash_attn_varlen_fp8_pertensor_func. The low-level mha_varlen_fwd op keeps CK's skip.
  • The flash_attn_varlen_func docstring says min_seqlen_q is unused.
  • setup.py prebuilds the four bf16 _nskip mask/lse modules this path now uses, in place of the three _skip ones. That covers mask_lse_nskip, which vLLM's causal extend call needs and which was not prebuilt.
  • test_mha_varlen.py adds a mixed-length regression test. __main__ calls it, because CI runs this file as a script and not through pytest.

Performance (if applicable)

The _nskip modules can use CK's qr_async_trload instances on gfx950 (codegen only emits them for skip=f). Numbers are from CK mha_varlen_fwd, causal, H=32/Hkv=8, min_seqlen_q=1 before (_skip) vs 0 after (_nskip). Both runs are interleaved in one process. Each value is the median of 10 processes, and each process is the median of 15×200 iterations. The range is the min and max of the per-process change. As a noise check, the same _skip call was run a second time in the same loop. d64 and the asm v3 path are unaffected. The d128 rows apply to fp16, and to bf16 calls that go to CK (sink/SWA).

Hardware Workload/configuration Before After Change (min..max) Same build twice
MI350X fp16 d128, 4 × 2048 228.8 us 236.3 us +3.3% (+3.0..+3.3) +0.5%
MI350X fp16 d128, 16 × 512 101.6 us 101.2 us -0.1% (-4.2..+4.3) +1.5%
MI350X fp16 d128, 1 × 2 + 7 × 1024 128.9 us 132.7 us +3.1% (+1.5..+4.5) +1.4%
MI350X fp16 d128, 64 × 16 32.7 us 14.8 us -54.7% 0.0%
MI350X fp16 d128, 256 × 8 121.5 us 21.5 us -82.3% 0.0%
MI350X fp16 d64, 4 × 2048 139.7 us 140.2 us +0.3% (-1.3..+1.4) +0.2%
MI350X bf16 d64, 4 × 2048 136.2 us 139.3 us +0.9% (-2.5..+5.6) +1.2%

The cost on long sequences is real. With _nskip, CK selects the qr_async_trload 128×64 tile when max_seqlen_q > 32. With _skip, it selects the qr_async 128×128 tile. rocprofv3 shows the same split. Callers that pass min_seqlen_q=0 already get the _nskip kernel today, so this PR adds no new kernel. To get this cost back, change the tile selection in CK. Short sequences become much faster, because _nskip has the 16×32 and 32×32 tiles for max_seqlen_q <= 32.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

flash_attn_varlen_func(min_seqlen_q=N) no longer skips sequences with seqlen_q <= N on the CK path. A caller that relied on the skip to leave rows of a shared out buffer untouched will now get those rows computed and overwritten. No such caller was found in aiter, ATOM or vLLM. The low-level aiter.mha_varlen_fwd op still skips.

PR Self-Review

Reviewed revision

27bb920

Behavior and intent

The high-level varlen API stops forwarding min_seqlen_q to the kernels. Sequences no longer silently disappear when the call lands on CK (fp16, bf16 hd64, bf16 with sink or sliding window), and every backend now gives the same result for the same call.

Validation and unverified scope

On MI350X (gfx950), ROCm 7.15, torch 2.13:

  • pytest op_tests/test_mha_varlen.py::test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs: 16 passed in each of 10 consecutive runs. On main, 12 failed; the 4 that pass are bf16 d128, which runs on asm v3.
  • The [Issue]: flash_attn_varlen_func incorrect results for FP16 + q_len=1 (decode) on gfx942 #2229 repro matches an fp32 reference for fp16/bf16 at hd 64/128/256 and q_len 1/2/8; before this change fp16 gave inf/nan.
  • vLLM tests/kernels/attention/test_rocm_aiter_fa.py against this branch: 94 passed, and its FP16 single-token decode xfail now passes (max abs 1.8e-4).
  • ruff check (0.16.0) and black --check pass.

Rebased again on 2026-11-20 onto main 4ba20eb, which includes #7984 (the test_mha_v4_sparse.py gfx942 abort that failed the Aiter Test Gate here). No conflicts; git range-diff shows the commit unchanged. On MI355X (gfx950) at ee54960, the same pytest command: 16 passed (one run, clean JIT cache). The MI300X results below are from before this rebase.

On MI300X (gfx942), ROCm 7.15, torch 2.13, after the rebase onto 95d2112:

  • The same pytest command: 16 passed in each of 10 consecutive runs on 326ef26. On 95d2112 without this change, 12 failed. The 4 that pass are bf16 d128, which runs on asm v3. This is the same split as on MI350X.
  • python3 op_tests/test_mha_varlen.py (the CI command, which now also runs the new test): exit 0, in 533 s.
  • vLLM tests/kernels/attention/test_rocm_aiter_fa.py against this branch: 97 passed.

The CI wheel build PREBUILD_KERNELS=1, GPU_ARCHS=gfx942;gfx950 (job 126786209948, on 6802b3f) builds the four bf16 _nskip modules and no _skip module.

Not tested: end-to-end model accuracy. ci:all covers it. The MI300X CI shards did not run on 6802b3f, because the label came after the first run. They run on this push.

Merged main f90c562 on 2026-12-03. The only conflict was op_tests/test_mha_varlen.py, where this test and the hd256 THD test from #8704 were added at the same spot; both are kept. #8704 also kept THD calls off mha_v4 when min_seqlen_q != 0, because CK used to skip short sequences. That check is gone now that the argument is unused, so min_seqlen_q no longer changes which kernel runs. On MI350X, a THD-eligible hd256 bf16 batch with 1- and 2-token documents (MHA and GQA, causal or not) runs fmha_fwd_hd256_bf16_varlen for min_seqlen_q 0, 1 and 2, with bitwise-equal out/lse and no NaN. test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs and test_flash_attn_varlen_func_thd_hd256: 21 passed in each of 10 runs. python op_tests/test_mha_varlen.py: exit 0.

PR-specific question

setup.py only changes which bf16 varlen modules are prebuilt. Three _skip names become the _nskip twins, so the list goes from six modules to four and no dependency changes. On a clean cache, mha_varlen_fwd_bf16_nlogits_nbias_mask_lse_ndropout_nskip_nqscale and the fp16 _nskip modules were JIT-built through get_mha_varlen_prebuild_variants_by_names, the same recipe the prebuild uses. The existing-cache path is the second and later run of every test above. The CI wheel build with PREBUILD_KERNELS=1 and GPU_ARCHS=gfx942;gfx950 (job 126786209948) prebuilt all four _nskip modules, which include mask_lse_nskip, and no _skip module.

Changed op tests

op_tests/test_mha_varlen.py: adds test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs. It runs a batch with q lens 1/2/8/1 into a NaN-filled out with min_seqlen_q 1 and 2, and requires out and lse to equal the min_seqlen_q=0 call. On main it fails on every CK case. The existing varlen tests only parametrize min_seqlen_q=0, so nothing covered the skip. __main__ runs all 16 cases, so the CI script run covers the test.

@AndreasKaratzas
AndreasKaratzas requested a review from a team November 4, 2026 18:44
@AndreasKaratzas AndreasKaratzas added ci:all ci:mi300x Run MI300X standard and OPUS CI on PRs labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

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 7473 --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 Nov 4, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 27bb92025fce · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The high-level varlen API stops forwarding `min_seqlen_q` to the kernels. Sequences no longer silently disappear when the call lands on CK (fp16, bf16 hd64, bf16 with sink or sliding window), and every backend now gives the same result for the same call.

Validation and unverified scope

On MI350X (gfx950), ROCm 7.15, torch 2.13:
- `pytest op_tests/test_mha_varlen.py::test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs`: 16 passed in each of 10 consecutive runs. On main, 12 failed; the 4 that pass are bf16 d128, which runs on asm v3.
- The #2229 repro matches an fp32 reference for fp16/bf16 at hd 64/128/256 and q_len 1/2/8; before this change fp16 gave inf/nan.
- vLLM `tests/kernels/attention/test_rocm_aiter_fa.py` against this branch: 94 passed, and its FP16 single-token decode xfail now passes (max abs 1.8e-4).
- `ruff check` (0.16.0) and `black --check` pass.

Rebased again on 2026-11-20 onto main `4ba20eb`, which includes #7984 (the `test_mha_v4_sparse.py` gfx942 abort that failed the Aiter Test Gate here). No conflicts; `git range-diff` shows the commit unchanged. On MI355X (gfx950) at `ee54960`, the same pytest command: 16 passed (one run, clean JIT cache). The MI300X results below are from before this rebase.

On MI300X (gfx942), ROCm 7.15, torch 2.13, after the rebase onto `95d2112`:
- The same pytest command: 16 passed in each of 10 consecutive runs on `326ef26`. On `95d2112` without this change, 12 failed. The 4 that pass are bf16 d128, which runs on asm v3. This is the same split as on MI350X.
- `python3 op_tests/test_mha_varlen.py` (the CI command, which now also runs the new test): exit 0, in 533 s.
- vLLM `tests/kernels/attention/test_rocm_aiter_fa.py` against this branch: 97 passed.

The CI wheel build `PREBUILD_KERNELS=1`, `GPU_ARCHS=gfx942;gfx950` ([job 126786209948](https://github.com/ROCm/aiter/actions/runs/41890089682/job/126786209948), on `6802b3f`) builds the four bf16 `_nskip` modules and no `_skip` module.

Not tested: end-to-end model accuracy. `ci:all` covers it. The MI300X CI shards did not run on `6802b3f`, because the label came after the first run. They run on this push.

Merged main `f90c562` on 2026-12-03. The only conflict was `op_tests/test_mha_varlen.py`, where this test and the hd256 THD test from #8704 were added at the same spot; both are kept. #8704 also kept THD calls off mha_v4 when `min_seqlen_q != 0`, because CK used to skip short sequences. That check is gone now that the argument is unused, so `min_seqlen_q` no longer changes which kernel runs. On MI350X, a THD-eligible hd256 bf16 batch with 1- and 2-token documents (MHA and GQA, causal or not) runs `fmha_fwd_hd256_bf16_varlen` for `min_seqlen_q` 0, 1 and 2, with bitwise-equal `out`/`lse` and no NaN. `test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs` and `test_flash_attn_varlen_func_thd_hd256`: 21 passed in each of 10 runs. `python op_tests/test_mha_varlen.py`: exit 0.

PR-specific question

`setup.py` only changes which bf16 varlen modules are prebuilt. Three `_skip` names become the `_nskip` twins, so the list goes from six modules to four and no dependency changes. On a clean cache, `mha_varlen_fwd_bf16_nlogits_nbias_mask_lse_ndropout_nskip_nqscale` and the fp16 `_nskip` modules were JIT-built through `get_mha_varlen_prebuild_variants_by_names`, the same recipe the prebuild uses. The existing-cache path is the second and later run of every test above. The CI wheel build with `PREBUILD_KERNELS=1` and `GPU_ARCHS=gfx942;gfx950` ([job 126786209948](https://github.com/ROCm/aiter/actions/runs/41890089682/job/126786209948)) prebuilt all four `_nskip` modules, which include `mask_lse_nskip`, and no `_skip` module.

Changed op tests

`op_tests/test_mha_varlen.py`: adds `test_flash_attn_varlen_func_min_seqlen_q_computes_short_seqs`. It runs a batch with q lens 1/2/8/1 into a NaN-filled `out` with `min_seqlen_q` 1 and 2, and requires `out` and `lse` to equal the `min_seqlen_q=0` call. On main it fails on every CK case. The existing varlen tests only parametrize `min_seqlen_q=0`, so nothing covered the skip. `__main__` runs all 16 cases, so the CI script run covers the test.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • FAIL — Aiter Test Gate: failed
  • Required CI failed; fix it before requesting human review.

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

ChuanLi1101
ChuanLi1101 previously approved these changes Nov 12, 2026

@ChuanLi1101 ChuanLi1101 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 — correct fix for the CK min_seqlen_q skip leaving short-seq out/lse uninitialized (#2229). High-level API forcing 0 while keeping low-level mha_varlen_fwd skip is the right split; regression test covers it.

Process APPROVE from me — please have TEAM_AITER / MHA owners clear for merge.

@AndreasKaratzas
AndreasKaratzas force-pushed the akaratza_varlen_min_seqlen_q_no_skip branch from 6802b3f to 326ef26 Compare November 15, 2026 19:00
@github-actions github-actions Bot changed the title [MHA] Stop flash_attn_varlen_func from dropping sequences with seqlen_q <= min_seqlen_q [Build] [MHA] Stop flash_attn_varlen_func from dropping sequences with seqlen_q <= min_seqlen_q Nov 15, 2026
@github-actions github-actions Bot added the Build label Nov 15, 2026
stefankoncarevic added a commit to stefankoncarevic/aiter that referenced this pull request Nov 16, 2026
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

The CI issues are unrelated to this PR

@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

@Zzz9990 @fsx950223 could you confirm the min_seqlen_q change described under Breaking Changes is acceptable for the MHA varlen API? ChuanLi1101 asked for an MHA owner to clear it before merge.

…_q <= min_seqlen_q

With min_seqlen_q != 0 the CK varlen path builds the skip variant, and CK
returns early for every sequence with seqlen_q <= min_seqlen_q, leaving its
out/lse rows uninitialized. asm v3 and opus ignore the argument, so results
depended on dtype and head size. Pass 0 from _flash_attn_varlen_forward so
every backend computes every sequence, prebuild the matching _nskip bf16
module, and add a mixed-length regression test. Call the test from
__main__, because CI runs this file as a script.

Fixes #2229

Signed-off-by: Andreas Karatzas <[email protected]>
@AndreasKaratzas
AndreasKaratzas force-pushed the akaratza_varlen_min_seqlen_q_no_skip branch from 326ef26 to ee54960 Compare November 20, 2026 18:26
…eqlen_q_no_skip

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@xiangxli-cop

Copy link
Copy Markdown

@AndreasKaratzas Thanks, the change looks right to me. Forcing 0 in the high-level API fixes the silently uninitialized rows and makes CK behave like v3 and OPUS, and keeping the skip in the low-level mha_varlen_fwd leaves a way for anyone who still needs it.

I also checked the current callers: vLLM's rocm_aiter_fa backend and ATOM's main backend already pass 0, and SGLang doesn't use the argument. ATOM's vLLM plugin passes 1 for prefill/extend, so it is the one caller whose kernel changes, and for it this goes from dropping 1-token prefills to computing them.

One question on perf: fp16 d128 at 4 × 2048 is +4.4% (237.2 → 247.5 us). Is that run-to-run noise or a real cost of the _nskip instance? If it is real, please note it in the description.

@Zzz9990 @fsx950223 since you added min_seqlen_q, could you confirm the change in meaning described under Breaking Changes is fine with you?

@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

it's real, not noise. re-ran it with 10 alternated runs: 4 x 2048 is +3.3% every run (+3.0 to +3.3), while two runs of the same _skip build differ by 0.5% at most. the cause is CK's tile choice: _nskip picks the qr_async_trload 128x64 tile for any max_seqlen_q > 32, where _skip only has qr_async 128x128. it's the same kernel every min_seqlen_q=0 caller already gets today, so a fix belongs in the CK dispatch, not here. i also refreshed the table in the description: the 1 x 2 + 7 x 1024 row is a small cost too (+3%), not the -6.3% i had before.

@shay-li77

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

aiter-bot — queued behind 2 review(s); expect to start in about 40 min. The box reviews one PR at a time.

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ROCm/aiter PR #7473 — [Build] [MHA] Stop flash_attn_varlen_func from dropping sequences with seqlen_q <= min_seqlen_q

Review (advisory): 🔴 HIGH RISK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled; the single test target op_tests/test_mha_varlen.py exists — the PR reports the new test passing 16/16 on gfx942 and gfx950 and failing 12/16 on main, unverified here)
Perf (advisory): NOT RUN — REVIEW_AUTO_VALIDATE=0 disabled the base-vs-head auto-run and all 8 GPUs hold 95–96% VRAM from other processes; the PR's own MI350X medians (+3.3% on fp16 d128 4×2048, −55/−82% on short-seq shapes) are unverified here
Size: 60 lines / 3 files
Design (advisory): the high-level API forces min_seqlen_q=0 while the low-level mha_varlen_fwd keeps CK's skip; the prebuild list follows to the four bf16 _nskip modules
Human: recommend Jim Guo review whether redefining min_seqlen_q as ignored on the stable flash_attn_varlen_func contract is right for vLLM/ATOM/SGLang callers, and whether the PR-reported +3.3% fp16 d128 long-seq cost (whose recovery belongs in CK tile dispatch, not here) is acceptable to merge

🔴 [verified] aiter/ops/mha.py changes the behavior of the stable, downstream-consumed flash_attn_varlen_func kwarg min_seqlen_q — a caller passing 1 (ATOM's vLLM plugin does, on prefill/extend) goes from silently dropped rows to computed rows on every CK-served call (fp16 any head dim, bf16 d64, bf16 with sink/SWA) — but the PR's only approval is dismissed and the 2026-11-20 ping to fsx950223/Zzz9990, who added the parameter in #470, is unanswered, so this contract change has no owner sign-off. Reviewer must obtain explicit sign-off from the de-facto aiter/ops/mha.py owner and the parameter's authors before merge, on top of the ci:all label already on the PR.

2 finding(s) posted inline, on the lines they are about:

  • aiter/ops/mha.py:4365 — now documents min_seqlen_q as "Unused
  • setup.py:354-356 — drops the three bf16 _skip modules from the PREBUILD_KERNELS wheel list, so a wheel install no longer ships…

Comment thread aiter/ops/mha.py
max_seqlen_q: int. Maximum query sequence length in the batch.
max_seqlen_k: int. Maximum key sequence length in the batch.
min_seqlen_q: int. Minimum query sequence length for chunked prefill.
min_seqlen_q: int. Unused; kept for API compatibility. Every sequence is

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 [verified] aiter/ops/mha.py:4365 now documents min_seqlen_q as "Unused; kept for API compatibility", but the same docstring's provider contract at aiter/ops/mha.py:4400 still says "how_v3_bf16_cvt and min_seqlen_q tune AITER's kernels and may be ignored" — a provider author reading the contract still believes the kwarg is a live tuning knob. Author must update the provider-contract sentence to match the new semantics.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, good catch. the contract sentence now names only how_v3_bf16_cvt as a tuning kwarg and says min_seqlen_q is unused.

Comment thread setup.py
Comment on lines +354 to 356
"mha_varlen_fwd_bf16_nlogits_nbias_mask_lse_ndropout_nskip_nqscale",
"mha_varlen_fwd_bf16_nlogits_nbias_nmask_nlse_ndropout_nskip_nqscale",
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 [verified] setup.py:354-356 drops the three bf16 _skip modules from the PREBUILD_KERNELS wheel list, so a wheel install no longer ships them and the first low-level aiter.mha_varlen_fwd(min_seqlen_q>0) call JIT-compiles at runtime instead of loading a prebuilt module; no such caller exists in aiter, vLLM, ATOM or SGLang (PR audit, confirmed by reviewer), and fp16 variants were never prebuilt, so JIT is the pre-existing norm. Reviewer should ask whether any external consumer of the low-level op relies on the prebuilt _skip modules before merge.

@shay-li77

Copy link
Copy Markdown
Contributor

@rocking5566 could you help take a look at this one? It changes which CK varlen forward modules the high-level API uses. @Zzz9990 and @fsx950223, who added min_seqlen_q, haven't had a chance to reply to the pings on Nov 20 and Nov 29.

A summary:

  • Semantics: flash_attn_varlen_func now always passes min_seqlen_q=0, so CK loads the _nskip varlen modules and computes every sequence. Before, a caller passing min_seqlen_q > 0 got the _skip modules, and sequences with seqlen_q <= min_seqlen_q came back with out/lse never written ([Issue]: flash_attn_varlen_func incorrect results for FP16 + q_len=1 (decode) on gfx942 #2229). The low-level mha_varlen_fwd keeps the skip for anyone who still needs it. Of the known callers, only ATOM's vLLM plugin passes 1 (prefill/extend). vLLM's rocm_aiter_fa and ATOM's main backend already pass 0, and SGLang doesn't use the argument.
  • Perf: for such callers, long sequences get slower, e.g. +3.3% on fp16 d128 at 4 × 2048 on MI350X. _nskip picks the qr_async_trload 128×64 tile for max_seqlen_q > 32, while _skip only has qr_async 128×128. Every caller that already passes 0 gets this kernel today, so recovering it would be a CK dispatch change rather than part of this PR.
  • Wheel: setup.py now prebuilds the four bf16 _nskip modules instead of the three _skip ones, so a low-level call with min_seqlen_q > 0 JIT-compiles on first use.

Does this look reasonable to you from the CK side, including the change in meaning and the long-sequence cost? Thanks!

The contract sentence still named min_seqlen_q as a tuning kwarg that may
be ignored. Only how_v3_bf16_cvt is one now.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
op_tests/test_mha_varlen.py: this branch's min_seqlen_q test and main's
gfx950 hd256 THD test were added at the same spot; keep both.

aiter/ops/mha.py: drop the min_seqlen_q == 0 condition main added to
can_impl_fmha_v4_thd (and its docstring mention). It existed because CK
skipped short sequences; this branch makes min_seqlen_q unused, so it no
longer changes which kernel runs.

Co-authored-by: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>

This branch has not been deployed

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

Labels

Build ci:all ci:mi300x Run MI300X standard and OPUS CI on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: flash_attn_varlen_func incorrect results for FP16 + q_len=1 (decode) on gfx942

5 participants