Repository navigation
[CK] [FlyDSL] [JIT] gfx942 a8w4 MoE stage1 fp8 kernel - #6247
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
- moe_kernels: register the _g942 stage-1 names (flydsl_moe1_afp8_wfp4_bf16_*_g942*) and route fp8 x fp4 stage 1 on gfx942 to gemm1_a8w4_gfx942 (bf16 sorted intermediate, consumed by the unchanged a16w4 stage 2). - fused_moe: no inter-stage requant for the _g942 stage 1 (a2/a2_scale = None). - gemm1_a8w4_gfx942: x_layout="moe_sort" reads x / scales as produced by fused_dynamic_mxfp8_quant_moe_sort; exponent rule bitwise equal to it. - kimik3_a8w4_tuned_fmoe.csv: 32 gfx942 (cu 304) rows, inter 384/512, M 1..32768 except M=3 (fused_moe pads 3 -> 4); input shapes in kimik3_a8w4_gfx942_untuned_fmoe.csv. - op_tests/test_flydsl_moe_a8w4_gfx942.py: a16w4 vs a8w4 through fused_moe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
checkAllclose(rtol=atol=1e-2) reported err ~0.22 for both a16w4 and a8w4: the MoE output is O(1e3) and the paths and the torch reference round the bf16 intermediate differently (1-3 bf16 ulps, <= 1.2 % of max|ref| on all 8 shapes). atol = 2e-2 * max|ref| gives err 0 for both paths; cos checks unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
At M=1 the separate fused_dynamic_mxfp8_quant_moe_sort launch cost more than the fp8 stage 1 saved, so a8w4 lost to a16w4 (0.96x). The new x_layout="bf16" stage-1 variant reads bf16 x and quantises each K tile to MXFP8 straight into LDS in A8W4_K8_ORDER, bitwise equal to the separate quant: - x of tile kt+1 is loaded before compute_tile(kt), quantised after it; - block amax via maxnum + DPP quad swaps (no NaN-propagating max, no LDS swizzle with a full lgkmcnt wait); - padding rows of the M tile are not quantised (their LDS is zeroed once). Registry: every _g942 name gets a _qi variant (x_layout="bf16"); fused_moe skips the separate x quant for _qi rows and passes bf16 x. CSV: gfx942 M=1,2 rows use the _qi stage 1; inter 384 M=1 uses the a16w4 t16x256x128_atomic stage 2. MI300X, whole MoE vs a16w4 at M=1: 1.05x (inter 512), 1.11-1.16x (inter 384), was 0.96x / 1.00x. Non-_qi kernels compile to the same ISA as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…small_M_SILOTIGER-907 # Conflicts: # aiter/configs/model_configs/kimik3_a8w4_tuned_fmoe.csv
- Enable the gfx942 a8w4 stage 1 on MI325X only (PCI device id 0x74A5, read from sysfs); elsewhere raise NotImplementedError. On MI300X a8w4 is slower than a16w4 at large M and the tuned CSV rows are shared by both cards. The op test skips on other gfx942 parts. - XOR-swizzle the A tile in LDS (as gemm2) only in the _qi kernels, where the in-kernel quant hit LDS bank conflicts; other kernels unchanged. - With that, _qi also wins at M=4, 8: switch those CSV rows to _qi. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- Add 0x74B9 (MI325X VF, SR-IOV guests) to the MI325X allow-list. - The PciChipId comment: chip_info.py's hardcoded 10019 is wrong on ROCm 7.2.4 / 7.13 / 7.14 (PciChipId is 10020), hence sysfs. - Error text: MI300X numbers of this PR (0.81-0.89x at M>=1024). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…small_M_SILOTIGER-907 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…MI325X in test_moe_2stage - aot/flydsl/moe.py: the `_g942` stage-1 kernels are built by gemm1_a8w4_gfx942 (JIT on first use); the AOT stage-1 compile would build the gfx950 mixed-MoE kernel for them and fail (wheel build: 64 failed). - test_moe_2stage.py: tuned-CSV rows are selected by cu_num only, so on MI300X (cu 304) the gfx942 a8w4 rows were picked up and the MI325X-only stage 1 raises; skip them where a8w4_gfx942_supported() is False (test_flydsl_moe_a8w4_gfx942.py covers them on MI325X). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…small_M_SILOTIGER-907 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Did you run the existing skills in aiter? flydsl-kernel-code-cleanup, flydsl-kernel-authoring, aiter-op-test, review-pr and validate-kernel-pr |
|
@fhuizing No. I will do it. |
…IGER-907 # Conflicts: # aiter/fused_moe.py
…x tests - Remove x_layout="a8w4", x_scale="row" and the Triton MXFP8 quantiser from gemm1_a8w4_gfx942 (no production caller or test reached them). The gfx942 ISA is bitwise identical on 5 variants (moe_sort and _qi, k_wave 1/2/4). - _if_then: a local @flyc.jit dispatch instead of a raw scf.IfOp. - test_moe_2stage: always skip _g942 rows; the CSV sweep prepares neither the a8w4 relayout nor the separated gate/up layout they need, so they aborted the run on MI325X. test_flydsl_moe_a8w4_gfx942.py covers them. - test_flydsl_moe_a8w4_gfx942: set AITER_SITUV2_A8W4 to 1 or 0 explicitly and restore the caller's value; add M = 1024 and 4096. The merge with main (previous commit) resolves the fused_moe_2stages conflict with #6165 and rejects prequantized_a1 together with the gfx942 a8w4 stage 1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@fhuizing |
fhuizing
left a comment
There was a problem hiding this comment.
Thanks for the thorough description and the measurements. Below are the items I would like to see addressed before merge. Items 1 and 2 can give wrong output without an error, so I would look at those first. Items 12 and 13 are about the PR description and are written out below; the rest are inline comments. At the end are two design questions, not numbered, which I'd be glad to hear your view on; the second is probably follow-up material.
- Fp8 pre-quantised input is cast to bf16 on the
_qirows - Stage-1 dispatch keys on dtype and arch, not on the
_g942name - The relaid-weight layout cannot be detected
- No CI runner executes the kernel
- The repo tuner cannot regenerate the gfx942 rows
- The PCI-id gate duplicates
chip_info - The AOT prebuild skips the
_g942kernels - Non-stable FlyDSL APIs at the 0.3.4.1 pin
- Hand-bumped
revtag in the kernel name - Compile skeleton duplicated from
gemm1.py - Development vocabulary in code comments
- The PR description no longer matches the code
- The FlyDSL cleanup pass in the description
Item 12: The PR description no longer matches the code (category: documentation)
Two lines of the description look out of date at the current head:
- The kernel file no longer contains a Triton MXFP8 quantiser, only the torch reference
mxfp8_quant_a8w4_gfx942_ref. - For
op_tests/test_moe_2stage.pythe description says the gfx942 a8w4 rows run on MI325X, but theif "_g942" in kernel_name1:skip is unconditional, so they are skipped on every card, MI325X included.
Could you update those?
Item 13: The FlyDSL cleanup pass in the description (category: documentation)
Following up on your reply about running flydsl-kernel-code-cleanup: could the description carry a checkbox saying so? Several of the points in item 8 (buffer_ops, _raw, the raw MFMA call, fx.math.fma) are ones that pass normally rewrites, so a second pass over the final gemm1_a8w4_gfx942.py may be worth it.
Design question: one weight layout for both stage-1 kernels
The relaid W1 is readable only by the a8w4 kernel, which is why the flag cannot fall back to a16w4 and why a layout mismatch gives wrong numbers (item 3). The a16w4 stage 1 applies the MX scale before its MFMA, so as far as I can see it could read the relaid layout too, with the four packed block scales per lane instead of one, as another w_layout next to standard / guinterleave. Did you look at that? If the cost is small, one layout would let MI300X and untuned shapes fall back to a16w4 instead of raising, and would remove the need to keep two copies of W1.
Design question: device in the config key
MI300X and MI325X share the (gfx942, 304) CSV key, which is why the device check is a runtime raise. The key was extended with gfx when gfx950 and gfx1250 collided on 256 CU, and chip_info.get_device_name() already tells gfx942 parts apart. Would a device column (or a per-device CSV) be a better long-term home for this choice, possibly in a follow-up?
…rror The tuner recognised a gfx942 a8w4 row by the arch alone, while the runtime path also requires a8w4_gfx942_supported(), so on an MI300X every `_g942` candidate raised NotImplementedError on its own and nothing said the shape is MI325X-only. The a8w4 branch now checks the gate once and raises with that message before queuing anything. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a16w4 one does With act="silu" the epilogue called gate_up_act with no SiTU parameters, so a finite swiglu_limit was ignored, while the a16w4 stage 1 clamps gate and up with clamp_gate_up before the unclamped SiLU and runtime_swiglu_limit documents that a positive SiLU limit is applied. The silu path now builds the parameters and clamps the same way (+inf without a limit). test_stage1_kernel takes act and limit and checks silu with limit 1.0 against torch: equal with the change, 84 % of the elements outside the tolerance without it. The shipped rows are SiTUv2 and unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_ARCHS get_gfx() follows GPU_ARCHS and takes its last entry, so with GPU_ARCHS="gfx942;gfx950" the test decided it was on gfx950 and skipped everything on a real MI325X, still exiting 0. It now uses get_gfx_runtime(), as the dispatcher does, for the gate and for the gfx column: with that GPU_ARCHS on MI325X the old test ran 0 stage-1 checks, the new one all 14. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-O keeps them The eleven shape checks in compile_gemm1_a8w4_gfx942 were asserts, which python -O removes; with D_INTER not a multiple of TILE_N, for example, the kernel would then floor NUM_N_BLOCKS and leave the last columns of the intermediate unwritten, and the `_g942` branch returns before any upstream tile check. They now raise ValueError through one helper, with the same conditions, messages and order. A test compiles a bad shape in a python -O subprocess: it raises now and passed silently before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1. TUNE_ONLY unset queues no gfx942 a8w4 candidates (
|
…rows (#8211) serve those keys again. The main merge kept both rows for the same 12 keys and the first one, ours, won, so test_moe_mxfp4fp8_gfx942_asm.py failed on MI300X. Measured on MI325X in one process, eager wall clock, A/B/B/A pairs, null control within 0.9%: asm is 20-33% faster on all 12 keys and won every pair. The FlyDSL rows for M = 1..512, where main has no gfx942 row, stay. The untuned CSV drops the same tokens so a re-tune reproduces the tuned CSV, and the op test runs fused_moe only at M served by FlyDSL rows (1..512); the stage-1 kernel checks are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@valar-cop review |
|
@vedenev-amd Since #8211 landed and Description:
Code:
|
|
@vedenev-amd The new |
|
@vedenev-amd Do both new test files need to stay in this PR, |
…e rows still serve, now that #8211 serves M >= 1024. The gate docstring, the NotImplementedError and the op test's skip message cited the 0.81-0.89x slowdown at M >= 1024, where the _g942 stage 1 no longer runs. On MI300X a8w4 is also slower than a16w4 at M = 128-512 (0.92-0.99x at inter 384), which is what the texts now give. The "MI325X only" substring the tests match is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…suggested removing tests that only serve local validation. It held the unit tests of the review-round-3 tuner fixes; they passed at bd616e3 and d9ab86b (10 tests), and the result is posted in the review thread. The op test test_flydsl_moe_a8w4_gfx942.py stays, as the only numeric check of the _g942 stage-1 kernels on the MI300X CI runners. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@Bernard-Liu Thanks. Items 1 and 3 are one commit each, item 2 needed no change; the description is updated to version 10. 1. Description and the gate texts after #8211 (d9ab86b) Code:
Description:
2. Yes. MI325X (gfx942, 304 CU), torch 2.10.0+rocm7.2.4, FlyDSL 0.5.3 (main's pin), a checkout of The same 10 pass at 3. Do both new test files need to stay (36cf238)
|
|
@valar-cop Thanks. The two inline points are covered in my reply to Bernard above: the description is at version 10 (head
|
|
@vedenev-amd all three covered, thanks. the aiter test on |
|
@valar-cop ping |
|
@Bernard-Liu ci on |
Conflict: aiter/fused_moe.py fused_moe_2stages, where main (ROCm#6247) added the gfx942 a8w4 stage-1 parameter lookup and input check at the same spot as this branch's row-strided-input copy. Both kept, this branch's first: a row-strided activation that does not take the fused MXFP4 sort-quant is made dense before main's a8w4 input check and its bf16 `_qi` path read it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Description version 10, 2026-12-01.
Motivation
Kimi-K3 MoE on gfx942 runs on the FlyDSL a16w4 path (bf16 activations × MXFP4 weights). gfx942 has no FP4 MFMA, so stage 1 spends most of its time unpacking FP4 weights to bf16 (~12 VALU per MFMA) and reaches ~45 % of HBM peak. This PR adds an opt-in stage-1 path that takes MXFP8 activations instead ("a8w4"): FP4 → FP8 is exact and cheap, and the fp8 MFMA does twice the K per instruction. Kimi-K3 was trained with this scheme (MXFP4 expert weights, MXFP8 expert activations, QAT).
This PR serves M = 1–512. At M ≥ 1024 the gfx942 keys go to the 1-stage asm kernel of #8211, which is faster there (asm 20–33 % ahead of this PR's former rows on MI325X, eager wall clock, all 12 keys).
The path is enabled on MI325X only. On MI300X (same gfx942 / 304 CU) a8w4 is slower than a16w4 at the M this PR serves (0.92–0.99x at inter 384, M = 128–512), and aiter's tuned-CSV key cannot tell the two cards apart, so the rows tuned for MI325X would also run on MI300X. There the path raises an explicit error and a16w4 stays the default.
Ticket: SILOTIGER-907. Design notes, data and history: https://amd.atlassian.net/wiki/x/4bxBeQ
Technical Details
aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm1_a8w4_gfx942.py(gfx942 only):fused_moeit comes from the existing HIPfused_dynamic_mxfp8_quant_moe_sort, read in its sorted layout;v_permbyte table (exact; −0 → +0 because 0x80 is NaN in FNUZ);s_x · s_wis applied once per MFMA result:acc = fma(mfma, s_x * s_w, acc);k_wave1/2/4), tiles BM 16 / 32 × TILE_N 32/64/128 × TILE_K 128/256;xcd_tile_map,gemm1_gridinmoe_2stage_a16wmix/utils.py; final ISA of every production stage-1 kernel unchanged on gfx942 and gfx950, confirmed by a runtime A/B on MI355X for all 25 gfx950 a16w4 rows);>>,fx.thread_idx/fx.block_idx,.ir_value(), thefx.rocdl.MFMAatom); the output store stays onbuffer_ops(aBufferCopystore changes one instruction), andperm_b32,cvt_pk_fp8_f32,readfirstlanehave no stable wrapper yet;flydsl==0.5.0(main's pin since [FlyDSL] [CI] [Build] Bump FlyDSL pin to v0.5.0 #7600). Its cache key tracks edits to helpers two calls deep, so the source-hash tag that 0.3.4.1 needed is gone;_qikernels). At small M the separate x-quantisation launch cost about what stage 1 saved. The_qivariants take the bf16 x and quantise each K tile to MXFP8 straight into the A LDS slot (same rounding rule, output bitwise equal to the separate-quant path);fused_moethen skips the quant launch. The block amax usesmaxnum+ DPP quad swaps, padding rows of the M tile are not quantised, and the A tile is XOR-swizzled in LDS by row (only in the_qikernels; all other stage-1 kernels compile to the same ISA as before). The CSV uses_qifor M ≤ 8.moe_kernels.py: 128 stage-1 namesflydsl_moe1_afp8_wfp4_bf16_t{M}x{N}x{K}_g942[_bnt0][_kw{n}][_qi]within_dtype="a8w4_gfx942"andx_layoutin their params. One predicate,is_a8w4_gfx942_kernel(name or params), tells a_g942stage 1 apart forfused_moe, the tuner, the AOT replay and the tests._flydsl_moe_stage1_implruns this kernel only forin_dtype="a8w4_gfx942"and takes the x layout from the name. Any other fp8 × fp4 stage-1 name on gfx942 raises, and so does a_g942name off gfx942; the arch is the live device's (chip_info.get_gfx_runtime()).check_a8w4_gfx942_inputs(moe_kernels.py) holds the input checks of a_g942stage 1 (W1 layout tag, pre-quantised x, x dtype of the_qirows);fused_moe_2stagescalls it once.shuffle_{weight,scale}_a8w4_gfx942inaiter/ops/shuffle.py; the MXFP8 shared-exponent rulegfx942_mxfp8_block_exponentinaiter/utility/fp4_utils.py(used by the tuner and the op test); the kernel entry point is exported frommoe_2stage_a16wmix.a8w4_gfx942_supported()): the PCI device id, read throughchip_info._get_pci_chip_id(correct on ROCm 7.x since [Triton/Gluon] [JIT] Identify MI350P, and stop hardcoding the XCD count #5182), must be inchip_info.MI325X_CHIP_IDS(MI325X 0x74A5, MI325X VF 0x74B9); otherwise the stage 1 raisesNotImplementedError("enabled on MI325X only …"). A failed read counts as "not MI325X". In an AOT replay (AITER_AOT_REPLAY=1, no device) the gate passes, so the kernels can be prebuilt.fused_moe.py: for a_g942stage 1 the bf16 intermediate goes straight to the a16w4 stage 2 (no inter-stage requant); for_qirows the separate x quantisation is skipped. A_g942stage 1 requires W1 and W1 scale taggeda8w4_gfx942_layout(see caller contract); any other stage 1 refuses tagged weights.AITER_SITUV2_A8W4=1on gfx942 MI325X (the existing gfx950 a8w4 path is unchanged). Default stays bf16 activations.kimik3_a8w4_tuned_fmoe.csv: 20 gfx942 (cu 304) rows from this PR, inter 384 / 512, M 1, 2, 4, …, 512;_qistage 1 for M ≤ 8 only (the op test checks this, since_qirows refuse pre-quantised x). No M = 3 rows (fused_moepads M = 3 to 4). Input shapes inkimik3_a8w4_gfx942_untuned_fmoe.csv(M ≤ 512, so a re-tune reproduces the CSV). The 12 gfx942 rows for M = 1024–32768 in the same file are [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211's asm 1-stage rows; this PR's rows for those keys were dropped inbd616e3c(asm 20–33 % faster, 8 of 8 A/B pairs on every key, null control ≤ 0.9 %).gemm_moe_tune.py): on gfx942, per_1x32 fp8 × fp4 shapes are tuned over the_g942stage-1 kernels and the a16w4 stage-2 kernels (the tuner otherwise rejects per_1x32 on non-gfx950). Themoe_sortkernels get the time of the separate MXFP8 x-quant launch added, the_qikernels are markedxbf16(they quantise x themselves), as the tuner already does for per_1x128; the gfx950 inter-stage fp8 cast is not added, since stage 2 reads the bf16 intermediate. How candidates are timed and picked is unchanged.aiter/aot/flydsl/moe.py): the replay builds separated gate/up W1 relaid byshuffle_{weight,scale}_a8w4_gfx942for_g942rows, so these kernels are prebuilt in the wheel (gfx942 replay of the 20_g942rows at36cf23846: 216 ok / 0 failed).op_tests/test_moe_2stage.pyskips the_g942rows on every card: its sweep prepares interleaved gate/up a16w4 weights, which these kernels do not read. They are covered byop_tests/test_flydsl_moe_a8w4_gfx942.py.e7b242a88), which brought [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211; the 2026-11-10 mergedf12a2616brought FlyDSL 0.5.0; main now pins FlyDSL 0.5.3._g942stage 1 withTUNE_ONLYunset and fails loudly when the selection leaves it out (18b2925b5);_qioffered to the tuner only up to 8 tokens (391652070); a stage-1 tile over the 64 KiB LDS refused at compile time and kept out of the tuner (807601281);moe_sortstage 1 only with TILE_K 128 / 256 (438583017); a tuner run off MI325X stops with one up-front error (23f25326e);swiglu_limitapplied to the silu stage 1 (b731350ae); the op test gated on the running GPU (3b1f53c8b); stage-1 shape checks raise, sopython -Okeeps them (6d711de8f). After [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211: rows for M ≥ 1024 dropped (bd616e3c), gate texts updated (d9ab86bcf), the tuner unit-test file dropped (review: it ran on no CI job).Caller contract
aiter.ops.shuffle.shuffle_weight_a8w4_gfx942/shuffle_scale_a8w4_gfx942(~2.5 ms per layer, temporary copy of one layer). The relaid weights replace the a16w4 ones (same size, same dtype and shape).a8w4_gfx942_layout = Trueand carriesis_shuffled. Likeis_shuffled, the tag is an attribute of that tensor object: a.view, a copy or annn.Parameterwrap drops it, so a caller that wraps the weights sets it again on the final tensor. The a16w4 and a8w4 layouts mixed up either way raise aValueErrorinstead of giving wrong output. The relayouts take the separated (GGUU) a16w4 preshuffle and raise on a gate/up-interleaved (GUGU) weight or scale, read from thegate_up_interleavetag thatshuffle_weightandshuffle_scaleset.fused_moeraisesNotImplementedError; it does not fall back to a16w4, because the relaid W1 cannot be read by the a16w4 kernel (keeping both layouts would need +112 GiB per GPU for K3 at TP 8). Callers must not set the flag there.a1_scale) is read through the MXFP8 passthrough on themoe_sortrows (M ≥ 16); the_qirows (M ≤ 8) take bf16 / fp16 x only and raise otherwise.a8w4_gfx942_supported(), setAITER_SITUV2_A8W4=1); no further aiter change is needed for that.How the CSV rows were produced, and the final selection
The rows were produced on MI325X with
gemm_moe_tune.py(the tuner change above, then as a local patch) and confirmed with a whole-MoE CUDA-graph benchmark throughfused_moe; tuner and graph rank the stage-1 tiles the same (Spearman 0.97–1.00 over 32 shapes). The M ≤ 8 rows use the_qivariant, chosen by the graph benchmark (the tuner over-states small-M gains, since it omits the separate x-quant launch). Re-tuning with this PR's tuner (MI325X, ROCm 7.2) reproduces the picks except for a few shapes; each candidate was timed as whole MoE in the same way (fused_moe, CUDA graph of 32 routings, interleaved rounds, median; ratio tuner/shipped, < 1 ⇒ tuner faster; A/A control ±0.3 %):The CSV takes the tuner's row wherever the whole-MoE A/B shows a real win beyond the ±0.3 % noise, and keeps the graph-measured (shipped) row where the tuner regresses: tuner rows for M = 1, 2, 8 (both inter); the shipped row kept for M = 4 (both inter) and inter-384 M = 256 and 512. (The inter-384 M = 1024–16384 tuner rows of that round were dropped with the rest of M ≥ 1024, see #8211.) At inter-384 M = 256 the tuner's pick (0.961) is a
_qistage 1, which refuses pre-quantised x, so the shipped moe_sort row stays there (review, 2026-11-20). inter-512 M = 16–512 and inter-384 M = 16…128 were not re-tuned this round and keep their current rows. 12 rows changed in5d7e4e12d(11 remain after the M = 256 revert); all swapped rows are numerically equivalent to the ones they replace (cos ≈ 1e-6). The tuner must run on a ROCm 7.x image; on the ROCm 10.1 images we tried, the torch profiler records no GPU events in the tuner's spawned workers and every candidate times as 0 µs.Test Plan
python3 op_tests/test_flydsl_moe_a8w4_gfx942.py:moe_sort, TILE_K 256,bnt0, BM 32) and all five_qikernels, the_qiones also with full M tiles (2 experts, top 2, 16 tokens) so the in-kernel quant's LDS swizzle and per-row x-scales are exercised beyond row 0. Every element must be withincheckAllclose's default tolerances, and the test checks that doubling one W1 block scale of one column fails that check (W1 is scaled by 1/8 so no output sits at SiTUv2's saturation, where such an error would not show). The same launch captured in a CUDA graph must replay the same output;_qionly at M ≤ 8; both relayouts refuse a GUGU weight and scale; the stage-1 dispatch by name; off MI325X, that thefused_moepath refuses;fused_moe(Kimi-K3 shapes: inter 384 / 512, M 1 / 2 / 16 / 128 / 512, the M this PR's rows serve), witherr == 0asserted and a self-check that one zeroed output row fails; pre-quantised x (refused only at M ≤ 8, elsewhere equal to the bf16-x output); mixed W1 layouts.fused_moe, a16w4 vs a8w4: cold weights (CUDA graph of 32 different routings), interleaved runs, MI325X.kimik3_a8w4_tuned_fmoe.csvfor gfx942.fp8rounds the routed-expert input to MXFP8 bitwise as this kernel's quantiser (vLLM plugin; the kernel equals bf16 MoE on that input), armbasekeeps bf16.Test Result
Correctness (MI325X)
bd616e3ctree (MI325X, 2026-11-30;fused_moepart at M = 1 / 2 / 16 / 128 / 512);err0 for both paths; cos diff vs reference 1.5e-5 (a8w4 vs MXFP8-rounded reference), a8w4 vs bf16 reference 3.2e-3…3.6e-3. Kernel-only check: every element within the default tolerances, cos diff 0 (M = 1), 1.5e-12 (_qi, full tiles), 2.4e-12 … 3.7e-12 (other families); one doubled W1 block scale is caught in every case; CUDA-graph replay identical to the eager launch. A kernel that reads A without the_qiswizzle, or writes a row's x-scale into the neighbouring row, fails the full-tile_qicases (err 0.86–0.93) while still passing M = 1. Pre-quantised x at inter 384, M = 256 now runs (cos diff 5.0e-6 vs bf16 x).moe_sortkernels; the 6_qikernels differ by ≤ 0.25 % of instructions (same MFMAs, waits and loads). The 0.3.4.1 side is head5d7e4e12d, since this branch now needs ≥ 0.5.0. AOT replay of the gfx942 rows: 360 ok / 0 failed then (32 rows); 216 ok / 0 failed for the 20 rows at36cf23846. The 12 rows swapped by the item-5 CSV update are numerically equivalent to the ones they replace (cos ≈ 1e-6), so correctness is unchanged._qivs separate-quant path: 0 mismatches (M = 1, 2, 4, 8).a1_scaleon_qirows (cos diff 0.9998 →ValueError); plain a16w4 W1 with the flag, or relaid W1 without it (cos diff 0.87–0.89 →ValueError); a non-_g942fp8 × fp4 name on gfx942 (→NotImplementedError).MI300X CI (
ci:mi300x, run 46451342414 atbd616e3c): green, 8 / 8 MI300X and 8 / 8 MI35X shards.test_flydsl_moe_a8w4_gfx942.pypassed on MI300X shard 7 (36.5 s): all 12 stage-1 kernels the test lists (the 8 in the CSV among them) against the torch reference, CUDA-graph replay, dispatch by name, the_qirule, GUGU refusal and the off-MI325X refusal; thefused_moepart skips there, as designed.test_moe_mxfp4fp8_gfx942_asm.py(#8211) passed on MI300X shard 2.MI300X (gate check)
_g942row: with the flag,NotImplementedErrorwith the text above in 28 / 28 cases (14 M × inter 512 / 384), nothing ran; without the flag, stage-1 output bitwise equal to the a16w4 baseline in 28 / 28 cases, same kernels selected._g942row and refuses as before; M ≥ 1024 picks [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211's asm row and runs. On the MI300X CI runner (run 46451342414 atbd616e3c) the op test checks the refusal at the stage-1 entry, and [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211's test checks that M = 1024–32768 dispatch to the asm kernel and that it runs throughfused_moewith the flag at M = 1024 and 4096. The 28 cases throughfused_moeand the no-flag a16w4 comparison were not re-run on MI300X after the row drop (no MI300X node here).Speed, MI325X, whole MoE through
fused_moe, cold weights (sorting + x quantisation + stage 1 + stage 2; µs, median; in brackets a16w4 / a8w4 with a 95 % interval over n = 8 interleaved runs, each ratio taken within one run). Node: 8× MI325X, torch 2.11 + ROCm 7.13. These numbers were measured atc3b128ed8, before the item-5 CSV row update; that update swapped 12 rows to faster tuner picks (whole-MoE A/B 3.9–8.0 % faster at the changed M, M = 512 excluded where the shipped row is kept), so a8w4 is now at least as fast as shown.On MI325X a8w4 is faster than a16w4 at every M this PR serves (M ≥ 1024 now goes to #8211's asm kernel). Stage 1 alone (vs the tuned a16w4 row) is 1.21–1.32x faster at M = 1..64.
MI300X, for reference (path disabled there): with the same rows a8w4 / a16w4 is 0.92–0.99x at inter 384, M = 128–512 (and was 0.81–0.89x at M ≥ 1024, which this PR no longer serves). Details: Confluence page, section 4.5.2.
Accuracy, Kimi-K3 GSM8K (1319 questions, 3-shot, greedy)
Paired: 10 questions right only with bf16, 17 only with MXFP8; fp8 − bf16 = +0.53 pt, 95 % CI [−0.24, +1.30] pt, exact McNemar p = 0.25 — no drop. GPQA, MMLU and long context were not run; the path stays opt-in.
PR Self-Review
Reviewed revision
36cf238
Behavior and intent
Adds an opt-in gfx942 MoE stage-1 path ("a8w4") that takes MXFP8 activations instead of bf16. The existing a16w4
path (bf16 × MXFP4) is insufficient on gfx942 because the hardware has no FP4 MFMA, so stage 1 spends most of its
time unpacking FP4 weights to bf16 (~12 VALU per MFMA) and reaches only ~45 % of HBM peak. a8w4 decodes FP4 → FP8
(exact, cheap) and uses the fp8 MFMA (2× the K per instruction); Kimi-K3 was trained with exactly this scheme
(MXFP4 weights, MXFP8 activations, QAT). The path is opt-in (
AITER_SITUV2_A8W4=1) and MI325X-only; with the flagoff nothing changes, and the default stays bf16 activations.
Validation and unverified scope
Validated on MI325X (8× MI325X node, torch 2.11 / ROCm 7.13; tuner and AOT on a ROCm 7.x image — on ROCm 10.1 the
tuner profiler records 0 µs per candidate):
python3 op_tests/test_flydsl_moe_a8w4_gfx942.py— kernel vs torch reference on MXFP8-rounded x (cos diff 0 atM = 1, 3.7e-12 at M = 16, every element within the default tolerances), CUDA-graph replay equals the eager launch, dispatch-by-name, and off-MI325X refusal;
on MI325X a16w4 vs a8w4 through
fused_moe.err0.fused_moe, CUDA graph of 32 routings, interleaved rounds, median): a8w4 faster than a16w4 atevery M this PR serves (1.06–1.20×). The item-5 CSV row selection uses the same A/B (tuner pick vs shipped, 12 rows swapped).
kimik3_a8w4_tuned_fmoe.csvat36cf23846: 216 ok / 0 failed.NotImplementedErrorin 28 / 28 flag cases; without the flag a16w4 isbitwise-equal to the baseline, same kernels selected. Since [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211 the flag cases at M ≥ 1024 run its asm kernel;
M ≤ 512 still refuses (checked on the MI300X CI runner at the stage-1 entry).
no drop.
Unverified: MI325X VF (0x74B9 — no SR-IOV node); inter-512 M = 16–512 and inter-384 M = 16…128 were not re-tuned
this round; GPQA / MMLU / long-context accuracy not run (the path stays
opt-in). The op test ran on the MI300X CI runner with the
ci:mi300xlabel (run 46451342414 atbd616e3c, passed). All 12 listed stage-1 kernels are checked numerically on MI300X CI (kernel-only); the wholefused_moepath runs only on MI325X, which CI does not have.PR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents
unsupported inputs from reaching it? The a8w4 stage 1 runs only when all of these hold: arch gfx942; device MI325X
(PCI id 0x74A5 / 0x74B9 via
chip_info._get_pci_chip_id, checked bya8w4_gfx942_supported()); the opt-in flagAITER_SITUV2_A8W4=1; astage-1 kernel name ending
_g942within_dtype="a8w4_gfx942"; and W1 / W1-scale taggeda8w4_gfx942_layout.The invariants that keep unsupported inputs out all raise instead of silently misbehaving: off-MI325X the gate
raises
NotImplementedError(no a16w4 fallback — the relaid W1 is unreadable by a16w4); a non-_g942fp8 × fp4name on gfx942 raises, and a
_g942name off gfx942 raises; an untagged W1 reaching a_g942stage 1 (or a taggedW1 reaching any other stage 1) raises
ValueError; and the_qirows (M ≤ 8) take bf16 / fp16 x only and raise onfp8 +
a1_scale. Each of these is checked in the op test.Changed op tests
op_tests/test_flydsl_moe_a8w4_gfx942.py(new): covers the gfx942 a8w4 stage-1 kernels directly against the torchreference on MXFP8-rounded x (all 12 CSV kernels,
_qialso on full M tiles), CUDA-graph replay equality,dispatch-by-name, the CSV
_qirule, GUGU refusal by the relayouts, and the off-MI325X refusal; on MI325X alsoa16w4 vs a8w4 through
fused_moewith pre-quantised x and mixed W1 layouts.Not redundant: before this PR no CI ran the kernel at all (review item 4), and the gate is on speed not numerics,
so a direct kernel-vs-reference test on any gfx942 (MI300X runners included) is the only numeric coverage.
op_tests/test_moe_2stage.py: the_g942rows are now skipped on every card. The shared sweep builds interleavedgate/up a16w4 weights, which these kernels do not read (they need separated, relaid W1), so without the skip the
sweep would feed wrong-layout weights to the new kernels. Their coverage lives in the dedicated test above; this
change only prevents a wrong-layout run, it adds no new assertions.
Submission Checklist
flydsl-kernel-code-cleanup,flydsl-kernel-authoring,aiter-op-testandreview-prskills run on the kernel. The FlyDSL API changes of review item 8 are in, and a secondflydsl-kernel-code-cleanuppass over the finalgemm1_a8w4_gfx942.pyfound no residual legacy and needed no change (lint clean).🤖 Generated with Claude Code