Skip to content

[ASM] [HIP] [FlyDSL] Add pin gpr(nhead96/128) and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 - #5844

Merged
coderfeli merged 3 commits into
ROCm:mainfrom
xiangM99:kimi_mla_nhead96_DCP
Oct 1, 2026
Merged

coderfeli merged 3 commits into
ROCm:mainfrom
xiangM99:kimi_mla_nhead96_DCP

Conversation

@xiangM99

@xiangM99 xiangM99 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Motivation

This PR adds round-robin DCP support to the persistent PS1 FlyDSL kernel. It also ships the 96/128-head kernel as pre-built code objects.

What's new

1. nhead = 96 in the persistent PS1 FP8 kernel (aiter/ops/flydsl/kernels/mla_gfx1250/mla_pagesize1_fp8_fp8.py)

  • The 96 heads are split into six 16-head tiles over the 8 waves. The two waves that own no head tile only gather, and are gated off from computing and storing.
  • Above 64 heads the metadata planner emits one query row per work item, so 96 heads supports MTP at any max_seqlen_q (tested with 1/2/3/4/6/8), causal and non-causal, with or without the final LSE.

2. Round-robin DCP (cp_world_size > 1, causal)

  • Global KV position p lives on rank p % W. Each rank runs on its own KV shard, and the kernel applies the causal mask on global positions using qo_indptr / kv_indptr / g_kv_indptr. A query row that sees no local KV writes out = 0 and lse = -inf, so the per-rank results can be merged by LSE.
  • flydsl_mla_pagesize1_fp8_fp8 gains qo_indptr, kv_indptr, g_kv_indptr, cp_world_size and cp_rank. mla_decode_fwd now keeps CP calls on the FlyDSL PS1 path when g_kv_indptr is given.

3. Tests (op_tests/test_mla_flydsl.py)

  • --mode cp: round-robin DCP. Each rank is checked against a per-rank torch reference, including LSE and the empty-row convention. The LSE-merged output of all ranks is checked against full-KV attention.
  • --mode ps1-asm / --mode cp-asm: every case runs through mla_decode_fwd twice, once on FlyDSL JIT and once on the code object. Output and LSE must match bit for bit, and the code-object output is checked against the torch reference. The test also asserts which backend actually ran, so a silent fallback fails the test. Causal and LSE are swept, which reaches all six .co files.
  • --mode ps1-vs-asm now covers 96 heads. The ASM PS64 side pads Q to 128 heads, and the asm_heads column shows this.
  • pytest entry points: test_ps1_asm_matches_flydsl, test_cp_asm_matches_flydsl, test_cp_asm_no_lse_matches_flydsl, test_ps1_cp_round_robin.

Test Plan

Run on gfx1250 from the repo root. The test script sets AITER_MLA_DECODE_PS1_FLYDSL=1 itself.

# pytest smoke tests
python3 -m pytest -q op_tests/test_mla_flydsl.py

# Persistent PS1 accuracy + perf, all head counts (16 heads: q_seq 1-4, 96 heads: up to 8)
python3 op_tests/test_mla_flydsl.py --mode ps1 --q-seq-len 1 2 3 4 6 8
python3 op_tests/test_mla_flydsl.py --mode ps1 --q-seq-len 1 2 3 4 6 8 --varlen
python3 op_tests/test_mla_flydsl.py --mode ps1 -b 1 -c 1 63 64 65

# Round-robin DCP, W = 2 / 4 / 8
python3 op_tests/test_mla_flydsl.py --mode cp --varlen --scales poc

# Code objects vs FlyDSL JIT, bit-exact (covers all six 96-head .co)
python3 op_tests/test_mla_flydsl.py --mode ps1-asm --q-seq-len 1 2 3 4 6 8 --varlen
python3 op_tests/test_mla_flydsl.py --mode cp-asm --varlen --scales poc

# Perf vs ASM PS
python3 op_tests/test_mla_flydsl.py --mode ps1-vs-asm --num-heads 96 \
    -b 1 4 16 64 256 -c 2048 8192 16384
python3 op_tests/test_mla_flydsl.py --mode ps1-vs-asm --num-heads 96 \
    -b 32 64 -c 8192 16384 32768 131072 --varlen --varlen-min-ratio 0.1

Test Result

Accuracy

  • pytest: 6 passed.
  • ps1 / cp / ps1-asm / cp-asm: every mode exits 0, and no case exceeds the 5% mismatch threshold.
  • ps1-asm / cp-asm: the code objects match FlyDSL JIT bit for bit in output and LSE for every case. That includes cp-asm with LSE on and off: 72 cases over W = 2 / 4 / 8.

**96 heads: FlyDSL PS1 vs ASM **

Scenario Points Geomean speedup Range
Equal length, baseline sweep 15 1.07x 0.84x – 1.48x
Large batch + short context 9 1.48x 1.06x – 1.74x
Small batch + long context 12 1.05x 0.99x – 1.14x
Small batch + long context, varlen 16 1.83x 1.22x – 5.02x
Large batch + short context, varlen 12 1.27x 1.03x – 1.46x
All 64 1.32x

Most of the gain is in short contexts and variable-length batches.

Equal length, baseline sweep
batch ctx FlyDSL (us) ASM (us) speedup
1 2048 19.1 28.3 1.48x
4 2048 21.1 21.3 1.01x
16 2048 24.8 21.8 0.88x
64 2048 32.1 26.9 0.84x
256 2048 48.4 53.8 1.11x
1 8192 25.2 31.9 1.27x
4 8192 27.3 32.8 1.20x
16 8192 33.3 35.8 1.08x
64 8192 59.6 61.6 1.03x
256 8192 150.9 169.3 1.12x
1 16384 32.0 34.2 1.07x
4 16384 34.5 31.0 0.90x
16 16384 42.8 48.3 1.13x
64 16384 93.2 97.7 1.05x
256 16384 310.4 345.7 1.11x
Large batch + short context
batch ctx FlyDSL (us) ASM (us) speedup
4096 256 172.5 299.7 1.74x
8192 256 342.0 582.2 1.70x
16384 256 683.7 1155.9 1.69x
4096 288 188.1 320.3 1.70x
8192 288 377.7 633.1 1.68x
16384 288 751.7 1259.1 1.68x
4096 2048 726.7 865.5 1.19x
8192 2048 1499.1 1718.8 1.15x
16384 2048 3230.7 3433.2 1.06x
Small batch + long context
batch ctx FlyDSL (us) ASM (us) speedup
32 4096 31.8 31.4 0.99x
64 4096 41.6 47.4 1.14x
32 8192 40.7 45.1 1.11x
64 8192 59.7 62.1 1.04x
32 16384 58.8 60.0 1.02x
64 16384 93.7 96.9 1.03x
32 32768 92.2 95.4 1.03x
64 32768 164.7 170.3 1.03x
32 65536 162.6 172.2 1.06x
64 65536 324.1 337.9 1.04x
32 131072 321.6 345.6 1.07x
64 131072 627.9 682.0 1.09x
Small batch + long context, varlen

ctx is the mean context length; actual ctx is the min–max drawn for the batch.

batch ctx min_ratio actual ctx FlyDSL (us) ASM (us) speedup
32 8192 0.5 4143–19895 46.6 56.9 1.22x
64 8192 0.5 4189–22722 67.3 96.7 1.44x
32 16384 0.5 8425–36437 64.8 85.1 1.31x
64 16384 0.5 8274–55182 102.3 190.0 1.86x
32 32768 0.5 16590–93934 100.7 169.5 1.68x
64 32768 0.5 16534–94084 173.2 305.6 1.76x
32 131072 0.5 65896–419324 330.0 665.0 2.02x
64 131072 0.5 67088–425934 636.7 1313.2 2.06x
32 8192 0.1 901–21769 46.9 57.3 1.22x
64 8192 0.1 841–29282 68.9 108.8 1.58x
32 16384 0.1 2372–58074 67.8 108.7 1.60x
64 16384 0.1 1689–60630 103.2 204.1 1.98x
32 32768 0.1 4308–102543 101.4 174.7 1.72x
64 32768 0.1 3411–310429 176.1 884.3 5.02x
32 131072 0.1 13720–456283 330.7 692.5 2.09x
64 131072 0.1 17239–586259 639.7 1687.1 2.64x
Large batch + short context, varlen
batch ctx min_ratio actual ctx FlyDSL (us) ASM (us) speedup
4096 256 0.5 128–1209 223.3 313.9 1.41x
16384 256 0.5 128–1375 823.3 1203.6 1.46x
4096 288 0.5 144–2053 229.4 323.9 1.41x
16384 288 0.5 144–1715 855.3 1243.8 1.45x
4096 2048 0.5 1024–10886 793.0 886.0 1.12x
16384 2048 0.5 1024–11381 3355.8 3467.0 1.03x
4096 256 0.1 26–2144 224.8 288.9 1.29x
16384 256 0.1 26–2382 815.1 1108.0 1.36x
4096 288 0.1 29–1701 232.6 297.4 1.28x
16384 288 0.1 29–2454 853.6 1160.4 1.36x
4096 2048 0.1 205–17905 795.3 887.6 1.12x
16384 2048 0.1 205–18085 3351.2 3481.2 1.04x

Submission Checklist

@xiangM99
xiangM99 requested review from a team, coderfeli and shengnxu September 25, 2026 10:04
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5844 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot changed the title [ASM][HIP][FLYDSL] Add nhead=96 and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 [ASM] [HIP] [FlyDSL] Add nhead=96 and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 Sep 25, 2026
@xiangM99 xiangM99 changed the title [ASM] [HIP] [FlyDSL] Add nhead=96 and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 [ASM] [HIP] [FlyDSL] Add pin vgpr and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 Sep 30, 2026
@xiangM99 xiangM99 changed the title [ASM] [HIP] [FlyDSL] Add pin vgpr and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 [ASM] [HIP] [FlyDSL] Add pin gpr and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 Sep 30, 2026
@xiangM99 xiangM99 changed the title [ASM] [HIP] [FlyDSL] Add pin gpr and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 [ASM] [HIP] [FlyDSL] Add pin gpr(nhead96/128) and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 Sep 30, 2026
@coderfeli
coderfeli merged commit 4ee3874 into ROCm:main Oct 1, 2026
90 of 92 checks passed
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
Add the host-only pure header csrc/include/mla_decode_shape.h with
MlaPlanner, MlaHeadPlan, MlaPlannerFlags, MlaDecodeHeadPlan and
mla_decode_head_plan() (per-planner v1_0/v1_1/v1_2 bodies). The bodies
are literal moves of the inline head-fold / native-support / acceptance
logic from the v1_0, v1_1 and v1_2 metadata planners, which now call the
header; get_gpu_arch() and the env reads stay at the call sites and the
AITER_CHECK messages are unchanged. mla_metadata_cluster_multiplier also
moves into the header. The v1_2 text is moved as of ROCm#5844, whose gfx1250
FlyDSL PS1 clause also covers 96 heads at any max_seqlen_qo.

No behavior change: planner/reduce/decode golden capture on gfx950 is
bit-identical to the pre-change baseline.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
Move the stage1 head/qseqlen remap into a pure
mla_asm_decode_config(arch, q_type, kv_type, num_heads, nhead_kv,
max_seqlen_q, persistent, causal, has_lse, has_cprr) that returns an
MlaAsmDecodeCfg with a status (Ok=0, RemapReject=1, NoKernel=2,
ArchNotBuilt=3), a reason and the table key. The remap block is moved
literally; its three AITER_CHECKs become RemapReject with the same text.
gfx1250 gets its own remap (persistent/lse/cprr -> NoKernel; the
supported_variant list moved verbatim). Add
try_get_heuristic_kernel_mla() returning "" on miss;
get_heuristic_kernel_mla wraps it with the identical AITER_CHECK. Stage1
and the gfx1250 dispatch call the new function and throw the same
messages as before. The provably dead stage1 "cannot find suitable
kernel" check is removed. The cfg_mla_dsl lookup of mla_ps1_fp8_asm_fwd
(ROCm#5844) moves verbatim into mla_ps1_fp8_asm_config(), which returns
nullptr on a miss; the entry point keeps its AITER_CHECK.

Notes: status is enum class MlaAsmStatus : int (doc types it as int; a
ctypes packer must cast). A gfx1250 variant miss is RemapReject and
gfx1250 has_cprr is NoKernel (both unspecified in the doc). causal is
now bool, so a raw caller passing a value other than 0/1 gets the causal
kernel instead of a miss. The equally dead gfx1250 "cannot find suitable
gfx1250 kernel" check is kept.

No behaviour change: golden compare.py 0 unexpected diffs (gfx950),
device-free old-vs-new sweep identical for gfx942/gfx950/gfx1250.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
Add get_mla_decode_head_plan_v1 / mla_reduce_v1_supports pybinds in
module_mla_metadata, the mla_decode_asm_query ctypes entry in module_mla_asm
(bound with ctypes.CDLL, NULL stream, device-free with an explicit arch), and
the public aiter.get_mla_decode_shape_support query with
MLA_DECODE_SHAPE_API_VERSION = 1 (design doc §5.2-5.4).

mla_decode_fwd's native/fold gate and FlyDSL/opus/HK backend selection now
come from the same C++ helpers the planner uses (C++ arch, atoi env parse),
with a new fast_mode keyword (default True, today's behaviour) so the fold
follows the planner mode the caller ran. Intended changes: >128-head folds
(fp8 144 now runs), fp16, the gfx1250 fallthrough, the arch source, and
"2"-style env values. A byte KV buffer (3-buffer layout) is planned as fp8
like its callers plan it; non-native fp8 variants and byte KV always take
asm. is_experimental_enabled and the PS1 FlyDSL parses use atoi semantics.
AITER_MLA_USE_OPUS now uses atoi semantics too (previously only "1").

ROCm#5844's gfx1250 dispatch is ported into mla_decode_backend: FlyDSL PS1
also takes 96 heads at any max_seqlen_qo and round-robin CP (new
cp_round_robin input), and 96/128 heads go to the new
MlaBackend.PS1_FP8_ASM (mla_ps1_fp8_asm_fwd) unless
AITER_MLA_DECODE_PS1_ASM (atoi, default 1) is 0; the query checks that
route against cfg_mla_dsl through the new mla_ps1_fp8_asm_query entry.
The query reports a FlyDSL PS1 or PS1 asm route as unsupported when the
planner folds the heads (fast_mode=False), since those kernels read
unfolded heads; mla_decode_fwd's dispatch is unchanged there.

Adds op_tests/test_mla_shape_support.py (device-free planner verdict,
asm LSE and gfx1250 PS1 backend checks, GPU planner and decode
agreement) and passes fast_mode at test_mla_persistent's mla_decode_fwd
call sites.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
Add get_mla_decode_head_plan_v1 / mla_reduce_v1_supports pybinds in
module_mla_metadata, the mla_decode_asm_query ctypes entry in module_mla_asm
(bound with ctypes.CDLL, NULL stream, device-free with an explicit arch), and
the public aiter.get_mla_decode_shape_support query (design doc §5.2-5.4).

mla_decode_fwd's native/fold gate and FlyDSL/opus/HK backend selection now
come from the same C++ helpers the planner uses (C++ arch, atoi env parse),
with a new fast_mode keyword (default True, today's behaviour) so the fold
follows the planner mode the caller ran. Intended changes: >128-head folds
(fp8 144 now runs), fp16, the gfx1250 fallthrough, the arch source, and
"2"-style env values. A byte KV buffer (3-buffer layout) is planned as fp8
like its callers plan it; non-native fp8 variants and byte KV always take
asm. is_experimental_enabled and the PS1 FlyDSL parses use atoi semantics.
AITER_MLA_USE_OPUS now uses atoi semantics too (previously only "1").

ROCm#5844's gfx1250 dispatch is ported into mla_decode_backend: FlyDSL PS1
also takes 96 heads at any max_seqlen_qo and round-robin CP (new
cp_round_robin input), and 96/128 heads go to the new
MlaBackend.PS1_FP8_ASM (mla_ps1_fp8_asm_fwd) unless
AITER_MLA_DECODE_PS1_ASM (atoi, default 1) is 0; the query checks that
route against cfg_mla_dsl through the new mla_ps1_fp8_asm_query entry.
The query reports a FlyDSL PS1 or PS1 asm route as unsupported when the
planner folds the heads (fast_mode=False), since those kernels read
unfolded heads; mla_decode_fwd's dispatch is unchanged there.

Adds op_tests/test_mla_shape_support.py (device-free planner verdict,
asm LSE and gfx1250 PS1 backend checks, GPU planner and decode
agreement) and passes fast_mode at test_mla_persistent's mla_decode_fwd
call sites.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
Add get_mla_decode_head_plan_v1 / mla_reduce_v1_supports pybinds in
module_mla_metadata, the mla_decode_asm_query ctypes entry in module_mla_asm
(bound with ctypes.CDLL, NULL stream, device-free with an explicit arch), and
the public aiter.get_mla_decode_shape_support query (design doc §5.2-5.4).

mla_decode_fwd's native/fold gate and FlyDSL/opus/HK backend selection now
come from the same C++ helpers the planner uses (C++ arch, atoi env parse),
with a new fast_mode keyword (default True, today's behaviour) so the fold
follows the planner mode the caller ran. Intended changes: >128-head folds
(fp8 144 now runs), fp16, the gfx1250 fallthrough, the arch source, and
"2"-style env values. A byte KV buffer (3-buffer layout) is planned as fp8
like its callers plan it; non-native fp8 variants and byte KV always take
asm. is_experimental_enabled and the PS1 FlyDSL parses use atoi semantics.
AITER_MLA_USE_OPUS now uses atoi semantics too (previously only "1").

ROCm#5844's gfx1250 dispatch is ported into mla_decode_backend: FlyDSL PS1
also takes 96 heads at any max_seqlen_qo and round-robin CP (new
cp_round_robin input), and 96/128 heads go to the new
MlaBackend.PS1_FP8_ASM (mla_ps1_fp8_asm_fwd) unless
AITER_MLA_DECODE_PS1_ASM (atoi, default 1) is 0; the query checks that
route against cfg_mla_dsl through the new mla_ps1_fp8_asm_query entry.
The query reports a FlyDSL PS1 or PS1 asm route as unsupported when the
planner folds the heads (fast_mode=False), since those kernels read
unfolded heads; mla_decode_fwd's dispatch is unchanged there.

Adds op_tests/test_mla_shape_support.py (device-free planner verdict,
asm LSE and gfx1250 PS1 backend checks, GPU planner and decode
agreement) and passes fast_mode at test_mla_persistent's mla_decode_fwd
call sites.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 2, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 12, 2026
Add the host-only pure header csrc/include/mla_decode_shape.h with
MlaPlanner, MlaHeadPlan, MlaPlannerFlags, MlaDecodeHeadPlan and
mla_decode_head_plan() (per-planner v1_0/v1_1/v1_2 bodies). The bodies
are literal moves of the inline head-fold / native-support / acceptance
logic from the v1_0, v1_1 and v1_2 metadata planners, which now call the
header; get_gpu_arch() and the env reads stay at the call sites and the
AITER_CHECK messages are unchanged. mla_metadata_cluster_multiplier also
moves into the header. The v1_2 text is moved as of ROCm#5844, whose gfx1250
FlyDSL PS1 clause also covers 96 heads at any max_seqlen_qo.

No behavior change: planner/reduce/decode golden capture on gfx950 is
bit-identical to the pre-change baseline.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 12, 2026
Move the stage1 head/qseqlen remap into a pure
mla_asm_decode_config(arch, q_type, kv_type, num_heads, nhead_kv,
max_seqlen_q, persistent, causal, has_lse, has_cprr) that returns an
MlaAsmDecodeCfg with a status (Ok=0, RemapReject=1, NoKernel=2,
ArchNotBuilt=3), a reason and the table key. The remap block is moved
literally; its three AITER_CHECKs become RemapReject with the same text.
gfx1250 gets its own remap (persistent/lse/cprr -> NoKernel; the
supported_variant list moved verbatim). Add
try_get_heuristic_kernel_mla() returning "" on miss;
get_heuristic_kernel_mla wraps it with the identical AITER_CHECK. Stage1
and the gfx1250 dispatch call the new function and throw the same
messages as before. The provably dead stage1 "cannot find suitable
kernel" check is removed. The cfg_mla_dsl lookup of mla_ps1_fp8_asm_fwd
(ROCm#5844) moves verbatim into mla_ps1_fp8_asm_config(), which returns
nullptr on a miss; the entry point keeps its AITER_CHECK. ROCm#6132's gfx950
non-persistent fp8 gqa64 qlen1 clause moves with the remap; its
total_q * kv_split <= 32768 check needs launch sizes, so the remap records
the bound in MlaAsmDecodeCfg::max_q_x_kv_split and stage1 raises the same
AITER_CHECK right after the remap.

Notes: status is enum class MlaAsmStatus : int (doc types it as int; a
ctypes packer must cast). A gfx1250 variant miss is RemapReject and
gfx1250 has_cprr is NoKernel (both unspecified in the doc). causal is
now bool, so a raw caller passing a value other than 0/1 gets the causal
kernel instead of a miss. The equally dead gfx1250 "cannot find suitable
gfx1250 kernel" check is kept.

No behaviour change: golden compare.py 0 unexpected diffs (gfx950),
device-free old-vs-new sweep identical for gfx942/gfx950/gfx1250.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 12, 2026
Add get_mla_decode_head_plan_v1 / mla_reduce_v1_supports pybinds in
module_mla_metadata, the mla_decode_asm_query ctypes entry in module_mla_asm
(bound with ctypes.CDLL, NULL stream, device-free with an explicit arch), and
the public aiter.get_mla_decode_shape_support query (design doc §5.2-5.4).
The CDLL path is build_ctypes_module, factored out of _ctypes_call with
main's JIT_LIB_EXT (.pyd on Windows); the entry points export via AITER_C_ITFS.

mla_decode_fwd's native/fold gate and FlyDSL/opus/HK backend selection now
come from the same C++ helpers the planner uses (C++ arch, atoi env parse),
with a new fast_mode keyword (default True, today's behaviour) so the fold
follows the planner mode the caller ran. Intended changes: >128-head folds
(fp8 144 now runs), fp16, the gfx1250 fallthrough, the arch source, and
"2"-style env values. A byte KV buffer (3-buffer layout) is planned as fp8
like its callers plan it; non-native fp8 variants and byte KV always take
asm. is_experimental_enabled and the PS1 FlyDSL parses use atoi semantics.
AITER_MLA_USE_OPUS now uses atoi semantics too (previously only "1").

ROCm#5844's gfx1250 dispatch is ported into mla_decode_backend: FlyDSL PS1
also takes 96 heads at any max_seqlen_qo and round-robin CP (new
cp_round_robin input), and 96/128 heads go to the new
MlaBackend.PS1_FP8_ASM (mla_ps1_fp8_asm_fwd) unless
AITER_MLA_DECODE_PS1_ASM (atoi, default 1) is 0; the query checks that
route against cfg_mla_dsl through the new mla_ps1_fp8_asm_query entry.
The query reports a FlyDSL PS1 or PS1 asm route as unsupported when the
planner folds the heads (fast_mode=False), since those kernels read
unfolded heads; mla_decode_fwd's dispatch is unchanged there. With
persistent=False the planner and reducer verdicts do not gate supported,
since that path never plans; launch-size bounds such as ROCm#6132's
total_q * kv_split <= 32768 are not checked.

Adds op_tests/test_mla_shape_support.py (device-free planner verdict,
asm LSE, non-persistent asm and gfx1250 PS1 backend checks, GPU planner
and decode agreement) and passes fast_mode at test_mla_persistent's
mla_decode_fwd call sites.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 12, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 12, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
Add the host-only pure header csrc/include/mla_decode_shape.h with
MlaPlanner, MlaHeadPlan, MlaPlannerFlags, MlaDecodeHeadPlan and
mla_decode_head_plan() (per-planner v1_0/v1_1/v1_2 bodies). The bodies
are literal moves of the inline head-fold / native-support / acceptance
logic from the v1_0, v1_1 and v1_2 metadata planners, which now call the
header; get_gpu_arch() and the env reads stay at the call sites and the
AITER_CHECK messages are unchanged. mla_metadata_cluster_multiplier also
moves into the header. The v1_2 text is moved as of ROCm#5844, whose gfx1250
FlyDSL PS1 clause also covers 96 heads at any max_seqlen_qo.

No behavior change: planner/reduce/decode golden capture on gfx950 is
bit-identical to the pre-change baseline.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
Move the stage1 head/qseqlen remap into a pure
mla_asm_decode_config(arch, q_type, kv_type, num_heads, nhead_kv,
max_seqlen_q, persistent, causal, has_lse, has_cprr) that returns an
MlaAsmDecodeCfg with a status (Ok=0, RemapReject=1, NoKernel=2,
ArchNotBuilt=3), a reason and the table key. The remap block is moved
literally; its three AITER_CHECKs become RemapReject with the same text.
gfx1250 gets its own remap (persistent/lse/cprr -> NoKernel; the
supported_variant list moved verbatim). Add
try_get_heuristic_kernel_mla() returning "" on miss;
get_heuristic_kernel_mla wraps it with the identical AITER_CHECK. Stage1
and the gfx1250 dispatch call the new function and throw the same
messages as before. The provably dead stage1 "cannot find suitable
kernel" check is removed. The cfg_mla_dsl lookup of mla_ps1_fp8_asm_fwd
(ROCm#5844) moves verbatim into mla_ps1_fp8_asm_config(), which returns
nullptr on a miss; the entry point keeps its AITER_CHECK. ROCm#6132's gfx950
non-persistent fp8 gqa64 qlen1 clause moves with the remap; its
total_q * kv_split <= 32768 check needs launch sizes, so the remap records
the bound in MlaAsmDecodeCfg::max_q_x_kv_split and stage1 raises the same
AITER_CHECK right after the remap.

Notes: status is enum class MlaAsmStatus : int (doc types it as int; a
ctypes packer must cast). A gfx1250 variant miss is RemapReject and
gfx1250 has_cprr is NoKernel (both unspecified in the doc). causal is
now bool, so a raw caller passing a value other than 0/1 gets the causal
kernel instead of a miss. The equally dead gfx1250 "cannot find suitable
gfx1250 kernel" check is kept.

No behaviour change: golden compare.py 0 unexpected diffs (gfx950),
device-free old-vs-new sweep identical for gfx942/gfx950/gfx1250.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
Add the host-only pure header csrc/include/mla_decode_shape.h with
MlaPlanner, MlaHeadPlan, MlaPlannerFlags, MlaDecodeHeadPlan and
mla_decode_head_plan() (per-planner v1_0/v1_1/v1_2 bodies). The bodies
are literal moves of the inline head-fold / native-support / acceptance
logic from the v1_0, v1_1 and v1_2 metadata planners, which now call the
header; get_gpu_arch() and the env reads stay at the call sites and the
AITER_CHECK messages are unchanged. mla_metadata_cluster_multiplier also
moves into the header. The v1_2 text is moved as of ROCm#5844, whose gfx1250
FlyDSL PS1 clause also covers 96 heads at any max_seqlen_qo.

No behavior change: planner/reduce/decode golden capture on gfx950 is
bit-identical to the pre-change baseline.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
Move the stage1 head/qseqlen remap into a pure
mla_asm_decode_config(arch, q_type, kv_type, num_heads, nhead_kv,
max_seqlen_q, persistent, causal, has_lse, has_cprr) that returns an
MlaAsmDecodeCfg with a status (Ok=0, RemapReject=1, NoKernel=2,
ArchNotBuilt=3), a reason and the table key. The remap block is moved
literally; its three AITER_CHECKs become RemapReject with the same text.
gfx1250 gets its own remap (persistent/lse/cprr -> NoKernel; the
supported_variant list moved verbatim). Add
try_get_heuristic_kernel_mla() returning "" on miss;
get_heuristic_kernel_mla wraps it with the identical AITER_CHECK. Stage1
and the gfx1250 dispatch call the new function and throw the same
messages as before. The provably dead stage1 "cannot find suitable
kernel" check is removed. The cfg_mla_dsl lookup of mla_ps1_fp8_asm_fwd
(ROCm#5844) moves verbatim into mla_ps1_fp8_asm_config(), which returns
nullptr on a miss; the entry point keeps its AITER_CHECK. ROCm#6132's gfx950
non-persistent fp8 gqa64 qlen1 clause moves with the remap; its
total_q * kv_split <= 32768 check needs launch sizes, so the remap records
the bound in MlaAsmDecodeCfg::max_q_x_kv_split and stage1 raises the same
AITER_CHECK right after the remap.

Notes: status is enum class MlaAsmStatus : int (doc types it as int; a
ctypes packer must cast). A gfx1250 variant miss is RemapReject and
gfx1250 has_cprr is NoKernel (both unspecified in the doc). causal is
now bool, so a raw caller passing a value other than 0/1 gets the causal
kernel instead of a miss. The equally dead gfx1250 "cannot find suitable
gfx1250 kernel" check is kept.

No behaviour change: golden compare.py 0 unexpected diffs (gfx950),
device-free old-vs-new sweep identical for gfx942/gfx950/gfx1250.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

ROCm#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit to okorzh-amd/aiter that referenced this pull request Oct 20, 2026
…nner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: ROCm#5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
okorzh-amd added a commit that referenced this pull request Oct 23, 2026
…acked by shared C++ head-fold/backend rules (#6107)

* [MLA] A1: move decode head-count planning into mla_decode_shape.h

Add the host-only pure header csrc/include/mla_decode_shape.h with
MlaPlanner, MlaHeadPlan, MlaPlannerFlags, MlaDecodeHeadPlan and
mla_decode_head_plan() (per-planner v1_0/v1_1/v1_2 bodies). The bodies
are literal moves of the inline head-fold / native-support / acceptance
logic from the v1_0, v1_1 and v1_2 metadata planners, which now call the
header; get_gpu_arch() and the env reads stay at the call sites and the
AITER_CHECK messages are unchanged. mla_metadata_cluster_multiplier also
moves into the header. The v1_2 text is moved as of #5844, whose gfx1250
FlyDSL PS1 clause also covers 96 heads at any max_seqlen_qo.

No behavior change: planner/reduce/decode golden capture on gfx950 is
bit-identical to the pre-change baseline.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] A2: move the mla_reduce (heads, head_dim) table into mla_reduce_cases.h

Move the _AITER_MLA_REDUCE_FOR_EACH_ROW support matrix (#5481) out of
mla_reduce_kernels.cuh into the preprocessor-only
csrc/include/mla_reduce_cases.h, with the same 24 rows in the same order;
mla_reduce_kernels.cuh includes it, so MLA_REDUCE_ROUTER, the extern
template block and reduce_instances/ are unchanged. The one edit to the
moved text: the comment's "the extern template block below" now reads
"the extern template block in mla_reduce_kernels.cuh", so it stays true
in the new file.

Add mla_reduce_v1_supports(num_heads, head_dim) to mla_decode_shape.h.
It expands the same table, and it does not check dtype or work-group
count.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] A3: factor the ASM decode remap into mla_asm_decode_config

Move the stage1 head/qseqlen remap into a pure
mla_asm_decode_config(arch, q_type, kv_type, num_heads, nhead_kv,
max_seqlen_q, persistent, causal, has_lse, has_cprr) that returns an
MlaAsmDecodeCfg with a status (Ok=0, RemapReject=1, NoKernel=2,
ArchNotBuilt=3), a reason and the table key. The remap block is moved
literally; its three AITER_CHECKs become RemapReject with the same text.
gfx1250 gets its own remap (persistent/lse/cprr -> NoKernel; the
supported_variant list moved verbatim). Add
try_get_heuristic_kernel_mla() returning "" on miss;
get_heuristic_kernel_mla wraps it with the identical AITER_CHECK. Stage1
and the gfx1250 dispatch call the new function and throw the same
messages as before. The provably dead stage1 "cannot find suitable
kernel" check is removed. The cfg_mla_dsl lookup of mla_ps1_fp8_asm_fwd
(#5844) moves verbatim into mla_ps1_fp8_asm_config(), which returns
nullptr on a miss; the entry point keeps its AITER_CHECK. #6132's gfx950
non-persistent fp8 gqa64 qlen1 clause moves with the remap; its
total_q * kv_split <= 32768 check needs launch sizes, so the remap records
the bound in MlaAsmDecodeCfg::max_q_x_kv_split and stage1 raises the same
AITER_CHECK right after the remap.

Notes: status is enum class MlaAsmStatus : int (doc types it as int; a
ctypes packer must cast). A gfx1250 variant miss is RemapReject and
gfx1250 has_cprr is NoKernel (both unspecified in the doc). causal is
now bool, so a raw caller passing a value other than 0/1 gets the causal
kernel instead of a miss. The equally dead gfx1250 "cannot find suitable
gfx1250 kernel" check is kept.

No behaviour change: golden compare.py 0 unexpected diffs (gfx950),
device-free old-vs-new sweep identical for gfx942/gfx950/gfx1250.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] A4: expose the decode shape query and drive mla_decode_fwd from it

Add get_mla_decode_head_plan_v1 / mla_reduce_v1_supports pybinds in
module_mla_metadata, the mla_decode_asm_query ctypes entry in module_mla_asm
(bound with ctypes.CDLL, NULL stream, device-free with an explicit arch), and
the public aiter.get_mla_decode_shape_support query (design doc §5.2-5.4).
The CDLL path is build_ctypes_module, factored out of _ctypes_call with
main's JIT_LIB_EXT (.pyd on Windows); the entry points export via AITER_C_ITFS.

mla_decode_fwd's native/fold gate and FlyDSL/opus/HK backend selection now
come from the same C++ helpers the planner uses (C++ arch, atoi env parse),
with a new fast_mode keyword (default True, today's behaviour) so the fold
follows the planner mode the caller ran. Intended changes: >128-head folds
(fp8 144 now runs), fp16, the gfx1250 fallthrough, the arch source, and
"2"-style env values. A byte KV buffer (3-buffer layout) is planned as fp8
like its callers plan it; non-native fp8 variants and byte KV always take
asm. is_experimental_enabled and the PS1 FlyDSL parses use atoi semantics.
AITER_MLA_USE_OPUS now uses atoi semantics too (previously only "1").

also takes 96 heads at any max_seqlen_qo and round-robin CP (new
cp_round_robin input), and 96/128 heads go to the new
MlaBackend.PS1_FP8_ASM (mla_ps1_fp8_asm_fwd) unless
AITER_MLA_DECODE_PS1_ASM (atoi, default 1) is 0; the query checks that
route against cfg_mla_dsl through the new mla_ps1_fp8_asm_query entry.
The query reports a FlyDSL PS1 or PS1 asm route as unsupported when the
planner folds the heads (fast_mode=False), since those kernels read
unfolded heads; mla_decode_fwd's dispatch is unchanged there. With
persistent=False the planner and reducer verdicts do not gate supported,
since that path never plans; launch-size bounds such as #6132's
total_q * kv_split <= 32768 are not checked.

Adds op_tests/test_mla_shape_support.py (device-free planner verdict,
asm LSE, non-persistent asm and gfx1250 PS1 backend checks, GPU planner
and decode agreement) and passes fast_mode at test_mla_persistent's
mla_decode_fwd call sites.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] A5: size metadata info and occupancy from the C++ planner rules

get_mla_metadata_info_v1 (dense path) now takes qk_batch_ratio,
kernel_num_heads and packed_qo_len_per_wg from the C++ head plan
(get_mla_decode_head_plan_v1) instead of its Python mirror of the planner.
For now each buffer is the max of the plan-derived size and the former
mirror size, so no size shrinks on any shape (doc 5.5 rows 3-4; the shrink
the doc's 2.4 row 6 allows is left to a follow-up). The sizes grow where
the mirror under-sized the planner (v1_0/v1_1 folds, fp16 at msq 5-7).
The num_head_qo % 4 assert now fires only where the planner rejects the
shape, so N=10 bf16/fp16 fast_mode is sized instead of asserting. The
sparse path stays on the moved mirror (_mla_legacy_max_qo_tiles_per_batch,
which still resolves the arch with get_gfx()); it could not be proven to
match the head plan.

#5844's gfx1250 FlyDSL PS1 96-head sizing clause is honored by the
plan-based dense sizing (the head plan makes 96 heads native, so
max_seqlen_qo tiles per batch); the moved mirror keeps the clause, with
the atoi parse, for the floor and the sparse path.

get_mla_decode_fwd_occupancy / _max_splits call the new pybind
mla_metadata_cluster_multiplier_v1 with the C++ arch and env parse, and
gain mla_version and rope dtype parameters with backward-compatible
defaults. mla_decode_fwd passes fp8 for a byte KV buffer, the dtype the
planner is given.

Separate fix: with fast_mode and intra_batch_mode both on, the dense
work_info_set and reduce_partial_map are now at least the v1_2 (non-intra)
bounds; tile_cnt * num_kv_splits under-counts the v1_2 planner, which
num_kv_splits does not cap. The sparse path has the same under-count and
is left unchanged.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] A6: take decode_update_mla_metadata_v1's head fold from the planner

decode_update_mla_metadata_v1 kept a hand-written copy of the v1_2 head
fold rule, resolved with get_gfx() and an exact dtypes.fp8 check, which had
drifted from metadata.cu. Where it disagreed it mapped works to the wrong
request (e.g. gfx950 bf16 N=32: request 1's KV range became request 0's)
without raising. It now asks the C++ head plan (get_mla_decode_head_plan_v1
via _mla_metadata_head_plan: C++ get_gpu_arch(), atoi env parse, original
max_seqlen_qo, fast_mode=True) for qk_batch_ratio and the kernel head count.

Changelog (behavior change for external callers):
- The fold now matches what get_mla_metadata_v1 (fast_mode=True) planned.
  Shapes no longer folded: gfx950 fp8 N=32 at max_seqlen_qo != 4, gfx950
  fp8 N=64, gfx950 bf16/fp16 at any N > 16 with N % 16 == 0, gfx942 fp8
  N=64 at max_seqlen_qo == 1, and the AITER_ENABLE_EXPERIMENTAL HK
  (hk_mtp_experimental) shapes.
- gfx1250 fp8 N=96 with AITER_MLA_DECODE_PS1_FLYDSL is no longer folded
  either: #5844 made it native in the planner but not in this copy.
- float8_e4m3fnuz on gfx950 now counts as fp8, as in the planner.
- Callers must pass the max_seqlen_qo they planned with (>= 1, before the
  qlen > 1 -> 1 rewrite; now asserted) and the dtype_q_nope /
  dtype_kv_nope given to get_mla_metadata_v1. The commented-out caller in
  op_tests/test_mla_persistent.py that passes max_seqlen_qo=1 for
  decode_qlen > 1 is wrong under this contract.
- vLLM main (7e583e615c) does not call this function; it only uses
  get_mla_metadata_v1.
- The unused batch_size local is gone; the signature is unchanged.

Known limitations: only v1_2 (fast_mode=True) metadata is handled, as
before (v1_0's N=128 seqlen fold is not undone). The arch is resolved on
torch.cuda.current_device(), not the metadata tensors' device.

Test (op_tests/test_mla_shape_support.py): on the GPU the update leaves
the planner's work_info request/KV columns unchanged when no token is
added. It fails on the previous rule.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] Group mla_reduce_v1_supports with the compile_ops shape-query ops

mla_reduce_v1_supports is a pybind op bound through compile_ops, but in
NONE_WRAPPED_OP it sat after the ctypes.CDLL-bound mla_decode_asm_query.
Drop mla_decode_asm_query from the list: it is a plain Python function,
not a compile_ops op, so its entry was never consulted. The compile_ops
shape-query entries now form one group.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [MLA] Shape query: take cp_world_size, model HK and the gfx1250 page64 rule

Review follow-ups on get_mla_decode_shape_support, so the query answers what
mla_decode_fwd does for the same inputs:

- New cp_world_size keyword (default 1, ValueError below 1). The planner used
  to get 2 if cp_round_robin else 1, while mla_decode_fwd passes the real
  value, so CP > 1 without g_kv_indptr showed the gfx1250 FlyDSL PS1 route
  that the launch rejects. The PS1 asm kernel lookup now keys cprr on
  cp_world_size > 1 as mla_ps1_fp8_asm_fwd does; stage-1 asm keeps keying it
  on g_kv_indptr (cp_round_robin).
- HK: #6455 made the route real (aiter.hk_mla_v32_decode_fwd), so it is no
  longer reported as undefined. It answers None, or False when the launch
  would be wrong: return_lse (no final LSE for unsplit work), causal=False at
  max_seqlen_qo > 1 (always masked) and round-robin CP (no g_kv_indptr). The
  reasons note that HK ignores q_scale/kv_scale.
- gfx1250 stage-1 asm needs page_size == 64. The rule moves into
  mla_asm_decode_remap_gfx1250 (NoKernel, so the dispatch keeps its own
  message), and mla_decode_asm_query takes page_size.
- gfx1250 A0: stage-1 asm routes answer False (require_gfx1250_asm raises).
- The gfx1250 LSE reason says LSE is valid only for gqa64 or kv_split > 1.
- Docstrings: only kv_layout="token_major" is described; fp8 Q is assumed
  to come with scales; persistent=True is the persistent route, and gfx950
  bf16 16-head qlen-1 decode can still downgrade at large batch.

Tests (op_tests/test_mla_shape_support.py, host-only): query vs the head
plan mla_decode_fwd actually requests, captured before launch, at
cp_world_size 1/4 with and without round-robin; PS1 cprr kernel choice;
HK verdicts; gfx1250 page size. Each new test fails when its fix is
reverted.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] gfx1250 stage 1: reject round-robin CP instead of running unmasked

mla_decode_gfx1250_dispatch takes no g_kv_indptr, so a round-robin CP call
ran without the global-position mask and returned wrong results. It now
fails with the same check mla_asm_decode_config (and so the shape query)
already applies.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] test_mla_persistent: add --metadata_mode to cover planner v1_1

-nps selects fast_mode=False, intra_batch_mode=True (v1_0), and nothing ran
v1_1 (both flags off). -mm/--metadata_mode {fast,v1_0,v1_1} picks the
planner for get_mla_metadata_info_v1, get_mla_metadata_v1 and the
mla_decode_fwd calls; the default stays v1_0 with -nps, else fast.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] Add a numerical regression for decode_update_mla_metadata_v1

The function's block in test_mla_persistent.py is commented out, so nothing
checked the metadata it rewrites. The new test plans get_mla_metadata_v1
(fast_mode) for 4 requests with different KV lengths (1100, 37, 530, 2049),
moves them to new lengths with decode_update_mla_metadata_v1 (+1 each, and
+1/0/-1/0 through num_reject_tokens), and decodes with the updated plan:

- fp8/fp8 and bf16/bf16 at 16, 32, 48 (folded on gfx950 fp8), 64 and 128
  heads; planned max_seqlen_qo 1 and 2 (the qlen > 1 -> 1 rewrite); the
  parallel and the serial (AITER_MLA_META_USE_PARALLEL=0) planner fill;
- the updated works must tile every (pseudo-)request's new KV range, and at
  least one request must span several splits;
- O and LSE are compared with a fresh plan at the new lengths and with an
  fp32 torch reference.

On MI355X: 46 passed, 28 skipped (shapes the query does not report as
supported, serial fill on folded or qlen > 1 plans, and qlen-2 plans that
split per token), 6 xfailed. The xfails are fp8 with 32 heads: the
persistent qh32 qseqlen1 lse kernel leaves the final LSE of a request whose
work is not split unwritten, with fresh metadata as well, and on main too.
O is still checked for them. Restoring main's hand-written fold rule fails
30 of the cases.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] Cut the host cost of the decode gate and of get_mla_metadata_info_v1

An eager-mode A/B against main on MI355X (same image, same GPU, ABBA order)
showed what moving the gate into C++ cost on the host: mla_decode_fwd issued
about 8.7 us more per call (46.6 -> 55.3 us, fp8 16 heads, batch 32) and
get_mla_metadata_info_v1 went from 0.6 to 5.9 us. Graph replay, capture,
GPU kernel time and buffer sizes were unchanged. Most of the cost was five
env-flag reads parsed with a regex, two device-arch lookups and three
separate cache lookups per call.

- env_flag_atoi memoises the parse per raw value. The variable is still
  read on every call, so changing it at run time still takes effect.
- mla_decode_fwd's persistent gate is one call, _mla_decode_launch_plan. It
  reads the four flags as raw strings, and one cache keyed on them and on the
  device returns both the head plan and the split bound.
- get_mla_metadata_info_v1 caches its result on its arguments, the arch and
  the two env flags it depends on.
- The occupancy cache is keyed on torch dtypes rather than converted ids.

The issue time is now 47.9 us against main's 46.1. The rest is the four
env reads that main skips when it short-circuits. get_mla_metadata_info_v1
takes 1.2 us. The CP query-vs-launch test now captures
_mla_decode_launch_plan.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] test_mla_persistent: take the reference's head fold from the planner

torch_mla_extend_split_kv kept its own copy of the v1_2 head-fold rule to
undo the planner's 16-head pseudo-batches. Nothing else used that copy, and
it only matched fast_mode plans with 32..128 heads. With -mm v1_1, and with
the >128-head folds (144 heads, fold 9) that mla_decode_fwd now runs, the
reference read work_info batch ids it had not folded and raised IndexError.
That happened after the O check had already run, so the split-level
comparison was lost.

The reference now asks aiter.get_mla_decode_shape_support for the fold.
It passes the dtypes and the planner mode (fast_mode/intra_batch_mode) the
metadata was built with, which test_mla threads through. The 3-buffer
wrapper plans its byte KV as fp8, as mla_decode_fwd does. On MI355X the
fold the query reports matches the work_info batch ids for every
(dtype, heads, qlen, planner) combination probed.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] Shape query: report opus CP launches that abort

opus_mla_decode_fwd raises when cp_world_size > 1 and Q is not fp8, or when
it gets no g_kv_indptr. The query answered None (no availability table) for
both, the same as for a launch that runs. It now answers False with the
launcher's reason. The CP query-vs-launch test also asserts that CP without
round-robin on gfx1250 is unsupported, not only that it is routed to ASM.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [MLA] test_mla_shape_support: pin #6563's FlyDSL PS1 rules

#6563 widened the gfx1250 FlyDSL PS1 route (32/64 heads at qlen <= 4 with
heads x qlen <= 128, bf16/bf16 on the FlyDSL JIT kernel, fp8 asm code
objects only) and narrowed 16 heads to qlen <= 4. On rebase those rules
were ported into mla_decode_head_plan_v1_2 and mla_decode_backend; these
asserts check the query reports them.

Signed-off-by: Oxana Korzh <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Signed-off-by: Oxana Korzh <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants