Skip to content

[HIP] [FlyDSL] [CI] Add aiter.paged_mqa_logits with a tuned Gluon/FlyDSL table - #6140

Merged
samremes merged 22 commits into
ROCm:mainfrom
amd-sriram:rocm/paged-mqa-logits-dispatch
Nov 3, 2026
Merged

samremes merged 22 commits into
ROCm:mainfrom
amd-sriram:rocm/paged-mqa-logits-dispatch

Conversation

@amd-sriram

@amd-sriram amd-sriram commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

vLLM calls the Gluon paged MQA-logits kernel directly, with fixed ChunkK=256, WavePerEU=2. Moving to the FlyDSL kernel from #4221 took a vLLM PR (vllm-project/vllm#59422), and so would every later switch as the kernels improve. This adds aiter.paged_mqa_logits: the framework asks for paged MQA logits, and AITER picks the backend and its launch settings from a tuned table, the way fused_moe does.

What it adds

  • paged_mqa_logits(...): takes the same tensors as deepgemm_fp8_paged_mqa_logits. context_lens is [B], as the kernels on main read it. (B, next_n) support comes with [Triton/Gluon] [FlyDSL] Read (B, next_n) context lengths in the paged MQA logits kernels #6153.
  • A tuned table keyed on what a decode CUDA graph fixes at capture: (gfx, cu_num, batch_size, next_n, heads, head_dim, kv_block_size, preshuffle). Each row picks Gluon (ChunkK, WavePerEU) or FlyDSL (wg_per_cu). Rows are looked up with the live GPU arch (get_gfx_runtime()), the same one the tuner records.
  • A tuner. It checks every candidate against a torch reference before timing it, then keeps the fastest by geomean over the context lengths in the untuned file (8192 and 60000 for GLM-5). A FlyDSL row also stores the best Gluon ChunkK and WavePerEU. Context length cannot be a key, because reading it needs a host sync.
  • gfx950 rows for the GLM-5 indexer (H=32, D=128, KV block 64): next_n 1..8, batch 1..256.

Without a matching row it runs Gluon with today's ChunkK=256, WavePerEU=2, so an empty table changes nothing. A FlyDSL row is only used where the kernel can run (gfx950, H=32, D=128, KV block 64, preshuffled, next_n <= 8, KV cache under 2 GiB); otherwise the call runs Gluon with the ChunkK and WavePerEU the tuner measured for that row.

Same structure as fused MoE

fused MoE paged MQA logits
Entry point aiter/fused_moe.py aiter/paged_mqa_logits.py
Config AITER_CONFIG_FMOE AITER_CONFIG_PAGED_MQA_LOGITS
Generic table configs/tuned_fmoe.csv configs/paged_mqa_logits_tuned.csv
Per-model rows model_configs/*tuned_fmoe_glm5*.csv model_configs/paged_mqa_logits_tuned_glm5.csv
Tuner csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py csrc/paged_mqa_logits/paged_mqa_logits_tune.py
Test op_tests/test_moe_2stage.py op_tests/test_paged_mqa_logits.py

Difference from #4221: explicit SplitKV

With SplitKV=None, the #4221 wrapper computes min(ceil(context_lens.max() / 64), ceil(cu * 3 / B)). Its context_lens.max() call reads the device on the host, which fails under CUDA graph capture, and decode runs under graphs.

This op always passes an explicit SplitKV = min(ceil(max_model_len / 64), ceil(cu * wg_per_cu / B)), built only from values fixed at capture, with wg_per_cu tuned per row (default 3). The two agree except at small batch with short contexts. Every FlyDSL row in the shipped table is at batch >= 64, where they agree.

Test Result

MI355X (gfx950), this branch at bcfd182e6 (base 7bfe279de), Triton 3.8.0, FlyDSL 0.3.4.1.

  • Kernel time against today's default (Gluon ChunkK=256, WavePerEU=2): -10.7% geomean at 8k context, -18.3% at 60k. Best -52.7%, worst +1.8%.
  • FlyDSL wins 16 of the 72 shapes, all at batch >= 64. Gluon wins the rest, all but one with WavePerEU=4.
  • Every candidate matches torch (exact -inf mask, calc_diff < 1e-3) with [B] context_lens.
  • --run_config: 71/72 rows within 10% of the tuned time. The other one (batch 16, next_n=2) measured +11.9%, then within 2.3% on three reruns. Collision guard: OK.
  • Not measured end to end. Microbenchmarks miss one effect [FlyDSL] Paged mla indexer #4221 reports: FlyDSL keeps its logit stores in L2 for the following top-k.
python3 csrc/paged_mqa_logits/paged_mqa_logits_tune.py \
    -i aiter/configs/model_configs/paged_mqa_logits_untuned_glm5.csv \
    -o aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv
python3 csrc/paged_mqa_logits/paged_mqa_logits_tune.py --run_config aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv
python3 op_tests/test_paged_mqa_logits.py
python3 -m unittest op_tests.tuning_tests.test_config_shape_collision.TestConfigShapeCollision.test_paged_mqa_logits
All 72 shapes (us; default = Gluon ChunkK=256, WavePerEU=2)
next_n batch default 8k default 60k picked 8k 60k vs default 8k vs default 60k
1 1 3.68 5.12 gluon ChunkK=128 WavePerEU=2 3.37 5.03 -8.4% -1.8%
1 2 4.01 6.13 gluon ChunkK=128 WavePerEU=4 3.72 6.24 -7.2% +1.8%
1 4 4.57 9.30 gluon ChunkK=128 WavePerEU=4 4.31 9.31 -5.7% +0.1%
1 8 5.36 17.90 gluon ChunkK=256 WavePerEU=4 5.37 14.80 +0.2% -17.3%
1 16 6.62 30.80 gluon ChunkK=256 WavePerEU=4 6.58 27.63 -0.6% -10.3%
1 32 10.43 59.29 gluon ChunkK=256 WavePerEU=4 9.41 53.30 -9.8% -10.1%
1 64 18.70 115.74 flydsl wg_per_cu=3 17.22 99.51 -7.9% -14.0%
1 128 31.82 199.26 gluon ChunkK=256 WavePerEU=4 29.91 191.31 -6.0% -4.0%
1 256 60.44 374.84 flydsl wg_per_cu=3 54.27 375.95 -10.2% +0.3%
2 1 3.77 6.06 gluon ChunkK=128 WavePerEU=4 3.48 5.99 -7.7% -1.2%
2 2 4.20 8.55 gluon ChunkK=256 WavePerEU=4 4.19 8.11 -0.2% -5.1%
2 4 4.96 15.59 gluon ChunkK=256 WavePerEU=4 4.96 12.62 +0.0% -19.1%
2 8 5.80 22.11 gluon ChunkK=256 WavePerEU=4 5.83 17.86 +0.5% -19.2%
2 16 8.56 41.04 gluon ChunkK=256 WavePerEU=4 7.34 33.35 -14.3% -18.7%
2 32 14.40 78.63 gluon ChunkK=256 WavePerEU=4 11.79 65.12 -18.1% -17.2%
2 64 22.36 128.85 gluon ChunkK=256 WavePerEU=4 19.63 117.44 -12.2% -8.9%
2 128 39.00 242.13 gluon ChunkK=256 WavePerEU=4 35.27 231.35 -9.6% -4.5%
2 256 75.00 550.40 flydsl wg_per_cu=3 68.37 457.82 -8.8% -16.8%
3 1 3.85 7.09 gluon ChunkK=128 WavePerEU=4 3.57 6.80 -7.3% -4.1%
3 2 4.33 11.74 gluon ChunkK=256 WavePerEU=4 4.33 10.29 +0.0% -12.4%
3 4 5.22 17.25 gluon ChunkK=128 WavePerEU=4 4.83 15.63 -7.5% -9.4%
3 8 6.85 23.48 gluon ChunkK=256 WavePerEU=4 6.29 21.81 -8.2% -7.1%
3 16 9.52 41.76 gluon ChunkK=256 WavePerEU=4 9.11 39.30 -4.3% -5.9%
3 32 15.73 82.29 gluon ChunkK=256 WavePerEU=4 13.88 74.29 -11.8% -9.7%
3 64 27.03 158.23 gluon ChunkK=256 WavePerEU=4 23.39 138.73 -13.5% -12.3%
3 128 47.70 342.87 flydsl wg_per_cu=3 43.04 267.29 -9.8% -22.0%
3 256 99.29 860.68 flydsl wg_per_cu=3 79.08 514.28 -20.4% -40.2%
4 1 4.02 8.44 gluon ChunkK=128 WavePerEU=4 3.76 8.45 -6.5% +0.1%
4 2 4.82 15.16 gluon ChunkK=256 WavePerEU=4 4.83 12.53 +0.2% -17.3%
4 4 5.34 19.92 gluon ChunkK=256 WavePerEU=4 5.36 15.66 +0.4% -21.4%
4 8 7.92 34.15 gluon ChunkK=256 WavePerEU=4 6.87 26.15 -13.3% -23.4%
4 16 12.86 62.19 gluon ChunkK=256 WavePerEU=4 10.48 49.16 -18.5% -21.0%
4 32 19.75 99.94 gluon ChunkK=256 WavePerEU=4 16.84 84.80 -14.7% -15.1%
4 64 33.47 187.37 gluon ChunkK=256 WavePerEU=4 28.60 165.07 -14.6% -11.9%
4 128 60.86 377.41 flydsl wg_per_cu=3 51.62 311.80 -15.2% -17.4%
4 256 120.30 1146.94 flydsl wg_per_cu=3 93.67 605.61 -22.1% -47.2%
5 1 4.11 10.77 gluon ChunkK=256 WavePerEU=4 4.12 9.05 +0.2% -16.0%
5 2 5.01 12.75 gluon ChunkK=128 WavePerEU=4 4.65 12.22 -7.2% -4.2%
5 4 6.61 23.25 gluon ChunkK=256 WavePerEU=4 5.80 18.12 -12.3% -22.1%
5 8 8.95 36.92 gluon ChunkK=256 WavePerEU=4 8.33 29.37 -6.9% -20.4%
5 16 13.96 69.39 gluon ChunkK=256 WavePerEU=4 11.66 56.58 -16.5% -18.5%
5 32 21.83 120.06 gluon ChunkK=256 WavePerEU=4 18.93 102.18 -13.3% -14.9%
5 64 37.58 234.44 gluon ChunkK=256 WavePerEU=4 32.39 195.91 -13.8% -16.4%
5 128 69.94 562.20 flydsl wg_per_cu=3 60.85 369.80 -13.0% -34.2%
5 256 145.55 1388.57 flydsl wg_per_cu=3 110.64 722.10 -24.0% -48.0%
6 1 4.30 11.62 gluon ChunkK=256 WavePerEU=4 4.29 10.15 -0.2% -12.7%
6 2 5.05 16.93 gluon ChunkK=128 WavePerEU=4 4.70 15.29 -6.9% -9.7%
6 4 6.52 21.78 gluon ChunkK=256 WavePerEU=4 5.85 19.45 -10.3% -10.7%
6 8 9.22 37.73 gluon ChunkK=256 WavePerEU=4 8.66 33.03 -6.1% -12.5%
6 16 14.81 74.31 gluon ChunkK=256 WavePerEU=4 13.05 63.39 -11.9% -14.7%
6 32 25.36 136.47 gluon ChunkK=256 WavePerEU=4 21.43 116.78 -15.5% -14.4%
6 64 43.06 264.09 gluon ChunkK=256 WavePerEU=4 37.40 226.57 -13.1% -14.2%
6 128 81.60 533.85 flydsl wg_per_cu=2 69.00 426.12 -15.4% -20.2%
6 256 166.37 1665.84 flydsl wg_per_cu=3 126.90 828.08 -23.7% -50.3%
7 1 4.44 13.48 gluon ChunkK=256 WavePerEU=4 4.46 11.96 +0.5% -11.3%
7 2 5.06 18.44 gluon ChunkK=256 WavePerEU=4 5.07 14.65 +0.2% -20.6%
7 4 7.24 31.31 gluon ChunkK=256 WavePerEU=4 6.34 22.74 -12.4% -27.4%
7 8 11.17 52.82 gluon ChunkK=256 WavePerEU=4 9.46 40.86 -15.3% -22.6%
7 16 17.21 85.60 gluon ChunkK=256 WavePerEU=4 14.61 71.43 -15.1% -16.6%
7 32 27.75 153.77 gluon ChunkK=256 WavePerEU=4 23.89 132.71 -13.9% -13.7%
7 64 47.64 300.26 gluon ChunkK=256 WavePerEU=4 41.48 255.19 -12.9% -15.0%
7 128 89.83 790.93 flydsl wg_per_cu=2 76.64 481.30 -14.7% -39.1%
7 256 190.50 1952.05 flydsl wg_per_cu=3 143.32 943.14 -24.8% -51.7%
8 1 4.69 15.13 gluon ChunkK=256 WavePerEU=4 4.67 12.58 -0.4% -16.9%
8 2 5.24 19.37 gluon ChunkK=256 WavePerEU=4 5.24 15.16 +0.0% -21.7%
8 4 7.53 32.00 gluon ChunkK=256 WavePerEU=4 6.49 24.43 -13.8% -23.7%
8 8 12.50 57.95 gluon ChunkK=256 WavePerEU=4 10.22 44.91 -18.2% -22.5%
8 16 19.05 92.81 gluon ChunkK=256 WavePerEU=4 16.12 77.35 -15.4% -16.7%
8 32 32.04 168.52 gluon ChunkK=256 WavePerEU=4 27.19 147.53 -15.1% -12.5%
8 64 56.89 331.07 flydsl wg_per_cu=2 46.91 277.58 -17.5% -16.2%
8 128 102.70 681.59 flydsl wg_per_cu=2 85.20 535.19 -17.0% -21.5%
8 256 209.61 2227.68 flydsl wg_per_cu=3 158.19 1054.64 -24.5% -52.7%

PR Self-Review

Reviewed revision

8b797cb

Behavior and intent

Adds a new entry point, aiter.paged_mqa_logits. vLLM main calls the Gluon kernel deepgemm_fp8_paged_mqa_logits directly with fixed ChunkK=256, WavePerEU=2, so every move to a faster kernel or launch setting needs a vLLM PR. With this, AITER picks Gluon (tuned ChunkK/WavePerEU) or FlyDSL (wg_per_cu) per decode shape from a tuned CSV, the way fused_moe does. One existing behavior changes: the gfx950 FlyDSL paged kernel checks the GPU it runs on (get_gfx_runtime()) instead of GPU_ARCHS (get_gfx()), the same as the table lookup. With GPU_ARCHS=gfx942 on a gfx950 GPU it used to raise RuntimeError; now it runs. The tuning CI workflow also uploads aiter/configs/model_configs/*.csv.

Validation and unverified scope

MI355X (gfx950, 256 CUs), image amdsiloai/vllm-private:glm53flash_nightly1014_week43_best_monofp8_20261022, this PR's tree on PYTHONPATH (8b797cb for the op test, daf4e64 for the rest; they differ only in the op test):

  • python3 op_tests/test_paged_mqa_logits.py: passed. The op, Gluon and FlyDSL match the reference (same -inf mask, calc_diff < 1e-3) on the 9 default shapes (batch 1/16/128, next_n 1/3/5, 8k context). It also checks dispatch to the shipped row under GPU_ARCHS=gfx942, the FlyDSL-to-Gluon fallback, strided context_lens rejection, the (B, next_n) table through the op and both backends (checkAllclose passed), and CUDA graph replay: the op, Gluon and FlyDSL are captured at 1024 tokens, context_lens is changed to 512 in place, and the replay matches the reference at 512. A launch that baked the lengths at capture fails this check (negative control run).
  • pytest -k paged_mqa_logits op_tests/tuning_tests/: test_config_shape_collision passed. test_run_config failed on timing only: it compares each row's time to the CSV and does not check output. 68/72 rows were within 10% and 4 drifted more; the previous head showed 6-8 such rows on another MI355X box.
  • csrc/paged_mqa_logits/paged_mqa_logits_tune.py --all --verbose on the 72 shapes (8 GPUs in parallel): every candidate passed the reference check before timing (0 rejected, 72/72 tuned). The shipped picks are within 3.6% of the re-run's geomean winner. Per-context gaps are up to 9.4% at 8k and 20.7% at 60k (see the review reply).
  • Tuner exit code (Finished -> 0, Error/Interrupted -> 1) and the 8192;60000 default for a CSV without context_len were checked on 2026-10-24. The tuner has changed since only by the per-context logging.

Unverified: FlyDSL 0.4.1 (main's current pin; the image has 0.4.0); gfx942 (no table rows, so it uses the Gluon default); end-to-end vLLM serving (no vLLM caller yet); the CI tuning workflow itself (manual dispatch only, not run).

PR-specific question

Two CI files change. .github/scripts/op_tune.sh adds one entry to its list of tuning jobs, and .github/workflows/operators-tuning.yaml widens the artifact upload path to also include aiter/configs/model_configs/*.csv. op_tune.sh is only called by that workflow, and the workflow's only trigger is workflow_dispatch: it runs when someone with write access starts it on a ROCm/aiter branch, on runner linux-aiter-oci-mi300x-1. A fork PR can't trigger it or select its branch. This PR doesn't change its trigger, permissions or secrets, and neither change reads PR input; the upload only adds CSVs the job itself writes.

Changed op tests

  • op_tests/test_paged_mqa_logits.py (new): the only test of the new aiter.paged_mqa_logits dispatch. It runs the op and both backends against the reference, and checks shipped-row dispatch on the live GPU, the FlyDSL-to-Gluon fallback, strided-input rejection, the 2D context_lens table, and CUDA graph capture and replay with lengths changed after capture. The existing kernel tests (op_tests/test_flydsl_fp8_paged_mqa_logits.py, op_tests/triton_tests/attention/test_pa_mqa_logits_2d_context_lens.py) call each kernel directly and never go through the dispatch.
  • op_tests/tuning_tests/test_config_shape_collision.py (+4): adds the new paged_mqa_logits_tuned family to the shared duplicate-shape check, as every tuned family is.
  • op_tests/tuning_tests/test_run_config.py (+9): adds the new tuner to the shared --run_config check, as every tuner is.

@amd-sriram
amd-sriram requested review from a team and a balanced review from Copilot October 4, 2026 20:35
@github-actions

github-actions Bot commented Oct 4, 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
multigpu 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 6140 --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.

Copilot review overview

🟡 Changes recommended

The merge collision key incorrectly includes context-length metadata, allowing runtime-equivalent configurations to overwrite one another silently.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds a unified paged FP8 MQA-logits entry point that selects tuned Gluon or FlyDSL configurations by runtime shape.

Changes:

  • Adds tuned backend dispatch and configuration loading.
  • Adds a tuner, correctness tests, and configuration guards.
  • Ships GLM-5 gfx950 tuning data.
File Description
aiter/​paged_mqa_logits.py Implements tuned dispatch and fallback logic.
aiter/​jit/​core.py Registers the configuration family.
csrc/​paged_mqa_logits/​paged_mqa_logits_tune.py Adds backend tuning and validation.
op_tests/​test_paged_mqa_logits.py Tests dispatch and both backends.
op_tests/​tuning_tests/​test_run_config.py Registers run-config validation.
op_tests/​tuning_tests/​test_config_shape_collision.py Registers collision checking.
aiter/​configs/​paged_mqa_logits_tuned.csv Defines the tuned-table schema.
aiter/​configs/​paged_mqa_logits_untuned.csv Defines tuning inputs.
aiter/​configs/​model_configs/​paged_mqa_logits_tuned_glm5.csv Supplies tuned GLM-5 rows.
aiter/​configs/​model_configs/​paged_mqa_logits_untuned_glm5.csv Supplies GLM-5 tuning shapes.

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

@amd-bartgips
amd-bartgips marked this pull request as draft October 5, 2026 08:18

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

Thanks, this is the right shape for the op: one entry point, a CSV the call already reads, and an explicit SplitKV so decode can stay inside a CUDA graph. Three changes before merge, plus one question.

Lookup should use the live GPU. get_paged_mqa_logits_config and flydsl_supports call get_gfx(), which follows GPU_ARCHS. The tuner stamps rows with get_gfx_runtime(), and fused_moe looks up the same way. On a gfx950 GPU with GPU_ARCHS=gfx942, batch 64 / next_n=8 returned the default Gluon launch (ChunkK=256, WavePerEU=2). The shipped row for that shape is FlyDSL wg_per_cu=2. Numerics stay correct and the table is skipped with no error. Please look up with get_gfx_runtime(), and assert in the op test that a known CSV row is what paged_mqa_logits actually launches.

The merge key is wider than the runtime key. update_config_files dedups on the untuned header, which includes context_len. _load_tuned_table does not, and a later row overwrites on batch_size. Two files that share the runtime shape and differ only in the context string (8192;32768 vs 4096;16384) pass the collision test, then one disappears at load. The GLM-5 file is clean today. Please drop context_len from the untuned key and keep it as tuner metadata. It cannot be a runtime key: the length lives in a GPU tensor, and reading it syncs the host under CUDA graph capture.

A rejected FlyDSL row should fall back to the Gluon knobs the tuner measured. Above 2 GiB, flydsl_supports is false (the kernel's page offset is fx.Int32, PAGE_BYTES=8448) and the call substitutes ChunkK=256, WavePerEU=2. That default is correct. It is not the Gluon candidate that won the sweep. A FlyDSL row stores ChunkK=0, WavePerEU=0, so those knobs are gone. For next_n=8, batch=64 the row's gluon_us is 89.05; the default's geomean is about 102.5. Please keep the winning Gluon ChunkK and WavePerEU on the row and use them when FlyDSL cannot run.

Question, not a change request. Context length cannot be a lookup index, so one row has to serve 8k, 32k, and everything in between, and the tuner picks by sqrt(t_8k * t_32k). For next_n=1, batch=256 that selects FlyDSL (54.19 / 225.10 us, geomean 110.4) over the default Gluon (60.07 / 216.29 us, geomean ~114) even though FlyDSL is +4.1% at 32k. If GLM-5 decode for this shape sits near 32k, a score that rejects a long-context loss would fit better. If those calls are usually short, the geomean is the right rule. The other 32k cells in the table still favor FlyDSL.

Not blocking: please add a one-line recipe to .github/scripts/op_tune.sh pointing at paged_mqa_logits_tune.py and the GLM-5 CSVs, so the manual tuning workflow can reach this family.

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

Line notes for the review above.

Comment thread aiter/paged_mqa_logits.py Resolved
Comment thread aiter/paged_mqa_logits.py Resolved
@amd-sriram

amd-sriram commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Lookup should use the live GPU. get_paged_mqa_logits_config and flydsl_supports call get_gfx(), which follows GPU_ARCHS. The tuner stamps rows with get_gfx_runtime(), and fused_moe looks up the same way. On a gfx950 GPU with GPU_ARCHS=gfx942, batch 64 / next_n=8 returned the default Gluon launch (ChunkK=256, WavePerEU=2). The shipped row for that shape is FlyDSL wg_per_cu=2. Numerics stay correct and the table is skipped with no error. Please look up with get_gfx_runtime(), and assert in the op test that a known CSV row is what paged_mqa_logits actually launches.

@amd-bartgips I added a test case - check_launches_shipped_row() for checking if the GPU_ARCHS is set to the wrong chip, does the op still use the tuned setting for this card?

Comment thread aiter/paged_mqa_logits.py Resolved
Comment thread aiter/paged_mqa_logits.py Resolved

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

Backend dispatch and graph capture require independent GPU validation and human review, and the tuning artifact omission remains unresolved.

1 open issue

Review effort: Balanced

Comment thread .github/scripts/op_tune.sh Resolved

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

Review: PR #6140 — paged_mqa_logits GLM-5 tuning

The tuned/untuned CSV pair, the shape-keyed dispatch, and the base-tuner
subclass all follow the existing pattern. The notes below are about the
context-length tuning structure, which diverges from the attention precedent.

1. Context is provenance, not a dispatch key (divergence from HSTU)

Comment on aiter/paged_mqa_logits.py:90 (the key tuple).

Now: the loader keys on (gfx, cu_num, next_n, heads, head_dim, kv_block_size, preshuffle) with batch_size nested. context_len is read from
the row but never used. The closest precedent, HSTU attention
(hstu_attention_tuned.csv), keys on max_seq_len and buckets it with
prev_power_of_2.

Why it differs: HSTU gets max_seq_len as a host-side int, so keying is
free. Here context_lens is a [B] GPU tensor, so keying would force a host
sync at launch. So this op cannot follow the HSTU pattern and instead tunes one
config to be good across a context range. This is a reasonable divergence, and it
is documented in the docstring.

Ask: keep the "provenance only, dispatch does not key on it" note prominent,
so a future reader does not try to key on context_len.

2. The semicolon-list cell has no precedent

Comment on aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv:2 (a data
row, context_len = 8192;60000).

Now: no other tuned CSV in the repo uses a multi-value cell. The value is a
list because dispatch is context-agnostic, so there is one row per shape and the
tuned contexts collapse into one cell. The loader ignores the column, so it is
harmless to dispatch.

Not covered: the format is non-standard. A generic CSV tool, or a future
loader that tried to key on context_len, would mis-parse 8192;60000.

Fix: none required for this loader. Please keep a comment near the loader that
context_len is a free-text provenance column, not parsed, so no one later adds
int(row["context_len"]) and breaks on the list.

3. One config per shape across 8k and 60k can hide a divergence

Comment on csrc/paged_mqa_logits/paged_mqa_logits_tune.py:100 (_geomean).

Now: the tuner times each candidate at 8192 and 60000 and picks the best
geomean, then writes one row with context_len = 8192;60000 and that geomean.

Not covered: the geomean hides whether the per-context optima agree. If 8k and
60k want the same config, the compromise is free. If 60k is more memory-bound and
wants a larger ChunkK than 8k, the single picked config is slower at one end,
and the geomean masks it. The tuner records the contexts and the geomean, not the
per-context times.

Fix: log the per-context time for the chosen config, or the gap between the
per-context best and the geomean winner. If 8k and 60k diverge by more than a few
percent, note it. In that case consider taking a host-side context-bucket hint
(like HSTU's max_seq_len) so dispatch can key per context without a sync.

4. The context_lens contract tightened (not tuning)

Comment on aiter/paged_mqa_logits.py:215.

Now: the old _per_sequence_context_lens handling of 2D [B, next_n]
context_lens (take the last column) is removed. The op now requires [B]
contiguous int32 and rejects a strided tensor.

Not covered: a caller that passed the 2D or strided form went through the old
path and now gets a hard error.

Fix: confirm no caller passes 2D or strided context_lens, or keep accepting
the 2D form and normalize it as before.

Summary

The tuning structure mostly follows precedent. The one justified divergence is
treating context as provenance, not a key, because context_lens is a GPU
tensor. The thing worth pushing on is finding 3: the single cross-context config
can leave perf at one end, and the geomean hides it. Log the per-context times so
that cost is visible.

Dispatch deliberately does not key on context length; say so up front and at the loader, where the context_len column is free text that is never parsed (only the tuner reads it). Both kernels read the (B, next_n) table vLLM builds since ROCm#6451 and ROCm#6450, so the contract now lists it.
Uses the shipped B=64, next_n=8 row, which dispatches to FlyDSL, and checks the op, Gluon and FlyDSL against the reference.
The pick minimises the geomean over the row's contexts, which can hide a context where it is well off that context's best. Print the pick's time, the per-context best and the loss for every context.
The paged_mqa_logits job writes aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv, which aiter/configs/*.csv does not match.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:12
@amd-sriram

amd-sriram commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

keep the "provenance only, dispatch does not key on it" note prominent

Done - b9a19cc. It's its own paragraph in the module docstring now.

Please keep a comment near the loader that context_len is a free-text provenance column, not parsed

Done - b9a19cc. The loader now says context_len is free text such as 8192;60000 that it never parses; only the tuner reads it, as the lengths to time.

log the per-context time for the chosen config, or the gap between the per-context best and the geomean winner

Done - 1d12e9a. The tuner prints each context's pick time, best and loss. Re-run on MI355: the shipped picks are within 3.6% of the geomean winner, but on 16/72 shapes the pick is more than 5% off one context's best. Worst is 9.4% at 8k (B=64, next_n=8) and 20.7% at 60k (B=1, next_n=8). Small batches with next_n 4-8 prefer Gluon at 8k and FlyDSL at 60k. So a host-side context hint would pay off; I'd like to do it as a follow-up PR, since it changes the API and needs the vLLM side too.

confirm no caller passes 2D or strided context_lens, or keep accepting the 2D form

2D is accepted: both kernels read (B, next_n) since #6451 and #6450, so the shim isn't needed. I merged main and added a test for the 2D table through the op, Gluon and FlyDSL (fbb421f). Only a strided view is rejected, since both kernels would misread it. No caller uses aiter.paged_mqa_logits yet.

@aiter-bot

aiter-bot commented Oct 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 8b797cbac2d4 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Adds a new entry point, `aiter.paged_mqa_logits`. vLLM main calls the Gluon kernel `deepgemm_fp8_paged_mqa_logits` directly with fixed `ChunkK=256, WavePerEU=2`, so every move to a faster kernel or launch setting needs a vLLM PR. With this, AITER picks Gluon (tuned `ChunkK`/`WavePerEU`) or FlyDSL (`wg_per_cu`) per decode shape from a tuned CSV, the way `fused_moe` does. One existing behavior changes: the gfx950 FlyDSL paged kernel checks the GPU it runs on (`get_gfx_runtime()`) instead of `GPU_ARCHS` (`get_gfx()`), the same as the table lookup. With `GPU_ARCHS=gfx942` on a gfx950 GPU it used to raise `RuntimeError`; now it runs. The tuning CI workflow also uploads `aiter/configs/model_configs/*.csv`.

Validation and unverified scope

MI355X (gfx950, 256 CUs), image `amdsiloai/vllm-private:glm53flash_nightly1014_week43_best_monofp8_20261022`, this PR's tree on `PYTHONPATH` (8b797cb for the op test, daf4e64 for the rest; they differ only in the op test):
- `python3 op_tests/test_paged_mqa_logits.py`: passed. The op, Gluon and FlyDSL match the reference (same `-inf` mask, `calc_diff < 1e-3`) on the 9 default shapes (batch 1/16/128, next_n 1/3/5, 8k context). It also checks dispatch to the shipped row under `GPU_ARCHS=gfx942`, the FlyDSL-to-Gluon fallback, strided `context_lens` rejection, the `(B, next_n)` table through the op and both backends (`checkAllclose` passed), and CUDA graph replay: the op, Gluon and FlyDSL are captured at 1024 tokens, `context_lens` is changed to 512 in place, and the replay matches the reference at 512. A launch that baked the lengths at capture fails this check (negative control run).
- `pytest -k paged_mqa_logits op_tests/tuning_tests/`: `test_config_shape_collision` passed. `test_run_config` failed on timing only: it compares each row's time to the CSV and does not check output. 68/72 rows were within 10% and 4 drifted more; the previous head showed 6-8 such rows on another MI355X box.
- `csrc/paged_mqa_logits/paged_mqa_logits_tune.py --all --verbose` on the 72 shapes (8 GPUs in parallel): every candidate passed the reference check before timing (0 rejected, 72/72 tuned). The shipped picks are within 3.6% of the re-run's geomean winner. Per-context gaps are up to 9.4% at 8k and 20.7% at 60k (see the review reply).
- Tuner exit code (`Finished` -> 0, `Error`/`Interrupted` -> 1) and the `8192;60000` default for a CSV without `context_len` were checked on 2026-10-24. The tuner has changed since only by the per-context logging.

Unverified: FlyDSL 0.4.1 (main's current pin; the image has 0.4.0); gfx942 (no table rows, so it uses the Gluon default); end-to-end vLLM serving (no vLLM caller yet); the CI tuning workflow itself (manual dispatch only, not run).

PR-specific question

Two CI files change. `.github/scripts/op_tune.sh` adds one entry to its list of tuning jobs, and `.github/workflows/operators-tuning.yaml` widens the artifact upload path to also include `aiter/configs/model_configs/*.csv`. `op_tune.sh` is only called by that workflow, and the workflow's only trigger is `workflow_dispatch`: it runs when someone with write access starts it on a ROCm/aiter branch, on runner `linux-aiter-oci-mi300x-1`. A fork PR can't trigger it or select its branch. This PR doesn't change its trigger, permissions or secrets, and neither change reads PR input; the upload only adds CSVs the job itself writes.

Changed op tests

- `op_tests/test_paged_mqa_logits.py` (new): the only test of the new `aiter.paged_mqa_logits` dispatch. It runs the op and both backends against the reference, and checks shipped-row dispatch on the live GPU, the FlyDSL-to-Gluon fallback, strided-input rejection, the 2D `context_lens` table, and CUDA graph capture and replay with lengths changed after capture. The existing kernel tests (`op_tests/test_flydsl_fp8_paged_mqa_logits.py`, `op_tests/triton_tests/attention/test_pa_mqa_logits_2d_context_lens.py`) call each kernel directly and never go through the dispatch.
- `op_tests/tuning_tests/test_config_shape_collision.py` (+4): adds the new `paged_mqa_logits_tuned` family to the shared duplicate-shape check, as every tuned family is.
- `op_tests/tuning_tests/test_run_config.py` (+9): adds the new tuner to the shared `--run_config` check, as every tuner is.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

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 tests omit CUDA-graph capture/replay coverage and the required elementwise logits comparison for 2D contexts, leaving important regression checks missing.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_paged_mqa_logits.py Resolved
Comment thread op_tests/test_paged_mqa_logits.py Resolved
Capture the op, Gluon and FlyDSL in a CUDA graph at 1024 tokens, change context_lens to 512 in place and replay: the output must match the reference at 512 and leave columns past it untouched, which fails if a launch reads the lengths on the host. The 2D context_lens check now also runs checkAllclose with the main test's tolerances.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 16:43

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

Production FlyDSL dispatch still requires GPU correctness, graph-replay, and latency validation on pinned FlyDSL 0.4.1 and the gfx942 fallback, which this review environment cannot run.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@amd-bartgips amd-bartgips 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

@samremes
samremes merged commit 41c2528 into ROCm:main Nov 3, 2026
amd-sriram added a commit to amd-sriram/vllm that referenced this pull request Nov 5, 2026
…e logits

Ask AITER for paged MQA logits (ROCm/aiter#6140) and let its tuned table
pick the Gluon or FlyDSL kernel and launch knobs, instead of passing fixed
Gluon knobs. With an AITER that has no aiter.paged_mqa_logits, the
existing Gluon call runs unchanged.

Both calls take the same Preshuffle flag, so RDNA keeps its unshuffled
K cache layout on the AITER path too.

Signed-off-by: Sriram Kumar <[email protected]>
amd-sriram added a commit to amd-sriram/vllm that referenced this pull request Nov 5, 2026
…e logits

Ask AITER for paged MQA logits (ROCm/aiter#6140) and let its tuned table
pick the Gluon or FlyDSL kernel and launch knobs, instead of passing fixed
Gluon knobs. With an AITER that has no aiter.paged_mqa_logits, the
existing Gluon call runs unchanged.

Both calls take the same Preshuffle flag, so RDNA keeps its unshuffled
K cache layout on the AITER path too.

Signed-off-by: Sriram Kumar <[email protected]>
amd-sriram added a commit to amd-sriram/vllm that referenced this pull request Nov 9, 2026
…e logits

Ask AITER for paged MQA logits (ROCm/aiter#6140) and let its tuned table
pick the Gluon or FlyDSL kernel and launch knobs, instead of passing fixed
Gluon knobs. With an AITER that has no aiter.paged_mqa_logits, the
existing Gluon call runs unchanged.

Both calls take the same Preshuffle flag, so RDNA keeps its unshuffled
K cache layout on the AITER path too.

Signed-off-by: Sriram Kumar <[email protected]>
amd-sriram added a commit to amd-sriram/vllm that referenced this pull request Nov 14, 2026
…e logits

Ask AITER for paged MQA logits (ROCm/aiter#6140) and let its tuned table
pick the Gluon or FlyDSL kernel and launch knobs, instead of passing fixed
Gluon knobs. With an AITER that has no aiter.paged_mqa_logits, the
existing Gluon call runs unchanged.

Both calls take the same Preshuffle flag, so RDNA keeps its unshuffled
K cache layout on the AITER path too.

Signed-off-by: Sriram Kumar <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…DSL table (ROCm#6140)

* [Triton][FlyDSL] Add aiter.paged_mqa_logits with a tuned Gluon/FlyDSL table

Picks the paged MQA logits backend and its launch knobs per shape from paged_mqa_logits_tuned.csv. Adds the tuner and op test, and gfx950 rows for the GLM-5 indexer.

Signed-off-by: Sriram Kumar <[email protected]>

* [Triton][FlyDSL] Move paged_mqa_logits next to fused_moe, GLM-5 rows to model_configs

Signed-off-by: Sriram Kumar <[email protected]>

* [Triton][FlyDSL] Look up paged_mqa_logits on the live GPU

get_gfx() follows GPU_ARCHS and skipped the tuned row.

* [Triton][FlyDSL] Drop context_len from the paged_mqa_logits merge key

The generic untuned header is the dedup key. Two rows that differ only
in context length now collide.

* fix: keep paged_mqa_logits run_config off the merge-key header

The generic untuned file no longer has context_len. pre_process still
runs on --run_config and needs that column.

* [FlyDSL] Check the live GPU in the gfx950 paged MQA logits kernel

get_gfx() follows GPU_ARCHS, so the kernel raised on gfx950 with
GPU_ARCHS=gfx942 once the dispatcher picked FlyDSL.

* test: run the shipped-row check with GPU_ARCHS set at process start

Setting GPU_ARCHS mid-process did not reach get_gfx(); the child process
also launches the real kernel.

* [FlyDSL] Fall back to the tuned Gluon knobs when FlyDSL cannot run

FlyDSL rows now store the winning Gluon ChunkK and WavePerEU.
GLM-5 gfx950 table retuned.

* test: check the dispatched paged_mqa_logits config without compiling

The shipped-row check records the config and no longer launches a kernel.

* ci: add paged_mqa_logits to the manual tuning recipes

* [Triton][FlyDSL] Pass context_lens through to the paged MQA logits kernels

Drop the 2D context_lens shim; ROCm#6153 adds 2D support in the kernels.

* [Triton][FlyDSL] Tune the GLM-5 paged_mqa_logits rows at 8k and 60k context

Matches the benchmark input lengths (8192 and 60000).

* Document the paged_mqa_logits contract and the context_len column

State the tensors the front-end takes instead of pointing at the Gluon
wrapper, and say that context_len is tuning metadata dispatch does not
read.

* Default the paged_mqa_logits tuner context lengths to 8192;60000

A row with no context_len (a generic-schema untuned CSV, or an empty cell) got an empty context list, so the tuner timed nothing and reported the shape as failed. Such rows now use --context_len, which defaults to the lengths the shipped table was tuned over; context_len stays out of the collision-key header.

* Exit nonzero when paged_mqa_logits tuning errors or is interrupted

TunerCommon.run() catches the exception and calls tune_summary with status Error or Interrupted. With no failed row recorded, the script exited 0 and op_tune.sh reported a pass.

* Reject a strided context_lens in paged_mqa_logits for both backends

Gluon already rejects a non-contiguous context_lens, but the FlyDSL wrapper reshapes it without removing the stride and the kernel reads it as dense, so a table[:, -1] view gave wrong causal bounds on the shipped B=64, next_n=8 FlyDSL row. run_paged_mqa_logits, which the op and the tuner share, now raises ValueError for it; the test covers that view.

* Document context_len as provenance and accept (B, next_n) context_lens

Dispatch deliberately does not key on context length; say so up front and at the loader, where the context_len column is free text that is never parsed (only the tuner reads it). Both kernels read the (B, next_n) table vLLM builds since ROCm#6451 and ROCm#6450, so the contract now lists it.

* Test (B, next_n) context_lens through paged_mqa_logits and each backend

Uses the shipped B=64, next_n=8 row, which dispatches to FlyDSL, and checks the op, Gluon and FlyDSL against the reference.

* Log each context's gap to its own best in the paged_mqa_logits tuner

The pick minimises the geomean over the row's contexts, which can hide a context where it is well off that context's best. Print the pick's time, the per-context best and the loss for every context.

* ci: upload model_configs tuned CSVs in the tuning artifact

The paged_mqa_logits job writes aiter/configs/model_configs/paged_mqa_logits_tuned_glm5.csv, which aiter/configs/*.csv does not match.

* Test CUDA graph replay and elementwise accuracy in paged_mqa_logits

Capture the op, Gluon and FlyDSL in a CUDA graph at 1024 tokens, change context_lens to 512 in place and replay: the output must match the reference at 512 and leave columns past it untouched, which fails if a launch reads the lengths on the host. The 2D context_lens check now also runs checkAllclose with the main test's tolerances.

---------

Signed-off-by: Sriram Kumar <[email protected]>
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