Repository navigation
[HIP] [Feature] Add group/varlen and sliding-window support to the hd128 opus forward - #7584
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
cff6bb0 to
7030839
Compare
ea4ed29 to
6a57824
Compare
6a57824 to
af2b15c
Compare
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.
Summary
Adds two features to the gfx950 hd128 bf16 OPUS forward:
gqa_d128_kernel: no mask and causal, KV/Q padding,cross-attention, GQA/MQA, LSE as
[H_q, total_q].window_size=(left, 0),causal=True), batch and groupmode, on a new kernel
gqa_d128_swa_kernel.Both are selected from
flash_attn_func/flash_attn_varlen_funcunderAITER_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_MODEtrait: per-sequence lengths fromseqstart_q/kand row bases fromseqstart_q_pad/k_pad; flat Q-block grid oftotal_q / 256 + batchblocks.LOCALtrait (requiresCAUSAL) launchesgqa_d128_swa_kernel, which:window_size_left.Performance
MI355X, ROCm 7.2.4, bf16, D=128, group mode. OPUS through
flash_attn_varlen_func, ck_tilethrough
mha_varlen_fwd, same inputs; device time fromrun_perftestover rotated inputs.TFLOPS counts only the (row, key) pairs the mask keeps.
Testing
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
Causal sliding window (
window_size=(W, 0))Batch sweep (lengths 7,500–9,400, H=4/4)
Sliding window, causal + W=256:
Group mode, causal, no window:
Peak-performance exploration
TFLOPS at H=32/8 with 128K tokens per call (B = 131,072 / S):
Documentation
Opt-in path; documented in the
fmha_fwd_bf16_opus_fwd/_varlen_fwddocstrings.Dependencies
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 onOPUS 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
causalandwindow_size_right > 0are not implemented and route to otherbackends.
PR-specific question
Selected only for gfx950, bf16,
hdim_q == hdim_v == 128,nhead_q % nhead_k == 0,window_size_right in (-1, 0)withcausalfor any window, KV byte extent < 2^32, nodropout / bias / alibi / sink / descale / paged KV, and
AITER_ENABLE_FMHA_OPUS=1.LOCALrequiresCAUSAL(static_assert),gqa_d128_kernelrejectsLOCAL, and thetorch entry validates
seqstart(int32, contiguous, lengthB + 1).Changed op tests
test_mha_varlen.py: D=128 group tests (structural, long sequences, Q padding, slidingwindow) and varlen dispatch routing.
test_mha.py: batch-mode sliding window.test_mha_common.py:opus_ref_lsetakeswindow_size_left(default -1).