Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
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.
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
… 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.
…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.
5c159dc to
2d34816
Compare
…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).
2d34816 to
bd060b3
Compare
…(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.
a0308cc to
3ac7ea5
Compare
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 22 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to
Review (advisory):
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…
| s = get_mla_decode_shape_support( | ||
| heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs | ||
| ) | ||
| if s.supported or ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| kv_dtype: torch.dtype, | ||
| **kwargs, | ||
| ) -> int | None: | ||
| """The fewest Q heads, at least num_heads, that mla_decode_fwd runs for a decode. |
There was a problem hiding this comment.
📝 [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.
There was a problem hiding this comment.
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.
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 24 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to
Review (advisory):
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…
| kv_dtype: torch.dtype, | ||
| **kwargs, | ||
| ) -> int | None: | ||
| """The fewest Q heads, at least num_heads, that mla_decode_fwd runs for a decode. |
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 24 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to
Review (advisory):
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…
| s = get_mla_decode_shape_support( | ||
| heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs | ||
| ) | ||
| if s.supported or ( |
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
| # 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) |
There was a problem hiding this comment.
📝 [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.
There was a problem hiding this comment.
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.
|
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 |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 24 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8181 — [MLA] Add get_mla_decode_num_heads: the head count to pad a decode query to
Review (advisory):
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
|
|
||
| # 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) |
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
| s = get_mla_decode_shape_support( | ||
| heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs | ||
| ) | ||
| if s.supported or ( |
There was a problem hiding this comment.
📝 [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.
There was a problem hiding this comment.
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.
| _MLA_DECODE_JIT_BACKENDS_THAT_RUN = (MlaBackend.FLYDSL_PS1, MlaBackend.OPUS) | ||
|
|
||
|
|
||
| def get_mla_decode_num_heads( |
There was a problem hiding this comment.
📝 [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.
| # 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) |
There was a problem hiding this comment.
📝 [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.
There was a problem hiding this comment.
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.
|
Re the |
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.
… 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]>
|
@zufayu could you review this? |
…#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.
…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.
… 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)
Summary
Adds
get_mla_decode_num_heads(num_heads, max_seqlen_qo, q_dtype, kv_dtype, **kwargs)toaiter.ops.attention: the first ofnum_headsand the kernel head counts above it (MLA_DECODE_KERNEL_HEAD_COUNTS) thatmla_decode_fwdruns 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_supportalready 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_headstriesnum_headsand each kernel head count above it (16, 32, 64, 96, 128) throughget_mla_decode_shape_supportwith 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 reportssupported is None, buthk_mla_v32_decode_fwdignoresq_scaleandkv_scale.Nonewhen 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 toMlaDecodeShapeSupportfor 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 asMLA_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_headscovers 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=Falsegives 128 for 64 heads), and every returned count is one the shape query says runs and is either the requested count or one ofMLA_DECODE_KERNEL_HEAD_COUNTS. It also checks that gfx950's experimental HK route never counts: 128 fp8 heads withenable_experimentalget no answer. The OPUS route (AITER_MLA_USE_OPUS=1, as intest_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):
#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
On MI455X (gfx1250), this branch at
0d34555e(onmainffbd9c6a):op_tests/test_mla_shape_support.py: 20 passed, 2 skipped (includingtest_decode_num_heads).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.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.blackandruffclean on the changed files.Details in PR Self-Review below.
Documentation
Dependencies
Breaking Changes
None: a new function; nothing existing changes.
PR Self-Review
Reviewed revision
0d34555eba8940d99526971d35ad8d375309f59aBehavior 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 ofnum_headsand the kernel head counts above it thatmla_decode_fwdruns for the described decode, orNonewhen no count up to 128 runs. It walks those candidates through the existingget_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.get_mla_decode_shape_supportreportssupported is True, orsupported is Noneon a FlyDSL PS1 or OPUS JIT route.Falsefor the calls each cannot take. SoNonethere means the rules accept the call.Nonebut is not counted, because the shape rules note thathk_mla_v32_decode_fwdignoresq_scaleandkv_scale.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.MlaDecodeShapeSupport, which the docstring points to: launch-size limits are not checked, and onlykv_layout="token_major"is described.Why the existing behavior is insufficient:
get_mla_decode_shape_supportanswers 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-20261120container, this branch at0d34555eonPYTHONPATH, 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 revision929e7c42, the new HK assertion fails withassert 128 is None, because the HK route was counted.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, allerr0.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.black --check(26.5.1) andruff check(0.16.7) are clean on both changed files.Unverified:
test_decode_num_headsexercises 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 whateverget_mla_decode_shape_supportreports for them.test_mla_flydsl.py's--q-seq-lenchoices. The 96-head kernel runs cover qlen 1, 2, 4 (ps1) and 6, 8 (cp) around it.PR-specific question
Before this PR.
test_decode_num_headsfails at import:get_mla_decode_num_headsandMLA_DECODE_KERNEL_HEAD_COUNTSdo 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):
fast_mode=False, 64 heads gives 128.arch="gfx950", enable_experimental=True, 128 fp8 heads route to HK (supported is None) and get no answer. Before this revision they got 128.AITER_MLA_USE_OPUS=1, gfx950, fp8, CP 4 (as intest_opus_cp):supported is None) and answer 16;get_mla_decode_shape_support;MLA_DECODE_KERNEL_HEAD_COUNTS.Why existing tests do not cover it. The existing tests in this file check
get_mla_decode_shape_supportfor 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: addstest_decode_num_heads, described above, and imports the two new names.get_mla_decode_num_heads.