Skip to content

[Triton/Gluon] benchmark + config + tuning for fused_qk_concat on gfx950 - #6287

Merged
brunomazzottiamd merged 4 commits into
ROCm:mainfrom
nidal567:fused_qk_concat_bench_tune
Oct 19, 2026
Merged

brunomazzottiamd merged 4 commits into
ROCm:mainfrom
nidal567:fused_qk_concat_bench_tune

Conversation

@nidal567

@nidal567 nidal567 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Motivation

On gfx950, fused_qk_cat and fused_qk_rope_cat are up to 18% slower on Triton 3.8 than on Triton 3.4, with the same aiter source: 87 of 185 measured shapes regress. Neither op had a benchmark / dedicated config file

Technical Details

Everything is gfx950-only: other archs ship no config and launch exactly as main does

  • Two new gfx950 config families, one per kernel, each a flat DEFAULT.json bucketed on M = B x QH (one program per row) with M_LEQ_<x>/any keys, as in the GEMM tables and FUSED_CLAMP_ACT_MUL's -N= files:
config (configs/gfx950/triton/fusions/) kernel M_LEQ_ bucket any
fused_qk_cat/DEFAULT.json _qk_cat_kernel M_LEQ_65535: num_warps 4 num_warps 1
fused_qk_rope_cat/DEFAULT.json _qk_rope_cat_kernel M_LEQ_8191: num_warps 4 num_warps 1
  • The ceilings are inclusive and sit one row below the first regressed size (65,536 rows for qk_cat, 8,192 for qk_rope_cat), so that size and everything above get 1 warp. Smaller shapes keep 4 warps, Triton's default (the same binary as passing nothing).
  • No other arch is seeded, gfx1250 included: without a table, _get_config returns {}, which is main's launch.
  • _get_config(config_name, M) picks the bucket at each launch with select_leq_config and the use of resolve_config_dir

Benchmark: op_tests/op_benchmarks/triton/bench_fused_qk_concat.py.

  • Default shapes: the unit tests' grid: B 1/4/8/16/32, QH_PER_KH 1/2/4/8/16, KH 1/4, D_nope 512, D_pe 64/128. That tops out at 2,048 rows, so only the 4-warp buckets; -B 4096 16384 --kh 1 --qh-per-kh 16 reaches the 1-warp ones.
  • Flags: --op, -B, --kh, --qh-per-kh, --d-nope, --d-pe, --dtype, --neox, --reuse-freqs-front-part, --max-embed-positions, --metric, --rep, -print_vgpr, -o (writes a CSV).
  • Timing: do_bench_cudagraph, preceded by a torch.cuda.synchronize(). The timer runs fn on a new stream that does not wait for the inputs, so without the sync qk_rope_cat can index cos/sin with a pos that hasn't been written yet

Test Plan

  • Perf: rocprofv3 --kernel-trace, trimmed-mean kernel time, on MI355X.
    • Shapes: 185.
      • 168 cover both ops: B 1–32768, QH 4–128, KH 1/4, D_pe 64/128, bf16 (plus 3 fp16 qk_cat shapes), and all four RoPE variants (GPT-J/NeoX x full/half-width cos/sin, e.g. reuse_freqs_front_part).
      • 17 use the input layout that SGLang's DeepSeek MLA path passed in v0.5.2-v0.5.6.post1: non-contiguous q_nope, q_pe and k_pe views, KH 1, D_pe 64, half-width cos/sin.
    • Regression rule: a baseline >= 4 µs and a result > 1.005 x baseline + 0.5 µs.
  • Correctness:
    • pytest op_tests/triton_tests/fusions/test_fused_qk_concat.py -v
  • Lint: black, ruff

Test Result

pytest: 600 passed, 60 warnings in 12.46s

shapes (gfx950) regressions: main 3.8 vs 3.4 this PR vs 3.4 this PR vs main 3.8
qk_cat bf16, D_pe 64 (60) 23 (+1% to +6%) 0 0
qk_cat bf16, D_pe 128 (12) 6 (+3% to +4%) 0 0
qk_cat fp16, D_pe 64 (3) 2 (+4% to +5%) 0 0
qk_rope_cat GPT-J, half-width cos/sin, D_pe 64 (59) 28 (+1% to +8%) 0 0
qk_rope_cat GPT-J, D_pe 128 (9) 4 (+2% to +4%) 0 0
qk_rope_cat NeoX, D_pe 64 (16) 13 (+6% to +18%) 0 0
qk_rope_cat NeoX, half-width cos/sin, D_pe 128 (9) 5 (+8% to +13%) 0 0
qk_rope_cat, SGLang DeepSeek MLA layout (17) 6 (+2% to +5%) 0 0

Every previously regressed shape is now at least as fast as Triton 3.4 (up to 52% faster) and 9-53% faster than main. No shape is slower than main beyond the expected noise threshold

op / shape B QH KH main, Triton 3.4 (µs) main, Triton 3.8 this PR vs main 3.8
qk_cat, D_pe 64 4096 16 1 26.76 27.82 (+4%) 23.82 (−11%) −14%
qk_cat, D_pe 64 2048 64 1 90.84 94.50 (+4%) 55.10 (−39%) −42%
qk_cat, D_pe 64 16384 64 1 639.20 672.57 (+5%) 506.66 (−21%) −25%
qk_cat, D_pe 128 4096 64 4 184.66 191.88 (+4%) 150.72 (−18%) −21%
qk_rope_cat GPT-J, half-width 2048 16 1 16.39 17.49 (+7%) 12.51 (−24%) −28%
qk_rope_cat GPT-J, half-width 4096 64 1 194.32 203.72 (+5%) 132.35 (−32%) −35%
qk_rope_cat NeoX 1024 16 1 9.71 11.10 (+14%) 6.71 (−31%) −40%
qk_rope_cat NeoX 16384 64 1 848.07 918.99 (+8%) 502.60 (−41%) −45%
qk_rope_cat NeoX, half-width, D_pe 128 128 64 1 6.93 7.76 (+12%) 5.40 (−22%) −30%
qk_rope_cat, SGLang layout 4096 128 1 367.79 375.76 (+2%) 222.74 (−39%) −41%
qk_rope_cat, SGLang layout 16384 16 1 201.07 209.34 (+4%) 118.74 (−41%) −43%

Submission Checklist

@nidal567 nidal567 self-assigned this Oct 8, 2026
@nidal567
nidal567 requested a review from a team October 8, 2026 19:47
@github-actions github-actions Bot changed the title benchmark + config + tuning for fused_qk_concat on gfx950 [Triton/Gluon] benchmark + config + tuning for fused_qk_concat on gfx950 Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 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: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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6287 --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.

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

Import-time GPU probing, incomplete kernel representations, and uncovered 1-warp paths should be addressed.

3 open findings
What changed in this PR

Adds gfx950-specific launch tuning and benchmarking for fused Q/K concatenation kernels.

Changes:

  • Selects 1- or 4-warp launches based on B × QH.
  • Adds gfx950 configuration tables.
  • Adds a configurable performance benchmark.
File Description
op_tests/​op_benchmarks/​triton/​bench_fused_qk_concat.py Adds benchmark and CLI.
aiter/​ops/​triton/​fusions/​fused_qk_concat.py Applies resolved launch configurations.
aiter/​ops/​triton/​_triton_kernels/​fusions/​fused_qk_concat.py Loads and selects configuration buckets.
aiter/​ops/​triton/​configs/​gfx950/​triton/​fusions/​fused_qk_cat/​DEFAULT.json Tunes concat warp counts.
aiter/​ops/​triton/​configs/​gfx950/​triton/​fusions/​fused_qk_rope_cat/​DEFAULT.json Tunes RoPE-concat warp counts.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@nidal567
nidal567 force-pushed the fused_qk_concat_bench_tune branch from 23d2cfc to 8e03cd2 Compare October 9, 2026 16:25
@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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

@aiter-bot

Copy link
Copy Markdown

[ROCm/aiter] PR #6287 — [Triton/Gluon] benchmark + config + tuning for fused_qk_concat on gfx950

Ships gfx950-only num_warps launch-config tables for the fused q/k concat and RoPE-concat kernels (4 warps below a per-kernel M = B×QH ceiling, 1 warp above), selected per launch through the shared config machinery, plus a CLI benchmark for both ops.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — the PR changes run-time launch code but ships no test target for the auto-run to pick up (auto-validation disabled, REVIEW_AUTO_VALIDATE=0); the changed path is executed at run time, so the coverage gap is reported as a finding below
Perf (advisory): NOT RUN — triage selected no perf target (the PR ships no test target) and the shipped benchmark could not be run by hand on this box (no torch/triton python env; all 8 GPUs at 94–95% VRAM); the PR's 185-shape rocprofv3 base-vs-head table is author-reported

⚠️ [verified] The 1-warp bucket this PR exists to ship — everything above M_LEQ_8191 in aiter/ops/triton/configs/gfx950/triton/fusions/fused_qk_rope_cat/DEFAULT.json and above M_LEQ_65535 in aiter/ops/triton/configs/gfx950/triton/fusions/fused_qk_cat/DEFAULT.json — is unreachable by every correctness test: the grid in op_tests/triton_tests/fusions/test_fused_qk_concat.py (B ≤ 32, QH ≤ 64 → M ≤ 2048), and therefore the reported "600 passed" and CI, exercise only the 4-warp launch main already uses, and the only harness that crosses the ceilings (the new benchmark) asserts no values — so a warp-count-specific defect in the 1-warp variant would ship silently. Author must add a case past at least one ceiling (e.g. B=8192, KH=1, QH_PER_KH=2 → M=16384, ideally with the SGLang non-contiguous layout) or state why num_warps=1 needs no correctness coverage.
⚠️ [inferred] Every eager launch on every arch now pays the uncached _get_config lookup at aiter/ops/triton/fusions/fused_qk_concat.py:58,146 (regex-validated path build + cached JSON load + bucket select, no memoization), a recurring host cost neither of the PR's timing methods can see — rocprofv3 measures kernel time and do_bench_cudagraph replays a captured graph — while below the ceilings (all decode shapes, and all of gfx942/gfx1250) the lookup returns main's own 4-warp launch; could this add measurable per-call latency on the per-layer MLA path? Author must measure wrapper host time at a decode shape base vs head, or memoize the bucket lookup, and confirm it is noise.
📝 [verified] No base-vs-head timing exists outside the author's own runs: auto-validation was disabled on this box and the shipped harness op_tests/op_benchmarks/triton/bench_fused_qk_concat.py could not be re-run here (no torch/triton python env), so the 185-shape rocprofv3 table (0 regressions, 9–53% faster than main) is author-reported. Reviewer should re-run the benchmark on base vs head on an MI355X before merging, or accept the numbers as author-reported.
📝 [verified] The new benchmark's default sweep (op_tests/op_benchmarks/triton/bench_fused_qk_concat.py: B 1–32, QH ≤ 64 → M ≤ 2048) never reaches the 1-warp bucket it exists to tune, so a bare run measures only main-equivalent 4-warp launches and cannot reproduce any number in the PR. Author must make the default grid cross at least one ceiling (the body documents -B 4096 16384 --kh 1 --qh-per-kh 16 but nothing runs it by default) or warn when every shape lands in one bucket.

@zufayu

zufayu commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks.

Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:

@aiter-bot review

  • Reviews the PR at its current head. Comment again after pushing fixes for a fresh pass; a repeat on the same commit is deduped.
  • One review runs at a time on one box, roughly 20 minutes. If work is ahead of you the bot replies with your place in the queue, and if the runner is down it says so rather than leaving you waiting for a review that will never start.
  • The card is advisory. It never blocks a merge, 🔴 included — it is there to be argued with.

Feedback on the review itself is welcome; it is how the rules get better.

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

Sharing some minor comments on the newly added benchmark script. Please internalize these design choices, and ship your next benchmark with them in place.

@nidal567
nidal567 force-pushed the fused_qk_concat_bench_tune branch from bace9f9 to 8154c4e Compare October 16, 2026 16:19

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

This PR is facing some CI issues at the moment, but as far as I can tell it's network related. Rerun failed shards and hope for the best.

@brunomazzottiamd

Copy link
Copy Markdown
Contributor

All Triton tests passed, merging...

@brunomazzottiamd
brunomazzottiamd merged commit 948dd26 into ROCm:main Oct 19, 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.

5 participants