Skip to content

[MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to - #8181

Open
gbyu-amd wants to merge 7 commits into
mainfrom
gyu/mla-decode-num-heads
Open

gbyu-amd wants to merge 7 commits into
mainfrom
gyu/mla-decode-num-heads

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds get_mla_decode_num_heads(num_heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs) to aiter.ops.attention: the first of num_heads and the kernel head counts above it (MLA_DECODE_KERNEL_HEAD_COUNTS) that mla_decode_fwd runs for a decode with the given arguments. A caller that can pad its query heads (a decode-context-parallel gather pads with zeros) asks aiter which width to gather to instead of hard-coding head counts per architecture.

Motivation

Which head counts a multi-token decode runs at depends on the architecture, the backend, the KV dtype, the query length and the call (LSE, round-robin KV across a CP group). On gfx1250 the FlyDSL PS1 kernel takes a multi-token query at 16/32/64 heads only while it fits one qo tile, and 96 heads at any length; aiter does not fold the other counts onto it. get_mla_decode_shape_support already answers "does this exact shape run, and how"; a caller that pads still has to search the head counts above its own. ROCm/ATOM#2760 (speculative decode with DCP on gfx1250) needs that answer to pick the width its DCP group gathers the query heads to.

Changes

  • aiter/ops/attention.py. get_mla_decode_num_heads tries num_heads and each kernel head count above it (16, 32, 64, 96, 128) through get_mla_decode_shape_support with the caller's keywords, and returns the first that runs: a known kernel (supported is True), or a FlyDSL PS1 / OPUS JIT route, which has no availability table (supported is None, asm_status is NOT_ASM). A folded PS1 route, a count the planner or reducer rejects, an asm route without a kernel, and gfx950's experimental HK route do not run. The HK route reports supported is None, but hk_mla_v32_decode_fwd ignores q_scale and kv_scale. None when no count up to 128 runs. No new C++; it only uses the existing shape rules. Its docstring states that "runs" is the shape rules' answer (nothing is launched) and points to MlaDecodeShapeSupport for the limits it inherits. Only those candidates are tried: narrower counts some architectures also run (gfx950 fp8: 8 heads at qlen 4, 12 heads up to 128 rows) are never answered, since fewer heads are not always faster and padding to them is the caller's measured choice. The kernel head counts it pads to are exported as MLA_DECODE_KERNEL_HEAD_COUNTS, so a caller that tries wider widths itself ([DSpark][DCP] Allow speculative decode with DCP on gfx1250's PS1 MLA kernel ATOM#2760) reads aiter's list instead of keeping a copy. The comment on the list names its source of truth: the per-arch asm tables and the FlyDSL / OPUS kernels.
  • op_tests/test_mla_shape_support.py. test_decode_num_heads covers a gfx1250 DCP decode (LSE, round-robin KV over 8 ranks): a count that runs is kept, one that does not pads to the next that does, a folded route does not count (fast_mode=False gives 128 for 64 heads), and every returned count is one the shape query says runs and is either the requested count or one of MLA_DECODE_KERNEL_HEAD_COUNTS. It also checks that gfx950's experimental HK route never counts: 128 fp8 heads with enable_experimental get no answer. The OPUS route (AITER_MLA_USE_OPUS=1, as in test_opus_cp) counts where its rules accept the call and never where they reject it.

What it returns today, gfx1250 DCP decode (bf16, LSE, round-robin KV over 8 ranks, FlyDSL PS1):

query heads qlen 1 2 3 4 5 8 9
16 16 16 16 16 96 96 96
32 32 32 32 32 96 96 96
64 64 64 96 96 96 96 96
96 96 96 96 96 96 96 96

#7913 (stacked on this PR) lets PS1 take 32/64 heads up to qlen 8 as several qo tiles; with it the 32 and 64 rows keep their count up to qlen 8.

Performance (if applicable)

None: a host-side query over the existing shape rules (cached), no kernel change.

Testing

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

On MI455X (gfx1250), this branch at 0d34555e (on main ffbd9c6a):

  • op_tests/test_mla_shape_support.py: 20 passed, 2 skipped (including test_decode_num_heads).
  • Regression, test_mla_flydsl.py --mode ps1 --num-heads 16 32 64 96 --q-seq-len 1 2 4 -b 4 -c 65 2048 (fp8, against the torch reference): 22 cases, all pass.
  • The DCP route a padded 96-head query takes, test_mla_flydsl.py --mode cp --dtype {bf16,fp8} --num-heads 96 --q-seq-len 6 8 --cp-world-size 8, default lengths and --varlen -b 32 -c 1200. Each rank's output and final LSE, and the LSE-merged output, are checked against the torch reference: 16 cases, all pass.
  • black and ruff clean on the changed files.

Details in PR Self-Review below.

Documentation

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

Dependencies

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

Breaking Changes

None: a new function; nothing existing changes.

PR Self-Review

Reviewed revision

0d34555eba8940d99526971d35ad8d375309f59a

Behavior and intent

The PR adds one function and one constant to aiter.ops.attention. No existing function, kernel or route changes.

  • get_mla_decode_num_heads(num_heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs) returns the first of num_heads and the kernel head counts above it that mla_decode_fwd runs for the described decode, or None when no count up to 128 runs. It walks those candidates through the existing get_mla_decode_shape_support, with the caller's keywords.
  • MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128) is the list it pads onto.
  • A head count runs when get_mla_decode_shape_support reports supported is True, or supported is None on a FlyDSL PS1 or OPUS JIT route.
    • Neither of those routes has an availability table, and the shape rules already return False for the calls each cannot take. So None there means the rules accept the call.
    • gfx950's experimental HK route also reports None but is not counted, because the shape rules note that hk_mla_v32_decode_fwd ignores q_scale and kv_scale.
  • The helper inherits get_mla_decode_shape_support's coverage and adds no rules of its own. A gap in those rules exists today for any caller that checks a shape or picks a width with them, and fixing it there fixes every caller.
  • "Runs" means the shape rules accept the head count; nothing is launched. The inherited limits are documented on MlaDecodeShapeSupport, which the docstring points to: launch-size limits are not checked, and only kv_layout="token_major" is described.
  • Only those candidates are tried. Narrower counts that some architectures also run are never answered: on gfx950 fp8, 8 heads at qlen 4 and 12 heads up to 128 rows. For example, 9 heads give 16 there, not 12. Fewer heads are not always faster, so padding to such a width stays the caller's choice, made by measurement. perf(mla): decode Kimi-K3's dense MLA layers at 12 query heads for an 8-token verify ATOM#2915 is an example: it decodes Kimi-K3's 12 heads unpadded only at the 8-token verify where it measured that faster.

Why the existing behavior is insufficient: get_mla_decode_shape_support answers only whether one exact head count runs. A caller that can pad its query heads (a DCP gather pads with zeros) has to search the counts above its own. Today such callers hard-code head counts per architecture, and those copies go stale when aiter's routing changes. For example, with #7913 gfx1250 PS1 takes 64 heads up to qlen 8, while a hard-coded table still pads such a query to 96. With this function the answer follows aiter's own shape rules.

Validation and unverified scope

Setup: MI455X (gfx1250), one GPU, rocm/fw-bringup:gfx1250-atom-k3-20261120 container, this branch at 0d34555e on PYTHONPATH, flydsl 0.5.3.

  • python3 -m pytest -q op_tests/test_mla_shape_support.py: 20 passed, 2 skipped. The two skips are the existing gfx942/gfx950 asm-table tests ("no gfx942/gfx950 asm table built").
  • python3 -m pytest -q op_tests/test_mla_shape_support.py -k test_decode_num_heads: 1 passed. Run against the previous revision 929e7c42, the new HK assertion fails with assert 128 is None, because the HK route was counted.
  • Regression of the decode path the function reports on: python3 op_tests/test_mla_flydsl.py --mode ps1 --num-heads 16 32 64 96 --q-seq-len 1 2 4 -b 4 -c 65 2048. This is fp8 against the torch reference: 22 cases, all err 0.
  • The DCP configuration the function answers for, at the width it pads to (96 heads, multi-token, round-robin KV, LSE): python3 op_tests/test_mla_flydsl.py --mode cp --dtype {bf16,fp8} --num-heads 96 --q-seq-len 6 8 --cp-world-size 8, at the default lengths (batch 4, 2048/4096/8192) and with --varlen -b 32 -c 1200.
    • Each rank's output and final LSE are checked against the torch reference for that rank's shard.
    • The ranks' LSE-merged output is checked against full-KV attention.
    • Result: 16 cases, every rank error and merged error 0.
  • black --check (26.5.1) and ruff check (0.16.7) are clean on both changed files.

Unverified:

  • gfx942 / gfx950 hardware. No MI300X / MI355X machine was available. The two asm-table tests skip on gfx1250. test_decode_num_heads exercises the gfx1250 DCP rules, plus the gfx950 HK route through host-side rules only. Apart from not counting HK, the function adds no architecture-specific logic, so other architectures get whatever get_mla_decode_shape_support reports for them.
  • The [DSpark][DCP] Allow speculative decode with DCP on gfx1250's PS1 MLA kernel ATOM#2760 integration was not re-run at this revision. In that integration, the DCP decode picks the gathered head width through this function. The changes since its last end-to-end run do not change any answer on its Kimi-K3 path (gfx1250, fp8, DCP decode with LSE and round-robin KV, served by the PS1 code object / FlyDSL PS1). Those changes only scope the docstring and stop counting the gfx950 HK route, which that path never reaches.
  • qlen 5 (a k=4 speculative verify) is not among test_mla_flydsl.py's --q-seq-len choices. The 96-head kernel runs cover qlen 1, 2, 4 (ps1) and 6, 8 (cp) around it.

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

Before this PR. test_decode_num_heads fails at import: get_mla_decode_num_heads and MLA_DECODE_KERNEL_HEAD_COUNTS do not exist.

What the test pins. It fixes the function's contract on a gfx1250 DCP decode (bf16, LSE, round-robin KV over 8 ranks):

  • A count that runs is kept: 16 heads at qlen 1 and 4, 64 heads at qlen 2.
  • A count that does not run pads to the next count that does: 16 heads at qlen 5, 64 heads at qlen 3 and 9, and 65 heads at qlen 1 all give 96.
  • A folded PS1 route never counts as running: with fast_mode=False, 64 heads gives 128.
  • gfx950's experimental HK route never counts as running. With arch="gfx950", enable_experimental=True, 128 fp8 heads route to HK (supported is None) and get no answer. Before this revision they got 128.
  • The OPUS route counts only where its rules accept the call. With AITER_MLA_USE_OPUS=1, gfx950, fp8, CP 4 (as in test_opus_cp):
    • with round-robin KV, 16 heads route to OPUS (supported is None) and answer 16;
    • CP without round-robin KV, and bf16 CP, never answer 16.
  • Over a grid of head counts × qlen, every returned count:
    • is at least the request;
    • is reported runnable by get_mla_decode_shape_support;
    • is either the request or an entry of MLA_DECODE_KERNEL_HEAD_COUNTS.

Why existing tests do not cover it. The existing tests in this file check get_mla_decode_shape_support for one exact shape at a time. None searches upward for a padded count. The padding order, the exclusion of folded routes and of the HK route, the OPUS branch of the predicate, and the "pad only onto a kernel head count" rule are new behavior with no prior coverage.

Changed op tests

  • op_tests/test_mla_shape_support.py: adds test_decode_num_heads, described above, and imports the two new names.
    • Why it lives here. This file is the canonical host-side test of the MLA decode shape rules, and the new function is a query over those rules. The test runs no kernel, so it belongs here rather than in a kernel test.
    • Why it is not redundant. No other test calls get_mla_decode_num_heads.

@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 8181 --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 added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
get_mla_decode_num_heads now comes from its own aiter PR, ROCm/aiter#8181. ROCm/aiter#7913 keeps only the 32/64-head multi-token PS1 tiles: with it the 64-head draft block runs unpadded, without it the draft pads to 96 heads.
@gbyu-amd
gbyu-amd marked this pull request as ready for review November 18, 2026 10:07
@gbyu-amd
gbyu-amd requested a review from a team November 18, 2026 10:07
@aiter-bot

aiter-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 0d34555eba89 · 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

The PR adds one function and one constant to `aiter.ops.attention`. No existing function, kernel or route changes.
- `get_mla_decode_num_heads(num_heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs)` returns the first of `num_heads` and the kernel head counts above it that `mla_decode_fwd` runs for the described decode, or `None` when no count up to 128 runs. It walks those candidates through the existing `get_mla_decode_shape_support`, with the caller's keywords.
- `MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128)` is the list it pads onto.
- A head count runs when `get_mla_decode_shape_support` reports `supported is True`, or `supported is None` on a FlyDSL PS1 or OPUS JIT route.
  - Neither of those routes has an availability table, and the shape rules already return `False` for the calls each cannot take. So `None` there means the rules accept the call.
  - gfx950's experimental HK route also reports `None` but is not counted, because the shape rules note that `hk_mla_v32_decode_fwd` ignores `q_scale` and `kv_scale`.
- The helper inherits `get_mla_decode_shape_support`'s coverage and adds no rules of its own. A gap in those rules exists today for any caller that checks a shape or picks a width with them, and fixing it there fixes every caller.
- "Runs" means the shape rules accept the head count; nothing is launched. The inherited limits are documented on `MlaDecodeShapeSupport`, which the docstring points to: launch-size limits are not checked, and only `kv_layout="token_major"` is described.
- Only those candidates are tried. Narrower counts that some architectures also run are never answered: on gfx950 fp8, 8 heads at qlen 4 and 12 heads up to 128 rows. For example, 9 heads give 16 there, not 12. Fewer heads are not always faster, so padding to such a width stays the caller's choice, made by measurement. ROCm/ATOM#2915 is an example: it decodes Kimi-K3's 12 heads unpadded only at the 8-token verify where it measured that faster.

Why the existing behavior is insufficient: `get_mla_decode_shape_support` answers only whether one exact head count runs. A caller that can pad its query heads (a DCP gather pads with zeros) has to search the counts above its own. Today such callers hard-code head counts per architecture, and those copies go stale when aiter's routing changes. For example, with ROCm/aiter#7913 gfx1250 PS1 takes 64 heads up to qlen 8, while a hard-coded table still pads such a query to 96. With this function the answer follows aiter's own shape rules.

Validation and unverified scope

Setup: MI455X (gfx1250), one GPU, `rocm/fw-bringup:gfx1250-atom-k3-20261120` container, this branch at `0d34555e` on `PYTHONPATH`, flydsl 0.5.3.
- `python3 -m pytest -q op_tests/test_mla_shape_support.py`: 20 passed, 2 skipped. The two skips are the existing gfx942/gfx950 asm-table tests ("no gfx942/gfx950 asm table built").
- `python3 -m pytest -q op_tests/test_mla_shape_support.py -k test_decode_num_heads`: 1 passed. Run against the previous revision `929e7c42`, the new HK assertion fails with `assert 128 is None`, because the HK route was counted.
- Regression of the decode path the function reports on: `python3 op_tests/test_mla_flydsl.py --mode ps1 --num-heads 16 32 64 96 --q-seq-len 1 2 4 -b 4 -c 65 2048`. This is fp8 against the torch reference: 22 cases, all `err` 0.
- The DCP configuration the function answers for, at the width it pads to (96 heads, multi-token, round-robin KV, LSE): `python3 op_tests/test_mla_flydsl.py --mode cp --dtype {bf16,fp8} --num-heads 96 --q-seq-len 6 8 --cp-world-size 8`, at the default lengths (batch 4, 2048/4096/8192) and with `--varlen -b 32 -c 1200`.
  - Each rank's output and final LSE are checked against the torch reference for that rank's shard.
  - The ranks' LSE-merged output is checked against full-KV attention.
  - Result: 16 cases, every rank error and merged error 0.
- `black --check` (26.5.1) and `ruff check` (0.16.7) are clean on both changed files.

Unverified:
- **gfx942 / gfx950 hardware.** No MI300X / MI355X machine was available. The two asm-table tests skip on gfx1250. `test_decode_num_heads` exercises the gfx1250 DCP rules, plus the gfx950 HK route through host-side rules only. Apart from not counting HK, the function adds no architecture-specific logic, so other architectures get whatever `get_mla_decode_shape_support` reports for them.
- **The ROCm/ATOM#2760 integration** was not re-run at this revision. In that integration, the DCP decode picks the gathered head width through this function. The changes since its last end-to-end run do not change any answer on its Kimi-K3 path (gfx1250, fp8, DCP decode with LSE and round-robin KV, served by the PS1 code object / FlyDSL PS1). Those changes only scope the docstring and stop counting the gfx950 HK route, which that path never reaches.
- **qlen 5** (a k=4 speculative verify) is not among `test_mla_flydsl.py`'s `--q-seq-len` choices. The 96-head kernel runs cover qlen 1, 2, 4 (ps1) and 6, 8 (cp) around it.

PR-specific question

> What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

**Before this PR.** `test_decode_num_heads` fails at import: `get_mla_decode_num_heads` and `MLA_DECODE_KERNEL_HEAD_COUNTS` do not exist.

**What the test pins.** It fixes the function's contract on a gfx1250 DCP decode (bf16, LSE, round-robin KV over 8 ranks):
- A count that runs is kept: 16 heads at qlen 1 and 4, 64 heads at qlen 2.
- A count that does not run pads to the next count that does: 16 heads at qlen 5, 64 heads at qlen 3 and 9, and 65 heads at qlen 1 all give 96.
- A folded PS1 route never counts as running: with `fast_mode=False`, 64 heads gives 128.
- gfx950's experimental HK route never counts as running. With `arch="gfx950", enable_experimental=True`, 128 fp8 heads route to HK (`supported is None`) and get no answer. Before this revision they got 128.
- The OPUS route counts only where its rules accept the call. With `AITER_MLA_USE_OPUS=1`, gfx950, fp8, CP 4 (as in `test_opus_cp`):
  - with round-robin KV, 16 heads route to OPUS (`supported is None`) and answer 16;
  - CP without round-robin KV, and bf16 CP, never answer 16.
- Over a grid of head counts × qlen, every returned count:
  - is at least the request;
  - is reported runnable by `get_mla_decode_shape_support`;
  - is either the request or an entry of `MLA_DECODE_KERNEL_HEAD_COUNTS`.

**Why existing tests do not cover it.** The existing tests in this file check `get_mla_decode_shape_support` for one exact shape at a time. None searches upward for a padded count. The padding order, the exclusion of folded routes and of the HK route, the OPUS branch of the predicate, and the "pad only onto a kernel head count" rule are new behavior with no prior coverage.

Changed op tests

- `op_tests/test_mla_shape_support.py`: adds `test_decode_num_heads`, described above, and imports the two new names.
  - **Why it lives here.** This file is the canonical host-side test of the MLA decode shape rules, and the new function is a query over those rules. The test runs no kernel, so it belongs here rather than in a kernel test.
  - **Why it is not redundant.** No other test calls `get_mla_decode_num_heads`.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

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.

gbyu-amd added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
… each layer's call

- Import get_mla_decode_num_heads (ROCm/aiter#8181) at module top; drop the
  ImportError probe and its test. ATOM's import needs an aiter that has it.
- Every persistent decode of more than one query row pads its gathered heads to
  the width aiter names for that call, with no arch branch. The errors quote
  aiter's reasons from get_mla_decode_shape_support instead of an arch list.
- Sparse / DSA layers size their DCP decode for q_len=1 (layer and native
  metadata builder), so they never ask about a k+1 round-robin call and never
  reach the speculative decode + DCP refusal.
- The DSpark draft's non-causal block sizes for its block width T
  (decode_query_len), not the verify's k + 1.
- One fp8/bf16 KV dtype mapping (mla_kv_dtype) and one shape query
  (mla_dcp_decode_shape_support), shared by dcp_utils and attention_mla.
- Plugin tests set causal_decode and a current atom config; refusal-skip tests
  for the draft block, dcp=1 and sparse layers.
- Docs: the DSpark support matrix lists gfx1250 (ROCm/aiter#8181; #7913 runs
  the 64-head draft unpadded); dense MTP on gfx1250 is marked not validated.
@gbyu-amd
gbyu-amd requested a review from valarLip November 18, 2026 12:47
gbyu-amd added a commit to ROCm/ATOM that referenced this pull request Nov 18, 2026
…fusal

- vLLM plugin builder: plan the persistent DCP decode at the call its layers
  make (mla_dcp_layers_persistent_width): a DSpark draft's KV group at its
  non-causal block of T rows, the target at its causal k + 1 verify, sparse /
  DSA layers at 1 -- the width the layers pad their queries to. Before, the
  draft's builder planned the target's verify and could plan 96 heads while
  the draft layer padded to 64.
- mla_dcp_persistent_width returns None when aiter names no width for a
  decode of more than one row, so both builders stay non-persistent and the
  layer's speculative decode + DCP refusal fires (with aiter's reasons)
  instead of an error from inside the width query.
- No getattr defenses on aiter's MlaDecodeShapeSupport or on
  MLAAttention.decode_query_len.
- dcp_persistent_supported counts a width as aiter's get_mla_decode_num_heads
  does: a known kernel, or a route without an availability table (NOT_ASM),
  not only FlyDSL PS1.
- Docs and comments: the width query runs on every arch; at q > 1 the width
  is aiter's (96 included) and no width is a refusal.
- Tests: aiter naming no width (width None, the refusal fires without a
  stubbed width); the draft builder plans the draft layer's width under the
  PS1 rules with ROCm/aiter#8181 (k=2) and with #7913 (k=8);
  dcp_persistent_supported reads asm_status.
@gbyu-amd
gbyu-amd added this pull request to stack #8247 November 19, 2026 02:33
@gbyu-amd
gbyu-amd force-pushed the gyu/mla-decode-num-heads branch from 5c159dc to 2d34816 Compare November 19, 2026 06:16
gbyu-amd added a commit to ROCm/ATOM that referenced this pull request Nov 19, 2026
…e at 1..k + 1

- tests: test_dense_layer_decodes_at_every_length needs the full atom import
  (@needs_dcp_ops); without aiter it raised NameError in the non-GPU job.
- dcp_persistent_supported is the one-row query again and counts a None
  answer only on the FlyDSL PS1 route, as before: a DCP decode without
  speculative decode does not move onto opus. Past one row the width is the
  one aiter's get_mla_decode_num_heads names for the call.
- _persistent_width: when the widest width aiter names does not run at every
  length the layer decodes (e.g. it routes to HK, which writes no final LSE,
  at one row), try each wider kernel head count before giving up.
- mla_dcp_decode_query_lens: every length from 1 to k + 1 on the native path
  too (shorter verifies, e.g. DSpark's confidence_schedule buckets), as under
  the vLLM plugin.
- Stale text: mla_dcp_decode_query_len docstring; docs on widths past 128 at
  one row (they abort in mla_decode_fwd, no folded fallback) and on
  ROCm/aiter#8181 (needed on every arch for the import).
@gbyu-amd
gbyu-amd force-pushed the gyu/mla-decode-num-heads branch from 2d34816 to bd060b3 Compare November 24, 2026 07:28
@gbyu-amd
gbyu-amd requested a review from zufayu November 24, 2026 07:37
gbyu-amd added a commit to ROCm/ATOM that referenced this pull request Nov 24, 2026
…(1, k + 1)

- _persistent_width tries aiter's own MLA_DECODE_KERNEL_HEAD_COUNTS
  (ROCm/aiter#8181) past the width aiter names; the local copy is gone. The
  test stand-in for get_mla_decode_num_heads reads the same list and only
  answers a count mla_decode_fwd dispatches.
- mla_dcp_decode_query_lens: native MTP / Eagle and DSpark without
  confidence_schedule decode the verify's k + 1 and the one-row draft steps
  only, so they size at (1, k + 1) again; every length from 1 to k + 1 only
  under the vLLM plugin or DSpark's confidence_schedule. Test configs carry
  `dspark`; refusal regexes and docs are back to (1, k + 1).
- New test: gfx950 fp8 MTP k=2 at 16 / 48 gathered heads keeps the gathered
  width natively and pads to 32 / 64 only with confidence_schedule.
- Docs: one-row widths (a persistent decode keeps the gathered width up to
  128, 96 for Kimi-K3 at tp8 dcp8; non-persistent pads to 16 / 32 / 128, or
  16 / 128 with fp8), and AITER_MLA_USE_OPUS=1 refusing spec + DCP on gfx950.
…ery to

A caller that pads its query heads (a DCP gather pads with zeros) needs the
fewest heads mla_decode_fwd runs for its decode. get_mla_decode_num_heads tries
num_heads and each kernel head count above it through
get_mla_decode_shape_support with the caller's arguments and returns the first
that runs: a known kernel, or a JIT route with no availability table. A folded
PS1 route, a count the planner or reducer rejects and an asm route without a
kernel do not run.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Callers that pick a padded decode width (ATOM's DCP decode, which tries the
next kernel head count when the width get_mla_decode_num_heads names does not
run at every query length it decodes) read the list instead of keeping a copy.
test_decode_num_heads checks that every padded answer is one of its counts.
@gbyu-amd
gbyu-amd force-pushed the gyu/mla-decode-num-heads branch from a0308cc to 3ac7ea5 Compare November 25, 2026 07:19
@gbyu-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0); the target op_tests/test_mla_shape_support.py exists but the runner could not be invoked (environment gap, not a PR defect)
Perf (advisory): NOT RUN — the target exposes no benchmark entry point, and the change is a host-side query over cached shape rules, so no kernel latency is involved
Size: 90 lines / 2 files
Design (advisory): the runs predicate — a JIT route with no availability table (supported is None, NOT_ASM) counts as running; a failed or kernel-less asm query does not
Human: recommend Oxana Korzh review whether treating a supported=None FlyDSL/OPUS JIT route as running in get_mla_decode_num_heads is the right contract for the ATOM#2760 DCP caller to gather query heads against

2 finding(s) posted inline, on the lines they are about:

  • aiter/ops/attention.py:2743 — No kernel run in this PR covers a padded width at qlen ≥ 5 in the DCP configuration get_mla_decode_num_heads…
  • aiter/ops/attention.py:2721 — The docstring at aiter/ops/attention.py:2721 promises "the fewest Q heads ... that mla_decode_fwd runs", but…

Comment thread aiter/ops/attention.py
s = get_mla_decode_shape_support(
heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs
)
if s.supported or (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] No kernel run in this PR covers a padded width at qlen ≥ 5 in the DCP configuration get_mla_decode_num_heads exists to answer: the regression that ran is test_mla_flydsl.py --mode ps1 --num-heads 16 32 64 96 --q-seq-len 1 2 4 (fp8, ps1 mode, no LSE, no CP), while the scenario the function answers for — test_decode_num_heads and the ATOM#2760 consumer — is bf16 with return_lse over round-robin CP, a route aiter/ops/attention.py:2743 reports as supported=None, i.e. no availability table vouches for it; if the 96-head bf16 kernel has a constraint the host rules don't encode, the DCP gather pads to 96 and fails only at run time in ATOM. Author must run the harness's own DCP configuration (test_mla_flydsl.py --mode cp --dtype bf16 --num-heads 96 --q-seq-len 6 8 --cp-world-size 8, final LSE checked against the torch reference) or re-run the ATOM#2760 integration at this revision.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the harness's DCP configuration at fd90954 (MI455X, gfx1250): test_mla_flydsl.py --mode cp --dtype {bf16,fp8} --num-heads 96 --q-seq-len 6 8 --cp-world-size 8, at the default lengths (batch 4, 2048/4096/8192) and with --varlen -b 32 -c 1200. Each rank's output and final LSE are checked against the torch reference for its shard, and the LSE-merged output against full-KV attention: 16 cases, every rank error and merged error 0. Added to Testing and to the PR Self-Review. The ROCm/ATOM#2760 integration itself was not re-run at this revision; it is listed as unverified.

Comment thread aiter/ops/attention.py Outdated
kv_dtype: torch.dtype,
**kwargs,
) -> int | None:
"""The fewest Q heads, at least num_heads, that mla_decode_fwd runs for a decode.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [verified] The docstring at aiter/ops/attention.py:2721 promises "the fewest Q heads ... that mla_decode_fwd runs", but the query it loops over documents two caveats the new docstring does not carry: launch-size limits are not checked (the gfx950 non-persistent fp8 64-head kernel still raises at launch when kv_split > 1 and total_q * kv_split > 32768) and only kv_layout="token_major" is described — a caller on that gfx950 route could be told a count "runs" and hit a launch-time raise. Author must scope the claim in the docstring, or point at the caveats on MlaDecodeShapeSupport, so the ATOM#2760 caller knows what "runs" does not cover.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped in fd90954. The docstring now says that "runs" means the shape rules accept the head count and nothing is launched. It also names the two limits it inherits from get_mla_decode_shape_support (documented on MlaDecodeShapeSupport): launch-size limits are not checked (the gfx950 non-persistent fp8 64-head kernel still raises when kv_split > 1 and total_q * kv_split > 32768), and only kv_layout="token_major" is described.

The docstring promised the fewest heads mla_decode_fwd runs, but the answer
covers only what get_mla_decode_shape_support checks. Say that nothing is
launched, and name the two limits documented on MlaDecodeShapeSupport and
get_mla_decode_shape_support: launch-size limits are not checked (gfx950
non-persistent fp8 64 heads, kv_split > 1, total_q * kv_split > 32768) and
only kv_layout="token_major" is described.
@gbyu-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled); the target op_tests/test_mla_shape_support.py exists but could not be run from this review environment either (no /dev/kfd access, CPU-only torch) — environment gap, not a PR defect
Perf (advisory): NOT RUN — the target exposes no benchmark entry point, and the change is a host-side query over the existing cached shape rules, so no kernel latency is involved
Size: 97 lines / 2 files
Design (advisory): the runs predicate and candidate list — a JIT route with no availability table (supported is None, asm_status NOT_ASM) counts as running; a folded route, a planner/reducer rejection and a failed or kernel-less asm query do not; only num_heads and the five kernel head counts (16/32/64/96/128) are tried
Human: recommend Oxana Korzh review whether that runs predicate and candidate list are the right contract for the ATOM#2760 DCP caller to gather query heads against (she authored get_mla_decode_shape_support in #6107)

📝 [verified] The named consumer, the ROCm/ATOM#2760 DCP gather, was not re-run at this revision (PR Self-Review "Unverified"), so the answer the function gives is pinned only by its own unit test on a gfx1250 DCP config. Reviewer should ask for the ATOM#2760 integration to exercise get_mla_decode_num_heads end-to-end before it is relied on.

1 finding(s) posted inline, on the lines they are about:

  • aiter/ops/attention.py:2721 — promises "the fewest Q heads, at least num_heads, that mla_decode_fwd runs", but the loop at…

Comment thread aiter/ops/attention.py Outdated
kv_dtype: torch.dtype,
**kwargs,
) -> int | None:
"""The fewest Q heads, at least num_heads, that mla_decode_fwd runs for a decode.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] aiter/ops/attention.py:2721 promises "the fewest Q heads, at least num_heads, that mla_decode_fwd runs", but the loop at aiter/ops/attention.py:2744 tries only num_heads and MLA_DECODE_KERNEL_HEAD_COUNTS (16/32/64/96/128) — on gfx950 fp8 the same shape rules also run at 8 and 12 heads (12 native per csrc/include/mla_decode_shape.h:176, 8 accepted at qlen 4 per :189, both reducible per csrc/include/mla_reduce_cases.h:24 and served by hsa/gfx950/mla/mla_asm.csv via the remap at csrc/py_itfs_cu/asm_mla.cu:458), so get_mla_decode_num_heads(9, 1, fp8, fp8, arch="gfx950") answers 16 although 12 runs, and a gfx950 caller pads a third wider than needed. Author must qualify the docstring and the MLA_DECODE_KERNEL_HEAD_COUNTS comment ("the fewest of num_heads and the kernel head counts above it") or extend the candidate list with the other runnable counts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the first option in 929e7c4. The docstring and the MLA_DECODE_KERNEL_HEAD_COUNTS comment now say that only num_heads and the list entries above it are tried, so the answer is the fewest heads among those candidates, not among every count the shape rules accept. They name the gfx950 fp8 routes that are never answered: 8 heads at qlen 4 and 12 heads up to 128 rows (9 heads give 16 there, not 12).

The candidate list stays as it is, because fewer heads are not always faster. The gfx950 12-head route runs on the gqa-32 / qlen-4 configuration through the remap in csrc/py_itfs_cu/asm_mla.cu, so padding to a narrower width is left to the caller's measurement. ROCm/ATOM#2915 does exactly that: it decodes Kimi-K3's 12 heads unpadded only at the 8-token verify, where it measured that faster, and pads to 16 elsewhere.

…counts only

The docstring promised the fewest heads mla_decode_fwd runs, but only num_heads
and the MLA_DECODE_KERNEL_HEAD_COUNTS entries above it are tried. On gfx950 fp8
the shape rules also accept 8 heads (qlen 4) and 12 heads (up to 128 rows),
which are never answered (9 heads give 16, not 12). Say so in the docstring and
in the constant's comment, and leave padding to such a narrower width to the
caller: fewer heads are not always faster.
@gbyu-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — the target op_tests/test_mla_shape_support.py exists, but this review environment has no GPU (CPU-only torch 2.15.0+cpu, rocminfo reports no gfx arch, import aiter fails in the JIT core) — environment gap, not a PR defect
Perf (advisory): NOT RUN — the target exposes no benchmark entry point, and the change is a host-side query over the existing cached shape rules, so no kernel latency is involved
Size: 105 lines / 2 files
Design (advisory): the runs predicate and candidate list — a JIT route with no availability table (supported is None, asm_status NOT_ASM) counts as running; a folded PS1 route, a planner/reducer rejection and a failed or kernel-less asm query do not; only num_heads and the five kernel head counts (16/32/64/96/128) are tried, never narrower counts
Human: recommend Oxana Korzh review whether that runs predicate and candidate list are the right contract for the ATOM#2760 DCP caller to gather query heads against in PR #8181 (she authored get_mla_decode_shape_support)

📝 [verified] The named consumer, the ROCm/ATOM#2760 DCP gather, was not re-run at this revision (the PR's "Unverified" section says so), so get_mla_decode_num_heads is exercised only by its own unit test on one gfx1250 DCP config — a consumer config the test does not cover (other kwargs, another arch) meets a contract nothing end-to-end has validated. Reviewer should ask for the ATOM#2760 integration to exercise get_mla_decode_num_heads end-to-end before it is relied on.

2 finding(s) posted inline, on the lines they are about:

  • aiter/ops/attention.py:2758 — The runs predicate at aiter/ops/attention.py:2758 counts every supported=None JIT route as running, but on…
  • aiter/ops/attention.py:2713 — MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128) at aiter/ops/attention.py:2713 is a hand-maintained…

Comment thread aiter/ops/attention.py
s = get_mla_decode_shape_support(
heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs
)
if s.supported or (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] The runs predicate at aiter/ops/attention.py:2758 counts every supported=None JIT route as running, but on gfx950 with enable_experimental an HK-routed fp8 decode reports supported=None with "hk_mla_v32_decode_fwd ignores q_scale and kv_scale" only in reasons (aiter/ops/attention.py:2553, pinned by test_hk_backend) — a caller that pads its fp8 query heads to the answered count runs a route the shape rules themselves flag as ignoring the fp8 scales, and the wrapper drops the reasons the direct get_mla_decode_shape_support query would have shown. Author must exclude routes whose reasons carry a numerics caveat from the runs predicate, or document in the docstring that "runs" includes the HK scale-ignoring case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 24fadf3. The runs predicate now counts supported is None only for the FlyDSL PS1 and OPUS JIT routes (_MLA_DECODE_JIT_BACKENDS_THAT_RUN), on top of the existing asm_status is NOT_ASM check. The HK route is excluded, since the shape rules record that hk_mla_v32_decode_fwd ignores q_scale and kv_scale, and the docstring says so.

test_decode_num_heads pins it: on gfx950 with enable_experimental, 128 fp8 heads route to HK (supported is None) and now get no answer. At 929e7c4 the same assertion fails with assert 128 is None. HK already reported supported is False for any call with LSE or round-robin KV, so DCP callers never reached it.

Comment thread aiter/ops/attention.py
# these or the count it was asked for; narrower counts some architectures also
# run (gfx950 fp8: 8 heads at qlen 4, 12 heads up to 128 rows) are not tried.
# Callers that pick a padded width themselves read the list here.
MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [verified] MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128) at aiter/ops/attention.py:2713 is a hand-maintained copy of the kernel widths that actually live in the per-arch C++ asm tables (asm_mla.cu's gqa_ratio cases) and the FlyDSL/OPUS builds, and nothing pins it there — when a width is added or dropped the tuple silently goes stale, the same staleness this PR's motivation moves from downstream callers into aiter. Reviewer should ask for a pin (e.g. a test asserting the tuple against mla_decode_asm_query on a built arch) or a comment naming the source of truth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment naming the source of truth in 24fadf3: the head counts the decode backends are built for, i.e. the per-arch asm tables (hsa/<arch>/mla/*.csv) and the FlyDSL / OPUS kernels. The comment also says to update the list when a backend gains or drops a width.

I did not add a pin test. The widths come from several backends: the asm tables, whose rows are kernel gqa values that wider counts reach through the remaps in asm_mla.cu, and the FlyDSL / OPUS JIT kernels, which have no availability table. So there is no single table on one arch to assert the tuple against.

The runs predicate counted every supported=None JIT route. gfx950's experimental
HK route also reports None, but hk_mla_v32_decode_fwd ignores q_scale and
kv_scale, so a caller padding an fp8 query to that answer would run a route the
shape rules flag for its numerics. Count supported=None only for the FlyDSL PS1
and OPUS JIT routes (_MLA_DECODE_JIT_BACKENDS_THAT_RUN); the asm checks are
unchanged. test_decode_num_heads pins it: 128 fp8 heads on gfx950 with
enable_experimental route to HK and now get no answer (128 before).

The MLA_DECODE_KERNEL_HEAD_COUNTS comment also names its source of truth: the
per-arch asm tables and the FlyDSL / OPUS kernels.
@gbyu-amd

Copy link
Copy Markdown
Contributor Author

On the end-to-end note in the review summary: the ROCm/ATOM#2760 integration was not re-run for this revision. The changes since its last end-to-end run do not change any answer on the path it exercises. That path is Kimi-K3 on gfx1250, fp8, DCP decode with LSE and round-robin KV, served by the PS1 code object / FlyDSL PS1. The changes only scope the docstring and the list comment, and stop counting the gfx950 HK route, which that path never reaches (HK reports supported is False for any LSE or round-robin call). The unit test and the --mode cp runs in the PR Self-Review cover that DCP configuration at this revision.

@gbyu-amd

Copy link
Copy Markdown
Contributor Author

@aiter-bot review

@aiter-bot

Copy link
Copy Markdown

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

@aiter-bot aiter-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled); the target op_tests/test_mla_shape_support.py exists but this review environment has no GPU (CPU-only torch 2.15.0+cpu, no rocminfo arch), so it could not be run — environment gap, not a PR defect
Perf (advisory): NOT RUN — the target exposes no benchmark entry point, and the change is a host-side query over the existing cached shape rules, so no kernel latency is involved
Size: 124 lines / 2 files
Design (advisory): the runs predicate and candidate list — a supported=None FlyDSL PS1/OPUS JIT route counts as running (no availability table to consult), while a folded PS1 route, a planner/reducer rejection, a kernel-less or failed asm query and gfx950's HK route (ignores q_scale/kv_scale) do not; only num_heads and the five kernel head counts (16/32/64/96/128) are tried, never narrower counts (gfx950 fp8's 8/12)
Human: recommend Oxana Korzh review whether that runs predicate and candidate list are the right contract for the ATOM#2760 DCP caller to gather query heads against in PR #8181 (she authored get_mla_decode_shape_support)

4 finding(s) posted inline, on the lines they are about:

  • aiter/ops/attention.py:2720 — _MLA_DECODE_JIT_BACKENDS_THAT_RUN at aiter/ops/attention.py:2720 counts OPUS routes as running, but nothing…
  • aiter/ops/attention.py:2766 — The runs predicate at aiter/ops/attention.py:2766 counts a FlyDSL PS1 route with v_head_dim != 512 as…
  • aiter/ops/attention.py:2723 — The named consumer, the ROCm/ATOM#2760 DCP gather, was not re-run at this revision (PR Self-Review…
  • aiter/ops/attention.py:2716 — MLA_DECODE_KERNEL_HEAD_COUNTS at aiter/ops/attention.py:2716 is maintained by hand

Comment thread aiter/ops/attention.py

# JIT routes whose supported=None get_mla_decode_num_heads counts as running.
# HK also reports None, but hk_mla_v32_decode_fwd ignores q_scale and kv_scale.
_MLA_DECODE_JIT_BACKENDS_THAT_RUN = (MlaBackend.FLYDSL_PS1, MlaBackend.OPUS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [verified] _MLA_DECODE_JIT_BACKENDS_THAT_RUN at aiter/ops/attention.py:2720 counts OPUS routes as running, but nothing exercises that branch — the autouse fixture at op_tests/test_mla_shape_support.py:44 deletes AITER_MLA_USE_OPUS, no test sets it for get_mla_decode_num_heads, and opus_mla_decode_fwd has no kernel test in op_tests/ at all — so under AITER_MLA_USE_OPUS=1 (test_opus_cp shows 16 fp8 heads on gfx950 routing to OPUS with supported None) the function answers head counts whose runnability nothing verified, and if opus_mla_decode_fwd rejects a planner-accepted count, that caller pads its query to a width that fails at launch. Author must add an OPUS-route case to test_decode_num_heads (set AITER_MLA_USE_OPUS=1 the way test_opus_cp does) or state the basis for counting OPUS routes as running.

@gbyu-amd gbyu-amd Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered in 7720ede: test_decode_num_heads selects OPUS as test_opus_cp does. An accepted call (fp8, CP 4, round-robin) answers 16; rejected ones (no round-robin, bf16 CP) never do. Basis, now on _MLA_DECODE_JIT_BACKENDS_THAT_RUN: like FlyDSL PS1, OPUS has no availability table, and the shape rules already return False for calls it cannot take.

Comment thread aiter/ops/attention.py
s = get_mla_decode_shape_support(
heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs
)
if s.supported or (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [inferred] The runs predicate at aiter/ops/attention.py:2766 counts a FlyDSL PS1 route with v_head_dim != 512 as running, but the base query's bad_v_dim check exempts FlyDSL routes (merge-target aiter/ops/attention.py:2531) while the PS1 kernel's layout checks hard-require the 512 latent (aiter/ops/flydsl/mla_kernels.py:91-96) — can a caller passing a non-512 latent, for which reduce cases exist (merge-target aiter/ops/attention.py:2528-2530), be told "runs" for a route the kernel rejects at launch? Reviewer should ask whether get_mla_decode_num_heads should reject v_head_dim != 512 outright, as the asm and OPUS routes already do.

@gbyu-amd gbyu-amd Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper only inherits get_mla_decode_shape_support's coverage. If its v_head_dim check should not exempt FlyDSL routes, that gap affects every caller of the shape rules today; the fix belongs there, in a separate change.

Comment thread aiter/ops/attention.py
_MLA_DECODE_JIT_BACKENDS_THAT_RUN = (MlaBackend.FLYDSL_PS1, MlaBackend.OPUS)


def get_mla_decode_num_heads(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [verified] The named consumer, the ROCm/ATOM#2760 DCP gather, was not re-run at this revision (PR Self-Review "Unverified"; the author's comment argues the changes since its last end-to-end run do not change the Kimi-K3 path's answers), so get_mla_decode_num_heads (aiter/ops/attention.py:2723) is pinned only by its own unit test on one gfx1250 DCP config — and the 96-head answer that test pins at qlen 5 has no kernel run at qlen 5, since test_mla_flydsl.py offers q-seq-len 1/2/4/6/8 only. Reviewer should ask for the ATOM#2760 integration to exercise get_mla_decode_num_heads end-to-end before it is relied on.

Comment thread aiter/ops/attention.py
# truth: the head counts the decode backends are built for, i.e. the per-arch
# asm tables (hsa/<arch>/mla/*.csv) and the FlyDSL / OPUS kernels; update this
# list when a backend gains or drops a width.
MLA_DECODE_KERNEL_HEAD_COUNTS = (16, 32, 64, 96, 128)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [verified] MLA_DECODE_KERNEL_HEAD_COUNTS at aiter/ops/attention.py:2716 is maintained by hand — its comment names the per-arch asm tables and the FlyDSL/OPUS kernels as the source of truth, but nothing re-derives it (the same five counts already exist separately as _PAGESIZE1_NUM_Q_HEADS at aiter/ops/flydsl/mla_kernels.py:19), so a width a backend later gains is silently never padded to and every padding caller skips it; answers stay correct, because each candidate is still checked through the shape rules, but wider than needed. Reviewer should ask for a test deriving the list from hsa//mla/.csv and the PS1 kernel's set, or accept the documented update duty.

@gbyu-amd gbyu-amd Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the documented update duty: a stale list only pads wider than needed, never wrongly, since every candidate goes through the shape rules. Deriving it from hsa/*/mla/*.csv would need every arch's tables, and the FlyDSL / OPUS widths have none.

The runs predicate counts supported=None on the FlyDSL PS1 and OPUS JIT routes,
but nothing exercised the OPUS branch. Cover it the way test_opus_cp selects
OPUS (AITER_MLA_USE_OPUS=1, gfx950, fp8, CP 4): a call its rules accept
(round-robin KV) answers 16, and calls they reject (CP without round-robin KV,
bf16 CP) never answer 16.

The comment on _MLA_DECODE_JIT_BACKENDS_THAT_RUN now states the basis: neither
route has an availability table, and the shape rules already return False for
the calls each cannot take, so None there means accepted by the rules.
@gbyu-amd

gbyu-amd commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Re the attention.py:2723 note (the thread reply would not post): ROCm/ATOM#2760 was not re-run, since nothing since its last end-to-end run changes an answer on its Kimi-K3 path. qlen 5 is not a test_mla_flydsl.py choice; the 96-head runs cover 4 (ps1) and 6/8 (cp, LSE, round-robin) around it.

Comment-only: the docstring, the two module-level comments and the test
comments now state the contract briefly and point at MlaDecodeShapeSupport for
the limits of the shape rules instead of restating them. No code change.
gbyu-amd added a commit that referenced this pull request Nov 26, 2026
… VGPR pins (#8736 @ 13b071f, head 2026-11-26T06:02:59Z) (#8743)

Port of #8736's commits d9926d2 and 13b071f onto k3-455-dev; its
first commit (#8181 + #7913) is already here.

Conflicts:
- mla_pagesize1_fp8_fp8.py: #8736's file. It carries #7913 @ 51bb7c6
  (k3-455-dev had 067fee3), the only difference in that file.
- mla_reduce_kernels.cuh: k3-455-dev's file (keeps #7876 and #7914) plus
  #8736's row-parallel reducer and its dispatch, checked first as in #8736.

Co-authored-by: xiangM99 <[email protected]>
@gbyu-amd

Copy link
Copy Markdown
Contributor Author

@zufayu could you review this?

gbyu-amd added a commit that referenced this pull request Dec 3, 2026
…#8181 @ 2d34816, head 2026-11-19T06:16:25Z)

Applied as the diff 2037a77..2d34816 (2 files) onto the rebased 1116 tree; PR state: open, author gbyu-amd, base main.

(cherry picked from commit b6bd5a6)

Updated 12-03 to the PR head #8181 @ 0d34555: folds in the PR's later commits 3ac7ea5 [MLA] Export MLA_DECODE_KERNEL_HEAD_COUNTS; fd90954 [MLA] get_mla_decode_num_heads: state the shape-query limits it inherits; 929e7c4 [MLA] get_mla_decode_num_heads: say it answers among the kernel head counts only; 24fadf3 [MLA] get_mla_decode_num_heads: do not count the HK route as running; 7720ede [MLA] test_decode_num_heads: cover the OPUS route; state why None counts; 0d34555 [MLA] get_mla_decode_num_heads: shorten the comments.
gbyu-amd added a commit to ROCm/ATOM that referenced this pull request Dec 3, 2026
…2542233, head 2026-11-24T07:47Z)

Applied as the diff 7762f29..ab2bfb5 (10 files) onto the rebased 1116 tree; PR state: open, author gbyu-amd, base main.

(cherry picked from commit 9430c00)

Updated 12-03 to the PR head 2542233: + 2542233 "Read aiter's kernel head counts; size native decode at (1, k + 1)" (needs ROCm/aiter#8181 at its head for the public MLA_DECODE_KERNEL_HEAD_COUNTS). Onto main: imports kept as main has them (no mla_prefill_fwd here, is_plugin_mode from atom.plugin.prepare); docs/context_parallel_guide.md keeps main's head-width text (folds rebuild the indptrs) over the PR's rewrite.
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
… VGPR pins (#8736 @ 13b071f, head 2026-11-26T06:02:59Z) (#8743)

Port of #8736's commits d9926d2 and 13b071f onto k3-455-dev; its
first commit (#8181 + #7913) is already here.

Conflicts:
- mla_pagesize1_fp8_fp8.py: #8736's file. It carries #7913 @ 51bb7c6
  (k3-455-dev had 067fee3), the only difference in that file.
- mla_reduce_kernels.cuh: k3-455-dev's file (keeps #7876 and #7914) plus
  #8736's row-parallel reducer and its dispatch, checked first as in #8736.

Co-authored-by: xiangM99 <[email protected]>
(cherry picked from commit 5b18892)

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.

2 participants