Skip to content

[gfx1250] [Perf] FP8 varlen ASM prefill: split the keys of a non-causal call that underfills the GPU - #7946

Draft
gbyu-amd wants to merge 1 commit into
mainfrom
gyu/gfx1250-fp8-fmha-split-kv
Draft

gbyu-amd wants to merge 1 commit into
mainfrom
gyu/gfx1250-fp8-fmha-split-kv

Conversation

@gbyu-amd

Copy link
Copy Markdown
Contributor

Problem

fmha_fwd_fp8_varlen_asm (gfx1250, FP8 per-tensor, D192x128) launches ceil(max_seqlen_q / 256) x heads x batch workgroups, and each one walks its sequence's whole key range. A chunked-prefix prefill call — 1024 new query tokens, 12 heads (a 96-head model at TP8), one sequence, a 16384-key cached chunk — is 48 workgroups on a 256-CU MI455X. Such a call is bound by one workgroup's walk over the keys, so its time barely depends on the query length: 512, 1024 and 4096 queries against 16384 keys take 109, 113 and 125 µs.

Change

New aiter/ops/fmha_fp8_split_kv.py, called from the top of fmha_fwd_fp8_varlen_asm for non-causal calls:

  • Split. Each sequence's keys are split into S contiguous parts and given to the same ASM kernel as S sequences of one varlen batch.
    • S doubles while tiles x S stays within the CU count and every part keeps at least 512 keys.
    • There is no split below 8192 keys.
    • The batch is sequence-major, so the split cu_seqlens stay monotone and K/V are read in place.
  • Two small Triton kernels.
    • One writes the split cu_seqlens and repeats each query row S times.
    • The other merges the S partial outputs by their LSE.
    • Both launch through fast_launch (the eager prefill path would otherwise wait on Triton's argument binding).
  • Same contract as before.
    • The result has the layout and meaning of the unsplit call: out is [total_q, H, 128] bf16 and lse is the natural-log [total_q, H, 1].
    • Everything stays on the device: no host sync, and it is graph-capturable.
  • Never split:
    • causal calls, because a part's bottom-right mask would differ;
    • a non-contiguous q.
  • Switch. AITER_FMHA_FP8_SPLIT_KV=0 turns it off and =N forces N parts.

Results

MI455X, one GPU. Times are profiler kernel time, median of 10 calls, with inputs rotated so they are not cache-resident. "Plain" is the ASM kernel alone; "split" is the query copy, the ASM kernel and the merge.

batch x q x k parts plain µs split µs speedup
1 x 1024 x 16384 4 96.2 44.8 2.15x
1 x 925 x 12288 4 74.2 37.5 1.98x
1 x 512 x 16384 8 93.3 30.3 3.08x
1 x 256 x 16384 16 89.9 22.8 3.94x
1 x 128 x 16384 16 89.5 19.8 4.52x
2 x 1024 x 16384 2 117.7 77.1 1.53x
1 x 2048 x 16384 2 101.6 69.8 1.46x
1 x 1024 x 8192 4 50.1 30.8 1.63x

Three kinds of call are unchanged: causal calls, calls whose grid already fills the GPU (e.g. 1 x 4096 x 16384), and calls with fewer than 8192 keys.

Wall clock of back-to-back calls (CUDA events, python op_tests/test_fmha_fp8_split_kv.py): 1.38–1.81x on the split cases and 1.00x elsewhere. With nothing else queued on the GPU this loop includes the host side, so it understates the kernel gain.

Correctness

python -m pytest op_tests/test_fmha_fp8_split_kv.py: 20 passed. The test covers:

  • 6 shapes x S in {2, 4, 8};
  • sequences with fewer keys than parts (empty parts);
  • the automatic dispatch.

The output matches the unsplit call to ~1e-5. The kernel's LSE is the log of the sum of the FP8-rounded probabilities, so a part with its own running max rounds slightly differently: |ΔLSE| ≤ ~5e-3. The test tolerance is 2e-2.

Testing

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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 Radeon R9700 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 7946 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@gbyu-amd
gbyu-amd requested a review from shay-li77 November 18, 2026 02:44
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
…rfills the GPU (#7946 @ 88c4ddf, head 2026-11-13T18:08:12Z)

Applied as the diff 74a3010..88c4ddf (3 files) onto the rebased 1116 tree; PR state: draft, author gbyu-amd, base main.

(cherry picked from commit 572a65d)

Rebase onto main 12-03: imports fast_launch from aiter.ops.triton.utils.fast_launch; main's #8061 moved it there from _triton_kernels/kimi_delta_attn/.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant