Repository navigation
[CK] [FlyDSL] [CI] [Perf] MiniMax-M3.1 TP4 decode MoE through fused_moe(shared_folded) + tuned rows + --decode-chain tuner - #8676
ganyi1996ppo wants to merge 67 commits into
Conversation
…MM tile primitives
Adds two new, self-contained helper modules to aiter's existing
mega_moe_tp family:
- decode_id_routing.py: in-kernel canonical expert-block routing for the
small-M decode shape (<=128 rows, E128 top4) -- one workgroup resolves
its 16-row expert block straight from topk_ids via an LDS-atomic
histogram and a DPP wave scan, no sort launch and no global atomics.
- decode_tile_primitives.py: per-tile building blocks for the same shape's
GEMM1/GEMM2 compute at H6144/I768 -- scaled-MFMA wrappers (MXFP4 A4W4 and
MXFP8 A8W8), the SwiGLU activation, and MXFP4/MXFP8 row quantization.
Both are ports of the technique in amd-kernels'
moe/mxfp4_h6144_i768_e128_top4/{routing_ids.py,gemm1_a4w4_id_rows.py,
shared_gemm1_a8w8.py,shared_quant.py} (Apache-2.0, "Copyright contributors
to the amd-kernels project") -- same algorithm, reimplemented against
aiter's own aiter.ops.flydsl.kernels.buffer_ops instead of amd-kernels'
private copy of the same buffer-op wrappers. Neither file imports
amd_kernels; each file's docstring credits the specific amd-kernels source
module it is ported from.
mega_moe_tp already carries the epoch-flag / XCD-affinity / loader-wave
LDS-DMA primitives a fused decode GEMM1->GEMM2 kernel needs, but only at
128/256-row prefill tile shapes; this adds the small-M (8-128 row)
in-kernel routing and tile primitives it is missing for a decode-shape
fusion, generalized over the pair/row count (no model-specific constant
beyond the E128/top4/16-row-block shape a call site fixes).
This is a primitives-only PR: the tile loop, prefetch ring and LDS layout
that assemble these into a full fused kernel currently live in a
model-side integration (MiniMax-M3.1 decode MoE) that is not yet upstream
in ATOM, so no aiter op_test exercises the full assembled kernel here.
Correctness was verified through that integration instead: 72/72
adversarial-input bit-identical results against the original
amd_kernels-based kernel, and 12/12 matches against an independent
production reference, on real MI355X hardware (node 035, gpurun lease).
Perf (200 iters, same hardware): the assembled kernel using these
primitives measured -21.3/-12.1/-13.4 us vs production at n=16/24/32 rows,
within +0.2..+1.7 us (noise) of the pre-port amd_kernels version -- no
regression from the port itself.
Follow-up: land the model-side integration (currently
atom/models/minimax_m3/moe_one_launch_aiter.py in a private tree) as its
own ATOM-side PR once the file it extends is upstream, and add a native
aiter op_test once there is a complete in-aiter kernel to test against.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tials bf16x3 split-K router GEMM (E128 x H6144, MFMA 16x16x32) for 1-32 rows: a no-LDS direct kernel for 1-16 rows and a line-layout two-wave kernel for 17-32 rows, plus the tier dispatch (router_gemm_partials) and the one-time gate permutation (router_line_layout). Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4 (router_gemm_direct / router_gemm_nblocks_lines / router_gemm dispatch, Apache-2.0), bodies unchanged, imports moved to aiter's buffer_ops / tensor_shim. Verified on gfx950: partials bit-identical to amd-kernels for rows 1..32 (3 input kinds), graph-replayed GPU time equal to +-0.01 us. Co-Authored-By: Claude <[email protected]>
…, optional input-quant workgroups) Adds the 33-128 row router GEMM tier (router_gemm_nblocks: split-48 to 64 rows, split-16 above, optional MXFP4 + MXFP8 input-quant workgroups appended or prepended to the same launch for the top-k + quant chain that follows) and extends the router_gemm_partials dispatch to 128 rows. Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4/router_gemm_nblocks.py (Apache-2.0), bodies unchanged; the quant group reuses decode_tile_primitives' _fp8 / _e8m0_fp8. Verified on gfx950: partials bit-identical to amd-kernels for rows 1..128 (3 input kinds, with and without the line-layout gate), graph-replayed GPU time within +-0.03 us at 1..128 rows. Co-Authored-By: Claude <[email protected]>
…XFP8 input quant chain Completes the decode-shape routing front end that replaces amd_kernels' chain._route_quant_small: biased sigmoid top-4 over the router partials (decode_router_topk_sorted), the top-4 with the MXFP4 + MXFP8 input quant in one launch for <= 256 rows (decode_router_topk_quant), and route_quant_small (decode_router_chain), which picks per row count between the router launch with the quant workgroups folded in (58-128 rows) and router GEMM + top-4/quant launch (1-57 rows). Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4 (router_topk_sorted, router_topk_mxfp4_mxfp8_quant_sorted_tasks, router_gemm_topk_mxfp4_mxfp8_quant, chain, Apache-2.0), kernel bodies unchanged. Verified on gfx950 against amd-kernels' chain._route_quant_small: q4/s4/q8/s8/ topk weights/topk ids bit-identical for every row count 8..128 (3 input kinds, 484 checks, 0 mismatches); graph-replayed GPU time equal within +-0.1 us at 8..128 rows (4.7-6.1 us per call). Torch-reference pytest included (no amd_kernels dependency). Co-Authored-By: Claude <[email protected]>
…tials bf16x3 split-K router GEMM (E128 x H6144, MFMA 16x16x32) for 1-32 rows: a no-LDS direct kernel for 1-16 rows and a line-layout two-wave kernel for 17-32 rows, plus the tier dispatch (router_gemm_partials) and the one-time gate permutation (router_line_layout). Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4 (router_gemm_direct / router_gemm_nblocks_lines / router_gemm dispatch, Apache-2.0), bodies unchanged, imports moved to aiter's buffer_ops / tensor_shim. Verified on gfx950: partials bit-identical to amd-kernels for rows 1..32 (3 input kinds), graph-replayed GPU time equal to +-0.01 us. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
… tiles with the shared expert folded in
Adds the routed MXFP4 + shared MXFP8 expert tiles of the E128 top4 H6144 I768
decode path on top of the in-kernel routing and tile primitives:
- decode_expert_tiles.py: routed GEMM1 (gate/up, SwiGLU, MXFP4 quant; each
workgroup builds its 16-row expert block from topk_ids, no sort launch),
routed GEMM2 (top-k weighted BF16 slot rows), the shared expert's MXFP8
gate/up and down tiles, and the two "shared tiles first" launches that run
the shared expert's workgroups ahead of the routed ones in the same launch.
- decode_expert_gemms.py: per-row-count tiling (tiles_for), plan/launcher
selection and the two-launch host decode_expert_gemms().
- op_tests/test_mega_moe_tp_decode_expert_gemms.py: bitwise equivalence vs the
amd-kernels expert tiles (oracle only, skipped when not installed).
Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4 gemm{1,2}_a4w4_id_rows,
shared_gemm{1,2}_a8w8 (Apache-2.0, "Copyright contributors to the amd-kernels
project"); no amd_kernels import in the library code.
Co-Authored-By: Claude <[email protected]>
…expert reduce moe_sorting_onewg: single-workgroup LDS sort for E == 128, M <= 512 (no output clearing), 2-3x faster than the multi-phase sorts; opt-in through moe_sorting(unordered=True), used by fused_moe for route-reduce stage2. moe_slots_shared_reduce: fp32 sum of routed slots plus the shared expert to bf16 in one pass (bitwise equal to the generic topk reduction). Techniques credit: amd-kernels sort_a16w4 / reduce_slots_shared. Co-Authored-By: Claude <[email protected]>
…reduce extent - moe_sorting_onewg / moe_slots_shared_reduce launch under the tensors' device and key the compiled handle per device (a FlyDSL handle is device bound; one process on several GPUs reused cuda:0's). - moe_slots_shared_reduce asserts CUDA tensors on one device and a < 2 GiB parts buffer (32-bit buffer-resource extents and offsets). - test docstring no longer claims equality with the generic reduction it does not compare against. Co-Authored-By: Claude <[email protected]>
…use rocdl cvt wrappers; add routing test Co-Authored-By: Claude <[email protected]>
…use rocdl cvt wrappers; add routing test Co-Authored-By: Claude <[email protected]>
…use rocdl cvt wrappers; add routing test Co-Authored-By: Claude <[email protected]>
…use rocdl cvt wrappers; add routing test Co-Authored-By: Claude <[email protected]>
…fails without the id-range guard) Co-Authored-By: Claude <[email protected]>
…rch/strides, per-GPU launcher, CI runs the test Review findings on ROCm#8551: - router_gemm_partials launched on the current device with whatever pointers it was given: a CPU or foreign-GPU gate / hidden state became an invalid GPU address, gfx942 reached an MFMA form it lacks, and one cached compiled handle served every GPU. It now returns None unless every tensor is CUDA storage on one gfx950 device, launches under that device with its stream and keeps one launcher per GPU (kernels/topk/topk_launch._launcher_on). - An expanded row (stride(0) == 0) gave the kernels an empty buffer descriptor and silently zero partials (max error 10.46 = |logits| on 8 rows, reproduced on gfx950). Rows must not overlap, and m * stride * 2 must fit the 32-bit descriptor extent; both return None. - _get_kernel took a hard-coded (48, 64) beside split_config; it uses the tier. - The test had no per-split oracle (permuted split slots passed), no stride or rejection case, and CI runs op_tests with `python3 file` (collects nothing): add per-chunk reference, padded-stride and rejection cases, a gfx950 skip, and list the file in aiter_test.sh's pytest dispatch. Verified on gfx950: 14 passed. Co-Authored-By: Claude <[email protected]>
…ce; torch-reference test - decode_expert_gemms: check every operand (device, contiguity, one-byte dtype, byte length from plan.n; topk_ids int32 / topk_w float32 (n, 4)) before the launch, since the tiles bind num_records from plan.n and not from the tensors; key both compiled launchers by device (tensor_shim keeps one handle per JitFunction); import H/I/E/TOPK from the tile modules. - test: independent fp32 torch reference for routed + shared GEMM1/GEMM2 at 7 row counts (rel error 0.0017, gate 0.01), operand-contract rejection test, gate via get_gfx_runtime, runnable main; the amd-kernels bit-identical comparison stays as an optional extra. Co-Authored-By: Claude <[email protected]>
…e, stride-aware input quant, per-GPU launcher, quant tests Review findings on ROCm#8552 (the 8551 fixes ride along, same files): - router_gemm_partials selected the 33-128 row n-blocks tier on any arch: its LDS (69632 B at 65-128 rows) exceeds gfx942's 64 KiB and the MFMA form is gfx950-only. It now returns None unless every tensor, including the optional line-layout gate copy, is CUDA storage on one gfx950 device, launches under that device and stream, and keeps one launcher per GPU. - _dual_quant_group (the MXFP4 / MXFP8 input-quant workgroups) ignored the row stride: for a [m, 6144] view with row stride > 6144 it quantized the padding of the previous row. It reads rows at i32_sx like the GEMM path. - Neither quant mode had a test. test_input_quant_workgroups launches modes 1 and 2 (also with a padded row stride) and checks the e8m0 scales against a torch rule exactly, every element against the e4m3 / e2m1 error bound, every row's reconstruction error, and that the router partials still sum to the logits. Rows 1-128, per-split oracle, padded stride and rejection cases are covered; the file is listed in aiter_test.sh's pytest dispatch (CI runs op_tests with `python3 file`, which collects nothing here). Verified on gfx950: 63 passed. Co-Authored-By: Claude <[email protected]>
…e, stride-aware input quant, per-GPU launcher, quant tests Review findings on ROCm#8552 (the 8551 fixes ride along, same files): - router_gemm_partials selected the 33-128 row n-blocks tier on any arch: its LDS (69632 B at 65-128 rows) exceeds gfx942's 64 KiB and the MFMA form is gfx950-only. It now returns None unless every tensor, including the optional line-layout gate copy, is CUDA storage on one gfx950 device, launches under that device and stream, and keeps one launcher per GPU. - _dual_quant_group (the MXFP4 / MXFP8 input-quant workgroups) ignored the row stride: for a [m, 6144] view with row stride > 6144 it quantized the padding of the previous row. It reads rows at i32_sx like the GEMM path. - Neither quant mode had a test. test_input_quant_workgroups launches modes 1 and 2 (also with a padded row stride) and checks the e8m0 scales against a torch rule exactly, every element against the e4m3 / e2m1 error bound, every row's reconstruction error, and that the router partials still sum to the logits. Rows 1-128, per-split oracle, padded stride and rejection cases are covered; the file is listed in aiter_test.sh's pytest dispatch (CI runs op_tests with `python3 file`, which collects nothing here). Verified on gfx950: 63 passed. Co-Authored-By: Claude <[email protected]>
…fails without the id-range guard) Co-Authored-By: Claude <[email protected]>
…fails without the id-range guard) Co-Authored-By: Claude <[email protected]>
…fails without the id-range guard) Co-Authored-By: Claude <[email protected]>
…ne), per-GPU launcher, per-row quant checks Review findings on ROCm#8553 (the 8551 / 8552 fixes it includes are cherry-picked alongside): - route_quant_small checked rows, contiguity and shape[1] only: an fp32 [58, 6144] x was read as bf16, a one-element bias as 128 floats, and a CPU or foreign-GPU tensor was handed to the kernels as an address. It now returns None (like router_gemm_partials) unless x, the gate and the bias have the expected dtype, shape and contiguity on one gfx950 device, and launches under that device with its stream and one launcher per GPU (run_on_device). - splitk_biased_topk_mxfp4_mxfp8_quant guarded its buffers with `assert` on strides only (stripped under python -O): fp16 [m, 4] weights passed and the kernel wrote four fp32 per row into them. It raises ValueError unless the partials, bias, outputs and x have the dtype, shape (m, 4), row stride >= 4 and device the kernel assumes. - test_route_quant_small's batch-wide FP4 bound (0.25) passes with one whole row zeroed (1 / sqrt(128) = 0.088) and the scales were never compared. It checks every row's reconstruction error and the e8m0 scales against a torch rule, and adds rejection cases; the files are listed in aiter_test.sh's pytest dispatch (CI runs op_tests with `python3 file`, which collects nothing here). Verified on gfx950: the chain, router GEMM and id-routing tests pass (118). Co-Authored-By: Claude <[email protected]>
…k order 8548 -> 8551 Co-Authored-By: Claude <[email protected]>
Keeps this branch's own content; the parent's older copies of shared files are superseded by this branch's versions. Co-Authored-By: Claude <[email protected]> # Conflicts: # aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_common.py # aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm.py # op_tests/test_decode_router_gemm.py
…52 -> 8553 -> 8555) Co-Authored-By: Claude <[email protected]>
Keeps this branch's own content; the parent's older copies of shared files are superseded by this branch's versions. Co-Authored-By: Claude <[email protected]> # Conflicts: # .github/scripts/aiter_test.sh
…[E, 2, I/16, block] layout in place (get_plan(w13_split=True)) Only the GEMM1 tile's block address changes (gate blocks then up blocks instead of interleaved), so a caller keeps its original w13 and needs no second re-laid copy (612 MiB per layer and rank at TP4); outputs are bitwise equal to the interleaved layout (new test). Co-Authored-By: Claude <[email protected]>
… entry point CI runs op_tests/test_moe_sorting.py with python3, so a test function without a caller never ran. Call it on gfx950 (the path it asserts is gfx950-only). Co-Authored-By: Claude <[email protected]>
… LDS fit, cache source, tuner arch - reject clamp_shared=False (the shared GEMM hard-codes the limit-7 clamp) - validate output= metadata and overlap before the decode impl - prequantized branch: reject codes whose dtype is not uint8/fp4x2 (routed) or uint8/float8_e4m3fn (shared) - RouterCfg.fits: reject nblocks candidates whose LDS footprint exceeds 160 KiB - derived weight cache keeps its source tensor alive - --decode-chain tuner gates on the runtime GPU (self.get_gfx()) - test_fused_moe_m3_decode: module-wide skipif instead of module-level skip Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Active issues can cause incorrect scale-cache reuse and silent dtype misinterpretation, while the standalone timing command lacks a gate to skip unsupported architectures.
3 open issues
8 resolved since last review
Tuner admits candidates exceeding gfx950 LDS capacity Prequantized codes are not validated against their source dtypes Reject unsupported shared-folded precision overrides and global scales Tuning gate checks build targets instead of runtime GPU architecture Cache key can reuse stale layouts after source storage is freed Early return skips output validation and overlap checks Early return ignores clamp_shared=False Use padded token buckets for tuning candidate rows
Review effort: Balanced
…tself on gfx950 Co-Authored-By: Claude <[email protected]>
… weight / E8M0 scale dtype checks, arch gate in the timing main Co-Authored-By: Claude <[email protected]>
|
Status for the Copilot overviews (latest on |
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because the tuning correctness gate can accept incorrect expert-weight pairings, while benchmark paths do not reliably measure the integrated decode chain.
No open issues 🎉
3 resolved since last review
Review effort: Balanced
…-tuner Co-Authored-By: Claude <[email protected]>
…m3route_ kernel names aiter.moev2.api.fused_moe mirrors the legacy signature (shared_folded, shared_a1; shared_folded raises NotImplementedError there: the whole-graph row runs from the legacy entry), MoeProblem.from_legacy_key takes shared_expert_id as get_2stage_cfgs now does, and kernel_names parses the router entry (kernelName2 = flydsl_m3route_<name>) of the decode whole-graph rows, so tests/test_moev2_switch.py and tests/test_moev2_dispatch.py pass again. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The benchmark uses FP32 scales where shared-expert GEMMs require E8M0, and the decode-chain run/compare hook omits the shared expert and router, making the baseline and before/after timings invalid.
2 open issues
Review effort: Balanced
…hain --run_config/--compare Copilot 4705315013: decode_moe_bench.public_path quantized the shared-expert GEMM inputs with get_hip_quant(per_1x32)(..., quant_dtype=fp8), whose default scale_type is fp32, while gemm_a8w8_mxfp8_bpreshuffle requires 1x32 e8m0 scales. Pass scale_type=dtypes.fp8_e8m0 at both call sites so the public-path benchmark baseline (used by op_tests/test_fused_moe_m3_decode.py's timing table and decode_chain_tune.py's tune_shape comparison) quantizes the way the kernel expects. Copilot 4705315073: --decode-chain --run_config / --compare silently inherit FmoeTuner.run_config(), which calls the routed-only fused_moe and supplies neither the shared expert nor the router, so neither option measures the shared-folded chain DecodeChainTuner searches. Reject both at argument parsing (DecodeChainTuner.parse_args) with a clear error instead of running a benchmark/reference that silently measures the wrong thing.
|
Status for the latest Copilot overview (on |
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because omitted findings identify a critical weight-layout mismatch that can silently produce incorrect expert outputs, alongside input-validation and test-checking gaps.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
|
Closing this as part of consolidating our MiniMax-M3.1 TP4 decode-MoE work. Rationale: this decode chain (#8548 router GEMM + id-routing + tile primitives, #8553 top-4 + MXFP4/MXFP8 input-quant, #8555 expert GEMM1/GEMM2 + shared-expert fold, #8676 The one genuinely new optimization from this effort — the one-workgroup E128 expert sort (2.5-3x vs the default sort, through the general Closing to keep the review queue focused. Thanks to everyone who reviewed. |


What / why
MiniMax-M3.1 TP4 decode MoE (E128 top-4, H6144 / I768, MXFP4 routed experts + MXFP8 shared expert, 8-128 rows, gfx950) through aiter's existing MoE interface instead of a side API:
fused_moe(..., shared_folded=True, shared_a1=...): the shared expert is a separate MLP (sum_k w_k * expert_k(x) + shared(x)), folded into the routed expert GEMM1/GEMM2 launches. It is served by a tuned row of the newtuned_shared_fmoe.csvfamily (kernelName1 = impl__flydsl_m3decode__<tiles>, resolved through the existingget_2stage_cfgs/fused_moe_registrywhole-graph path, newshared_expert_id=argument so a-1row does not alias FHMoE's dummy-expert key). Without a tuned row it raisesNotImplementedError(no silent fallback).moe_route_quant(...): router entry (fp32 gate GEMM + biased sigmoid top-4 + MXFP4/MXFP8 input quant, 1-2 launches). Its split-K / tile comes from the same row (kernelName2 = flydsl_m3route_...).gemm_moe_tune.py --decode-chain(DecodeChainTuner, search incsrc/ck_gemm_moe_2stages_codegen/decode_chain_tune.py) writes rows oftuned_shared_fmoe.csv, comparing every candidate against the public path of the layer and writing no row when the public path wins. Rows shipped:aiter/configs/model_configs/minimax_m3_tp4_decode_tuned_shared_fmoe.csv(own family*tuned_shared_fmoe*, no overlap withtuned_fmoe; 8/16 rows are the default tiles without timings, 32/64/128 are tuner picks).No amd-kernels runtime dependency (credit in file headers only).
Stack / dependencies
Stacked on #8548 -> #8553 -> #8555 and #8556 (the four heads are merged into this branch as merge commits, so the diff shows their files until they land; those PRs are untouched by this one). Merge order: #8548, #8553, #8555, #8556 (any time), then this PR. Review only the integration commits on top (
fused_moe(shared_folded), tuned rows, tests, tuner) and the review-fix commit514d35527.origin/mainis merged into the branch (no conflicts).Net integration delta over the merged stack (19 files, +1939/-155 before the two small review commits):
aiter/fused_moe.py+226 (shared_folded dispatch,moe_route_quant,shared_expert_id),aiter/ops/flydsl/fused_moe_m3_decode.py+196,decode_moe_cfg.py+331,decode_moe_bench.py+226,decode_chain_tune.py+241,gemm_moe_tune.py+112, teststest_fused_moe_m3_decode.py+216 /test_decode_moe_cfg.py+100, router/expert kernel touch-ups (decode_router_topk_quant.py,decode_router_gemm.py,decode_router_chain.py,decode_expert_gemms.py), 3 small config files,jit/core.py+14,fused_moe_registry.py+7.Measured gain (MI355X gfx950, 1 GPU, CUDA-graph replay, 8 rotated cold weight sets, ABAB x3, median, us per layer)
Public path = gate GEMM + topk_gating + standard 2-stage
fused_moefor the routed experts + shared MXFP8 MLP separately.fused_moe(shared_folded)+ public routerfused_moe(shared_folded)+moe_route_quantGain is positive at every M (2.5x at 8 rows, 1.8x at 128). Integrated path equals the direct chain ops within noise (the interface adds no measurable overhead). Reproduce:
python op_tests/test_fused_moe_m3_decode.py --rows 8 16 32 64 128 --sets 8 --abab 3.Correctness
pytest op_tests/test_decode_moe_cfg.py op_tests/test_fused_moe_m3_decode.py op_tests/test_decode_router_chain.py op_tests/test_decode_router_gemm.py op_tests/flydsl_tests/test_decode_id_routing.py: 180 passed;op_tests/test_mega_moe_tp_decode_expert_gemms.py: 14 passed, 15 skipped (the optional amd-kernels bitwise tests), all on gfx950 (head514d35527). The integrated path is bit-identical (torch.equal) to the chain ops for every row count and for every tiling config the tuner enumerates; router configs pick identical routes; scale re-layout matches a logical reference; a missing row / out-of-contract request fails closed.op_tests/test_fhmoe.pypasses,op_tests/tuning_tests/test_config_shape_collision.pypasses (new family has no collision). Tuner smoke (gemm_moe_tune.py --decode-chain -i <1 row, 16 tokens> -o <tmp> --iters 10): wrote a row, chain 44.4 us vs public 106.3 us.Known non-delta failures on this run:
op_tests/tuning_tests/test_grouped_ep_fused_lookup.py(gfx1250 rows, run on gfx950) and the pytest collection ofop_tests/test_moe_sorting.py(script-style functions from the stack/main); neither touches this change.Fail-closed contract (review follow-ups)
fused_moe(shared_folded=True)raisesNotImplementedErrorfor anything outside the kernels' contract instead of ignoring it: no tuned row, activation / quant overrides,a2_scale, global scales,linear_beta,splitk,clamp_shared=False(the shared GEMM hard-codes the limit-7 clamp), shared weights that are not preshuffledfloat8_e4m3fn, prequantized codes of the wrong dtype.output=goes through the same metadata / overlap checks as the other paths. Dropped routes (ids outside[0, E)) contribute nothing (masked slot reduction from #8556). Router configs whose LDS footprint exceeds the 160 KiB budget are not tuner candidates.--decode-chaingates on the runtime GPU arch.Memory
No weight is re-laid: the routed w13 is read in place (
get_plan(w13_split=True)from #8555,9e02b0320), so there is no ~35 GB per GPU KV-block cost. What is derived and cached per layer: the e8m0 routed w13 scales re-laid once (36.0 MB), the fp32 router line-layout copy (3.0 MB) and the shared expert scales (0.42 MB): 39.4 MB/layer, about 4.2% of the 932 MB the layer holds, roughly +2.4 GB for a ~61-layer model. The original scale tensor stays resident (public path/other callers). Build before CUDA graph capture (prepare_decode_weights, or one eager call).Router GEMM caveat
The router GEMM (1-128 rows) is NOT on the unified BF16 tuner (fp32 gate, split-K partial output); it is served through the fmoe row (
kernelName2) oftuned_shared_fmoe.csvandmoe_route_quant.review-pr by hand
Checked against
.github/instructions/aiter-ops-flydsl.instructions.mdandaiter/ops/flydsl/AGENTS.md, the aiter-config-shape skill, ruff 0.16.0 (pinned CI version) and black on touched Python. Fixed: ruff findings (I001, RUF100, RUF059, C408, B023, SIM115/SIM103),op_tests/test_fhmoe.pypositional-order test (the appendedshared_folded/shared_a1parameters), the two new pytest files are now in the pytest list of.github/scripts/aiter_test.sh(they would otherwise be run as scripts). Compiled handles key per device; launcher checks tensors (check_request); runtime dispatch usesget_gfx_runtime(). Deviations: the new tests compare withtorch.equal/assert_close(bit identity is the contract) instead ofcheckAllclose; the derived-scale cache is keyed on data_ptr + tensor version (callclear_derived_weight_cache()after replacing weights in place);SIM102in the kernel body is left (DSLconst_exprnesting).Limits
gfx950 only; E128 top-4, H6144 / I768, MXFP4 routed + MXFP8 shared, 8-128 rows, SwiGLU-OAI (alpha 1.702, limit 7), separated GGUU weights; no expert_mask / bias / padding / EP.
PR Self-Review
Reviewed revision
bb5d7fe (e05f66f + 610fe93 shared_folded/flydsl_m3route_ naming + the two fixes below)
Behavior and intent
Serves the MiniMax-M3.1 TP4 decode MoE through
fused_moe(shared_folded=True)with tuned rows and a--decode-chaintuner, so the interface path matches the chain ops at 38.0-81.8 us per layer instead of 96.8-144.0 us.Validation and unverified scope
Bit-identical to the chain ops; 180 tests passed on gfx950 at
514d35527; table in the body.bb5d7fea4fixes two Copilot findings:decode_moe_bench.public_path(the tuner's / op-test's public-path comparison baseline) now passesscale_type=dtypes.fp8_e8m0to both shared-expert quant calls, matching whatgemm_a8w8_mxfp8_bpreshuffleexpects (it defaulted to fp32 scales, which would have made the baseline invalid);DecodeChainTuner.parse_argsnow rejects--decode-chain --run_config/--compare(both would silently inherit the routed-onlyFmoeTuner.run_config(), measuring neither the shared expert nor the router). Not verified on a GPU:e05f66f41and610fe93d8/bb5d7fea4(no node was free this pass);torch.compilenot tested; CK-dependent shapes not run.PR-specific question
Adds the new test files to the pytest lists in
aiter_test.sh/split_tests.shonly; no workflow, permission or secret change.Changed op tests
op_tests/flydsl_tests/test_decode_id_routing.py: torch oracle for the in-kernel canonical expert-block routing (8-128 rows, partial blocks, skewed ids, ids outside [0, E)); nothing else in the tree exercisesdecode_id_routing.op_tests/test_decode_router_gemm.py: split-K partials of the router GEMM sum tox @ W.Tin fp64 for 1-128 rows; no other test covers these kernels.op_tests/test_decode_router_chain.py: top-4 ids / weights vs an fp64 reference and per-row FP8 / FP4 dequant error ofroute_quant_small, rows 1-128.op_tests/test_mega_moe_tp_decode_expert_gemms.py: fp32 torch reference for the routed + shared expert GEMMs (batch and per-token error), dropped-route and bad-operand checks; optional bitwise test against amd-kernels (skipped without the package).op_tests/test_decode_moe_cfg.py: CPU tests of the tuning-config names, legality (including LDS fit) and candidates, and that the shipped tuned rows name legal configs.op_tests/test_fused_moe_m3_decode.py: thefused_moe(shared_folded=True)path is bit-identical to the chain ops, fails closed outside the contract, caches derived scales correctly; also the layer timing table.op_tests/test_moe_sorting.py: one-workgroup sort vs the torch reference up to the pair order (including the topk 1/2/3/6 table-boundary cases and a check thatunordered=Trueactually takes that path) and the slots + shared reduce (including dropped routes).op_tests/test_fhmoe.py: only the positional-parameter-order list gains the appendedshared_folded/shared_a1parameters.🤖 Generated with Claude Code