You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FlyDSL] [CI] mega_moe_tp: decode-shape (8-128 row) MoE expert GEMM1/GEMM2 tiles with the shared expert folded in - #8555
Third PR of the MiniMax-M3.1 decode MoE series (E128 top-4, H6144 / I768, MXFP4 routed experts + MXFP8 shared expert, 8-128 rows, gfx950): the expert GEMM tiles that sit on top of the routing / tile primitives (#8548) and the router chain (#8553).
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, one writer per (token, slot)), the shared expert's MXFP8 gate/up and down tiles, and the two "shared tiles first" launches: the shared expert's workgroups run ahead of the routed ones inside the same launch, so the shared expert costs no extra launch.
op_tests/test_mega_moe_tp_decode_expert_gemms.py: an independent fp32 torch reference test (mandatory) and an optional amd-kernels bitwise test.
Every tiling keeps the K order, so the outputs are the same bits for any tile / prefetch choice. Ported from amd-kernels (gemm{1,2}_a4w4_id_rows, shared_gemm{1,2}_a8w8; Apache-2.0, credited in the headers); no amd_kernels import.
Performance (MI355X gfx950, real MiniMax-M3.1 layer weights, TP4 shard shapes)
Parity with the amd-kernels tiles (GEMM1 + GEMM2 launches, cold weights via 4-layer rotation, CUDA-graph replay, ABAB, us per layer, this PR vs amd-kernels): 8 rows 34.58 vs 34.57, 32 rows 65.84 vs 65.65, 64 rows 79.91 vs 79.99, 128 rows 104.62 vs 104.64; within +-0.7 us at every row count, the sign flips with launch order. No end-to-end gain by itself; the gain of the whole chain is in #8676.
Tests / how to run
pytest op_tests/test_mega_moe_tp_decode_expert_gemms.py (gfx950): 14 passed, 15 skipped (the amd-kernels bitwise tests, package not installed); per-token and batch Frobenius gates against the fp32 reference. Collected and skipped (not an empty run) on non-gfx950 GPUs.
Bit identity vs the amd-kernels tiles launched with the same tiling (harness imports amd-kernels): 168/168 calls over rows 8-128 x {with, without the 32-128 row tuning} x 3 input kinds, two rounds.
Known unrelated CI failure: Triton Tests (MI35X) / Shard 4 (test_gemm_a16wfp4); this PR does not touch Triton.
Adds the 8-128 row expert GEMM1/GEMM2 tiles with the shared expert folded in, on top of #8553.
Validation and unverified scope
168/168 bitwise calls vs amd-kernels tiles; fp32 torch reference test (14 passed, 15 amd-kernels tests skipped); timing within +-0.7 us. Not verified: gfx942 skip path (no such GPU available).
PR-specific question
Only adds test files to the existing pytest lists (inherited); 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).
…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]>
ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm
vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8555 --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.
Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The launchers can reuse device-bound compiled handles across GPUs and leave outputs unwritten, while unchecked operand contracts and ineffective correctness coverage leave additional risks unresolved.
Adds decode-shape MoE expert GEMMs to Aiter’s FlyDSL mega_moe_tp family, building on #8548’s routing and tile primitives. The path handles 8–128 rows and folds shared-expert work into the two routed-expert launches.
Changes:
Adds routed MXFP4 and shared MXFP8 GEMM1/GEMM2 tiles.
Introduces row-dependent tiling, cached plans and a two-launch host wrapper.
Adds optional amd-kernels bitwise-equivalence tests across tiling bands.
File
Description
op_tests/test_mega_moe_tp_decode_expert_gemms.py
Adds optional oracle comparisons for routed and shared outputs.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Shared compiled handles can be reused across devices, raw-buffer inputs lack required layout validation, and CI does not execute the new correctness cases.
This introduces a local architecture probe instead of the shared runtime helper required by aiter/ops/flydsl/AGENTS.md:38-41 and .claude/skills/aiter-op-test/SKILL.md:47. Please use get_gfx_runtime() == "gfx950" for the gate so the test follows the same architecture-detection contract as runtime dispatch, rather than maintaining a separate gcnArchName substring check.
…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]>
ROCm/aiter PR #8555 — [FlyDSL] mega_moe_tp: decode-shape (8-128 row) MoE expert GEMM1/GEMM2 tiles with the shared expert folded in
Adds the two decode expert GEMM launches (routed MXFP4 + shared MXFP8, GEMM1+SwiGLU+requant and GEMM2) for the E128/top4/H6144/I768 MoE path, ported from amd-kernels; reviewed here is only commit 82410b3 (the commits of #8548 below it are reviewed there).
Review (advisory): ⚠️ NEEDS WORK -- the three findings below were fixed in 1ee4b96 on this branch; not independently refuted
Validation (deterministic): NOT RUN -- triage found 2 candidate test targets and no unique added one; instead the changed test file was run by hand on gfx950 (MI355X): 23 passed (7 torch-reference row counts, 1 operand-contract test, 15 bit-identical vs amd-kernels cases)
Perf (advisory): NOT RUN -- no stages.perf; the PR body's parity table (+-0.7 us per layer vs amd-kernels, 8-128 rows) is [unverified], no script or log is in the PR
Size: 1843 lines / 6 files -- over the review bar (this is the stacked diff; #8548's commits make up the first 535 lines)
Design (advisory): SPLIT -- decode_expert_tiles.py (945 lines, tile bodies) / decode_expert_gemms.py (host tiling + launch) / the test; already stacked on #8548, which was the right seam
Human: recommend Felix Li review whether the shared expert should stay folded into the routed launches (nsh leading workgroups) in PR #8555 given the one-handle-per-JitFunction launcher contract
⚠️ [verified] decode_expert_gemms.py decode_expert_gemms bound every buffer's num_records from plan.n and passed the caller's tensors through .view(-1) unchecked: get_plan(16) called with 8-row operands reads 8 rows past xq/xs/q8 (and a slice such as x[:, ::2] or a CPU / other-device tensor is not caught). Reads out of bounds, silently wrong output. Author must keep the metadata-only operand check added in 1ee4b96 (_check_operands: device, contiguity, one-byte dtype, byte length from plan.n, topk_ids int32 and topk_w float32 of shape (n, 4)). ⚠️ [inferred] decode_expert_gemms.py launched both kernels through _run_compiled with no specialization_key, so the single cached handle per JitFunction is shared by cuda:0 and cuda:1 (a handle compiled on device 0 and reused on device 1 does not launch, per aiter/ops/flydsl/AGENTS.md); one-process-per-GPU serving never hits it. Not tested here: only one GPU was available. Author must keep the per-device key added in 1ee4b96 and, if a second GPU is at hand, run the plan on two devices. ⚠️ [verified] op_tests/test_mega_moe_tp_decode_expert_gemms.py: the only oracle was amd-kernels (same algorithm, same byte layouts) behind a module-level importorskip, so CI ran zero cases, a bug present in both implementations would pass, the gate used gcnArchName, and the file had no __main__ (python3 file collects nothing). Author must keep the rewrite in 1ee4b96: an independent fp32 torch reference for routed and shared GEMM1/GEMM2 at 8, 16, 24, 40, 64, 97 and 128 rows (measured relative Frobenius error 0.0017, gate 0.01; weight scales are constant per expert so a scale permutation inside an expert is covered only by the bit-identical test), the amd-kernels comparison as an optional extra, get_gfx_runtime() as the gate.
📝 [verified] Not changed: decode_expert_tiles.py uses legacy buffer_ops descriptors and raw llvm/inline-asm MFMA where aiter/ops/flydsl/AGENTS.md asks new code to use FlyDSL buffer tensors and fx.copy; porting 945 lines of hand-scheduled tile bodies would risk the bit-identity and the parity the PR claims. Reviewer should ask whether a follow-up port is wanted, and that the PR body record this as a known exception. Also compile_routed_gemm1_id_rows accepts bm in (16, 32) then asserts bm == 16 and builds tok identically for every mi: dead generality.
📝 [unverified] P6: decode_expert_tiles.py and decode_expert_gemms.py claim parity with the amd-kernels tiles (+-0.7 us per layer at 8-128 rows, cold weights, CUDA-graph replay) and tile/prefetch tuning gains (-0.3..-1.2 us per layer); no script or log of those runs is in the PR and none could be run by the validator. Author must attach the benchmark script (or link its log) so the numbers can be reproduced.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The gfx950 kernel changes require hardware correctness and latency validation, but no head-matched report was supplied and this review environment cannot run those checks.
…e fp4 cvt, gfx950 gate via get_gfx_runtime, collect the id-routing probe in CI
- router_gemm_partials: reject non-2D hidden_states before reading shape[0] (a 0-D tensor raised IndexError instead of returning None for the caller fallback).
- decode_router_common._cvt_pk_fp4: use FlyDSL's rocdl.cvt_scalef32_pk_fp4_f32 wrapper (as decode_tile_primitives._fp4) instead of the raw LLVM intrinsic.
- test_decode_id_routing: gate on get_gfx_runtime() == "gfx950" instead of a gcnArchName substring probe.
- split_tests.sh / aiter_test.sh: add flydsl_tests/test_decode_id_routing.py to the nested-file list and dispatch it through pytest (it has no script entry point), so routing regressions run in CI.
Co-Authored-By: Claude <[email protected]>
…op-k output / partials spans
splitk_biased_topk_mxfp4_mxfp8_quant: reject output rows or partials whose byte span exceeds 2**31 - 1 (the 32-bit buffer descriptor extent, which is also the masked-store sentinel), as router_gemm_partials does.
Co-Authored-By: Claude <[email protected]>
…-token error check, dispatch the test through pytest
- decode_expert_gemms: the slot buffer is torch.zeros: GEMM2 writes only slots of ids in [0, E), so a dropped route (id outside the range, ignored by wave_expert) left uninitialized rows that the caller's slot reduction summed. Test: all-dropped and mixed ids with a poisoned allocator.
- decode_expert_gemms: reject non-gfx950 devices (the tiles emit gfx950-only scaled-MFMA / conversions) via on_supported_device.
- test: per-token relative error next to the batch-wide norm, so a corrupted chunk of one row cannot hide; the pytest main block moves to the end of the file.
- aiter_test.sh: dispatch test_mega_moe_tp_decode_expert_gemms.py through pytest (module-level skips raise under `python3 file`).
Co-Authored-By: Claude <[email protected]>
…asked in the reduction); dropped-route test
Zero-filling the slot buffer measured +1.8 us (16 rows) / +4.4 us (128 rows) per decode layer (graph replay, ABAB, 035 GPU 2). The reduction masks dropped routes instead (moe_slots_shared_reduce(topk_ids=, num_experts=)); this test covers the GEMM side: ids outside [0, E) leave the valid slots and the shared expert correct.
Co-Authored-By: Claude <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
On MI300X/gfx942, two test modules skip at import, leaving no collected tests and causing pytest exit code 5 to fail the shard; architecture gating or collection-preserving skips are needed.
A module-level pytest.skip leaves no collected tests, so the per-file pytest
run exits with code 5 on MI300X shards. Use a module-wide skipif mark.
Co-Authored-By: Claude <[email protected]>
Module-wide skipif instead of a module-level skip, so the per-file pytest run
does not exit 5 (no tests collected) on MI300X shards. Also gate on gfx950
exactly, as the kernels do.
Co-Authored-By: Claude <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed to evaluate an unpublished CUDA device-context risk affecting GEMM launches and first-time compilation when operands are on a non-current GPU.
Status for the Copilot overviews (latest on 86976cfde) and the aiter-bot self-review: inline findings are answered in their threads (fixed in dc41ed3 / 088b7a1 / 86976cf, or not applicable with evidence); tracked with a decision pending: legacy buffer_ops migration, benchmark entry point, per-expert varying weight scales in the reference test. The description now has the PR Self-Review section for revision 86976cf.
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, #8676fused_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third PR of the MiniMax-M3.1 decode MoE series (E128 top-4, H6144 / I768, MXFP4 routed experts + MXFP8 shared expert, 8-128 rows, gfx950): the expert GEMM tiles that sit on top of the routing / tile primitives (#8548) and the router chain (#8553).
decode_expert_tiles.py: routed GEMM1 (gate/up + SwiGLU + MXFP4 quant; each workgroup builds its 16-row expert block fromtopk_ids, no sort launch), routed GEMM2 (top-k weighted BF16 slot rows, one writer per (token, slot)), the shared expert's MXFP8 gate/up and down tiles, and the two "shared tiles first" launches: the shared expert's workgroups run ahead of the routed ones inside the same launch, so the shared expert costs no extra launch.decode_expert_gemms.py: per-row-count tiling (tiles_for), plan / launcher selection, operand checks (device, contiguity, dtype, exact byte counts), and the two-launch hostdecode_expert_gemms(). Routing and the slot + shared reduction stay with the caller (router chain [FlyDSL] [CI] mega_moe_tp: decode-shape (1-128 row) router top-4 + MXFP4/MXFP8 input quant chain #8553, reduce [FlyDSL] MoE: one-workgroup E128 expert sort and routed-slots + shared-expert reduce #8556, integration [CK] [FlyDSL] [CI] [Perf] MiniMax-M3.1 TP4 decode MoE through fused_moe(shared_folded) + tuned rows + --decode-chain tuner #8676).op_tests/test_mega_moe_tp_decode_expert_gemms.py: an independent fp32 torch reference test (mandatory) and an optional amd-kernels bitwise test.Every tiling keeps the K order, so the outputs are the same bits for any tile / prefetch choice. Ported from amd-kernels (
gemm{1,2}_a4w4_id_rows,shared_gemm{1,2}_a8w8; Apache-2.0, credited in the headers); noamd_kernelsimport.Performance (MI355X gfx950, real MiniMax-M3.1 layer weights, TP4 shard shapes)
Parity with the amd-kernels tiles (GEMM1 + GEMM2 launches, cold weights via 4-layer rotation, CUDA-graph replay, ABAB, us per layer, this PR vs amd-kernels): 8 rows 34.58 vs 34.57, 32 rows 65.84 vs 65.65, 64 rows 79.91 vs 79.99, 128 rows 104.62 vs 104.64; within +-0.7 us at every row count, the sign flips with launch order. No end-to-end gain by itself; the gain of the whole chain is in #8676.
Tests / how to run
pytest op_tests/test_mega_moe_tp_decode_expert_gemms.py(gfx950): 14 passed, 15 skipped (the amd-kernels bitwise tests, package not installed); per-token and batch Frobenius gates against the fp32 reference. Collected and skipped (not an empty run) on non-gfx950 GPUs.Triton Tests (MI35X) / Shard 4(test_gemm_a16wfp4); this PR does not touch Triton.Dependencies / merge order
#8548 -> #8553 -> #8555 -> #8676 (#8556 independent). This branch contains #8553's commits (merged, not rebased); its own delta: ganyi1996ppo/aiter@ganyi/mega-moe-tp-router-chain...ganyi/mega-moe-tp-decode-expert-tiles
PR Self-Review
Reviewed revision
86976cf
Behavior and intent
Adds the 8-128 row expert GEMM1/GEMM2 tiles with the shared expert folded in, on top of #8553.
Validation and unverified scope
168/168 bitwise calls vs amd-kernels tiles; fp32 torch reference test (14 passed, 15 amd-kernels tests skipped); timing within +-0.7 us. Not verified: gfx942 skip path (no such GPU available).
PR-specific question
Only adds test files to the existing pytest lists (inherited); 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).🤖 Generated with Claude Code