Skip to content

[CK] [FlyDSL] [CI] [Perf] MiniMax-M3.1 TP4 decode MoE through fused_moe(shared_folded) + tuned rows + --decode-chain tuner - #8676

Closed
ganyi1996ppo wants to merge 67 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/moe-decode-fmoe-tuner
Closed

ganyi1996ppo wants to merge 67 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/moe-decode-fmoe-tuner

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 new tuned_shared_fmoe.csv family (kernelName1 = impl__flydsl_m3decode__<tiles>, resolved through the existing get_2stage_cfgs / fused_moe_registry whole-graph path, new shared_expert_id= argument so a -1 row does not alias FHMoE's dummy-expert key). Without a tuned row it raises NotImplementedError (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_...).
  • Tuner: gemm_moe_tune.py --decode-chain (DecodeChainTuner, search in csrc/ck_gemm_moe_2stages_codegen/decode_chain_tune.py) writes rows of tuned_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 with tuned_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 commit 514d35527. origin/main is 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, tests test_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_moe for the routed experts + shared MXFP8 MLP separately.

rows public fused_moe(shared_folded) + public router fused_moe(shared_folded) + moe_route_quant chain ops direct
8 96.81 49.01 37.98 38.00
16 111.15 55.32 44.89 44.83
32 106.49 55.81 48.02 48.77
64 121.28 70.74 63.81 64.08
128 144.03 88.11 81.81 86.13

Gain 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 (head 514d35527). 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.py passes, op_tests/tuning_tests/test_config_shape_collision.py passes (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 of op_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) raises NotImplementedError for 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 preshuffled float8_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-chain gates 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) of tuned_shared_fmoe.csv and moe_route_quant.

review-pr by hand

Checked against .github/instructions/aiter-ops-flydsl.instructions.md and aiter/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.py positional-order test (the appended shared_folded/shared_a1 parameters), 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 uses get_gfx_runtime(). Deviations: the new tests compare with torch.equal / assert_close (bit identity is the contract) instead of checkAllclose; the derived-scale cache is keyed on data_ptr + tensor version (call clear_derived_weight_cache() after replacing weights in place); SIM102 in the kernel body is left (DSL const_expr nesting).

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-chain tuner, 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. bb5d7fea4 fixes two Copilot findings: decode_moe_bench.public_path (the tuner's / op-test's public-path comparison baseline) now passes scale_type=dtypes.fp8_e8m0 to both shared-expert quant calls, matching what gemm_a8w8_mxfp8_bpreshuffle expects (it defaulted to fp32 scales, which would have made the baseline invalid); DecodeChainTuner.parse_args now rejects --decode-chain --run_config / --compare (both would silently inherit the routed-only FmoeTuner.run_config(), measuring neither the shared expert nor the router). Not verified on a GPU: e05f66f41 and 610fe93d8/bb5d7fea4 (no node was free this pass); torch.compile not tested; CK-dependent shapes not run.

PR-specific question

Adds the new test files to the pytest lists in aiter_test.sh / split_tests.sh only; 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 exercises decode_id_routing.
  • op_tests/test_decode_router_gemm.py: split-K partials of the router GEMM sum to x @ W.T in 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 of route_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: the fused_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 that unordered=True actually takes that path) and the slots + shared reduce (including dropped routes).
  • op_tests/test_fhmoe.py: only the positional-parameter-order list gains the appended shared_folded / shared_a1 parameters.

🤖 Generated with Claude Code

ganyi1996ppo and others added 30 commits November 24, 2026 01:44
…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]>
… 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]>
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
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]>
ganyi1996ppo and others added 4 commits November 25, 2026 20:48
… 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread aiter/ops/flydsl/fused_moe_m3_decode.py Resolved
Comment thread aiter/ops/flydsl/fused_moe_m3_decode.py Resolved
Comment thread op_tests/test_fused_moe_m3_decode.py Resolved
Copilot AI balanced review requested due to automatic review settings November 26, 2026 04:45
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Status for the Copilot overviews (latest on 514d35527) and the aiter-bot self-review: inline findings are answered in their threads (fixed in 845d0c3 / 75f12a4 / 514d355 / e05f66f); decision pending (acknowledged, tracked): the shared-weight is_shuffled / float8_e4m3fn contract and the M=8 tuned row. The description now has the PR Self-Review section for revision e05f66f.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

ganyi1996ppo and others added 2 commits November 26, 2026 01:42
…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]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 08:47
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Status for the latest Copilot overview (on 610fe93d8): both inline findings are fixed in bb5d7fea4 (the public-path bench now quantizes with e8m0 scales for the shared-expert GEMMs; --decode-chain --run_config/--compare are now rejected at argument parsing instead of silently measuring the wrong thing) and replied in their threads. The description's PR Self-Review is updated to bb5d7fea4.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

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 fused_moe(shared_folded) integration + decode-chain tuner) is a parity port of the amd-kernels decode path — bit-identical to that reference, not a speedup over it. aiter main already serves MiniMax-M3.1 TP4 decode at the same shapes (M=8-256) through the merged mega_moe_tp backend (#8270), which is the path our production stack uses, so this standalone single-GPU chain adds no independent end-to-end gain.

The one genuinely new optimization from this effort — the one-workgroup E128 expert sort (2.5-3x vs the default sort, through the general moe_sorting interface, useful to every E128 MoE model) — landed separately in #8556 and stays.

Closing to keep the review queue focused. Thanks to everyone who reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants