Skip to content

[Triton/Gluon] fp8_mqa_logits: Do not recompile per batch size on gfx950 - #7022

Merged
azaidy merged 6 commits into
mainfrom
eppaneamd/mqa-logits-no-respecialize
Nov 13, 2026
Merged

azaidy merged 6 commits into
mainfrom
eppaneamd/mqa-logits-no-respecialize

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On gfx950, fp8_mqa_logits no longer compiles a new Gluon kernel variant when the number of query rows, KV rows or KV splits changes, so serving prefills no longer stall on recompiling this kernel.

Motivation

The gfx950 Gluon kernel of fp8_mqa_logits compiles a new variant when the number of query rows, KV rows or KV splits changes Triton's integer specialization class (equal to 1, divisible by 16, or other). In a serving prefill these values change with every batch, so the kernel compiles again while the server is already serving requests. Each compile stalls the batch for about 0.6 s on MI355X.

The gl.int32 annotations on these arguments do not stop the specialization. The comment on num_kv_splits ("runtime value to remove unexpected compilations") shows that this was the intent.

Changes

  • aiter/ops/triton/_gluon_kernels/gfx950/attention/fp8_mqa_logits.py: _gluon_fp8_mqa_logits_kernel adds do_not_specialize=["seq_len", "seq_len_kv", "num_kv_splits"].
    • At the base commit, seq_len is used once, in the row clamp of the BLOCK_M == 2 path (:962). seq_len_kv clamps each row's KV range (:999, :1004, :1024). num_kv_splits divides the KV tiles among the splits (:1013).
    • The generated gfx950 code is identical with these values plain or divisible by 16, for 5 launch configurations (compiled on CPU and compared).
    • The launch constexprs (BLOCK_M, BLOCK_KV, HAS_KV_SPLIT, ...) are not changed, so each launch configuration still compiles once.
  • Scope: every fp8_mqa_logits call on gfx950 with Triton 3.6 or later, which selects the Gluon kernel. The gfx1250 Gluon kernel and the Triton kernel (other architectures, and Triton before 3.6) are not changed.

Performance (if applicable)

MI355X, image and runs as in "Validation and unverified scope"; mean of two runs per side.

Compile cost, one process, query rows 16 → 17 → 1 → 33 (64 heads, 1024 KV rows), wall time of the first call at each size:

Query rows Without this PR (ms) With this PR (ms)
16 1269 1270
17 589 0.24
1 597 0.12
33 0.11 0.10

The first call compiles on both sides. Without this PR, 17 and 1 query rows compile again.

Kernel time (KV splits as the launcher picks them):

python op_tests/op_benchmarks/triton/bench_fp8_mqa_logits.py --metric time --num_heads_q <H> --seq_q_l <N> --seq_kv_l <M>
Heads Query rows KV rows KV splits Without (µs) With (µs) Change
64 1 4096 1 37.1 37.2 +0.2 %
64 16 4096 1 29.5 29.6 +0.3 %
64 17 4096 1 29.7 29.8 +0.2 %
64 1000 4096 1 50.9 50.9 −0.1 %
64 4096 8192 1 248.3 248.8 +0.2 %
32 4096 8192 1 159.2 159.4 +0.1 %
64 16 65536 4 89.1 89.3 +0.3 %

Testing

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

Documentation

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

Only the arguments that Triton specializes on change; the API and the outputs do not.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

5a90ed984c38dc41337e5ff0e606fea70a2a936a

Behavior and intent

Each launch configuration now compiles one variant, whatever the number of query rows, KV rows and KV splits; before, every change of class of these values compiled a new variant while serving (see Motivation). Logits and kernel time do not change: the generated gfx950 code is the same with these values plain or divisible by 16.

Validation and unverified scope

Setup:

  • AMD Instinct MI355X (gfx950), one GPU.
  • Image lmsysorg/sglang-rocm:v0.5.22-rocm724-mi35x-20261021 (AITER 285579b621, whose kernel file equals this PR's base; Triton 3.7.0). The kernel file is replaced by this PR's file for "with this PR"; both sides run this PR's test file.
  • Two runs per side, each in a fresh container with an empty Triton cache. Tests at 1034524fa0; Performance at 4a655057e1, which has the same kernel file.

Results, the same in both runs of each side:

  • pytest op_tests/triton_tests/attention/test_fp8_mqa_logits.py at 1034524fa0: 159 passed with this PR; 158 passed and 1 failed without it (test_fp8_mqa_logits_query_rows_do_not_add_specializations, assert 3 == 1). That test was removed from this PR in review (5a90ed984), so the PR no longer adds a test; the logits tests are unchanged.
  • bench_fp8_mqa_logits.py --metric time: −0.1 % to +0.3 % (Performance).

Unverified: the gfx1250 Gluon kernel (same arguments, not changed here, no gfx1250 hardware) and Triton versions other than 3.7.0. Not run on MI250X or MI300X: this PR changes only the gfx950 Gluon kernel. The merge of main (6867e39f2) and the test removal change neither the kernel file nor its behavior and have not run on a GPU; CI runs on the push. Nothing in the repository now checks that the kernel compiles once per launch configuration.

PR-specific question

What is the most important boundary or failure mode introduced by this change, and what evidence covers it?

do_not_specialize makes seq_len, seq_len_kv and num_kv_splits plain runtime values, so Triton can no longer assume that they are divisible by 16 (or equal to 1). If the kernel's code relied on that, results or speed would differ for the sizes that were divisible. Evidence: the generated gfx950 code is identical with these values plain or divisible by 16, for 5 launch configurations (compiled on CPU and compared; see Changes); test_fp8_mqa_logits passes (159 passed at 1034524fa0); kernel time is within -0.1 % to +0.3 % for 7 shapes (Performance).

Changed op tests

None. This PR changes no file under op_tests/: the specialization test it added was removed in review.

This change was developed with AI assistance (Claude); I reviewed every line and ran the tests listed.

seq_len, seq_len_kv and num_kv_splits change with the batch, and Triton
specialized _gluon_fp8_mqa_logits_kernel on each (divisible by 16, and a
separate key for 1), so a serving prefill compiled a new variant whenever
the query row count changed class. The gl.int32 annotations do not stop
this. Their divisibility does not change the generated gfx950 code.

Mark them do_not_specialize, and add a test that query row counts 16, 17,
1 and 33 reuse one compiled variant, with logits checked against the
reference.

Signed-off-by: Rony Leppänen <[email protected]>
Co-authored-by: Claude <[email protected]>
@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 7022 --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

The FP8 MQA logits tests duplicate input setup, which should be extracted into a shared helper to avoid keeping changes synchronized manually.

1 open issue
What changed in this PR

This PR prevents batch-dependent recompilation of the gfx950 Gluon fp8_mqa_logits kernel while preserving specialization for launch configurations.

Changes:

  • Disables integer specialization for query rows, KV rows, and KV splits.
  • Adds a gfx950 regression test that checks output accuracy and requires one compiled variant across four query-row counts.
File Description
op_tests/​triton_tests/​attention/​test_fp8_mqa_logits.py Adds accuracy and compilation-cache checks for varying query-row counts.
aiter/​ops/​triton/​_gluon_kernels/​gfx950/​attention/​fp8_mqa_logits.py Marks three runtime arguments as non-specializing.

Review effort: Balanced

…alization test

The specialization test repeated the input setup and the reference check
of test_fp8_mqa_logits. Call that test for each query row count instead,
with the same 64 heads, 1024 KV rows and checks.

Signed-off-by: Rony Leppänen <[email protected]>
Co-authored-by: Claude <[email protected]>
@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 79e91318b528 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What is the most important boundary or failure mode introduced by this change, and what evidence covers it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

@fhuizing fhuizing self-assigned this Oct 30, 2026
fhuizing
fhuizing previously approved these changes Oct 30, 2026
@fhuizing
fhuizing marked this pull request as ready for review October 30, 2026 09:07
@fhuizing
fhuizing requested a review from a team October 30, 2026 09:07
@zufayu
zufayu requested review from a team and k50112113 November 2, 2026 01:25
@azaidy
azaidy requested a review from cagrikymk November 4, 2026 09:14
@cagrikymk

Copy link
Copy Markdown
Contributor

@eppaneamd Could you take a look at the review I added?

eppaneamd and others added 2 commits November 9, 2026 15:40
No conflicts: main has not changed either of this branch's two files since
the previous merge.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Review on #7022: the compiled-variant count is a minor thing to test for.
test_fp8_mqa_logits_query_rows_do_not_add_specializations is removed; the
kernel change stands alone.

Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 21:42

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.

🟢 Approval recommended

No active review issues are reported for the change to avoid batch-size-triggered kernel recompilation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@eppaneamd
eppaneamd requested a review from cagrikymk November 9, 2026 21:47
@cagrikymk

Copy link
Copy Markdown
Contributor

LGTM! I think any kind of warmup should capture these recompilations as there are very few modes and these args are not constexpr but still an improvement!

waqahmed-amd-fi added a commit that referenced this pull request Nov 10, 2026
…h size on gfx950

PR head 5a90ed9, applied as its diff against merge base 1eab5ae.

Co-authored-by: Cursor <[email protected]>
waqahmed-amd-fi added a commit that referenced this pull request Nov 10, 2026
…h size on gfx950

PR head 5a90ed9, applied as its diff against merge base 1eab5ae.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 16:38

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.

🔵 Needs a closer look

The JIT specialization change requires gfx950 runtime testing to confirm compile-cache reuse and performance across supported Triton versions, which source-only review cannot establish.

No open issues 🎉

Review effort: Balanced

@zufayu
zufayu requested review from a team and removed request for a team November 13, 2026 01:49

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

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.

6 participants