Repository navigation
[FlyDSL] M3 index score: NVFP4 prefill scorer (score_prefill_flydsl_nvfp4) - #7814
Conversation
Decode block scorer over an NVFP4 index cache: the same e2m1 data view as the MXFP4 path, but one e4m3 scale byte per 16 elements (8 per token, 9216 B per 128-token page) and no per-tensor scale; Q is e4m3 or bf16. Two numerics, selected by k_round: - "e4m3" (default): K = e4m3_rn_satfinite(e2m1 * scale) through a per-CTA LDS table of the 8 e4m3 values of every scale byte, scored on the fp8 MFMA with an e4m3 Q; bit-identical to vLLM's NVFP4 indexer. - "exact": K = e2m1 * e4m3 scale, unrounded. The product is exact in f16 and so is an e4m3 Q, so with an e4m3 Q the K dwords are converted straight to f16 pairs and scored on the f16 MFMA; a bf16 Q uses the bf16 MFMA. Not bit-identical to vLLM, which rounds K to e4m3. Page ids are read into an SGPR so the K buffer descriptors need no waterfall loop; the causal mask is skipped on tiles whose tokens are all visible; the f16 scale pair is built with one u24 multiply; and a depth table for S8H4 batches 3..16 is selected through geometry(..., nvfp4=True) so MXFP4 work maps do not move. The e4m3 table and widen helpers are module-level so the prefill scorer can reuse them. Co-Authored-By: Claude <[email protected]>
…vfp4) Depends on the NVFP4 decode scorer PR: it reuses that kernel's e4m3 table and e2m1 widen helpers, so the two cannot disagree on the bits of K. Prefill block scorer over the same NVFP4 index cache as the decode scorer (e2m1 data view, one e4m3 scale per 16 elements, no per-tensor scale). k_round="exact" (default) keeps K = e2m1 * scale unrounded: the page is widened to f16 in LDS (one convert and one packed multiply per element pair, no table) and scored on the 16x16x32 f16 MFMA with an e4m3 Q. The 256-row 4-wave tile uses lane-spread, staged score stores. k_round="e4m3" rounds K to e4m3 like vLLM and is bit-identical to it. The page is widened once per CTA through a per-CTA LDS table of e4m3_rn_satfinite(mag * scale) and scored on the fp8 MFMA. On shapes with enough tiles the CTA takes a 512-row tile (4 waves x 128 rows, Q resident in registers, staged in rounds), an explicit MFMA/VALU interleave, lane-spread stores staged into aligned 64 B pieces, and an async raw-page DMA pipeline: the e2m1 page and scale bytes land in LDS by buffer-to-LDS DMA with counted waits (asyncmark), the dependent scale-table lookups are issued right after the first tile's MFMAs and the widen pieces are spread over later tiles, and the block table is read through the constant address space. The register-bounce path stays for the small shapes, where an SMEM lookup measured slower. Public signature and page format match the other prefill scorers. Co-Authored-By: Claude <[email protected]>
Extends the existing decode index-score op test with the NVFP4 scorer. No pytest in the added code: `check_nvfp4_*` functions run through the file's own runner, like the MXFP4 checks next to them. - A torch oracle (e2m1 x e4m3 scale, unrounded and rounded to e4m3) and a torch NVFP4 page writer, since this change has no NVFP4 write kernel. - A minimal matrix, both k_round values and both Q dtypes: oracle match on page and tile boundaries, ragged and empty requests; bit-exact on exact-sum data; tail pages; scale range and saturation; the NVFP4 depth table; e4m3 Q equals bf16 Q on the exact arm; split vs single-region views; repeat launches bitwise identical; the default k_round is "e4m3"; modes do not share a compiled kernel; rejections. - An @benchmark table (us, TFLOPS, TB/s, err per k_round) in the decode sweep. The wider regression matrices stay out of the test file. Co-Authored-By: Claude <[email protected]>
Extends the existing prefill index-score op test with the NVFP4 scorer. No pytest in the added code: `check_prefill_nvfp4_*` functions run through the file's own runner, like the MXFP4 prefill checks. - A torch oracle that dequantizes the NVFP4 cache itself (K = e2m1 x e4m3 scale, unrounded or rounded to e4m3) and a torch page writer, since this stack has no NVFP4 write kernel. Exact-sum data makes every fp32 partial sum exact, so the comparison is bit for bit whatever the accumulation order. - A minimal matrix: page and tile tails, a prefix-only and an empty request, H = 1/4, both Q dtypes, the 16- and 32-wide MFMA, the 512-row DMA tile and the 8-wave tile, both k_round values; random data against aiter's fp8 scorer on the e4m3 arm; split vs single-region views; the default k_round is "e4m3"; modes do not share a compiled kernel; rejections. - An @benchmark table (us, TFLOPS, TB/s, err per k_round) after the MXFP4 one. The wider regression matrices stay out of the test file. Co-Authored-By: Claude <[email protected]>
…ork-map test non-vacuous index_score_supported_nvfp4 passed k_round=None straight to the shared validator, which reads None as an MXFP4 cache, so the predicate said True for arguments that score_flydsl_nvfp4 rejects. Return False unless k_round is one of NVFP4_ROUNDINGS. The tuned-work-map refusal check fed NVFP4 scale views to the MXFP4 scorer, which refused them on shape before looking at the work map. Use real MXFP4 views, check the shared map is accepted and the tuned one is refused with a message naming work_map. Host-side and test-only; kernel outputs are unchanged. Co-Authored-By: Claude <[email protected]>
bench_score_nvfp4 passed a shared (MXFP4) work map, which score_flydsl_nvfp4 keeps as-is, so the benchmark never ran the NVFP4 depth-table launch that the default scorer picks (S8H4, batch 3..16). Build the map with nvfp4=True. Co-Authored-By: Claude <[email protected]>
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 |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (5)
- Rebase onto #7813's current head and land it after #7813. The branch merges #7813 at
cf804109e, one commit behind its head80ff1e7ee(the NVFP4 work-map benchmark fix), sogit diff 80ff1e7ee..HEADshows that fix reverted inop_tests/test_flydsl_minimax_m3_index_score.py:2834. No CI has run on this PR yet (onlyevaluate). aiter-bot's PR Self-Review also still lists every section as missing. While editing the description, add one line saying NVFP4 is MiniMax-M3.1's native fp4 index format, so the reason it is needed despite being slower than MXFP4 is visible here too. - Fix the docstrings that say bf16 where the exact arm uses f16. Fix
minimax_m3_index_score_prefill.py:398("widens it to bf16") and:1562("16x16x32 bf16 MFMA"), andtest_..._prefill_fp4.py:854("bf16 MFMA"). The code usesfx.Float16andMFMA(..., fx.Float16). Also fixnv_case(test:642), which says scales are in [0.5, 2), but bytes 0x30..0x47 give [0.5, 3.75]. - Remove the new references to vLLM internals and to the out-of-tree matrix. These are new instances of the ask on #7813: kernel
:45,:777,:1181-1183,:2616; test:19,:547,:552,:595,:786,:899("vLLM's_quant4", "the kernel's partition is vLLM's", ...). Alsotest:1132says "the full regression matrix lives outside this file". In their place, state the rule: RNE e4m3 of min(amax·RN(1/6), 448) per 16 elements, then RNE e2m1, plus the_k32_chunkgrouping. - Make the LDS check count the NVFP4 fields, and drop the legacy
buffer_opsimport. Atminimax_m3_index_score_prefill.py:539-541the_LDS_LIMITguard runs beforelut/stg/raware added. After that,_total += _lut_bytesis never read. The 512-row DMA tile actually needs about 76.8 KB against the 64 KB budget (it fits in gfx950's 160 KB, so the guard is just misleading). Check the full total against the real limit.:35/:1009import the legacykernels.buffer_opsonly forget_element_ptr.aiter/ops/flydsl/AGENTS.mdsays new code uses the FlyDSL pointer/buffer API, so use it, or add a comment at the call naming the missing API. - Cover the new dispatch arms in the test, and share the NVFP4 oracle with the decode test.
check_prefill_geometry_arms_are_exhaustive(test:332) only walks the MXFP4geometry. Addgeometry(..., xwide=True)andexact_geometryso a change to the_use_xwidethresholds cannot leave an arm untested. Add an empty request (e.g.([5, 0, 7], ...)) towide(test:1143); the DMA tile never seesql = 0.e2m1_encode/nv_product/nv_pack/nv_quantize(test:561-613) copytest_flydsl_minimax_m3_index_score.py:2455-2528; import them. That also removes theE2M1redefinition (test:395list vs:555tuple).
Step 0 is fine: the NVFP4 path extends build_prefill_score(nvfp4=) and the shared _score_prefill_impl and reuses #7813's e4m3 table and widen helpers instead of adding a parallel builder. The oracle is an independent torch dequant + einsum, main() gates on gfx950, and the description has a 32-shape table against vLLM and MXFP4.
Reviewed at 44fee06 (own commits 4db0df7, 9de7817; base #7813, not merged).
Module and build_index_score docstrings described one arm; spell out the bf16-Q, e4m3-Q/"e4m3" (fp8 MFMA) and e4m3-Q/"exact" (f16 MFMA) routes, say scale bytes are non-negative and not 0x7F, fix the depth-table comment (depth 2 for batches 3-4, depth 3 for 5..16) and drop references to vLLM internals and an unnamed microtest. Comments only. Co-Authored-By: Claude <[email protected]>
…rences exact_sum_case scale range is [0.5, 3.75] (bytes 0x30..0x47) and its sum bound 2^14; check_nvfp4_bit_exact only asserts; replace references to vLLM internals and an out-of-tree regression matrix with the rule itself and the tests that pin it. Comments and docstrings only. Co-Authored-By: Claude <[email protected]>
fp8_dwords_to_bf16 and fp8_dwords_to_f16 were the same loop with a different intrinsic and element type. One helper, fp8_dwords_widen, takes the output dtype; the e4m3-Q NVFP4 loader drops its duplicated branch. Generated ISA of all 65 kernels the op test builds is byte-identical. Co-Authored-By: Claude <[email protected]>
The decode module folded fp8_dwords_to_f16 into fp8_dwords_widen; follow it. No behaviour change. Co-Authored-By: Claude <[email protected]>
…eferences The NVFP4 exact arm scores on the f16 MFMA; two docstrings said bf16. State the numeric rule (RNE e4m3 of e2m1 * scale, saturating at 448, and the _k32_chunk grouping with the tests that pin it) instead of pointing at vLLM internals. Comments and docstrings only. Co-Authored-By: Claude <[email protected]>
The guard ran before the scale table, score staging and DMA landing zone were added, and the later `_total += _lut_bytes` was never read. Check the full sum against gfx950's 160 KB (measured group_segment_fixed_size: 76800 B for the 512-row DMA tile, 77824 B for the exact 256-row tile; both pass, so no behaviour change) and say why the one legacy buffer_ops GEP stays. Co-Authored-By: Claude <[email protected]>
…he decode oracle check_prefill_geometry_arms_are_exhaustive now also walks geometry(xwide=True) and exact_geometry. That found an arm no case reached (exact, 128-row tile), so nvfp4_exact_every_shape runs on every GEOM_SHAPES entry. `wide` gains an empty request ([5, 0, 7]) for the DMA tile. The NVFP4 quantizer / pack / cache helpers are imported from the decode test instead of copied (which also drops the duplicate E2M1 and unused NV_ROUNDS). Docstrings say f16 where the exact arm uses f16, the nv_case scale range is [0.5, 3.75], and vLLM / out-of- tree-matrix references are replaced by the rule itself. Co-Authored-By: Claude <[email protected]>
|
Thanks @valarLip. All five items are addressed at head ef9caca (a merge of #7813's current head plus 4 fix commits; the description now has the self-review sections the bot asked for). Item 1 (rebase onto #7813's current head; benchmark fix reverted; description line). Done. I merged #7813's current head 6e6f677 (which contains 80ff1e7 and the three #7813 review fixes) into this branch instead of rebasing, so there is no force push and the history of the earlier review stays; Item 2 (bf16 vs f16; Item 3 (vLLM internals, out-of-tree matrix). Fixed in 5a1174bd17 (kernel Item 4 (LDS guard; Item 5 (dispatch-arm coverage, empty request, shared oracle). Fixed in 8101d21aaf. |
…ch geometry Reuses the MXFP4 every-geometry check (token split, ppw 2/4, non-served nt2 arms), checks ValueError on the int8 and wide-stride scale views, and folds nvfp4_single_region_views into single_region_views (scale width from the view). Co-Authored-By: Claude <[email protected]>
… scale-byte contract, derive the raw-slot sizes score_prefill_flydsl takes a keyword-only nvfp4 again instead of a 11-argument wrapper over _score_prefill_impl. The NVFP4 scale-byte contract reads as the decode scorer's (non-negative, zero allowed, 0x7F out of contract), and the module header no longer says NVFP4 keeps the fp8 compute for k_round="exact". The DMA raw slot sizes come from PAGE, WAVES and the byte constants; the vector score store predicate no longer repeats `full`. Co-Authored-By: Claude <[email protected]>
SHORT_TAILS is written out instead of picked by index from a 17-entry list. The forced m32=1 tail cases are removed: every one hit "m32 needs an even FEAT_TILES_PER_WAVE", returned early and counted as PASS, and the forced m32=0 ones ran the geometry the selector already picks. The 32-wide shape stays covered by nvfp4_every_geometry. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Fix the e4m3-arm layout comments, which describe the wrong element order. The module header (
minimax_m3_index_score_prefill.py:39-43) says NVFP4 "takes the fp8 path's compute unchanged" and widens into "32 e4m3 bytes in natural element order". The commit_page comment at:1259says "Natural element order" too. In factfp4_dword_to_e4m3emits each 8 elements as evens then odds, andstage_q_ldspermutes Q to match (:788-798,perm_b32 0x06040200/0x07050301). Only the exact/f16 widen (:1313) is in natural order. Say "evens-then-odds per 8 elements; Q is permuted to match", and drop "unchanged". - Correct the test comment that claims the 8-wave tile. At
test_..._prefill_fp4.py:1220,(GEOM_SHAPES[2], GEOM_SHAPES[5]) # a 128-row and the 8-wave tileis wrong.(8, 2048, 16384)has max_block 128 and 4·8·1 = 32 tiles, so_use_xwidepicks the 512-row DMA tile. That leaves the 8-wave/256-row NVFP4 e4m3 arm with no bit-exact case. Either add a shape that reaches that arm (non-xwide, ≥ CU-count CTAs) or fix the comment. Then letcheck_nvfp4_geometry_arms_are_coveredalso walk the non-xwidegeometry(..., xwide=True)arms, the way the MXFP4 check does. - Update the description and finish the small cleanups. The description still says "Review the two last commits only" (there are now 13 own commits, including three merges of #7813), and "Scale bytes must be positive e4m3 and not 0x7F", which the docstring now words as "non-negative ... zero is allowed". The Self-Review "Reviewed revision" is still dab3ee3. In code:
fx.Int32(1024 * h)at:1390/:1429isRAW_DATA // 2and should be named that.:2371-2372raises "nvfp4: k_round must be one of …" when the actual problem is a missingk_scale, so split the two checks. In the test,nv_ref_ofisc[k_round], andcheck_prefill_nvfp4_tails/_exact_tails/_every_geometry/_exact_every_shapeare one-line forwards tocheck_prefill_nvfp4_bit_exact. Passk_roundthroughbuild_casesinstead (about -18 lines).
Merge after #7813 (unmerged; its head 9a5d21b is in this branch). CI at head is not done: 19 pass, and the 8 Standard Tests (1 GPU) MI35X shards of run 43752203867 have been queued since 11-15 19:24.
Re-reviewed at bd6a4a2. Already fixed: _score_prefill_impl folded into score_prefill_flydsl(*, nvfp4=None) (1); prefill_tail_cases() and the forced-m32 early return are gone, SHORT_TAILS is literal, and the 32-wide MFMA is still reached naturally by (8, 512, 2048) (2); scale-byte docstring matches decode and the header names the exact arm (3, code part); vec_pred and RAW_DATA/RAW_SCALE (4, code part).
|
@valarLip, re-review of 11-15 17:51, point by point. Pushed head is now bd6a4a2 (fast-forward of dab3ee3): two commits for this review, b6e1fc6 and a584346, plus a merge of #7813's current head 9a5d21b. The description is updated to match.
On the merged tree the decode op test also passes (193 checks, 0 FAIL). Not re-measured: the performance tables quoted in the description (it keeps the earlier runs), and CI's ruff 0.16.0. |
…LDS/barrier comments, restore score_flydsl docstring load_q8_lifted is only called under f16_arm, so its dtype and the MFMA dtype are plain Float16. The "no LDS, no barrier" comments now name the fp8 arm's scale table and its barrier. Final ISA of 56 NVFP4 e4m3-Q kernels is identical before and after. Co-Authored-By: Claude <[email protected]>
…r both builders Co-Authored-By: Claude <[email protected]>
…ALF, split the nvfp4 / k_scale checks The module header and the commit_page comment said the NVFP4 e4m3 page is widened in natural element order and is exactly an fp8 page; it is evens then odds per 8 elements (fp4_dword_to_e4m3), with Q permuted to match in stage_q_lds. Only the exact (f16) widen is in natural order. The 1024 B offset of the second DMA pass is RAW_HALF. A missing k_scale with nvfp4 set no longer reports a bad k_round. Co-Authored-By: Claude <[email protected]>
…he one-line NVFP4 forwarders (8, 2048, 16384) takes the 512-row DMA tile, not the 8-wave tile. nv_ref_of was c[k_round]; the tails / every-geometry / exact cases call check_prefill_nvfp4_bit_exact through build_cases (same 160 case names). Adds the missing-k_scale rejection. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
…ometry arm nvfp4_every_geometry ran only (8, 512, 2048) and (8, 2048, 16384), and the latter takes the 512-row DMA tile, so the 8-wave tile had no bit-exact case. It now runs every GEOM_SHAPES entry plus (8, 1024, 32768) (8 waves, 4 pages per wave), and the arms check requires a case for every arm geometry(..., xwide=True) reaches, not only the DMA ones. Co-Authored-By: Claude <[email protected]>
|
Round 4, head
Evidence, MI355X, flydsl 0.5.0: prefill op test 165 PASS, 0 FAIL, 0 SKIP (was 160); #7813's test on the merged tree 193 PASS, 0 FAIL, 0 SKIP. Kernel ISA unchanged by the merge and the comment/constant changes: offline compile of 56 kernels (38 NVFP4) identical, and the 50 kernels the op test dumps on the GPU identical, plus 3 new kernels from the new shape. Not run: perf, CI's ruff 0.16.0 (ruff 0.17.3 and black 26.10.1 clean). The red @valarLip @valar-cop re-review at |
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
any measured nvfp4 prefill with max_query_len < 512? e.g. B=32,H=1,q=1,ctx 16K
ci green.
|
|
||
|
|
||
| @cache | ||
| def _use_xwide(max_query_len, batch, heads, max_block) -> bool: |
There was a problem hiding this comment.
for max_query_len <= 128 this is 1 query tile, same as the 256/128 tiles, so no page read saved? gate on max_query_len > _WIDE_CTA_TILE_Q or measure small-q shape?
There was a problem hiding this comment.
Right, and it was a regression, not just no saving: q <= 256 took the 512-row tile (b32/H1/q1/ctx16K: 33.6 us) and ran 1.6-1.7x slower than the 8-wave / tile_q 256 CTA (19.8 us). Fixed in abd26fd: _use_xwide needs max_query_len > _WIDE_CTA_TILE_Q. Outputs bit-identical on every changed shape, offline ISA of all 56 kernels identical, op test 165 PASS. q 384-640 is mixed and left as is.
| out=None, | ||
| k_scale=None, | ||
| *, | ||
| nvfp4=None, |
There was a problem hiding this comment.
docstring still says only MXFP4, no mention of nvfp4? public entry point, please add one line on the nvfp4 mode
There was a problem hiding this comment.
Fixed in 7c997ce: score_prefill_flydsl's docstring now says what nvfp4= ("e4m3" / "exact") selects and the NVFP4 views.
| ) # pages per wave forced on the WIDE cases; None keeps the selector's | ||
|
|
||
|
|
||
| def check_prefill_nvfp4_xwide(qls, seqs, heads, qdt, ppw): |
There was a problem hiding this comment.
single-shot launches only.. a missed wait_asyncmark in the DMA pipeline is nondeterministic, add a repeat check like the decode suite?
There was a problem hiding this comment.
Fixed in 872c725: every bit-exact NVFP4 case (DMA tile, 8-wave, tails, exact) launches 8 times and must return the first launch's bytes. With wait_asyncmark(0) weakened to (1) in the DMA loop on a scratch tree, the old test passed 3 of 3 runs, the new one failed in 2 of 3 (nvfp4_every_geometry_b8_q2048_ctx16384, launches differ); a missing wait cannot be forced to show every time.
…s of 256 rows or fewer A query of 256 rows or fewer is one tile for the 8-wave / tile_q 256 CTA too, so the 512-row tile saves no page read there, and it measured 1.6-1.7x slower (NVFP4 e4m3, ctx 16K/32K, batch 1-32, H 1-4, q 1-256: e.g. b32/H1/q1/ctx16K 33.6 -> 19.8 us). _use_xwide now also needs max_query_len > _WIDE_CTA_TILE_Q (_XWIDE_MIN_QUERY_LEN). The test's _with_xwide forces the new threshold too; the near-int32 window case runs on the forced 512-row tile and on the tile the selector now picks. Co-Authored-By: Claude <[email protected]>
…fill_flydsl's docstring Co-Authored-By: Claude <[email protected]>
…, judge the unrounded-K check with checkAllclose Every bit-exact NVFP4 case now launches 8 times and requires the first launch's bytes every time (a missed wait_asyncmark in the DMA pipeline races, and one launch passes). The exact-arm random-data check used its own max-relative-error assert; it now goes through checkAllclose like the other checks (rtol 4e-6, atol 4e-8). Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The intertwined gfx950 DMA/LDS synchronization and MFMA scheduling require human assessment backed by head-matched GPU correctness and performance validation unavailable in this static-only review.
No open issues 🎉
Review effort: Balanced
|
Round 5, head
Op test on one MI355X, flydsl 0.5.0: prefill 165 PASS / 0 FAIL / 0 SKIP; #7813's test file 193 PASS; ruff 0.17.3 and black clean. Not run: any end-to-end effect, large-q shapes re-timed (unchanged by construction), CI's ruff 0.16.0. The @valarLip @valar-cop re-review at |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- Update the Q-staging comments that this PR's
Q_BOTH/stage_q_lds(rnd)change made stale. The code now has three cases. Q sits in page buffer 1 while it fits one page (fp8 tile 128, exact tile 256). It gets its own object only for fp8 tile 256 (Q_OWN). On the 512-row tile it is staged inQ_ROUNDSpasses through both page buffers (Q_BOTH,Q_LDS_BASE = 0). Three places still describe the old two-case layout:minimax_m3_index_score_prefill.py:24-26(module header): "Q takes an LDS object of its own past tile_q 128".:726-729: "Past tile_q 128 Q is larger than a page buffer and gets its own LDS object".- the
stage_q_ldsdocstring (:752-778). It says "Fill page buffer 1" and "costs no LDS". It says the readback is rows[wave*FEAT_TILES_PER_WAVE*16, +…), but rows are now per round (wave*QS_ROUND_ROWS). It never explainsrnd.
- Drop the redundant disjunct in
Q_BOTH(:466).Q_ROUNDS > 1can only be true whenTILE_Q > 256 and not k_fp4, so the line is justQ_BOTH = TILE_Q > 256 and not k_fp4. Also,:540says the LUT covers "every scale byte", but it hasLUT_ENTRIES= 128 entries, for the non-negative bytes (sign masked).
Comment-level only, so no blocker. CI is green at head (31 pass, 27 skipped, including all 8 Standard Tests (1 GPU) MI35X shards). Merge after #7813, which is still open; its head 499b0e0 is already in this branch.
Re-reviewed at 872c725. Already fixed: e4m3-arm order comments now say evens-then-odds with Q permuted (header :38-46, :1268), and only the exact arm is natural order. (8, 1024, 32768) reaches the 8-wave tile, and the arms check walks geometry(..., xwide=True). The description has 16 own commits + 4 merges, "non-negative, zero allowed", and Reviewed revision 872c725. RAW_HALF. The nvfp4 / k_scale checks are split (:2386-2389). nv_ref_of and the one-line forwarders are gone. valar-cop: _use_xwide now gates on max_query_len > 256, with small-q numbers given (1.6-1.8x faster); the nvfp4= docstring; REPEATS = 8 launches compared against the first, each into a fresh SENTINEL buffer. Copilot: checkAllclose in exact_random.
Depends on #7813 (the NVFP4 decode scorer): it reuses that PR's e4m3 table and e2m1 widen helpers so the two scorers cannot disagree on the bits of K. This branch is stacked on the decode one: it has 16 commits of its own plus 4 merges of #7813 (44fee06, 8de660a, bd6a4a2, e7918ed);
git rev-list --no-merges --count 499b0e0f45..HEAD= 16 and--merges= 4, counted from #7813's head 499b0e0, so the diff againstmainalso carries #7813's changes until that lands.NVFP4 is MiniMax-M3.1's native fp4 index format, which is why this scorer is needed even though it is slower than MXFP4 (e4m3 arm geomean 1.097x the MXFP4 prefill time on the 24 shapes below, exact arm 1.926x).
Summary
Adds the prefill block scorer for the MiniMax-M3 lightning indexer over an NVFP4 index cache, next to the fp8 and MXFP4 prefill scorers:
score_prefill_flydsl_nvfp4, exported asminimax_m3_index_score_prefill_nvfp4_flydsl. Same operator as the other prefill scorers (score[h, r, p] = max over the 128 tokens of page p visible to row r of dot(K, Q) * scale), new page format. gfx950 only.Page format
One NVFP4 index page is 9216 B: 128 tokens x 64 B of e2m1 codes (two 4-bit codes per byte, low nibble = even element) = 8192 B, followed by 128 tokens x 8 B of e4m3 scales = 1024 B. One scale per 16 elements, no per-tensor scale. Q is e4m3 (bf16 is accepted). The scorer reads the two regions as separate views (
k_data [pages, 128, 64]uint8 andk_scale [pages, 128, 8]uint8, each with its own page stride), so a single[pages, 9216]allocation works. Scale bytes must be non-negative e4m3 (the sign bit is not read; a zero scale gives K = 0) and not 0x7F, as for the decode scorer; contents are a caller contract, shapes, dtypes and strides are validated.Numerics:
k_roundk_round="e4m3"(default): K = e4m3_rn_satfinite(e2m1 x scale), as vLLM's NVFP4 indexer. The page is widened once per CTA through a per-CTA LDS table and scored on the fp8 MFMA. Bit-identical to vLLM's NVFP4 prefill indexer when both run the same MFMA shape: 51 forced-16-wide cases (8,994,678 live slots), the same 51 on the 512-row tile, 15 forced-32-wide cases (4,768,890 slots) and five real-size shapes that select the 512-row tile on their own (B4/q8192/ctx32K, B16/q2048/ctx32K, B2/q8192/ctx128K, H=4 q4096/ctx16K, q8200 with an 8-row tail tile, H=2): 100.000% bit-equal in every group, live-slot sets identical. With both scorers on their automatic choice 99.772% of live slots are bit-equal (inferred, not further characterised: the two dispatchers choose by different rules, so some shapes pair our 32x32 kernel with vLLM's 16-wide one and the sums round differently).k_round="exact": K = e2m1 x scale, not rounded; with an e4m3 Q (a bf16 Q is rounded to e4m3 first in every prefill scorer here) the product is exact in f16, so the page is widened to f16 in LDS and scored on the 16x16x32 f16 MFMA. Not bit-identical to vLLM; top-k block overlap with vLLM's scores (synthetic random-normal data quantized to NVFP4; the e4m3 arm is 1.0):What changes
aiter/ops/flydsl/kernels/minimax_m3_index_score_prefill.py(+898/-80). e4m3 arm: on shapes with enough tiles and a query longer than 256 rows a 512-row tile (4 waves x 128 rows, Q resident in registers, staged in rounds), an explicit MFMA/VALU interleave, lane-spread stores staged into aligned 64 B pieces, and an async raw-page DMA pipeline (e2m1 page and scale bytes go to LDS by buffer-to-LDS DMA with counted waits, the scale-table lookups are issued after the first tile's MFMAs and the widen pieces are spread over later tiles, the block table is read through the constant address space). Smaller shapes keep the register-bounce path with the 16- or 32-wide MFMA. exact arm: a 256-row 4-wave tile with lane-spread staged stores. Public signature and page format match the other prefill scorers.aiter/ops/flydsl/__init__.py(+5): the lazy export.op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py(+645/-6): see Tests.No csrc, no tuned CSV (
aiter-config-shapedoes not apply).Performance (prefill, vs vLLM)
One MI355X, same process, interleaved, 7 repetitions, two runs. Shapes are (B, q = new tokens per request, ctx = context);
mxis aiter's MXFP4 prefill scorer,vllmthe MiniMax-M3 NVFP4 prefill indexer of our vLLM tree (models/minimax_m3/amd/ops/nvfp4_index_prefill, unmodified). TFLOPS counts 2 x (query, block) pairs x 128 x 128. Ratios by mean time (below 1 = faster than vLLM). For scale, a pure fp8 GEMM measured on the same card (hipBLASLt, 16384^3 shape family) tops out at 3.16 PFLOPS at K = 8192 (4.38 PFLOPS microbenchmark peak); the largest e4m3 shape here (B16/q8192/ctx128K) is at 2.64 PFLOPS, vLLM 2.65.24 shapes:
exact/vLLM time ratio: geomean 1.585, worst 1.887, best 1.151, slower than vLLM in 24 of 24 shapes
e4m3/vLLM time ratio: geomean 0.903, worst 1.019, best 0.744, slower than vLLM in 2 of 24 shapes
shapes where exact is slower than vLLM (mean of the two runs):
(1, 512, 4096) exact/vLLM = 1.151
(1, 512, 32768) exact/vLLM = 1.404
(1, 512, 131072) exact/vLLM = 1.475
(1, 2048, 4096) exact/vLLM = 1.729
(1, 2048, 32768) exact/vLLM = 1.599
(1, 2048, 131072) exact/vLLM = 1.558
(1, 8192, 32768) exact/vLLM = 1.569
(1, 8192, 131072) exact/vLLM = 1.871
(4, 512, 4096) exact/vLLM = 1.735
(4, 512, 32768) exact/vLLM = 1.478
(4, 512, 131072) exact/vLLM = 1.353
(4, 2048, 4096) exact/vLLM = 1.406
(4, 2048, 32768) exact/vLLM = 1.312
(4, 2048, 131072) exact/vLLM = 1.784
(4, 8192, 32768) exact/vLLM = 1.814
(4, 8192, 131072) exact/vLLM = 1.887
(16, 512, 4096) exact/vLLM = 1.388
(16, 512, 32768) exact/vLLM = 1.327
(16, 512, 131072) exact/vLLM = 1.745
(16, 2048, 4096) exact/vLLM = 1.533
(16, 2048, 32768) exact/vLLM = 1.721
(16, 2048, 131072) exact/vLLM = 1.843
(16, 8192, 32768) exact/vLLM = 1.864
(16, 8192, 131072) exact/vLLM = 1.835
shapes where e4m3 is slower than vLLM (mean of the two runs):
(1, 512, 4096) e4m3/vLLM = 1.019
(16, 8192, 131072) e4m3/vLLM = 1.003
8 further shapes not used to tune the geometry thresholds:
exact/vLLM time ratio: geomean 1.800, worst 2.069, best 1.558, slower than vLLM in 8 of 8 shapes
e4m3/vLLM time ratio: geomean 0.942, worst 1.029, best 0.859, slower than vLLM in 1 of 8 shapes
shapes where exact is slower than vLLM (mean of the two runs):
(8, 4096, 65536) exact/vLLM = 1.852
(2, 8192, 65536) exact/vLLM = 1.834
(16, 4096, 32768) exact/vLLM = 1.88
(1, 16384, 131072) exact/vLLM = 2.069
(8, 8192, 131072) exact/vLLM = 1.846
(4, 1024, 131072) exact/vLLM = 1.558
(16, 1024, 65536) exact/vLLM = 1.738
(1, 8192, 65536) exact/vLLM = 1.667
shapes where e4m3 is slower than vLLM (mean of the two runs):
(1, 16384, 131072) e4m3/vLLM = 1.029
Shapes where the e4m3 arm is slower than vLLM: B1/q512/ctx4K 1.019 (5.4 vs 5.3 us, launch-bound), B16/q8192/ctx128K 1.003 (a tie, runs 1.002 and 0.996), B1/q16384/ctx128K 1.029. Every other e4m3 shape is faster (best 0.744). The exact arm is slower than vLLM on every shape, 1.15x to 2.07x (geomean 1.585 on the 24, 1.80 on the 8), because it runs on the f16 MFMA at half the fp8 rate while vLLM's kernel uses the fp8 MFMA; exact is 1.445 PFLOPS on the largest shape (about 70% of the 2.07 PFLOPS f16 microbenchmark peak by rocprof). Against aiter's MXFP4 scorer the NVFP4 arms are slower by time: geomean e4m3/mx 1.097, exact/mx 1.926 on the 24.
Raw tables
24 shapes:
8 further shapes:
Tests
python3 op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py(about 15 s; exits non-zero on any failed check): the existing MXFP4 prefill checks and table, then the NVFP4 checks and an NVFP4 table. The added code has no pytest (check_prefill_nvfp4_*functions run by the file's own runner), an@benchmarkwithrun_perftest,checkAllclose, TFLOPS and TB/s, a markdown table, andget_gfx_runtime()gating inmain(). The oracle dequantizes the NVFP4 cache in torch (this stack has no NVFP4 write kernel) on data whose fp32 partial sums are exact, so the kernel must match it bit for bit whatever the accumulation order; the benchmark asserts err = 0 for both arms. Minimal matrix: page and tile tails, a prefix-only and an empty request, H = 1/4, both Q dtypes, the 16- and 32-wide MFMA, the 512-row DMA tile and the 8-wave tile, bothk_roundvalues; random data against aiter's fp8 scorer on the e4m3 arm; split vs single-region views; the defaultk_roundis "e4m3"; modes do not share a compiled kernel; rejections.Checked on this tree with flydsl 0.5.0, gfx950, outside the diff:
origin/main.Dependencies and scope
Depends on the decode PR; flydsl==0.5.0 as pinned; gfx950 only. Not in this PR: the NVFP4 write kernel, ATOM integration.
PR Self-Review
Reviewed revision
872c725 (head after review round 5: one selector gate in the prefill kernel file, a docstring, and test changes on top of 438390a; the ISA of every compiled kernel is unchanged)
Behavior and intent
Adds
score_prefill_flydsl_nvfp4(+ lazy export): the prefill block scorer over an NVFP4 index cache (9216 B pages: e2m1 codes + one e4m3 scale per 16 elements), reusing #7813's e4m3 table and widen helpers and the sharedscore_prefill_flydsl(a keyword-onlynvfp4=selects the NVFP4 path). Before this PR aiter had no scorer for that cache in prefill.k_round="e4m3"(default) runs the fp8 MFMA on K = RNE e4m3 of e2m1 x scale (saturating at 448);"exact"keeps K unrounded on the f16 MFMA.Validation and unverified scope
On one MI355X (gfx950, flydsl 0.5.0), at the revision above:
python3 op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py -b 1 --q-len 4096 --ctx-len 8192: exit 0, 165 checks PASS, 0 FAIL, 0 SKIP (default run:python3 op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py, one card). [measured]python3 op_tests/test_flydsl_minimax_m3_index_score.py --ctx-len 8192(the [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813 test, which also runs the fp8 prefill table): exit 0, 153 PASS, 0 FAIL, final ISA of its 65 kernels byte-identical to the [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813 base. [measured] At bd6a4a2 (with [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813's new NVFP4 geometry sweep) the same file passes 193 checks, 0 FAIL. [measured]score_prefill_flydslpassthrough folded back with a keyword-onlynvfp4=None, one scale-byte contract with the decode scorer (non-negative, zero allowed), the module header corrected,vec_predand the raw-slot constants derived fromPAGE // WAVES; a584346: the NVFP4 tail cases written out literally, with the forced-m32axis removed because all 12 forced-m32=1cases returned early and counted as PASS): the prefill op test at bd6a4a2 passes 160 checks, 0 FAIL, 0 SKIP (the 12 removed cases are the ones that did nothing); the final ISA of the 50 NVFP4 prefill kernels is identical before and after; zero and sign-set scale bytes are bit-equal to the oracle on both arms and both Q dtypes. [measured]abd26fd822,7c997ce656,872c7257bf). (a) A small-q measurement was asked for; it found a regression:_use_xwidehad no query-length term, so a query of 256 rows or fewer with batch x heads >= 32 took the 512-row DMA tile, which is a single query tile for such a query (no page read saved) and ran 1.6-1.7x slower than the 8-wave / tile_q 256 CTA. The 512-row tile now needsmax_query_len > 256(q 257-640 is mixed, xwide wins some shapes and loses up to 18% on others, and is left unchanged). One MI355X, test perf harness, ctx 16384, us pushed head -> gated: batch 32, H 1, e4m3 Q, nvfp4 e4m3: q=1 33.6 -> 20.1, q=16 34.5 -> 20.3, q=64 35.0 -> 20.5, q=128 35.2 -> 21.1, q=256 36.9 -> 22.6 (all 30 shape x Q-dtype rows measured are 1.6-1.8x faster; batch 32 / H 4 / q=1: 109.1 -> 60.8; ctx 32768, batch 32 / H 1 / q=1: 57.8 -> 32.8); the exact arm (37.5-40.7), MXFP4 (16.9-21.6) and fp8 arms are unchanged within +1-3% run-order drift. Gated selector vs xwide forced off in the same process: 0.98-1.01 everywhere. Outputs bit-identical on every changed shape; offline compile of 56 kernels: identical ISA.check_prefill_nvfp4_causal_window_near_int32_boundassumed q=1 takes the 512-row tile and failed after the gate; it now runs on the forced 512-row tile and on the selector's tile, both bit-equal to the reference. (b)score_prefill_flydsl's docstring now says whatnvfp4=selects. (c) Every bit-exact NVFP4 case launches 8 times and must return the first launch's bytes (as the decode suite does); on a scratch kernel withwait_asyncmark(0)weakened to(1)in the DMA loop the old test passed 3 of 3 runs and the new one failed in 2 of 3, in one case only (nvfp4_every_geometry_b8_q2048_ctx16384), so it catches a real race probabilistically, not every time. (d)check_prefill_nvfp4_exact_randomusescheckAllclose(rtol 4e-6, atol 4e-8) like the other checks; one element perturbed by 0.1% fails with the shared diagnostics. Op test 165 PASS / 0 FAIL / 0 SKIP; [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813's test file 193 PASS; ruff 0.17.3 and black clean. Not run: any end-to-end effect, large-q shapes re-timed (the kernel is unchanged there by construction), CI's ruff 0.16.0. [measured]score_flydsl_nvfp4) #7813's 499b0e0, then 922171e / fa79d75 / 438390a): the e4m3 arm's element-order comments now say evens then odds per 8 elements with Q permuted to match (only the exact arm is natural order); a namedRAW_HALFinstead ofRAW_DATA // 2; thenvfp4andk_scalechecks are split with their own messages; the one-line NVFP4 forwarders in the test are folded; a new case(8, 1024, 32768)runs the 8-wave tile at 4 pages per wave (the first version of the new check failed on the GPU for lack of that case). Prefill op test 165 PASS, 0 FAIL, 0 SKIP (was 160); [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813's test on the merged tree 193 PASS, 0 FAIL, 0 SKIP. Offline (no-GPU) compile of 56 kernels (38 NVFP4) before and after the changes and before and after the merge: ISA identical; the 50 kernels the op test dumps on the GPU are identical to the pre-merge run, plus 3 kernels from the new shape. Not run: perf, CI's ruff 0.16.0. [measured][2,128]table with stride(0)=2**29 made request 1 read 2 GiB before the table; new casenvfp4_block_table_row_stride_beyond_2gibfails before, passes now) and e8m0 / fp4x2 typed views are refused for NVFP4 (nvfp4_rejections). Prefill op test 170 PASS, decode op test 153 PASS, 0 FAIL; ISA of 42 of 50 kernels identical, the 8 DMA kernels differ only in scalar address math. [measured]nvfp4_causal_window_near_int32_bound), and the host call copies the cachedexact_geometrydict before settingcontig_k(new casenvfp4_exact_geometry_is_not_mutated_by_the_output). Prefill op test 172 PASS, decode op test 153 PASS, 0 FAIL; all 50 kernels differ by 7-18 ISA lines (prologue scalar math and scheduling; MFMA, memory, LDS counts and VGPR unchanged); prefill perf over 8 shapes x 5 arms, 10 alternating runs per tree on one card: geomean new/base 0.994, worst shape +0.5%, inside the run-to-run spread. [measured]PR-specific question
Before this PR every NVFP4 prefill check fails at the first call (
score_prefill_flydsl_nvfp4does not exist). What they pin that an oracle match would not: bit-exact scores on exact-sum data on both MFMA shapes, the 512-row DMA tile and the 8-wave tile, tails and empty requests (now including an empty request inside the DMA tile,[5, 0, 7]), single-region views, the defaultk_round, no compiled-kernel sharing between modes, rejections.check_prefill_geometry_arms_are_exhaustivenow also walksgeometry(..., xwide=True)andexact_geometry: with the thirdwidecase removed it fails naming the xwide arm(512, 4, 2, 0, 1), and with the(8, 512, 1000)shape removed it names the exact arm(128, 4, 1, 0, 0). [measured by mutating the lists in a scratch script]. That check also found a real gap: the exact arm's 128-row tile had no case;nvfp4_exact_every_shapenow runs on everyGEOM_SHAPESentry.Changed op tests
op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py: the canonical MXFP4/NVFP4 prefill test, extended in place with the NVFP4 oracle, matrix and benchmark; the NVFP4 quantizer and pack helpers are imported from the decode test, not copied.op_tests/test_flydsl_minimax_m3_index_score.py: not changed by this PR's own commits; it appears in the diff againstmainonly because this PR is stacked on [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813, where its NVFP4 decode checks are explained.🤖 Generated with Claude Code