Skip to content

[CK] [FlyDSL] [JIT] gfx942 a8w4 MoE stage1 fp8 kernel - #6247

Merged
vedenev-amd merged 73 commits into
mainfrom
MoE_fp8_small_M_SILOTIGER-907
Dec 2, 2026
Merged

vedenev-amd merged 73 commits into
mainfrom
MoE_fp8_small_M_SILOTIGER-907

Conversation

@vedenev-amd

@vedenev-amd vedenev-amd commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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

  • New FlyDSL stage-1 kernel aiter/ops/flydsl/kernels/moe_2stage_a16wmix/gemm1_a8w4_gfx942.py (gfx942 only):
    • x quantised to MXFP8 (E4M3FNUZ, max 240, one E8M0 scale per 32 values); in fused_moe it comes from the existing HIP fused_dynamic_mxfp8_quant_moe_sort, read in its sorted layout;
    • MXFP4 weights decoded to FP8 with a v_perm byte table (exact; −0 → +0 because 0x80 is NaN in FNUZ);
    • fp8 MFMA 16x16x32 with one MFMA per MX block, so s_x · s_w is applied once per MFMA result: acc = fma(mfma, s_x * s_w, acc);
    • split-K inside the block (k_wave 1/2/4), tiles BM 16 / 32 × TILE_N 32/64/128 × TILE_K 128/256;
    • same sorting / bf16 intermediate contract as the a16w4 stage 1; stage 2 is the existing a16w4 kernel, unchanged;
    • the XCD tile map and the grid size are shared with the a16w4 stage 1 (xcd_tile_map, gemm1_grid in moe_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);
    • written against the stable FlyDSL API where that leaves the ISA unchanged (>>, fx.thread_idx / fx.block_idx, .ir_value(), the fx.rocdl.MFMA atom); the output store stays on buffer_ops (a BufferCopy store changes one instruction), and perm_b32, cvt_pk_fp8_f32, readfirstlane have no stable wrapper yet;
    • built against 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;
    • every buffer descriptor is bounded, the sorted x-scale one included (pad32(sorted rows) × the scale row stride).
  • In-kernel x quantisation for small M (_qi kernels). At small M the separate x-quantisation launch cost about what stage 1 saved. The _qi variants 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_moe then skips the quant launch. The block amax uses maxnum + 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 _qi kernels; all other stage-1 kernels compile to the same ISA as before). The CSV uses _qi for M ≤ 8.
  • moe_kernels.py: 128 stage-1 names flydsl_moe1_afp8_wfp4_bf16_t{M}x{N}x{K}_g942[_bnt0][_kw{n}][_qi] with in_dtype="a8w4_gfx942" and x_layout in their params. One predicate, is_a8w4_gfx942_kernel(name or params), tells a _g942 stage 1 apart for fused_moe, the tuner, the AOT replay and the tests. _flydsl_moe_stage1_impl runs this kernel only for in_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 _g942 name 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 _g942 stage 1 (W1 layout tag, pre-quantised x, x dtype of the _qi rows); fused_moe_2stages calls it once.
  • Host-side helpers are outside the kernel module: shuffle_{weight,scale}_a8w4_gfx942 in aiter/ops/shuffle.py; the MXFP8 shared-exponent rule gfx942_mxfp8_block_exponent in aiter/utility/fp4_utils.py (used by the tuner and the op test); the kernel entry point is exported from moe_2stage_a16wmix.
  • MI325X-only gate (a8w4_gfx942_supported()): the PCI device id, read through chip_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 in chip_info.MI325X_CHIP_IDS (MI325X 0x74A5, MI325X VF 0x74B9); otherwise the stage 1 raises NotImplementedError ("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 _g942 stage 1 the bf16 intermediate goes straight to the a16w4 stage 2 (no inter-stage requant); for _qi rows the separate x quantisation is skipped. A _g942 stage 1 requires W1 and W1 scale tagged a8w4_gfx942_layout (see caller contract); any other stage 1 refuses tagged weights.
  • Opt-in: AITER_SITUV2_A8W4=1 on 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; _qi stage 1 for M ≤ 8 only (the op test checks this, since _qi rows refuse pre-quantised x). No M = 3 rows (fused_moe pads M = 3 to 4). Input shapes in kimik3_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 in bd616e3c (asm 20–33 % faster, 8 of 8 A/B pairs on every key, null control ≤ 0.9 %).
  • Tuner (gemm_moe_tune.py): on gfx942, per_1x32 fp8 × fp4 shapes are tuned over the _g942 stage-1 kernels and the a16w4 stage-2 kernels (the tuner otherwise rejects per_1x32 on non-gfx950). The moe_sort kernels get the time of the separate MXFP8 x-quant launch added, the _qi kernels are marked xbf16 (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.
  • AOT (aiter/aot/flydsl/moe.py): the replay builds separated gate/up W1 relaid by shuffle_{weight,scale}_a8w4_gfx942 for _g942 rows, so these kernels are prebuilt in the wheel (gfx942 replay of the 20 _g942 rows at 36cf23846: 216 ok / 0 failed).
  • op_tests/test_moe_2stage.py skips the _g942 rows on every card: its sweep prepares interleaved gate/up a16w4 weights, which these kernels do not read. They are covered by op_tests/test_flydsl_moe_a8w4_gfx942.py.
  • Merged with main eight times, last on 2026-11-30 (e7b242a88), which brought [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211; the 2026-11-10 merge df12a2616 brought FlyDSL 0.5.0; main now pins FlyDSL 0.5.3.
  • Review round 3 (2026-11-30): the tuner picks the _g942 stage 1 with TUNE_ONLY unset and fails loudly when the selection leaves it out (18b2925b5); _qi offered 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_sort stage 1 only with TILE_K 128 / 256 (438583017); a tuner run off MI325X stops with one up-front error (23f25326e); swiglu_limit applied to the silu stage 1 (b731350ae); the op test gated on the running GPU (3b1f53c8b); stage-1 shape checks raise, so python -O keeps 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

  • W1 / W1-scale must be relaid once at load: a16w4 preshuffle with separated gate/up, then 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).
  • The relayout tags its output a8w4_gfx942_layout = True and carries is_shuffled. Like is_shuffled, the tag is an attribute of that tensor object: a .view, a copy or an nn.Parameter wrap 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 a ValueError instead 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 the gate_up_interleave tag that shuffle_weight and shuffle_scale set.
  • With the flag on a non-MI325X gfx942 card (e.g. MI300X) fused_moe raises NotImplementedError; 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.
  • Pre-quantised x (fp8 + a1_scale) is read through the MXFP8 passthrough on the moe_sort rows (M ≥ 16); the _qi rows (M ≤ 8) take bf16 / fp16 x only and raise otherwise.
  • With the flag, a shape without a CSV row fails (the default heuristic picks gfx950-only kernels); rows exist for every reachable M (M ≥ 1024 through [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211's asm rows).
  • vLLM does not call this path yet: on gfx942 it routes Kimi-K3 MXFP4 MoE to its emulation backend, not to aiter. Using this kernel from vLLM on MI325X needs a separate vLLM PR (relay and tag W1, separated gate/up, check a8w4_gfx942_supported(), set AITER_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 through fused_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 _qi variant, 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 %):

M inter 512 inter 384
1 0.969 0.986
2 0.968 0.952
4 1.006 1.008
8 0.960 0.945
M (inter 384) ratio tuner/shipped
256 0.961
512 1.048 (101 rounds) — tuner ~5 % slower

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 _qi stage 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 in 5d7e4e12d (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:
    • every gfx942 (MI300X CI runners included): the stage-1 kernel alone vs the torch reference on MXFP8-rounded x (model_dim 1536), for all 12 stage-1 kernels in the CSV (the test asserts that every CSV stage-1 kernel was run): every tile family (moe_sort, TILE_K 256, bnt0, BM 32) and all five _qi kernels, the _qi ones 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 within checkAllclose'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;
    • every gfx942: the CSV uses _qi only at M ≤ 8; both relayouts refuse a GUGU weight and scale; the stage-1 dispatch by name; off MI325X, that the fused_moe path refuses;
    • MI325X: a16w4 vs a8w4 through fused_moe (Kimi-K3 shapes: inter 384 / 512, M 1 / 2 / 16 / 128 / 512, the M this PR's rows serve), with err == 0 asserted 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.
  • Kernel vs a16w4 on the same MXFP8-rounded input, all tile / k_wave variants.
  • Whole MoE through fused_moe, a16w4 vs a8w4: cold weights (CUDA graph of 32 different routings), interleaved runs, MI325X.
  • FlyDSL MoE AOT replay of kimik3_a8w4_tuned_fmoe.csv for gfx942.
  • FlyDSL 0.5.0 vs 0.3.4.1: outputs of the 12 stage-1 kernels in the CSV at M = 1 / 16 / 128, and their final ISA.
  • Model level: Kimi-K3 GSM8K A/B on 8× MI325X with vLLM. Arm fp8 rounds the routed-expert input to MXFP8 bitwise as this kernel's quantiser (vLLM plugin; the kernel equals bf16 MoE on that input), arm base keeps bf16.

Test Result

Correctness (MI325X)

  • Op test passes at FlyDSL 0.5.3 (main's pin) on the bd616e3c tree (MI325X, 2026-11-30; fused_moe part at M = 1 / 2 / 16 / 128 / 512); err 0 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 _qi swizzle, or writes a row's x-scale into the neighbouring row, fails the full-tile _qi cases (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).
  • FlyDSL 0.5.0 vs 0.3.4.1: outputs of the 12 CSV stage-1 kernels bitwise identical (36 / 36). Final ISA identical for the 11 moe_sort kernels; the 6 _qi kernels differ by ≤ 0.25 % of instructions (same MFMAs, waits and loads). The 0.3.4.1 side is head 5d7e4e12d, 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 at 36cf23846. 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.
  • Kernel equals a16w4 on the same MXFP8-rounded x: cos diff 0, max abs 7e-9; no NaN.
  • _qi vs separate-quant path: 0 mismatches (M = 1, 2, 4, 8).
  • Wrong inputs now raise instead of giving wrong output (before → after): fp8 x + a1_scale on _qi rows (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-_g942 fp8 × fp4 name on gfx942 (→ NotImplementedError).

MI300X CI (ci:mi300x, run 46451342414 at bd616e3c): green, 8 / 8 MI300X and 8 / 8 MI35X shards. test_flydsl_moe_a8w4_gfx942.py passed 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 _qi rule, GUGU refusal and the off-MI325X refusal; the fused_moe part skips there, as designed. test_moe_mxfp4fp8_gfx942_asm.py (#8211) passed on MI300X shard 2.

MI300X (gate check)

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 at c3b128ed8, 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.

M inter 512: a16w4 µs a8w4 µs inter 384: a16w4 µs a8w4 µs
1 38.2 34.5 (1.106x ± 0.008) 36.8 31.5 (1.168x ± 0.008)
2 53.0 47.6 (1.113x ± 0.005) 47.6 42.0 (1.134x ± 0.003)
4 83.1 69.4 (1.198x ± 0.004) 69.3 59.6 (1.165x ± 0.002)
8 137.9 122.3 (1.129x ± 0.007) 111.2 99.3 (1.120x ± 0.006)
16 219.0 205.2 (1.069x ± 0.005) 174.2 164.6 (1.057x ± 0.003)
32 373.8 345.4 (1.083x ± 0.004) 285.3 263.7 (1.081x ± 0.003)
64 571.5 519.4 (1.100x ± 0.003) 436.8 409.7 (1.067x ± 0.002)
128 765.7 680.2 (1.124x ± 0.002) 576.0 536.6 (1.072x ± 0.003)
256 857.0 760.0 (1.127x ± 0.002) 645.1 596.8 (1.082x ± 0.003)
512 930.7 812.3 (1.145x ± 0.005) 693.7 625.5 (1.105x ± 0.003)

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)

arm (routed-expert input) exact_match strict exact_match flexible
bf16 0.9636 0.9636
MXFP8 E4M3FNUZ (this kernel's numerics) 0.9689 0.9697

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 flag
off 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 at
    M = 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. err 0.
  • Whole-MoE A/B (fused_moe, CUDA graph of 32 routings, interleaved rounds, median): a8w4 faster than a16w4 at
    every 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).
  • FlyDSL MoE AOT replay of the gfx942 rows of kimik3_a8w4_tuned_fmoe.csv at 36cf23846: 216 ok / 0 failed.
  • MI300X gate check (before [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211): NotImplementedError in 28 / 28 flag cases; without the flag a16w4 is
    bitwise-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).
  • Model level, Kimi-K3 GSM8K on 8× MI325X (vLLM): fp8 − bf16 = +0.53 pt, 95 % CI [−0.24, +1.30], McNemar p = 0.25 —
    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:mi300x label (run 46451342414 at bd616e3c, passed). All 12 listed stage-1 kernels are checked numerically on MI300X CI (kernel-only); the whole fused_moe path 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 by a8w4_gfx942_supported()); the opt-in flag AITER_SITUV2_A8W4=1; a
stage-1 kernel name ending _g942 with in_dtype="a8w4_gfx942"; and W1 / W1-scale tagged a8w4_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-_g942 fp8 × fp4
name on gfx942 raises, and a _g942 name off gfx942 raises; an untagged W1 reaching a _g942 stage 1 (or a tagged
W1 reaching any other stage 1) raises ValueError; and the _qi rows (M ≤ 8) take bf16 / fp16 x only and raise on
fp8 + 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 torch
    reference on MXFP8-rounded x (all 12 CSV kernels, _qi also on full M tiles), CUDA-graph replay equality,
    dispatch-by-name, the CSV _qi rule, GUGU refusal by the relayouts, and the off-MI325X refusal; on MI325X also
    a16w4 vs a8w4 through fused_moe with 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 _g942 rows are now skipped on every card. The shared sweep builds interleaved
    gate/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

🤖 Generated with Claude Code

@vedenev-amd
vedenev-amd requested a review from a team October 8, 2026 06:05
@vedenev-amd
vedenev-amd marked this pull request as draft October 8, 2026 06:05
@vedenev-amd vedenev-amd self-assigned this Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6247 --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.

@github-actions github-actions Bot added the FlyDSL label Oct 8, 2026
vedenev-amd and others added 9 commits October 8, 2026 10:29
- 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]>
@vedenev-amd
vedenev-amd marked this pull request as ready for review October 13, 2026 14:07
vedenev-amd and others added 2 commits October 13, 2026 14:52
…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]>
@zufayu
zufayu requested a review from coderfeli October 14, 2026 01:29
@fhuizing
fhuizing marked this pull request as draft October 14, 2026 09:55
@fhuizing

Copy link
Copy Markdown

Did you run the existing skills in aiter? flydsl-kernel-code-cleanup, flydsl-kernel-authoring, aiter-op-test, review-pr and validate-kernel-pr

@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@fhuizing No. I will do it.

vedenev-amd and others added 2 commits October 14, 2026 13:56
…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]>
@zufayu
zufayu removed the request for review from coderfeli October 15, 2026 00:30
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@fhuizing
claude generated:
Done. I ran flydsl-kernel-code-cleanup, flydsl-kernel-authoring, aiter-op-test and review-pr; the fixes are in 29f3ed3 (unused x layouts
removed, @flyc.jit dispatch instead of raw scf.IfOp, test_moe_2stage skips _g942 rows, the op test sets AITER_SITUV2_A8W4 explicitly, M = 1024 and 4096
added).
validate-kernel-pr on MI325X: all executed stages pass (merge with main, correctness, grid M = 3, 17, 333, 8192); the verdict is INCONCLUSIVE only
because the route receipt could not be established. The CI has no MI325X runner, so the kernel is not run in CI.

@fhuizing fhuizing left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. Fp8 pre-quantised input is cast to bf16 on the _qi rows
  2. Stage-1 dispatch keys on dtype and arch, not on the _g942 name
  3. The relaid-weight layout cannot be detected
  4. No CI runner executes the kernel
  5. The repo tuner cannot regenerate the gfx942 rows
  6. The PCI-id gate duplicates chip_info
  7. The AOT prebuild skips the _g942 kernels
  8. Non-stable FlyDSL APIs at the 0.3.4.1 pin
  9. Hand-bumped rev tag in the kernel name
  10. Compile skeleton duplicated from gemm1.py
  11. Development vocabulary in code comments
  12. The PR description no longer matches the code
  13. 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.py the description says the gfx942 a8w4 rows run on MI325X, but the if "_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?

Comment thread aiter/fused_moe.py Resolved
Comment thread aiter/ops/flydsl/moe_kernels.py Resolved
Comment thread op_tests/test_flydsl_moe_a8w4_gfx942.py Resolved
Comment thread aiter/aot/flydsl/moe.py Resolved
vedenev-amd and others added 4 commits November 30, 2026 10:09
…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]>
@vedenev-amd vedenev-amd added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 30, 2026
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

1. TUNE_ONLY unset queues no gfx942 a8w4 candidates (gemm_moe_tune.py:5976)

Thanks, confirmed and fixed in 18b2925. With TUNE_ONLY unset the tuner no longer asks the flydslv2 generator for gfx942 a8w4 rows, so TUNE_ONLY stays empty and the _g942 stage 1 is queued. A TUNE_ONLY or OPUS_ONLY that excludes flydsl now raises a ValueError that names the row, instead of tuning nothing.

The new CPU test op_tests/tuning_tests/test_a8w4_gfx942_tune_sources.py drives tune() for M = 256 / 3584 / 384 / E = 896 / top-k 16 with the generators mocked: with TUNE_ONLY unset, empty or flydsl it queues the _g942 stage-1 tasks, and with TUNE_ONLY=opus or OPUS_ONLY=1 it raises. Without the change it queues 0 tasks with TUNE_ONLY unset, as in your reproduction.

2. The tuner offers _qi at any M (moe_kernels.py:767)

Fixed in 3916520. The limit is one constant now, moe_kernels.A8W4_GFX942_QI_MAX_TOKEN = 8, used by the tuner and by test_csv_qi_rows. The tuner skips every _qi stage 1 above it, so a re-tune can no longer put a _qi row at M > 8. A new CPU test in test_a8w4_gfx942_tune_sources.py checks that the tuner offers _qi kernels at 8 tokens and none at 9, with the moe_sort kernels still there. Without the limit it lists all 52 _qi names at 9 tokens and fails. The op test still passes on MI325X.

3. _qi TILE_K 256 tiles over the 64 KiB LDS (gemm1_a8w4_gfx942.py:765)

Confirmed and fixed in 8076012. Without a check, the BM 32 / TILE_N 128 / TILE_K 256 / k_wave 4 _qi tile at K = 7168 compiles with only a printed "local memory (73728) exceeds limit (65536)", and the launch then fails with hipErrorIllegalState, which says nothing about LDS. a8w4_gfx942_stage1_lds_bytes now gives the tile's LDS size (your 73728 B; 65536 B for the moe_sort variant), compile_gemm1_a8w4_gfx942 raises a ValueError above GFX942_LDS_BYTES (not an assert, so it survives -O), and the tuner skips such tiles for the shape's K. New CPU tests check the size, the compile refusal, and that the tuner at K = 7168 drops that _qi tile but keeps its moe_sort twin. The op test and the gfx942 AOT replay (360 ok) pass on MI325X.

4. moe_sort x-scale read wrong at TILE_K 384 / 512 (gemm1_a8w4_gfx942.py:748)

Thanks, fixed in 4385830. compile_gemm1_a8w4_gfx942 now raises a ValueError for x_layout="moe_sort" with any TILE_K other than 128 or 256 (not an assert), since load_x_scale_moe_sort assumes the whole tile shares y // 8. A new CPU test checks that 384 and 512 are refused; with the check removed it fails. The registered names, the op test and the gfx942 AOT replay (360 ok) are unchanged.

5. No up-front MI325X-only error in the tuner (gemm_moe_tune.py:452)

Fixed in 23f2532. For a gfx942 a8w4 row the tuner now checks a8w4_gfx942_supported() once and raises NotImplementedError ("gfx942 a8w4 stage 1 is enabled on MI325X only … tune it on an MI325X") before queuing any candidate, instead of letting each _g942 candidate fail on its own. A new CPU test with the gate mocked off checks the single error; without the change it fails.

6. swiglu_limit ignored with act="silu" (gemm1_a8w4_gfx942.py:712)

Fixed in b731350. The silu path now builds the SiTU parameters and clamps gate and up with clamp_gate_up before silu_mul_batch, as gemm1.py does (+inf when no limit is set). test_stage1_kernel takes act and limit, and main() adds a silu case with limit 1.0 against the torch reference: it matches with the change and fails without it (84 % of the elements outside the tolerance). The scale self-check runs on the unclamped cases only, since a limit clamps the very values it probes. The CSV rows are SiTUv2 and unchanged; the op test and the gfx942 AOT replay (360 ok) pass on MI325X.

7. The op test gates on get_gfx() (test_flydsl_moe_a8w4_gfx942.py:503)

Fixed in 3b1f53c: the gate and the gfx field use get_gfx_runtime(). On MI325X with GPU_ARCHS="gfx942;gfx950" the old test logged "unsupported on gfx950; skipping" and ran 0 stage-1 checks with exit 0; the new one runs all 14 and passes.

8. Shape checks are plain asserts (gemm1_a8w4_gfx942.py:751)

Fixed in 6d711de. The eleven checks now raise ValueError through one helper, with the same conditions, messages and order, so python -O keeps them. A new test compiles D_INTER=384, TILE_N=256 in a python -O subprocess and expects the "multiple of TILE_N" error; with the old asserts it raised nothing. The op test and the gfx942 AOT replay (360 ok) pass on MI325X.

…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]>
@Bernard-Liu

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small things..

op test and gfx942 AOT replay at head bd616e3, and MI300X flag-case re-run after the row drop?

ci green.

@Bernard-Liu

Copy link
Copy Markdown
Contributor

@vedenev-amd Since #8211 landed and bd616e3c dropped the FlyDSL rows for M ≥ 1024, parts of the description and one error message still describe the earlier state. Could you update them?

Description:

  • The version line (version 9, 2026-11-20) and Reviewed revision (5d7e4e12d413, which aiter-bot reports as FAIL) predate the current head bd616e3c. The review-round changes are listed only up to 12196e01a, so the 11-30 fixes are missing.
  • [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211 is not mentioned. The gfx942 keys at M ≥ 1024 are now served by its 1-stage asm kernel, and this PR's rows cover M 1–512 only.
  • "kimik3_a8w4_tuned_fmoe.csv: 32 gfx942 (cu 304) rows, … M 1, 2, 4, …, 32768": 20 of these rows are this PR's. The 12 rows for M ≥ 1024 come from [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211.
  • The speed table still lists M = 1024 and 2048, and the tuner/shipped table lists inter-384 M = 1024–16384. This kernel no longer serves any of those M.
  • "The path is enabled on MI325X only" gives the M ≥ 1024 slowdown (0.81–0.89x) as its reason, which no longer applies to the rows this PR ships.
  • The "MI300X CI" paragraph cites run 44554877610 at 7cb2fdc4c (since reverted) and "six stage-1 kernels". The ci:mi300x run on bd616e3c is green, and the op test now checks all 12 CSV kernels.
  • "Changed op tests" does not list op_tests/tuning_tests/test_a8w4_gfx942_tune_sources.py.

Code:

  • The NotImplementedError in _flydsl_moe_stage1_impl (moe_kernels.py L1973) and the a8w4_gfx942_supported docstring (L705–706) still justify the MI325X gate with "slower than a16w4 at large M (0.81-0.89x at M >= 1024)". The _g942 stage 1 no longer runs at M ≥ 1024.

@Bernard-Liu

Copy link
Copy Markdown
Contributor

@vedenev-amd The new op_tests/tuning_tests/test_a8w4_gfx942_tune_sources.py is not run by any CI job. split_tests.sh only picks up the tuning_tests/ files it lists by name, and tuning-tests.yaml runs a fixed list of modules; neither list includes this file. So the tests for the TUNE_ONLY, _qi token-limit, LDS, TILE_K, MI325X up-front error and python -O fixes run on no runner. Have you run this file yourself at the current head bd616e3c? Could you post the command and the result, so we can confirm it passes?

@Bernard-Liu

Copy link
Copy Markdown
Contributor

@vedenev-amd Do both new test files need to stay in this PR, op_tests/tuning_tests/test_a8w4_gfx942_tune_sources.py and op_tests/test_flydsl_moe_a8w4_gfx942.py? The first runs on no CI job. The second runs only on the MI300X runners, and only when the ci:mi300x label is set; it returns early on MI35X, and its fused_moe part needs an MI325X, which CI does not have. If a file is only for local validation and does not need to run in CI, it can be removed from the PR.

vedenev-amd and others added 2 commits December 1, 2026 10:47
…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]>
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@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:

  • The NotImplementedError in _flydsl_moe_stage1_impl, the a8w4_gfx942_supported docstring and the op test's skip message now give the MI300X numbers at the M this PR still serves: a8w4 is 0.92–0.99x of a16w4 at inter 384, M = 128–512. The "MI325X only" text the tests match is unchanged.

Description:

2. test_a8w4_gfx942_tune_sources.py at bd616e3c

Yes. MI325X (gfx942, 304 CU), torch 2.10.0+rocm7.2.4, FlyDSL 0.5.3 (main's pin), a checkout of bd616e3c:

python3 -m unittest -v op_tests.tuning_tests.test_a8w4_gfx942_tune_sources
test_compile_refuses_a_tile_over_the_limit ... ok
test_lds_bytes ... ok
test_tuner_skips_tiles_over_the_limit ... ok
test_moe_sort_refuses_tile_k_384_and_512 ... ok
test_qi_only_up_to_the_limit ... ok
test_bad_tile_n_raises_with_O ... ok
test_a_selection_without_flydsl_raises ... ok
test_empty_and_flydsl_tune_only_queue_it_too ... ok
test_off_mi325x_one_up_front_error ... ok
test_unset_tune_only_queues_the_g942_stage1 ... ok
----------------------------------------------------------------------
Ran 10 tests in 10.657s

OK

The same 10 pass at d9ab86bcf. Whether the file stays and runs in CI is item 3.

3. Do both new test files need to stay (36cf238)

  • op_tests/tuning_tests/test_a8w4_gfx942_tune_sources.py is removed. It ran on no CI job; its result at bd616e3c is in item 2.
  • op_tests/test_flydsl_moe_a8w4_gfx942.py stays. It is the only test that checks the _g942 stage-1 kernels numerically, and it does run in CI: on the MI300X runners with ci:mi300x (run 46451342414, shard 7, 36.5 s), all 12 listed stage-1 kernels against the torch reference, CUDA-graph replay, dispatch by name and the off-MI325X refusal. On MI35X it returns at once, since the kernels are gfx942 only. The fused_moe part needs an MI325X and skips itself on the CI runners.

@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@valar-cop Thanks. The two inline points are covered in my reply to Bernard above: the description is at version 10 (head 36cf23846), and test_a8w4_gfx942_tune_sources.py is removed. On the three checks:

  • Op test: at 36cf23846 on MI325X, python3 op_tests/test_flydsl_moe_a8w4_gfx942.py exits 0; through fused_moe it runs M = 1, 2, 16, 128, 512 at inter 512 and 384, err 0 in all 10. On the MI300X CI runner (run 46451342414 at bd616e3c, shard 7) it passed in 36.5 s.

  • gfx942 AOT replay: at 36cf23846, GPU_ARCHS=gfx942 python3 -m aiter.aot.flydsl.moe --csv <the gfx942 rows of kimik3_a8w4_tuned_fmoe.csv>: 216 ok, 0 failed, 0 unsupported, 20 of 20 rows. It was 360 ok with the former 32 rows; the 12 asm rows of [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211 are not FlyDSL replays.

  • MI300X flag cases after the row drop: not re-run on an MI300X node, but run 46451342414 (bd616e3c) covers both halves on the MI300X CI runner. With the flag, M ≤ 512 still picks a _g942 row and must refuse; M ≥ 1024 now picks [ASM] [HIP] gfx942: 1-stage ASM MXFP4 x MXFP8 SiTUv2 MoE kernel for M ≥ 1024 #8211's asm row and runs.

    • M ≤ 512, shard 7, test_flydsl_moe_a8w4_gfx942.py: the runner is detected as not MI325X, so test_gate_off_mi325x runs and passes: the _g942 stage 1 through _flydsl_stage1_wrapper raises NotImplementedError with "MI325X only". The log also has 20 gfx942 a8w4 rows, 8 _qi rows, all at M <= 8 and skipping it on AMD Instinct MI300X for the fused_moe part.

    • M ≥ 1024, shard 2, test_moe_mxfp4fp8_gfx942_asm.py: the dispatcher picks the asm kernel for all 12 keys (using 1stage (kernelName1='_ZN5aiter50fmoe_bf16_pertokenMXfp4Fp8_g1u1_novs_situv2_32x256E' for inter 512, ..._32x192E for inter 384, tokens 1024–32768), and through fused_moe with AITER_SITUV2_A8W4=1 and the relaid W1:

      token inter us err cos diff vs torch
      1024 512 1116.4 0 2.04e-4
      4096 512 2862.4 0 2.04e-4
      1024 384 824.6 2.7e-7 2.04e-4
      4096 384 2357.0 0 2.04e-4

    Not re-run after the drop: the 28 flag cases end to end through fused_moe (M ≤ 512 is checked at the stage-1 entry, which fused_moe calls), and the no-flag a16w4 comparison (a16w4 code is unchanged since that check). The description's gate-check section says so.

@valar-cop

Copy link
Copy Markdown

@vedenev-amd all three covered, thanks. the aiter test on 36cf23846 is still running on my side, ping me when it's green and this can go.

@vedenev-amd
vedenev-amd requested a review from fhuizing December 1, 2026 11:29
@Bernard-Liu

Copy link
Copy Markdown
Contributor

@valar-cop ping

@valar-cop

Copy link
Copy Markdown

@Bernard-Liu ci on 36cf23846 is green now (aiter test run 46632760372, plus checks / opus / triton all success). both inline points are resolved too: description is at v10 and the tune-sources test file is gone. LGTM, thanks.

@vedenev-amd
vedenev-amd merged commit 163947e into main Dec 2, 2026
76 checks passed
@vedenev-amd
vedenev-amd deleted the MoE_fp8_small_M_SILOTIGER-907 branch December 2, 2026 08:04
whx-sjtu added a commit to whx-sjtu/aiter that referenced this pull request Dec 2, 2026
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]>
@zufayu zufayu mentioned this pull request Dec 2, 2026
5 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:mi300x Run MI300X standard and OPUS CI on PRs CK FlyDSL JIT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants