Skip to content

[HIP] [OPUS] [JIT] [MLA] gfx950 fp8 flat-row MTP decode: host planner, stage 1 and bf16 merge - #7415

Merged
amd-ruitang3 merged 12 commits into
ROCm:mainfrom
nehmathe2:nm/mla-opus-flat-mtp-decode
Dec 2, 2026
Merged

amd-ruitang3 merged 12 commits into
ROCm:mainfrom
nehmathe2:nm/mla-opus-flat-mtp-decode

Conversation

@nehmathe2

@nehmathe2 nehmathe2 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds OpusMlaFlatDecode, an opt-in fp8 MLA decode path for MTP on gfx950 (MI355X). It has three parts: a CPU planner, a stage-1 kernel and a merge of bf16 partials. Rows are flat (token * H + head), so a request's query tokens and heads together fill 128-row chunks at any head count, and the requests of one call may have different query lengths. The code is part of the existing module_mla_decode_opus, which is now built with --amdgpu-mfma-vgpr-form. No existing decode path, planner or default changes.

Motivation

MTP decode sends several query tokens per request. At some head counts the existing gfx950 kernels pack those rows poorly: 96 heads per rank under 8-way round-robin context parallelism (CP), and 12 heads per rank without CP. At query length 6 and batch 4 or more, with 8k and 131k tokens of context per request, this path is:

  • 1.06-1.81x faster than the upstream opus path (AITER_MLA_USE_OPUS=1) at 96 heads with CP, and 1.09-1.23x faster at 12 heads without CP;
  • 1.22-2.12x faster than the default mla_decode_fwd path.

At batch 1-2 it is 1.05-1.36x the speed of upstream opus at 96 heads and 0.80-1.26x at 12 heads. The gain is not specific to that query length: at 96 heads with CP and 2-8 query tokens it is 1.00-3.54x the speed of upstream opus from batch 8 and 0.97-2.90x at batch 1-4. "When to use it" below lists the shapes that should stay on mla_decode_fwd.

This is the decode path we run in deployment for these shapes. The first revision of this PR (d10965ef) compiled to the same device code as the deployed build: stage 1 (causal and non-causal) and both merges were compared instruction by instruction, with the same register, scratch and LDS usage. With every workgroup active, its planner produced the same plans as the deployed one on 4000 random batches, and out / LSE were bit-identical on the shapes benchmarked then. The reviewed revision adds the split cap and per-request query lengths (see Changes).

Why a separate path instead of the existing metadata and reduce

We first ran this kernel through the existing pipeline: flat-row tiles in get_mla_metadata_v1, bf16 partials in mla_reduce_v1, and dispatch from mla_decode_fwd. That version, with an earlier build of the same stage-1 kernel, already got most of the gain at 96 heads. It got little of it at 12 heads with small batches, where this PR's planner and 16-deep merge matter. It also had to change get_mla_metadata_v1, mla_reduce_v1 and mla_decode_fwd, which every MLA decode caller goes through. This PR leaves all three untouched. The comparison was made at the first revision (d10965ef) and is not repeated here.

Changes

Three parts, launched in this order every step:

  • Host planner, opus_mla_decode_flat_plan, runs on the CPU and fills one int32 plan: per-workgroup item ranges, then the work items {request, partial slot, row range, KV range}, then the merge units {first slot, end slot, first row, rows}.
    • Each request's KV is cut into pieces balanced over the XCDs and all their workgroups, and a request's chunks stay on one XCD so they share KV through L2.
    • With round-robin CP the merge loads 4 partials per round trip.
    • Without CP only an XCD's last workgroup absorbs a remainder, and the merge loads 16 partials per round trip, for the few rows and many splits per chunk of a small batch at 12 or 16 heads.
    • The pieces per chunk are capped at what the merge pays for, so a small batch is not cut into 200+ pieces per chunk. Plans the cap does not bind are unchanged.
    • Query lengths are per request: q_len is one token count or a per-request array. With mixed lengths, each XCD's requests are grouped by chunk depth (bucketed=True), so no workgroup idles above a shallow request. A uniform batch gets the same plan either way.
    • Stage 1 is built with -ffast-math, so a row with no key in its piece would produce NaN. Without CP the planner checks every piece and fails the plan otherwise. With CP see Requirements.
    • The planner has no threshold on batch size, context length or head count. Its four cost constants (kItemTiles, kXcdSplit, kMergePieceTiles, kMergePieceTilesDeep) have one value each, and the policy differs only between CP and no CP, as above. Swept one at a time on a scratch build at 8k and 131k tokens of context, each value costs under 5% in mean time against the best single value for that context: the item cost 4.9% at 8k and 1.6% at 131k, the 4-deep merge cost 3.5% at 8k, the others at most 0.4%.
  • Stage 1, opus_mla_decode_a8w8_flat_32mx4_kernel (256 threads, one workgroup per CU), runs the items. A chunk with a single piece writes out and LSE directly; the other chunks write a 128-row bf16 partial slot plus LSE.
  • Merge: combines each split chunk's partial slots by LSE.

OpusMlaFlatDecode (aiter/ops/opus/mla_flat.py) keeps the plan, partial and staging buffers at fixed addresses, so a CUDA graph captured around the decode call replays with every later plan. The plan is built outside the graph and copied from one of two pinned buffers on the current stream.

dec = OpusMlaFlatDecode(max_batch=128)
dec.plan(kv_indptr_host, q_len, num_heads, cp_world_size)   # every step, on the CPU; q_len: int or per-request array
lse = dec(q, kv, out, qo_indptr, kv_indptr, kv_indices, sm_scale, q_scale, kv_scale,
          g_kv_indptr, cp_world_size, cp_rank)               # graph-capturable

Requirements:

  • gfx950; fp8 Q / KV with per-tensor descales; page size 1 and one KV head; a KV cache below 4 GiB.
  • Causal decode. Query lengths may differ between the requests of a call. The widest request has at most 1024 rows (q_len * num_heads): up to 10 tokens at 96 heads, 64 at 16 heads and 85 at 12 heads. The row limit is 128 * max_chunks (default 8; larger values are not tested). Without CP, plan raises on some batches with more than 33 query tokens per request ("a piece would have rows that see no key").
  • With CP, a request shorter than cp_rank + q_len tokens (query included) has query rows that see no key on this rank. mla_decode_fwd writes 0 and an LSE of -inf for them; this path writes NaN and -3e38, so the caller has to mask those rows.
  • At most max_batch requests and item_cap work items (default 1024) per step. When a step needs more (128 heads x 8 tokens x batch 128 under CP needs 1216), plan raises a ValueError that names both numbers and publishes an empty plan.
  • Toolchain: ROCm 7.2.4 (HIP 7.2.53211, AMD clang 22) and ROCm 10.1 (HIP 7.16.26385, AMD clang 24) are validated; earlier versions are not.

Build flag: module_mla_decode_opus is built with -mllvm --amdgpu-mfma-vgpr-form. Stage 1 keeps O in all 256 AccVGPRs and issues its PV MFMAs as inline asm. Without the flag, ROCm 7.2's clang put its own MFMA results in AccVGPRs and spilled O next to the PV MFMAs, and the output was wrong. The flag applies to the whole module. On ROCm 10.1 the module's device code is the same with and without it. On ROCm 7.2.4 it also changes the code of the existing opus_mla_decode_a8w8_16mx1_32nx4 kernels, which op_tests/test_mla.py covers with AITER_MLA_USE_OPUS=1.

Files:

  • New: csrc/kernels/mla/opus/mla_decode_a8w8_flat_32mx4_64nx1.hpp (stage 1) and aiter/ops/opus/mla_flat.py (OpusMlaFlatDecode).
  • csrc/kernels/mla/opus_mla_decode_fwd.cu: planner, both merges and the two ctypes entry points, added after the existing launchers. The existing code changes only in its header comment.
  • aiter/ops/opus/mla.py: ctypes declarations of the two entry points; aiter/ops/attention.py exports them next to the other opus ops.
  • aiter/jit/optCompilerConfig.json: adds the stage-1 header to the sources of module_mla_decode_opus, and the build flag.
  • op_tests/test_mla.py: check_opus_flat_decode(), run by main() on gfx950.

Performance (if applicable)

Microbenchmark: upstream opus vs this PR

Three decode paths on the same inputs:

  • default: mla_decode_fwd without AITER_MLA_USE_OPUS (the asm kernels).
  • upstream opus: mla_decode_fwd with AITER_MLA_USE_OPUS=1, the faster of the two existing paths.
  • new opus: this PR, OpusMlaFlatDecode.

Default and upstream opus are called with return_lse=True, with plans from get_mla_metadata_v1 (fast_mode=True, kv_granularity=16, max_split_per_batch=-1). New opus plans with opus_mla_decode_flat_plan. All plans are built outside the timed region.

Stage 1 plus merge, timed as CUDA graph replays, in µs. Each value is the median of 200 replays, interleaved across the three paths so that clock and thermal drift hit all three alike, then averaged over three separate runs (run-to-run spread at most 6.8%). MI355X, ROCm 10.1, at 484364f0, fp8 Q / KV, q_len 6, softmax scale 192^-0.5. Every request of a batch has the same context, 8k (8192) or 131k (131072) tokens. With CP, each rank holds a round-robin eighth of the context, and one rank is timed.

Hardware Workload/configuration Before (upstream opus) After (new opus) Change
MI355X 96 heads, 8-way CP, 8k context, batch 4 35.5 31.1 1.14x
MI355X 96 heads, 8-way CP, 8k context, batch 32 66.0 36.4 1.81x
MI355X 96 heads, 8-way CP, 8k context, batch 128 126.6 95.0 1.33x
MI355X 96 heads, 8-way CP, 131k context, batch 4 75.5 57.6 1.31x
MI355X 96 heads, 8-way CP, 131k context, batch 32 391.8 266.8 1.47x
MI355X 96 heads, 8-way CP, 131k context, batch 128 1449.8 999.5 1.45x
MI355X 12 heads, no CP, 8k context, batch 4 33.3 30.1 1.11x
MI355X 12 heads, no CP, 8k context, batch 32 55.5 47.3 1.17x
MI355X 12 heads, no CP, 131k context, batch 4 96.5 78.6 1.23x
MI355X 12 heads, no CP, 131k context, batch 32 520.6 454.1 1.15x

Query length, 96 heads with 8-way CP: speedup of new opus over upstream opus, the faster existing path in every cell, as the min-max over batch 1-64. Timed as above, except that each path runs in its own process, averaged over two runs.

context q_len 1 2 3 4 5 6 7 8
8k 1.04-1.27x 1.04-1.45x 1.06-1.72x 1.02-1.24x 1.00-1.90x 1.06-1.76x 2.46-3.40x 2.55-3.54x
131k 0.93-1.24x 0.97-1.32x 1.02-1.45x 0.97-1.35x 1.05-1.74x 1.06-1.50x 1.48-2.20x 1.41-2.23x

The 5 cells below 1.00x are at batch 1-4 with 131k contexts.

The other setups of a 96-head model at the same contexts, with 2, 4, 6 and 8 query tokens, against the faster existing path: 0.97-2.73x from batch 8 and 0.91-2.87x at batch 1-4 with 2- or 4-way CP; 1.03-2.23x at every batch without CP at 96 or 48 heads per rank; 1.07-1.32x from batch 4 at 12 heads per rank. At 24 heads per rank, and at 48 heads with 2 tokens, neither mla_decode_fwd path has an fp8 kernel to compare with.

With ROCm 7.2.4 (PyTorch 2.10.0, on a second MI355X of the same node) a replay takes about 9 µs longer on every path. The microbenchmark then gives 1.05-1.60x over upstream opus at 96 heads and 1.04-1.18x at 12 heads from batch 4, and the query-length table 0.97-3.05x with 2-8 tokens.

These numbers replace those of the earlier revisions of this description, which were measured at other context lengths.

When to use it

Measured as the query-length table, against the faster existing path, at 8k and 131k tokens of context. Rows per request are q_len * num_heads.

  • Use it for 2 or more query tokens per request:
    • with round-robin CP (2-, 4- and 8-way) from 96 rows per request: 0.97-3.54x from batch 8, with 175 of 176 cells at or above 1.00x, and 0.91-2.90x at batch 1-4;
    • without CP at 48 or 96 heads at any batch (1.03-2.23x), and at 12 or 16 heads from batch 4 (0.99-1.32x).
  • Keep mla_decode_fwd:
    • with CP under 96 rows per request (0.59-1.22x);
    • without CP at 12 or 16 heads at batch 1-2 (0.90-1.32x at 8k, 0.73-1.08x at 131k);
    • with one token per request, except from batch 8 at 96 or more heads with CP and at 48 or more heads without (1.02-2.77x).

OpusMlaFlatDecode does not choose between the paths; the caller does.

Accuracy of the timed outputs

out and LSE are checked against an fp32 reference on the same inputs (Q and KV are standard normal values cast to fp8, with descales 1.0): every request of every cell behind the numbers above, 913 cells. By the checks of aiter's MLA decode tests (op_tests/test_mla_persistent.py), every cell passes:

check bound for fp8 default upstream opus new opus
cal_diff (1 - cosine similarity to the reference) < 3e-2 at most 1.1e-4 at most 2.6e-4 at most 2.9e-4
checkAllclose (rtol = atol = 1e-2): elements outside up to 5% at most 0.0067% at most 0.48% at most 1.7%

Every path's LSE is within 5.1e-5 of the reference. The RMS error relative to the reference's RMS is 0.0045-0.0242 for new opus, 0.0032-0.0229 for upstream opus and 0.0029-0.0148 for default: both opus paths feed the softmax probabilities to the PV product as fp8, and the asm kernels do not. ROCm 7.2.4 gives the same numbers.

New opus's RMS error is 0.46-2.24x upstream opus's from batch 8 (median 1.01x) and 0.75-4.17x at batch 1-4 (median 1.25x). The error of both opus paths rises as a request's KV is cut into fewer, longer pieces, and at small batches new opus cuts fewer: 5 against 64 for a one-chunk request at batch 1 under 8-way CP at 8k. The gap depends on how peaked the attention is: with descales of 0.37 and 0.61 on the same Q and KV (logits 4.4 times smaller, ROCm 10.1), new opus's RMS error is 0.98-1.14x upstream opus's and 1.00-1.11x default's, and no path has an element outside checkAllclose's tolerance.

At 1024 tokens of context, 4 of 455 new-opus cells are above the 5% bound with descales 1.0 (5.0-6.0%): 12 or 16 heads with 1-2 tokens under 8-way CP at batch 1-4, shapes that stay on mla_decode_fwd above. With the smaller descales none of them is.

Testing

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

gfx950 only (MI355X). python3 op_tests/test_mla.py runs check_opus_flat_decode() on gfx950 and logs opus flat-row decode: passed; see "Validation and unverified scope".

Documentation

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

aiter/ops/opus/mla_flat.py documents usage, the plan layout, the requirements, the build flag and when to keep mla_decode_fwd.

Dependencies

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

Breaking Changes

None. The path is new and opt-in; no existing op, signature or default changes.

PR Self-Review

Reviewed revision

484364f0

Behavior and intent

This adds a new opt-in decode path and changes no existing behavior. A caller builds a plan each step with OpusMlaFlatDecode.plan and runs OpusMlaFlatDecode.__call__. mla_decode_fwd, get_mla_metadata_v1 and mla_reduce_v1 are untouched and never dispatch to it. The only change that reaches existing code is the build flag of module_mla_decode_opus (see Changes).

The existing paths are insufficient for MTP decode at 96 heads with round-robin CP and at 12 heads without CP: they pack query rows per token or per fixed head tile. The flat-row layout with this planner and merge is 1.06-1.81x faster than the faster of them at query length 6 from batch 4, at 8k and 131k tokens of context (see Performance). At batch 1-2 and on other shapes it can be slower, and "When to use it" says where callers should keep mla_decode_fwd.

Validation and unverified scope

On MI355X (gfx950) at d4c20908, with ROCm 10.1 (PyTorch 2.13.0) and with ROCm 7.2.4 (PyTorch 2.10.0), same results on both:

  • Clean rebuild of module_mla_decode_opus; --amdgpu-mfma-vgpr-form is in the generated build.ninja.
  • python3 op_tests/test_mla.py: exit code 0 and opus flat-row decode: passed, on the default path and with AITER_MLA_USE_OPUS=1. Each run also prints 16 non-fatal checkAllclose failed! lines from the existing bf16 check mla_decode-absorb [golden vs aiter_asm] (nhead 128, decode_qlen 2, ctx_lens 21 and 64). python3 op_tests/test_mla.py -n 128,2 -c 21 64 prints the same 16 on main at the merge base 44301b66, so they do not come from this PR.
  • python3 -m pytest -q op_tests/test_mla_shape_support.py op_tests/test_mla_decode_gate.py: 25 passed, 1 skipped (gfx1250 only).
  • ROCm 10.1 only: a GPU_ARCHS="gfx942;gfx950" build of the module passes check_opus_flat_decode() on gfx950. Plans and out / LSE were compared with d10965ef on the benchmark cells of the earlier description: bit-identical from batch 4 at 96 heads and from batch 2 at 12 heads; in the smaller batches the split cap cuts fewer pieces.

The reviewed revision differs from d4c20908 only in the module docstring of aiter/ops/opus/mla_flat.py, so the results above hold for it. check_opus_flat_decode() was run again with that change on both toolchains and passes.

At the reviewed revision, with the module built at d4c20908: the microbenchmark, the query-length grid and the accuracy pass under Performance, on both toolchains. The descale pass and the planner-constant sweeps ran on ROCm 10.1 only, the sweeps on a scratch build that reads the constants from the environment.

Unverified:

  • MI250X, MI300X and every architecture other than gfx950 are not tested; the entry point rejects them.
  • ROCm versions other than 7.2.4 and 10.1, and max_chunks above 8, are not tested.
  • The non-causal build of stage 1 is compiled but not reachable through OpusMlaFlatDecode, and is not tested.
  • The "Why a separate path" comparison and the comparison with the deployed build were made at d10965ef and not run again at this revision.

PR-specific question

Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?

Nothing in aiter selects this path. mla_decode_fwd never dispatches to it; it runs only when a caller builds an OpusMlaFlatDecode and calls it. Unsupported inputs are rejected before any kernel launches:

  • Architecture: opus_mla_decode_flat_fwd raises unless the device is gfx950, and the stage-1 body is compiled only for gfx950.
  • Dtype and layout: it raises unless Q is a contiguous fp8 [total_q, H, 576] tensor and KV a contiguous fp8 [tokens, 576] tensor (page size 1, one KV head) below 4 GiB, with fp32 descales, bf16 out, int32 index tensors and plan buffers of the expected sizes.
  • Shape: plan raises a ValueError for a batch above max_batch, a request wider than 128 * max_chunks rows, a q_len array that does not match the batch or has a negative entry, and a step that needs more than item_cap work items. When the planner itself fails, as on item_cap, plan publishes an empty plan, so a later call cannot run the previous step's plan on this step's tensors.
  • Rows without a key: stage 1 is built with -ffast-math, so a row that sees no key in its piece would produce NaN. Without CP the planner verifies every piece and fails the plan otherwise, and check_opus_flat_decode() asserts it on each no-CP plan it checks against the reference. With CP the planner's cut rule never cuts within one work item's cost of a request's end, so a row lacks a key only when the request is shorter than cp_rank + q_len tokens; those rows are not rejected and get NaN (see Requirements).

Which shapes should take the path is the caller's decision; "When to use it" gives the measured boundaries.

Changed op tests

op_tests/test_mla.py gains check_opus_flat_decode(), which main() runs on gfx950. It is the only test of this path; the rest of the file tests mla_decode_fwd and does not reach it. It covers:

  • Plan invariants: exact KV coverage of every chunk, no row without a key (no-CP plans), unique and in-range partial slots, and merge units that match the split chunks.
  • out and LSE against an fp32 reference: 96 heads with 8-way round-robin CP at q_len 2, 4, 5, 6 and 8, and without CP at 4 and 6; 12 and 16 heads without CP at q_len 2, 4, 6 and 8; batch sizes 1-64; mixed, short and tail contexts (a last KV tile shorter than the query).
  • Per-request query lengths at 96 heads with and without CP and at 12 and 16 heads without CP, with and without the bucketed layout, including requests with no query token. A uniform batch planned from an int and from a per-request array, bucketed or not, gives the same plan.
  • CUDA graph replay with plans that change between replays, for uniform and per-request query lengths.
  • Rejection of unsupported inputs (rows, batch, q_len entries, non-fp8 Q), and the item_cap error with its empty plan.
  • The split cap: one request of one chunk gets 8-48 work items at 96 heads with CP, and at most 200 at 12 heads without CP.

Profiling Data KIMI-K3, TP8 DCP8 c128 + Accuracy

ATOM nightly: rocm/atom-dev:nightly_202610261615-rocm10.0 (ROCm 10.0.0, PyTorch 2.11.0+rocm10.0.0, bundled aiter 0.1.28.dev9+g41d4d8d7e.d20261026)
Standalone Swebench accuracy test for c128 with opus mla kernel: resolved 188 / 200 = 94.00%

Profiling Data at 81920/1024 ISL/OSL, one mla layer comparison at decode[bs=128 tok=768 d=128 spec=5]
One MLA layer's decode is 2.07x faster than with the default asm kernel.

image image

…d bf16 merge

Adds a decode path for fp8 MLA (576 / 512) with several query tokens per
request (MTP) at head counts the existing kernels pack poorly: 96 heads per
rank under 8-way round-robin context parallelism, and 12 or 16 heads without.
A request's rows are flat (token * H + head), so its tokens and heads together
fill 128-row chunks at any head count.

It has three parts, launched in this order every step:

- A host planner (opus_mla_decode_flat_plan) builds one int32 plan on the CPU:
  per-workgroup item ranges, the work items {request, partial slot, rows, KV
  range}, and the merge units. Each request's KV is cut into pieces balanced
  over the XCDs and all their workgroups. Without CP the planner lets only an
  XCD's last workgroup absorb a remainder and keeps every row of a piece seeing
  at least one key (stage 1 is built with -ffast-math, so a row with no key
  would produce NaN).
- Stage 1 (opus_mla_decode_a8w8_flat_32mx4_kernel, 256 threads, one
  workgroup per CU) runs the items. A chunk that has a single piece writes out
  and LSE directly; the others write a 128-row bf16 partial slot and LSE.
- A merge combines the partial slots of each split chunk by LSE, loading 4
  partials per round trip with CP and 16 without (few rows, many splits per
  chunk at 12 or 16 heads).

OpusMlaFlatDecode (aiter/ops/opus/mla_flat.py) keeps the plan, partial and
staging buffers at fixed addresses, so a CUDA graph captured around the decode
call replays with each later plan. The plan is built outside the graph and
copied from one of two pinned buffers on the current stream.

Requirements: gfx950, fp8 Q / KV with per-tensor descales, page size 1, one KV
head, a KV cache below 4 GiB, causal decode with the same query length for
every request, at most 1024 work items and 1024 rows per request.

op_tests/test_mla_opus_flat_decode.py checks the plan invariants (exact KV
coverage of every chunk, no row without a key, unique partial slots, merge units
that match the split chunks), checks the output and LSE against an fp32
reference at 96 heads with and without round-robin CP and at 12 and 16 heads,
over batch sizes 1-64 and mixed, short, and tail contexts (a last KV tile
shorter than the query), checks CUDA graph
replay with plans that change between replays, and checks the input checks.

Co-authored-by: Cursor <[email protected]>
@nehmathe2
nehmathe2 requested a review from a team November 3, 2026 20:58
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

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

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [OPUS] [MLA] gfx950 fp8 flat-row MTP decode: host planner, stage 1 and bf16 merge [HIP] [OPUS] [JIT] [MLA] gfx950 fp8 flat-row MTP decode: host planner, stage 1 and bf16 merge Nov 3, 2026
@nehmathe2
nehmathe2 marked this pull request as draft November 3, 2026 20:58
@aiter-bot

aiter-bot commented Nov 3, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 6590589324b8 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

The flat-row decode planned one query length for the whole batch, but the
kernel already reads a request's causal span from q_indptr and its rows from
the work item, so only the host planner stood in the way of a ragged step.

Give the planner a q_indptr instead of a q_len: a request's chunk count, row
base and valid rows all come from its own token count. Add a second layout
that groups an XCD's requests by chunk depth and apportions its workgroups
between the groups, since the column layout sizes every column by the deepest
request and leaves a worker idle above every shallower one. On a batch of 64
requests where every eighth verifies 8 tokens and the rest verify 1, the
columns light up 74 of 256 workgroups and the buckets light up all 256.

Both are reachable through build_plan_ragged; build_plan keeps its uniform
signature for existing callers and still takes the column layout, which plans
a single depth identically. 720 uniform configurations across head counts,
batch sizes, query lengths, worker counts and the balance flag produce
byte-identical plans before and after.

Ported from the kimi-k3 endpoint patches by Rita Brugarolas Brufau.
@nehmathe2
nehmathe2 marked this pull request as ready for review November 4, 2026 05:37
@hmahmad26

Copy link
Copy Markdown
Contributor

Commit 8a03207c on this branch.

Summary

Lets the requests of one call have different query lengths, and adds a depth-bucketed workgroup layout for such batches. A caller that passes a single query length gets the same plan as before, bit for bit.

Motivation

A speculative decode step accepts a different number of draft tokens for each request, so the requests of one step have different query lengths. The planner took one query length for the whole batch, so such a step had to be padded to its deepest request and the extra tokens computed and discarded.

With 7 draft tokens and an acceptance rate of 0.8, a batch of 128 carries 481 real query tokens out of the 1024 the padded plan computes. Over half the stage-1 work is thrown away. At an acceptance rate of 0.5 it is 270 out of 1024.

Padding also hides the imbalance from the planner: it sees one depth for the whole batch and cannot tell a request that needs 8 chunks from one that needs 1.

Changes

  • OpusMlaFlatDecode.plan takes either one integer or one query length per request. A per-request array is normalised to a qo_indptr and passed to the planner; a batch whose lengths are all equal collapses back to the scalar path, so nothing changes for existing callers.
  • opus_mla_decode_flat_plan gains a qo_indptr argument. When it is null the planner behaves exactly as before. When it is given, each request is cut into chunks at its own length.
  • Column layout (the existing one, generalised): a request's chunks are stacked into one column of workgroups so they share the request's KV through L2. Column height is set by the deepest request in the batch, so a workgroup above a shallow request idles.
  • Bucketed layout (new, and the default): an XCD's requests are first grouped by chunk depth, and the XCD's workgroups are apportioned between the groups by how much work each holds. No workgroup idles above a shallow request; the spare ones split that request's KV instead. Selected per call by plan(..., bucketed=), default True.
  • If a bucketed plan would exceed the work-item cap, the planner falls back to the column layout for that step rather than failing it.

This makes the Requirements bullet that reads "Causal decode with the same query length for every request in a call" no longer apply; the limit is now 1024 rows for the widest request rather than for every request.

Performance

Same protocol as the microbenchmark in the description: stage 1 plus merge, timed as CUDA graph replays, in µs. Each value is the median of 200 replays, before and after interleaved so that clock and thermal drift hit both alike, then averaged over three separate processes (run-to-run spread at most 3.9%). MI355X, fp8 Q / KV, 96 heads under 8-way round-robin CP, lognormal contexts with a median of 66k.

Query lengths are drawn per request for 7 draft tokens plus one bonus token. accept-p is a geometric run of accepted drafts at acceptance rate p. deep-few is one request in eight verifying all 8 tokens while the rest verify 1.

Hardware Workload/configuration Before (padded to deepest) After (ragged) Change
MI355X 96 heads, 8-way CP, uniform q=8, batch 32 239 239 1.00x
MI355X 96 heads, 8-way CP, uniform q=8, batch 128 793 792 1.00x
MI355X 96 heads, 8-way CP, accept-0.8, batch 32 238 144 1.65x
MI355X 96 heads, 8-way CP, accept-0.8, batch 64 460 324 1.42x
MI355X 96 heads, 8-way CP, accept-0.8, batch 128 793 507 1.56x
MI355X 96 heads, 8-way CP, accept-0.5, batch 32 193 86 2.24x
MI355X 96 heads, 8-way CP, accept-0.5, batch 64 366 171 2.14x
MI355X 96 heads, 8-way CP, accept-0.5, batch 128 795 278 2.85x
MI355X 96 heads, 8-way CP, deep-few, batch 64 462 141 3.27x
MI355X 96 heads, 8-way CP, deep-few, batch 128 796 220 3.63x

A batch whose requests all verify the same number of tokens measures 1.00x at every batch size, so no existing caller changes.

Depth grouping carries most of the gain above batch 16. Below it the groups get more workgroups than they can use, over-split the KV, and cost 0.7-0.9x against the plain column layout; both still stay ahead of padding, so the floor is unchanged either way.

Testing

  • python3 op_tests/test_mla_opus_flat_decode.py at 8a03207c: 104 passed, up from 62. The new cases cover per-request query lengths under both layouts, at 96 heads with and without CP and at 12 and 16 heads, batch 1-64, requests that verify no token at all, a CUDA graph replayed across plans whose query lengths move between replays, and that a uniform batch described per request plans identically to the same batch described by one integer.
  • Ragged planning is a strict generalisation of the uniform path: over 720 uniform configurations (head counts, batch sizes, query lengths, workgroup counts and the balance flag) the planner emits byte-identical plans before and after the change.
  • Both layouts checked under AddressSanitizer for exact KV coverage per chunk, rows inside their request, no row without a key, and unique in-range partial slots.

Measured on gfx950 at 96 heads with CP only; 12 and 16 heads are covered by the op test but not benchmarked ragged.

@zufayu

zufayu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@aiter-bot review

@zufayu

zufayu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

clean code : merge cu and op test

@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the GLM model service, not with this PR.

GLM backend unavailable at http://localhost:30000 (deep inference probe returned '000')

@yhl-amd — please take a look.

Triage: if GLM serves but its output is malformed it may be the ATOM framework (@valarLip); if the box, GPU, disk or network is unhealthy it may be the machine (@gyohuangxin).

Re-comment @aiter-bot review once it is resolved.

1 similar comment
@aiter-bot

Copy link
Copy Markdown

⚠️ aiter-bot — this review could not complete: a problem with the GLM model service, not with this PR.

GLM backend unavailable at http://localhost:30000 (deep inference probe returned '000')

@yhl-amd — please take a look.

Triage: if GLM serves but its output is malformed it may be the ATOM framework (@valarLip); if the box, GPU, disk or network is unhealthy it may be the machine (@gyohuangxin).

Re-comment @aiter-bot review once it is resolved.

nehmathe2 and others added 2 commits November 12, 2026 16:46
Keep one ctypes translation unit for opus MLA decode, and run the gfx950
flat-row cases from test_mla.py with the rest of the MLA op tests.

Co-authored-by: Cursor <[email protected]>
@nehmathe2

Copy link
Copy Markdown
Contributor Author

@zufayu folded both in 9f8ba3b:

  • opus_mla_decode_flat.cu is now in opus_mla_decode_fwd.cu with the other decode ctypes ops (opus_mla_decode_flat_plan / opus_mla_decode_flat_fwd).
  • op_tests/test_mla_opus_flat_decode.py is now check_opus_flat_decode() in op_tests/test_mla.py, run on gfx950 with the rest of the MLA op test.

The kernel header, OpusMlaFlatDecode, and the ctypes bindings are unchanged.

@nehmathe2

Copy link
Copy Markdown
Contributor Author

hi @zufayu, @fangche123, @amd-ruitang3 - can you please help review this pr. thanks

@amd-ruitang3

Copy link
Copy Markdown
Contributor

@nehmathe2 does your PR need to work with ROCm 10?

@amd-ruitang3

Copy link
Copy Markdown
Contributor

Thanks for the detailed write-up. I reproduced this on MI355X (single GPU, PR head 15a64af7) and swept about 650 shapes beyond the ones in the description. I timed default asm, AITER_MLA_USE_OPUS=1 and OpusMlaFlatDecode as CUDA graph replays, two passes each; run-to-run spread was within ±3%. On the target shapes the speedup reproduces: 96 heads with 8-way RR CP, q_len 6, batch 4–128 gives 1.30–1.64x over upstream opus. I hit a few issues that I think should be addressed before merge.

1. Wrong results on ROCm 7.2 without any error (blocking)

Built in rocm/atom-dev:latest (ROCm 7.2.4, HIP 7.2.53211, AMD clang 22), the flat path produces wrong output:

  • check_opus_flat_decode fails on its first case (96 heads, CP, q_len 2) with O max error 8.3e-01 of the reference's max.
  • Against mla_decode_fwd on the same inputs, 1 - cos is about 0.07–0.11. The cal_diff bound is 3e-2.
  • It reproduces at every PR commit I tried: d10965ef (the self-reviewed revision), 8a03207c, 9f8ba3b9 and 449a8710. So it is not caused by the merges with main.

With rocm/atom-dev:ROCm_10.1.0 (HIP 7.16) the same code passes, and 1 - cos vs. default is at most 4.9e-4 across all shapes.

Since the kernel compiles and runs without error on the older toolchain, a user would get silently wrong attention. Could you either:

  • find and fix the toolchain-dependent part (e.g. something under -ffast-math, inline asm, or the scheduling assumptions in the stage-1 kernel), or
  • refuse to build or dispatch on unsupported compilers, and document the minimum ROCm version?

2. The test added to test_mla.py cannot pass as committed

op_tests/test_mla.py sets torch.set_default_device("cuda") at module level. OpusMlaFlatDecode.__init__ then builds its staging buffers with torch.zeros(self.plan_ints, dtype=torch.int32).pin_memory(). That tensor lands on the GPU, and the call fails with:

RuntimeError: cannot pin 'torch.cuda.IntTensor' only dense CPU tensors can be pinned

So check_opus_flat_decode() errors before running any kernel. Passing device="cpu" explicitly for _host and _stats in aiter/ops/opus/mla_flat.py fixes it. It also makes the class robust for callers that change the default device.

3. Regressions outside the benchmarked shapes

Comparing against the faster of default and upstream opus, the flat path is more than 5% slower on 137 of 654 shapes, and more than 2x slower on 30. The main clusters:

  • Small batch with RR CP (the largest regression). At batch 1 with long contexts (lognormal, median 66k), any request whose q_len * H ≤ 128 takes about 88–99 µs on the flat path, versus 18–36 µs on opus (3–5x slower). The time drops as the row count grows: about 62 µs at 2 chunks, about 50 µs at 3–4 chunks, about 40 µs at 5 or more. Even the target shape is slower at batch 1:

    shape batch upstream opus flat
    96 heads, CP, q_len 6 1 36.2 µs 43.8 µs
    12 heads, no CP, q_len 6 1 36.2 µs 54.6 µs

    This looks like the planner splitting a single short chunk across all workgroups, so the merge carries a large fixed cost. I haven't profiled it to confirm.

  • 12/16/32 heads with CP at batch 16: up to about 20% slower.

  • q_len = 1 at 12/16 heads with short contexts: 10–35% slower.

Where the path clearly wins is batch ≥ 16 with q_len ≥ 2. Without CP, no shape regressed (median 1.12–1.38x). With CP, 64/96/128 heads never regressed, and 12/16/32 heads regressed by at most 18% on a few shapes.

Suggestions:

  • Cap the split count for small batches or short local KV in the planner, or fall back to mla_decode_fwd when the plan would be merge-dominated.
  • Document the shapes where callers should keep using the existing path.
  • Add batch 1–2 to the performance table, since low-concurrency serving hits those.

4. Minor

  • The PR description lists csrc/kernels/mla/opus_mla_decode_flat.cu and op_tests/test_mla_opus_flat_decode.py. After 9f8ba3b9, that code lives in opus_mla_decode_fwd.cu and test_mla.py, so please update the description.
  • For 128 heads × q_len 8 × batch 128 with CP, opus_mla_decode_flat_plan throws because it exceeds the 1024 work-item cap. That matches the documented limit, but a clearer Python-side error that names the cap would help callers pick a fallback.

Repro notes

Timing setup:

  • Metadata from get_mla_metadata_v1 with fast_mode=True, kv_granularity=16, max_split_per_batch=-1, return_lse=True.
  • Page size 1, contiguous kv_indices, CP rank 3 of 8.
  • Each path in its own process, because capturing the default and opus mla_decode_fwd graphs in one process faults on replay.

I'm happy to share the sweep script and the raw CSV.

…t cap, host planner buffers

- Build module_mla_decode_opus with --amdgpu-mfma-vgpr-form. ROCm 7.2 clang put the
  compiler's MFMA results in AccVGPRs, so O (all 256 AccVGPRs) was spilled next to the
  inline-asm PV MFMAs and the flat kernel returned wrong output. Validated on ROCm 7.2.4
  and 10.1.
- Planner: cap an XCD's columns at what the merge chain pays for, so a small batch is not
  cut into ~200+ pieces per chunk (96 heads CP q1 b1: 92.5 -> 34.7 us). Plans the cap does
  not bind are unchanged.
- Planner host buffers are created on the CPU whatever the default device is.
- A plan past item_cap raises a ValueError naming the need and the cap, and publishes an
  empty plan.
- Document where callers should keep mla_decode_fwd.

Co-authored-by: Cursor <[email protected]>
@amd-ruitang3

Copy link
Copy Markdown
Contributor

Thanks for the quick turnaround on d4c20908. I re-ran everything on MI355X in a fresh rocm/atom-dev:latest (ROCm 7.2.4, HIP 7.2.53211, AMD clang 22). That is the same toolchain as my first review. I used 15a64af7 as the control.

1. Wrong results on ROCm 7.2: resolved ✅

revision check_opus_flat_decode
15a64af7 (control) ❌ O max error 7.97e-01
d4c20908 ✅ passed
  • --amdgpu-mfma-vgpr-form is in the generated build.ninja of module_mla_decode_opus.
  • Over 683 shapes, 1 - cos of the flat path against mla_decode_fwd is at most 1.35e-2, inside the 3e-2 cal_diff bound.
  • The flag does not affect the existing opus path (AITER_MLA_USE_OPUS=1). Over 680 shapes, time with d4c20908 divided by time with 15a64af7 has a median of 1.000, a p5–p95 range of 0.98–1.02, and a worst case of 1.08x. That is within run-to-run noise.

2. pin_memory failure in test_mla.py: resolved ✅

I ran check_opus_flat_decode with the default device left at cuda, as test_mla.py sets it, and it passes. The new item_cap error message is clear.

3. Regressions outside the benchmarked shapes: much improved, some remain

I compared the flat path against the faster of default and upstream opus, using the min of two passes:

15a64af7 d4c20908
shapes >5% slower 138 90
shapes >2x slower 32 0
  • Target shapes (q_len 6, lognormal 66k context):
    • 96 heads with CP: 1.30–1.63x over opus at batch 4–128.
    • 12 heads without CP: 1.15–1.20x at batch 16–64.
  • 96 heads, CP, q_len 6, batch 1 is now on par with opus: about 40 µs for flat vs. 40.7 µs for opus.

The remaining slow region is 12/16 heads at batch ≤ 4 and q_len 1–3, with and without CP. Some examples:

shape batch best existing flat ratio
16 heads, CP, q_len 1 4 23.3 µs (opus) 42.0 µs 0.56x
16 heads, CP, q_len 1 1 22.1 µs (opus) 35.9 µs 0.62x
16 heads, no CP, q_len 1 1 29.3 µs (opus) 46.0 µs 0.64x
12 heads, CP, q_len 1 1 24.4 µs (opus) 35.3 µs 0.69x
12 heads, CP, q_len 2–4 4 31.3–34.1 µs (opus) 41.9–43.5 µs 0.75–0.79x

The mla_flat.py docstring already says to keep mla_decode_fwd for these shapes, and I think that is acceptable. Could you:

  • add this residual small-batch range to the PR description (the "When to use it" guidance plus a few batch 1–4 rows in the performance table), and
  • confirm that the caller you deploy with (ATOM / the serving integration) actually falls back to mla_decode_fwd for these shapes, rather than relying on users reading the docstring? If the dispatch rule lives outside this PR, a pointer to it would be enough.

4. PR description: still outdated

The description still lists csrc/kernels/mla/opus_mla_decode_flat.cu and op_tests/test_mla_opus_flat_decode.py, including the "62 passed" test command. Since 9f8ba3b9, that code lives in opus_mla_decode_fwd.cu and test_mla.py. Could you please update the file list and test instructions, and also mention the --amdgpu-mfma-vgpr-form build flag and the minimum validated ROCm versions (7.2.4 and 10.1)?

Once 3 and 4 are addressed, I'm fine with this from my side.

Setup: one MI355X, CUDA-graph replays, 2 passes per path, min of the two passes. The node is shared and occasionally showed single-pass spikes, so a regression was counted only if it appeared in both passes.

…la_flat.py docstring

Docstring only, no code change.

The ranges are now the flat path's speedup over the faster of the two mla_decode_fwd
paths (default asm or AITER_MLA_USE_OPUS=1), per request class and batch range, from
the same MI355X measurement as the "When to use it" section of the PR description
(66k tokens of context per request, batch 1-64). The shapes that should stay on
mla_decode_fwd are listed in one sentence.

Co-authored-by: Cursor <[email protected]>
@nehmathe2

Copy link
Copy Markdown
Contributor Author

Thanks for the quick turnaround on d4c20908. I re-ran everything on MI355X in a fresh rocm/atom-dev:latest (ROCm 7.2.4, HIP 7.2.53211, AMD clang 22). That is the same toolchain as my first review. I used 15a64af7 as the control.

1. Wrong results on ROCm 7.2: resolved ✅

revision check_opus_flat_decode
15a64af7 (control) ❌ O max error 7.97e-01
d4c20908 ✅ passed

  • --amdgpu-mfma-vgpr-form is in the generated build.ninja of module_mla_decode_opus.
  • Over 683 shapes, 1 - cos of the flat path against mla_decode_fwd is at most 1.35e-2, inside the 3e-2 cal_diff bound.
  • The flag does not affect the existing opus path (AITER_MLA_USE_OPUS=1). Over 680 shapes, time with d4c20908 divided by time with 15a64af7 has a median of 1.000, a p5–p95 range of 0.98–1.02, and a worst case of 1.08x. That is within run-to-run noise.

2. pin_memory failure in test_mla.py: resolved ✅

I ran check_opus_flat_decode with the default device left at cuda, as test_mla.py sets it, and it passes. The new item_cap error message is clear.

3. Regressions outside the benchmarked shapes: much improved, some remain

I compared the flat path against the faster of default and upstream opus, using the min of two passes:

15a64af7 d4c20908
shapes >5% slower 138 90
shapes >2x slower 32 0

  • Target shapes (q_len 6, lognormal 66k context):

    • 96 heads with CP: 1.30–1.63x over opus at batch 4–128.
    • 12 heads without CP: 1.15–1.20x at batch 16–64.
  • 96 heads, CP, q_len 6, batch 1 is now on par with opus: about 40 µs for flat vs. 40.7 µs for opus.

The remaining slow region is 12/16 heads at batch ≤ 4 and q_len 1–3, with and without CP. Some examples:

shape batch best existing flat ratio
16 heads, CP, q_len 1 4 23.3 µs (opus) 42.0 µs 0.56x
16 heads, CP, q_len 1 1 22.1 µs (opus) 35.9 µs 0.62x
16 heads, no CP, q_len 1 1 29.3 µs (opus) 46.0 µs 0.64x
12 heads, CP, q_len 1 1 24.4 µs (opus) 35.3 µs 0.69x
12 heads, CP, q_len 2–4 4 31.3–34.1 µs (opus) 41.9–43.5 µs 0.75–0.79x
The mla_flat.py docstring already says to keep mla_decode_fwd for these shapes, and I think that is acceptable. Could you:

  • add this residual small-batch range to the PR description (the "When to use it" guidance plus a few batch 1–4 rows in the performance table), and
  • confirm that the caller you deploy with (ATOM / the serving integration) actually falls back to mla_decode_fwd for these shapes, rather than relying on users reading the docstring? If the dispatch rule lives outside this PR, a pointer to it would be enough.

4. PR description: still outdated

The description still lists csrc/kernels/mla/opus_mla_decode_flat.cu and op_tests/test_mla_opus_flat_decode.py, including the "62 passed" test command. Since 9f8ba3b9, that code lives in opus_mla_decode_fwd.cu and test_mla.py. Could you please update the file list and test instructions, and also mention the --amdgpu-mfma-vgpr-form build flag and the minimum validated ROCm versions (7.2.4 and 10.1)?

Once 3 and 4 are addressed, I'm fine with this from my side.

Setup: one MI355X, CUDA-graph replays, 2 passes per path, min of the two passes. The node is shared and occasionally showed single-pass spikes, so a regression was counted only if it appeared in both passes.

Thanks for re-running everything on d4c20908. Points 3 and 4 are addressed in the description.

One docstring-only commit, 484364f0, follows d4c20908 (no code change): the "When to use it" numbers in mla_flat.py now match the description.

3. Residual small-batch range

Description. There is now a "When to use it" section: a grid of new opus against the faster existing path (34 shapes, batch 1-64, three context sets), the guidance that follows from it, and a table of the residual cells in µs. The microbenchmark tables now have batch 1 and 2 rows. Your slow region reproduces: 12/16 heads at batch 1-4 with 1-3 tokens is 0.55-0.92x under CP and 0.61-1.00x without CP on ROCm 10.1, and 0.61-0.93x and 0.67-0.99x on ROCm 7.2.4.

Dispatch. The rule lives in ATOM, in ROCm/ATOM#2961 (open, opt-in with ATOM_OPUS_MLA=1): wanted(), dcp1_shape_ok() and uses_opus_for_batch() in atom/model_ops/opus_mla.py, applied at graph capture and at replay by _uses_opus_mla / _opus_mla_dcp1_heads in atom/model_ops/attentions/aiter_mla.py. The flat path is taken only for causal fp8 MTP decode with query length above 1, and only at 96 heads under round-robin CP or at 12/16 heads without CP. Everything else stays on mla_decode_fwd. So all five rows of your table stay on mla_decode_fwd: four have q_len 1, and the fifth is 12 heads under CP.

One part of the residual range is not gated there: 12/16 heads without CP and q_len 2 or more take the flat path from batch 1. On ROCm 10.1, at batch 1-2 that is 0.73-1.04x the speed of upstream opus. ATOM's fallback is the default path unless the deployment sets AITER_MLA_USE_OPUS=1, and against the default path the flat path is 0.96-1.25x at batch 1-2 and 1.24-1.42x at batch 4. The exception is 16 heads with 3-4 tokens: 0.76-0.91x at batch 1-2, 0.92-1.00x at batch 4 and 1.05-1.11x at batch 8. On ROCm 7.2.4 the ends of these ranges differ by at most 0.07x.

I will keep 16 heads with 3-4 tokens on mla_decode_fwd below batch 8 in ROCm/ATOM#2961 before it merges. In the cells measured on both toolchains, the flat path is then at worst 0.95x the speed of ATOM's fallback wherever ATOM takes it, and as fast or faster in about 95% of them.

4. Description

Updated: the file list (opus_mla_decode_fwd.cu, test_mla.py), the test instructions (python3 op_tests/test_mla.py runs check_opus_flat_decode()), the --amdgpu-mfma-vgpr-form build flag with what it changes on each toolchain, and the validated ROCm versions (7.2.4 and 10.1). The PR Self-Review sections are filled in for the current head.

The microbenchmark and accuracy tables are re-measured at d4c20908. The "Why a separate path" table and the serving and profiling numbers are still the first revision's, and say so. Two things changed:

  • 12 heads without CP: since the first revision, main has made both existing paths faster at small batches (upstream opus at batch 1, uniform contexts: 70 -> 39 µs). [HIP] [Perf] Add a wide split-K reduce for MLA decode and verify with few units and many splits #7570's wide split-K reduce targets that case, but I did not bisect the speedup to it. New opus's lead at batch 4 is now 1.05-1.14x (was 1.19-1.22x), and at batch 1-2 it is 0.86-0.96x.
  • Accuracy: the section now covers every request of every cell, including the "When to use it" grid. On the two target shapes new opus's RMS error is within 3% of upstream opus's from batch 4, and within 8% at batch 1-2. Elsewhere it is higher at small batches, where new opus cuts a request's KV into fewer pieces: up to 2.8x at batch 1 for one-chunk requests under CP (0.012-0.016 against 0.005-0.006). The split cap is part of that (12 rows per request under CP, batch 1: 0.0072 -> 0.0119). Every cell stays far inside the test bounds (cal_diff at most 1.9e-4 against 3e-2).

@amd-ruitang3 amd-ruitang3 added ci:mi300x Run MI300X standard and OPUS CI on PRs and removed ci:mi300x Run MI300X standard and OPUS CI on PRs labels Dec 1, 2026
nehmathe2 and others added 2 commits December 1, 2026 07:11
…tokens

Test only (check_opus_flat_decode in op_tests/test_mla.py); no kernel or planner change.

- long contexts now log-uniform between 8192 and 262144 tokens. Its merge chains are as
  long as before: up to 34 pieces per split chunk with CP and 78 without (32 and 72 before).
- Split-cap check, one request of 131072 tokens: 24 work items at 96 heads with CP and
  168 at 12 heads without CP, within the same bounds.
- Drop the unused `import math`.

python3 op_tests/test_mla.py passes on the default path and with AITER_MLA_USE_OPUS=1,
on ROCm 10.1 and 7.2.4 (MI355X).

Co-authored-by: Cursor <[email protected]>
@nehmathe2
nehmathe2 force-pushed the nm/mla-opus-flat-mtp-decode branch from 6c89823 to 56db871 Compare December 1, 2026 07:13
@amd-ruitang3
amd-ruitang3 merged commit 423e556 into ROCm:main Dec 2, 2026
60 checks passed
nehmathe2 added a commit to nehmathe2/ATOM that referenced this pull request Dec 3, 2026
…rts; default on

Addresses the review of ROCm#2961 on top of main (merged in the previous commit)
and aiter's merged OpusMlaFlatDecode (ROCm/aiter#7415). Needs the aiter
follow-up that adds aiter.ops.opus.mla_flat.supports / min_batch /
unsupported_reason and sizes the decoder from its widest request.

- What the kernel can run and where it is the faster one are aiter's:
  opus_mla.py keeps only what ATOM knows (aiter backend, unshuffled dense KV,
  the gathered head width under DCP) and asks aiter for the rest, once, at
  builder construction. The 20-condition wanted() and the module-global plan
  buffer are gone; aiter is imported directly, with no ImportError probe.
- ATOM_OPUS_MLA is on by default. The decode buckets that take the kernel are
  aiter's: 2 or more query tokens a request, and under round-robin DCP 96 or
  more rows a request, or without DCP 48 or 96 heads at any batch and 12 or
  16 heads from batch 4. Every other decode keeps mla_decode_fwd. A refusal is
  logged once, at debug level unless ATOM_OPUS_MLA is set.
- ATOM_OPUS_MLA_MAX_BS is removed: the builder's decoder is sized from max_bs
  and num_spec_tokens + 1.
- finish_decode publishes the step's plan over the scheduled requests at their
  own query lengths; build_for_cudagraph_capture publishes an empty one. Both
  ask the same helper with the replay key (running_bs, max_seqlen_q), so a
  replayed graph finds a plan for the kernel it recorded. A TBO-split bucket
  keeps mla_decode_fwd; unsplit buckets of a TBO run take the kernel.
- The KV cache's row width and size are checked on the first decode bucket
  after the pool exists.
- AttentionMetaData declares opus_plan. _forward_decode runs it where the
  call is the decode it was built for (causal, the plan's query length and
  head width, inputs aiter takes), so a drafter's own decodes on the target's
  metadata, and a draft KV cache of another dtype, keep mla_decode_fwd.

Tests: tests/test_opus_mla_dispatch.py (ATOM's gates, sizing, the layer call
site) and tests/model_ops/test_opus_mla_gpu.py (gfx950: the kernel against
mla_decode_fwd and an fp32 reference, graph replay with later plans, short
contexts merged across the DCP group, and a real AiterMLAMetadataBuilder's
prepare_decode / build_for_cudagraph_capture feeding a real
MLAAttention._forward_decode, with the switch on, off and at its default).
nehmathe2 added a commit to nehmathe2/aiter that referenced this pull request Dec 4, 2026
…ks in supports

Review of ROCm#9178:

- min_batch now takes one token per request from batch 8 at 96 or more heads
  with CP and at 48 or more without, as the "When to use it" table says; it
  returned None for every q_len below 2, which contradicted the table.
  check_opus_flat_decode gains one-token shapes (96 and 128 heads with CP,
  48 and 96 without) against the reference.
- min_batch keeps 16 heads at 3-4 tokens without CP on mla_decode_fwd below
  batch 8 (0.92-1.00x of the default path at batch 4, 1.05-1.11x at batch 8),
  as committed in the review of ROCm#7415; the docstring's table now lists it.
- supports() passes max_chunks to unsupported_reason, so it answers for a
  decoder built with a non-default max_chunks.
- min_batch's docstring says the boundaries were measured on MI355X and are
  unmeasured on other gfx950 parts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants