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
[FlyDSL] [Perf] MiniMax-M3.1 TP4 decode QKV front as one op: one-launch (1-64 rows) + split-K (65-128 rows) GEMM / norm / RoPE / NVFP4 insert - #8607
Change: one op, gemm_a8w8_qkv_front, for the MiniMax-M3.1 TP4 decode QKV front (hidden 6144 -> 2560 columns): MXFP8 QKV GEMM, q/k/index RMSNorm, partial RoPE and NVFP4 K/V/index-K page inserts. One launch for 1-64 rows, two (split-K GEMM + reduce/insert) for 65-128 rows.
Why it is faster: it replaces three launches per sparse layer (activation quantize, QKV GEMM, fused_qknorm_idxrqknorm) with one or two.
End to end: not measured as an isolated A/B (in-step decode_bench --sim1 on the earlier 17-64 build: -0.24 to -0.69 ms per step inside the window; combined-stack c32 runs did not isolate it).
One op for the MiniMax-M3.1 TP4 decode QKV front (hidden 6144 -> 2560 columns = q 2048 | k 128 | v 128 | index-q 128 | index-k 128): MXFP8 QKV GEMM, q/k/index-q/index-k RMSNorm, partial RoPE and the NVFP4 K/V/index-K page inserts. It replaces the three launches the public decode path runs per sparse layer (activation quantize, QKV GEMM, fused_qknorm_idxrqknorm). The tier is chosen by the row count inside gemm_a8w8_qkv_front; there is no tuned table, tuner script or config family (a fused chain, not a plain GEMM), and the split-K factor ks is a kernel parameter (default 3, measured best; 1/2/3/4/6 are bit-checked).
Activations are plain row-major (no pre-shuffled layout, no extra quantizer). The NVFP4 insert half is the existing fused_qknorm_idxrqknorm HIP op for the unfused path; the chain kernels carry their own fused epilogue and share 25 device helpers (qkv_front_common.py, moved byte-for-byte from the closed FlyDSL insert of #8576). Technique source: amd-kernels attention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128 and the decode GEMM primitives of mxfp8_gemm_decode.py (credited in the file headers, no import).
This PR folds #8607 (17-64 rows), #8610 (65-128 GEMM) and #8611 (65-128 reduce + insert) into one (both closed); #8606 (shuffled quantizer) and #8576 (FlyDSL insert) are no longer needed and are not in the net diff. ATOM wiring: ROCm/ATOM#3809 / #3810 (ATOM_M3_QKV_CHAIN, default off), to become one thin PR.
Measured gain
Merged-tree rerun (a tree with #8472 merged; MI355X gfx950, one lease, graph replay, ABAB, 8 rotated weight sets, median of 30). Complete front sequence, us per layer. plain = per_group_quant_hip + gemm_a8w8_blockscale (public tuned table) + fused_qknorm_idxrqknorm (nvfp4, with #8472's insert); fused = gemm_a8w8_qkv_front. Two independent runs each:
rows
tier
plain
fused
delta
1
one-launch
13.77 / 13.62
9.85 / 9.85
-3.84 (-28.1%)
8
one-launch
13.26 / 13.00
10.38 / 10.29
-2.79 (-21.3%)
16
one-launch
13.62 / 13.54
10.62 / 10.56
-2.99 (-22.0%)
32
one-launch
14.04 / 14.07
11.35 / 11.34
-2.71 (-19.3%)
64
one-launch
15.82 / 15.83
14.20 / 14.15
-1.64 (-10.4%)
96
split-K
18.60 / 18.71
15.22 / 15.26
-3.42 (-18.3%)
128
split-K
18.94 / 18.85
17.29 / 17.20
-1.65 (-8.7%)
About 1.6-3.8 us per layer on a tree where #8472 is already merged, roughly 100-230 us per decode step over the 60 sparse layers. Rows 17 and 65 were not in this rerun. The earlier table of this PR was measured against the plain chain before #8472 (its insert was slower, so the plain column was higher): 3.0-4.8 us per layer over rows 1, 8, 16, 17, 32, 64, 65, 96, 128 (-19.5% to -29.0%), roughly 200-290 us per decode step; that earlier range is superseded by the merged-tree numbers above. In-step (decode_bench --sim1, TP4 rank-0 shard on one GPU, k=7, ctx 100K, median step ms; measured on the earlier 17-64 build, same kernel bodies): -0.24 .. -0.69 ms per step (2-6%) inside the window, 0 outside (noise +-0.35 ms).
Not measured / honest limits: no end-to-end serve-level A/B of the chain alone. In the combined stack runs (c32, 900 s) the chain was on (60 layers, window 17..128) but not isolated; one earlier pre-fix arm showed +0.0% on c32 throughput. 71% of the c32 decode steps fall in the window, so the expected e2e effect is a few percent of decode time, not yet shown. Rows 1-8 are served by the mono path in ATOM (ATOM_MONO_MAX_ROWS=8) and never reach this op.
Correctness
op_tests/test_gemm_a8w8_qkv_front.py + op_tests/test_flydsl_qkv_chain.py (gfx950): 193 passed, 64 skipped (ks != 3 on the one-launch tier, by design). Rows 1..128 including the tier edges 16/17/64/65/128, decode-shaped scattered slots, skipped slots (slot -1 writes nothing), fused-vs-unfused bitwise equality for ks in 1/2/3/4/6, quantizer guard bytes, CUDA-graph replay with changed inputs equal to eager (epoch counters need no re-arm; they belong to a device and eager stream, or the HIP capture id plus stream).
Against the amd-kernels chain (development oracle, not imported): bit-identical q_out, index_q_out, KV pages and index pages for the one-launch tier (measured on the 17..64 build).
Against the unfused public path: q within bf16 rounding, index-q mean diff < 5%, pages differ in < 3% of bytes (the two GEMMs sum K in different fp32 orders).
Input validation raises ValueError (not assert; verified under python -O): head set 16/1/1, rotary 64, N=2560, K=6144, ks in (1,2,3,4,6), buffer extents. Split launches are keyed by device and run on the operand's device and stream.
AOT: aiter/aot/flydsl/qkv_front.py registered in AOT_MODULES (replays qkv_chain_insert at 128 rows and bisects down); python -m aiter.aot.flydsl.qkv_front and --check pass (32 sizes, 0 failed).
Review
By-hand pass over the repo review rules (AGENTS.md, aiter-ops-flydsl.instructions.md): buffer-resource sizes come from the runtime row count or exact constants; arch gate by get_gfx_runtime(); the hook raises when a parked front cannot be consumed (no silent bypass; the defer_ok hand-off contract is in the module docstring); coop and split kernels share one helper module (no divergent copies). Known deviations, stated rather than hidden: (1) the kernels use the legacy buffer_ops addressed by raw IPC / device pointers like the sibling comm and prefill kernels, because the op's ABI is raw device pointers; (2) about 27 raw llvm/rocdl/inline-asm sites (flag atomics, ballot/mbcnt, DPP, MFMA scale operands) have no stable fx equivalent at the pinned FlyDSL. Size: 3532 added lines in 13 files, one kernel family that cannot be split (user ruling: one PR).
Merge order with #8472: both edit aiter/ops/fused_qknorm_idxrqknorm.py. A scratch merge conflicts in that one file only (mechanical); resolution = #8472's file plus this PR's 124-line hook, and the deferred-front block must run before #8472's _nvfp4_raw_front call (otherwise the raw front would read the uncomputed qkv). Land #8472 first, then rebase this PR with that resolution.
Status: draft until a c32 end-to-end A/B of the chain is in.
Review-fix update (head bb6f2be0e)
8ee460766 (operand validation as exceptions, op-boundary shape / head checks, device-keyed split launches) and 91cbef5c6 (stale skips and wording) answered the review comments of the first revisions; bb6f2be0e documents the slot_mapping run contract in the gemm_a8w8_qkv_front.py module docstring: rows sharing an 8-slot octet are packed as one run into consecutive slots starting at the first row's slot; gapped or two-run octets are unsupported; slot -1 is supported; callers that cannot guarantee the contract pass defer_ok=False. There is no runtime check for it (it would need a device sync). The last commit is a docstring change only and was not run on a GPU.
…Max-M3 TP4 prefill
Same bytes as the HIP kernel, 1.6-3.0x faster on device and 3.5x less host time per
call for calls of at least 1024 tokens (nvfp4 K/V/index-K, 16/1/1 heads, rotary 64,
gfx950). Ported from amd-kernels. AITER_FUSED_QKNORM_NVFP4_FLYDSL=0 keeps the HIP kernel.
Co-Authored-By: Claude <[email protected]>
…6) code layout + shuffled E8M0 scales
gfx950 FlyDSL quantizer: bf16 [M, K] -> fp8 e4m3 codes in the weight's (16, 16) preshuffled layout (rows padded to the row
tile, padding rows zero) plus E8M0 scales in AITER's shuffled layout, or row-major codes. One launch, a workgroup per
32-row x 256-K tile. Prerequisite of the one-launch QKV front chain (next PR): that kernel reads exactly these codes.
Technique source: amd-kernels gemm/mxfp8_common/mxfp8_quant.py and the scale/convert helpers of mxfp8_gemm_decode.py
(ported, no import). op_tests/test_flydsl_mxfp8_quant_shuffled.py compares codes and scales byte for byte against a torch
reference of the Triton MXFP8 rule (60 shape/magnitude cases).
Co-Authored-By: Claude <[email protected]>
…ode rows (TP4)
QKV MXFP8 GEMM (deferred split-3) + q/k/index-q/index-k RMSNorm + partial RoPE + NVFP4 K/V/index-K page inserts in ONE
launch: 240 five-wave workgroups, a head's 12 workgroups publish sc1 slabs and bump an epoch counter, the last roles reduce
and insert eight rows each. Replaces the three launches of the public decode path (quantize, GEMM, fused_qknorm_idxrqknorm)
for 17-64 rows. Host wrapper qkv_chain_cooperative_insert keeps counters per device/stream or HIP capture id.
Technique source: amd-kernels attention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128 (kernel_cooperative.py,
host.py) and the decode GEMM primitives of mxfp8_gemm_decode.py (ported, no import). Helpers come from the FlyDSL NVFP4
insert of ROCm#8576, activation codes from the quantizer of the previous commit.
Co-Authored-By: Claude <[email protected]>
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 8607 --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.
Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.
Adds a FlyDSL QKV front chain for MiniMax-M3.1 TP4 decode batches of 17–64 rows, building on the shuffled MXFP8 quantizer and NVFP4 insert work in stacked PRs #8606 and #8576.
Changes:
Fuses QKV GEMM, normalization, partial RoPE and NVFP4 cache inserts into one launch after activation quantization.
Adds host-side validation, workspace allocation and stream/capture-specific epoch counters.
Adds public-path comparisons and graph-replay tests, alongside the stacked quantization and prefill-insert tests.
File
Description
op_tests/test_fused_qknorm_nvfp4_flydsl.py
Stacked NVFP4 insert correctness and timing tests.
op_tests/test_flydsl_qkv_chain.py
Decode-chain comparisons and graph-replay tests.
op_tests/test_flydsl_mxfp8_quant_shuffled.py
Stacked shuffled-quantizer byte comparisons.
aiter/ops/fused_qknorm_idxrqknorm.py
Stacked FlyDSL dispatch for eligible NVFP4 prefill calls.
aiter/ops/flydsl/kernels/qkv_chain.py
Chain launcher, input checks and counter management.
…-128 rows, MiniMax-M3.1 TP4 QKV
One-wave workgroups over RT 16-row x NI 16-column tiles of one K third, both operands in the (16, 16) preshuffled layout,
W / A blocks issued ahead of the scaled MFMAs, odd-RT A scale re-pairing; writes the fp32 slabs a fused reduce-insert reads.
Bit-identical to the amd-kernels decode GEMM at 65..128 rows; graph replay 8.1-9.1 us vs 9.7-11.7 us for the public GEMM.
Technique source: amd-kernels gemm/mxfp8_common/mxfp8_gemm_decode.py (ported, no import).
Co-Authored-By: Claude <[email protected]>
…n for 65-128 decode rows (TP4)
Sums the three fp32 K-third slabs, rounds to bf16 and runs the norm / RoPE / NVFP4 K, V, index-K insert arithmetic of
fused_qknorm_idxr_nvfp4_insert in one launch (V in workgroups of its own through LDS); qkv_chain_insert serves 17-128 rows
(one launch to 64 rows, GEMM + reduce-insert above). Bit-identical to the amd-kernels chain at 65..128 rows; graph replay
13.7-16.3 us vs 16.9-20.0 us for quantize + public GEMM + fused_qknorm_idxrqknorm.
Technique source: amd-kernels attention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128 (reduce_insert.py, packing.py).
Co-Authored-By: Claude <[email protected]>
Review fixes pushed (cbf0252, includes the #8606 fixes via merge, fast-forward):
Validation (real): operand devices, bf16/int64 dtypes and contiguity, 128-element norm weights, q_out shape (m, 2048), index_q_out rows/columns, slot/position extents are asserted before the raw-pointer launch.
Device handling (real): counters, compile and launch run under activation.device with its stream; the handle is keyed per device.
Counter-set limit (not changed): the 512 sets are indexed by capture id as in the source kernel's design; ATOM captures a handful of graphs per process, so the limit is documented rather than made graph-lifetime-aware here (that needs graph-destruction hooks HIP does not expose cheaply).
Test strength (real): both implementations now start from the same nonzero pages; the test asserts nothing is written outside the inserted tokens, >97% of the reference's touched bytes are touched, and <3% of those differ.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The cooperative kernel writes rows to incorrect cache slots for accepted gapped mappings, while validation gaps permit unsupported inputs and test thresholds can miss localized corruption.
Reject unsupported GPU targets before kernel launch
aiter/ops/flydsl/kernels/qkv_chain.py:128
A shape-valid gfx942 call passes this entry point's checks and reaches a kernel containing gfx950-only scaled MFMA and FP4 conversion instructions. Reject unsupported targets with get_gfx_runtime() before compilation or launch, as the public NVFP4 wrapper does.
Validate scale dtypes, buffer layout, and cache alignment
aiter/ops/flydsl/kernels/qkv_chain.py:193
A bf16 [1] scale passes these checks although the kernel reads four bytes as FP32, and float32 caches pass although their element strides are interpreted as byte strides. GEMM code dtypes and scale-buffer contiguity are also unchecked, allowing raw loads to interpret or address the wrong bytes. Validate FP32 scalar scales, contiguous E4M3/E8M0 byte buffers, and uint8 caches with aligned, non-overlapping pages before launch.
Use elementwise allclose checks for Q and index-Q
op_tests/test_flydsl_qkv_chain.py:162
The batch-wide max/mean thresholds can hide localized corruption; for example, a missing representative index-Q row at m=40 contributes only about 2.5% mean error and can pass the 5% bound. Compare FP32 Q and index-Q with checkAllclose, use justified elementwise tolerances, and assert that its returned mismatch ratio is zero, as required by .claude/skills/aiter-op-test/SKILL.md:289-304. Keep separate preservation checks for untouched page bits.
…_front + deferred fused epilogue in fused_qknorm_idxrqknorm
The MXFP8 QKV projection of a decode layer is one interface (gemm_a8w8_qkv_front); a tuned row
(a8w8_mxfp8_qkv_front_tuned_gemm.csv, kernelId qkvfront) picks plain / one-launch chain (17-64 rows) / split-3 chain
(65-128 rows). A fused tier only quantizes in the projection and runs GEMM + norm + RoPE + NVFP4 insert inside the
fused_qknorm_idxrqknorm call on the same tensor. Whole-front tuner: op_tests/tune_gemm_a8w8_qkv_front.py.
Co-Authored-By: Claude <[email protected]>
Status of the bot review summaries (Copilot reviews 6044881774, 6046182976), head bb6f2be (draft):
Inline items on output extents, operand device, written-region checks, test entry point, footprint masks: fixed in 8ee4607 / bb6f2be, see the thread replies.
4684532876 (counter sets never reclaimed) and 4685584309 (gapped slot octets): acknowledged, tracked, decision pending.
6046182976 "previously missed" items, not addressed yet: gfx950 target check before launch in qkv_chain.py, scale dtype / buffer-layout / cache-alignment validation, and elementwise checkAllclose for Q / index-Q in the test. Acknowledged, tracked; no fix pushed.
aiter-bot comment ("DRAFT - evaluation paused"): the bot does not evaluate drafts; it will re-evaluate on its own when the PR is marked ready. Nothing further to answer there.
Rebased onto merged #8472 (f70ac7f90) via a merge of origin/main. The one expected conflict in aiter/ops/fused_qknorm_idxrqknorm.py was resolved per this PR's documented resolution: #8472's version of the file plus this PR's qkv-front hook, with the deferred-front block (_take_deferred_front / _run_deferred_front) running before #8472's _nvfp4_raw_front call so the raw front never reads an uncomputed qkv. All of #8472's int64-slot / output-align guards and reworded NVFP4 page comments are preserved; no PR code was dropped. Static checks clean: py_compile, ast.parse, ruff check, black --check all pass. GPU bit-exact re-verification of the fused op is pending a free gfx950 node. Flipped to ready for review.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical slot-index truncation and missing scale and cache-layout validation can corrupt cache data, produce incorrect NVFP4 output, and permit out-of-bounds writes.
…ing uint8 KV pages
Harden the operand checks the raw-pointer launch depends on (Copilot review,
PR ROCm#8607):
- k_scale / v_scale: the kernels read the scalar via _gptr(..., T.f32, 4), so
require float32 with numel() >= 1; a 1-element bf16 scalar previously passed
but would be a 2-byte read reinterpreted as f32.
- kv_cache / index_cache: require uint8 and stride(0) >= full page footprint
(2*128*72 / 128*72). The kernels index pages by slot>>7, so an expanded or
overlapping page layout (e.g. stride(0)==0) would let distinct slots alias the
same page. dtype uint8 is now also enforced.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Critical issues spanning row-stride consistency, packed-scale validation, and deferral guarantees require human assessment of correctness across execution paths.
…chain.py (remove standalone file)
All chain and gemm_a8w8_qkv_front correctness cases are retained verbatim in the
single file; no coverage change (7 test functions / 257 parametrized cases before
and after). Shared `needs_gfx950` mark and `NB` constant deduplicated; the
standalone file is removed.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Consolidated the two op-test files into the single op_tests/test_flydsl_qkv_chain.py: all chain + gemm_a8w8_qkv_front cases retained (7 test functions / 257 parametrized cases, unchanged), and the standalone test_gemm_a8w8_qkv_front.py is removed. The unified __main__ still runs under pytest for .github/scripts/aiter_test.sh. ruff/black clean; GPU run pending a free node.
…he row layout (gfx950, gfx1250)
kv_cache_dtype="nvfp4" with byte k_scale / v_scale planes (uint8 or
float8_e4m3fn) writes K (normed, roped) and V straight into the NVFP4 row
layout of MiniMax-M3's sparse pool and of the FlyDSL paged decode: per
(page, kv head) an e2m1 payload [128, 64] and E4M3 scales [128, 8], no
global scale. With it, index_cache_dtype="nvfp4" and the new index_scale
argument write the index key in the same layout and the same pass: payload
[pages, 128, 64], scales [pages, 128, 8], addressed by index_slot_mapping.
ATOM staged these rows in BF16 and quantized them in three more launches
per sparse layer.
- The scale dtype picks the layout. fp32 [1] k_scale / v_scale keep the
page layout of ROCm#7824, still gfx950-only; byte planes select the row
layout, on gfx950 and gfx1250. The wrapper uses this only for its arch
check; the C++ host checks own every other rule.
- The row layout runs the generic kernel at every token count. The prefill
variant and the raw-pointer entry of ROCm#8472 are the page layout's: their
V runs, K scale order and single page stride are that format's, and the
variant is compiled for gfx950 only. The launcher reaches it under
kNvfp4, which the row layout does not set. Neither Python fast path
(the raw front, the deferred QKV front of ROCm#8607) takes a call with
index_scale, so a page-layout call that passes it is refused (by the
C++ checks, or by the deferred front itself) instead of having it
dropped.
- With the row-layout K/V the index cache is "auto", fp8 or NVFP4 rows
(index_scale). An mxfp4 or page-layout nvfp4 index cache is refused
(each would be its own set of kernels).
- scale = e4m3(amax / 6) (RNE, saturating at 448), codes = e2m1(x * (1 /
scale)) half to even, sign included, in IEEE arithmetic: the rule of
ATOM's Triton NVFP4 stores (kv_nvfp4_store, index_fp4_store), so the
bytes match them on finite rows. The scale byte and the magnitudes come
from nvQuantLane with a unit global scale (the page layout's quantizer,
on gfx950 its hardware converts): amax * float32(1/6) rounds to the e4m3
byte of amax / 6 for every bf16 and fp16 amax. The sign is the row
layout's own: none for a NaN, a zero or any element of a zero-scale
group, read from x's bits because this file is built with fp32
denormals flushed and x * (1 / scale) can be one. The store is
storeNvfp4IndexRow with a kRows flag.
- Token rows are contiguous inside a (page, head); the base and the page
and head strides of every plane are free, each plane on its own. The
16-bit payload store (nvStoreRowData, which the page layout shares)
assumes no alignment and compiles to the same code as before; the host
refuses a plane in which two (page, head)s share bytes.
- Kernel: template flags kNvRows and kNvIndexRows (default false) and one
trailing NvRows argument: the K and V scale-plane strides, and the index
rows' scale plane and page strides. 16 new kernels. The existing ones
keep their instructions and resources; only the implicit-kernarg offset
moves, by the argument's 56 B. The prefill kernels are unchanged.
op_tests/test_fused_qknorm_nvfp4.py: test_nvfp4_rows checks the K/V and
index rows byte for byte against "auto" + a torch reference of the rule, on
strided fields of one pre-filled pool: also with odd payload bases and odd
page and head strides, with every plane on its own strides and the two
scale planes of different byte dtypes, and in the call shape of the prefill
variant (16 q / 1 kv / 1 index heads, bf16, e4m3 index_q_out). The rows
include zero-scale blocks of either sign, elements whose x * (1 / scale) is
an fp32 denormal, NaN and infinities. test_rows_reject covers the host
refusals, the wrapper's arch gate per scale dtype and the deferred front's
refusal; test_reject gains the page-layout call of the raw front's shape
with index_scale. stress_qkv's largest magnitude is now the dtype's (3e38
does not fit fp16).
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…plain row-major contract (#8607), floor 1
ROCm/aiter#8607 removed the standalone mxfp8_quant_shuffled module and changed the
chain's activation contract: qkv_chain_cooperative_insert / qkv_chain_split_insert now
read the PLAIN quantizer's row-major E4M3 codes [m,K] + 1x32 E8M0 scales [m,K/32]
(no (16,16) relayout). available() therefore returned False on current aiter and the
feature was inert.
- Re-point: new _front_quant(x2) = per_group_quant_hip(x2, quant_dtype=dtypes.fp8,
group_size=32, scale_type=dtypes.fp8_e8m0) -- exactly aiter's own gemm_a8w8_qkv_front
call; replaces mxfp8_quantize_shuffled(x2, code_rows(m)) at both the qkv_front and warm
sites (the (m+15)//16*16 tiling is now internal to aiter). available() checks
aiter.ops.quant instead of the removed module, so it is True on current aiter.
- Lower the engage floor MIN_ROWS 17 -> 1 (keep 64 coop / 128 split ceiling): the
front-chain bench shows the fused path winning 22-28% at M=1-16, the dominant M3.1
decode band.
KEPT ATOM_M3_QKV_CHAIN default-off: the shuffled->row-major activation layout change is
correctness-sensitive and CANNOT be GPU-validated today (the aiter front feature is not
built in any reachable container). Flip to default-on only after a GPU relL2 / op-test
confirms the QKV front output.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
main brings ROCm#8472 (NVFP4 prefill kernel, raw NVFP4 entry, gfx950 lane exchanges and
converts in the generic kernel) and ROCm#8607 (deferred QKV front in the wrapper).
Conflicts, resolved mechanically:
- csrc/include/rocm_ops.hpp: both sides (qkv_partials / check_only arguments of
fused_qknorm_idxrqknorm, main's fused_qknorm_nvfp4_raw binding).
- csrc/kernels/fused_qknorm_idxrqknorm.cu
- includes: the union.
- norm / rope helpers: both sets, each written out in full. main's xorLane, warpSum32,
NormRopeOperands, loadNormWeights, loadRopeOperands and normAndRope (the prefill
kernel uses all but the two loaders) next to this branch's shflXor, warpReduceSum /
warpReduceMax,
NormRopeInputs, loadCosSin, rotateElems, ropeElems and normAndRope. The two
normAndRope differ in the operand type.
- fusedQKNormIdxrQKNormKernel: this branch's body, plus one line: the NVFP4 V store
passes the lane's loaded row, which main's storeNvfp4VToken now takes.
- the prefill kernel, its launcher, fused_qknorm_nvfp4_raw and the NVFP4 store
helpers are main's, untouched.
The host entry, the launcher, the header, the wrapper and the tests merged without
conflict.
At this commit the generic kernel does not yet use main's helpers: off gfx12 its lane
exchanges are ds_bpermute again, and its packed loads still assume 8 B aligned norm
weights and cos/sin, which main's prefill launcher hands to it unaligned. The wrapper's
two new fronts (deferred QKV front, raw NVFP4 front) return before check_only and
qkv_partials are looked at. The following commits fix these.
Device assembly (CPU compile, JIT flags): on gfx1250 1152 of the 1160 generic instances
and reduceQkvPartialsKernel are identical to 0af322d's; the 8 NVFP4 instances take
main's store helpers. The prefill kernel is identical to main's on gfx1250, gfx950 and
gfx942.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…he row layout (gfx950, gfx1250)
kv_cache_dtype="nvfp4" with byte k_scale / v_scale planes (uint8 or
float8_e4m3fn) writes K (normed, roped) and V straight into the NVFP4 row
layout of MiniMax-M3's sparse pool and of the FlyDSL paged decode: per
(page, kv head) an e2m1 payload [128, 64] and E4M3 scales [128, 8], no
global scale. With it, index_cache_dtype="nvfp4" and the new index_scale
argument write the index key in the same layout and the same pass: payload
[pages, 128, 64], scales [pages, 128, 8], addressed by index_slot_mapping.
ATOM staged these rows in BF16 and quantized them in three more launches
per sparse layer.
- The scale dtype picks the layout. fp32 [1] k_scale / v_scale keep the
page layout of ROCm#7824, still gfx950-only; byte planes select the row
layout, on gfx950 and gfx1250. The wrapper uses this only for its arch
check; the C++ host checks own every other rule.
- The row layout runs the generic kernel at every token count. The prefill
variant and the raw-pointer entry of ROCm#8472 are the page layout's: their
V runs, K scale order and single page stride are that format's, and the
variant is compiled for gfx950 only. The launcher reaches it under
kNvfp4, which the row layout does not set. Neither Python fast path
(the raw front, the deferred QKV front of ROCm#8607) takes a call with
index_scale, so a page-layout call that passes it is refused (by the
C++ checks, or by the deferred front itself) instead of having it
dropped.
- With the row-layout K/V the index cache is "auto", fp8 or NVFP4 rows
(index_scale). An mxfp4 or page-layout nvfp4 index cache is refused
(each would be its own set of kernels).
- scale = e4m3(amax / 6) (RNE, saturating at 448), codes = e2m1(x * (1 /
scale)) half to even, sign included, in IEEE arithmetic: the rule of
ATOM's Triton NVFP4 stores (kv_nvfp4_store, index_fp4_store), so the
bytes match them on finite rows. The scale byte and the magnitudes come
from nvQuantLane with a unit global scale (the page layout's quantizer,
on gfx950 its hardware converts): amax * float32(1/6) rounds to the e4m3
byte of amax / 6 for every bf16 and fp16 amax. The sign is the row
layout's own: none for a NaN, a zero or any element of a zero-scale
group, read from x's bits because this file is built with fp32
denormals flushed and x * (1 / scale) can be one. The store is
storeNvfp4IndexRow with a kRows flag.
- Token rows are contiguous inside a (page, head); the base and the page
and head strides of every plane are free, each plane on its own. The
16-bit payload store (nvStoreRowData, which the page layout shares)
assumes no alignment and compiles to the same code as before; the host
refuses a plane in which two (page, head)s share bytes.
- Kernel: template flags kNvRows and kNvIndexRows (default false) and one
trailing NvRows argument: the K and V scale-plane strides, and the index
rows' scale plane and page strides. 16 new kernels. The existing ones
keep their instructions and resources; only the implicit-kernarg offset
moves, by the argument's 56 B. The prefill kernels are unchanged.
op_tests/test_fused_qknorm_nvfp4.py: test_nvfp4_rows checks the K/V and
index rows byte for byte against "auto" + a torch reference of the rule, on
strided fields of one pre-filled pool: also with odd payload bases and odd
page and head strides, with every plane on its own strides and the two
scale planes of different byte dtypes, and in the call shape of the prefill
variant (16 q / 1 kv / 1 index heads, bf16, e4m3 index_q_out). The rows
include zero-scale blocks of either sign, elements whose x * (1 / scale) is
an fp32 denormal, NaN and infinities. test_rows_reject covers the host
refusals, the wrapper's arch gate per scale dtype and the deferred front's
refusal; test_reject gains the page-layout call of the raw front's shape
with index_scale. stress_qkv's largest magnitude is now the dtype's (3e38
does not fit fp16).
Co-Authored-By: Claude Fable 5.2 <[email protected]>
zhuyuhua-v
pushed a commit
to ROCm/ATOM
that referenced
this pull request
Dec 3, 2026
…ed decode, default-on): fused qkv GEMM + q/k/index RMSNorm + partial RoPE + NVFP4 insert via aiter qkv_chain_insert (#3810)
* [M3] decode: 17-64 row QKV front chain, quantize in the linear + one-launch GEMM/norm/RoPE/insert in the attention op (ATOM_M3_QKV_CHAIN, default off)
For 17-64 row pure-decode steps (TP4, NVFP4 K/V and index caches) a sparse layer's qkv_proj only runs the MXFP8 activation
quantizer and the attention op's rope_cache runs aiter's one-launch QKV GEMM + q/k/index RMSNorm + RoPE + NVFP4 insert
(qkv_chain_cooperative_insert) on the parked codes. Decided at run time inside two custom ops; other rows keep today's path.
Needs the paired aiter PRs (feature-detected, a no-op without them).
Co-Authored-By: Claude <[email protected]>
* [M3] qkv chain: review fixes (token-graph, preshuffle, eligibility, weight-cache key, per-thread hand-off) + black
- take(): never inside a token graph (TR_HYBRID decode replays the captured quantizer without the Python hand-off)
- chain only with a preshuffled weight (qkv_front gate + load-time check, else chain off for the layer)
- eligibility: native 1x32 MXFP8 qkv weights only (linear_ok), forward keys on _qkv_chain_scale existing
- ATOM_M3_QKV_CHAIN added to the weight-cache key
- hand-off slot is thread-local (TBO decode micro-batches)
- black formatting of the PR files
Co-Authored-By: Claude <[email protected]>
* [M3] decode: QKV front chain window 17-64 -> 17-128 rows (split-3 GEMM + reduce-insert), feature-detected
With an aiter that has qkv_chain_insert / code_rows the chain serves 65-128 rows through the split chain; the quantizer pads to
code_rows(m); warm-up covers the three 65-128 row configs. Without it the window stays 17-64. ATOM_M3_QKV_CHAIN still gates it.
Co-Authored-By: Claude <[email protected]>
* [M3] qkv chain: one-shot 'chain active' log (layer census, row window, aiter features, per-reason decision tally over the first 1000 python-side calls)
Counters live only where Python runs (warm-up, eager, graph capture); graph replay is untouched.
Co-Authored-By: Claude <[email protected]>
* test: the census log test pins the stage-1 window
* [M3] qkv chain: review fixes round 2 (import before the preshuffle branch, gfx950 gate, refuse TR_HYBRID record/replay via ForwardContext.tr_graph, ruff BLE001/S110)
Co-Authored-By: Claude <[email protected]>
* MiniMax-M3 QKV front chain: re-point the activation quantizer to the plain row-major contract (#8607), floor 1
ROCm/aiter#8607 removed the standalone mxfp8_quant_shuffled module and changed the
chain's activation contract: qkv_chain_cooperative_insert / qkv_chain_split_insert now
read the PLAIN quantizer's row-major E4M3 codes [m,K] + 1x32 E8M0 scales [m,K/32]
(no (16,16) relayout). available() therefore returned False on current aiter and the
feature was inert.
- Re-point: new _front_quant(x2) = per_group_quant_hip(x2, quant_dtype=dtypes.fp8,
group_size=32, scale_type=dtypes.fp8_e8m0) -- exactly aiter's own gemm_a8w8_qkv_front
call; replaces mxfp8_quantize_shuffled(x2, code_rows(m)) at both the qkv_front and warm
sites (the (m+15)//16*16 tiling is now internal to aiter). available() checks
aiter.ops.quant instead of the removed module, so it is True on current aiter.
- Lower the engage floor MIN_ROWS 17 -> 1 (keep 64 coop / 128 split ceiling): the
front-chain bench shows the fused path winning 22-28% at M=1-16, the dominant M3.1
decode band.
KEPT ATOM_M3_QKV_CHAIN default-off: the shuffled->row-major activation layout change is
correctness-sensitive and CANNOT be GPU-validated today (the aiter front feature is not
built in any reachable container). Flip to default-on only after a GPU relL2 / op-test
confirms the QKV front output.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* MiniMax-M3 QKV chain: default-on (remove ATOM_M3_QKV_CHAIN), fix stale 17-row window text + warm tiers
The QKV front chain is a measured-good decode path, so it ships default-on with
no opt-in flag (feature-detected: aiter has the chain ops and the GPU is gfx950),
matching the project's default-on-no-flag convention.
- Remove the `ATOM_M3_QKV_CHAIN` env var: `enabled()` is now `available() and
_is_gfx950()`; drop it from `envs.py` and from the weight-cache key `_ENV_VARS`
(the weight layout now varies only by stable arch / aiter availability, not a
user toggle); reword the flag-named comments/log lines to "M3 QKV chain".
- The row window was already lowered to 1..128 in code (`MIN_ROWS = 1`,
`SPLIT_MAX_ROWS = 128`); fix the remaining stale "17-64" docstring/comment text
and the row-window tests, which still asserted the old 17-row floor (they were
masked because the aiter import-guard skips the module on a non-GPU runner).
- Warm the 32-code tier again: with the floor at 1 the coop warm set
`(MIN_ROWS, 33, 49)` covered code tiles 16/48/64 and dropped 32 (m=17-32); use
`(MIN_ROWS, 17, 33, 49)` -> 16/32/48/64 so every in-window tile compiles at load.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* M3 QKV chain: arch gate uses live GPU (get_gfx_runtime), fix stale activation-layout docstring
- `_is_gfx950()` now probes `get_gfx_runtime()` instead of `get_gfx()`. aiter's own
guidance: get_gfx_runtime detects the live GPU and is for runtime dispatch /
code-path selection, while get_gfx follows the GPU_ARCHS build arch. Since the
chain is now default-on, this arch guard is the primary gate and must follow the
real device (it also handles the AOT-replay case internally).
- Module docstring: the activation quantizer is `per_group_quant_hip` (row-major
e4m3 codes [m, K] + 1x32 E8M0 scales [m, K/32], no relayout), not the old
(16,16)-tile / AITER-shuffled layout — matches the merged aiter #8607 contract.
- Drop the inaccurate "16-row code tile" wording from the warm() comment (the
merged entries take [m, K] row-major activation, no code tiling).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* M3 QKV chain: gate the qkv_front forward branch on the layer's own _qkv_chain, not just the cached scale
The forward branch selected the deferred-QKV chain path whenever `_qkv_chain_scale`
was present. But the weight cache can hand that attribute to a client whose kv dtype
is not chain-eligible (`_qkv_chain=False`) — the cache key omits kv_cache_dtype, so an
FP8-cache client can reuse an NVFP4 sibling's prepared weight and receive its
`_qkv_chain_scale`. That client would then enter the NVFP4-only chain insert and fail
decode. Gate the branch on `getattr(self, "_qkv_chain", False)` as well, matching the
weight-prep guard that produces the scale (linear.py:1462).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* M3 QKV chain: light up the full 1-128 window — fix split_available probe + per-m coop/split dispatch
The merged aiter #8607 serves 65-128 rows with a real split kernel
(`qkv_chain_split_insert` -> `mxfp8_gemm_decode_splitk`, ROWS=(65,128)), but ATOM's
`split_available()` probed a `code_rows` symbol that #8607 never exported, so it was
always False and the 65-128 path was dead (window capped at 64).
- `split_available()` now probes the real entry `qkv_chain_split_insert` (and drops the
vestigial `code_rows` / (16,16)-tile model: both merged entries take plain row-major
`[m, K]` activation from `per_group_quant_hip`, no tiling).
- Dispatch is now per-m, not per-`split_available()`: `_chain_entry(m)` returns
`qkv_chain_cooperative_insert` for 1-64 and `qkv_chain_split_insert` for 65-128
(each aiter entry raises outside its own row range). Applied in both `run_chain` and
the load-time `warm()` loop (the old code picked the split entry for every m, which
would have raised for the 1-64 warm rows).
- Window is now the full 1-128 default-on (coop 1-64, split 65-128); `max_rows()` = 128
when the split entry is present.
NOTE: the 65-128 split path has not yet had an ATOM-level GPU numeric run (the aiter
kernel is aiter-CI-tested; the ATOM integration for 65-128 is not yet exercised e2e).
A one-time relL2/op-test of the 65-128 path should run before/at merge.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* [M3] QKV front chain: M3-owned path, no aiter probing, aiter's dispatch, per-step decision
Addresses the review of de32196:
- import aiter.ops.flydsl.kernels.qkv_chain directly; drop available() /
split_available() / aiter_features() / _is_gfx950() (NVFP4 caches are
already gfx950-only in minimax_m3/config.py)
- gate on aiter's chain_supported(m) and call qkv_chain_insert; drop
COOP_MAX_ROWS / SPLIT_MAX_ROWS / _chain_entry
- LinearBase untouched: MiniMaxM3SparseAttention.forward calls the M3 op
minimax_m3_qkv_front over its own qkv weight; codes are parked on the
layer's own attention impl (one slot per TBO micro-batch), no thread-local
- chain-scale prep + warm-up in MiniMaxM3SparseAttention.post_load, run by
both load paths (end of load_model and a weight-cache hit) via
run_post_load_hooks
- warm every row count qkv_chain_insert serves (1-128, all split tiers incl.
121-128), once per device
- the step decision is MiniMaxM3SparseMetadata.qkv_chain (decode, set at
build); per call only tr_graph and chain_supported(m); drop the census log
- CPU-lane tests via aiter_stub over the real wiring
Co-Authored-By: Claude <[email protected]>
* test: M3 QKV chain rope_cache consumes the codes of its own micro-batch id (1 as well as 0)
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: post_load decides qkv_chain afresh on every load (a weight-cache hit restores the exporter's flag)
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: run post-load hooks in the serving process, not inside load_weights
The weight-cache daemon loads through load_weights; a hook run there (the
chain's warm-up: aiter's counter pool, the warmed-device set) would be
exported to every client as a process change. ModelRunner runs the hooks
after a checkpoint load (model and drafter), the client after a cache hit.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: pin where post_load hooks run; document the fused insert's octet slot contract
- tests/test_weight_cache.py: the daemon's _DaemonLoad (through the real
load_weights -> load_model) runs no post_load; a checkpoint load through
ModelRunner._build_and_load_model / _build_and_load_drafter runs each
hook exactly once; a cache hit (load_from_cache / load_drafter_from_cache)
runs each hook exactly once.
- rope_cache_chain: state the 8-slot octet contract of aiter's fused insert
(rows sharing an octet are written as one consecutive run), narrower than
fused_qknorm_idxrqknorm's.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: eligibility requires the qkv weight to be aiter's chain shape (N x K)
A layer with the TP4 head layout and NVFP4 caches but another hidden size
(e.g. 8192) passed linear_ok/layer_ok and then failed in warm() (aiter's
qkv_chain_insert validates weight == (N, K)). linear_ok now compares the
weight shape against aiter's exported N, K (aiter has no shape predicate);
such a layer keeps its linear.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: a step that does not take the chain pays nothing per layer; test the drafter-warmup flag; aiter's ROT
- MiniMaxM3Model decides once per step (_qkv_chain_step): eagerly, the step's
sparse-metadata flag and aiter's chain_supported(rows); while compiling,
always (the op decides at run time). The decision is handed down
(decoder layer -> attention); a step that cannot take the chain calls
qkv_proj directly, with no op, config lookup or import.
- qkv_chain_step (sparse_attn.py, no FlyDSL import) reads the per-step flag
before anything else; takes_chain = qkv_chain_step() and chain_supported(m).
- post_load binds takes_chain / quant_activation on the layer: no import on
the per-layer path; MiniMaxM3Model.post_load binds the row window only when
a layer is eligible.
- layer_ok uses aiter's ROT instead of 64.
- CPU-lane tests: the per-step decision, the model handing one decision to
every layer, the decoder handing it to attention, the row-window binding,
and prepare_mtp_decode building qkv_chain=False on a dummy (warmup) step.
Co-Authored-By: Claude <[email protected]>
* test: the drafter-warmup metadata case gives the launch grid a real cdiv on the CPU job
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain scope: eager forward only (eager decode, CUDA-graph captured decode); compiled code holds no chain
The maintainer's option (b) for the cost of non-chain steps:
- MiniMaxM3Model._qkv_chain_step is False while compiling: compiled code
never routes through qkv_front, so a compiled step pays nothing for it.
- The chain-layer qkv front is a plain method again (no custom op, no
static_forward_context entry): only the eager forward reaches it.
- support_torch_compile asks an optional model hook, runs_eager(*args,
**kwargs), once per call and runs the eager forward when it is True.
MiniMaxM3Model.runs_eager is True for a CUDA-graph capture (in_hipgraph)
of a decode step the chain takes, so the captured decode graph records
the chain; every other compiled step runs the compiled code.
- CPU-lane tests: never in compiled code, the capture hook's cases, the
wrapper running the eager forward only where the model asks, routing
through qkv_front.
- docs: compilation guide (the hook), model ops guide (the scope).
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: SGLang's sparse forward takes the decoder's qkv_chain; bind the capture hook only to an enabled chain layer
- atom/plugin/sglang/models/minimax_m3.py: _sparse_forward_native_for_sglang
accepts (and ignores) the qkv_chain the decoder layer passes on every
step; it raised TypeError for every M3 sparse model under SGLang.
- run_post_load_hooks runs children before their parent, so
MiniMaxM3Model.post_load binds the row window only when a layer's own
post_load enabled the chain: an eligible layer whose weight is not
preshuffled no longer makes decode captures run the eager forward.
- CPU-lane tests for both and for the hook order.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: bind each sparse layer's qkv route at post_load; main's call signatures
MiniMaxM3Model, MiniMaxM3DecoderLayer, MiniMaxM3Attention and the SGLang
sparse-forward override keep main's signatures: no per-step qkv_chain
keyword is threaded through the layer calls. MiniMaxM3SparseAttention.forward
calls self.project_qkv, a plain attribute bound to the qkv linear's __call__
at build and by post_load, or to qkv_front on a layer post_load enables the
chain on. qkv_front reads torch.compiler.is_compiling() and the step flag
itself (takes_chain), so compiled code traces the qkv linear only; its
fallback calls the linear through a bound attribute too. The model forward
no longer reads the step flag; runs_eager (captured decode) reads it once.
CPU-lane tests pin the binding (init, post_load reset/enable, forward route,
compiling / pre-quantized fallback, no kwarg on any layer call, SGLang
signature); 13 mutants of the binding each fail a test.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: GPU test of repeated rollout graph release / recapture
Drives MemoryManagerMixin's own release_cudagraphs ->
_recapture_cudagraphs_if_needed 50 times on decode graphs (default capture
sizes up to 128 rows) that run aiter's qkv_chain_insert, and checks that the
runner never falls back to enforce_eager and that a replay after the last wake
equals the eager call at 1/8/64/128 rows. Before ROCm/aiter#9074 aiter never
returned a destroyed graph's counter set, so the 42nd wake's recapture failed
("more than 512 counter sets") and the runner went eager for good; ATOM
itself manages no counters. GPU only (gfx950); skips on the CPU job.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: recapture test captures as capture_cudagraph does; warm docstring
ROCm/aiter#9074 now keeps the chain's counters as one set per (device, stream),
shared by eager calls and captures on that stream (the split-K GEMM semaphore
pattern). The GPU recapture test now captures the way ModelRunner does under
graph_capture(): a new stream per pass, and per bucket an eager warmup forward
on it, then the recording on it. warm()'s docstring no longer cites the old
"first call inside capture raises" counter-pool rule; warm-up still compiles
every row count before serving.
Co-Authored-By: Claude <[email protected]>
* [M3] QKV chain: a weight-discarding sleep frees the chain's weight scale
The chain's shuffled weight scale is GPU memory outside the parameters
(about 0.47 MiB per chain layer), so it stayed allocated through a rollout
sleep that discards the weights. MiniMaxM3SparseAttention and
MiniMaxM3Model now define release_weight_memory / resume_weight_memory
(the MemoryManagerMixin contract): the release drops the scale and binds
the qkv linear back, and the model unbinds its chain row window. The scale
is derived from the weights, so only a load (post_load) enables the chain
again. CPU tests; 4/4 mutants of the release hooks fail them.
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
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.
At a glance
gemm_a8w8_qkv_front, for the MiniMax-M3.1 TP4 decode QKV front (hidden 6144 -> 2560 columns): MXFP8 QKV GEMM, q/k/index RMSNorm, partial RoPE and NVFP4 K/V/index-K page inserts. One launch for 1-64 rows, two (split-K GEMM + reduce/insert) for 65-128 rows.fused_qknorm_idxrqknorm) with one or two.decode_bench --sim1on the earlier 17-64 build: -0.24 to -0.69 ms per step inside the window; combined-stack c32 runs did not isolate it).aiter/ops/fused_qknorm_idxrqknorm.py; one-file conflict). ATOM wiring: [M3] decode: 17-64 row QKV front chain (quantize in the linear + one-launch GEMM/norm/RoPE/insert), ATOM_M3_QKV_CHAIN default off ATOM#3809 / Port/aakbarza/flydsl blockmoe fusion #3810 (ATOM_M3_QKV_CHAIN, default off), to become one thin PR.Summary
One op for the MiniMax-M3.1 TP4 decode QKV front (hidden 6144 -> 2560 columns = q 2048 | k 128 | v 128 | index-q 128 | index-k 128): MXFP8 QKV GEMM, q/k/index-q/index-k RMSNorm, partial RoPE and the NVFP4 K/V/index-K page inserts. It replaces the three launches the public decode path runs per sparse layer (activation quantize, QKV GEMM,
fused_qknorm_idxrqknorm). The tier is chosen by the row count insidegemm_a8w8_qkv_front; there is no tuned table, tuner script or config family (a fused chain, not a plain GEMM), and the split-K factorksis a kernel parameter (default 3, measured best; 1/2/3/4/6 are bit-checked).qkv_reduce_insertActivations are plain row-major (no pre-shuffled layout, no extra quantizer). The NVFP4 insert half is the existing
fused_qknorm_idxrqknormHIP op for the unfused path; the chain kernels carry their own fused epilogue and share 25 device helpers (qkv_front_common.py, moved byte-for-byte from the closed FlyDSL insert of #8576). Technique source: amd-kernelsattention/mxfp8_qkv_norm_rope_nvfp4_insert_n2560_k6144_rot64_p128and the decode GEMM primitives ofmxfp8_gemm_decode.py(credited in the file headers, no import).This PR folds #8607 (17-64 rows), #8610 (65-128 GEMM) and #8611 (65-128 reduce + insert) into one (both closed); #8606 (shuffled quantizer) and #8576 (FlyDSL insert) are no longer needed and are not in the net diff. ATOM wiring: ROCm/ATOM#3809 / #3810 (
ATOM_M3_QKV_CHAIN, default off), to become one thin PR.Measured gain
Merged-tree rerun (a tree with #8472 merged; MI355X gfx950, one lease, graph replay, ABAB, 8 rotated weight sets, median of 30). Complete front sequence, us per layer. plain =
per_group_quant_hip+gemm_a8w8_blockscale(public tuned table) +fused_qknorm_idxrqknorm(nvfp4, with #8472's insert); fused =gemm_a8w8_qkv_front. Two independent runs each:About 1.6-3.8 us per layer on a tree where #8472 is already merged, roughly 100-230 us per decode step over the 60 sparse layers. Rows 17 and 65 were not in this rerun. The earlier table of this PR was measured against the plain chain before #8472 (its insert was slower, so the plain column was higher): 3.0-4.8 us per layer over rows 1, 8, 16, 17, 32, 64, 65, 96, 128 (-19.5% to -29.0%), roughly 200-290 us per decode step; that earlier range is superseded by the merged-tree numbers above. In-step (
decode_bench --sim1, TP4 rank-0 shard on one GPU, k=7, ctx 100K, median step ms; measured on the earlier 17-64 build, same kernel bodies): -0.24 .. -0.69 ms per step (2-6%) inside the window, 0 outside (noise +-0.35 ms).Not measured / honest limits: no end-to-end serve-level A/B of the chain alone. In the combined stack runs (c32, 900 s) the chain was on (60 layers, window 17..128) but not isolated; one earlier pre-fix arm showed +0.0% on c32 throughput. 71% of the c32 decode steps fall in the window, so the expected e2e effect is a few percent of decode time, not yet shown. Rows 1-8 are served by the mono path in ATOM (
ATOM_MONO_MAX_ROWS=8) and never reach this op.Correctness
op_tests/test_gemm_a8w8_qkv_front.py+op_tests/test_flydsl_qkv_chain.py(gfx950): 193 passed, 64 skipped (ks != 3on the one-launch tier, by design). Rows 1..128 including the tier edges 16/17/64/65/128, decode-shaped scattered slots, skipped slots (slot -1 writes nothing), fused-vs-unfused bitwise equality for ks in 1/2/3/4/6, quantizer guard bytes, CUDA-graph replay with changed inputs equal to eager (epoch counters need no re-arm; they belong to a device and eager stream, or the HIP capture id plus stream).ValueError(notassert; verified underpython -O): head set 16/1/1, rotary 64, N=2560, K=6144,ksin (1,2,3,4,6), buffer extents. Split launches are keyed by device and run on the operand's device and stream.aiter/aot/flydsl/qkv_front.pyregistered inAOT_MODULES(replaysqkv_chain_insertat 128 rows and bisects down);python -m aiter.aot.flydsl.qkv_frontand--checkpass (32 sizes, 0 failed).Review
By-hand pass over the repo review rules (AGENTS.md,
aiter-ops-flydsl.instructions.md): buffer-resource sizes come from the runtime row count or exact constants; arch gate byget_gfx_runtime(); the hook raises when a parked front cannot be consumed (no silent bypass; thedefer_okhand-off contract is in the module docstring); coop and split kernels share one helper module (no divergent copies). Known deviations, stated rather than hidden: (1) the kernels use the legacybuffer_opsaddressed by raw IPC / device pointers like the sibling comm and prefill kernels, because the op's ABI is raw device pointers; (2) about 27 rawllvm/rocdl/inline-asm sites (flag atomics, ballot/mbcnt, DPP, MFMA scale operands) have no stablefxequivalent at the pinned FlyDSL. Size: 3532 added lines in 13 files, one kernel family that cannot be split (user ruling: one PR).Merge order with #8472: both edit
aiter/ops/fused_qknorm_idxrqknorm.py. A scratch merge conflicts in that one file only (mechanical); resolution = #8472's file plus this PR's 124-line hook, and the deferred-front block must run before #8472's_nvfp4_raw_frontcall (otherwise the raw front would read the uncomputedqkv). Land #8472 first, then rebase this PR with that resolution.Status: draft until a c32 end-to-end A/B of the chain is in.
Review-fix update (head
bb6f2be0e)8ee460766(operand validation as exceptions, op-boundary shape / head checks, device-keyed split launches) and91cbef5c6(stale skips and wording) answered the review comments of the first revisions;bb6f2be0edocuments theslot_mappingrun contract in thegemm_a8w8_qkv_front.pymodule docstring: rows sharing an 8-slot octet are packed as one run into consecutive slots starting at the first row's slot; gapped or two-run octets are unsupported; slot -1 is supported; callers that cannot guarantee the contract passdefer_ok=False. There is no runtime check for it (it would need a device sync). The last commit is a docstring change only and was not run on a GPU.Reproduce:
python3 op_tests/test_gemm_a8w8_qkv_front.py,python3 op_tests/test_flydsl_qkv_chain.py.🤖 Generated with Claude Code