Skip to content

[FlyDSL] [Perf] gfx1250 NVFP4 sparse decode: plan-free launches, wave groups and XCD-local rows for the fused split-KV reduce - #8462

Draft
XiaobingSuper wants to merge 5 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-nvfp4-pa-fused-reduce
Draft

XiaobingSuper wants to merge 5 commits into
ROCm:mainfrom
XiaobingSuper:xiaobingsuper/gfx1250-nvfp4-pa-fused-reduce

Conversation

@XiaobingSuper

Copy link
Copy Markdown
Contributor

What

Three launch options for the gfx1250 NVFP4 wave tile of pa_decode, all default off. The MiniMax-M3 sparse decode runs one length-1 sequence per (row, KV head) over a top-k window of at most 32 pages. With these options it merges each row's split-KV partials inside the paged attention instead of running the tile kernel and then the PS reduce.

  • plan_free=True. No plan lookups in the tile prologue; work holds the context lengths.
    • Direct output. One CTA per sequence.
    • Cluster merge. A cluster of P CTAs gives the sequence's tiles to min(P, tiles) CTAs, split evenly. That is the planner's split for a plan with P tasks per sequence.
    • Page ids. Every wave copies the sequence's page ids (at most 32) into LDS with an async load, issued together with the context-length load. The first page DMAs therefore go out one memory round trip after launch.
    • Query split. The CTA splits the query into its FP8 terms once, through LDS, instead of once per wave.
  • page_groups (2 or 4). That many groups of four waves per CTA take pages g, g + G, ... of the task and merge in LDS after the loop. One CTA then holds a whole top-k window with G times more pages in flight. BF16 or MXFP8 output only; not with the last-arriver merge.
  • xcd_rows (plan-free only). The direct and cluster grids are remapped so that xcd_rows consecutive sequences run on one XCD and share its L2. These are one request's MTP rows, which share most of their selected pages. The grid pads to whole XCD groups.
  • cluster_rows (2 or 4). Puts that many sequences in one plan-free cluster. It maps onto the cluster_seqs clusters pa_decode already has.
  • Last-key page. The wave pipeline also stops its loop at the page that holds a one-token row's last key, and masks that page through the QK start value.

None of the options changes a row's math. One wave group and the plan's split give exactly the planned launch's bytes. Every existing mode is unchanged.

Why

In MiniMax-M3.1 TP4 decode on MI455X, the sparse attention core is a tile kernel and a separate PS-reduce kernel per layer. That costs about 14 us per layer, including the kernel switch between them.

Performance

MiniMax-M3.1 TP4 decode on 4x MI455X, per-layer attention core in us (split path today vs this PR):

decode rows 8 10 12 16 24 32
split path 6.53 8.40 8.68 8.50 12.93 13.77
fused (this PR) 4.98 6.23 6.37 6.94 8.65 9.44

At C64-shaped decode (CUDA graph, us/layer, fused vs split), with the split ATOM's policy picks:

decode rows fused split ATOM's choice
32 4.6 5.1 cluster of 8
64 5.1 6.5 cluster of 4, two wave groups
80 6.3 8.5
128 6.9 8.6
192 8.5 13.0 cluster of 4
256 9.6 13.7 one CTA per row, four wave groups

Correctness

  • Bytes. At the same split, the MXFP8 output is byte-identical to the planned launch. The plan-free outputs equal the group-32 quant of the BF16 output of the same call, which matches an FP32 reference.
  • Tests. On our stack, 176 + 43 test cases pass. op_tests/test_flydsl_pa_decode_nvfp4.py::test_pa_decode_nvfp4_plan_free covers direct and cluster launches (P 2/4/8), 1/2/4 wave groups, XCD remap, f16 and bf16 queries, short contexts, store_output on/off and padded rows.
  • Model. The fused path ran in our MiniMax-M3.1 integration stack (ATOM_M3_PA_FUSED_REDUCE=1), which passes our serving gate with real speculative acceptance. GSM8K (1319, 5-shot) scores 0.9545-0.9553.

Dependencies

Stacked on #8365 (lirui927's NVFP4 PA decode MXFP8 output, which carries #8289's NVFP4 wave tile); please review only the top commit. The ATOM wiring (ATOM_M3_PA_FUSED_REDUCE) follows separately, stacked on lirui927's ROCm/ATOM#3581 / #3634.

Port onto #8365

#8365's branch carries main's pa_decode refactor: traits-driven compile, cluster_seqs, step and run clusters, reversed direct-output order, and no validated-launch cache. Our stack validated K4 on the older code, so this is a re-implementation on the new structure, not a mechanical rebase. The differences from what ran in our stack:

  • New prologue branches. The plan-free prologue and epilogue are new const_expr branches beside the existing cluster and direct ones. The existing branches are untouched.
  • No separate merge. cluster_rows maps onto cluster_seqs, and the cluster merge is Gfx1250ClusterMerge unchanged; K4's own multi-sequence merge is dropped.
  • Narrower scope. xcd_rows now requires plan_free, and plan_free takes only the BF16 and MXFP8 outputs, not the FP32 per-token one. Those are the only combinations ATOM uses.
  • Test cleanup. The test no longer patches the removed _VALIDATED_LAUNCHES cache, and one unused variable is gone.

Validation status

  • Validated on our 1120 integration stack (image base aiter 576d3f0) on 4x MI455X, as the stack's K4 commit.
  • Re-checked after the port (no GPUs):
    • FlyDSL compile-only for gfx1250, in a GPU-less container, of 15 variants: plan-free direct (1, 2 and 4 wave groups, MXFP8 with and without the BF16 store, BF16 output, XCD remap); plan-free clusters of 2, 4 and 8 (with and without two wave groups, f16 / bf16 query); a plan-free two-sequence cluster; and [FlyDSL] gfx1250 PA decode: MXFP8 (E8M0 group-32) output for o_proj #8365's own modes (direct, cluster 4, two-sequence cluster, last-arriver merge, MXFP8 and BF16). All compiled to gfx1250 code objects;
    • py_compile, black, and ruff (E4/E7/E9/F) are clean.
  • Not re-run on GPUs after the port: the op test above and the model. Both are needed before this leaves Draft.

🤖 Generated with Claude Code

ruili and others added 3 commits November 19, 2026 08:54
NVFP4 K/V (packed e2m1, one E4M3 scale per 16 values, token-major per
(page, KV head): [128, 64] payload and [128, 8] scale bytes) for the gfx1250
FlyDSL pa_decode, selected by key/value scales of dtype float8_e4m3fn.

Gfx1250Nvfp4WavePipeline serves tiles of one query tile (<= 16 rows, M3.1 TP4
decode, MTP and prefill rows): each wave owns 32 tokens of every page and DMAs
them itself, QK is v_wmma_scale16_f32_16x16x128_f8f6f4 straight from the raw K
rows and their E4M3 scales (the query split into FP8 terms exact to 2^-21 of a
16-dim block's maximum), V is dequantized and transposed by the same
instruction with a constant selector, and softmax and P stay in registers, so
the page loop has no CTA barrier. Direct, last-arriver, cluster and reducer
outputs and the FP8 output epilogue are supported.

v_wmma_scale16 misreads 64-bit scale operands that come from an inline
constant or an SGPR pair on gfx1250; every selector scale is ORed with a
lane-varying zero so it stays in a VGPR pair.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t_scale)

MiniMax-M3.1's MXFP4 checkpoint runs o_proj as a native MXFP8 GEMM
(gemm_a8w8_mx32: E4M3 activations, one E8M0 scale per 32 along K). Each of
the 57 sparse layers stored the PA's BF16 output and quantized it in a
separate kernel (ATOM quantize_fp8: 2.4 us decode, 7.2 us prefill a layer).
The per-token quantized_output (one FP32 descale a token) does not fit it.

An E8M0 output_scale [rows, H * D / 32] (dtypes.fp8_e8m0 or uint8) now
selects that output in pa_decode: FP8 bytes in the output's layout and
row-major scales, bit for bit the BF16/FP16 output of the same call
quantized as the split path did: code = ceil_pow2(max(amax, 1e-10) / 448)
(emit_mx_e8m0_scale RoundUp), values e4m3(clamp(x * 2^(127 - code), +-448))
after rounding to the output dtype. Padded bucket rows are FP8 zeros with
E8M0 1.0. A float32 [rows, 1] scale keeps the per-token output unchanged.

A 32-element group lies in one head row, so its maximum takes lane shuffles
only (kernels/pa_decode/op_mxfp8.py), no LDS, CTA or cluster exchange, and
the plan's split is kept in every output mode:

- NVFP4 wave tile: under the MXFP8 output each wave merges output tiles
  2 w, 2 w + 1 instead of w, w + 4 (dims 32 w + [0, 32)), so a group is a
  lane pair; direct rows, single-task rows of merging plans, empty and padded
  rows (Gfx1250OutputMxQuant);
- cluster merges of any size, clusters shared by several sequences, and the
  last-arriver merge: 8 lanes a group, no extra cluster barrier;
- the reducer (pa_decode_reduce_kernel_*_mxfp8[only]): 16 lanes a group with
  pairs; its FP8 / scale pointers take the unused sink slot so every
  argument still preloads, and it runs the XCD-contiguous grid: a token's
  64-byte scale row written by 16 CTAs spread over the XCDs cost 2.7 us at
  512 rows, nothing with the token's CTAs on one XCD.

Other tiles (FP8, BF16) take the reducer path and its epilogue. Padded rows
of plans whose kernel has no padding CTAs (last-arriver merge, shared
clusters, reducer) are filled after the launch. No sinks.

gfx1250 compile, no spills, no extra LDS: wave direct 212 VGPR, cluster
2/4/8 and merges 210, reducer np3/8/32 9/14/53 (as BF16). The existing tile
and reducer kernels (NVFP4 wave direct, cluster2 shared, cluster8, merge,
reducer-fed; per-token quant direct/cluster8; FP8 page16 direct and
cluster8 quant; reducer np3/8/32) compile to byte-identical ISA.

op_tests/test_flydsl_pa_decode_nvfp4.py: test_pa_decode_nvfp4_mxfp8_output
(direct prefill/decode, cluster8 c4/c24, cluster4, shared clusters 2 x4,
3 x4 and 8 x2, last-arriver merge, reducer np8; bf16/fp16; kept or skipped BF16 store;
padded and empty rows) against a torch reference and a copy of the split
quant kernel, and a __main__ benchmark (fused vs split vs BF16).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… groups and XCD-local rows for the fused split-KV reduce

The NVFP4 wave tile of pa_decode (MiniMax-M3 sparse decode: one length-1
sequence per (row, KV head), a top-k window of at most 32 pages) gains
three launch options. ATOM's sparse decode uses them to merge each row's
split-KV partials inside the paged attention (a cluster of 4 or 8 CTAs a
row, or one CTA a row) instead of the tile kernel plus the PS reduce:

- plan_free: no plan lookups in the tile prologue. The direct output runs
  one CTA a sequence; a cluster merge gives the sequence's tiles to
  min(P, tiles) CTAs split evenly, the planner's split for a plan of P
  tasks a sequence. `work` holds the context lengths. Every wave copies
  the sequence's page ids into LDS with an async load that issues with
  the context-length load, and the CTA splits the query into its FP8 terms
  once (through LDS) instead of once a wave.
- page_groups (2 or 4): that many groups of four waves a CTA take pages
  g, g + G, ... of the task and merge in LDS after the loop, so one CTA
  holds a whole top-k window with G x more pages in flight (BF16 / MXFP8
  output, no last-arriver merge).
- xcd_rows (plan-free): the direct and cluster grids are remapped so that
  xcd_rows consecutive sequences (one request's MTP rows, which share most
  selected pages) run on one XCD and share its L2; grids pad to whole XCD
  groups.

The wave pipeline also stops its loop at the page holding a one-token
row's last key and masks that page through the QK start value.
cluster_rows (2 or 4 sequences a plan-free cluster) maps onto the
cluster_seqs clusters pa_decode already has. None of the options changes
a row's math: one group and the plan's split give the planned launch's
bytes.

Ported from the validated stack onto this branch's pa_decode refactor
(cluster_seqs, step / run clusters, the reversed direct order): the
plan-free branches sit next to them and leave every existing mode
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

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

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

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

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

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

XiaobingSuper added a commit to XiaobingSuper/ATOM that referenced this pull request Nov 23, 2026
… the paged attention

With NVFP4 sparse K/V, decode rows merge their top-k window inside aiter's
FlyDSL paged attention instead of the tile kernel plus the separate PS
reduce kernel, wherever aiter's pa_decode can (page_groups / plan_free,
ROCm/aiter#8462). sparse_attn_nvfp4.fused_reduce_split picks the split: a
cluster of 8 or 4 CTAs a row while every row's cluster stays resident (two
wave groups at the 4-cluster bound), otherwise one CTA a row whose four wave
groups merge in LDS. The launch is plan-free, and a request's rows (which
share most selected pages) dispatch on one XCD. Prefill rows keep the split
path; both the BF16 and the MXFP8 (ROCm#3634) outputs are covered.

MI455X, C64 decode, CUDA graph, us per layer, fused vs split: 32 rows 4.6 vs
5.1, 64 rows 5.1 vs 6.5, 80 rows 6.3 vs 8.5, 128 rows 6.9 vs 8.6, 192 rows
8.5 vs 13.0, 256 rows 9.6 vs 13.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
XiaobingSuper and others added 2 commits November 25, 2026 03:11
Four cases, ATOM's fused_reduce_split regimes (cluster 8, cluster 4 with two page
groups, cluster 4, direct with four groups), each checking the BF16 output against
the FP32 reference, the MXFP8 bytes against quant(BF16), the quant-only call (ATOM's)
and its recorded relaunch against the same bytes, and the planned launch's bytes
where the split matches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants