Skip to content

[Triton/Gluon] tune fused_bmm_rope_kv_cache on gfx950, add bench & configs (gfx950/1250) - #6501

Merged
nidal567 merged 2 commits into
ROCm:mainfrom
nidal567:fused_bmm_rope_kv_cache_bench_tune
Oct 20, 2026
Merged

nidal567 merged 2 commits into
ROCm:mainfrom
nidal567:fused_bmm_rope_kv_cache_bench_tune

Conversation

@nidal567

Copy link
Copy Markdown
Contributor

Motivation

On gfx950, the fused MLA BMM + RoPE + KV-cache kernels (fused_fp4_bmm_rope_cat_and_cache_mla, fused_fp8_bmm_rope_cat_and_cache_mla) are up to 2.1x slower on Triton 3.8 (TOT) compared to golden (Triton 3.4). 75 of 187 measured shapes regress, mostly decode regression near range that sets TPOT (Time per Output Token).

This kernel also does not have a benchmark in AITER, which is now added in this PR.

The fp8 kernel is on SGLang's default MLA path for DeepSeek-V3.2 and GLM-5 on MI355X. On the Triton 3.8 build measured here, main's tile for GLM-5's shape at M ≥ 512 also returns wrong results, including with SGLang's default bf16 KV cache; this PR replaces it

Technical Details

All tuning is gfx950-only, as other archs launch exactly as on main.

Since triton-lang/triton#8151 (Triton 3.6), waves_per_eu=N pins the kernel to exactly N waves per SIMD (Triton 3.4 passed it as a minimum). The shipped values 2 and 4 make LLVM reserve 169 and 97 VGPRs while the regressed tiles use 34-64, so occupancy drops (for example 5 -> 2 waves for fp4's 128x128 tile). One fp8 tile (N=512-K=128, 16 < M <= 256) regresses from Triton 3.8 codegen instead: 86 VGPRs vs 78 on 3.4, so 5 waves instead of 6. 8 warps make this worse, because the same launch also runs one-row RoPE programs (a median 94% of the workgroups), and each gets a 512-thread workgroup.

Every changed bucket now uses 4 warps and waves_per_eu=0:

  • fp8: only the regressed buckets change in N=512-K=128 and N=128-K=512. N=512-K=192 changes every bucket: its tile is also 24-51% faster than main in the buckets that didn't regress, and it replaces main's miscompiled M >= 512 tile.
  • fp4: the fused kernel gets its own config family, FUSED-FP4-BMM-ROPE-CAT-AND-CACHE-MLA, read by a one-line _get_fp4_config like _get_fp8_config ([Triton/Gluon] stop fused_bmm_rope_kv_cache from using batched_gemm_a8w8_a_per_token… #5877). It used to borrow the standalone batched_gemm_a16wfp4 configs, so tuning there would have retuned that kernel too. DEFAULT.json, -N=128-K=512.json, -N=8192-K=8192.json (gfx950) and DEFAULT.json (gfx1250) are byte-identical copies of the batched files, so every other shape and arch keeps main's picks. Open [Triton/Gluon] Satya/1250 config cleanup #6293 edits the gfx1250 source file; whichever PR lands second should re-copy it.
  • Benchmark: op_tests/op_benchmarks/triton/bench_fused_bmm_rope_kv_cache.py runs the unit tests' shapes by default (do_bench_cudagraph after a torch.cuda.synchronize()).

Test Plan

  • Perf: rocprofv3 --kernel-trace, trimmed mean; main on 3.4, main on 3.8 and this PR on 3.8. 187 shapes at unit-test and SGLang settings, plus 56 more (SGLang's default bf16 KV cache, GLM-5's QH 8/16/64, T up to 8192), plus 36 on the CI wheel. A regression is a result > 1.005 × baseline + 0.5 µs, with a baseline ≥ 4 µs.
  • Correctness: pytest runs on all three builds and a stress test to validate all five outputs compared bitwise with main (341 cases); a NaN-filled stress test of every changed bucket; bitwise reruns of the fp8 N=512 buckets.
  • Other archs: config picks and launches compared with main on 10 archs (forced in software); gfx1250 compiled offline from main and from this PR.

Test Result

shapes (gfx950) regressions: main 3.8 vs 3.4 this PR vs 3.4 this PR vs main 3.8
fp4 N=512/K=128, unit-test settings (32) 13 (+11% to +106%) 0 0
fp4 N=512/K=128, SGLang fp8-KV settings (16) 7 (+10% to +87%) 0 0
fp8 N=512/K=128, unit-test settings (32) 13 (+4% to +17%) 0 0
fp8 N=128/K=512, unit-test settings (26) 12 (+13% to +110%) 0 0
fp8 N=512/K=128, SGLang fp8-KV, DeepSeek-V3.2 (36) 19 (+1% to +10%) 0 0
fp8 N=512/K=192, SGLang fp8-KV, GLM-5's shape (45) 11 (+22% to +93%) 0 0
  • Every regressed shape is now at least as fast as Triton 3.4 (up to 2.3x faster) and 1.15x-4.16x faster than main. On the measured build, no shape is slower than main beyond the noise threshold.
  • The 56 extra shapes: main regresses in 19, this PR in 0 (14-74% faster than main on those).
  • CI wheel: main regresses in 11 of 36, this PR in 0. This PR is 0.6-2.6% slower than main in one bucket (fp8 N=512-K=128 any, fp8 KV cache, QH=128, T 512-1536), where main doesn't regress on the wheel; no tile screened beats this PR's on both builds.
  • Correctness: pytest 128/128 on all three builds. Outputs are bitwise identical to main in 1,700 of 1,705 tensors; the other 5 come from main's miscompiled GLM-5 tile.
  • Other archs: config picks and launches are identical to main; for gfx1250 the compiled machine code is also identical (72 launches).
kernel / shape T QH KH main, Triton 3.4 (µs) main, Triton 3.8 this PR vs main 3.8
fp4, unit-test 64 128 8 24.25 49.95 (+106%) 16.07 (−34%) −68%
fp4, unit-test 256 128 8 117.74 198.84 (+69%) 52.82 (−55%) −73%
fp8 N=128/K=512, unit-test 2048 128 8 891.51 1718.53 (+93%) 478.92 (−46%) −72%
fp8 N=512/K=128, unit-test 256 128 8 97.56 109.65 (+12%) 57.83 (−41%) −47%
fp8 N=512/K=128, SGLang fp8-KV 256 128 1 74.39 81.43 (+9%) 45.17 (−39%) −45%
fp8 N=512/K=192 (GLM-5), SGLang fp8-KV 384 64 1 69.72 131.61 (+89%) 39.83 (−43%) −70%

Kernel time in µs; percentages in the main and this-PR columns are vs main on Triton 3.4.

Submission Checklist

@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 (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 6501 --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.

@github-actions github-actions Bot changed the title tune fused_bmm_rope_kv_cache on gfx950, add bench & configs (gfx950/1250) [Triton/Gluon] tune fused_bmm_rope_kv_cache on gfx950, add bench & configs (gfx950/1250) Oct 13, 2026
@Boss2002n
Boss2002n requested a balanced review from Copilot October 13, 2026 21:33

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.

🟡 Changes recommended

The corrected FP8 GLM-5 shape lacks a checked-in correctness regression test.

1 open finding
What changed in this PR

Retunes fused FP4/FP8 MLA BMM + RoPE + KV-cache kernels for gfx950, separates FP4 tuning, and adds benchmarking support.

Changes:

  • Adds a dedicated FP4 config family for gfx950/gfx1250.
  • Retunes affected gfx950 FP8 and FP4 shapes.
  • Adds a configurable CUDA-graph benchmark.
File Description
op_tests/​op_benchmarks/​triton/​bench_fused_bmm_rope_kv_cache.py Adds FP4/FP8 benchmark CLI.
aiter/​ops/​triton/​fusions/​fused_bmm_rope_kv_cache.py Uses the fused kernel’s FP4 config loader.
aiter/​ops/​triton/​_triton_kernels/​fusions/​fused_bmm_rope_kv_cache.py Defines dedicated FP4 config lookup.
.../​fused_fp8.../​FUSED-FP8-...-N=512-K=192.json Retunes all M buckets.
.../​fused_fp8.../​FUSED-FP8-...-N=512-K=128.json Retunes regressed buckets.
.../​fused_fp8.../​FUSED-FP8-...-N=128-K=512.json Retunes selected buckets.
.../​gfx950/​.../​fused_fp4.../​DEFAULT.json Adds the gfx950 FP4 default.
.../​gfx950/​.../​fused_fp4.../​FUSED-FP4-...-N=512-K=128.json Adds fused-kernel-specific tuning.
.../​gfx950/​.../​fused_fp4.../​FUSED-FP4-...-N=128-K=512.json Preserves prior specialized selection.
.../​gfx950/​.../​fused_fp4.../​FUSED-FP4-...-N=8192-K=8192.json Preserves prior large-shape selection.
.../​gfx1250/​.../​fused_fp4.../​DEFAULT.json Preserves gfx1250 default behavior.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@brunomazzottiamd brunomazzottiamd 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.

Benchmark looks good, I've just shared minor nitpicks.

My main concern lies in aiter/ops/triton/configs/gfx1250/triton/gemm/fused_fp4_bmm_rope_cat_and_cache_mla/DEFAULT.json. Please check the comment.

@nidal567
nidal567 force-pushed the fused_bmm_rope_kv_cache_bench_tune branch from 3655671 to 3f6c94e Compare October 19, 2026 18:34

@brunomazzottiamd brunomazzottiamd 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!

@nidal567
nidal567 merged commit e78e5a4 into ROCm:main Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants