Skip to content

[FlyDSL] M3 index score: NVFP4 prefill scorer (score_prefill_flydsl_nvfp4) - #7814

Merged
valarLip merged 31 commits into
mainfrom
ganyi/nvfp4-index-prefill-pr
Nov 16, 2026
Merged

valarLip merged 31 commits into
mainfrom
ganyi/nvfp4-index-prefill-pr

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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 against main also 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 as minimax_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 and k_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_round

  • k_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):
case scorer arm k top-k overlap with vLLM rows counted
prefill q[2048, 2048] ctx[32768, 32768] H1 exact 8 0.95157 4096
prefill q[2048, 2048] ctx[32768, 32768] H1 exact 16 0.95888 4096
prefill q[2048, 2048] ctx[32768, 32768] H1 exact 32 0.96480 4096
prefill q[2048, 2048] ctx[32768, 32768] H1 e4m3 8 1.00000 4096
prefill q[2048, 2048] ctx[32768, 32768] H1 e4m3 16 1.00000 4096
prefill q[2048, 2048] ctx[32768, 32768] H1 e4m3 32 1.00000 4096
prefill q[4096, 1024] ctx[65536, 20000] H4 exact 8 0.94806 20480
prefill q[4096, 1024] ctx[65536, 20000] H4 exact 16 0.95517 20480
prefill q[4096, 1024] ctx[65536, 20000] H4 exact 32 0.96181 20480
prefill q[4096, 1024] ctx[65536, 20000] H4 e4m3 8 1.00000 20480
prefill q[4096, 1024] ctx[65536, 20000] H4 e4m3 16 1.00000 20480
prefill q[4096, 1024] ctx[65536, 20000] H4 e4m3 32 1.00000 20480

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-shape does 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); mx is aiter's MXFP4 prefill scorer, vllm the 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:

B q ctx mx us (r1/r2) exact us (r1/r2) e4m3 us (r1/r2) vllm us (r1/r2) mx TFLOPS exact TFLOPS e4m3 TFLOPS vllm TFLOPS exact/vLLM e4m3/vLLM
1 512 4096 4.7/4.7 6.1/6.1 5.4/5.4 5.3/5.3 109 84 95 97 1.151 1.019
1 512 32768 7.5/7.5 11.7/11.6 8.0/8.0 8.3/8.3 571 366 535 517 1.404 0.964
1 512 131072 12.8/12.9 28.4/28.1 14.5/14.6 19.2/19.1 1333 607 1180 897 1.475 0.760
1 2048 4096 5.9/5.8 11.5/11.5 6.4/6.3 6.7/6.6 282 143 259 248 1.729 0.955
1 2048 32768 13.4/13.3 29.0/28.9 15.0/15.0 18.1/18.1 1253 577 1111 920 1.599 0.829
1 2048 131072 31.9/31.8 66.5/66.4 37.1/37.0 42.6/42.7 2142 1027 1842 1600 1.558 0.869
1 8192 32768 32.1/31.9 65.5/65.5 37.0/37.0 41.5/42.0 1886 920 1627 1444 1.569 0.886
1 8192 131072 106.4/106.8 223.2/223.5 114.4/114.6 119.4/119.3 2500 1193 2327 2233 1.871 0.959
4 512 4096 5.8/5.7 11.8/11.8 6.3/6.3 6.8/6.8 357 174 327 301 1.735 0.926
4 512 32768 13.0/13.0 28.2/28.1 14.7/14.6 19.1/19.0 1314 607 1166 896 1.478 0.769
4 512 131072 32.4/32.2 66.4/66.1 37.6/37.5 49.1/48.8 2125 1036 1828 1402 1.353 0.767
4 2048 4096 9.5/9.4 16.5/16.4 11.4/11.4 11.7/11.7 698 400 576 560 1.406 0.974
4 2048 32768 31.7/31.8 65.1/64.8 36.9/36.8 49.5/49.5 2102 1027 1809 1347 1.312 0.744
4 2048 131072 106.5/106.6 226.4/225.3 113.8/113.5 127.0/126.2 2561 1208 2402 2156 1.784 0.898
4 8192 32768 107.8/108.2 222.4/224.2 117.5/117.5 123.0/123.2 2232 1080 2052 1958 1.814 0.955
4 8192 131072 460.1/465.6 834.3/837.3 434.8/442.6 438.2/447.5 2303 1275 2429 2407 1.887 0.991
16 512 4096 9.7/9.7 16.8/16.8 11.7/11.6 12.1/12.1 842 488 704 678 1.388 0.963
16 512 32768 33.5/33.0 66.2/66.1 38.1/38.2 50.1/49.6 2054 1033 1790 1370 1.327 0.765
16 512 131072 105.3/105.0 226.1/224.0 115.2/115.3 129.7/128.2 2610 1220 2382 2128 1.745 0.894
16 2048 4096 23.2/23.2 43.3/43.8 28.1/28.1 28.3/28.5 1132 604 936 927 1.533 0.989
16 2048 32768 108.8/108.7 224.0/222.4 120.2/120.5 129.9/129.5 2454 1195 2216 2057 1.721 0.928
16 2048 131072 489.2/487.6 860.1/858.9 459.7/452.8 472.1/460.6 2235 1270 2392 2341 1.843 0.978
16 8192 32768 439.9/448.0 825.0/823.0 433.7/434.7 448.3/435.8 2172 1170 2221 2182 1.864 0.982
16 8192 131072 1749.6/1749.5 2946.7/2954.0 1612.9/1613.0 1605.0/1609.8 2436 1445 2643 2652 1.835 1.003

8 further shapes:

B q ctx mx us (r1/r2) exact us (r1/r2) e4m3 us (r1/r2) vllm us (r1/r2) mx TFLOPS exact TFLOPS e4m3 TFLOPS vllm TFLOPS exact/vLLM e4m3/vLLM
8 4096 65536 212.2/217.5 441.8/438.7 217.5/221.8 237.9/237.6 2482 1211 2427 2242 1.852 0.924
2 8192 65536 106.3/106.7 222.8/222.7 115.5/115.8 120.8/122.1 2422 1158 2231 2124 1.834 0.952
16 4096 32768 215.4/213.8 438.1/439.2 221.6/218.4 232.7/233.9 2407 1178 2348 2214 1.880 0.943
1 16384 131072 212.8/210.0 434.9/437.7 215.4/218.8 211.1/210.7 2440 1182 2375 2445 2.069 1.029
8 8192 131072 931.0/945.3 1576.7/1592.9 857.1/854.5 857.7/859.6 2272 1345 2490 2482 1.846 0.997
4 1024 131072 56.4/56.2 119.7/119.8 66.0/66.0 76.4/77.3 2433 1144 2075 1782 1.558 0.859
16 1024 65536 106.4/106.7 222.7/225.0 117.5/118.4 128.1/129.5 2562 1220 2315 2119 1.738 0.916
1 8192 65536 55.6/55.8 118.8/118.1 65.6/65.5 71.1/71.0 2316 1089 1968 1815 1.667 0.923

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 @benchmark with run_perftest, checkAllclose, TFLOPS and TB/s, a markdown table, and get_gfx_runtime() gating in main(). 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, 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.

Checked on this tree with flydsl 0.5.0, gfx950, outside the diff:

  • 1338 NVFP4 prefill checks of the wide regression matrix pass; the 76 MXFP4 output hashes are identical to origin/main.
  • NVFP4 prefill outputs (both arms, both Q dtypes, H = 1/2, five geometries) are byte-identical to the development branches this PR was cut from.
  • e4m3 arm vs vLLM: the groups listed under Numerics, 100.000% bit-equal.

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 shared score_prefill_flydsl (a keyword-only nvfp4= 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]
  • The 49 prefill kernels the test built before the review fixes have byte-identical final ISA after them; the review fixes add one more kernel (exact arm, 128-row tile), see Changed op tests. [measured]
  • Review round 3 (b6e1fc6: the score_prefill_flydsl passthrough folded back with a keyword-only nvfp4=None, one scale-byte contract with the decode scorer (non-negative, zero allowed), the module header corrected, vec_pred and the raw-slot constants derived from PAGE // WAVES; a584346: the NVFP4 tail cases written out literally, with the forced-m32 axis removed because all 12 forced-m32=1 cases 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]
  • Review round 5 (valar-cop and Copilot at 438390a; abd26fd822, 7c997ce656, 872c7257bf). (a) A small-q measurement was asked for; it found a regression: _use_xwide had 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 needs max_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_bound assumed 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 what nvfp4= 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 with wait_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_random uses checkAllclose (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]
  • Review round 4 (valarLip, 21:11; merge of [FlyDSL] M3 index score: NVFP4 decode scorer (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 named RAW_HALF instead of RAW_DATA // 2; the nvfp4 and k_scale checks 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]
  • black 26.10.1 and ruff 0.17.3 clean (CI pins 0.16.0, not run). [measured]
  • Copilot round 2 (8221f69): the DMA block-table byte offset is now computed in Int64 (a [2,128] table with stride(0)=2**29 made request 1 read 2 GiB before the table; new case nvfp4_block_table_row_stride_beyond_2gib fails 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]
  • Copilot round 3 (dab3ee3): the causal-window sum is done in int64 before the clamp (boundary hardening: seq_len near 2**31 scored nothing; new case nvfp4_causal_window_near_int32_bound), and the host call copies the cached exact_geometry dict before setting contig_k (new case nvfp4_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]
  • Unverified: the vLLM bit comparison and the wide regression matrix quoted above were not repeated after the review fixes (no numerics changed; ISA identical); the perf tables are the description's earlier runs, not re-measured; gfx942 and other flydsl versions.

PR-specific question

Before this PR every NVFP4 prefill check fails at the first call (score_prefill_flydsl_nvfp4 does 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 default k_round, no compiled-kernel sharing between modes, rejections. check_prefill_geometry_arms_are_exhaustive now also walks geometry(..., xwide=True) and exact_geometry: with the third wide case 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_shape now runs on every GEOM_SHAPES entry.

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 against main only 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

ganyi1996ppo and others added 4 commits November 11, 2026 01:08
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]>
ganyi1996ppo and others added 3 commits November 11, 2026 19:22
…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]>
@ganyi1996ppo
ganyi1996ppo changed the base branch from ganyi/nvfp4-index-decode-pr to main November 13, 2026 07:18
@ganyi1996ppo
ganyi1996ppo requested a review from a team November 13, 2026 07:18
@aiter-bot

aiter-bot commented Nov 13, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 872c7257bf7b · 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. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  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.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (5)

  1. Rebase onto #7813's current head and land it after #7813. The branch merges #7813 at cf804109e, one commit behind its head 80ff1e7ee (the NVFP4 work-map benchmark fix), so git diff 80ff1e7ee..HEAD shows that fix reverted in op_tests/test_flydsl_minimax_m3_index_score.py:2834. No CI has run on this PR yet (only evaluate). 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.
  2. 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"), and test_..._prefill_fp4.py:854 ("bf16 MFMA"). The code uses fx.Float16 and MFMA(..., fx.Float16). Also fix nv_case (test:642), which says scales are in [0.5, 2), but bytes 0x30..0x47 give [0.5, 3.75].
  3. 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", ...). Also test:1132 says "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_chunk grouping.
  4. Make the LDS check count the NVFP4 fields, and drop the legacy buffer_ops import. At minimax_m3_index_score_prefill.py:539-541 the _LDS_LIMIT guard runs before lut/stg/raw are added. After that, _total += _lut_bytes is 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/:1009 import the legacy kernels.buffer_ops only for get_element_ptr. aiter/ops/flydsl/AGENTS.md says new code uses the FlyDSL pointer/buffer API, so use it, or add a comment at the call naming the missing API.
  5. 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 MXFP4 geometry. Add geometry(..., xwide=True) and exact_geometry so a change to the _use_xwide thresholds cannot leave an arm untested. Add an empty request (e.g. ([5, 0, 7], ...)) to wide (test:1143); the DMA tile never sees ql = 0. e2m1_encode/nv_product/nv_pack/nv_quantize (test:561-613) copy test_flydsl_minimax_m3_index_score.py:2455-2528; import them. That also removes the E2M1 redefinition (test:395 list vs :555 tuple).

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).

ganyi1996ppo and others added 8 commits November 15, 2026 03:57
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]>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 10:10
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

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; op_tests/test_flydsl_minimax_m3_index_score.py now keeps build_work_map(..., nvfp4=True) (the diff of that file against #7813's head is empty). The native-fp4-format line is in the description, and the five self-review sections are filled in.

Item 2 (bf16 vs f16; nv_case range). Fixed in 5a1174bd17 (kernel :398 "widens it to f16", :1562 "16x16x32 f16 MFMA") and 8101d21aaf (test :854 "f16 MFMA"; nv_case scale range [0.5, 3.75]). Comments only.

Item 3 (vLLM internals, out-of-tree matrix). Fixed in 5a1174bd17 (kernel :45, :777, :1181-1183, :2616) and 8101d21aaf (test header, section comment, nv_quantize docstring, :786, :899, :1132). The text now states the rule: K = RNE e4m3 of e2m1 x scale saturating at 448; scale = RNE e4m3 of min(amax x RN(1/6), 448) per 16 elements, then RNE e2m1 (the test header points at quantize_nvfp4 in the decode test); the _k32_chunk docstring says the NVFP4 grouping is 64h32 + 32st versus aiter's 64st + 32h32 and names check_prefill_nvfp4_matches_aiter (few fp32 ulps against aiter's fp8 scorer) and the exact-sum oracle cases (bit-exact). "full regression matrix lives outside this file" is gone.

Item 4 (LDS guard; buffer_ops). Fixed in 2b58b15c19. The 64 KB _LDS_LIMIT stays as the page-buffer + Q-staging budget that sizes tile_q; the NVFP4 fields (scale table, score staging, DMA landing zone) are now added before a second check against gfx950's 160 KB (_LDS_HW_BYTES), and the dead _total += _lut_bytes is now read. Measured group_segment_fixed_size from the dumped ISA: 76800 B for the 512-row DMA tile (matches your ~76.8 KB), 77824 B for the exact 256-row tile, 52224 B for the DMA tile without score staging; all pass, so no behaviour change and ISA unchanged. buffer_ops.get_element_ptr (now :73/:1949 here) is kept with a comment at the call: FlyDSL 0.5.0's fly.ptr has no constant (addrspace 4) address space (enum: Generic/Global/Shared/Register) and fx.ptr_load has no invariant flag, so the scalar block-table load has no pointer-API form. [read from the installed flydsl 0.5.0 source; I did not try to rewrite the load and compare ISA] If you would rather have a raw llvm.GEPOp there, say so.

Item 5 (dispatch-arm coverage, empty request, shared oracle). Fixed in 8101d21aaf. check_prefill_geometry_arms_are_exhaustive now also walks geometry(..., xwide=True) (DMA arms) and exact_geometry over the same grid at H = 1 and 4, against the arms the NVFP4 cases reach (xwide forced as _with_xwide does; exact from GEOM_SHAPES, the short tails and the forced 256-row tile). It found a real gap: no case reached the exact arm's 128-row tile (128, 4, 1, 0, 0), so nvfp4_exact_every_shape now runs on every GEOM_SHAPES entry (one extra compiled kernel). wide gains ([5, 0, 7], [300, 300, 4099]), (wide already fed check_prefill_nvfp4_exact_wide, so that gets it too). e2m1_encode, nv_product and nv_quantize copies are deleted (they are reached only through the two functions now imported from the decode test, pack_nvfp4 and nvfp4_cache_of; the decode names differ, nvfp4_product/quantize_nvfp4). The decode helpers return bf16 where the copies returned fp32; the values are the same (the decode pack_nvfp4 asserts bf16 exactness) and nv_oracle upcasts. The E2M1 redefinition and the unused NV_ROUNDS went with them. Measured on one MI355X: prefill op test 149 -> 169 PASS, 0 FAIL; mutating the lists makes the new check fail, naming (512, 4, 2, 0, 1) when the third wide case is dropped and (128, 4, 1, 0, 0) when (8, 512, 1000) is dropped.

ganyi1996ppo and others added 4 commits November 15, 2026 11:54
…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]>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh an unpublished finding that the oracle check bypasses the standard comparison path and omits mismatch diagnostics.

No open issues 🎉

Review effort: Balanced

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (3)

  1. 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 :1259 says "Natural element order" too. In fact fp4_dword_to_e4m3 emits each 8 elements as evens then odds, and stage_q_lds permutes 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".
  2. 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 tile is wrong. (8, 2048, 16384) has max_block 128 and 4·8·1 = 32 tiles, so _use_xwide picks 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 let check_nvfp4_geometry_arms_are_covered also walk the non-xwide geometry(..., xwide=True) arms, the way the MXFP4 check does.
  3. 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/:1429 is RAW_DATA // 2 and should be named that. :2371-2372 raises "nvfp4: k_round must be one of …" when the actual problem is a missing k_scale, so split the two checks. In the test, nv_ref_of is c[k_round], and check_prefill_nvfp4_tails / _exact_tails / _every_geometry / _exact_every_shape are one-line forwards to check_prefill_nvfp4_bit_exact. Pass k_round through build_cases instead (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).

@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

@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.

  1. score_prefill_flydsl passthrough: fixed in b6e1fc6. _score_prefill_impl is folded back into score_prefill_flydsl with a keyword-only nvfp4=None, and score_prefill_flydsl_nvfp4 calls it the way _fp4 does. The wrapper and one name are gone; every caller of the function was checked and none changed. The final ISA of all 50 kernels the test builds is identical before and after.
  2. Test matrix: fixed in a584346. SHORT_TAILS is written out literally and prefill_tail_cases() is deleted. You were right about the early return, and it was worse than one case: all 12 forced-m32=1 tail cases returned early (the selector picks tile_q 64 for these tails, so FEAT_TILES_PER_WAVE is 1) and counted as PASS, and the 12 forced-m32=0 ones ran what the selector already picks. I removed the forced-m32 axis (_with_m32, the parameter and the early return) instead of reporting SKIP; the 32-wide shape is still covered by nvfp4_every_geometry. The prefill op test is now 160 PASS, 0 FAIL, 0 SKIP on the merged tree (172 before, the difference being those 12 cases).
  3. Scale-byte contract: fixed in b6e1fc6. Both kernels mask with 0x7F, so the sign is not read and a zero scale gives K = 0; exact-sum data with zero and sign-set scale bytes is bit-equal to the oracle on both arms and both Q dtypes. The docstring and the description now use the decode wording (non-negative, zero allowed, 0x7F out of contract). The module header now says the fp8 compute is unchanged only for k_round="e4m3", and that "exact" changes the MFMA to f16.
  4. Cleanups and description: fixed in b6e1fc6. vec_pred no longer repeats full. RAW_W and the bare 2048 / 256 come from PAGE // WAVES * DATA_BYTES and * NVFP4_SCALE_BYTES (2048 and 256 as before, asserted), and the generated ISA is identical. The description now says "10 commits of its own plus 3 merges of [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813" instead of "the two last commits".

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.

ganyi1996ppo and others added 6 commits November 15, 2026 18:42
…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]>
…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]>
…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]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 01:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the unrounded-K oracle check bypasses the required shared comparator and its expected/actual mismatch diagnostics.

No open issues 🎉

Review effort: Balanced

@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Round 4, head 438390a767 (fast-forward of bd6a4a2528: a merge of #7813's round 4 499b0e0f45, then three commits, all three of valarLip's 21:11 items). The PR body is updated to this head.

  1. e4m3-arm layout comments. Fixed in 922171e97b. The module header and the commit_page comment now say evens then odds per 8 elements with Q permuted to match (fp4_dword_to_e4m3, stage_q_lds); "unchanged" and "exactly an fp8 page" are dropped, and only the exact arm is described as natural order.
  2. Wrong 8-wave comment. Right: (8, 2048, 16384), H=1 gets the 512-row DMA tile. Fixed in fa79d751b2 (comment) and 438390a767 (case). nvfp4_every_geometry now runs the six GEOM_SHAPES plus (8, 1024, 32768), which reaches the 8-wave tile at 4 pages per wave; that shape was found because the arms check failed on the GPU without it, and it passes with it. The arms check requires a case for every arm that geometry(..., xwide=True) reaches.
  3. Description and cleanups. Body updated (13 own commits + 4 merges of [FlyDSL] M3 index score: NVFP4 decode scorer (score_flydsl_nvfp4) #7813 counted from 499b0e0f45, "non-negative, zero allowed", Reviewed revision 438390a767). RAW_HALF replaces 1024 * h, the nvfp4 and k_scale checks are split (a missing k_scale now says so), and nv_ref_of and the four one-line forwarders are folded into build_cases(k_round); the case list is unchanged (same names, same order).

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 evaluate check on this head is the Self-Review run that my body edit triggered and that was cancelled, not a failure; I did not re-run it.

@valarLip @valar-cop re-review at 438390a767 (merge of #7813 round 4 + comment, constant and test changes).

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring still says only MXFP4, no mention of nvfp4? public entry point, please add one line on the nvfp4 mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single-shot launches only.. a missed wait_asyncmark in the DMA pipeline is nondeterministic, add a repeat check like the decode suite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ganyi1996ppo and others added 3 commits November 15, 2026 20:02
…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]>
…, 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]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 02:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Round 5, head 872c7257bf (fast-forward of 438390a767: three commits, a gate in the prefill kernel file, a docstring and test changes; the ISA of every compiled kernel is unchanged). The PR body is updated.

  • valar-cop's question, nvfp4 prefill with max_query_len < 512: Measured now, nvfp4 e4m3 / exact, one MI355X, the test's perf harness (-b 32 --q-len 1 16 64 128 256 --ctx-len 16384, us): e4m3 was 33.6 / 34.5 / 35.0 / 35.2 / 36.9 (q = 1 / 16 / 64 / 128 / 256) and is 20.1 / 20.3 / 20.5 / 21.1 / 22.6 after abd26fd; exact 37.5-40.7 (unchanged); MXFP4 at the same shapes 16.9-21.6. The PR body quotes the H = 4 and ctx 32768 rows I measured (for example batch 32, H 4, q = 1: 109.1 -> 60.8 us); all 30 shape x Q-dtype rows measured are 1.6-1.8x faster.
  • Gate on max_query_len (minimax_m3_index_score_prefill.py:249): real, and a regression; fixed in abd26fd822, details in the thread.
  • Docstring (score_prefill_flydsl): fixed in 7c997ce656, details in the thread.
  • Repeat check (op_tests/test_flydsl_minimax_m3_index_score_prefill_fp4.py:788): fixed in 872c7257bf, details in the thread. It catches the race probabilistically (2 of 3 runs, in one case) on a kernel I weakened for the test.
  • Copilot, unrounded-K check bypasses the shared comparator: Fixed in 872c725: check_prefill_nvfp4_exact_random now uses checkAllclose (rtol 4e-6, atol 4e-8) like the other checks; one element perturbed by 0.1% is reported with its mismatch diagnostics and fails.

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 PR Self-Review run on the push succeeded; the two started by my body edits also finished, one of them started by a no-op edit of mine that I made by mistake (it changed no text).

@valarLip @valar-cop re-review at 872c7257bf (xwide gate for q <= 256, docstring, tests).

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Action required before merge (2)

  1. 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 in Q_ROUNDS passes 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_lds docstring (: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 explains rnd.
  2. Drop the redundant disjunct in Q_BOTH (:466). Q_ROUNDS > 1 can only be true when TILE_Q > 256 and not k_fp4, so the line is just Q_BOTH = TILE_Q > 256 and not k_fp4. Also, :540 says the LUT covers "every scale byte", but it has LUT_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.

@valarLip
valarLip merged commit dad1b66 into main Nov 16, 2026
@valarLip
valarLip deleted the ganyi/nvfp4-index-prefill-pr branch November 16, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants