Repository navigation
[HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V and the index key in the row layout (gfx950, gfx1250) - #8290
[HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V and the index key in the row layout (gfx950, gfx1250)#8290lirui927 wants to merge 4 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…qk-norm launch With NVFP4 K/V the FP4 index key was the last thing still staged: the fused qk-norm/rope/cache launch wrote it in BF16 to a token-major staging buffer and index_fp4_store quantized it into the index planes in a launch of its own. aiter's fused_qknorm_idxrqknorm now quantizes it there too (index_cache_dtype="nvfp4" with index_scale, the row layout of the NVFP4 K/V write), so that launch and the staging buffer are gone; the builder no longer allocates an index stage for an NVFP4 K/V layer. FP8/BF16 K/V layers with an FP4 index keep staging + index_fp4_store. tests/test_minimax_m3_nvfp4_fused_paths.py: the fused index planes against staging + index_fp4_store, bitwise (zero- and subnormal-scale blocks included), and the K/V pool, q_out and index query unchanged. Needs aiter's NVFP4 index rows in fused_qknorm_idxrqknorm (ROCm/aiter#8290). Co-Authored-By: Claude Opus 5.5 <[email protected]>
700c167 to
1712b07
Compare
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
aiter-bot — queued behind 5 review(s); expect to start in about 1.8 h. The box reviews one PR at a time. |
@zufayu — please take a look. Re-comment |
|
@aiter-bot review |
|
aiter-bot — queued behind 6 review(s); expect to start in about 2.2 h. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #8290 — [HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V in the row layout (gfx950, gfx1250)
Review (advisory):
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0), so no head-matched report exists; the target op_tests/test_fused_qknorm_nvfp4.py is real and ran green in this PR's MI35X CI at head, but that is the PR's CI, not a head-matched report
Perf (advisory): NOT RUN — wrong arch on this box (8× gfx942); the row layout and its timing sweep are gfx950/gfx1250-only and skip on gfx942, so the harness has nothing to time here
Size: 689 lines / 5 files
Design (advisory): the row layout reuses the kv_cache_dtype="nvfp4" string, switched by the k_scale/v_scale dtype (byte planes vs fp32 [1] globals) — the PR's own open question
Human: recommend Pleaplusone review whether PR #8290's scale-dtype switch between the two NVFP4 layouts is the right call-site contract for the MiniMax-M3 pool and the FlyDSL paged decode before ATOM builds on it
2 finding(s) posted inline, on the lines they are about:
csrc/kernels/fused_qknorm_idxrqknorm.cu:1560— The row-layout checks (csrc/kernels/fused_qknorm_idxrqknorm.cu:1560) accept any page/head strides and base…aiter/ops/fused_qknorm_idxrqknorm.py:96— The row layout activates only when a consumer passes byte k_scale/v_scale planes and the new index_scale…
| "kv_cache_dtype='nvfp4' pages hold 128 tokens: block_size must be 128"); | ||
| AITER_CHECK(v_scale.has_value() && v_scale->dtype() == k_scale->dtype(), | ||
| "nvfp4 row-layout k_scale and v_scale must both be byte planes"); | ||
| const auto is_payload = [&](const aiter_tensor_t& t) { |
There was a problem hiding this comment.
There was a problem hiding this comment.
Addressed in 647dceb: the payload store no longer needs any alignment, and overlapping planes are refused on the host.
- Alignment:
nvStoreRowDatanow writes its 16-bit unit without an alignment assumption (__builtin_memcpy), which is well defined for any address. A row-layout plane may therefore start at any byte and take any page and head strides. Only the C++ pointer type assumed alignment: for the alignment-free form the compiler emits the same 16-bit store, and the device assembly of the whole file, all 705 kernels, is byte-identical with and without the change on gfx950 and gfx1250.test_nvfp4_rowsgains 9 cases on a pool whose payloads (K, V and index) have odd bases and whose fields have odd page strides and, with more than one kv head, odd head strides, compared byte for byte against the same reference as the aligned cases. Every byte the kernel can address in them lies inside the pool. - Aliasing: every row-layout plane now passes one predicate before any launch (
nv_rows_apartinfused_qknorm_idxrqknorm_impl): the K/V payloads and scale planes, and the index payload and scale plane. No two (page, head)s of a tensor may share bytes: either the pages step over a whole page's heads, or the heads over a whole head's pages. A stride-0 expanded view is refused, and so are strides that interleave pages and heads; the stride of a one-entry dim is never stepped and is not constrained.test_rows_rejecthas a case for each of the four places the predicate is applied. Their four tokens write page 0 only, so each case stays in bounds even if its check regressed.
The mxfp4 row path (storeMxfp4Row) is unchanged from main and outside this PR.
| v_scale: Tensor | None = None, | ||
| asm_layout: bool = False, | ||
| skip_index_branch: bool = False, | ||
| index_scale: Tensor | None = None, |
There was a problem hiding this comment.
📝 [verified] The row layout activates only when a consumer passes byte k_scale/v_scale planes and the new index_scale kwarg (aiter/ops/fused_qknorm_idxrqknorm.py:96), and the PR links no ATOM consumer PR — until that lands, the new path is unreachable from every existing caller. Reviewer should ask where the ATOM change that passes the byte planes and index_scale will land, and track it.
There was a problem hiding this comment.
The consumer is ROCm/ATOM#3581 (draft). Its sparse layers call fused_qknorm_idxrqknorm with kv_cache_dtype="nvfp4" and the pool's E4M3 planes as k_scale / v_scale, and pass index_scale so that the index key is written in the same launch. ROCm/ATOM#3634 is stacked on it. The K/V rows are read by the FlyDSL pa_decode NVFP4 path of #8289.
ATOM calls aiter directly, without probing for the new arguments, so ROCm/ATOM#3581 stays a draft until this PR and #8289 are in. Until then only the op test reaches the new path. The description now links all three.
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Fix the text the second commit made stale.
aiter/ops/fused_qknorm_idxrqknorm.py:130-132still says the row-layout K/V takes an index cache that "is "auto" or fp8".csrc/kernels/fused_qknorm_idxrqknorm.cu:1340says "with any index cache but an fp4 one". Both should say "auto, fp8, or the NVFP4 index rows (index_scale)". The squash text has the same problem: a2a1ed0's body says "an fp4 index with the row-layout K/V is refused", "One new kernel template flag" and that existing kernels have "identical ISA", and 1712b07 contradicts all three. Please write one squash body that describes the final state. - Decide the row layout in one place.
fused_qknorm_idxrqknorm.py:156-159repeats the C++ index-cache rule (cu:1349-1360) inside the Python arch gate. The C++ checks already refuse row K/V with an mxfp4 index, with a page-layout nvfp4 index, or with an nvfp4 index that has noindex_scale, and they do so before any launch. So the Python predicate only needskv_cache_dtype == "nvfp4"and a bytek_scale. Today the duplicate gives a wrong reason on gfx1250: an unsupported index combination is refused with "require gfx950" (andROWS_REJECT["rows fp4 index"]asserts that message). Keep the arch check and let C++ own the combination rules. - Pass the K/V scale-plane strides in their own named arguments. Right now the K/V scale-plane page and head strides go through
k_s_token/v_s_token(cu:1586-1589). In the row layout those arguments mean something else:k_s_tokenis read as a page stride andv_s_tokenas a head stride, atcu:727-731andcu:925-929, and only a static_assert comment says so. Commit 2 already adds a trailing struct. RenameNvIndexRowsto something likeNvRowsand give it the K/Vscale_page/scale_headfields. This costs no extra launch argument, and the meaning of each argument is visible at the call site.
Correctness checks, no change needed:
- The e4m3 scale (
__fdiv_rn(amax, 6), RNE, saturating at 448) matches ATOM's_nvfp4_store_kernel(atom/model_ops/minimax_m3/index_fp4.py). So doinv = 1/scale(0 when the scale is 0), the e2m1 thresholds, and the sign rule (+0 for a zero-scale block). - Gates for the two layouts: fp32
[1]scales still pass the page-layout check (cu:1534) unchanged. Byte planes take the new branch. Every mixed combination I enumerated is refused on the host. - The default path adds only a few host bool tests and a 24 B kernarg, which is far below 1 µs per step.
- On MI35X, CI shard 2 ran
test_nvfp4_rowsand the row refusals, and they pass.
On aiter-bot's open alignment thread: the mxfp4 row path (storeMxfp4Row, free strides, cu:1636-1655) uses the same uint16 stores without an alignment check, so I don't see this as blocking. Please reply on the thread anyway, either with a 2 B check or with the alignment stated as part of the caller contract, so it can be resolved.
On your open question: the dtype switch is fine with me. After item 2, it is decided in a single place.
Reviewed at 1712b07 (deep tier, 1 hunter pass by the orchestrator; no pass B because the verdict is request_changes). Already fixed: n/a (first review).
|
@lirui927 Please take a look at the aiter-bot review. It has been over 12 hours without a follow-up commit or explanation. Please address the feedback or leave a brief update on how you plan to proceed. |
|
Thanks for the reviews; they are being addressed now. Plan for the next push:
The change needs a gfx1250 run before it is pushed, so it will follow once the MI455X box is free. |
1712b07 to
647dceb
Compare
|
Force-pushed for both reviews. The branch is now one commit, 647dceb, on current main (e6d2d31); the previous head was 1712b07. Its message describes the final state, so the pre-filled squash text no longer carries the bodies of the intermediate commits. The description is rewritten for the final state as well, and its Self-Review section is on the new head. valarLip's action items:
The dtype switch stays, as valarLip answered the open question; the description now states it as the rule instead of asking. aiter-bot's threads, answered inline:
On MI455X, |
…he row layout (gfx950, gfx1250) kv_cache_dtype="nvfp4" with byte k_scale / v_scale planes (uint8 or float8_e4m3fn) writes K (normed, roped) and V straight into the NVFP4 row layout of MiniMax-M3's sparse pool and of the FlyDSL paged decode: per (page, kv head) an e2m1 payload [128, 64] and E4M3 scales [128, 8], no global scale. With it, index_cache_dtype="nvfp4" and the new index_scale argument write the index key in the same layout and the same pass: payload [pages, 128, 64], scales [pages, 128, 8], addressed by index_slot_mapping. ATOM staged these rows in BF16 and quantized them in three more launches per sparse layer. - The scale dtype picks the layout. fp32 [1] k_scale / v_scale keep the page layout of ROCm#7824, still gfx950-only; byte planes select the row layout, on gfx950 and gfx1250. The wrapper uses this only for its arch check; the C++ host checks own every other rule. - The row layout runs the generic kernel at every token count. The prefill variant and the raw-pointer entry of ROCm#8472 are the page layout's: their V runs, K scale order and single page stride are that format's, and the variant is compiled for gfx950 only. The launcher reaches it under kNvfp4, which the row layout does not set. Neither Python fast path (the raw front, the deferred QKV front of ROCm#8607) takes a call with index_scale, so a page-layout call that passes it is refused (by the C++ checks, or by the deferred front itself) instead of having it dropped. - With the row-layout K/V the index cache is "auto", fp8 or NVFP4 rows (index_scale). An mxfp4 or page-layout nvfp4 index cache is refused (each would be its own set of kernels). - scale = e4m3(amax / 6) (RNE, saturating at 448), codes = e2m1(x * (1 / scale)) half to even, sign included, in IEEE arithmetic: the rule of ATOM's Triton NVFP4 stores (kv_nvfp4_store, index_fp4_store), so the bytes match them on finite rows. The scale byte and the magnitudes come from nvQuantLane with a unit global scale (the page layout's quantizer, on gfx950 its hardware converts): amax * float32(1/6) rounds to the e4m3 byte of amax / 6 for every bf16 and fp16 amax. The sign is the row layout's own: none for a NaN, a zero or any element of a zero-scale group, read from x's bits because this file is built with fp32 denormals flushed and x * (1 / scale) can be one. The store is storeNvfp4IndexRow with a kRows flag. - Token rows are contiguous inside a (page, head); the base and the page and head strides of every plane are free, each plane on its own. The 16-bit payload store (nvStoreRowData, which the page layout shares) assumes no alignment and compiles to the same code as before; the host refuses a plane in which two (page, head)s share bytes. - Kernel: template flags kNvRows and kNvIndexRows (default false) and one trailing NvRows argument: the K and V scale-plane strides, and the index rows' scale plane and page strides. 16 new kernels. The existing ones keep their instructions and resources; only the implicit-kernarg offset moves, by the argument's 56 B. The prefill kernels are unchanged. op_tests/test_fused_qknorm_nvfp4.py: test_nvfp4_rows checks the K/V and index rows byte for byte against "auto" + a torch reference of the rule, on strided fields of one pre-filled pool: also with odd payload bases and odd page and head strides, with every plane on its own strides and the two scale planes of different byte dtypes, and in the call shape of the prefill variant (16 q / 1 kv / 1 index heads, bf16, e4m3 index_q_out). The rows include zero-scale blocks of either sign, elements whose x * (1 / scale) is an fp32 denormal, NaN and infinities. test_rows_reject covers the host refusals, the wrapper's arch gate per scale dtype and the deferred front's refusal; test_reject gains the page-layout call of the raw front's shape with index_scale. stress_qkv's largest magnitude is now the dtype's (3e38 does not fit fp16). Co-Authored-By: Claude Fable 5.2 <[email protected]>
647dceb to
bc7cbbb
Compare
|
Re-ported onto current main after #8472 (and #8607). The branch is one commit, bc7cbbb, on What changed against the previous head:
On one idle MI455X at this head: |
…50-strict too The wrapper compared get_gfx_runtime() with gfx950 / gfx1250, so a gfx1250-strict device (MI450 A0) was refused although its device pass builds the same row-layout kernels: the kernel file's only arch switch is __gfx950__, and opus pairs __gfx1250_strict__ with __gfx1250__ for the fp8 convert. The gate and the op test's gate go through base_gfx_arch; test_rows_reject takes one row-layout call with the arch faked to gfx1250-strict. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rule as the kernel applies it The comment said the sign is that of x * (1 / scale). The kernel reads it from the bits of x: set for x < 0 with a non-zero scale, so -0, NaN and every element of a zero-scale block code +0. Comment only. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rlapping rows Four of the child-process refusal cases repeated a C++ check another case already reaches with the same message: a missing v_scale (the plane check, next to the fp32 plane), the mxfp4 index cache (next to the page-layout nvfp4 one) and two of the four aliased-plane cases (one K/V payload and one index scale plane stay, both through nv_plane). 11 calls instead of 15; the file is shorter than before this branch's gfx1250-strict row. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
review-pr scan (ROCm/aiter main ea578b4, CardROCm/aiter PR #8290 — [HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V and the index key in the row layout (gfx950, gfx1250)Lets the fused qk-norm op write K, V and optionally the index key directly as NVFP4 rows (e2m1 payload plus E4M3 scale plane, free page and head strides) on gfx950 and gfx1250, selected by byte-typed scale planes and a new Review (advisory):
Scan logThe fired rules on the new head (
|
| Finding on the card | On the new head |
|---|---|
| Row layout refused on gfx1250-strict although the kernel has no gfx1250-only switch | Fixed: the wrapper and the op test use base_gfx_arch(get_gfx_runtime()); test_rows_reject expects a strict call to be taken. Checked on the host with mocks. Not compiled for strict, not run on A0. |
| Row layout enabled on gfx950 without a hardware run | Open: needs a green MI35X run of op_tests/test_fused_qknorm_nvfp4.py at the new head. |
A third candidate (no timing entry point in the op test) was killed by the independent reader: test_nvfp4_rows times every row case with run_perftest.
|
The
Card
Step 8 gates |
|
Status at Review of 11-24:
New since the 11-26 reply (three small commits on
What ran at this head:
Scan note 2 (reader PR): correct. The description still names #8289 as the reader of these rows; #8289 was closed unmerged, and the reader is now draft #8365. The description will be corrected separately; ROCm/ATOM#3581 stays the writer-side consumer. Still open:
|
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- Nit: the kernel's sign-rule comment still has the old wording.
csrc/kernels/fused_qknorm_idxrqknorm.cu:605-609says "The sign is that of the IEEE product: none for a NaN, a zero, or any element of a zero-scale group". That is not what IEEE gives:-0 * (1/s)is-0, and a negativextimes the1/0of a zero-scale group is-inf, so the product carries a sign in both cases. The kernel (cu:631-638) sets the sign only forx < 0with a non-zero scale byte. 43874be fixed this sentence in the wrapper (aiter/ops/fused_qknorm_idxrqknorm.py:388-390); please use the same wording in the kernel. - Nit: squash text and description. aiter squashes with the commit messages, so all four land on main.
- 34d77c3, 43874be and 6a6934d describe in-branch history ("was refused although", "The comment said", "11 calls instead of 15; the file is shorter than before this branch's ..."), which means nothing on main.
- bc7cbbb never mentions gfx1250-strict.
- Please squash to one message: bc7cbbb's body plus one sentence on gfx1250-strict.
- Also update the description's "Not covered" line ("gfx950 has never been run on hardware for the row layout"). MI35X CI at this head has run it (see below).
Prior asks (11-24)
- Stale index-cache text and squash body: fixed (
py:392-394,cu:2311-2313,cu:2330-2333). bc7cbbb is a single final-state body. - Python decides only the arch: fixed (
py:491-500). The "rows fp4 index" case now asserts the C++ message. - Named scale-plane strides: fixed.
NvRowsis atcu:731-743, and its strides are read atcu:948-949andcu:1159-1160. The split-stride cases pass on MI35X. - Both aiter-bot threads have author answers but are still unresolved. Please resolve them.
Root cause vs patch
The producer op now writes the consumer's NVFP4 row layout in the launch it already runs, so ATOM no longer stages BF16 and re-quantizes afterwards. It reuses #8472's nvQuantLane / storeNvfp4IndexRow through a kRows flag rather than copying them. The scale dtype selects the layout, and every combination rule is a C++ host check. Verdict: root fix.
Checked, no change needed
- MI35X CI at 6a6934d (run 46877700011, shard 2/8) ran
op_tests/test_fused_qknorm_nvfp4.py: 84test_nvfp4_rowscases, all byte-exact, and both row-layout and page-layout refusals reported ok. Shard 4/8 ran the idxrqknorm and prefill tests; both passed. There is no gfx1250 CI lane. gfx1250-strict is enabled from source only, as the description says. - No other front can take a row-layout call: the raw front needs fp32
[1]scales, and the deferred front needs K and V to be one tensor. Thenv_planeoverlap check is sound. - Existing kernels change only a kernarg offset, and the host cost is a few bool tests.
- The PR merges cleanly with current main (d21d704). #8011 edits the same files. Whichever PR lands second must route or refuse the row layout on the
qkv_partialspath.
Reviewed at 6a6934d (round 2, pass A; whole PR diff, since the branch was re-ported onto #8472).
What
fused_qknorm_idxrqknormcan now write NVFP4 K/V, and optionally the index key, straight into the NVFP4 row layout. This is the layout of MiniMax-M3's sparse NVFP4 pool and of the FlyDSL paged decode's NVFP4 K/V.kv_cache_dtype="nvfp4"with bytek_scale/v_scale(uint8 or float8_e4m3fn) selects the row layout. Per (page, kv head) it writes an e2m1 payload[128, 64]and an E4M3 scale plane[128, 8], with no global scale.index_cache_dtype="nvfp4"with the new optionalindex_scalewrites the index key in the same row layout and in the same pass. The payload is[pages, 128, 64], the plane is[pages, 128, 8], and rows are addressed byindex_slot_mapping.scale = e4m3(amax / 6)(RNE, saturating at 448), thencodes = e2m1(x * (1 / scale))rounded half to even, sign included, in IEEE arithmetic. This is the rule of ATOM's Triton NVFP4 stores (kv_nvfp4_store,index_fp4_store). The scale byte and the code magnitudes come from the page layout's quantizer (nvQuantLane) with a unit global scale:amax * float32(1/6)rounds to the same e4m3 byte asamax / 6for every bf16 and fp16amax. Only the sign is the row layout's own: none for a NaN, a zero, or any element of a zero-scale block. It is read from the bits ofx, because this file is built with fp32 denormals flushed andx * (1 / scale)can be one.[1]k_scale/v_scalestill select the [HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V/index-K caches #7824 page layout, and that path behaves as before. The page-layout nvfp4 and mxfp4 modes stay gfx950-only. With the row-layout K/V, the index cache may be"auto", fp8, or NVFP4 rows; the mxfp4 and page-layout nvfp4 index caches are refused by the C++ host checks (each would be its own set of kernels).kNvRowsandkNvIndexRows(both default false), plus one trailing argument,NvRows: the page and head strides of the K and V scale planes, and the index rows' scale plane and page strides. The K/V payloads use the existing page and head stride arguments. The row store is the page layout's index-row store (storeNvfp4IndexRow) with akRowsflag.Why
ATOM staged MiniMax-M3 sparse-layer K/V and the index key in BF16, then quantized them to NVFP4 in extra launches: two for K/V and one for the index key, per sparse layer. With this change all three come out of the one qk-norm launch, and the BF16 staging buffers go away.
The consumer is ROCm/ATOM#3581 (draft; ROCm/ATOM#3634 is stacked on it): its sparse layers call this op with the pool's E4M3 planes as
k_scale/v_scale, and withindex_scalefor the index key. The K/V rows are read by the FlyDSLpa_decodeNVFP4 path carried by draft #8365 (#8289, which introduced it, was closed unmerged).Timing on the current head (MI455X, one GPU, bf16, 16 q heads per kv head, slot-mapped writes; median of 5 runs × 200 iterations of
run_perftest, min–max in parentheses; a script outside the tree):"auto"K/V + fp8 index (µs)The table of the previous description was measured before #8472 reworked the kernel and is withdrawn. This PR does not measure an end-to-end gain.
Relationship to #7824, #8472, #8607 and #8011
"nvfp4", and thek_scaledtype tells them apart. The Python wrapper uses that only to pick the arch check (gfx950 or the gfx1250 family for byte planes, gfx950 for the fp32 globals); every other rule of the row layout is a C++ host check.fusedNvfp4InsertPrefillKernel) and raw-pointer entry (fused_qknorm_nvfp4_raw) are not extended to the row layout and do not refuse it: a row-layout call of their call shape runs the generic kernel. The variant is the page layout's work mapping (V runs inside the octets of the page layout's 32-bit V words, K scales in MFMA lane order, one page stride for one K+V tensor, fp32 global scales) and is compiled for gfx950 only. The launcher reaches it underkNvfp4, which the row layout does not set; the wrapper's raw front is not entered whenindex_scaleis given, so a page-layout call that passesindex_scalereaches the C++ refusal instead of having the argument dropped.index_scaleis given.qkv_partialsinput (in [HIP] [FlyDSL] [Perf] fused_qknorm_idxrqknorm: faster on gfx1250, split-K partials as input #8011 an fp4 cache takes the partials through the reduce-first kernel). A trial merge of the two heads conflicts in five files (kernel, wrapper, this op test, header, binding), 21 hunks.Testing
The two op tests ran on one idle MI455X (image
rocm/fw-bringup:gfx1250-minimax-m3-20261112) at the head. The module was not rebuilt in that run; the C++ is unchanged since bc7cbbb (the three later commits change the wrapper's arch gate, the op test's gate and refusal table and one comment). The rest ran without a GPU.python3 op_tests/test_fused_qknorm_nvfp4.py: exit 0; 84 of 84 row-layout cases with zero byte error (kv err,idx err,q errall 0);row-layout reject: ok; the page-layout part skips on gfx1250 ("tested on gfx950 only").test_nvfp4_rows: 84 cases against a torch reference of the rule, applied to the same call with"auto"caches, byte for byte. Cases cover bf16 / fp16; 1 / 2 / 4 kv heads; fp8, bf16 and NVFP4-rows index caches; uint8, e4m3 and mixed scale views; pad slots; andskip_index_branch. Each payload and plane is a strided field of one pool pre-filled with random bytes, and the whole pool is compared, so stray writes fail. 9 cases use odd bases and odd page and head strides; 9 put every plane on its own page stride and head stride; 3 are the call shape of [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's prefill variant and raw entry (16 q / 1 kv / 1 index heads, bf16, e4m3index_q_out) in the row layout. The V rows include ties, clamps, subnormal scales, signed zeros, zero-scale blocks of either sign, elements whosex * (1 / scale)is an fp32 denormal, NaN and infinities.test_rows_reject: at bc7cbbb 15 calls, each in a child process (2 valid ones and 13 host refusals, each matched on its C++ message); the head keeps 11 of them (four refusals that repeated another case's check and message are dropped); plus, in process, the wrapper's arch gate for each scale dtype (gfx942 refused, gfx1250-strict taken for byte planes; gfx1250 refused for the fp32 globals) and the deferred front's refusal ofindex_scale.gate_host.py, the C++ entry mocked and the arch faked): the row layout is taken on gfx950, gfx1250 and gfx1250-strict and refused on gfx942 and gfx1100; the page layout is taken on gfx950 only. At bc7cbbb the gfx1250-strict call was refused.python3 op_tests/test_fused_qknorm_idxrqknorm.py: exit 0; 21 passed, 0 failed.quant_host.py): the source text of the quantizer and ofstoreNvfp4IndexRowis cut out of the .cu and compiled with g++ (the non-gfx950 path, which is what gfx1250 compiles; lane exchanges,__fdiv_rn, NaN-skipping min / max and flushed denormals are stand-ins). 809200 rows (the test's own rows for bf16 and fp16, every 16-bit pattern of both dtypes in three orders, the finite ones at four scales), each stored at a token of a pre-filled page: 0 bytes differ from the test's reference and nothing else is written. This models the source on a CPU; it is not what the GPU executes. Four mutants of the sign rule (sign from the product, no zero-scale guard, -0 signed, NaN signed) each differ.e4m3(amax / 6)againste4m3(amax * float32(1/6)): 0 of 64386 bf16 / fp16amaxvalues differ.host_checks.py): the module is built for gfx1250 and for gfx950 in a GPU-less container, and its Python wrapper and C++ host checks are driven with the op test's operands as CPU tensors that claim a GPU device. Nothing can launch there: an accepted call stops athipGetDevice. 145 calls on the gfx1250 build and 158 on the gfx950 build give the expected verdict: the 15test_rows_rejectcalls, the 13 page-layouttest_rejectcalls (gfx950 build), the 84 row-layout calls of the sweep, 28 further stride / dtype cases, 13 arch-gate cases and 5 dispatch cases. The dispatch cases mock the device and the C++ entries: a page-layout call of the prefill shape reaches the raw entry; the same call withindex_scale, and row-layout calls, reach the generic entry; a parked QKV front givenindex_scaleraises before its chain kernel.index_scaleterm of the raw-front gate, the page-layout +index_scalecall reaches the raw entry and 15 row-layout calls enter the front (which declines them); without the deferred front's term, its chain kernel is called withindex_scaledropped.test_nvfp4_rowsis run with the op replaced by an emulation that quantizes rows with the test's reference and stores them at the byte addresses the kernel computes from each tensor's base and strides. All 84 cases come out byte-exact. With an emulated 16-bit store that assumes alignment, the 75 even-layout cases still pass and all 9 odd-layout cases fail. With V's scale plane or V's payload on K's strides, or the scale planes on their payload's page stride, 8 of the 9 split-layout cases fail (the ninth writes page 0 only); with V's scale plane on K's head stride, the 6 with more than one kv head fail.4960107ee; gfx1250 and gfx950, device code, the JIT's flags):0xe8→0x120, two instructions per kernel).v_divper kernel, was 16–24).Not covered
op_tests/test_fused_qknorm_nvfp4.py(with its new refusal case) skips on gfx1250: no hardware run from us, it runs on MI35X CI.__gfx950__switches in the kernel file; opus pairs__gfx1250_strict__with__gfx1250__). It was not compiled for strict and not run on A0.test_fused_qknorm_nvfp4.pythere, both the row part and the page part (the latter with the new refusal case).qkv_partialsinput for the row layout belong to the [HIP] [FlyDSL] [Perf] fused_qknorm_idxrqknorm: faster on gfx1250, split-K partials as input #8011 rebase.index_scale; it is a draft that depends on this PR and on that reader (now in draft [FlyDSL] gfx1250 PA decode: MXFP8 (E8M0 group-32) output for o_proj #8365).PR Self-Review
Reviewed revision
6a6934d
Behavior and intent
kv_cache_dtype="nvfp4"and bytek_scale/v_scaleplanes, the op writes K/V, and withindex_scalethe index key, as NVFP4 rows (e2m1 payload plus E4M3 scale plane) in the same launch as norm and RoPE. Before, this combination of arguments was refused.index_scaleis refused, also through the raw front and the deferred front. Their kernels differ from main only in the implicit-kernarg offset; the prefill kernels not at all.Validation and unverified scope
Reviewed revision
6a6934d31fc43d5fa6ec5e367b3ee5d876830bc0. Unless a bullet says otherwise, the items below were run at bc7cbbb, whose C++ is the head's (the three later commits touch the wrapper's arch gate, the op test's gate and refusal table and a comment). The CPU items used the imagerocm/fw-bringup:gfx1250-minimax-m3-20261112without devices; the two op tests ran on one MI455X at the head.module_fused_qknorm_idxrqknormwithGPU_ARCHS=gfx1250and withGPU_ARCHS=gfx950(aiter.jit.core.build_module, no GPU): both build.python3 host_checks.py <arch>on each of the two builds (local script;AITER_AOT_REPLAY=1 GPU_ARCHS=<arch>, CPU tensors that claim device 0, one child process per call that reaches C++): 145 calls on the gfx1250 build and 158 on the gfx950 build give the expected verdict, 0 bad. Four mutants (overlap check, byte-dtype check, raw-front gate term, deferred-front term) are each caught.test_nvfp4_rows(same script, no GPU): 84 of 84 cases byte-exact; the alignment and the four stride mutants fail the cases built for them.hostpy.py quant_host.py(local script, host g++; a host model of the kernel source, not what the GPU executes): 809200 rows, 0 bytes differ from the test's reference and no byte outside the row changes; four sign-rule mutants differ;quant_host.py sixth: 0 of 64386amaxvalues differ.4960107ee(hipcc --cuda-device-only -Swith the JIT's flags,--offload-arch=gfx1250andgfx950): 3 existing kernels identical, 680 differ only in the implicit-kernarg offset (0xe8→0x120), with the same resources; 16 new kernels.python3 op_tests/test_fused_qknorm_nvfp4.pyin the image without a GPU: exits 1 at the file's first tensor (No CUDA GPUs are available), the statement main's file has too.hostpy.py gate_host.py(wrapper arch gate, C++ entry mocked, arch faked): row layout taken on gfx950 / gfx1250 / gfx1250-strict, refused on gfx942 / gfx1100; page layout taken on gfx950 only.scratch_np/isa_host.sh <tree> gfx1250 <out> "--cuda-host-only -fsyntax-only"on the kernel file: no errors.python -m black --checkandruff check --no-cacheon the two changed Python files: pass.python3 op_tests/test_fused_qknorm_nvfp4.pyexits 0 (84 row cases byte-exact,row-layout reject: ok; the page-layout part skips, "tested on gfx950 only") andpython3 op_tests/test_fused_qknorm_idxrqknorm.pyexits 0 (21 passed).4960107ee, interleaved, 5 rounds ("auto"and fp8-asm K/V with an fp8 index at 64 / 3000 / 16384 tokens, 1 / 4 kv heads; 12 rows): this head − main is between −0.6% and +0.1% of the median, i.e. unchanged.op_tests/test_fused_qknorm_nvfp4.pyon hardware (skips on gfx1250; MI35X CI); gfx1250-strict itself (not compiled for strict, not run on A0); the in-bounds kernel mutants; gfx950 hardware (compile, ISA and the host-check dry run only; MI35X CI is the first run of the row layout there, on [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's hardware converts); the byte comparison against ATOM's Triton stores, last run on MI455X at 1712b07 with the previous arithmetic; an end-to-end ATOM run; clang-format.PR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
kv_cache_dtype="nvfp4"andk_scaleis a byte tensor (uint8 or float8_e4m3fn). The index key takes the new path only when, in addition,index_cache_dtype="nvfp4"andindex_scaleis given. fp32[1]scales keep the [HIP] fused_qknorm_idxrqknorm: write NVFP4 K/V/index-K caches #7824 page layout, including [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's prefill variant and raw entry; every other mode runs the same device code as before, apart from the implicit-kernarg offset.base_gfx_arch(get_gfx_runtime())is gfx950 or gfx1250 (RuntimeError), so gfx1250-strict is taken. The page-layout nvfp4 and mxfp4 caches stay refused off gfx950. The wrapper decides nothing else about the row layout.block_sizeis 128 and head_dim is 128. K/V payloads are[pages, nkv, 128, 64]and planes[pages, nkv, 128, 8]; the index payload is[pages, 128, 64]and its plane[pages, 128, 8]. Token rows are contiguous (the layout's definition). The mode is sparse insert only (qkv carries the index slots).AITER_CHECKbefore any launch, together with the device of every tensor. It refuses an mxfp4 or page-layout nvfp4 index cache with the row-layout K/V, and refusesindex_scalewithoutindex_cache_dtype="nvfp4", the row-layout K/V and the index branch. The two Python fast paths that bypass that entry (the raw front, the deferred front) do not take a call withindex_scale.test_rows_rejectandtest_rejectexercise these refusals.asm_layout): slot values are not bounds-checked against the pages, for both the K/V pages and the index rows.Changed op tests
op_tests/test_fused_qknorm_nvfp4.py(the only changed op test; CI runs it aspython3 <file>):test_nvfp4_rowscovers the new row-layout write: K/V rows and index rows, byte for byte against a torch reference of the rule applied to what the same call writes with"auto"caches, on strided fields of one pre-filled pool compared whole. Its odd-layout cases put every payload at an odd base with odd strides; its split-layout cases give every plane its own page and head stride; its prefill-shape cases would write page-layout bytes into the pool if the call were routed to [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's variant or raw entry.test_rows_rejectcovers the new host refusals (one case per C++ check and message), the wrapper's arch gate for each scale dtype and the deferred front's refusal ofindex_scale. The aliased views are pages expanded from one, and the four tokens write page 0 only, so those cases stay in bounds even if their check regressed.test_reject(page layout, gfx950) gains one case: a call of the raw front's shape withindex_scalemust be refused.stress_qkvtakes its largest magnitude from the dtype (3e38does not fit fp16, which the row sweep runs).op_tests/test_fused_qknorm_idxrqknorm.pyhas no NVFP4 case. Nothing else checks the row layout, its strides, or gfx1250. The file is extended rather than a second suite added.