Skip to content

[HIP] [Feature] Add group/varlen and sliding-window support to the hd128 opus forward - #7584

Merged
shay-li77 merged 4 commits into
ROCm:mainfrom
JingPhil:opus-hd128-group-swa-fwd
Nov 13, 2026
Merged

shay-li77 merged 4 commits into
ROCm:mainfrom
JingPhil:opus-hd128-group-swa-fwd

Conversation

@JingPhil

@JingPhil JingPhil commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two features to the gfx950 hd128 bf16 OPUS forward:

  1. Group (varlen) mode in gqa_d128_kernel: no mask and causal, KV/Q padding,
    cross-attention, GQA/MQA, LSE as [H_q, total_q].
  2. Causal sliding window (window_size=(left, 0), causal=True), batch and group
    mode, on a new kernel gqa_d128_swa_kernel.

Both are selected from flash_attn_func / flash_attn_varlen_func under
AITER_ENABLE_FMHA_OPUS=1.

Motivation

On gfx950, D=128 causal sliding window over packed sequences fell back to ck_tile, and the
D=128 OPUS kernel was batch-only.

Changes

  • GROUP_MODE trait: per-sequence lengths from seqstart_q/k and row bases from
    seqstart_q_pad/k_pad; flat Q-block grid of total_q / 256 + batch blocks.
  • LOCAL trait (requires CAUSAL) launches gqa_d128_swa_kernel, which:
    • loads only the KV tiles inside the window;
    • lets each four-wave group skip the tiles outside its rows' windows;
    • applies the softmax scale in fp32.
  • Python gates and torch entry points for D=128 group mode and window_size_left.

Performance

MI355X, ROCm 7.2.4, bf16, D=128, group mode. OPUS through flash_attn_varlen_func, ck_tile
through mha_varlen_fwd, same inputs; device time from run_perftest over rotated inputs.
TFLOPS counts only the (row, key) pairs the mask keeps.

Workload Mask ck_tile (µs) OPUS (µs) Speedup ck_tile TFLOPS OPUS TFLOPS
B=16, lengths 8,025–9,254, H=4/4 causal + W=256 257 211 1.22x 279 339
causal 1,491 1,116 1.34x 820 1,096
B=448, lengths 7,500–9,400, H=4/4 causal + W=256 5,727 4,736 1.21x 342 413
causal 36,766 27,654 1.33x 891 1,184
B=16, S=8,192, H=32/8 causal + W=4096 7,613 5,565 1.37x 867 1,186
causal 9,358 7,287 1.28x 940 1,207

Testing

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

gfx950-only; all results on MI355X.

Functional

pytest op_tests/test_mha.py op_tests/test_mha_varlen.py -k opus: 216 passed, 3 skipped
(window without causal). The benchmark shapes below also match ck_tile within bf16 tolerance.

Performance comparison

Group mode, no window

Shape Mask ck_tile (µs) OPUS (µs) Speedup ck_tile TFLOPS OPUS TFLOPS
B=16, lengths 8,025–9,254, H=4/4 none 2,556 2,020 1.27x 957 1,211
causal 1,491 1,116 1.34x 820 1,096
B=448, lengths 7,500–9,400, H=4/4 none 66,837 51,677 1.29x 980 1,267
causal 36,766 27,654 1.33x 891 1,184
B=16, S=8,192, H=32/8 none 17,485 13,908 1.26x 1,006 1,265
causal 9,358 7,287 1.28x 940 1,207
7 × 8,400 + 1 × 16,354, H=4/4 none 1,631 1,269 1.29x 956 1,229
causal 1,087 764 1.42x 717 1,021
B=2, S=32,768, H=32/8 none 34,506 27,084 1.27x 1,020 1,299
causal 17,811 13,886 1.28x 988 1,267
B=64, lengths 512–2,048, H=32/8 none 2,312 1,835 1.26x 845 1,064
causal 1,519 1,247 1.22x 643 784

Causal sliding window (window_size=(W, 0))

Shape W=128 W=256 W=512 W=1024 W=2048 W=4096
B=16, lengths 8,025–9,254, H=4/4 ck_tile (µs) 217 257 333 478 712 1,089
OPUS (µs) 178 211 264 377 549 833
Speedup 1.22x 1.22x 1.26x 1.27x 1.30x 1.31x
ck_tile TFLOPS 167 279 423 570 718 812
OPUS TFLOPS 203 339 533 723 930 1,061
B=448, lengths 7,500–9,400, H=4/4 ck_tile (µs) 4,743 5,727 7,800 11,703 18,608 28,980
OPUS (µs) 3,875 4,736 6,195 8,956 14,072 21,423
Speedup 1.22x 1.21x 1.26x 1.31x 1.32x 1.35x
ck_tile TFLOPS 209 342 493 636 748 828
OPUS TFLOPS 256 413 621 832 990 1,120
B=16, S=8,192, H=32/8 ck_tile (µs) 1,176 1,429 1,963 2,983 4,910 7,613
OPUS (µs) 983 1,149 1,527 2,225 3,496 5,565
Speedup 1.20x 1.24x 1.28x 1.34x 1.40x 1.37x
ck_tile TFLOPS 234 380 544 692 784 867
OPUS TFLOPS 280 473 699 927 1,101 1,186
Shape W ck_tile (µs) OPUS (µs) Speedup ck_tile TFLOPS OPUS TFLOPS
7 × 8,400 + 1 × 16,354, H=4/4 256 156 118 1.33x 250 331
2048 428 330 1.30x 657 851
B=2, S=32,768, H=32/8 256 809 658 1.23x 340 418
1024 1,614 1,197 1.35x 671 905
4096 4,770 3,442 1.39x 865 1,198
B=64, lengths 512–2,048, H=32/8 128 765 641 1.19x 216 258
256 909 741 1.23x 344 421
512 1,125 914 1.23x 493 606
1024 1,395 1,115 1.25x 608 760

Batch sweep (lengths 7,500–9,400, H=4/4)

Sliding window, causal + W=256:

B ck_tile (µs) OPUS (µs) Speedup ck_tile TFLOPS OPUS TFLOPS
1 44.5 20.3 2.19x 94 206
2 51.6 38.7 1.33x 170 227
4 86.8 63.3 1.37x 203 278
8 140.2 112.5 1.25x 253 315
16 253.8 206.0 1.23x 282 348
32 456.5 380.4 1.20x 311 373
64 839.8 696.6 1.21x 337 406
128 1,611.2 1,315.3 1.22x 346 423
256 3,252.4 2,623.2 1.24x 344 427
448 5,727.2 4,736.4 1.21x 342 413

Group mode, causal, no window:

B ck_tile (µs) OPUS (µs) Speedup ck_tile TFLOPS OPUS TFLOPS
1 270.3 137.3 1.97x 249 489
2 378.7 192.2 1.97x 387 763
4 475.0 331.3 1.43x 624 894
8 824.7 595.4 1.39x 725 1,004
16 1,470.1 1,115.2 1.32x 832 1,097
32 2,786.2 2,125.8 1.31x 862 1,129
64 5,502.0 4,181.2 1.32x 870 1,145
128 10,594.3 8,001.2 1.32x 876 1,160
256 21,163.6 16,004.0 1.32x 886 1,171
448 36,766.1 27,654.0 1.33x 891 1,184

Peak-performance exploration

TFLOPS at H=32/8 with 128K tokens per call (B = 131,072 / S):

Mask Backend S=2K S=4K S=8K S=16K S=32K
no mask ck_tile 931 987 1,010 1,015 1,020
OPUS 1,171 1,235 1,269 1,289 1,315
causal ck_tile 770 880 943 973 985
OPUS 963 1,128 1,207 1,253 1,293
causal + W=4096 ck_tile – – 856 861 861
OPUS – – 1,181 1,204 1,220

Documentation

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

Opt-in path; documented in the fmha_fwd_bf16_opus_fwd / _varlen_fwd docstrings.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. New traits and arguments default off; the path requires AITER_ENABLE_FMHA_OPUS=1.

PR Self-Review

Reviewed revision

72933dc

Behavior and intent

With AITER_ENABLE_FMHA_OPUS=1, bf16 D=128 varlen calls and causal-window calls run on
OPUS instead of the backends they reached before (causal-window calls fell back to
ck_tile).

Validation and unverified scope

Validated on MI355X: pytest op_tests/test_mha.py op_tests/test_mha_varlen.py -k opus
(216 passed, 3 skipped), plus the ck_tile cross-check and benchmarks under Testing.

Unverified: bitwise agreement with ck_tile (tiling and accumulation order differ; checked by
tolerance and an fp32 reference instead), and MI250X / MI300X (the path is gfx950-only).
Windows without causal and window_size_right > 0 are not implemented and route to other
backends.

PR-specific question

Selected only for gfx950, bf16, hdim_q == hdim_v == 128, nhead_q % nhead_k == 0,
window_size_right in (-1, 0) with causal for any window, KV byte extent < 2^32, no
dropout / bias / alibi / sink / descale / paged KV, and AITER_ENABLE_FMHA_OPUS=1.
LOCAL requires CAUSAL (static_assert), gqa_d128_kernel rejects LOCAL, and the
torch entry validates seqstart (int32, contiguous, length B + 1).

Changed op tests

  • test_mha_varlen.py: D=128 group tests (structural, long sequences, Q padding, sliding
    window) and varlen dispatch routing.
  • test_mha.py: batch-mode sliding window.
  • test_mha_common.py: opus_ref_lse takes window_size_left (default -1).

@github-actions

github-actions Bot commented Nov 6, 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 7584 --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.

@JingPhil
JingPhil marked this pull request as ready for review November 6, 2026 16:25
@JingPhil
JingPhil requested a review from a team November 6, 2026 16:25
@github-actions github-actions Bot changed the title [Feature] Add group/varlen and sliding-window support to the hd128 opus forward [HIP] [Feature] Add group/varlen and sliding-window support to the hd128 opus forward Nov 6, 2026
@github-actions github-actions Bot added the HIP label Nov 6, 2026
@aiter-bot

aiter-bot commented Nov 6, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 72933dcb8cfa · 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

With `AITER_ENABLE_FMHA_OPUS=1`, bf16 D=128 varlen calls and causal-window calls run on
OPUS instead of the backends they reached before (causal-window calls fell back to
ck_tile).

Validation and unverified scope

Validated on MI355X: `pytest op_tests/test_mha.py op_tests/test_mha_varlen.py -k opus`
(216 passed, 3 skipped), plus the ck_tile cross-check and benchmarks under Testing.

Unverified: bitwise agreement with ck_tile (tiling and accumulation order differ; checked by
tolerance and an fp32 reference instead), and MI250X / MI300X (the path is gfx950-only).
Windows without `causal` and `window_size_right > 0` are not implemented and route to other
backends.

PR-specific question

Selected only for gfx950, bf16, `hdim_q == hdim_v == 128`, `nhead_q % nhead_k == 0`,
`window_size_right in (-1, 0)` with `causal` for any window, KV byte extent < 2^32, no
dropout / bias / alibi / sink / descale / paged KV, and `AITER_ENABLE_FMHA_OPUS=1`.
`LOCAL` requires `CAUSAL` (`static_assert`), `gqa_d128_kernel` rejects `LOCAL`, and the
torch entry validates `seqstart` (int32, contiguous, length `B + 1`).

Changed op tests

- `test_mha_varlen.py`: D=128 group tests (structural, long sequences, Q padding, sliding
  window) and varlen dispatch routing.
- `test_mha.py`: batch-mode sliding window.
- `test_mha_common.py`: `opus_ref_lse` takes `window_size_left` (default -1).

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
  • PASS — Aiter Test Gate: passed

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

@zufayu
zufayu requested a review from shay-li77 November 7, 2026 06:47
@JingPhil
JingPhil force-pushed the opus-hd128-group-swa-fwd branch from cff6bb0 to 7030839 Compare November 10, 2026 10:40
@JingPhil
JingPhil force-pushed the opus-hd128-group-swa-fwd branch from ea4ed29 to 6a57824 Compare November 12, 2026 14:15
@JingPhil
JingPhil force-pushed the opus-hd128-group-swa-fwd branch from 6a57824 to af2b15c Compare November 12, 2026 15:08

@shay-li77 shay-li77 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

@shay-li77
shay-li77 merged commit 4690334 into ROCm:main Nov 13, 2026
amd-bartgips added a commit that referenced this pull request Nov 17, 2026
Main's #7584 extended the OPUS group/varlen forward to D=128, behind
AITER_ENABLE_FMHA_OPUS. A tuned opus row for such a call runs it when the
flag is set, and is declined to auto-select when it is not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants