Repository navigation
[HIP] [JIT] [Feature] MLA decode: add get_mla_decode_shape_support, backed by shared C++ head-fold/backend rules - #6107
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
24e4513 to
72871e7
Compare
AITER's persistent MLA decode folds a head count it does not run natively into num_heads/16 pseudo-batches of 16 heads, and each pseudo-batch reads its request's KV range again. DCP gathers counts such as 48, 80 and 112 that fold on gfx950 fp8, so the decode reads the KV cache 3, 5 or 7 times. Padding the query to 64, 96 or 128 heads reads it once; on MI355X the MLA decode kernel is 2.04x, 1.90x and 2.66x faster. Add VLLM_ROCM_AITER_MLA_PAD_TO_NATIVE_SHAPE (off|auto|force, default off). With auto or force, the metadata builder resolves one padded head count per run at init: the smallest multiple of 16 from the aligned count up that aiter.get_mla_decode_shape_support (ROCm/aiter#6107) reports native and supported at every (qlen, return_lse, causal) the non-cprr persistent decode can reach. auto caps the pad at twice the aligned count unless the aligned count has no kernel; force drops the cap. If the aligned count has no kernel and no target fits, init raises with AITER's reasons. The persistent schedule is planned at that count, carried on the decode metadata, and the backend pads q and unpads o and lse with it. cprr keeps its own count. This replaces the AITER source greps of the earlier version of this change with the AITER query. auto and force need an AITER that has get_mla_decode_shape_support and fail at init otherwise; off never calls it, so the current AITER pin keeps working. Size the shared persistent buffers for the elementwise max over every head count and qlen planned into them. With cprr on, the plain decode plans its own count into the cprr-sized buffers, and a folded count can need more reduce entries than cprr's; the cprr-only sizing let it write past reduce_indptr and reduce_final_map. This applies with off as well. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Thanks for the detailed baseline/head accuracy tables, known-failure analysis and test commands. Please complete the reproducibility/performance evidence for this host-path change:
Please retain the existing accuracy comparisons and include any failures/skips in the reproducible results. |
|
Following up on my earlier review comment, please extend the persistent MLA regression coverage. Every valid case entering Please run the full existing default matrix on the current head, and cover the non-default paths separately:
The posted 72-configuration run at There also appears to be a concrete |
72871e7 to
953af4b
Compare
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]>
…_cases.h Move the _AITER_MLA_REDUCE_FOR_EACH_ROW support matrix (ROCm#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]>
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]>
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 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]>
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]>
…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]>
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]>
…4 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: ROCm#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_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]>
-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]>
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]>
…fo_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]>
…anner 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]>
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]>
ROCm#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]>
834eb48 to
d89e7bc
Compare
@shengnxu Thanks for the review. I've updated the the and run additional tests on GPU. Testing part is the PR description is updated with new numbers. |
There was a problem hiding this comment.
Approving after an A/B of op_tests/test_mla_persistent.py default matrix, base e78e5a49f0 vs head d89e7bcdfa.
Setup: MI355X (gfx950), image vllm/vllm-openai-rocm@sha256:bdf0a71d472fe1ea32ec02f1cb74146c80036176f985c3cd8035b455bde1ff54, image's aiter uninstalled, each tree with its own AITER_JIT_DIR, GPU_ARCHS=gfx950, AITER_MLA_DECODE_PERSISTENT_MAX_BATCH=0. Each tree ran its own copy of the test script. 3 runs per tree on different GPUs (GPUs swapped between runs). Default matrix: nhead,qlen in 16,1 / 16,2 / 16,4 / 48,1 / 128,2 x Q/KV in {bf16,fp8} x 8 ctx x 8 batch = 960 configs (the fp8-Q/bf16-KV combination is unsupported and skipped by the script).
Accuracy: no regression.
- bf16/bf16: 320/320 configs have
decode:err == 0in all runs on both trees. err >= 0.05: 134-136 configs on base, 135-136 on head per run. All are fp8-KV configs (mostly ctx 21/64) and fail on base as well.- 3 configs flip across the 0.05 line only in one direction or the other (16,1 fp8/fp8 ctx64 b1; 16,2 fp8/fp8 ctx21 b5; 48,1 fp8/fp8 ctx64 b1). err varies 0.03-0.057 between repeat runs of the same tree, i.e. fp8 non-determinism, as already noted in the description.
Performance: no regression attributable to this PR. Geomean of mla_decode_fwd GPU time over 64 configs per row, min of 3 runs per config, speedup = base/head (>1 = head faster):
| nhead,qlen | Q/KV | base us | head us | speedup |
|---|---|---|---|---|
| 16,1 | bf16/bf16 | 28.96 | 29.44 | 0.984 |
| 16,1 | bf16/fp8 | 32.15 | 32.03 | 1.004 |
| 16,1 | fp8/fp8 | 21.16 | 20.78 | 1.018 |
| 16,2 | bf16/bf16 | 30.96 | 30.46 | 1.017 |
| 16,2 | bf16/fp8 | 33.39 | 33.19 | 1.006 |
| 16,2 | fp8/fp8 | 23.34 | 24.21 | 0.964 |
| 16,4 | bf16/bf16 | 32.75 | 32.85 | 0.997 |
| 16,4 | bf16/fp8 | 36.29 | 35.37 | 1.026 |
| 16,4 | fp8/fp8 | 26.56 | 26.50 | 1.002 |
| 48,1 | bf16/bf16 | 32.19 | 31.49 | 1.022 |
| 48,1 | bf16/fp8 | 68.45 | 68.38 | 1.001 |
| 48,1 | fp8/fp8 | 46.35 | 44.07 | 1.052 |
| 128,2 | bf16/bf16 | 59.58 | 59.48 | 1.002 |
| 128,2 | bf16/fp8 | 142.38 | 136.09 | 1.046 |
| 128,2 | fp8/fp8 | 45.10 | 45.25 | 0.997 |
Overall geomean 1.009. Some individual configs differ by more than 10% in both directions (e.g. 48,1 fp8/fp8 small ctx ~+15-19%, 16,2 fp8/fp8 small ctx ~-8-10%). These are not tree-dependent: rocprofv3 shows the same stage-1 / reduce / metadata kernels in both trees, and same-GPU ABBA runs show the same tree flipping between two timing modes from process to process (e.g. 48,1 fp8/fp8 ctx21 b16: base 20.2 / 23.8 us, head 20.3 / 24.0 us; 128,2 bf16/fp8 ctx64 b3: both trees 35.1-35.8 or 39.4-39.6 us).
Not covered by this run: -nps, -mm v1_1, -lse, --varlen, 3BUFFER / DS32_OPUS layouts, host-side overhead, metadata/workspace size and CUDA-graph replay/capture. The earlier review requests for those remain with the author's data.
Retracting my approval: the A/B run only covered the default test_mla_persistent matrix (no -nps/-mm v1_1/-lse/--varlen, host overhead, metadata size or graph checks).
AITER's persistent MLA decode folds a head count it does not run natively into num_heads/16 pseudo-batches of 16 heads, and each pseudo-batch reads its request's KV range again. DCP gathers counts such as 48, 80 and 112 that fold on gfx950 fp8, so the decode reads the KV cache 3, 5 or 7 times. Padding the query to 64, 96 or 128 heads reads it once; on MI355X the MLA decode kernel is 2.04x, 1.90x and 2.66x faster. Add VLLM_ROCM_AITER_MLA_PAD_TO_NATIVE_SHAPE (off|auto|force, default off). With auto or force, the metadata builder resolves one padded head count per run at init: the smallest multiple of 16 from the aligned count up that aiter.get_mla_decode_shape_support (ROCm/aiter#6107) reports native and supported at every shape the plain (non-cprr) persistent decode launches: qlen 1 with LSE under DCP, qlen 1..K without DCP, plus non-causal qlen 1..K when the builder can see non-causal blocks. auto pads at most 2x and force up to 128 heads. The aligned count is kept when nothing fits or when it is 16 or fewer. The plain persistent schedule is planned at the padded count, the shared buffers are sized for the larger of it and cprr's count, and the backend pads q and unpads o and lse with it. cprr keeps its own count. The query merged in ROCm/aiter#6107 (bf38b9153a), after AITER v0.1.26, the version vLLM pins. auto and force raise at init if AITER lacks get_mla_decode_shape_support. off never calls it and leaves the backend as it is, so the current AITER pin keeps working. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
AITER's persistent MLA decode folds a head count it does not run natively into num_heads/16 pseudo-batches of 16 heads, and each pseudo-batch reads its request's KV range again. DCP gathers counts such as 48, 80 and 112 that fold on gfx950 fp8, so the decode reads the KV cache 3, 5 or 7 times. Padding the query to 64, 96 or 128 heads reads it once; on MI355X with AITER v0.1.27 the MLA decode kernel is 2.43x, 2.00x and 3.16x faster (fp8, batch 52, 16K KV). Add VLLM_ROCM_AITER_MLA_PAD_TO_NATIVE_SHAPE (auto|off|force, default auto). With auto or force, the metadata builder resolves one padded head count per run at init: the smallest multiple of 16 from the aligned count up that aiter.get_mla_decode_shape_support reports native and supported at every shape the plain (non-cprr) persistent decode launches: qlen 1 with LSE under DCP, qlen 1..K without DCP, plus non-causal qlen 1..K when the builder can see non-causal blocks. auto pads at most 2x and force up to 128 heads. The aligned count is kept when nothing fits or when it is 16 or fewer. The plain persistent schedule is planned at the padded count, the persistent buffers are sized for both it and the unpadded (or cprr) count at every decode qlen, and the backend pads q and unpads o and lse with it. cprr keeps its own count. The fp8 non-causal qlen-2 guard checks the count the batch launches at, so a padded 64/96/128 block is no longer refused for its unpadded 48/80/112. The query is in AITER v0.1.27 (ROCm/aiter#6107), which vLLM pins. With an older AITER, auto logs once and keeps the aligned count; force raises at init. off never calls the query. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Replace the reduce_instances/nh12_hd128.cu source-tree probe with aiter.ops.attention.mla_reduce_v1_supports - A stale JIT-cached or prebuilt AITER no longer passes as having the 12-head reduce just because the source does - An AITER without the query (older than ROCm/aiter#6107, e.g. the pinned one) keeps padding to 16 heads - Test: force the padded 12-head path in one subtest so CI covers it whichever AITER is installed
AITER's persistent MLA decode folds a head count it does not run natively into num_heads/16 pseudo-batches of 16 heads, and each pseudo-batch reads its request's KV range again. DCP gathers counts such as 48, 80 and 112 that fold on gfx950 fp8, so the decode reads the KV cache 3, 5 or 7 times. Padding the query to 64, 96 or 128 heads reads it once; on MI355X with AITER v0.1.27 the MLA decode kernel is 2.43x, 2.00x and 3.16x faster (fp8, batch 52, 16K KV). The metadata builder resolves one padded head count per run at init: the smallest multiple of 16, from the aligned count up to twice it (at most 128), that aiter.get_mla_decode_shape_support reports native and supported at every shape the plain (non-cprr) persistent decode launches: qlen 1 with LSE under DCP, qlen 1..K without DCP, plus non-causal qlen 1..K when the builder can see non-causal blocks. The aligned count is kept when nothing fits or when it is 16 or fewer; a head count whose query raises is treated as unsupported. The query is in AITER v0.1.27 and later (ROCm/aiter#6107). The plain persistent schedule is planned at the padded count, the persistent buffers are sized for both it and the unpadded (or cprr) count at every decode qlen, and the backend pads q and unpads o and lse with it. cprr keeps its own count. The fp8 non-causal qlen-2 guard checks the count the batch launches at, so a padded 64/96/128 block is no longer refused for its unpadded 48/80/112. Signed-off-by: Oxana Korzh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…default launch - Add _mla_decode_launch_schedule: decode and target verify take launch modes and splits from one place - Opt-in: pass the planned fast_mode and intra_batch_mode, and None splits under SGLANG_AITER_MLA_AUTO_KV_SPLITS - fast_mode is passed only when aiter's mla_decode_fwd accepts it (ROCm/aiter#6107; the gfx950-rocm720 pin lacks it) - Opt-in off: module intra_batch_mode, no fast_mode, verify keeps forward_metadata.num_kv_splits (-1 under auto) - Tests cover the opt-in schedule under both split modes, an aiter without fast_mode, and the unchanged default launch
…utable persist flag - Split _asm_cprr_verify_requested (asm verify backend, DCP, fp8 KV) out of _asm_cprr_verify_enabled - _init_cprr_verify asks aiter on the request, so the persist block that runs later cannot leave it stale - Pass kv_lora_rank to _init_cprr_verify instead of the whole ModelConfig - Narrow the get_mla_decode_shape_support catch to its documented TypeError / ValueError; other errors raise - State when _MLA_ASM_CPRR_NATIVE_QLENS loses its query lengths (sglang requiring ROCm/aiter#6107) - Test the ask decision with persist off, the narrowed fallback, and that a broken aiter raises
…th comments - Turn the _is_gfx950 and is_zero_padded_h12_fp8_mla docstrings into comments above the def - Drop the _fp8_q_asm_mla_skip_reason docstring - State when to drop the fast_mode probe: once every pinned AITER includes ROCm/aiter#6107
Summary
Persistent MLA decode decides in several places whether a head count is native or gets folded into
N/16pseudo-batches of 16 heads, and those copies have drifted apart. This PR moves that rule, themla_reduce_v1(heads, head_dim) table and the asm-kernel remap/lookup into shared host-side C++ helpers. The planners, the reducer router, asm stage 1,mla_decode_fwd's fold/backend gate, the dense path ofget_mla_metadata_info_v1anddecode_update_mla_metadata_v1all use them.It adds one public query,
aiter.get_mla_decode_shape_support(...), which tells a caller before launch whether a shape is native, how far it folds, which backend runs it and whether a kernel exists. It also fixes two latent bugs off the vLLM path:get_mla_metadata_info_v1under-sized its buffers in some modes, so the planner wrote past their end (commit A5), anddecode_update_mla_metadata_v1applied folds the planner never made (commit A6).No kernel code changes. On gfx950 the
fast_modepaths vLLM uses (fp8/fp8, and bf16/bf16 for the default KV-cache dtype) give byte-identical metadata and decode output on the captured grid (batch 1-2, short KV). The one exception is bf16 with 10 heads, which used to assert inget_mla_metadata_info_v1and is now sized. The sparse sizing path, and a floor that keeps dense buffers from shrinking, still use the old Python rule (follow-up).The first consumer is vLLM #54899, which today greps AITER source files to make this decision.
Motivation
N % 16 == 0, it emitsN/16pseudo-batches of 16 heads per request. Each pseudo-batch reads the request's whole KV range. vLLM decode-context-parallel (DCP) multiplies the per-rank head count by the DCP size. For example, a 96-head model at TP8 with DCP4 gathers 48 heads, which folds 3x. Padding Q to a native head count with replicated heads reads the KV cache once (table below).get_mla_metadata_info_v1buffers, goes into everyget_mla_metadata_v1build and sets the Q pad / O slice, all frozen into graphs. It cannot be found by trial. A planner or reducer miss is anAITER_CHECKthat aborts the process (SIGABRT); an asm miss raisesRuntimeError, but only at the first decode launch, after the buffers are sized and possibly inside graph capture. The answer also depends on the AITER version: since v0.1.21 ([HIP] FIX MLA the nhead fold error for cp round robin #4964), 96 heads is native on gfx950 fp8 atmax_seqlen_qo <= 6, so padding 96 to 128 now costs 2-7% (measured on 0.1.21.post1) instead of saving time.natively_supportedinitializer inv1_2_device.cuh, theMLA_REDUCE_CASE_EFlist inreduce.cu, andhsa/<arch>/mla/mla_asm.csv(whoseGqacolumn is a post-remap tile id, not the model head count, and which can disagree with the arch-filtered build).mla_decode_fwd's Python gate, theget_mla_metadata_info_v1sizing mirror anddecode_update_mla_metadata_v1(plusget_mla_decode_fwd_occupancy, which mirrorsmla_metadata_cluster_multiplier).get_gfx()where the planner usesget_gpu_arch(), folds onlyrange(32, 129, 16), asserts above 128 heads and handles fp16 differently.decode_update_mla_metadata_v1is a latent silent-correctness bug (nothing in AITER or vLLM main calls it). Its native set is a stale subset of the planner's, so it can apply a fold the planner did not make and rewrite the request and KV-range columns of the plannedwork_infowithout raising. gfx950 fp8 with 64 heads is one such shape; the new regression test covers it.What padding saves downstream (MI355X, gfx950, fp8/fp8). The table compares the kernel time of
mla_decode_fwdat the folded head count with the kernel time at the native head count it would be padded to. This is the padding #54899 would choose with this query. It was measured standalone, not on this branch.Benchmark setup
mla_decode_fwdthat mirrors vLLM's DCP decode call. Batch 52, qlen 1, 16384 KV tokens per request (one DCP-8 rank's shard of a 131072-token context),return_lse=True, persistent metadata.rocprofv3. Times are kernel time only; they exclude the Q replicate and O slice.FETCH_SIZE) only for 96 heads on 0.1.19, at 6.05x.Changes
Commits:
csrc/include/mla_decode_shape.h. The v1_0/v1_1/v1_2 head-count planning (native set, fold,hk_mtp_experimental, the gfx1250 FlyDSL PS1 route, acceptance,kPackedQoLenPerWg) moves unchanged intomla_decode_head_plan_v1_{0,1,2}(), together withmla_metadata_cluster_multiplier. The planners call the new functions; AITER_CHECK messages are unchanged.csrc/include/mla_reduce_cases.h. The 24 reducer(heads, head_dim)cases become one X-macro that feeds bothMLA_REDUCE_ROUTERand the newmla_reduce_v1_supports(heads, head_dim).asm_mla.cu): the stage 1 and gfx1250 remap and kernel lookup move into a non-throwingmla_asm_decode_config()that returnsOk,RemapReject,NoKernelorArchNotBuilt. On a miss, dispatch raises the sameAITER_CHECKtext as before. The stage 1 "cannot find suitable kernel" check, which could never fire, is removed.get_mla_decode_head_plan_v1andmla_reduce_v1_supports; new C entry pointsmla_decode_asm_queryandmla_ps1_fp8_asm_queryinmodule_mla_asm; new C++mla_decode_backend()holding the former Python predicates in priority order FlyDSL PS1 (its 96/128-head PS1 FP8 asm sub-route,MlaBackend.PS1_FP8_ASM, first, unlessAITER_MLA_DECODE_PS1_ASM=0) > opus > HK > asm; new Pythonget_mla_decode_shape_supportand its result types. The backend rule takes two inputs [ASM] [HIP] [FlyDSL] Add pin gpr(nhead96/128) and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 #5844 added:cp_round_robin(g_kv_indptr is not None, which lets FlyDSL PS1 run with round-robin CP) anduse_ps1_asm.mla_decode_fwdtakes its fold and backend from the C++ plan, and gainsfast_mode=True.get_mla_decode_fwd_occupancy/_max_splitscall the new pybindmla_metadata_cluster_multiplier_v1.get_mla_metadata_info_v1(dense path) sizes its buffers from the C++ head plan, taking the max of the new and old size so no buffer shrinks. This fixes out-of-bounds metadata writes: forfast_mode=Falsefolds, fp16 at qlen 5-7, andfast_modewithintra_batch_mode, the old sizing was smaller than what the planner writes. A sentinel-guarded sweep found 1,725 overflowing cases with the base sizing and 0 with A5's (none on the fp8/fp8fast_modepath; run on the pre-review A5, and sizes have only grown since).decode_update_mla_metadata_v1takes its fold from the planner instead of a private copy, with a regression test.mla_decode_head_plan_v1_2(A1), thecfg_mla_dsllookup intomla_ps1_fp8_asm_config()(A3), and the round-robin CP gate and PS1 FP8 asm route intomla_decode_backend(A4).decode_update_mla_metadata_v1picks up the 96-head clause through the planner (A6).Design notes
module_mla_asmknows which asm kernels were built (GPU_ARCHS-filtered table).ctypes.CDLLformla_decode_asm_query: thecompile_opsctypes path always passes the current HIP stream, so it needs a device. The query takes a NULL stream and never launches, soarch=works without a GPU. It reusesbuild_ctypes_module, factored out of_ctypes_call.NONE_WRAPPED_OPfor the 3 scalar pybinds: otherwisetorch_compile_guardwraps them as custom ops and allocates a dummy device tensor per call.hsa/,optCompilerConfig.jsonor CI changes; host code only (auto-tags [HIP], [JIT]). The FlyDSL PS1 (JIT and PS1 FP8 asm), opus, HK and asm routes are selected, not changed.Public API.
get_mla_decode_shape_support,MlaDecodeShapeSupport,MlaBackend,MlaAsmStatus.aiter.ops.attentionhas no__all__and is star-imported, soget_mla_decode_head_plan_v1,mla_reduce_v1_supports,mla_metadata_cluster_multiplier_v1,mla_decode_asm_query,mla_ps1_fp8_asm_queryandenv_flag_atoialso becomeaiter.*attributes. I can underscore-prefix them if maintainers prefer.mla_decode_fwd(fast_mode=), andmla_version=,q_rope_dtype=,kv_rope_dtype=onget_mla_decode_fwd_occupancy/_max_splits.Build impact. No new JIT module. The new symbols go into
module_mla_metadata(3 pybinds) andmodule_mla_asm(2 C entry points).module_mla_reduce,module_pa_metadataandmodule_ps_metadataalso recompile from shared sources, with no new symbols. JIT checks only that a.soexists, so amodule_mla_metadata.socached from before this PR makesmla_decode_fwdandget_mla_metadata_info_v1fail withAttributeError: rebuild withAITER_REBUILD=1.Usage
(qlen, return_lse, causal, cp_round_robin)combination it can launch: nativeness is not monotone in qlen (96 heads is native at qlen <= 6 and folds 6x at qlen 7-8). vLLM will gate this on the AITER release that contains this PR.num_heads_k(must be 1),v_head_dim,return_lse,causal,persistent,cp_round_robin,page_size,fast_mode,intra_batch_mode.arch=answers for that arch without a device (the JIT modules must still be built);enable_experimental=andflydsl_ps1=override the env flags. Results are cached (get_mla_decode_shape_support.cache_clear()).natively_supportedis the planner's native set.nativealso requiresfold_factor == 1andseqlen_fold == 1(no head fold, and no v1_0 qlen fold of 128 heads), so the KV cache is read once.planner_acceptsis False whereget_mla_metadata_v1would abort.arch,enable_experimentalandflydsl_ps1echo the values used.supportedisTrue,False, orNonewhen it cannot be determined: the opus and FlyDSL PS1 JIT backends, or a failed asm query (asm_status=UNKNOWN). Theps1_fp8_asmbackend is checked against its code-object table (mla_ps1_fp8_asm_query), so it answersTrueorFalse. A FlyDSL PS1 or PS1 FP8 asm route on a planner that folds the heads (fast_mode=False) isFalse, because those kernels read unfolded heads.reasonsexplains every "no".TypeError(a non-int or bool count, or a non-torch.dtype) orValueError.Performance
N/A: no kernel change.
mla_decode_fwd's gate now parses 4 env vars (the same 4 flags main's gate reads), callstorch.cuda.current_device()and does 2 cached lookups. Whennum_kv_splitsis None,get_mla_decode_fwd_max_splitsadds one more of each, and the old code called that function too. This runs in eager mode and at graph capture, not on graph replay. Its cost was not timed.fast_mode=False, fp16 qlen 5-7, andfast_modewithintra_batch_mode, the metadata buffers grow to the size the planner already writes, and so doesmla_decode_fwd's fp32 logits scratch (Breaking Change 2).Testing
Setup
d89e7bcdfaagainst maine78e5a49f0. Both trees are clean.2.12.0+rocm10.0.0, HIP 7.15.26333, ROCm 10.0.0.vllm/vllm-openai-rocm@sha256:bdf0a71d472fe1ea32ec02f1cb74146c80036176f985c3cd8035b455bde1ff54(tagnightly-rocm100-36768d1bfd39094681cdbc8cb37d4b31c0729c89)./work.AITER_JIT_DIR.GPU_ARCHS=gfx950,AITER_MLA_DECODE_PERSISTENT_MAX_BATCH=0.test_mla_persistent.pymatrixThe matrix runs 31 invocations, 2,587 configs per tree, on GPU 0 (main first, then head). It covers:
-nps(v1_0), v1_0 with LSE checks, and-mm v1_1;-lse, causal and non-causal, and varlen;Results per tree:
e78e5a49f0d89e7bcdfaThere are 236 status changes between the trees:
IndexError; head raises "no kernel"The 2 pass → fail configs are fp8 kernel non-determinism, not a regression:
What remains on head:
IndexErroron v1_0 nh128 ql2. The same keys error on main.Accuracy:
Known on both trees:
test_mla.pyas well;New and updated unit tests (head)
test_mla_shape_support.py(gfx950 GPU)GPU_ARCHS=gfx942;gfx950;gfx1250test_mla_decode_update_metadata.pylse_psbug that leaves the LSE of unsplit work unwritten. It reproduces on main.Existing tests, head vs main
test_mla_reduce.pypytest test_mla_decode_gate.py test_ps_metadata_sizing.pytest_metadata.pytest_pa_ps.pytest_mla_sparse.py, seeded (pass/warn/fail)test_mla_v40_persistent.py, experimentaltest_mla_persistent.py --softmax-underflow, CP=2 +-lseand non-CPBehaviour capture and OOB sweep
Behaviour capture, head vs main:
Sentinel / OOB sweep, 6,144 keys per tree:
Host, graph and memory bench
The bench compares head against main in ABBA order. It covers 264 cases: fp8/bf16 × 16/48/128 heads × qlen 1/4 × batch 1/128 × KV 8192 × fast/fast_intra/v1_0/v1_1 × lse 0/1 × causal 1/0. Values are head/main geomeans.
mla_decode_fwdeager CPUget_mla_metadata_info_v1: 0.61–0.72 µs → about 1.25 µs per call.get_mla_metadata_v1: CPU 1.000, GPU 0.996.max_split_per_batch=-1.Not covered
gfx1250: no hardware. Only host-side query/launch agreement was checked.
gfx942: PR CI only. CI on
d89e7bcdfais green, including the MI300X shards.fast_intra: no O/LSE accuracy check.LSE: not checked for bf16-Q/fp8-KV,
-nps, varlen, or page > 1.Page size > 1: accuracy is broken on main as well.
HK experimental N=144 msq=4: memory faults, the same fault class as main's existing faults at N=48/80/112. The query reports it unsupported.
Unit tests added/updated:
test_mla_shape_support.py,test_mla_decode_update_metadata.py,test_mla_persistent.py -mm.Same-environment A/B vs main: matrix, capture, OOB sweep, host/graph/memory bench.
MI355X (gfx950) GPU.
Breaking Changes
No public function, keyword or pybind is removed or renamed. External callers could notice these behaviour changes:
atoi(the C++ planner reads the first two this way;AITER_MLA_USE_OPUSis Python-only and now uses the same parse).AITER_ENABLE_EXPERIMENTAL: "1.0" and "1abc" now turn it on, and "0_1" turns it off. This affects everything gated byis_experimental_enabled(), including the JIT module build.AITER_MLA_DECODE_PS1_FLYDSLandAITER_MLA_USE_OPUSused to require exactly "1"; "2", "01" and " 1" now also enable them.AITER_MLA_DECODE_PS1_ASM(new in main with [ASM] [HIP] [FlyDSL] Add pin gpr(nhead96/128) and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 #5844, default "1"): main enables it only for exactly "1"; the branch parses it with atoi and the same default, so "2" and " 1" also enable it, and "1abc" does too.0or1.get_mla_metadata_info_v1(all paths, sparse included),get_mla_decode_fwd_occupancyandget_mla_decode_fwd_max_splitsnow need a HIP device and build or loadmodule_mla_metadataon first use. Before, they were pure Python and honouredGPU_ARCHS; now the arch comes from the current device (the CU count still comes fromget_cu_num()). Migration: tooling that sized buffers on a GPU-less host must now run on a device.fast_mode=Falsefolds (e.g. bf16, 112 heads), up to 2x for fp16 at qlen 5-7, and forfast_modewithintra_batch_modeup to 32x per buffer at batch 1 in the captured grid (num_kv_splits=16, 256 CUs; 13x in total metadata bytes).mla_decode_fwd's fp32 logits scratch is sized fromreduce_partial_mapand grows with it.num_head_qo % 4assert now fires only where the planner rejects the shape.decode_update_mla_metadata_v1no longer folds shapes the planner treats as native: gfx950 fp8 with 32 heads at qlen != 4 and with 64 heads; gfx950 bf16/fp16 at every multiple of 16 above 16; gfx942 fp8 with 64 heads at qlen 1; the HK experimental shapes; gfx1250 fp8 with 96 heads andAITER_MLA_DECODE_PS1_FLYDSLon, which [ASM] [HIP] [FlyDSL] Add pin gpr(nhead96/128) and round-robin DCP to persistent MLA PS1 FP8 decode for GFX1250 #5844 made native in the planner but not in this copy. It also assertsmax_seqlen_qo >= 1. Migration: pass the samemax_seqlen_qoand dtypes that the metadata was built with.mla_decode_fwd:N % 16 == 0(e.g. 144) now folds and runs.RuntimeError("cannot get heuristic kernel"), orAttributeErroron the HK route, instead ofAssertionError.fast_mode=Falseshould passfast_mode=Falsehere too.get_mla_decode_fwd_occupancy/_max_splits: with default arguments the results are the same, apart from the device requirement in item 2. Both fp8 variants (e4m3fn and e4m3fnuz) count as fp8.causalis now a bool, so any nonzero value selects the causal kernel. Before, a value other than 0 or 1 was a kernel miss.