Repository navigation
Conversation
cd9fc7f to
0acef7c
Compare
0acef7c to
ff79769
Compare
ff79769 to
ea2cca7
Compare
…m_idxrqknorm on gfx1250 (#3405) Port of #3405 at 310014b, by @lirui927, with the prefill split at 512 tokens (the crossover measured with page 128). Needs ROCm/aiter#8011. On top of the PR, for the stack's deferred split-K QKV: the decode insert passes the partials to fused_qknorm_idxrqknorm when the kernel takes them (aiter_qknorm_takes_partials) and reduces them first otherwise, as before.
ea2cca7 to
e0c7c77
Compare
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…8 layer With an fp8 KV cache the Python op asserted the index norm weights and the index cache even for a layer without index heads (num_index_heads 0, a dense attention layer), where the kernel uses none of them. Only ask for them when the layer has an index branch. Adds a dense fp8 per-token case to the op test. Signed-off-by: lirui927 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
fusedQKNormIdxrQKNormKernel (qk-norm, partial NeoX RoPE and the KV / index-cache write), with the same outputs: - token and slot are wave-uniform on gfx12 (readfirstlane): scalar loads of the per-token tables, scalar branches on the slot kind - every independent load goes out first (row, norm weight, position), the cos/sin loads as soon as the position arrives, the cache slot last - one 64-bit store per lane for 16-bit rows, one 32-bit store for fp8 K / index-cache rows - warp reductions and RoPE partners with DPP / permlanex16 on gfx12, in the original xor pairing order - bf16 rounding with v_cvt_pk_bf16_f32 on gfx1250 (the same bits as hip_bfloat16 for every non-NaN FP32 result) - on gfx1250, launches of 128 or more (token, slot) rows per CU take 4 rows per warp, in every mode but the fp4 caches (gfx950 only); other archs get a trap stub for that instantiation, which the launcher never selects there The restructuring is shared by every arch: gfx942 and gfx950 compile to different (not yet measured) code too. Signed-off-by: lirui927 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
qkv_partials (optional, last argument): the fp32 [splits, >= num_tokens, row] split-K partials of a bf16 qkv whose GEMM left them unreduced (2, 4 or 8 splits), so that the GEMM can skip its reduce kernel. Each lane sums its elements as the gfx1250 split-K reduce kernel (gemm_a8w8_splitk_reduce) does: fp32, split order, one round to nearest even. It writes them back into qkv and goes on from them, so every output is what reduce + qknorm produce. This module flushes f32 denormals and the reduce kernel does not, so a lane whose partials or running sums leave the normal range redoes its sum exactly in double. Supported: bf16 insert mode with every qkv slot processed, no fp4 cache or fp8 q_out (refused on the host). The partials load has its own instances (48, one row per warp); the other instances compile to the same code as without this change. The op test checks every output bitwise against the op on the reduced qkv (a CPU fp32 sum in split order), with edge values (subnormal, overflowing, NaN and tie sums), q to q_out and in place, and the refused calls. Signed-off-by: lirui927 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
e0c7c77 to
46fb3f4
Compare
…heir consumers With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at most max_m; the consumer claims them (aiter.splitk_partials) and reduces them as it reads the output. - LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8 bpreshuffle GEMM through it. Not while a token graph records: its replay would run the consumer, an eager region, without the partials. - MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M (default 64, 0 = off) for the QKV projections whose attention impl claims the partials in rope_cache (not under Ulysses SP, whose head exchange reads qkv first) and for the dense MLP's gate/up. - PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache; SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch runs, no fp4 cache, and an aiter with the argument. Every other path finishes qkv with the standalone reduce first. A dummy run releases them. - swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run time and reduces them in the activation kernel. An aiter without #7449 never defers; one with #7449 but without #8011 defers and reduces in the sparse layers with the standalone kernel, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… decode For a Gemma q/k norm layer with a plain NeoX RoPE and head_dim 128 (the MiniMax-M3 dense layers), PagedAttentionImpl.rope_cache hands a decode batch to aiter fused_qknorm_idxrqknorm on gfx1250 instead of triton_fused_norm_rope_cache: one insert launch writes q and the normed, roped K and V into the SHUFFLE cache, per-token FP8 or bf16. k and v are not written back; the decode backends read only the cache. It needs ROCm/aiter#8011, which lets a layer without index heads insert into an FP8 cache (earlier versions assert index operands there) and brings the faster gfx1250 kernel; ATOM reads that off aiter.FUSED_QKNORM_IDXRQKNORM_SUPPORTS_INDEXLESS_FP8. Without it nothing changes. The op aborts on arguments it refuses, so _takes_aiter_gemma_norm_rope checks what the KV pool does not guarantee. tests/model_ops/test_gemma_qknorm_rope_aiter_gpu.py runs rope_cache against the Triton kernel (q, the dequantized K/V cache; pages of 16 and 128; CUDA graph padding rows) and checks the route each batch takes. Signed-off-by: lirui927 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…efused arguments A call whose mode does not sum the split-K partials in the op's own pass (no insert, the index branch skipped, an fp4 cache, an e4m3 q_out) now reduces them into qkv first with the same sum, so a caller passes the partials of any deferred qkv without restating which modes fuse them. The fused instantiations are unchanged (gfx1250 ISA identical). Refused arguments (head_dim, rotary_dim, qkv / positions / cache layout and dtype) now raise RuntimeError before anything launches instead of aborting the process, so callers need not pre-check them; the test checks the refusals in process. The fp8 arch check counts gfx1250-strict as gfx1250 and also covers fp8 KV and index caches, which opus would store as zeros on gfx11, as it already did an e4m3 q_out. Drop FUSED_QKNORM_IDXRQKNORM_SUPPORTS_INDEXLESS_FP8: it existed only for a caller to probe; callers raise their aiter floor instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Follow-up for ROCm/ATOM#2988 and #3405 (ATOM must not probe aiter or restate its rules), in 8335393:
|
A caller with another path can ask whether the op takes a call instead of restating its limits. The query runs the op itself with check_only: the Python wrapper's checks and every host check of the C++ entry run as for the real call, then it returns before the device guard and any launch. One set of checks serves both the refusal (RuntimeError) and the query (False). The reject harness asks the query for every case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added
|
…easured choice Drop the FUSED_QKNORM_IDXRQKNORM_SUPPORTS_INDEXLESS_FP8 probe, the copy of fused_qknorm_idxrqknorm's argument limits (head_dim, rotary_dim, qkv, positions, cache layout and dtype) and the getattr/hasattr checks on the rotary module: with ROCm/aiter#8011 the op raises on anything it refuses instead of aborting. ATOM keeps only its own choices: the route is opt-in per model (`aiter_gemma_norm_rope`, set by the MiniMax-M3 dense layers it was measured on), on the gfx1250 family (aiter's is_gfx1250_family, so gfx1250-strict counts), into its SHUFFLE cache layout. Needs aiter with #8011. Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (5)
Scope is fine: the perf rework, qkv_partials and fused_qknorm_idxrqknorm_supports belong together. ROCm/ATOM#3405 is waiting on this PR. It uses supports() as its only gate, so the query has to reject exactly what the launch path rejects, and do it quietly.
- Reject a non-fp16/bf16
qkvbefore thecheck_onlyreturn. The only dtype gate isAITER_DISPATCH_FLOATING16_TYPES_rmTorchatfused_qknorm_idxrqknorm.cu:2086, afterif(check_only) return;at:2058. As a result,supports()returns True for an fp32qkvand then the op raises. AddAITER_CHECK(qkv.dtype() == AITER_DTYPE_bf16 || qkv.dtype() == AITER_DTYPE_fp16, ...)with the other checks, plus anarg_rejectcase. - Stop
supports()from turning build or load failures intoFalse.fused_qknorm_idxrqknorm.py:221catches everyRuntimeError, which includes the JIT build failure (raise_build_errorinaiter/jit/core.py) and the pybind ABI-mismatch error. A broken install then looks like "unsupported", and the caller falls back silently on every call. Either load the module outside thetry, or raise a dedicated refusal exception and catch only that. - Keep
check_onlyquiet.check_fail(aiter_hip_common.h) writes[AITER] file:line ...to stderr before it throws, even underAiterThrowGuard. EveryFalsefromsupports()therefore prints a line: ATOM#3405 asks for each head_dim-256 layer on every long prefill. Skip the print when the check is a query, or print only on the abort path. - Raise
RuntimeErrorinstead of bareassertin the fp8-cache branch (fused_qknorm_idxrqknorm.py:171-183). The comment at:130promisesRuntimeError. Underpython -Othese asserts vanish, sosupports()answers True and the C++ entry rejects the call later. - Add a correctness case for the 4-rows-per-warp path.
kRows=4is used only when there are at least128 * CUsrows (.cu:1393-1398). The largest non-fp4 default case is 64 tokens, and--minimax_tp4uses 3, so the new path and its tail rows (min(row_token, num_tokens - 1),.cu:957) never run in the op test. Add a gfx1250-gated default case above the threshold whose row count is not a multiple of 4.
Also note: gfx942/gfx950 now run changed shared code that has not been executed there yet. Please merge only after aiter-test (MI300X / MI35X) has run op_tests/test_fused_qknorm_idxrqknorm.py green; it was still pending at review time. Non-blocking: the kRows=4 instances are built for every arch but trap off gfx1250, which accounts for most of the 680 -> 1160 instance growth and the 23 s -> 63 s JIT build. Nit: the message at .cu:1649 does not mention num_index_heads.
Reviewed at f646b7e.
- A non-fp16/bf16 qkv is refused with the other host checks, so check_only (and fused_qknorm_idxrqknorm_supports) sees it. - Under check_only a refusal raises ValueError (std::invalid_argument from the C++ entry), and supports() catches only that: a JIT build or module load failure raises instead of reading as "not supported". Real calls still raise RuntimeError. - AiterThrowGuard(quiet): a failed check throws without the stderr line; the entry uses it under check_only. Other guards are unchanged. - The Python fp8-cache asserts are dropped: the C++ entry checks the same operands (slot_mapping, V cache, index operands, k/v scales) under the throw guard, so they raise RuntimeError, also under python -O. - Test: gfx1250 cases above 128 rows per CU with a row count that is not a multiple of 4 (the 4-rows-per-warp path and its tail), a float32 qkv refusal, supports() quiet on stderr for every refused case, and a load failure raising through supports(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. New commit 930db88 (one commit on top of 30e2b20). Item by item: 1. gfx1250 in-place small-M slowdown: found and fixed. The cause is the row store, not the load order.
Each other piece, flipped alone in either direction, moved the time by ≤ 0.17 µs, and this PR's version was mostly the faster one. The pieces were the load order with
2. Self-Review / Testing (description only)
3. Squash text The last commit message now carries the corrected squash text, using your wording: "gfx942 / gfx950 build the same 680 one-row instances as main, from the reworked shared body (VGPR median 26 -> 28, occupancy unchanged); the multi-row and fused-partials kernels are gfx1250-only (static_assert elsewhere)". It also now mentions the two 32-bit stores in the one-row non-insert kernel. |
…heir consumers With ROCm/aiter#7449, aiter.gemm_a8w8_bpreshuffle_splitk_deferred leaves the fp32 partials unreduced when the tuned gfx1250 PTPC GEMM splits K and M is at most max_m; the consumer claims them (aiter.splitk_partials) and reduces them as it reads the output. - LinearBase.splitk_consumer_max_m (0 = off) routes the per-token FP8 bpreshuffle GEMM through it. Not while a token graph records: its replay would run the consumer, an eager region, without the partials. - MiniMax-M3 sets it on gfx1250 to ATOM_SPLITK_CONSUMER_REDUCE_MAX_M (default 64, 0 = off) for the QKV projections whose attention impl claims the partials in rope_cache (not under Ulysses SP, whose head exchange reads qkv first) and for the dense MLP's gate/up. - PagedAttentionImpl.rope_cache hands them to triton_fused_norm_rope_cache; SparseMHAPagedAttentionImpl.rope_cache to aiter.fused_qknorm_idxrqknorm (qkv_partials, ROCm/aiter#8011) when that op takes them: the index branch runs, no fp4 cache, and an aiter with the argument. Every other path finishes qkv with the standalone reduce first. A dummy run releases them. - swiglu_oai_split_reducing, an opaque op, claims a gate/up's partials at run time and reduces them in the activation kernel. An aiter without #7449 never defers; one with #7449 but without #8011 defers and reduces in the sparse layers with the standalone kernel, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[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]>
…ly calls, the raw front out of qkv_partials calls main's wrapper now has two fronts that launch and return before the generic entry: a QKV projection parked by gemm_a8w8_qkv_front, and the raw NVFP4 entry. Merged as they were, fused_qknorm_idxrqknorm_supports() (check_only) launched the kernel and consumed a parked projection, and a raw-front call with qkv_partials ran on the unreduced qkv. - A check_only call does not take the parked front (it stays parked) and does not take the raw front. The raw front is not taken with qkv_partials either: the generic entry reduces them. The two tests sit after block_size == 128 in the raw front's chain, so no other call pays for them. - The supports() docstring and the wrapper comment say that the answer and the C++ checks are the generic entry's; a front checks its own operands when it runs. - tests/test_fused_qknorm_fronts.py (no GPU, entries mocked; added to the CI test list in split_tests.sh): which entry takes a plain call, a check_only call, a call with qkv_partials, and both with a parked front. Each of the three gate clauses, deleted, fails a row. - op_tests/test_fused_qknorm_nvfp4.py (gfx950): on the shape that takes the raw front, supports() answers True and leaves sentinel-filled outputs untouched, and a call with qkv_partials on a NaN qkv gives the bytes of the call on the reduced qkv, qkv included. Two comments of main's that this branch makes wrong are corrected: the refusals run in this process, and the arch query no longer breaks a torch.compile(fullgraph=True) trace of the wrapper (checked on CPU with the C++ op mocked; no test in the tree asserts it). Not handled: a parked front together with qkv_partials. One GEMM cannot produce both (the parked projection is gfx950's FlyDSL front, the partials come from a split-K GEMM that has run), and the parked front would ignore the partials. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ed stores on main's helpers After the merge the file had two sets of lane-exchange helpers. One is left: - main's xorLane<M> gets a gfx12 branch (DPP row_xmask for 1/2/4/8, v_permlanex16 for 16), which is the body of this branch's shflXor; shflXor is gone. warpSum32 takes its first step through xorLane<16> off gfx950, warpReduceMax is written on xorLane, and this branch's normAndRope / ropeElems call warpSum32 / xorLane. warpReduceSum has no caller left and is back to main's text. - roundPackElems' gfx1250 branch calls main's pfPackBf16 (the same v_cvt_pk_bf16_f32 conversion) instead of its own copy. - The packed row and cache stores go through memcpy (storePacked): one 64-bit or 32-bit store that claims no alignment for a row or cache that starts at an odd element. Device assembly against the merge commit (CPU compile, JIT flags): - gfx942: all 680 generic instances identical. - gfx1250: 1152 of 1160 generic instances identical. The 8 NVFP4 instances, which the Python op refuses off gfx950, change because main's nvQuantLane calls xorLane. - gfx950: every generic instance changes as intended: the norm sum is main's v_permlane16_swap + DPP sum again (as on main), and the fp8 per-token scale's warpReduceMax takes DPP for xor 8/4/2/1 where main has five ds_bpermute. The latter is new on gfx950 and has not run there. - The prefill kernel is identical to main's on the three archs. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…re main's The second copy of the norm / rope helpers goes: NormRopeInputs, loadCosSin, rotateElems, ropeElems and this branch's normAndRope are deleted, and the kernel carries main's NormRopeOperands per row and calls main's loadNormWeights, loadRopeOperands and normAndRope from its own prologue (row, weight, position, barrier, cos/sin, slot: unchanged). unpackRawElems is main's pfUnpack. Three changes to main's helpers, none of which the prefill kernel sees (its device assembly is identical to main's on gfx1250, gfx950 and gfx942): - loadNormWeights / loadRopeOperands read the lane's 8 bytes with one memcpy each instead of four element loads. Only the generic kernel calls them. No alignment is claimed, which matters because main's prefill launcher sends norm weights and cos/sin caches that are not 8 B aligned to this kernel; this branch's explicit uint2 loads did claim it. The row load is a memcpy too. - normAndRope tests rotary_dim == 64 once per lane instead of once per element (the arithmetic and its order are unchanged). The RoPE partner by DPP is now main's rule: rotary_dim 64 only. This branch's gfx12 cases for rotary_dim 8, 16, 32 and 128 are gone; those take __shfl, as on main. The op test gets a 4-rows-per-warp case with rotary_dim 128 for that path (gfx1250). Device assembly against the previous commit (CPU compile, JIT flags), gfx1250, mean per instance: one-row kernels 871 -> 747 instructions (one rope case instead of five), the same 4 global loads, VGPRs 20 -> 20 median (max 26 -> 28), no scratch, occupancy unchanged; 4-row kernels 1331 -> 1505 instructions, the same 16 global loads, all of them now issued before the first row is processed, VGPRs 50 -> 52 median. Not run on a GPU: this commit changes the measured gfx1250 code and has to be timed against its parent. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Re-ported onto current main. Main now has #8472 and #8607 on this op, and the branch conflicted with them. The history you reviewed is untouched:
What I could check without a GPU (device assembly compiled on CPU with the JIT flags):
What is and is not verified:
Two things behave differently from what you reviewed:
One design point for you: the alternative to one shared body is main's body verbatim off gfx1250 and ours on gfx1250, which makes gfx942 / gfx950 byte-identical to main at the cost of about 450 duplicated lines. I kept the shared body, as reviewed. Say if you prefer the split. |
The op no longer takes the split-K partials of qkv: a caller reduces them and passes qkv, as on main. - The qkv_partials argument is gone from the Python op, the C++ entry and the pybind signature, with its host checks, the fused-partials kernel instances (kPartials), the reduce kernel and the exact-sum helpers that existed for them. - The kernel instances that remain compile to the same device code as before (gfx1250 and gfx950, compared per instance); only the trailing kernel argument is gone. - The wrapper keeps the check_only gates of the two fronts; the raw front's qkv_partials gate goes with the argument. - Tests: the qkv_partials modes, their summary table and helpers are removed (check_rejects runs the edited call itself); the fronts test and the nvfp4 raw-front test keep their check_only rows. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This reverts commit be2f8e2: the split-K partials input stays in this PR. The tree is that of 56ee759. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…here the code object has them The multi-row kernels and the fused split-K partials load are built by the gfx1250 device pass only, but the host took both when get_gpu_arch() said gfx1250, and that helper reports a gfx1250-strict device as gfx1250 under AITER_GFX1250_A0_ALLOW_ASM=1. The strict code object has neither kernel, so such a launch would fail there. One rule now serves both passes (kHasGfx1250Kernels for what is built, deviceHasGfx1250Kernels() for what is launched; the host asks the device for its own arch name). gfx1250-strict runs one row per warp and reduces split-K partials first, like gfx942 / gfx950. Host only: no device code changes. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…t scalar branch Every quantized cache is fp8 next to a 16-bit model dtype, so the packed 32-bit store is the only quantizing branch any kernel instantiates; the per-element fallback is deleted and the condition is a static_assert. Device assembly unchanged on gfx1250, gfx950 and gfx942. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ready covers op_tests/test_fused_qknorm_idxrqknorm.py (2903 -> 2888 lines): - arg_reject: the fp8 gate keeps the combined fp8-cache refusal, the fp8 index_q_out refusal and the two calls that write no fp8 and must be taken; the three rows that existed to fail when one clause is deleted are dropped, as are positions_2d and cache_4d (positions_int32 and cache_dtype reach the same checks' tensors). - qkv_partials_reject: short_rows and unaligned stay (they guard the kernel's loads); 3_splits and fp16_partials are dropped. - qkv_partials at 64 tokens is dropped (1, 17 and 33 tokens stay). The fused and the reduce-first paths are still compared bit for bit with the op on the reduced qkv. tests/test_fused_qknorm_fronts.py (100 -> 84 lines): the two mock tests of the raw NVFP4 front under check_only and with qkv_partials are dropped; op_tests/test_fused_qknorm_nvfp4.py checks both on the device (outputs untouched; the bytes of the reduced qkv). The parked front has no device test, so its two tests stay. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
review-pr scan (ROCm/aiter main, CardROCm/aiter PR #8011 — [HIP] [Perf] fused_qknorm_idxrqknorm: faster on gfx1250, split-K partials as inputSpeeds up the fused qk-norm / rope / cache-insert kernel on gfx1250 (cheaper lane exchanges and stores, and four rows per warp for large launches), lets it take the unreduced split-K partials of Review (advisory):
Scan logNote on The fired rules on the new head (
|
| Finding on the card | On the new head |
|---|---|
| Multi-row and fused-partials launches wider than the built kernels (gfx1250-strict under the A0 asm opt-in) | Fixed by reading: the host asks the device for its own arch name and both passes follow one stated rule (kHasGfx1250Kernels / deviceHasGfx1250Kernels()); strict reduces partials first. Device code identical on gfx1250 (1160 + 4), gfx950 and gfx942 (680 + 4). Not compiled for strict, not run on A0. |
| gfx942 / gfx950 run a changed body with no timing or run at the head | Open: needs CI at the new head (MI300X with ci:mi300x, MI35X) and the fused_kernel_us comparison. |
| Timing script outside the tree | Open: text only. |
One rule changes verdict on the new head: the scan's "shared chip_info helpers are the ISA gate" rule would fire on the added gcnArchName read in the kernel file. It is deliberate: the shared C++ helper get_gpu_arch() is the one that folds gfx1250-strict into gfx1250.
…) in the QKV chain test The mock-only tests/test_fused_qknorm_fronts.py and its line in split_tests.sh go: test_flydsl_qkv_chain.py already parks a real QKV front and has fused_qknorm_idxrqknorm take it, so the capability query is asked there, before the real call, and must leave the front parked. The raw front under check_only is checked on a device in test_fused_qknorm_nvfp4.py. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Status of the open review items at
What ran at this head, on one idle MI455X (gfx1250),
CI at this head (the first runs of the shared body on #8472's helpers off gfx1250; all 8 MI300X and 8 MI35X Standard Tests shards are green):
Still open:
|
What it does
fused_qknorm_idxrqknorm(qk-norm, partial NeoX RoPE and the KV / index-cache write) gets faster on gfx1250 with the same outputs, can take the unreduced split-K partials ofqkv, refuses bad arguments with an exception instead of aborting, and gains a query,fused_qknorm_idxrqknorm_supports. The branch contains main up to 4122ef5 and reuses the helpers #8472 added to this op.readfirstlane), so the per-token tables are read with scalar loads; all independent loads are issued first.v_permlanex16in the original xor pairing order (a gfx12 branch in main'sxorLane<M>); the RoPE partner is a DPP move for rotary_dim 64 only, as on main.v_cvt_pk_bf16_f32(main'spfPackBf16).qkv_partials; a reduce-first call can take them).qkv_partials(new optional argument): the fp32[splits, >= num_tokens, row]split-K partials of a bf16qkv(2, 4 or 8 splits).gemm_a8w8_splitk_reduce) does (fp32, split order, one round to nearest even), writes the reduced row back intoqkvand continues from it, so the GEMM in front ([FlyDSL] [Perf] Let the consumer finish a gfx1250 PTPC split-K GEMM #7449) can skip its reduce launch.q_out. Any other call reduces the partials intoqkvfirst with a small kernel doing the same sum, then runs as on a reducedqkv. A caller passes the partials of any deferredqkvand does not need to know which modes fuse them.static_assertelsewhere), and the host launches them only on a device that loads that code object. gfx942, gfx950 and gfx1250-strict run one row per warp and reduce the partials first;reduceQkvPartialsKernelis built everywhere.qkv/ positions / cache / partials layout, dtype and device) raiseRuntimeErrorbefore anything launches. The C++ entry checks the operands, so the Python fp8-cache asserts are gone, and with them the bug that an index-less layer (num_index_heads=0) with an fp8 KV cache was asked for index operands.fused_qknorm_idxrqknorm_supports(...)takes the op's arguments and returns whether the op takes the call. It runs the op withcheck_only=True: the wrapper's checks and every host check of the C++ entry run as for the real call, then the entry returns before the device guard and any launch. A refusal there is a quietValueError(AiterThrowGuard(/*quiet=*/true), opt-in), so only refusals answerFalse; a JIT build or load failure raises. It answers for the generic entry, leaves a parked QKV front ([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) parked, and does not take the raw NVFP4 front ([HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472). Eager only: undertorch.compilethe C++ checks do not run.q_out/index_q_outonly when the kernel writes them, treats gfx1250-strict as gfx1250, and looks the arch up only for an fp4 or fp8 store (assume_constant_result), so the default path costs what main's does and traces undertorch.compile(fullgraph=True).Benefit
MI455X (gfx1250), one idle GPU, image
rocm/fw-bringup:gfx1250-minimax-m3-20261112, against main 4122ef5, interleaved. Measured at 56ee759, whose device code is the head's (ISA comparison under Testing). MiniMax-M3 TP4 per-rank shapes: 16 q, 1 KV and 1 index head, rotary 64.Kernel time (
run_perftestprofiler time, median of 3 rounds, µs; a script outside the tree):HIP graph, µs per call (median of 5 rounds):
The in-place outputs are bitwise equal to main's in every case above. The op test's
--minimax_benchmark(eager calls, mostly launch overhead) shows 0.97–1.02x of main up to M = 2048 and 1.08–1.25x at M = 8192.qkv_partialshas no baseline on main. In the op test's partials table on MI455X,run_perftestgives about 2.3–2.9 µs without partials and 3.8–4.3 / 5.0–5.9 / 7.9–8.5 µs with 2 / 4 / 8 splits; those inputs carry many edge-value columns, which take the exact (double) path, so these are upper bounds. The reduce launch it replaces costs 1.6–2.6 µs (#7449).Cost, JIT build of the module for one arch from a clean build dir on CPU: gfx1250 62 s (main 28 s), gfx950 35 s (main 30 s), gfx942 36 s.
fusedQKNormIdxrQKNormKernelinstances: gfx1250 1160 (680 one-row, 432 multi-row, 48 that fuseqkv_partials), gfx942 / gfx950 680, as on main; plus one reduce kernel on every arch.Testing
python3 op_tests/test_fused_qknorm_idxrqknorm.pyexits 0: every summary rowpassed;arg_reject,q_fp8_outand theqkv_partials*rows err 0, the eight 1639-token cases included. The fused 2-split partials take 3.8-4.3 µs, as at 56ee759.python3 op_tests/test_fused_qknorm_idxrqknorm.py --minimax_tp4exits 1 inpa_sparse_block_score_decode("requires gfx950 architecture"), a case and an op this PR does not change.python3 op_tests/test_fused_qknorm_nvfp4.pyskips ("tested on gfx950 only");python3 -m pytest -q -rs op_tests/test_flydsl_qkv_chain.py: 1 passed, 256 skipped ("gfx950 only").flush_cache; gfx950 and gfx942 680 + 2 + 2: all identical in body and descriptor.--cuda-host-only -fsyntax-only): no errors. The JIT module builds for gfx1250, gfx950, gfx942 andgfx942;gfx950at 56ee759.op_tests/test_flydsl_qkv_chain.pynow asksfused_qknorm_idxrqknorm_supportsbefore the real call and asserts the parked QKV front stays parked (gfx950 only: it skips on MI455X, so the added assertion has not run on hardware; first run is MI35X CI). The former mock-onlytests/test_fused_qknorm_fronts.py(3 passed at 0e66537) and itssplit_tests.shline are removed.fused_kernel_usat or below main's).Not covered
op_tests/test_flydsl_qkv_chain.py(this PR's added assertion) andop_tests/test_fused_qknorm_nvfp4.pyskip on gfx1250: no hardware run from us, they need MI35X CI. The JIT module build for gfx950 / gfx942 was not repeated at the head.qkv_partialsoff gfx1250 (reduce first) runs only in CI.Dependencies
None to merge. #7449 (GEMM side, no shared files) produces the partials this op consumes. ROCm/ATOM#2988 and ROCm/ATOM#3405 (
fused_qknorm_idxrqknorm_supports) call the op directly once this PR is merged. #8607's parked QKV front is a second, gfx950 / NVFP4-only way to leave the split-K sum to this op;qkv_partialsstays the explicit one for a bf16qkvon gfx1250. #8290 edits the same files; whichever lands second needs a rebase.PR Self-Review
Reviewed revision
8b7ea11
Behavior and intent
permlanex16lane exchanges in the original xor order,v_cvt_pk_bf16_f32, packed stores, 4 rows per warp from 128 rows per CU. Kernel time vs main is 1.28x–1.79x on MiniMax-M3 TP4 shapes.qkv_partials(fp32[splits, >= num_tokens, row], 2 / 4 / 8 splits): summed asgemm_a8w8_splitk_reducedoes, bitwise under denormal flushing through an exact double redo, the reduced row written back intoqkv. Fused on gfx1250 in bf16 insert mode with every qkv slot, no fp4 cache and no fp8q_out; any other call reduces first with a small kernel doing the same sum.RuntimeErrorbefore any launch.fused_qknorm_idxrqknorm_supportsruns the same checks withcheck_only, where a refusal is a quietValueError; build and load failures raise.Validation and unverified scope
scratch_np/isa_host.sh <tree> <arch> <out.s>(hosthipcc --cuda-device-only -S, JIT flags) andisacmp.py, this revision vs cd5d83a, for gfx1250, gfx950, gfx942: every kernel identical in body and descriptor (1160 + 2 + 2, 680 + 2 + 2, 680 + 2 + 2).scratch_np/isa_host.sh <tree> gfx1250 <out> "--cuda-host-only -fsyntax-only": no errors.black --checkandruff check --no-cacheonop_tests/test_flydsl_qkv_chain.pyat the head: clean; its new assertions run on gfx950 only and have not run.python -m black --checkandruff check --no-cacheon the four changed Python files: clean.python3 op_tests/test_fused_qknorm_idxrqknorm.pyexits 0 (every summary rowpassed; theqkv_partialstable has err 0 in every row);python3 op_tests/test_fused_qknorm_idxrqknorm.py --minimax_tp4exits 1 inpa_sparse_block_score_decode("requires gfx950 architecture"), which this PR does not change;python3 op_tests/test_fused_qknorm_nvfp4.pyandpython3 -m pytest -q -rs op_tests/test_flydsl_qkv_chain.pyskip on gfx1250 (1 passed, 256 skipped).aiter.jit.core.build_modulebuilds for gfx1250 (62 s), gfx950 (35 s), gfx942 (36 s),gfx942;gfx950(61 s).op_tests/test_flydsl_qkv_chain.py(the assertion this PR adds) andop_tests/test_fused_qknorm_nvfp4.pyon hardware (both skip on gfx1250; MI35X CI); the JIT module build for gfx950 / gfx942 at this revision; gfx1250-strict (judged from the arch macros only, not compiled, not run on A0); gfx942 / gfx950 on hardware with [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's helpers,qkv_partialsthere, and their timing against current main; the NVFP4 kernels.PR-specific question
The kernel body is shared by all archs; what protects gfx942 / gfx950, which run changed code this PR's author cannot execute?
op_tests/test_fused_qknorm_idxrqknorm.pyat 30e2b20 and it passed; CI at this revision has to pass again, because the body now sits on [HIP] [Perf] fused_qknorm_idxrqknorm: early loads, hardware converts, DPP exchanges, xor-atomic V nibbles and a prefill variant #8472's helpers.Changed op tests
op_tests/test_flydsl_qkv_chain.py(two assertions added to the existing deferred-front insert helper)fused_qknorm_idxrqknorm_supportson a call with a parked QKV front returns True and leaves the front parked; the real call that follows still consumes it.fused_qknorm_idxrqknorm_supportsdoes not exist.op_tests/test_fused_qknorm_idxrqknorm.py(extended, not duplicated)num_index_heads=0); theqkv_partials*modes (sparse and dense layers, page-16 fp8 per-token / bf16 / page-128 caches, 2 / 4 / 8 splits, subnormal and tie sums in every head, overflow / NaN sums in one token), bit for bit against the op on the reducedqkv;qkv_partials_rejectfor the reduce-first modes and the refused partials;arg_reject: each refused argument raises in process, on a faked gfx1100 the two fp8-store calls are refused and the two calls that write no fp8 are taken, and all four are taken on a faked gfx1250-strict,supports()answers quietly and does not hide a load failure; on gfx1250 eight cases above 128 rows per CU, most with a row count that is not a multiple of 4, for the 4-rows-per-warp path and its tail rows.op_tests/test_fused_qknorm_nvfp4.py(refusal harness only; the NVFP4 write cases are unchanged)RuntimeErrorwith their own message before any launch, in this process; the--rejectchild-process entry is removed. On gfx950,supports()on the raw-front shape returns True and leaves the outputs untouched (not run here: no gfx950).