Repository navigation
[FlyDSL] gfx1250 MiniMax-M3 decode indexer over the NVFP4 index cache: flat-plan scorer + top-k - #8817
[FlyDSL] gfx1250 MiniMax-M3 decode indexer over the NVFP4 index cache: flat-plan scorer + top-k#8817lirui927 wants to merge 9 commits into
Conversation
…index cache `aiter.ops.flydsl.index_score_decode.index_score_decode_nvfp4`: the decode indexer's block scores from the FP4 index cache, a drop-in for ATOM's Triton `_decode_index_score_transposed_kernel` (the same scaled WMMA pair for every dot, so the same bits). Triton scores a request in one-wave workgroups of a few blocks each and loads and splits the query in every one; at TP1 a request has 32 query rows (4 index heads x 8 DSpark rows), and that fixed cost dominates. Here a four-wave workgroup owns up to 64 blocks, converts the query once, streams each wave's quarter of a block global -> LDS (`global_load_async_to_lds`, a ring of pages in flight) and stores each row's blocks coalesced. The grid is sized by the batch (`WORKGROUPS_PER_CU` a compute unit). Shares PAGE / E4M3_MAX / LOG2E with `kernels.minimax_m3_index_score`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ave top-k `index_topk_decode_nvfp4`: the decode indexer in two launches, the scorer on a flat, length-proportional plan (a ragged batch's long requests get proportionally more workgroups) and `index_select_decode`, a FlyDSL port of ATOM's decode selector (`_topk_index_packed_kernel` with DECODE_MAX_Q, sparse table emit included): the same ids in the same order, the same table rows. A row's selection runs on four waves by default (`waves=1` stays available; same result). MI455X, profiler kernel time, bs 15 a rank, DSpark K = 7 (8 rows x 4 index heads), against ATOM's Triton scorer + selector, bit-exact: 88K 33.1 -> 19.4 us, 300K 83.8 -> 40.5 us, 600K 147.5 -> 65.9 us; bs 16 at 600K 92.5 -> 69.3 us, bs 48 at 300K 127.9 -> 92.0 us. The scorer runs at ~87% of HBM bandwidth. 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: |
…t dtype index_topk_decode_score_plane allocated the padded plane with torch's default dtype; a serving engine sets that to its model dtype (BF16), so the plane, and with it the scores the selector ranks, silently became BF16. Allocate it as float32. Same fix as XiaobingSuper's 3d9245e on xiaobingsuper/m31-c4-gfx1250-opt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…are the NVFP4 index helpers Remove what no caller reaches: the scorer's per-request plan (`flat`, the 2-D grid, `decode_score_programs`, the 64-block window), its `ring` parameter (RING = 4), the op's `workgroups`, the selector's one-wave build (`waves`), and the builders' unread "kernel" entry (they return the launcher). What the decode and the prefill index kernels share moves to two files that are byte-identical in ROCm#8458: kernels/index_nvfp4_gfx1250.py (the scaled WMMA, the E8M0 scale operand, the pins, sm_scale_log2e) and index_nvfp4.py (the cache predicate, the int32 metadata rule, the launch). Every build the ops launch is byte-identical to ddc4c43 (whole gfx1250 code object, kernel name normalised): the scorer at h4q8 / h4q1 / h1q8 / h5q3 and the selector at 11 (width, top-k, emit) builds. Not run on a GPU. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…nches on the same blocks Needs a GPU run: the selector's ISA changes by one instruction and both launches change path. - One `_inputs_supported` for the three ops, each term once, ranks before extents; one ValueError. New terms: every tensor on the score plane's GPU (the selector checked none), payload and scale with the same page count, the query's heads and rows against the plane, the emit needing a block table. - `index_topk_decode_nvfp4` hands both launches `min(score.shape[2], block_table.shape[1])`: the selector no longer ranks columns the scorer did not write, nor reads the table past its row. The selector's build stays keyed on the plane's width. `index_select_decode` takes the same bound when it is given a table. - An empty batch returns before the check (it raised on an empty plane); a zero-block plane still launches the selector (-1 ids, empty table rows). - Launches go through the shared `launch`: under the tensors' device, with `current_stream_arg` (0.1 us) instead of `torch.cuda.current_stream` (5 us). - Dropped: `score.stride(1) >= cols` (the storage bound covers it), the builders' re-checks of the wrapper's, the LDS bound of the deleted one-wave build, and the selector's clamp of a block count that cannot be negative (`s_max_i32 s, s, 0`: the only ISA change, scorer builds byte-identical). Co-Authored-By: Claude Fable 5.2 <[email protected]>
… constants, raw-op comments Test (591 -> 393 lines): one test through `index_topk_decode_nvfp4`, the op ATOM calls. Its scores are graded with checkAllclose against the FP32 reference within the WMMA envelope, with NaN poison and guard rows for what it must not write; its ids, sparse table and context lengths exactly against the torch model of ATOM's selector over the op's own scores (ties from repeated pages and zero query rows, a graph pad request in every ragged batch). Added as cells of that test: a block table narrower than the plane (a view, so the guard columns hold valid pages), the scorer's widest split (S = 128, by patching get_cu_num), a second device when there is one; and one small check that six bad inputs are refused before anything is compiled (arch faked, so it runs on any GPU). Gone with the knobs they swept: --only, -w, -r, --ragged, the per-request plan, the one-wave selector, and the separate tests of the two launches. The hand-written dequant stays: msa_nvfp4_ref rounds K to E4M3, which is not this kernel's K. Kernels: PAGE_SHIFT / BLOCK_SHIFT / SLOT_SCALES instead of `>> 7`, 2048, 512 and 256; the missing-API comment at the raw ballot / mbcnt_lo; no reference to files outside aiter. ISA unchanged (15 builds). Not run on a GPU. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…or are private to the fused op Only what ATOM calls stays public: index_topk_decode_nvfp4, its predicate and index_topk_decode_score_plane. The standalone scorer and selector ops, their predicates and the validation that existed for them alone go (the selector's max_query_len < 128 follows from the fused op's 32-row bound). The fused op's launches and their arguments are unchanged; the kernels are not touched. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…at every pages_per_block The emit clamps a row with no key (causal_len <= 0) for every pages_per_block, as ATOM's _emit_sparse_block_table_row does; it wrote a negative sparse_ctx at pages_per_block != 1. The test's reference follows, and its scores are computed on the CPU, one matmul a request (the GPU matmul did not repeat run to run). The docstrings name ATOM main's _decode_index_score_tiled_kernel; the plane check drops the 16-bit block bound the LDS bound already implies. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ard; comments Co-Authored-By: Claude Fable 5.2 <[email protected]>
…lpers with the decode indexer The scaled WMMA, the E8M0 scale operand, the selection pins and sm_scale_log2e come from kernels/index_nvfp4_gfx1250.py, added here byte-identical to ROCm#8817 together with index_nvfp4.py (the host side); the copy of pa_decode's `_wmma_scale16` and the duplicate E4M3_MAX go. The two ops' launch blocks become one `_launch`; the builder returns the launcher; the stale `_lds32` name suffix goes. Every build is byte-identical to 26e57d0 (whole gfx1250 code object, kernel name normalised): the scorer (256/4/4 and 128/2/2 fold_max pad_lds) and the fused build at pins (0,1), (2,3), (0,0), plain and 512x8; the launch arguments are unchanged. Not run on a GPU. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
review-pr scan (ROCm/aiter main, After the scan the description was corrected where the card's first finding quotes it: the Card and scan log at 123e5f0CardROCm/aiter PR #8817 — [FlyDSL] gfx1250 MiniMax-M3 decode indexer over the NVFP4 index cache: flat-plan scorer + top-kAdds a new gfx1250-only FlyDSL op, Review (advisory):
Scan log |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
What
aiter.ops.flydsl.index_score_decode(gfx1250 only, MiniMax-M3 lightning indexer, decode), one new op; no existing code path changes:index_topk_decode_nvfp4: the decode indexer ATOM calls, two launches. It scores the blocks of every request over the NVFP4 index cache, then selects each row's top-k blocks and (optionally) emits the attention's sparse block table and context lengths.index_topk_decode_score_planemakes its score plane.global_load_async_to_lds, a ring of 4 pages in flight). Every dot is onev_wmma_scale16_f32_16x16x128_f8f6f4pair on the raw e2m1 keys and their E4M3 scales, the query as two E4M3 terms. The grid is length-proportional: a ragged batch's long requests get proportionally more workgroups._topk_index_packed_kernelin decode mode (forced init / local blocks,_pack_score_keyorder, -1 pads) with the sparse page-table emit, four waves a row.index_topk_decode_nvfp4_supported(...)says what the fused op serves; the op raisesValueErrorotherwise, before anything is compiled.Why
At TP1 with DSpark (K = 7) a request has 32 query rows (4 index heads x 8 rows). ATOM's Triton decode scorer reloads and splits the query in every one-wave workgroup of a few blocks; here a workgroup converts the query once for up to 128 blocks.
What serves gfx1250 decode on main today is ATOM's Triton scorer and selector: main's FlyDSL
score_flydsl_nvfp4is gfx950-only (SUPPORTED_ARCHS = ("gfx950",)), so there is no main-path A/B to run.Design questions from the review
topk_per_row_small_k. Same chunk-maximum narrowing, but the decode selection needs four things that op does not have: ATOM's exact tie order at the k-th place (score, then the larger block id,-0.0as0.0, a NaN under-inf), the row's validity and pins computed fromseq_lensin the kernel, a strided 3-D plane read in place, and the sparse-table emit in the same launch.index_topk_decode_score_plane), one build a plane; the block count both launches use is a runtime argument,min(score.shape[2], block_table.shape[1]).kernels/index_nvfp4_gfx1250.py(the scaled WMMA, the E8M0 scale operand, the pins,sm_scale_log2e) andindex_nvfp4.py(the cache predicate, the int32 metadata rule, the launch) are byte-identical in both PRs' heads (same blob hashes), so neither depends on the other and whichever lands second merges cleanly.What changed in this revision
flat=False, 64-block window, 2-D grid), theringandworkgroupsparameters, the one-wave selector (waves), the builders' unread"kernel"entry, the scorer's always-true row guard and a host bound the LDS bound already implies.index_topk_decode_nvfp4,index_topk_decode_nvfp4_supported,index_topk_decode_score_plane). Their standalone entries, predicates and validation are gone (index_score_decode.py445 -> 326 lines).score.shape[2]while the scorer clamped to the table's width: with a table narrower than the plane the selector ranked unscored columns and the emit read the table past its row.pages_per_block, as ATOM's_emit_sparse_block_table_rowdoes; it was negative atpages_per_block != 1.current_stream_arginstead oftorch.cuda.current_stream.index_topk_decode_nvfp4(591 -> 392 lines); its FP32 reference scores are computed on the CPU.Performance
One idle MI455X at this head, the
uscolumn ofpython3 op_tests/test_flydsl_index_score_decode_nvfp4.py(one run;run_perftest's profiler device time of the op's two launches, host wrapper time excluded; top-k 16, emit 1x1):Batch 15, 88K ragged, top-k 13, page-16 emit (8x16): 13.2 us, also without a baseline: no Triton run was timed at this head.
Not covered
PR Self-Review
Reviewed revision
123e5f0
Behavior and intent
index_topk_decode_nvfp4,index_topk_decode_nvfp4_supportedandindex_topk_decode_score_plane; no existing op changes.ValueErrorand before compiling, any layout its bare pointers cannot address.Validation and unverified scope
rocm/fw-bringup:gfx1250-minimax-m3-20261112, FlyDSL 0.5.3, at this revision:python3 op_tests/test_flydsl_index_score_decode_nvfp4.pyexits 0; 24 / 24 cells passcheckAllclose(atol 1.0) with err 0 and the exact id / table / length asserts. The same command also exited 0 twice at a52932e.ValueErrorbefore a builder is called; 7 inputs that must be served are (empty batch, empty plane, narrow table, zero-block table, no emit, FP8-typed scales, over-long buffers).python -m black --checkandruff check --no-cache(0.16.0) on the six files: clean.Changed op tests
op_tests/test_flydsl_index_score_decode_nvfp4.py(new): one test throughindex_topk_decode_nvfp4(scores within the WMMA envelope withcheckAllcloseagainst an FP32 reference computed on the CPU; ids, table and lengths exact; NaN / -7 poison and guard rows for what must not be written), with cells for a narrow block table, the scorer's widest split, more than a wave of requests, a second device when there is one, and one refusal check.