Repository navigation
[FlyDSL] [Perf] gfx1250 NVFP4 sparse decode: plan-free launches, wave groups and XCD-local rows for the fused split-KV reduce - #8462
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
… 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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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;workholds the context lengths.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 thatxcd_rowsconsecutive 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 thecluster_seqsclusterspa_decodealready has.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):
At C64-shaped decode (CUDA graph, us/layer, fused vs split), with the split ATOM's policy picks:
Correctness
op_tests/test_flydsl_pa_decode_nvfp4.py::test_pa_decode_nvfp4_plan_freecovers direct and cluster launches (P 2/4/8), 1/2/4 wave groups, XCD remap, f16 and bf16 queries, short contexts,store_outputon/off and padded rows.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 onlirui927's ROCm/ATOM#3581 / #3634.Port onto #8365
#8365's branch carries main's
pa_decoderefactor: 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:const_exprbranches beside the existing cluster and direct ones. The existing branches are untouched.cluster_rowsmaps ontocluster_seqs, and the cluster merge isGfx1250ClusterMergeunchanged; K4's own multi-sequence merge is dropped.xcd_rowsnow requiresplan_free, andplan_freetakes only the BF16 and MXFP8 outputs, not the FP32 per-token one. Those are the only combinations ATOM uses._VALIDATED_LAUNCHEScache, and one unused variable is gone.Validation status
py_compile, black, and ruff (E4/E7/E9/F) are clean.🤖 Generated with Claude Code