You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HIP] fused_qknorm_idxrqknorm: write MXFP4 index-K and main KV caches, emit an fp8 main Q - #7057
fused_qknorm_idxrqknorm can now write its caches as MXFP4 (e2m1 data, e8m0 scale per 32 elements), and its q_out can be an fp8 e4m3 tensor:
index_cache_dtype="mxfp4": the index-K slot is quantized and written into 128-token MXFP4 pages.
kv_cache_dtype="mxfp4": the main K (post norm + RoPE) and V are quantized and written into 128-token MXFP4 pages, one per (page, kv head).
q_out as an e4m3 tensor (float8_e4m3fn or uint8): the post norm + RoPE main Q is written as a unit-scale, saturating e4m3 cast instead of bf16/fp16, the same way an e4m3 index_q_out already works.
This kernel is the producer. The pages it writes are consumed by the MXFP4 index-score kernels (#7060 decode, #7061 prefill) and the MXFP4 paged-attention decode (#7056); this PR has no dependency on either and is tested without them. ATOM integration: ROCm/ATOM#2770 (draft; depends on these aiter PRs and on yuhua/m3.1-flash).
Fifteen commits: (1) index-K MXFP4 write, (2) main-KV MXFP4 write plus e4m3 Q output (first as separate q_fp8_out/q_scale arguments), (3) launch-lambda dedup in the .cu (vs the previous head: same registers for all 444 instantiations, same machine code for the 288 existing ones), (4) the two op tests merged into one aiter-style script, (5) a pytest entry test_sweep (dropped again in (12)), (6) the e4m3 Q goes through q_out and the q_fp8_out/q_scale arguments are removed, (7) the e4m3 test reaches out-of-range values, (8) the e4m3 q_out cast saturates, (9) mxfp4 caches are refused off gfx950 and the index-cache size is checked for the page-128 layout and the mxfp4 main K/V, (10) the test sweep is slimmed (no device-code change), (11) an fp8 q_out is refused where opus has no fp8 conversion and the mxfp4 V cache must have K's page count (host checks only), (12) the test file loses its pytest hooks (test_sweep, the __test__ flags): it is a plain script, same cases, (13) the test compares bytes with checkAllclose (rtol=atol=0) and reports an err column, same cases (test file only), (14) the MXFP4 test cases move into the existing op_tests/test_fused_qknorm_idxrqknorm.py and op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py is removed (test files only; the kernel and wrapper are unchanged since (11)), (15) two cases of the old file that were not carried over: separate contiguous mxfp4 K/V tensors (now the one-kv-head cases; the pool views stay for two kv heads) and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache (test file only).
Commit 80b5209's message says every existing instantiation compiles to the same code; that holds for that commit only, and at the final head none of the 288 existing instantiations has identical machine code (see Registers).
Format
A 128-token page is [128 x 64 B e2m1 data][128 x 4 B e8m0 scale] = 8704 B. The low nibble is the even element; one e8m0 scale per 32 elements.
Index cache: uint8, whole 8704 B pages, contiguous.
Main KV: per (page, kv head) the K field and the V field are each one 8704 B page. The op takes kv_cache_k / kv_cache_v as separate uint8 [pages, kv_heads, 8704] tensors and uses their own page/head strides, so they can be the K and V views of one pool uint8 [pages, 2, kv_heads, 8704]. block_size must be 128.
e8m0 rule: ceil(log2(amax / 6)) with an eps clamp (the rule of indexer_fp4_scale_e8m0 in cache_kernels.cu); e2m1 rounding is round-to-nearest-even with saturation. Elements are rounded to the input dtype first, so the bytes are the quantization of the row that "auto" mode would write.
e4m3 q_out: e4m3(q) with q rounded to the input dtype first (bf16 or fp16, as every other cache write of this op), scale fixed at 1.0, saturating: finite values beyond the e4m3 max become +-max and +-inf becomes +-max (the elements are clamped before the cast), NaN stays NaN. The clamp is only on the q_out path; an e4m3 index_q_out still uses the plain cast (beyond-range values become NaN there). As with an e4m3 index_q_out, the bf16 row is not written: neither a bf16 q_out nor the in-place qkv row. Insert mode only (kv caches given); an e4m3 q_out without them is rejected.
Known deviation from per_1x32_f4_quant: for an all-zero group, per_1x32_f4_quant gives e8m0 = 0, while the HIP rule gives 1 (0 is outside the decode kernel's contract). The writer uses the HIP rule; data bytes are 0 either way. The tests adjust the reference for exactly that case.
Interface
No new function arguments. New values: index_cache_dtype="mxfp4"; kv_cache_dtype="mxfp4" (sparse insert mode; skip_index_branch=True is supported for layers that reuse another layer's top-k); and q_out may now be an e4m3 tensor (it used to require the qkv dtype). Calls that do not use them are unaffected in behavior. MXFP4 index-K and MXFP4 main-KV are template bools; an e4m3 q_out is a runtime pointer check.
Verification
Hardware: MI355X (gfx950), ROCm 7.2.4 image rocm/atom-dev:nightly_202610261558, one GPU. "Base" is origin/main at 340bea3b54; "head" is this branch on top of it (the commits that landed on main since do not touch this module). The branch was then rebased onto 849f711d39 (which includes #7055); the PR diff is unchanged, and the tests, register counts and device assembly were re-checked on the rebased head with the same results.
Existing behavior.op_tests/test_fused_qknorm_idxrqknorm.py (default sweep, 21 cases, and --minimax_tp4) passes before and after: the default sweep 21/21 rows (1481 passed~ checks) and --minimax_tp4 155 passed~ checks, both times, with identical pass/fail summaries. Re-run at 071a842 (this round, same test file extended by the mxfp4 modes): the 21 existing rows and their 1481 passed~ checks are identical to the unmodified file run on the previous head (same rows, same pass counts, exit 0), and --minimax_tp4 gives 155 passed~, exit 0.
Registers (-Rpass-analysis=kernel-resource-usage, gfx950, every instantiation in the .cu; 288 existing instantiations in base):
existing 288
new instantiations
commit 1 (index-K MXFP4)
288/288 identical VGPR, SGPR, spills, occupancy
144: 20-32 VGPR, 30-57 SGPR
commit 2 (main KV MXFP4 + e4m3 q_out), final head
0/288 identical machine code (new kernel argument and branch); instruction count differs for 144 (up to +100); registers with bare hipcc flags: 107 change VGPR (-2 to +6), 48 change SGPR (-4 to -2); with the JIT build flags 111 VGPR / 40 SGPR; the maximum over all 444 instantiations is 32 VGPR
156 new in total: 20-32 VGPR, 26-48 SGPR
No spills or scratch anywhere (existing and new); occupancy is 8 waves/SIMD for every instantiation, before and after.
Timing of the existing modes (M3 TP4 shape: 16 q heads, 1 kv head, 1 index head, head_dim 128, rot 64, bf16; T = 1, 8, 32, 128, 512, 1024, 4096, 16384; kv fp8 page-16 with scales and auto; index cache auto and fp8). Each point is 50 launches captured in a CUDA graph, median of 21 replays; base and head runs interleaved three times, median of the three, same GPU and pinned cores. Head/base ratio over the 32 points: -0.8% to +1.8%. The kv-fp8 cases are consistently +0.2% to +1.8% (e.g. T=1 4.10 -> 4.18 us, T=16384 69.3 -> 70.2 us); kv-auto cases are within +/-0.7%. Spread between the three repeats is 0.6% median, up to 3% on the worst point, so differences below about 1% are at the noise level.
New modes (head only, same method; ratio of times):
Index-K write, mxfp4 / fp8: 0.98-1.01 for T=1..16384, with kv fp8 and with kv auto. (the mxfp4 table of op_tests/test_fused_qknorm_idxrqknorm.py prints the op-only time (run_perftest, 50 iterations after 50 warmups) of the index-K write with an auto / fp8 / mxfp4 index cache for kv fp8 page-16, kv auto page-16 and kv mxfp4 page-128, T = 1, 300, 1031, 16384, bf16 and fp16: at 071a842 mxfp4/fp8 is 0.98-1.02 over the 24 rows in one run and 0.96-1.04 in a second run, one card, so a single run is good to a few percent.)
Main KV mxfp4 + fp8 Q (page-128) / kv fp8 (page-16 with scales), measured with the earlier separate fp8-Q argument that also wrote the bf16 Q: 0.75 at T=1 to 1.03 at T=16384 (0.75, 0.77, 0.77, 0.77, 0.84, 0.88, 0.98, 1.03 across the T list). Versus the plain bf16 page-128 auto write, which writes more bytes but does no quantization and no fp8 Q, it is 1.11-1.22x. With an e4m3 q_out the bf16 Q is not written, and the same shapes run at 0.81 to 1.00 of that earlier configuration's time (3 interleaved runs, medians). The existing modes are within -1.4% to +1.4% of the previous head. The saturating clamp costs +0.0 to +0.4% on this configuration up to T=512, +1.0% at T=1024, +3.1% at T=4096 and +4.2% at T=16384 (3 interleaved runs, medians; spread 0.2-2.4%); the six other configurations (kv fp8/auto x index auto/fp8/mxfp4) stay within -1.3% to +1.5% of the version without the clamp. The clamp changes registers of 6 of the 444 instantiations by -2 VGPR (no SGPR change, no spills, occupancy 8).
op_tests/test_fused_qknorm_idxrqknorm.py is the existing test, extended; the separate op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py of the earlier heads is removed. It stays a module-level script with no new flags: the new modes are values of --mode (asm_layout_mxfp4, asm_layout_fp8_pertoken_mxfp4, mxfp4_kv, mxfp4_kv_skip_index, q_fp8_out, mxfp4_kv_q_fp8_out, mxfp4_scale_rule, mxfp4_reject) and use the existing -d, --num_tokens and the same default sweep, so the no-argument run that CI executes runs them. On any arch but gfx950 the file prints a warning and runs only the existing modes (exit 0). It reuses make_case, run_fused_qknorm_idxrqknorm (now with optional kv_dtype / index_dtype / q_dtype / index_pages arguments that default to the old behavior), make_shuffle_caches, make_insert_outputs and check_close (which now returns its error ratio); new are the MXFP4 page byte reference, the slot cases and the rejection harness. Measured on the pushed tree: 42-43 s once the HIP module is built (the unmodified file: 5 s); the first run, which also builds the module, took 94 s (the unmodified file: 54 s); the 21 existing rows are unchanged, followed by 50 mxfp4 rows with an err column (0 in all) and auto / fp8 / mxfp4 us and TB/s columns.
The judge is the op's own "auto" mode on the same case: the MXFP4 bytes must equal per_1x32_f4_quant of the "auto" rows bit for bit, over bf16/fp16, T = 1, 300, 1031, 16384, index-K mxfp4 (and fp8, and the auto control) with kv fp8 (page-16, per-token scales) / auto, main K/V mxfp4 (page-128; 1 kv head as separate contiguous K and V tensors, 2 kv heads as the two views of one pool) with index cache mxfp4/fp8/auto, and sequential / shuffled / skipped(-1) / main-index-differing slot mappings (336 comparisons); every other output (q, index q, scales, the other cache) must be bit-identical to "auto", and an fp8 index cache must equal the "auto" rows cast to e4m3. Also: skip_index_branch (mxfp4_kv_skip_index), K and V as views into one [pages, 2, kv_heads, 8704] pool (the 2-kv-head cases), an e4m3 q_out (float8_e4m3fn and uint8 views, kv auto and mxfp4) against the input-dtype q clamped and cast to e4m3 (with out-of-range, +-inf and NaN columns), with the qkv row left untouched, rewriting a slot replaces all 68 bytes, zero/sparse/outlier index-K rows in every case, a torch dequantization of the pages read back at the documented offsets, the e8m0 rule vs its bit-level definition (mxfp4_scale_rule), and contract rejections (mxfp4_reject: non-uint8 or partial-page index cache, an index cache of 128 bytes or with too few pages next to an mxfp4 main KV, an mxfp4 V cache with fewer pages than K, skip_index_branch with an mxfp4 index cache, each in its own interpreter because AITER_CHECK aborts the process; mxfp4 index cache, mxfp4 main K/V with each kind of index cache, and mxfp4 main K/V alone off gfx950, and an fp8 q_out on gfx1100, in process with the arch faked). Byte comparisons go through checkAllclose(rtol=0, atol=0) on the raw bytes; a rejection row reports err 0 when the expected refusal occurred.
No FlyDSL scorer or PA kernel is needed by these tests.
Known limits
Tested on gfx950 only; mxfp4 caches are refused with a RuntimeError on any other arch (opus converts to fp4 as zeros there), and its mxfp4 modes skip there. An e4m3 q_out is refused with a RuntimeError where opus has no fp8 conversion (anything but gfx942, gfx950, gfx1200, gfx1201, gfx1250); it is untested on gfx942 and gfx12xx. block_size must be 128 for the MXFP4 caches.
Written for the MiniMax-M3.1 shape (all-sparse layers, head_dim 128, 16 q heads / 1 kv head per TP4 rank; kv head count 1 and 2 are tested). Other models are untested.
An e4m3 q_out is a runtime pointer check, not a template bool, and the kernel gained an argument, so no existing instantiation has identical machine code (see Registers); there are no spills and occupancy stays 8 waves/SIMD for all 444 instantiations. If maintainers want the existing instantiations unchanged instruction for instruction, it can be turned into a template bool.
The all-zero-group e8m0 difference from per_1x32_f4_quant described under Format.
Consumers (index score, paged attention) are in separate PRs and are not exercised here.
Before: fused_qknorm_idxrqknorm could write only bf16/fp16 or fp8 (with scales) caches and a bf16/fp16 main Q. The MiniMax-M3.1 MXFP4 path needs index-K and main K/V stored as MXFP4 pages and an e4m3 main Q, and the kernels that read them (#7060, #7061, #7056) take exactly that layout; the op had no way to produce it. After: index_cache_dtype="mxfp4", kv_cache_dtype="mxfp4" and an e4m3 q_out are new accepted values, written by the same fused kernel (format in "Format"). Calls that use none of them keep their behavior; no existing instantiation keeps identical machine code (see Registers).
Validation and unverified scope
Measured at head 071a842 this round: MI355X (gfx950), image rocm/atom-dev:nightly_202610261558 with this branch's tree overlaid, a freshly built HIP module and FlyDSL cache off, one card. python3 op_tests/test_fused_qknorm_idxrqknorm.py with no arguments from the repo root (43 s, exit 0) and from /tmp (42 s, exit 0; the first run that also builds the HIP module took 94 s): the 21 existing rows (1481 passed~, rows and pass counts identical to the unmodified file run on the previous head) and then 50 mxfp4 rows (2057 passed~, err 0 in every row). --minimax_tp4 gives 155 passed~, exit 0. With one expected value deliberately changed (the e8m0 scale in the byte reference, not committed) the script exits 1 at the first mxfp4 row (index_cache mismatch ratio 0.00046, after the 21 existing rows passed); with an existing expectation changed (refs["q"] + 1, not committed) it exits 1 at the first existing row. With the wrapper's guard changed to ignore kv_cache_dtype (local copy, not committed) the mxfp4_reject mode exits 1 (accepted on gfx942 for an mxfp4 main K/V with an auto index cache). With GPU_ARCHS=gfx942 forced on the gfx950 card (this exercises only the arch gate, not gfx942 hardware) it prints the skip warning, runs the 21 existing rows and exits 0. black 26.10.1 and ruff 0.16.0 are clean on the file.
From earlier manual runs, not re-run at this head: register counts, instruction-count and machine-code comparisons, and every timing table in "Verification" except the index-K write table named there (including the head/base ratios and the clamp cost). Unverified: gfx942 and gfx12xx hardware (the fp8 q_out guard allows them; no run there), models other than the MiniMax-M3.1 shape, and CI at this head (the aiter GPU shard tests had not run on this PR when this was written).
PR-specific question
Architecture: the wrapper raises RuntimeError for an mxfp4 kv_cache_dtype or index_cache_dtype unless get_gfx_runtime() == "gfx950" (opus converts to fp4 as zeros elsewhere), and for an e4m3 q_out unless the arch is in _FP8_CVT_GFX (gfx942, gfx950, gfx1200, gfx1201, gfx1250; opus has an fp8 conversion there). mxfp4_reject exercises the refusals by overriding get_gfx_runtime; on real gfx942/gfx12xx hardware it was not run.
Dtype: qkv bf16 or fp16 (as before; both swept); mxfp4 caches must be uint8 (AITER_CHECK: not_uint8 case); k_scale/v_scale are refused with an mxfp4 KV cache; q_out e4m3 as float8_e4m3fn or a uint8 view (both swept).
Shape: block_size must be 128 for an mxfp4 KV cache; K and V are [pages, kv_heads, 8704] with matching kv-head count and the V cache must have at least K's page count; the index cache must be whole 8704 B pages holding at least num_blocks * block_size rows (checked for the page-128 layout and for an mxfp4 main K/V; the asm_layout path only checks whole 128-element rows, because its main-cache span is not the index cache's page domain); an mxfp4 KV cache needs the sparse insert mode with index slots, an mxfp4 index cache needs insert mode with the index branch (so skip_index_branch with an mxfp4 index cache is refused), an e4m3 q_out needs insert mode. head_dim 128 and the q/kv head counts are the op's existing constraints. Violations of the shape/dtype checks are AITER_CHECKs that abort the process rather than raise, which is why the mxfp4_reject mode runs each case in its own interpreter. Not covered: other head_dim values and models, which are untouched existing limits.
Changed op tests
op_tests/test_fused_qknorm_idxrqknorm.py (existing file, +333 -5 lines; the earlier heads added a separate 549-line test_fused_qknorm_idxrqknorm_mxfp4.py, now removed, so the op tests of this PR are 333 added lines instead of 549). The existing test knows only the auto/fp8 caches and a bf16 Q, so it could not see any of the new modes; it is extended rather than duplicated so the new cases share its inputs (make_case), its op runner, its comparison helper, its --mode / -d / --num_tokens sweep and its table. The existing 21 rows and --minimax_tp4 are unchanged (same rows, same pass counts). The lines that remain are what the file could not already express: the MXFP4 page byte reference (about 40), the slot cases, the rejection harness and the per-mode check loop. This file fails when: a page byte is wrong (nibble order, e8m0 byte, page or slot offset), checked bit for bit against per_1x32_f4_quant of the rows the op's own "auto" mode writes, for 336 write comparisons incl. shuffled, skipped (-1) and main/index-differing slots; a write disturbs another output (q, index q, the other cache must equal "auto"); a rewritten slot keeps stale bytes; the e4m3 q_out does not saturate or leaves the qkv row modified; an unsupported arch or malformed cache is accepted (mxfp4_reject). Verified failing only for the changed-expectation runs described above; I did not break the kernel itself.
ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm
vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all
All standard extended tests (excludes ci:atom_full)
Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7057 --add-label <label>
One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.
PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.
…rite
Follow the final ROCm/aiter#7057 API: `fused_qknorm_idxrqknorm` no longer has
`q_fp8_out` / `q_scale`; an e4m3 `q_out` is written with a saturating cast at
scale 1.0 and no bf16 q row is written. The bytes are those `q_fp8_out` gave.
Signed-off-by: ganyi <[email protected]>
Co-Authored-By: Claude <[email protected]>
follows the final aiter fused_qknorm_idxrqknorm API (ROCm/aiter#7057): q_fp8_out
and q_scale are gone, and an e4m3 q_out makes the kernel write the main q as
unit-scale saturating e4m3, with no bf16 q row and no write-back into the packed
qkv. The MXFP4 path now allocates one float8_e4m3fn q_out and passes it as q_out.
The bytes are those of the old q_fp8_out with q_scale=None. Nothing after the
call reads the bf16 q or the normalised qkv q region: the sparse prefill/decode
read q only for its shape and hand it to pa_decode_mxfp4, the index scorer reads
the separate index_q, and k/v are the pre-call views, ignored by the sparse
backends.
Co-Authored-By: Claude <[email protected]>
Extends the fused HIP normalization and RoPE operator to produce MXFP4 caches and FP8 main-Q output for downstream index-score and paged-attention consumers, without adding function arguments.
Changes:
Adds MXFP4 writes for index-K and main K/V using 128-token pages.
Supports unit-scale, saturating e4m3 output through q_out.
Adds correctness, layout, rejection, and performance sweeps for the new modes.
File
Description
op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py
Adds MXFP4 and FP8-Q validation and benchmark sweeps.
csrc/kernels/fused_qknorm_idxrqknorm.cu
Implements quantized writes, dispatch, and input validation.
aiter/ops/fused_qknorm_idxrqknorm.py
Documents the new cache formats and Q-output option.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Missing MXFP4 architecture guards can silently produce all-zero cache data on gfx942, while incomplete index-cache page validation permits out-of-bounds scale writes.
Enforce documented bf16 intermediate rounding for fp8 conversion
csrc/kernels/fused_qknorm_idxrqknorm.cu:557
The stated e4m3(bf16(q)) contract is not met for fp16 inputs: storeCacheElems rounds through scalar_t, so it uses an fp16 intermediate and can produce different fp8 values near rounding boundaries. The oracle in test_q_fp8_out also uses the input-dtype output rather than enforcing the documented bf16 intermediate. Either enforce bf16 rounding and update the oracle, or document input-dtype rounding consistently.
Avoid unsupported-target fp8 finfo failure during test collection
On unsupported targets such as gfx90a, aiter.utility.dtypes sets dtypes.fp8 to torch.uint8. This module-level torch.finfo call therefore raises before either architecture gate can skip the suite, causing pytest collection to fail. Since the suite only runs on gfx950, use the explicit e4m3fn dtype here, or defer this computation until after the gate.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
MXFP4 requests lack an architecture gate to prevent silent zero output on gfx942, and incomplete index-cache page validation can permit out-of-bounds writes.
Use BF16 intermediate for main-Q FP16 MXFP4 conversion
csrc/kernels/fused_qknorm_idxrqknorm.cu:566
The new main-Q path does not implement the documented e4m3(bf16(q)) contract for fp16 inputs: storeCacheElems<scalar_t, ...> rounds through fp16 instead. For example, a post-norm value of 1.064453125 produces e4m3 1.125 through fp16, but rounds to bf16 1.0625 and then e4m3 1.0 under the stated contract. Use an explicit bf16 intermediate for this path and update the fp16 test oracle, which currently also omits that conversion, or explicitly revise the public contract to specify input-dtype rounding.
…urating q_out clamp)
Tree equals ganyi/m31-mxfp4-testing-v2. First parent is the previous tip of
this branch, second parent is the v2 tip.
Co-Authored-By: Claude <[email protected]>
Review-body items that had no inline thread, handled in ee3ecab:
fp16 intermediate for the e4m3 q_out ("bf16 intermediate"): a documentation mismatch, not a kernel bug. The path rounds to the input dtype first like every other fp8/MXFP4 write of this op, and the test oracle does the same. The contract is now worded that way in the PR body and the test; no kernel change.
torch.finfo(dtypes.fp8) at import (fails where dtypes.fp8 is uint8): moved into the test function.
Missing architecture guards / undersized index cache: see the two inline replies (wrapper raises off gfx950; index-cache size checks for every layout).
New index_cache_dtype="mxfp4": the index-K slot is quantized to e2m1 with one
e8m0 scale per 32 elements and written into single-region 8704 B pages,
[128 tokens x 64 B data][128 tokens x 4 B scale]. Low nibble is the even
element; the scale rule is indexer_fp4_scale_e8m0's (ceil(log2(amax/6)), eps
clamp) and the rounding the hardware scaled_cast<fp4_t> already used by the DSA
writer.
Only the index-K write changes. It is a kIndexFp4 template bool, so every
existing instantiation compiles to the same code (identical VGPR/SGPR counts,
no spills); q/k norm, RoPE, index Q and the main KV are untouched, and the
thread mapping is still one warp per slot. The elements are rounded to the
input dtype first, so the bytes are the quantization of the row "auto" writes.
The new instantiations are launched from one generic lambda placed ahead of the
four existing launch sites, which are not touched.
Co-Authored-By: Claude <[email protected]>
…ting op test, drop the separate file
The MXFP4 cases move into op_tests/test_fused_qknorm_idxrqknorm.py, on its
make_case / run_fused_qknorm_idxrqknorm / check_close helpers, its --mode / -d /
--num_tokens sweep and its markdown table, and
op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py is removed. The runner gains
optional kv_dtype / index_dtype / q_dtype / index_pages arguments; the existing
modes and rows are unchanged. The mxfp4 modes run on gfx950 only and are skipped
with a warning elsewhere.
Co-Authored-By: Claude <[email protected]>
Head is now 55185dd (one test-only commit on 14ad2fc; kernel and wrapper unchanged).
The MXFP4 / e4m3 q_out tests moved into the existing op_tests/test_fused_qknorm_idxrqknorm.py, on its make_case, run_fused_qknorm_idxrqknorm, check_close, --mode / -d / --num_tokens sweep and table, and op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py is removed. No new flags; the default no-argument run covers them on gfx950 and skips them with a warning elsewhere.
op_tests diff against main: +329 -5 in one existing file (before: +549 in a new file; whole PR +686 -36, was +906 -31).
The 21 existing rows and their 1481 passed~ checks are identical to the unmodified file; --minimax_tp4 155 passed~.
50 mxfp4 rows added, err 0 in all; default run 43 s from the repo root and 42 s from /tmp on gfx950 (exit 0 both; unmodified file 5 s), 94 s for a first run that builds the HIP module.
A deliberately changed mxfp4 expectation and a changed existing expectation each make the script exit 1 (not committed).
PR body updated (Tests, Changed op tests, Reviewed revision, validation). CI has not run at this head yet.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Exact-head GPU correctness and latency validation is missing for the new MXFP4 writes and FP8 Q path, including the permitted but untested gfx942/gfx12xx targets.
…nd the kv-only arch guard
Two cases of the pre-merge mxfp4 test were not carried over: mxfp4 K and V as
separate contiguous tensors (now used for one kv head, the pool views stay for
two), and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache.
Co-Authored-By: Claude Code <[email protected]>
Head is now 071a842 (one more test-only commit on 55185dd; kernel and wrapper unchanged).
Parity check of the folded test against the removed file found two cases that had not been carried over, now added (+4 lines): mxfp4 K and V as separate contiguous tensors (the old 180 write cases used them; after the fold only the pool views were left), and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache (the folded kv case also had an mxfp4 index cache, so it could not isolate the kv_cache_dtype guard). Everything else maps one to one: write bytes (30 old configs are a subset of the 42 per dtype and token count), skip_index_branch, e4m3 q_out (8 -> 16 rows), existing index modes, 68-byte rewrite, zero/sparse/outlier rows, dequantized pages, e8m0 scale rule, the 7 rejections and the arch guards. The only dropped items are timing rows at T = 32, 128, 1024, 4096.
At 071a842 on gfx950: default run exit 0 from the repo root and from /tmp (42 s once built), the 21 existing rows and 1481 passed~ identical to the unmodified file, 50 mxfp4 rows err 0; with the wrapper guard changed to ignore kv_cache_dtype (local, not committed) the mxfp4_reject mode exits 1. op_tests diff vs main: +333 -5 in one existing file. PR body updated.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The newly enabled gfx942/gfx12xx FP8 Q paths require target-specific GPU validation of conversion and saturation, while supplied hardware results cover only gfx950.
… UT (review #7057)
- kQFp8 is a bool template of the kernel, instantiated only where insert mode can use it, instead
of a runtime `q_fp8_out != nullptr` branch: the 288 pre-existing instantiations are
VGPR/SGPR/spill-identical to origin/main again (the runtime branch added 1-3 VGPR to 111).
- asm_layout index_cache: the main-cache size(0) is a storage span in packed LBHNC mode, so no
capacity check is possible; state the index_slot_mapping bound as a caller contract.
- UT: skip on the live GPU (get_gfx_runtime), not GPU_ARCHS; each reject case asserts the message
of its own check instead of "mxfp4" or "index" anywhere in stderr (drops the duplicate
small-index case, it hit the same whole-page check as partial_page).
- Fix a stale comment that still named the removed op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py
(an uncommitted one-line edit found in the worktree, checked against the test file).
Co-Authored-By: Claude Code <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The new HIP packing and FP8-Q paths lack exact-head GPU correctness and latency validation, while gfx942/gfx12xx FP8 output remains outside the reported gfx950 hardware coverage.
…rite
Follow the final ROCm/aiter#7057 API: `fused_qknorm_idxrqknorm` no longer has
`q_fp8_out` / `q_scale`; an e4m3 `q_out` is written with a saturating cast at
scale 1.0 and no bf16 q row is written. The bytes are those `q_fp8_out` gave.
Signed-off-by: ganyi <[email protected]>
Co-Authored-By: Claude <[email protected]>
…, emit an fp8 main Q (#7057)
* [HIP] fused_qknorm_idxrqknorm: write the index K cache as MXFP4
New index_cache_dtype="mxfp4": the index-K slot is quantized to e2m1 with one
e8m0 scale per 32 elements and written into single-region 8704 B pages,
[128 tokens x 64 B data][128 tokens x 4 B scale]. Low nibble is the even
element; the scale rule is indexer_fp4_scale_e8m0's (ceil(log2(amax/6)), eps
clamp) and the rounding the hardware scaled_cast<fp4_t> already used by the DSA
writer.
Only the index-K write changes. It is a kIndexFp4 template bool, so every
existing instantiation compiles to the same code (identical VGPR/SGPR counts,
no spills); q/k norm, RoPE, index Q and the main KV are untouched, and the
thread mapping is still one warp per slot. The elements are rounded to the
input dtype first, so the bytes are the quantization of the row "auto" writes.
The new instantiations are launched from one generic lambda placed ahead of the
four existing launch sites, which are not touched.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: write the main KV cache as MXFP4 and emit an fp8 main Q
kv_cache_dtype="mxfp4" stores K (post norm/RoPE) and V as 128-token pages of
[128 x 64 B e2m1][128 x 4 B e8m0] per (page, kv head), the same page as the MXFP4
index cache. q_fp8_out/q_scale add a per-tensor e4m3 copy of the main Q (round to
model dtype, divide by q_scale, saturate). Index-cache modes and the fp8/auto KV
modes are unchanged.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: merge the MXFP4 launch lambdas, trim comments
One templated launch lambda replaces the two copies, storeMxfp4Row takes
(cache, slot, strides) so the index-K wrapper goes away, and the redundant
mxfp4 kv sparse check is simplified. Same registers for all 444
instantiations and same machine code for the 288 existing ones.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: one aiter-style op test
Merge the index and main-KV MXFP4 tests into one script with shared
helpers, @benchmark + torch.equal byte checks (as test_quant_mxfp4.py), a
gfx950 allow-list in main() and a summary table per sweep, so
`python3 op_tests/test_*.py` in CI runs every check; the old pytest files
were not collected there.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: make pytest collect one sweep test
Mark the argument-taking helpers __test__ = False as sibling op tests do
and expose the default sweep as test_sweep, so pytest no longer errors
on missing fixtures.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: take the fp8 main Q through q_out
Drop q_fp8_out/q_scale: q_out may now be an e4m3 tensor (fp8 or uint8,
insert mode), written unit-scale and saturating instead of the bf16 q,
as index_q_out already works. The header and pybind are back to main.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: make the e4m3 q_out test reach out-of-range values
The RMSNorm erased the x600 on the qkv row, so no q value passed 448.
Scale the q-norm weight instead and compare against the plain e4m3
cast: the op does not clamp, out-of-range values become NaN, as for an
e4m3 index_q_out. Say so in the wrapper comment.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: saturate the e4m3 q_out cast
Clamp the main-Q elements to the e4m3 max before the cast, so values
beyond it (and +-inf) become +-max instead of NaN; NaN stays NaN. Only
the q_out path changes: the shared cast, index_q_out and the existing
instantiations' outputs are untouched. The test now injects out-of-range,
inf and NaN values.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: refuse mxfp4 off gfx950, check the mxfp4 index cache
Raise in the wrapper when an mxfp4 cache is asked for on another arch
(opus converts to fp4 as zeros there). Require whole 8704 B index pages
for every layout and the same index-capacity check for the mxfp4 main-KV
layout as the page-128 one. The test gets a negative case for each, and
no longer evaluates torch.finfo(dtypes.fp8) at import.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: slim the sweep, drop duplicated code
Drop T=7 and the index-only shuffled slot case from the sweep (covered
by the other slot patterns), the **extra plumbing in make_call, and the
second q_out fp8 dtype computation in the host code. Device code is
unchanged for all 444 instantiations.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: gate the fp8 q_out by arch, match mxfp4 K/V page counts
Refuse an fp8 q_out where opus has no fp8 conversion (it would write
zeros); only gfx942, gfx950 and gfx12xx convert. Require V to have K's
page count in the mxfp4 layout, as the plain layout does, so a slot valid
for K cannot write past V. Negative tests for both.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: drop the pytest hooks, plain aiter script
Remove the test_sweep pytest entry and the __test__ = False loop; the file is
a script like the other op_tests (python3 op_tests/<file>), same cases.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: check bytes with checkAllclose, report err
The write-bytes, skip_index_branch and e4m3 q_out checks compared bytes with
bare asserts and returned a PASS row. Compare them with checkAllclose
(rtol=0, atol=0) like the sibling test_fused_qknorm_idxrqknorm.py and report
an err column; rejection rows report err 0 on the expected failure. Same cases.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm: test mxfp4 and e4m3 q_out in the existing op test, drop the separate file
The MXFP4 cases move into op_tests/test_fused_qknorm_idxrqknorm.py, on its
make_case / run_fused_qknorm_idxrqknorm / check_close helpers, its --mode / -d /
--num_tokens sweep and its markdown table, and
op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py is removed. The runner gains
optional kv_dtype / index_dtype / q_dtype / index_pages arguments; the existing
modes and rows are unchanged. The mxfp4 modes run on gfx950 only and are skipped
with a warning elsewhere.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm: cover separate contiguous mxfp4 K/V and the kv-only arch guard
Two cases of the pre-merge mxfp4 test were not carried over: mxfp4 K and V as
separate contiguous tensors (now used for one kv head, the pool views stay for
two), and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache.
Co-Authored-By: Claude Code <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: e4m3 q_out as a template flag, tighter UT (review #7057)
- kQFp8 is a bool template of the kernel, instantiated only where insert mode can use it, instead
of a runtime `q_fp8_out != nullptr` branch: the 288 pre-existing instantiations are
VGPR/SGPR/spill-identical to origin/main again (the runtime branch added 1-3 VGPR to 111).
- asm_layout index_cache: the main-cache size(0) is a storage span in packed LBHNC mode, so no
capacity check is possible; state the index_slot_mapping bound as a caller contract.
- UT: skip on the live GPU (get_gfx_runtime), not GPU_ARCHS; each reject case asserts the message
of its own check instead of "mxfp4" or "index" anywhere in stderr (drops the duplicate
small-index case, it hit the same whole-page check as partial_page).
- Fix a stale comment that still named the removed op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py
(an uncommitted one-line edit found in the worktree, checked against the test file).
Co-Authored-By: Claude Code <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: r <r@x>
akii96
pushed a commit
to akii96/vllm
that referenced
this pull request
Nov 3, 2026
…rite
Follow the final ROCm/aiter#7057 API: `fused_qknorm_idxrqknorm` no longer has
`q_fp8_out` / `q_scale`; an e4m3 `q_out` is written with a saturating cast at
scale 1.0 and no bf16 q row is written. The bytes are those `q_fp8_out` gave.
Signed-off-by: ganyi <[email protected]>
Co-Authored-By: Claude <[email protected]>
…ype fp4, --kv-cache-dtype fp4) (#2962)
* [MiniMax-M3.1] MXFP4 sparse KV pool and index-cache declaration
ATOM_M3_SPARSE_KV_MXFP4=1 with --kv_cache_dtype fp8 --index-cache-dtype mxfp4
declares the MXFP4 caches the aiter kernels read and write: one 8704 B field
(128 x 64 B e2m1 data, 128 x 4 B e8m0 scales) per (page, kv head) for K and for
V, and a single 8704 B field per block for the index key (136 + 68 B a token).
The sparse layers get a pool of their own: KvGeometry and MhaKvPool gain a
kv_format field ("" keeps every existing pool unchanged), so the MXFP4 pages sit
beside any dense layers' SHUFFLE pool.
Startup refuses plugin mode, a block size other than 128 and non-gfx950. Mono
declines MXFP4 KV, and indexer CP falls back with a warning. This commit only
declares the pool and the switches; the write and read paths follow.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 write path: one fused kernel writes K, V and the index key
rope_cache with the MXFP4 switches calls fused_qknorm_idxrqknorm with
kv_cache_dtype="mxfp4" straight onto the pool pages (no staging buffer and no
separate store kernel). The main q comes back as e4m3: one float8_e4m3fn q_out
is passed and the kernel writes the unit-scale saturating cast with no bf16 q
row (the final aiter API, ROCm/aiter#7057). A layer that reuses another layer's
top-k writes K and V only and passes skip_index_branch.
Adds dequantize_pages, the oracle the write test compares the cache against.
Needs aiter's fused_qknorm_idxrqknorm with kv_cache_dtype="mxfp4"
(ROCm/aiter#7057, merged).
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] Score the MXFP4 index cache with aiter's FlyDSL scorers; page-128 block table
index_topk's decode and prefill take index_mxfp4: the scores come from aiter's
score_flydsl_fp4 / score_prefill_flydsl_fp4 over the two views (data and scale)
of the pool page, in the layout the Triton scorers produce, so the selection
and the emit after them are unchanged. pages_per_block is a parameter of the
emit now (8 for the page-16 SHUFFLE cache, 1 for page-128 caches), which makes
the block table one page a block for the MXFP4 KV.
The decode scorer's work map is built once per step into a persistent buffer
(capacity over every step width, bound = max_model_len / 128) by
make_sparse_decode_metadata, outside the graph. The decode scorer's fp32 score
buffer is persistent too: without an out the aiter scorer runs a torch.full(-inf)
in every layer. The metadata refills the buffer's view once per step and every
layer passes it as out. Where the scorer lays scores out transposed (S*H >= 16,
not TP4) the view is None and nothing changes.
Tests: scorers against a dequantised oracle; replay of a captured decode against
a refilled work map; the persistent score buffer equals a fresh -inf buffer bit
for bit over permuted, shortened and smaller steps. Needs aiter's
score_flydsl_fp4 and score_prefill_flydsl_fp4 (ROCm/aiter#7060, #7061, merged).
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 KV attention through aiter pa_decode; ATOM_M3_INDEX_Q_FP8
sparse_pa_mxfp4 folds (token, kv head) into rows, hands the e4m3 q and the pool's
K and V pages (data and scale views of one 8704 B page) to aiter's pa_decode and
bypasses run_pa_decode's fp8 and ASM gates. attention_mha routes the sparse
prefill and decode through it, and asks the selection for a page-128 block table
(one page a block) and the MXFP4 scorer, with the step's work map and score
buffer on decode.
Decode keeps the planned path (the captured shapes are fixed): rows past the
planner's batch limit run in segments, each with a plan of its own, refreshed
once a step as the tail page is always selected. Prefill is plan-free
(work_plan=None): plan_pa_decode JIT-compiles a kernel specialised on the batch
size for every row count not seen before, and a prefill chunk has a new row
count almost every forward. One task and one direct write per row means one JIT
specialisation whatever the rows.
ATOM_M3_INDEX_Q_FP8 (off by default, refused without --index-cache-dtype mxfp4)
has the fused writer emit the indexer query as e4m3 and the scorer read it as
such.
Tests: decode and prefill against the dequantised oracle (Hkv 1 and 2); any row
count 1..700; plan-free bit for bit the planned kernel with a one-partition
plan; no new planner or PA kernel build across 12 new row counts.
Needs aiter's pa_decode with MXFP4 K/V (ROCm/aiter#7056, merged).
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 review fixes: padded replay, TBO plans, FP8-q reuse key, TP2 scores
Build the MXFP4 work map and score view from the captured batch on a padded graph
replay; key the pa_decode plan by TBO ubatch; record the FP8 index-query dtype in
the top-k reuse key; leave a transposed score to the Triton selector; check
sparse_local_block at startup; stub the arch query in the CPU cache test; document
the two env vars; drop the unused require_supported and the personal-branch hint.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] Build the selector bounds from the captured batch on a padded replay
n_valid_column_per_row is head-major, so with more than one index head its head
offsets depend on the batch the graph was captured at, like the work map and the
score view. Build it from the padded lengths when they are given (MXFP4 index only).
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 round 4: per-ubatch TBO score buffers, padded scorer batch, runtime gfx check
- Decode TBO gets its own MXFP4 index work map and score buffer per ubatch, so each
ubatch builds them once a step instead of every layer.
- The padded decode scorer batch comes from the query rows (index_batch); sparse
seq_lens, block table and context lens are sliced to it.
- The gfx950 startup check uses get_gfx_runtime(), called once.
Co-Authored-By: Claude <[email protected]>
* [MiniMax-M3.1] MXFP4: size each TBO ubatch's score buffers for its half of the batch
A split of up to max_bs requests gives each ubatch at most the larger half, so the
per-ubatch score buffer and its work map no longer need max_bs rows.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: select the KV cache with --kv-cache-dtype mxfp4, default the index query to FP8
--kv-cache-dtype mxfp4 replaces ATOM_M3_SPARSE_KV_MXFP4. Config derives kv_mxfp4 from
it and keeps kv_cache_dtype at fp8 for the non-MXFP4 layers, so the index cache still
defaults to fp8 and --index-cache-dtype mxfp4 stays independent. kv_mxfp4 keys the
compile hash and the offload page namespace, and mono refuses it.
With --index-cache-dtype mxfp4 the indexer query is always FP8 (e4m3, cast as is);
ATOM_M3_INDEX_Q_FP8 and its startup guard are removed.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: take the public cache dtype as fp4, not mxfp4
--kv-cache-dtype fp4 / --index-cache-dtype fp4 select MiniMax-M3's MXFP4 caches. Config maps
them to the internal kv_mxfp4 (+ fp8 storage) and index "mxfp4" once the architecture is
known, before the indexer-CP fallback and the index default, and only for MiniMax-M3.
Other models keep their fp4 index layout; a KV fp4 is refused except on DeepSeek-V4.1.
The parser no longer accepts mxfp4.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: drop pass-through aliases and duplicate index-dtype state
Pass k_cache/v_cache/slot_mapping/index_cache straight to fused_qknorm_idxrqknorm instead
of through same-valued fused_* aliases. Read the index MXFP4 mode from index_cache_dtype and
the spec's uint8 dtype instead of storing a second bool. Compute is_deepseek_v41 and the
text/sparse config once in Config.__post_init__. No behaviour change intended.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] config: keep the literal deepseek_v41_text check the geometry parity test scans for
test_the_hardcoded_index_plane_still_matches_what_the_config_resolves reads the index-default
branch's condition from the AST. Restore the literal there; behaviour is unchanged.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 tests: cover KV-only and index-only fp4 writes and the page-16 block table
KV-only (MXFP4 KV, fp8 index [pages,128,128]) and index-only (MXFP4 index, fp8 SHUFFLE KV
with per-token scales) writer cases beside the both-on one; the index-only run is pinned
byte-for-byte to the same write with a bf16 index. One MXFP4-index decode selection case with
8 pages a block. Test-only; GPU (gfx950) tests, not run on CPU.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: resolve the index cache dtype through aiter's fp4x2
_resolve_index_cache_dtype maps the internal "mxfp4" to d_dtypes["fp4x2"] like
bf16/fp8. fp4x2 is only the logical label: the entry stays one 8704 B uint8
page of E2M1 data and E8M0 scales (EntryField and field_view are unchanged).
Where torch has no float4 (or fp8 is uint8) the registry's fp8 and fp4x2 are
both uint8, so _IndexCacheSpec carries an explicit mxfp4 flag from the config
string and the two branches read that instead of comparing dtypes.
The new test needs aiter like the other aiter_attention builder tests, so the
no-aiter CPU CI job skips it; run with aiter present (96 passed there).
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: hold the index cache as "fp4x2" from init, resolve it through aiter's registry
For MiniMax-M3 the public --index_cache_dtype fp4 becomes "fp4x2" at Config
init (other models keep "fp4"), and _resolve_index_cache_dtype takes it through
the same d_dtypes lookup as bf16/fp8. This replaces the special mxfp4 branch,
the name helper and the spec flag of 1aacf2cd9.
fp4x2 is only the name: the entry stays one 8704 B uint8 page of E2M1 data and
E8M0 scales, and the two branches that lay it out key on the config string, not
the dtype (fp8 and fp4x2 are both uint8 where torch lacks float4). The AITER
fused writer still takes "mxfp4", so attention_mha translates it at that call.
The Mooncake namespace keeps "fp4x2" as is, so it does not change with the
torch build. Config checks, docs and tests follow the new string.
The aiter-gated test (test_aiter_index_cache_dtype.py) is skipped by the
no-aiter CPU CI job; writer tests need gfx950. Not run on GPU at this head.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: keep the index cache "fp4" inside ATOM, name it fp4x2 only for aiter
Undo the "fp4x2" config string of 9f424857d: MiniMax-M3's index cache stays
"fp4" in the config, and ATOM translates it only where aiter needs another
name -- d_dtypes["fp4x2"] in _resolve_index_cache_dtype, "mxfp4" on the fused
writer call.
_resolve_fp4_caches no longer takes or returns the index dtype (it only mapped
the KV now). Because "fp4" is also the DeepSeek-V4 / GLM index layout,
_check_m3_mxfp4 gates the index check on the model being MiniMax-M3, so those
models' fp4 index is not refused. The two page branches still key on the config
string, not the dtype, since fp8 and fp4x2 are both uint8 where torch lacks
float4; the entry stays one 8704 B uint8 page. The Mooncake namespace special
case goes: aiter's registry has no "fp4" key, so it stands as it is.
Tests follow the string; new cases cover the MiniMax-M3 index-only refusal and
a DeepSeek-V4 fp4 index that is not refused. The aiter-gated test
(test_aiter_index_cache_dtype.py) is skipped by the no-aiter CPU CI job. Not
run on GPU at this head.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: name the sparse KV pool format "fp4", not "mxfp4"
KvGeometry.kv_format / MhaKvPool.kv_format is ATOM-internal (aiter has no such
name) and is per row space: only MiniMax-M3's indexed sparse layers carry it,
dense layers keep "". It now reads "fp4" like the index cache, so the geometry
is named h8d128fp4 and its transfer-region role mha.h8d128fp4.<role>; peers on
different builds would see different role names for MXFP4 KV (the roles are
only logged and compared against the MLA constants).
The aiter writer literal kv_cache_dtype="mxfp4", kv_mxfp4 and config
kv_cache_dtype are unchanged. Pins the new geometry name in test_kv_pool_contract.
Not run on GPU at this head.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: review follow-ups -- docs, error wording, M3 gate, drop duplicate dequant
Small, verified items from the 12-point review:
- docs: the 64-block FP4 text is scoped to DeepSeek-V4, M3's MXFP4 caches are
128 (refused at startup otherwise, no FP8 fallback), add the kv_mxfp4 row;
index_topk comments say 8 / 1 pages per block (16 only for the plugin's
fused-K/V cache).
- config: the fp4 KV error names DeepSeek-V4.1 too; the MiniMax-M3 test is
_is_minimax_m3_config (architecture or model_type, also on text_config), once,
for the KV mapping and the MXFP4 gate, so it agrees with the attention builder
and the offload layout.
- index_mxfp4 docstring: the pinned aiter's MXFP4 prefill scorer keeps pages
MXFP4 through LDS (scaled MFMA); it does not stage them as fp8.
- kv_mxfp4: drop _E2M1 / dequantize_pages (tests only); tests call
dequantize_mxfp4(*page_views(pages)), bit-exact on every data byte and e8m0
0..254 (they differ only at 0xFF: inf there, NaN in mono, the e8m0 NaN).
Not addressed here: items 1, 2, 3, 6, 7, 8, 11 and the structural parts of 4, 5,
9. The index/attention/write tests are GPU-gated and skipped on CPU; not run on
GPU at this head.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] DSpark calibration identity: tell MXFP4 KV from fp8 KV
--kv-cache-dtype fp4 on MiniMax-M3 is held as kv_cache_dtype="fp8" plus
kv_mxfp4=True, so calibration_identity() gave an fp8 deployment and a KV-MXFP4
one the same identity (and index-only vs both-MXFP4), and a speed table
calibrated for one format validated for the other.
The identity now carries kv_mxfp4 when it is set. It is left out otherwise, so
every identity and profile that does not use MXFP4 KV is unchanged and keeps
matching. Test covers the collisions, the unchanged plain identity and a config
without the attribute.
Not run on GPU.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4: M3's startup checks move to models/minimax_m3/config.py; stale cache text
The MiniMax-M3-specific refusals of _check_m3_mxfp4 (vLLM/SGLang bridges, block
size 128, sparse_local_block, gfx950) become validate_runtime_config in
models/minimax_m3/config.py, called from Config.__post_init__ at the same point
as before and the way DeepSeek-V4.1's are. The generic refusal of kv_mxfp4 on
another model stays in Config with the same message. Same checks, order and
errors; tests call the hook, plus a Config-level test for the generic refusal.
attention_mha: the rope_cache docstring and comments, the _cache_format comment
and the dispatch_backend docstring no longer say the cache is always SHUFFLE
with scale planes (the MXFP4 pages are not).
Not run on GPU.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 KV needs a bf16 model: refuse an fp16 one at startup
aiter's MXFP4 pa_decode raises "needs a bf16 output" (flydsl/pa_decode.py), and
the sparse attention output takes the model dtype (rope_cache stores qkv.dtype),
so --kv-cache-dtype fp4 on a MiniMax-M3 checkpoint with an fp16 torch_dtype died
in its first forward. validate_runtime_config now refuses it at startup. The
MXFP4 index alone does not reach that kernel and is not restricted. The fp16 case
is refused, not made to run: a bf16 output plus cast would change the kernel call
and was not validated.
Tests: hook-level (fp16 refused, bf16 accepted, index-only fp16 accepted) and
Config-level on an hf dtype of float16.
Not run on GPU.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] MXFP4 index score buffer: size rows for the step widths that read it; CP-gate test
The persistent index score buffer had max_bs * max_qlen rows, but
fresh_index_score hands it out only when S * H < TRANSPOSE_MIN_F; wider
steps (TP1 S>=4, TP2 S>=8) take the scorer's own allocation and never read it.
index_score_rows sizes it for the widths that do. Sizing only: the transposed
path still allocates and fills per layer. Not run on a GPU, graph replay or TP2.
Also pins that --kv-cache-dtype fp4 alone (index stays fp8) still falls back
from the CP scorer, and drops stale size figures from a builder comment.
Co-Authored-By: Claude Code <[email protected]>
* [MiniMax-M3.1] Address review: single fp4 dtype source, shared plan cache, score-buffer step
- Drop Config.kv_mxfp4; kv_cache_dtype stays "fp4" and Config.kv_storage_dtype
gives the dtype of non-MXFP4 pages. Config.draft_config() builds draft
configs with the storage dtype.
- Rename kv_mxfp4.py to mxfp4_pages.py and add Mxfp4KvLayout / ShuffleLayout so
MhaKvPool carries no model name.
- Index score: persistent buffer matches aiter's transposed layout, fill is
bounded to the batch block count, eager steps use the batch width; carried in
one IndexScoreStep on the sparse metadata.
- MXFP4 decode uses the shared flydsl plan cache (plan_segment key) and the
sparse_local_block>=1 startup refusal is removed.
- Index cache spec, direct aiter.ops.flydsl imports, tests restructured.
Not done: unifying the skip-index writer (Triton path kept). Not run on this
head: TP2, real-runner TBO/graph, e2e accuracy.
Co-Authored-By: Claude Code <[email protected]>
* Fix RUF028: keep the fmt: skip on a statement in the eager-width index test
The `# fmt: skip` sat inside an `outs.append(...)` argument list, which ruff
rejects as an invalid suppression comment (Pre Checkin ruff job).
Co-Authored-By: Claude Code <[email protected]>
* Simplify MiniMax-M3 FP4 KV dtype routing
Derive dense KV page dtype from kv_cache_dtype and remove redundant sparse and pool state.
Co-Authored-By: Claude Code <[email protected]>
* WIP: route MiniMax-M3 paged KV through MXFP4
Wire dense and draft page paths, preserve independent index dtype, and isolate the new page namespace. Keep EAGLE3 and DSpark disabled pending GPU and AITER validation.
Co-Authored-By: Claude Code <[email protected]>
* Skip DSpark MXFP4 tests when aiter is unavailable
Keep the no-AITER CPU test job collecting successfully.
Co-Authored-By: Claude Code <[email protected]>
* Revert unvalidated all-layer MiniMax-M3 MXFP4 expansion
Revert commits 6c790ca96 and 6ffa5541b7; preserve the earlier #2962 sparse MXFP4 implementation.
Co-Authored-By: Claude Code <[email protected]>
* Reject MiniMax-M3 --kv-cache-dtype fp4; keep the MXFP4 index cache only
--kv-cache-dtype fp4 on MiniMax-M3 made the indexed sparse layers' KV MXFP4
while dense/sliding/draft layers silently used FP8. Refuse it at startup
(only DeepSeek-V4.1 takes an FP4 KV) and remove the code the guard makes
unreachable: the sparse MXFP4 KV reader/writer, Mxfp4KvLayout and the pool
layout abstraction, dense_kv_dtype and the draft FP8 override, and their
KV-only tests. --index-cache-dtype fp4 (index page ABI, writer, scorer) is
unchanged. The MXFP4 decode index batch sizing now applies only to that cache.
Co-Authored-By: Claude <[email protected]>
* Skip the MXFP4 index tests on an aiter without the FP4 index ops
An older aiter lacks minimax_m3_index_score_fp4_flydsl: the index test failed
with ImportError and the write test aborted the process in the fused writer.
Both skipif conditions now probe that op, so they skip there and still run on
an aiter that ships the MXFP4 index.
Co-Authored-By: Claude Code <[email protected]>
* Drop the thin FlyDSL wrappers around the MXFP4 index scorers
index_work_map_capacity, build_index_work_map, index_score_buffer,
decode_score_mxfp4 and prefill_score_mxfp4 only forwarded to aiter. The
callers now call aiter directly. The page_views check, the lazy aiter imports
and the empty-batch behaviour stay: alloc sizes a zero batch as zero rows
without asking aiter, and begin_step returns None before building a map.
Co-Authored-By: Claude Code <[email protected]>
* Add MiniMax-M3.1 MXFP4 KV cache with separate DSpark draft dtype
Co-Authored-By: Claude Code <[email protected]>
* Restore the MiniMax-M3.1 MXFP4 KV tree; port only the M3 gate and draft dtype back
Return the working tree to the earlier real-FP4 implementation (8704-byte
pages, fused writer, sparse_pa_mxfp4 reader, FP4 index scorer) and keep from
the current head only what it still needs: the all-indexed-sparse M3.1 gate
(dense attention, fp16, KV offload / --kv-transfer-config and FP4 drafts are
refused), the DSpark draft's own KV dtype (--spec-decode-kv-cache-dtype,
fp8 by default, bf16 allowed, fp4 refused), compile and calibration identity,
and the non-M3 DSpark / EAGLE3 behaviour. The thin FlyDSL wrappers around the
index scorers are gone, and the tests are trimmed of duplicated matrices.
Co-Authored-By: Claude Code <[email protected]>
* Review 5797687431: one decode row rule for every index cache, draft KV default, offload parser
- decode_rows_batch: the requests whose rows the sparse decode runs (scorer,
selector, attention), for every index cache; replaces the MXFP4-only
index_batch that raised on DP prefill padding. _sparse_decode slices q/idx_q
to those rows and zeroes the output past them (fp8 index + fp4 KV no longer
reads unwritten page ids).
- resolve_draft_kv_dtype defaults an own-pool draft to the target's dtype (fp8
only under an fp4 target); calibration identity adds the draft dtype only
when it differs from the target's.
- The offload refusal checks the model's own fp4/offload refusal first and no
longer suggests a flag that then fails.
- The draft's pool/dtype is decided once in Config (spec.kv_cache_dtype) and
read everywhere; DraftKvBuilder binds scales by pool.scale_fields.
- kv_offload_requested -> kv_pages_leave_pool, reading config.kv_transfer_config
only.
- Docs: --method lists mtp/eagle3/dspark; compute_hash comment lists the MXFP4
fallback.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* Review 5781200929 B14/B15: read index_cache_dtype directly, fix the mxfp4 sparse docstring
- aiter_attention: config.index_cache_dtype, as the same builder reads it at the
other site (B14).
- sparse_attn_mxfp4: the module docstring named a nonexistent plan_owner=None and
had a broken sentence (B15).
The other B-series items need aiter-side or GPU work and are tracked for a
follow-up PR.
Co-Authored-By: Claude <[email protected]>
* Resolve duplicate kv_cache_dtype entries left by merging origin/main
Both main and this PR added kv_cache_dtype="fp8" to the same stand-in configs
at different positions, so the merge produced a repeated keyword (a
SyntaxError at collection) in test_compile_hash_spec and test_indexer_cp_gate,
and a repeated dict key in test_config_compile_hash. Keep one of each.
Co-Authored-By: Claude <[email protected]>
* Review 5797687431 items 1/2: refuse fp4 KV beside a non-fp4 index; scope the row rule to the MXFP4 index
- Item 2: --kv-cache-dtype fp4 now defaults the M3 index to fp4, and
validate_runtime_config refuses an explicit other index (sparse_pa_mxfp4
walks every row of q; only the MXFP4 scorer is sized to those rows).
- Item 1: decode_rows_batch and the q / idx_q slicing in _sparse_decode apply only
under the MXFP4 index; every other index cache is back to running_bs and the
unsliced q, as before the review. Tests and docs follow.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* MiniMax-M3: an unspecified dtype stays bf16, fp4 only when asked for
- --kv-cache-dtype fp4 no longer defaults the index cache to fp4: the index is
left at bf16 and validate_runtime_config refuses it ("--kv-cache-dtype fp4
needs --index-cache-dtype fp4, got bf16").
- An unspecified draft under an fp4 target is bf16, not fp8; an explicit
--spec-decode-kv-cache-dtype fp8 is still honoured.
- Help text, docs and tests follow.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* Copilot review: calibration without a draft, fill_blocks=0, KvLayout.tag, head-count check, draft default help
- calibration_identity: no AttributeError when speculative_config is None.
- fresh_index_score: fill_blocks=0 fills nothing; only None means every column.
- KvLayout declares tag (ShuffleLayout's is ""), which KvGeometry.__str__ reads.
- sparse_pa_mxfp4: a clear ValueError when num_kv_heads does not match the pages.
- --spec-decode-kv-cache-dtype help: the default is the target's dtype (bf16
under an fp4 target), not fp8.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* MXFP4 index scorer: allocate the scores per call, keep only the work map persistent
Drop the persistent score storage of IndexScoreBuffers (alloc, the strided view,
the per-step -inf fill, the per-ubatch offset views). The scorer, given no out,
allocates the scores filled with its -inf sentinel (aiter alloc_score), as the
Triton scorers allocate theirs per call. The work map, whose pointer a captured
graph bakes and which is built outside the graph each step, stays persistent, per
TBO ubatch as before. Tests follow.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* MXFP4 index scorer: the work map is a builder attribute, not a forward_vars entry
Nothing reads forward_vars['sparse_attention_index_score'] (or its ub<i>_ copies)
but the builder that put it there, and it now holds only the scorer's work map.
Keep it as builder-owned self._index_work_maps (by ubatch prefix) and rename
IndexScoreBuffers/IndexScoreStep/index_score(_buffers/_eager) to
IndexWorkMap/IndexWorkMapStep/index_work_map(_eager). Tests follow.
Not run on a GPU.
Co-Authored-By: Claude <[email protected]>
* Drop IndexWorkMap/IndexWorkMapStep and the eager block-count shrink
The two classes only wrapped aiter's work-map builder: the builder now keeps
a {prefix: int32 buffer} dict (one per TBO ubatch) and make_sparse_decode_metadata
calls aiter's minimax_m3_index_score_work_map straight into it. The metadata
carries just the map tensor; the layer takes the model-length block bound from
its own max_model_len.
Eager steps used to build the map at the batch's own block count, which is what
threaded use_cudagraph through the shared build() contract
(backends.py, model_runner.py, _step_use_cudagraph). Eager steps now use the
model-length bound like graph steps, so all of that goes, together with the
test that covered the shrink.
Co-Authored-By: Claude <[email protected]>
* Inline decode_rows_batch at its only call site
The standalone function and its tests existed only to compute
min(running_bs, running_tokens // q) for the MXFP4 index decode. Inline that
one line in the metadata builder and keep the guard that mattered: refuse a
step whose rows cannot cover the scheduled requests. The non-divisible-rows
error is dropped (floor division is enough). _sparse_decode's row slicing and
zeroing of the rest is unchanged. Docstrings that named the function now
describe the behaviour directly.
Co-Authored-By: Claude <[email protected]>
* Decide "does the draft own a KV pool" once, off the selector in plugin mode
Config.__post_init__ asked `_config_has_own_pool_draft` for every speculative
config, and for a DSpark draft that went through attn_family/get_attn_backend.
A V4.1 DSpark draft is CSA2, which the selector refuses under vLLM/SGLang, so a
supported plugin deployment (V4.1 + DSpark) crashed at Config construction.
The decision is now the public `spec_decode.draft_kv.draft_owns_kv_pool(config)`;
`Config` and the offload deployment check both call it, and the private offload
helper is gone. Under a plugin it answers False without asking the selector (the
draft pool builder only exists in the native runner). Native answers are unchanged.
Test: a plugin-mode Config with a V4.1 DSpark draft built without touching the
selector (it raised NotImplementedError before the fix), plus the native cases of
`draft_owns_kv_pool`.
Not touched: SpeculativeConfig.kv_cache_dtype semantics, the index dtype default.
Co-Authored-By: Claude <[email protected]>
* Key the MXFP4 row rule on the index cache, not on a kwargs dict's truth
valarLip's item 2: `index_bs` was MXFP4-only but selected by the truthiness of
`_index_work_map_kwargs()`, and the "do not cover the scheduled requests"
ValueError sat outside that branch, where for bf16/fp8 (`index_bs == running_bs`
>= scheduled) it cannot fire.
The rule now reads `self._index_work_map_blocks` (non-zero exactly when the index
cache is MXFP4; set beside the work map) and the ValueError moves inside that
branch. Behaviour is unchanged for every index dtype. Not done, on purpose:
making the row rule uniform for bf16/fp8 (reviewer's 11-05 B6 objected to changing
their row count in this PR).
Test: the row rule for MXFP4 (ragged DP step, uncovered requests) and the padded
batch kept for the other index caches, driven through `finish_decode`.
Co-Authored-By: Claude <[email protected]>
* Carry the work map's block bound on the sparse metadata instead of recomputing it
valarLip's item 4: the decode work map was built at cdiv(config.max_model_len, 128)
in the builder (`make_sparse_decode_metadata` already receives that bound), and the
impl recomputed -(-impl.max_model_len // 128) for the scorer, which checks the two
for exact equality. They agreed only because both read the same config value.
`MiniMaxM3SparseMetadata.index_work_map_max_block` now sits beside `index_work_map`
(0 when no map was built) and `_mxfp4_select_kwargs` passes it through. No fallback
path remains: the impl only passes a map, and thereby a bound, when the metadata
holds one. `impl.max_model_len` (set by the builder's bind and initialised on main)
is left as it is; this change just stops reading it.
Test: the scorer kwargs take the bound off the metadata even when the impl's own
max_model_len says otherwise.
Co-Authored-By: Claude <[email protected]>
* Give sparse_pa_mxfp4 an out= and zero the DP pad tail once, like SHUFFLE
valarLip's item 5 (and the Copilot note on the same lines): on the MXFP4 KV decode
branch `sparse_pa_mxfp4` allocated its own output and `nn.functional.pad` then
allocated and copied the whole thing again on every DP-padded step and layer,
while the SHUFFLE branch wrote into `output[:rows]` of an empty_like and zeroed
`output[rows:]`.
`sparse_pa_mxfp4(..., out=)` takes the caller's contiguous [rows, H, 128] tensor of
`out_dtype` (checked: the query is e4m3, so it is never `empty_like(q)`), on the
planned and the plan-free path alike, and returns it; `out_dtype` keeps its meaning
(output dtype and plan-scratch dtype). `_sparse_decode` now allocates one output
(value dtype for the MXFP4 KV, q's otherwise), zeroes the tail once and hands
`output[:rows]` to whichever kernel runs. The prefill call is unchanged.
Tests: CPU doubles for pa_decode prove the segment views land in the caller's
buffer, pad rows untouched, wrong dtype refused. GPU (gfx950, aiter main 5469555096):
`out=` equals the allocated result bit for bit, planned and plan-free, rows past it
untouched; test_minimax_m3_mxfp4_attention.py passes there.
Co-Authored-By: Claude <[email protected]>
* Drop the redundant fp4 factor from compute_hash and read spec.kv_cache_dtype directly
valarLip's item 7: `factors.append(self.kv_cache_dtype == "fp4")` is implied by
`factors.append(self.kv_cache_dtype)` further down the same function, yet it changed
every model's compile-cache key. Deleted. `getattr(spec, "kv_cache_dtype", None)`
read a field this PR declares on SpeculativeConfig; it is now `spec.kv_cache_dtype`
(the SimpleNamespace spec in test_compile_hash_spec gets the field a real one has).
Unavoidable, not addressed: the speculative tuple's third element still changes the
hash of every speculative-decoding model against main.
Co-Authored-By: Claude <[email protected]>
* Say which dtype and which cause the DSpark q_out dtype warning is about
valarLip's item 8: the warning named `--kv_cache_dtype`, but the value it prints is
`speculative_config.kv_cache_dtype`, the draft's resolved dtype (the target's
--kv-cache-dtype, or --spec-decode-kv-cache-dtype for a draft with a pool of its
own, settled once by Config), and said the draft binds into the pool allocated
"from that same flag". Text only: it now names the field and where it comes from,
and that the pool is allocated at that resolved dtype. No behaviour change.
Co-Authored-By: Claude <[email protected]>
* Delete the empty index_mxfp4.py and bring the stale docs and leftovers in line
valarLip's item 10. `index_mxfp4.py` was 19 lines of docstring with no code and no
importer, while index_topk.py, aiter_attention.py and sparse_attn.py still sent
readers there for the scorer; and its "same [heads, rows, max_block] scores" is wrong
for the transposed layout (S*H >= 16).
- Deleted it; the useful sentences (e4m3 query, the page_views, the per-step work map
and the exact max_block it must be given, scores allocated per call and filled with
-inf, the transposed layout) are now in `minimax_m3_index_topk_decode`'s docstring,
and the three pointers name aiter's scorer instead.
- `index_topk.py` module docstring no longer says Triton-only / bf16 layout; the
`sparse_bt` docs say `topk * pages_per_block` (8 for SHUFFLE, 1 for MXFP4 KV).
- Removed the fp4 comment block in `SparseMHAPagedAttentionImpl.__init__` (documents
no field). `_cache_format = "SHUFFLE"` is now set only on the SHUFFLE branch: its
one reader (`attention_mha.py` cp gather) already defaults to SHUFFLE, and the MXFP4
pages are read only by `sparse_pa_mxfp4`, so nothing changes.
- The `kv_pools` comment/annotation said keyed by (num_kv_heads, head_dim); it is keyed
by KvGeometry.
Comment/doc changes only apart from the `_cache_format` move.
Co-Authored-By: Claude <[email protected]>
* Pass the MXFP4 decode scorer a persistent, unfilled, contiguous out=
valarLip's item 1 (and the Copilot note on the same call): the scorer was called
without `out=`, so aiter's `alloc_score` allocated and -inf-filled a model-width
[H, rows, max_block] fp32 buffer on every sparse layer of every step (the fill is
recorded into the graph), and for S*H >= 16 laid it out transposed, which made
`_select_with_aiter` decline on `not score.is_contiguous()` and every such step take
the Triton selector.
Now the builder allocates the score storage once, beside each work map ("" and the
two TBO ubatches, so two ubatches never share one), at the map's width; the sparse
metadata carries it (`index_score_out`) and `minimax_m3_index_topk_decode` hands the
scorer a contiguous [H, rows, max_block] view of its head as `out=`. Never filled:
read from the code, the Triton selector masks `idx < valid_blocks` (other=-1e30) and
aiter's `topk_per_row_small_k` replaces any column past the row's length with a
select, and the scorer writes every column below a row's valid blocks each step. The
-inf sentinel in aiter's `alloc_score` docstring is owed only to a consumer that
reads past them. The layout is page-contiguous by construction, so the aiter
selector stays eligible at any S*H.
Not done: "the step's width on eager steps". The scorer requires the work map and
`max_block` to match exactly and the map is built at the model length since 7bbdd0766
removed the eager shrink (reviewer B10), so eager steps stay at model width here;
narrowing them needs that shrink back.
Tests: GPU (gfx950, aiter main 5469555096): selections, block tables and contexts
bit for bit equal between the allocated and the junk-filled persistent buffer
(NaN/+-inf), ragged lengths, pad rows, a second shorter step reusing the buffer,
S*H 1..16 and 70 / 2100 blocks (2100 is where the aiter selector takes the
persistent one; the default path is Triton at S*H=16). CPU: the wiring and the
too-small-buffer refusal, per-ubatch buffers.
Co-Authored-By: Claude <[email protected]>
* Score the MXFP4 decode index into the indexers' LogitsWorkspace
Follow-up to the previous commit (persistent, unfilled scorer `out=`): the hand-made
flat fp32 buffer, `_alloc_index_scores`, and the manual slice-and-capacity-check in
`minimax_m3_index_topk_decode` are replaced by `sparse_indexer_chunk.LogitsWorkspace`,
the persistent logits plane the other indexer models (aiter_mla, deepseek_v4) already
allocate, so every indexer's persistent score buffer is one mechanism.
- The builder makes one `LogitsWorkspace(H * max_rows * index_work_map_blocks)` per
work map ("" and the two TBO ubatches, which therefore still never share one), by
the explicit-capacity constructor: `for_rows` bands the plane to a budget, which a
scorer that writes the whole grid cannot use.
- `MiniMaxM3SparseMetadata.index_score_out` (a tensor) becomes
`index_score_workspace` (the workspace); `minimax_m3_index_topk_decode` takes the
scorer's `out=` from `workspace.logits(H * total_q, width).view(H, total_q, width)`.
`logits` is a contiguous [rows, width] view, so the 3-D view is free, and it raises
when the step outgrows the workspace (no silent truncation). Without a workspace
the scorer still allocates its own scores, as before.
- Allocation time: unchanged and already right. The builder is constructed in
`ModelRunner.__init__` before `warmup_model`, and KV sizing reads the allocator's
current/peak after it, so the workspace is counted in the KV budget.
Not changed: the scorer's layout/fill behaviour (selections stay bit for bit equal to
the allocated scores), eager-step width, and nothing of the KvLayout, index-dtype
default or SpeculativeConfig.kv_cache_dtype items.
Tests: capacity and bytes of the main and the per-ubatch workspaces, ubatches do not
share storage, a workspace too small for the step raises, wiring through the
metadata; GPU: persistent-vs-allocated equality as before, plus a CUDA graph captured
into the workspace and replayed with a padded step (pointer unchanged, selection
equal to the allocated scores').
Co-Authored-By: Claude <[email protected]>
* Decide "the draft owns a KV pool" from the attention family, not by resolving a backend
valarLip's round-3 item 3: `draft_owns_kv_pool` answered through `get_attn_backend`,
and every backend module imports aiter, so building `Config` in the API process
(`LLMEngine`) loaded aiter (and initialised CUDA) for every native DSpark launch,
which `config.py` keeps out of `import atom.config` on purpose.
`selector.DRAFT_POOL_FAMILIES` (today MHA: an MHA draft keeps its own K and V; an
MLA / CSA draft's latent is the target's) is now the one answer. `draft_owns_kv_pool`
and `draft_kv_builder` both read it; the `DRAFT_OWNS_KV_POOL` class flag on
`AttentionBackend` / `AiterBackend` is gone, so the two cannot disagree. The plugin
answer (False, no lookup) is unchanged.
Test: `test_kv_pool_contract.py` pins the table to the backends: every listed family's
backend defines `make_kv_pool`, and every backend that defines it is listed. The
plugin V4.1 + DSpark regression test is kept (it now also asserts no backend is
resolved natively); the draft-builder and offload tests drive the family instead of
a stubbed backend.
Not changed: which methods ask (still DSpark only; the EAGLE3 question is the next
commit), SpeculativeConfig.kv_cache_dtype semantics.
Co-Authored-By: Claude <[email protected]>
* Settle DeepSeek-V4's fp8 -> bf16 KV fallback in Config, before the draft's dtype resolves
valarLip's round-3 item 1: V4's builder lowered the target's KV dtype to bf16 on a GPU
other than gfx950 / gfx1250 (aiter's fp8 2buff path runs only there) and rewrote
`config.kv_cache_dtype` after `Config.__post_init__` had already resolved
`spec.kv_cache_dtype`. A V4 DSpark draft shares the target's pool, so on gfx942 its
resolved dtype stayed fp8 against a bf16 pool: `_resolve_dtype_q` warned on every run,
`calibration_identity` gained `draft_kv_cache_dtype=fp8` (existing profiles stopped
matching), and the draft config was handed fp8.
The fallback is now a `Config` decision, made where the V4 block size is, with the
builder's own probe (`aiter.jit.utils.chip_info.get_gfx`: rocminfo, no CUDA init, and
already imported there for V4's indexer default). Native only (`plugin_config is
None`), as before: the builder never ran under a plugin. The builder's rewrite is
removed; it reads the settled dtype.
Tests: gfx950 / gfx1250 keep fp8 and gfx942 gets bf16, for the target and for a V4
DSpark draft resolved after it; a plugin config is left alone and never probed. The
existing indexer-default tests count arch probes, so their helper now asks for a bf16
KV (the probe those tests count is the indexer default's, not this one).
Co-Authored-By: Claude <[email protected]>
* Answer "the draft owns a KV pool" for EAGLE3 as well as DSpark
valarLip's round-3 item 2: `draft_owns_kv_pool` said True only for DSpark, but its
docstring says it is what `draft_kv_builder` answers, and `eagle_proposer.py` calls
`draft_kv_builder` for `--method eagle3` too: an MHA EAGLE3 draft gets a pool of its
own. So M3 with an fp8 target, EAGLE3 and `--spec-decode-kv-cache-dtype bf16` was
refused with "this draft caches in the target's KV pool", and M3.1 fp4 + EAGLE3 with
"the draft would have FP4 KV" although that draft has its own SHUFFLE pool.
The methods that build a draft pool are named once (`DRAFT_POOL_METHODS`: eagle3,
dspark; MTP runs the target's layers), and the family table decides. The M3 comment
that repeated the wrong premise, and the three doc sentences that put EAGLE3 in the
target's pool, are corrected.
Tests: an MHA EAGLE3 draft takes bf16 / fp8 / the target's dtype and runs bf16 under
fp4 KV; an EAGLE3 draft with an MLA family and MTP still share the target's pool.
Not run on a GPU: whether an MHA EAGLE3 draft actually runs beside M3.1 fp4 KV (this
only stops Config refusing it).
Co-Authored-By: Claude <[email protected]>
* Carry the MXFP4 index scorer's map, bound and workspace as one record; share the workspace
valarLip's round-3 items 8, 5 and 6, which all touch the same state.
Item 8: the work map, the block bound it is built at and its scores were three parallel
dicts/fields (`_index_work_maps`, `_index_score_workspaces`, `_index_work_map_blocks`),
split into three kwargs by the builder, three metadata fields, three kwargs again in
the impl, any missing one silently falling back to per-layer allocation. They are now
one frozen `IndexScoreBuffers(scores, work_map, max_block)` per prefix (the bound stays
beside the map): the builder's capacity record, and, on the step's metadata
(`index_scorer`), the same record with the map built for the step.
Item 5: the TBO ubatches no longer get score workspaces of their own. Read from
`atom/utils/tbo/`: both ubatches run on the one compute stream (`make_tbo_contexts`
gives every context the same `compute_stream`), CPU hand-off between them happens only
at explicit yield points, and a layer's scorer writes the workspace and its selector
reads it inside one `index_topk` call that contains none (the only `tbo_yield` in the
attention is after the prefill output). So the ubatches use the step's workspace; only
their work maps stay per ubatch (both ubatches' metadata are alive at once).
Item 6: `prepare_mtp_decode` now passes the same record, so the decode scorer has one
path: `minimax_m3_index_topk_decode` requires the record (a missing one, or a context
wider than its bound, raises) and the "no workspace -> aiter allocates, transposed at
S*H >= 16" branch is gone, with `_select_with_aiter`'s `not score.is_contiguous()`
exit (every scorer writes a contiguous table now) and the stale comment in the builder.
Not done here: the prefill scorer (next commit), eager-step width.
Tests: ubatch records share the workspace and have distinct maps; metadata builds the
map into the record's buffer at its bound; scorer view/too-small/missing-record
refusals; GPU tests compare the workspace path against aiter's own allocated scores
via a wrapper that drops `out=` (bit for bit; CUDA graph with a stable pointer).
Co-Authored-By: Claude <[email protected]>
* Give the MXFP4 prefill scorer the shared, unfilled score workspace too
valarLip's round-3 item 4 (the user reversed an earlier "do not change"): the prefill
call `minimax_m3_index_score_prefill_fp4_flydsl(...)` passed no `out`, so aiter's
prefill `alloc_score` did `torch.full(-inf)` of `[H, chunk rows, cdiv(max_seq_len,
128)]` fp32 on every sparse layer of every chunk (the Triton path it replaces used
`torch.empty`). The pinned aiter (5469555096) supports `out=` there (shape
[H, total_q, max_block], page-contiguous).
The prefill scorer now writes into a contiguous view of the same `LogitsWorkspace` the
decode scorer uses, never filled: `minimax_m3_index_topk` takes the step's
`IndexScoreBuffers` (required for the MXFP4 index), the prefill metadata carries the
record without a map, and `_mxfp4_select_kwargs` passes it for both phases. Not filled
for the same reason as decode: the selector reads a row only up to its valid blocks
(`n_valid_column_per_row`), and the prefill scorer writes every page inside a row's
causal window, which is exactly that range.
One workspace, shared: a step is prefill or decode (`dispatch_backend` picks one on
`is_prefill`), and within either the scorer and selector of a layer run back to back
on one stream. The builder sizes it for the larger of a decode step (`max_bs *
max_qlen`) and a prefill chunk (`max_num_batched_tokens`) rows, at the work map's
width, in the constructor, so the memory profile counts it. Memory, fp32:
4 * H * rows * ceil(max_model_len / 128). MiniMax-M3.1 (index heads 4, so H = 1 at
TP4), 16384 rows: 64 MiB at --max-model-len 128K, 512 MiB at 1M (the model's 1M
default); at TP1 (H = 4) four times that. Decode-only would be 8 / 64 MiB at q = 4,
512 seqs.
Tests: GPU (run only when a card is available, see the report): the prefill scorer
into a junk-filled workspace, reused by a second chunk, selects bit for bit what aiter's
own allocated, -inf-filled scores give (ragged chunks, prefixes, lengths off a block
boundary, H 1 to 4, 70 and 2100 blocks). CPU: the prefill scorer view and the missing-
record refusal, the prefill metadata keeping the workspace only, the builder's sizing.
Co-Authored-By: Claude <[email protected]>
* Offer only the draft KV dtypes a draft can have: --spec-decode-kv-cache-dtype bf16|fp8
valarLip's round-3 item 10: `--spec-decode-kv-cache-dtype fp4` could never take effect.
A draft with a pool of its own refuses it, and a draft in the target's pool takes it
only when it equals the target's dtype, i.e. the same as omitting the flag. The
choice existed to produce one error and was documented in three places.
`choices=["bf16", "fp8"]`; the fp4 error in `resolve_draft_kv_dtype`, its test, and the
doc / help lines that described it are gone (`resolve_draft_kv_dtype`'s docstring is now
its contract; the wider help / docs trimming is round-3 item 14). The `else` branch's
"needs --method" fired for `--method X --num-speculative-tokens 0` too, where the method
was given; it now names both conditions, and a test pins both ways speculation is off.
Not touched: `SpeculativeConfig.kv_cache_dtype` semantics (one field, requested then
resolved), as agreed.
Co-Authored-By: Claude <[email protected]>
* One source for M3's 128-token block, and one geometry check of an MXFP4 page
valarLip's round-3 item 11: `PAGE_TOKENS = 128` redefined `SPARSE_BLOCK_SIZE` (which was
itself defined in both `index_topk.py` and `sparse_attn.py`), `validate_runtime_config`
checked a literal 128, and the "128 wide, one block an entry" rule was checked in
`_index_cache_spec` and again in `Mxfp4KvLayout.check`; they agreed only because the
numbers match.
`SPARSE_BLOCK_SIZE` is defined once in the new import-free `model_ops/minimax_m3/
geometry.py` (not in `index_topk` / `sparse_attn`: `Config`'s startup checks and
`mxfp4_pages`, which no-aiter CI imports, must not pull aiter / triton), and imported
by `index_topk`, `sparse_attn`, `mxfp4_pages` (where `PAGE_TOKENS` is gone), the M3
startup check and the fused-write call. The MXFP4 index spec now goes through
`Mxfp4KvLayout.check`, the one place that checks the geometry of an MXFP4 page; its
message now says "an MXFP4 page" (the check serves K, V and the index key).
The page-geometry contract test reads constants with `ast`, so it is seeded with the
new module. `sglang`'s plugin keeps its own literal (it does not import atom kernels).
Co-Authored-By: Claude <[email protected]>
* Revert diff noise: moved test lines and a split one-line import
valarLip's round-3 item 12: `tests/test_config_compile_hash.py` and
`tests/test_compile_hash_spec.py` moved a `kv_cache_dtype="fp8"` line without changing
it, and `aiter_attention.py` split a one-line `forward_context` import that fits in 88
columns. The test_config_compile_hash.py hunk is reverted to main; test_compile_hash_spec.py
keeps only the `kv_cache_dtype` default its stub spec needs; the import is one line again.
Co-Authored-By: Claude <[email protected]>
* Say how the M3 K/V binding covers fp4 in its comment
valarLip's round-3 item 13: the comment on the sparse binding still said the standard
binding sets k_scale / v_scale and is page-128 SHUFFLE re-viewed to page-16; under
--kv-cache-dtype fp4 it binds scale-less MXFP4 pages. The same sentence was already
fixed in attention_mha.py. Comment only.
Co-Authored-By: Claude <[email protected]>
* State M3's fp4 rules once: in validate_runtime_config and the configuration guide
valarLip's round-3 item 14: the M3 fp4 rules were written five times and disagreed: the
--kv-cache-dtype help left out the vLLM/SGLang bridge refusal and the requirement that
the index be fp4 too, which validate_runtime_config and the guide have.
The rule list now lives in validate_runtime_config's docstring (the source) and the
configuration guide's kv_cache_dtype / index_cache_dtype rows; the two help texts, the
two CLI-table rows and _check_fp4_kv's docstring point there. resolve_draft_kv_dtype's
docstring was already cut to its contract with the draft-dtype flag change.
Co-Authored-By: Claude <[email protected]>
* Give IndexScoreBuffers an import-free home so the non-GPU suite can build it
The non-GPU CI job (no aiter, no triton) failed three tests of
tests/test_minimax_m3_mxfp4_decode_batch.py at `from atom.model_ops.minimax_m3.
sparse_attn import IndexScoreBuffers`: sparse_attn.py imports aiter at the top, and the
record is plain data. It now lives in `model_ops/minimax_m3/index_buffers.py`, which
imports only torch and `LogitsWorkspace`; `sparse_attn.py`, `aiter_attention.py` and the
tests import it from there (no re-export).
The three tests drive `minimax_m3_index_topk[_decode]`, which needs aiter, so without
it they skip like the rest of that file (their `importorskip` was never reached, the import
above failed first). A new test that needs no aiter checks the record itself: frozen,
and a step's record is the builder's with its map replaced.
Checked with the full tests/ run under a plugin that blocks aiter, triton, flydsl, vllm
and friends (outside the repo): on the pushed head it reproduces exactly CI's three
failures; with this commit none of them remains, and nothing fails that does not also
fail on the previous head fd64ce3ef.
Co-Authored-By: Claude <[email protected]>
* Build the EAGLE3 draft at the dtype its pool was allocated at
The draft's attention reads its cache dtype off the config it is built with,
and `_build_draft_model` copied the target's config without setting it. Once
an EAGLE3 draft owns its pool (`--spec-decode-kv-cache-dtype`, and bf16 under
an fp4 target), the pool was allocated at `speculative_config.kv_cache_dtype`
while the attention kept the target's dtype: an fp8 target with a bf16 draft
wrote bf16 pages through fp8 cache semantics, and the inverse mismatched too.
Set it from the same resolved value, as DSpark already does.
Co-Authored-By: Claude <[email protected]>
* Skip the whole-batch MXFP4 scorer map on a decode that splits
A decode TBO step is cut into micro-batches before the builder runs, and its
forward runs only their metadata, each with its own work map. `finish_decode`
(and the graph capture of a split bucket) still built the whole batch's map: a
launch on every step, and on every replay, that no layer reads. Both now build
the whole batch's sparse metadata without the scorer record when the step
splits; an unsplit step is unchanged, and a layer that did read a record-less
decode metadata would raise as before.
Co-Authored-By: Claude <[email protected]>
* Address the 4cc42e7ed review: scorer allocation out of the MHA builder, one row rule, direct imports
- The MXFP4 index scorer's allocation (work map, score workspace, per-ubatch maps)
moves from AiterAttentionMetadataBuilder to index_buffers.allocate_index_scorers;
"" in builder._index_scorers is the switch, _index_work_map_blocks is gone.
- index_topk takes index_scorer alone (index_mxfp4 removed); the layer raises when an
MXFP4 index has no record. The kwargs-dict helpers are deleted, the page constants
and sparse_pa_mxfp4 are bound once in the impl's __init__.
- Prefill takes the rows its metadata covers, as decode does (one _metadata_rows).
- index_topk, sparse_attn and sparse_attn_mxfp4 import their aiter / FlyDSL functions
at the top; the topk_per_row_small_k import has one path and no ImportError fallback.
- draft_owns_kv_pool reads config.speculative_config; the lmcache test stub gets it.
- Configuration guide: no history in the draft KV dtype row.
Co-Authored-By: Claude <[email protected]>
* Test that another index cache allocates no scorer, without aiter
Co-Authored-By: Claude <[email protected]>
* Import FlyDSL where it is selected; ask the plugin question before reading native fields
index_topk and sparse_attn took aiter.ops.flydsl names at module level, and
aiter.ops.flydsl imports flydsl, so every deployment that loads the shared MHA
backend needed FlyDSL, MXFP4 index or not. The MXFP4 scorers, their work map and
aiter's small-k selector are now imported once, by a cached loader, on the first
step that selects them; a deployment that selects one without FlyDSL fails there,
with no probe and no fallback.
draft_owns_kv_pool read the native speculative-config fields before the plugin
check, but the vLLM offload adapter hands over vLLM's own SpeculativeConfig, which
has no draft_model_hf_config: plugin mode is now asked first.
Co-Authored-By: Claude <[email protected]>
* Clamp a pad row's causal length where the block-table emission takes it (B12)
_emit_sparse_block_table_row computed self_blk and the tail token count from a
raw causal_len, which is <= 0 for a pad row (seq_len 0, Q > 1); only the final
store of the context was clamped. Clamp causal_len where it enters, give a row
with no key self_blk = -1 so no selected id can be valid, and drop the store-side
clamp. The helper is shared by the bf16/fp8 Triton selectors, the MXFP4 one and
the candidate exchange, so every index cache gets it.
The new test runs the helper on its own with a non-empty selection for pad rows:
on the CPU under Triton's interpreter (it fails on the old helper: a pad row
emitted page 100), and as a compiled kernel on gfx950 (GPU-pending, not run).
Co-Authored-By: Claude <[email protected]>
* Drop two tests that repeat a stricter test or the stdlib
test_every_family_that_owns_a_draft_pool_has_a_backend_that_builds_it asserts a
subset of what the next test asserts; the scorer-record test checks
dataclasses.replace and FrozenInstanceError, and the aiter-free construction is
pinned by test_another_index_cache_allocates_no_scorer_and_imports_no_aiter.
Co-Authored-By: Claude <[email protected]>
* Inline kv_pages_leave_pool, a one-line wrapper over bool(kv_transfer_config)
Co-Authored-By: Claude <[email protected]>
* Shorten the MXFP4 decode scorer docstring to what the buffers' docstring leaves out
Co-Authored-By: Claude <[email protected]>
* Record the aiter minimum the MiniMax-M3 index paths need (valarLip: bump the requirement)
The repo records no aiter minimum, and the selector import in index_topk.py has
no fallback since 224ae84bc: a bf16/fp8 row of 131072+ tokens on an aiter without
topk_per_row_small_k raises ImportError where main fell back to Triton. Say which
aiter builds the paths need (#7014 selector, #7060/#7061 MXFP4 index scorers,
#7056 MXFP4 K/V pa_decode) in the configuration guide, the repo's usual form
("Needs aiter with #NNNN"), and point the selector's docstring at it.
Whether bf16/fp8 should instead fall back to Triton on an older aiter is a policy
choice between valarLip's "no probe" rule and Copilot's review; the alternative is
kept as FALLBACK_ALTERNATIVE.patch beside this branch, not applied.
Co-Authored-By: Claude <[email protected]>
* Name aiter's writer formats from one table (B15, the mapping half)
The fused writer's "mxfp4" spelling of ATOM's fp4 was written twice, once for the
KV cache and once, after the fact, for the index cache. One table, used for both.
Behaviour-preserving: every (kv dtype, index dtype, skip-index) combination gives
the string it gave before (checked exhaustively by hand); the gfx950 write tests
that exercise the call (tests/test_minimax_m3_mxfp4_write.py) are GPU-pending.
Co-Authored-By: Claude <[email protected]>
* Name aiter#7057, the fused MXFP4 writer, in the minimum-aiter note
Co-Authored-By: Claude <[email protected]>
* Move --spec-decode-kv-cache-dtype out of this PR (valarLip 11-12 item 6)
The draft-KV dtype flag, its EngineArgs plumbing, the "requested" half of
SpeculativeConfig.kv_cache_dtype and resolve_draft_kv_dtype, the offload refusal
on a draft dtype that differs from the target's, the docs row and the flag tests
go to their own PR (branch ganyi/m31-draft-kv-flag, based on main).
What stays is what an fp4 target needs of it: a draft with a pool of its own is
bf16 under --kv-cache-dtype fp4 (an fp4 draft has no layout), a draft in the
target's pool keeps the target's dtype (M3.1's validator refuses fp4 there), and
every reader (draft pool, proposers, calibration identity, compile hash) reads the
one settled field, now named SpeculativeConfig.draft_kv_dtype so that both
branches share lines. The draft-pool decision from the attention family and V4's
fp8 -> bf16 fallback in Config stay: removing them needs the flag PR to land first
(SPLIT.txt, order A).
Co-Authored-By: Claude <[email protected]>
* MiniMax-M3.1: --kv-cache-dtype fp4 defaults the index cache to fp4; name M3.1 in the guard
valarLip (11-10 #6): the bf16 index default left by `--kv-cache-dtype fp4` existed
only to be refused. An omitted --index-cache-dtype now follows the KV dtype (fp4),
as for every other model; an explicit bf16 / fp8 is still refused by
validate_runtime_config. This reverses 4e4dca9bd ("fp4 only when asked for").
The _check_fp4_kv message and docstring now say MiniMax-M3.1 (the scope of this PR),
and that M3's dense-attention checkpoints are refused by the model's own validator.
Co-Authored-By: Claude <[email protected]>
* Trim the tests this PR adds: one test per behaviour, no plumbing or duplicate tests
Roughly halves the test code the PR adds. Merged near-duplicates into parametrized
cases (padded eager / graph / workspace rows, the startup refusals as one table, the
row rule for decode, prefill and a split TBO step), and removed tests that only
asserted mocks, private-helper plumbing or a second copy of another test
(test_aiter_index_cache_spec.py, the draft-pool agreement tests, a repr pin, ...).
Every deleted or merged test is listed with the review thread that asked for it in
TRIM_*.txt, and the thread is told. The B12 pad-row test, the FlyDSL-optional test
(now one subprocess test), the refusals, the row rules and the real-kernel
(gfx950, GPU-pending) tests each keep a case.
Co-Authored-By: Claude <[email protected]>
* Shorten comments and docstrings that restate the code (no code change)
Comment and docstring trims only in index_topk, index_buffers, sparse_attn_mxfp4,
sparse_attn, attention_mha, aiter_attention, models/minimax_m3/config, draft_kv and
config; comments that a review thread asked for are kept.
Co-Authored-By: Claude <[email protected]>
* Keep the test that pins the draft-pool family table to the backends that build a pool
It guards a silent failure (a backend with make_kv_pool missing from DRAFT_POOL_FAMILIES
leaves its draft sharing the target's rows); it replaced main's flag-agreement test.
Co-Authored-By: Claude <[email protected]>
* Refuse the MXFP4 caches under decode context parallelism
M3 has no DCP gather/merge: with DCP > 1 the writer stores only a rank's own
tokens while the sparse readers take global lengths, so a read can reach rows
nobody wrote. validate_runtime_config now refuses decode_context_parallel_size > 1
when either MXFP4 cache is on; tests cover the FP4-KV and index-only cases.
Co-Authored-By: Claude <[email protected]>
* Let the sparse impl declare its KV layout; type KvGeometry.layout; document the DCP and in-pool-draft refusals
The shared MHA builder no longer imports the MXFP4 layout or tests the
dtype: SparseMHAPagedAttentionImpl.kv_layout says how its pages are laid out.
KvGeometry.layout is a KvLayout, not object. The configuration guide now lists
the decode-context-parallel and in-pool-draft refusals, and three comments that
still described the removed backend flag are corrected.
Co-Authored-By: Claude <[email protected]>
* Test: a graph capture must not allocate the scorer buffers it already passes
_run built the buffers even when the caller handed it the metadata, so the
captured variant of the padded-step index test allocated inside the capture
(hipErrorStreamCaptureUnsupported on gfx950).
Co-Authored-By: Claude <[email protected]>
* Type KvGeometry.layout inside pool_layout; trim the comment and docs edits of the last commit
pool_layout/ may not import atom (tests/test_layout_packages.py), so the layout
annotation is a one-attribute Protocol defined beside KvGeometry instead of an
import of mha_kv_pool.KvLayout. The three comment corrections that belong to the
draft-KV PR are dropped here, and the docs wording and the impl's kv_layout
comment are shorter.
Co-Authored-By: Claude <[email protected]>
* Declare kv_layout once on the impl base; refuse MXFP4 KV under sequence parallelism; test leftovers
PagedAttentionImpl.kv_layout = None, read as module.impl.kv_layout by the shared
builder (no getattr); the test stub gets an impl. The fused MXFP4 writer checks
the qkv row width including the index columns, which Ulysses drops for a top-k
reusing layer, so fp4 KV is refused with --sequence-parallel-size > 1 (docs and
test row). Add the refusal test for a third model; the emit_pad_row docstring no
longer says the gfx950 variant is unrun.
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude Code <[email protected]>
…, emit an fp8 main Q (ROCm#7057)
* [HIP] fused_qknorm_idxrqknorm: write the index K cache as MXFP4
New index_cache_dtype="mxfp4": the index-K slot is quantized to e2m1 with one
e8m0 scale per 32 elements and written into single-region 8704 B pages,
[128 tokens x 64 B data][128 tokens x 4 B scale]. Low nibble is the even
element; the scale rule is indexer_fp4_scale_e8m0's (ceil(log2(amax/6)), eps
clamp) and the rounding the hardware scaled_cast<fp4_t> already used by the DSA
writer.
Only the index-K write changes. It is a kIndexFp4 template bool, so every
existing instantiation compiles to the same code (identical VGPR/SGPR counts,
no spills); q/k norm, RoPE, index Q and the main KV are untouched, and the
thread mapping is still one warp per slot. The elements are rounded to the
input dtype first, so the bytes are the quantization of the row "auto" writes.
The new instantiations are launched from one generic lambda placed ahead of the
four existing launch sites, which are not touched.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: write the main KV cache as MXFP4 and emit an fp8 main Q
kv_cache_dtype="mxfp4" stores K (post norm/RoPE) and V as 128-token pages of
[128 x 64 B e2m1][128 x 4 B e8m0] per (page, kv head), the same page as the MXFP4
index cache. q_fp8_out/q_scale add a per-tensor e4m3 copy of the main Q (round to
model dtype, divide by q_scale, saturate). Index-cache modes and the fp8/auto KV
modes are unchanged.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: merge the MXFP4 launch lambdas, trim comments
One templated launch lambda replaces the two copies, storeMxfp4Row takes
(cache, slot, strides) so the index-K wrapper goes away, and the redundant
mxfp4 kv sparse check is simplified. Same registers for all 444
instantiations and same machine code for the 288 existing ones.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: one aiter-style op test
Merge the index and main-KV MXFP4 tests into one script with shared
helpers, @benchmark + torch.equal byte checks (as test_quant_mxfp4.py), a
gfx950 allow-list in main() and a summary table per sweep, so
`python3 op_tests/test_*.py` in CI runs every check; the old pytest files
were not collected there.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: make pytest collect one sweep test
Mark the argument-taking helpers __test__ = False as sibling op tests do
and expose the default sweep as test_sweep, so pytest no longer errors
on missing fixtures.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: take the fp8 main Q through q_out
Drop q_fp8_out/q_scale: q_out may now be an e4m3 tensor (fp8 or uint8,
insert mode), written unit-scale and saturating instead of the bf16 q,
as index_q_out already works. The header and pybind are back to main.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: make the e4m3 q_out test reach out-of-range values
The RMSNorm erased the x600 on the qkv row, so no q value passed 448.
Scale the q-norm weight instead and compare against the plain e4m3
cast: the op does not clamp, out-of-range values become NaN, as for an
e4m3 index_q_out. Say so in the wrapper comment.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: saturate the e4m3 q_out cast
Clamp the main-Q elements to the e4m3 max before the cast, so values
beyond it (and +-inf) become +-max instead of NaN; NaN stays NaN. Only
the q_out path changes: the shared cast, index_q_out and the existing
instantiations' outputs are untouched. The test now injects out-of-range,
inf and NaN values.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: refuse mxfp4 off gfx950, check the mxfp4 index cache
Raise in the wrapper when an mxfp4 cache is asked for on another arch
(opus converts to fp4 as zeros there). Require whole 8704 B index pages
for every layout and the same index-capacity check for the mxfp4 main-KV
layout as the page-128 one. The test gets a negative case for each, and
no longer evaluates torch.finfo(dtypes.fp8) at import.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: slim the sweep, drop duplicated code
Drop T=7 and the index-only shuffled slot case from the sweep (covered
by the other slot patterns), the **extra plumbing in make_call, and the
second q_out fp8 dtype computation in the host code. Device code is
unchanged for all 444 instantiations.
Co-Authored-By: Claude <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: gate the fp8 q_out by arch, match mxfp4 K/V page counts
Refuse an fp8 q_out where opus has no fp8 conversion (it would write
zeros); only gfx942, gfx950 and gfx12xx convert. Require V to have K's
page count in the mxfp4 layout, as the plain layout does, so a slot valid
for K cannot write past V. Negative tests for both.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: drop the pytest hooks, plain aiter script
Remove the test_sweep pytest entry and the __test__ = False loop; the file is
a script like the other op_tests (python3 op_tests/<file>), same cases.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm mxfp4: check bytes with checkAllclose, report err
The write-bytes, skip_index_branch and e4m3 q_out checks compared bytes with
bare asserts and returned a PASS row. Compare them with checkAllclose
(rtol=0, atol=0) like the sibling test_fused_qknorm_idxrqknorm.py and report
an err column; rejection rows report err 0 on the expected failure. Same cases.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm: test mxfp4 and e4m3 q_out in the existing op test, drop the separate file
The MXFP4 cases move into op_tests/test_fused_qknorm_idxrqknorm.py, on its
make_case / run_fused_qknorm_idxrqknorm / check_close helpers, its --mode / -d /
--num_tokens sweep and its markdown table, and
op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py is removed. The runner gains
optional kv_dtype / index_dtype / q_dtype / index_pages arguments; the existing
modes and rows are unchanged. The mxfp4 modes run on gfx950 only and are skipped
with a warning elsewhere.
Co-Authored-By: Claude <[email protected]>
* [Test] fused_qknorm_idxrqknorm: cover separate contiguous mxfp4 K/V and the kv-only arch guard
Two cases of the pre-merge mxfp4 test were not carried over: mxfp4 K and V as
separate contiguous tensors (now used for one kv head, the pool views stay for
two), and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache.
Co-Authored-By: Claude Code <[email protected]>
* [HIP] fused_qknorm_idxrqknorm: e4m3 q_out as a template flag, tighter UT (review ROCm#7057)
- kQFp8 is a bool template of the kernel, instantiated only where insert mode can use it, instead
of a runtime `q_fp8_out != nullptr` branch: the 288 pre-existing instantiations are
VGPR/SGPR/spill-identical to origin/main again (the runtime branch added 1-3 VGPR to 111).
- asm_layout index_cache: the main-cache size(0) is a storage span in packed LBHNC mode, so no
capacity check is possible; state the index_slot_mapping bound as a caller contract.
- UT: skip on the live GPU (get_gfx_runtime), not GPU_ARCHS; each reject case asserts the message
of its own check instead of "mxfp4" or "index" anywhere in stderr (drops the duplicate
small-index case, it hit the same whole-page check as partial_page).
- Fix a stale comment that still named the removed op_tests/test_fused_qknorm_idxrqknorm_mxfp4.py
(an uncommitted one-line edit found in the worktree, checked against the test file).
Co-Authored-By: Claude Code <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: r <r@x>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fused_qknorm_idxrqknormcan now write its caches as MXFP4 (e2m1 data, e8m0 scale per 32 elements), and itsq_outcan be an fp8 e4m3 tensor:index_cache_dtype="mxfp4": the index-K slot is quantized and written into 128-token MXFP4 pages.kv_cache_dtype="mxfp4": the main K (post norm + RoPE) and V are quantized and written into 128-token MXFP4 pages, one per (page, kv head).q_outas an e4m3 tensor (float8_e4m3fnoruint8): the post norm + RoPE main Q is written as a unit-scale, saturating e4m3 cast instead of bf16/fp16, the same way an e4m3index_q_outalready works.This kernel is the producer. The pages it writes are consumed by the MXFP4 index-score kernels (#7060 decode, #7061 prefill) and the MXFP4 paged-attention decode (#7056); this PR has no dependency on either and is tested without them. ATOM integration: ROCm/ATOM#2770 (draft; depends on these aiter PRs and on yuhua/m3.1-flash).
Fifteen commits: (1) index-K MXFP4 write, (2) main-KV MXFP4 write plus e4m3 Q output (first as separate
q_fp8_out/q_scalearguments), (3) launch-lambda dedup in the .cu (vs the previous head: same registers for all 444 instantiations, same machine code for the 288 existing ones), (4) the two op tests merged into one aiter-style script, (5) a pytest entrytest_sweep(dropped again in (12)), (6) the e4m3 Q goes throughq_outand theq_fp8_out/q_scalearguments are removed, (7) the e4m3 test reaches out-of-range values, (8) the e4m3q_outcast saturates, (9) mxfp4 caches are refused off gfx950 and the index-cache size is checked for the page-128 layout and the mxfp4 main K/V, (10) the test sweep is slimmed (no device-code change), (11) an fp8q_outis refused where opus has no fp8 conversion and the mxfp4 V cache must have K's page count (host checks only), (12) the test file loses its pytest hooks (test_sweep, the__test__flags): it is a plain script, same cases, (13) the test compares bytes withcheckAllclose(rtol=atol=0) and reports anerrcolumn, same cases (test file only), (14) the MXFP4 test cases move into the existingop_tests/test_fused_qknorm_idxrqknorm.pyandop_tests/test_fused_qknorm_idxrqknorm_mxfp4.pyis removed (test files only; the kernel and wrapper are unchanged since (11)), (15) two cases of the old file that were not carried over: separate contiguous mxfp4 K/V tensors (now the one-kv-head cases; the pool views stay for two kv heads) and the gfx950 refusal of an mxfp4 main K/V with a non-mxfp4 index cache (test file only).Commit 80b5209's message says every existing instantiation compiles to the same code; that holds for that commit only, and at the final head none of the 288 existing instantiations has identical machine code (see Registers).
Format
[128 x 64 B e2m1 data][128 x 4 B e8m0 scale]= 8704 B. The low nibble is the even element; one e8m0 scale per 32 elements.kv_cache_k/kv_cache_vas separate uint8[pages, kv_heads, 8704]tensors and uses their own page/head strides, so they can be the K and V views of one pooluint8 [pages, 2, kv_heads, 8704].block_sizemust be 128.ceil(log2(amax / 6))with an eps clamp (the rule ofindexer_fp4_scale_e8m0incache_kernels.cu); e2m1 rounding is round-to-nearest-even with saturation. Elements are rounded to the input dtype first, so the bytes are the quantization of the row that"auto"mode would write.q_out:e4m3(q)with q rounded to the input dtype first (bf16 or fp16, as every other cache write of this op), scale fixed at 1.0, saturating: finite values beyond the e4m3 max become +-max and +-inf becomes +-max (the elements are clamped before the cast), NaN stays NaN. The clamp is only on theq_outpath; an e4m3index_q_outstill uses the plain cast (beyond-range values become NaN there). As with an e4m3index_q_out, the bf16 row is not written: neither a bf16q_outnor the in-place qkv row. Insert mode only (kv caches given); an e4m3q_outwithout them is rejected.per_1x32_f4_quant: for an all-zero group,per_1x32_f4_quantgives e8m0 = 0, while the HIP rule gives 1 (0 is outside the decode kernel's contract). The writer uses the HIP rule; data bytes are 0 either way. The tests adjust the reference for exactly that case.Interface
No new function arguments. New values:
index_cache_dtype="mxfp4";kv_cache_dtype="mxfp4"(sparse insert mode;skip_index_branch=Trueis supported for layers that reuse another layer's top-k); andq_outmay now be an e4m3 tensor (it used to require the qkv dtype). Calls that do not use them are unaffected in behavior. MXFP4 index-K and MXFP4 main-KV are template bools; an e4m3q_outis a runtime pointer check.Verification
Hardware: MI355X (gfx950), ROCm 7.2.4 image
rocm/atom-dev:nightly_202610261558, one GPU. "Base" isorigin/mainat340bea3b54; "head" is this branch on top of it (the commits that landed on main since do not touch this module). The branch was then rebased onto849f711d39(which includes #7055); the PR diff is unchanged, and the tests, register counts and device assembly were re-checked on the rebased head with the same results.Existing behavior.
op_tests/test_fused_qknorm_idxrqknorm.py(default sweep, 21 cases, and--minimax_tp4) passes before and after: the default sweep 21/21 rows (1481passed~checks) and--minimax_tp4155passed~checks, both times, with identical pass/fail summaries. Re-run at 071a842 (this round, same test file extended by the mxfp4 modes): the 21 existing rows and their 1481passed~checks are identical to the unmodified file run on the previous head (same rows, same pass counts, exit 0), and--minimax_tp4gives 155passed~, exit 0.Registers (
-Rpass-analysis=kernel-resource-usage, gfx950, every instantiation in the .cu; 288 existing instantiations in base):No spills or scratch anywhere (existing and new); occupancy is 8 waves/SIMD for every instantiation, before and after.
Timing of the existing modes (M3 TP4 shape: 16 q heads, 1 kv head, 1 index head, head_dim 128, rot 64, bf16; T = 1, 8, 32, 128, 512, 1024, 4096, 16384; kv
fp8page-16 with scales andauto; index cacheautoandfp8). Each point is 50 launches captured in a CUDA graph, median of 21 replays; base and head runs interleaved three times, median of the three, same GPU and pinned cores. Head/base ratio over the 32 points: -0.8% to +1.8%. The kv-fp8 cases are consistently +0.2% to +1.8% (e.g. T=1 4.10 -> 4.18 us, T=16384 69.3 -> 70.2 us); kv-auto cases are within +/-0.7%. Spread between the three repeats is 0.6% median, up to 3% on the worst point, so differences below about 1% are at the noise level.New modes (head only, same method; ratio of times):
op_tests/test_fused_qknorm_idxrqknorm.pyprints the op-only time (run_perftest, 50 iterations after 50 warmups) of the index-K write with an auto / fp8 / mxfp4 index cache for kv fp8 page-16, kv auto page-16 and kv mxfp4 page-128, T = 1, 300, 1031, 16384, bf16 and fp16: at 071a842 mxfp4/fp8 is 0.98-1.02 over the 24 rows in one run and 0.96-1.04 in a second run, one card, so a single run is good to a few percent.)autowrite, which writes more bytes but does no quantization and no fp8 Q, it is 1.11-1.22x. With an e4m3q_outthe bf16 Q is not written, and the same shapes run at 0.81 to 1.00 of that earlier configuration's time (3 interleaved runs, medians). The existing modes are within -1.4% to +1.4% of the previous head. The saturating clamp costs +0.0 to +0.4% on this configuration up to T=512, +1.0% at T=1024, +3.1% at T=4096 and +4.2% at T=16384 (3 interleaved runs, medians; spread 0.2-2.4%); the six other configurations (kv fp8/auto x index auto/fp8/mxfp4) stay within -1.3% to +1.5% of the version without the clamp. The clamp changes registers of 6 of the 444 instantiations by -2 VGPR (no SGPR change, no spills, occupancy 8).Tests
All run on gfx950 against head 071a842.
op_tests/test_fused_qknorm_idxrqknorm.pyis the existing test, extended; the separateop_tests/test_fused_qknorm_idxrqknorm_mxfp4.pyof the earlier heads is removed. It stays a module-level script with no new flags: the new modes are values of--mode(asm_layout_mxfp4,asm_layout_fp8_pertoken_mxfp4,mxfp4_kv,mxfp4_kv_skip_index,q_fp8_out,mxfp4_kv_q_fp8_out,mxfp4_scale_rule,mxfp4_reject) and use the existing-d,--num_tokensand the same default sweep, so the no-argument run that CI executes runs them. On any arch but gfx950 the file prints a warning and runs only the existing modes (exit 0). It reusesmake_case,run_fused_qknorm_idxrqknorm(now with optionalkv_dtype/index_dtype/q_dtype/index_pagesarguments that default to the old behavior),make_shuffle_caches,make_insert_outputsandcheck_close(which now returns its error ratio); new are the MXFP4 page byte reference, the slot cases and the rejection harness. Measured on the pushed tree: 42-43 s once the HIP module is built (the unmodified file: 5 s); the first run, which also builds the module, took 94 s (the unmodified file: 54 s); the 21 existing rows are unchanged, followed by 50 mxfp4 rows with anerrcolumn (0 in all) and auto / fp8 / mxfp4usandTB/scolumns."auto"mode on the same case: the MXFP4 bytes must equalper_1x32_f4_quantof the"auto"rows bit for bit, over bf16/fp16, T = 1, 300, 1031, 16384, index-K mxfp4 (and fp8, and the auto control) with kv fp8 (page-16, per-token scales) / auto, main K/V mxfp4 (page-128; 1 kv head as separate contiguous K and V tensors, 2 kv heads as the two views of one pool) with index cache mxfp4/fp8/auto, and sequential / shuffled / skipped(-1) / main-index-differing slot mappings (336 comparisons); every other output (q, index q, scales, the other cache) must be bit-identical to"auto", and an fp8 index cache must equal the"auto"rows cast to e4m3. Also:skip_index_branch(mxfp4_kv_skip_index), K and V as views into one[pages, 2, kv_heads, 8704]pool (the 2-kv-head cases), an e4m3q_out(float8_e4m3fnanduint8views, kv auto and mxfp4) against the input-dtype q clamped and cast to e4m3 (with out-of-range, +-inf and NaN columns), with the qkv row left untouched, rewriting a slot replaces all 68 bytes, zero/sparse/outlier index-K rows in every case, a torch dequantization of the pages read back at the documented offsets, the e8m0 rule vs its bit-level definition (mxfp4_scale_rule), and contract rejections (mxfp4_reject: non-uint8 or partial-page index cache, an index cache of 128 bytes or with too few pages next to an mxfp4 main KV, an mxfp4 V cache with fewer pages than K,skip_index_branchwith an mxfp4 index cache, each in its own interpreter becauseAITER_CHECKaborts the process; mxfp4 index cache, mxfp4 main K/V with each kind of index cache, and mxfp4 main K/V alone off gfx950, and an fp8q_outon gfx1100, in process with the arch faked). Byte comparisons go throughcheckAllclose(rtol=0, atol=0)on the raw bytes; a rejection row reports err 0 when the expected refusal occurred.Known limits
RuntimeErroron any other arch (opus converts to fp4 as zeros there), and its mxfp4 modes skip there. An e4m3q_outis refused with aRuntimeErrorwhere opus has no fp8 conversion (anything but gfx942, gfx950, gfx1200, gfx1201, gfx1250); it is untested on gfx942 and gfx12xx.block_sizemust be 128 for the MXFP4 caches.q_outis a runtime pointer check, not a template bool, and the kernel gained an argument, so no existing instantiation has identical machine code (see Registers); there are no spills and occupancy stays 8 waves/SIMD for all 444 instantiations. If maintainers want the existing instantiations unchanged instruction for instruction, it can be turned into a template bool.per_1x32_f4_quantdescribed under Format.PR Self-Review
Reviewed revision
071a842
Behavior and intent
Before:
fused_qknorm_idxrqknormcould write only bf16/fp16 or fp8 (with scales) caches and a bf16/fp16 main Q. The MiniMax-M3.1 MXFP4 path needs index-K and main K/V stored as MXFP4 pages and an e4m3 main Q, and the kernels that read them (#7060, #7061, #7056) take exactly that layout; the op had no way to produce it. After:index_cache_dtype="mxfp4",kv_cache_dtype="mxfp4"and an e4m3q_outare new accepted values, written by the same fused kernel (format in "Format"). Calls that use none of them keep their behavior; no existing instantiation keeps identical machine code (see Registers).Validation and unverified scope
Measured at head 071a842 this round: MI355X (gfx950), image
rocm/atom-dev:nightly_202610261558with this branch's tree overlaid, a freshly built HIP module and FlyDSL cache off, one card.python3 op_tests/test_fused_qknorm_idxrqknorm.pywith no arguments from the repo root (43 s, exit 0) and from/tmp(42 s, exit 0; the first run that also builds the HIP module took 94 s): the 21 existing rows (1481passed~, rows and pass counts identical to the unmodified file run on the previous head) and then 50 mxfp4 rows (2057passed~, err 0 in every row).--minimax_tp4gives 155passed~, exit 0. With one expected value deliberately changed (the e8m0 scale in the byte reference, not committed) the script exits 1 at the first mxfp4 row (index_cachemismatch ratio 0.00046, after the 21 existing rows passed); with an existing expectation changed (refs["q"] + 1, not committed) it exits 1 at the first existing row. With the wrapper's guard changed to ignorekv_cache_dtype(local copy, not committed) themxfp4_rejectmode exits 1 (accepted on gfx942for an mxfp4 main K/V with an auto index cache). WithGPU_ARCHS=gfx942forced on the gfx950 card (this exercises only the arch gate, not gfx942 hardware) it prints the skip warning, runs the 21 existing rows and exits 0. black 26.10.1 and ruff 0.16.0 are clean on the file.From earlier manual runs, not re-run at this head: register counts, instruction-count and machine-code comparisons, and every timing table in "Verification" except the index-K write table named there (including the head/base ratios and the clamp cost). Unverified: gfx942 and gfx12xx hardware (the fp8
q_outguard allows them; no run there), models other than the MiniMax-M3.1 shape, and CI at this head (the aiter GPU shard tests had not run on this PR when this was written).PR-specific question
Architecture: the wrapper raises
RuntimeErrorfor an mxfp4kv_cache_dtypeorindex_cache_dtypeunlessget_gfx_runtime() == "gfx950"(opus converts to fp4 as zeros elsewhere), and for an e4m3q_outunless the arch is in_FP8_CVT_GFX(gfx942, gfx950, gfx1200, gfx1201, gfx1250; opus has an fp8 conversion there).mxfp4_rejectexercises the refusals by overridingget_gfx_runtime; on real gfx942/gfx12xx hardware it was not run.Dtype: qkv bf16 or fp16 (as before; both swept); mxfp4 caches must be uint8 (
AITER_CHECK: not_uint8 case);k_scale/v_scaleare refused with an mxfp4 KV cache;q_oute4m3 asfloat8_e4m3fnor a uint8 view (both swept).Shape:
block_sizemust be 128 for an mxfp4 KV cache; K and V are[pages, kv_heads, 8704]with matching kv-head count and the V cache must have at least K's page count; the index cache must be whole 8704 B pages holding at leastnum_blocks * block_sizerows (checked for the page-128 layout and for an mxfp4 main K/V; the asm_layout path only checks whole 128-element rows, because its main-cache span is not the index cache's page domain); an mxfp4 KV cache needs the sparse insert mode with index slots, an mxfp4 index cache needs insert mode with the index branch (soskip_index_branchwith an mxfp4 index cache is refused), an e4m3q_outneeds insert mode. head_dim 128 and the q/kv head counts are the op's existing constraints. Violations of the shape/dtype checks areAITER_CHECKs that abort the process rather than raise, which is why themxfp4_rejectmode runs each case in its own interpreter. Not covered: other head_dim values and models, which are untouched existing limits.Changed op tests
op_tests/test_fused_qknorm_idxrqknorm.py(existing file, +333 -5 lines; the earlier heads added a separate 549-linetest_fused_qknorm_idxrqknorm_mxfp4.py, now removed, so the op tests of this PR are 333 added lines instead of 549). The existing test knows only the auto/fp8 caches and a bf16 Q, so it could not see any of the new modes; it is extended rather than duplicated so the new cases share its inputs (make_case), its op runner, its comparison helper, its--mode/-d/--num_tokenssweep and its table. The existing 21 rows and--minimax_tp4are unchanged (same rows, same pass counts). The lines that remain are what the file could not already express: the MXFP4 page byte reference (about 40), the slot cases, the rejection harness and the per-mode check loop. This file fails when: a page byte is wrong (nibble order, e8m0 byte, page or slot offset), checked bit for bit againstper_1x32_f4_quantof the rows the op's own "auto" mode writes, for 336 write comparisons incl. shuffled, skipped (-1) and main/index-differing slots; a write disturbs another output (q, index q, the other cache must equal "auto"); a rewritten slot keeps stale bytes; the e4m3q_outdoes not saturate or leaves the qkv row modified; an unsupported arch or malformed cache is accepted (mxfp4_reject). Verified failing only for the changed-expectation runs described above; I did not break the kernel itself.🤖 Generated with Claude Code