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 id routing, GEMM tile primitives and the router GEMM (1-128 rows) - #8548
First PR of the MiniMax-M3.1 decode MoE series (E128 top-4, H6144 / I768, 1-128 rows, gfx950). It adds the building blocks of mega_moe_tp that the decode path needs and that aiter did not have, so the decode MoE can run without the amd-kernels package:
decode_id_routing.py: in-kernel canonical expert-block routing for 8-128 decode rows. One workgroup builds its 16-row expert block straight from topk_ids (LDS-atomic histogram + DPP wave scan), so there is no separate sort launch and no global atomics. Ids outside [0, E) are ignored.
Ported from amd-kernels (moe/mxfp4_h6144_i768_e128_top4, Apache-2.0, credited in the file headers); kernel bodies are unchanged, imports moved to aiter's buffer_ops / tensor_shim. No amd_kernels import.
Performance (MI355X gfx950, 1 GPU)
These are primitives and a router GEMM that replace the amd-kernels originals, so the goal is parity, not a speedup of their own:
Router GEMM, CUDA-graph replay, vs amd-kernels: 2.00 / 2.07 / 2.11 / 2.33 / 2.35 / 2.40 us at 1 / 8 / 16 / 17 / 24 / 32 rows (equal within +-0.01 us); 33-128 rows within +-0.03 us (2.0 .. 3.4 us). Eager host time is +0.2..0.4 us per call (irrelevant under graphs).
Primitives: the expert kernel assembled from them (private model-side integration, not in this PR) measured -21.3 / -12.1 / -13.4 us vs production at n=16/24/32 rows, within +0.2..+1.7 us of the pre-port amd-kernels version (200 iterations).
pytest op_tests/flydsl_tests/test_decode_id_routing.py: torch oracle for the routing, 8..128 rows, partial blocks, skewed / all-one-expert ids, ids outside [0, E) (40 passed on gfx950). Wired into aiter_test.sh; the module is collected and skipped (not an empty run) on non-gfx950 GPUs.
pytest op_tests/test_decode_router_gemm.py: partials sum to x @ W.T (fp64 reference), 1-128 rows (30 passed).
Known unrelated CI failure: Triton Tests (MI35X) / Shard 4 (test_gemm_a16wfp4), see the PR discussion; this PR does not touch Triton.
Dependencies / merge order
Merge order of the series: #8548 -> #8553 -> #8555 -> #8676; #8556 is independent. #8553 and #8555 branches contain this PR's commits (merged, not rebased), so their diffs shrink once this one lands. #8548 absorbs the earlier #8551 / #8552 (closed).
Adds the decode routing / tile primitives and the 1-128 row router GEMM (previously #8548, #8551, #8552) so the MiniMax-M3.1 decode MoE can run without amd-kernels.
Validation and unverified scope
Router partials and the assembled kernel are bit-identical to amd-kernels and at kernel-time parity (see Performance). Not verified: no standalone benchmark of the primitives; CI Triton shards were flaky/pending at this revision.
PR-specific question
This PR touches .github/scripts/aiter_test.sh / split_tests.sh only to add test files to the existing pytest lists: no workflow, permission or secret change, and no fork-controlled text reaches a privileged step.
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.
…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]>
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 8548 --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.
Adds decode-shape MoE primitives to aiter’s mega_moe_tp family without an amd_kernels runtime dependency. This is a helpers-only addition; complete fused-kernel integration remains a follow-up.
Changes:
Adds in-kernel routing for E128/top-4 inputs into canonical 16-row expert blocks.
Adds gfx950 MXFP4/MXFP8 scaled-MFMA, SwiGLU, and quantization helpers.
Provides host-side routing-capacity and tile-sizing utilities.
…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]>
…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]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The routing helper can silently drop tokens because its default scan capacity is too small and corrupt scratch memory by treating out-of-range expert IDs as histogram indices.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The routing probe is not wired into CI discovery or execution, and the device compute helpers lack numerical tests for scaling, transpose handling, packing, and clamping.
The routing probe imports only id_pairs_for and max_sorted_rows, leaving this module's device compute helpers untested. Errors in MFMA scale-byte selection, transpose handling, packing, or activation clamping would go undetected by the added tests. Add small gfx950 probes with independent numerical references for A4W4/A8W8, activation, and quantization, using nonconstant scales and inputs that trigger the clamps; op_tests/flydsl_tests/test_silu_and_mul_fq.py provides a reference pattern.
Adds two helper modules: an in-kernel canonical expert-block routing primitive for 8-128 decode rows (no sort launch) and gfx950 scaled-MFMA / SwiGLU / MXFP4-MXFP8 quant tile primitives.
Review (advisory): ⚠️ NEEDS WORK, the findings below are fixed on the branch (commits 1b1d58d, 264be23); not independently refuted
Validation (deterministic): NOT RUN — validate_pr.sh needs a built aiter worktree and the PR shipped no test target, so there was no base to compare; hand-run on node 035 GPU 0 instead (advisory): new test_decode_id_routing.py 40/40 pass; with the id-range guard removed the out-of-range case fails (padding rows 96 -> 97/99); the amd-kernels bit-identical tile test (15 tests) and the router tests (83) also pass with the converts moved to the rocdl wrappers
Perf (advisory): NOT RUN — the primitives have no standalone benchmark; the PR's quoted -21.3/-12.1/-13.4 us is for the assembled kernel in #8555 and is [unverified] here
Size: 388 lines / 2 files
Design (advisory): in-kernel per-workgroup routing (LDS-atomic histogram + DPP scan + ballot) in place of a sort launch
Human: recommend vpietila-amd review whether an in-kernel routing primitive belongs in mega_moe_tp for PR 8548 or should reuse moe_sorting
🔴 [verified] decode_id_routing.py wave_expert defaulted pairs=256 scans only 64 rows although the docstring supports 128: with m=96 and every row routed to ids 0-3, 256 of 384 pairs are scanned, 16 blocks are built instead of 24 and tokens 64-95 are dropped. Fixed: pairs is now required (callers pass id_pairs_for(m)).
🔴 [verified] decode_id_routing.py wave_expert accepted only ids >= 0: ids >= 128 index the histogram, id 256+r increments row-table slot r (corrupting padding rows, reproduced on GPU 035: padding 96 -> 97/99) and id 336 writes past the wave's 1344-byte slice. Fixed: ids outside [0,128) go to the lane's dummy slot; the new test fails without the guard. ⚠️ [verified] decode_tile_primitives.py docstring and _fp4/_fp8 said FlyDSL has no wrapper for the packed converts, but mega_moe_tp/common.py already calls rocdl.cvt_scalef32_pk_fp4_f32 / fp8_f32. Fixed: both now use the wrappers, bit-identical on the 057 amd-kernels oracle test. ⚠️ [verified] decode_id_routing.py shipped with no collectible test for the routing primitive (no test_*.py in the PR, kernel_tests.txt lists both files). Fixed: op_tests/flydsl_tests/test_decode_id_routing.py (torch oracle, 8-128 rows, partial blocks, skewed/all-one-expert, out-of-range ids). Still open: MFMA / quant primitives have no standalone test; they are covered through #8555's bit-identical test. Author should add isolated scale/clamp boundary tests or state that #8555 is the coverage.
📝 [inferred] wave_expert still loads ids with the legacy buffer_ops helper, as the rest of mega_moe_tp does; the flydsl AGENTS guidance prefers buffer tensors. Reviewer should ask whether a family-wide migration is wanted rather than a one-off here.
…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]>
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
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The routing probe is not wired into CI, and the router indexes tensor dimensions before validating rank, causing zero-dimensional inputs to raise IndexError instead of allowing fallback.
…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]>
…#8555) into moe-decode-fmoe-tuner
# Conflicts:
# .github/scripts/aiter_test.sh
github-actionsBot
changed the title
[FlyDSL] mega_moe_tp: decode id routing, GEMM tile primitives and the router GEMM (1-128 rows)
[FlyDSL] [CI] mega_moe_tp: decode id routing, GEMM tile primitives and the router GEMM (1-128 rows)
Nov 26, 2026
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]>
Status for the Copilot overviews (latest on 037494656) and the aiter-bot self-review: all inline findings are answered in their threads (fixed in 6b89b92 / 0374946, or not applicable with evidence); two are tracked with a decision pending (legacy buffer_ops migration, benchmark entry point). The description now has the PR Self-Review section for revision 0374946. Open: Triton Tests (MI35X) shard failure on this run, unrelated to this PR (no Triton files), rerun pending.
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
First PR of the MiniMax-M3.1 decode MoE series (E128 top-4, H6144 / I768, 1-128 rows, gfx950). It adds the building blocks of
mega_moe_tpthat the decode path needs and that aiter did not have, so the decode MoE can run without the amd-kernels package:decode_id_routing.py: in-kernel canonical expert-block routing for 8-128 decode rows. One workgroup builds its 16-row expert block straight fromtopk_ids(LDS-atomic histogram + DPP wave scan), so there is no separate sort launch and no global atomics. Ids outside[0, E)are ignored.decode_tile_primitives.py: scaled-MFMA wrappers (MXFP4 A4W4, MXFP8 A8W8), SwiGLU-OAI and MXFP4/MXFP8 row quantization for the 8-128 row GEMM tiles (used by [FlyDSL] [CI] mega_moe_tp: decode-shape (8-128 row) MoE expert GEMM1/GEMM2 tiles with the shared expert folded in #8555).decode_router_gemm*.py(was [FlyDSL] [CI] mega_moe_tp: decode-shape (1-32 row) router GEMM split-K partials #8551 and [FlyDSL] [CI] mega_moe_tp: decode router GEMM to 128 rows (n-blocks kernel, optional input-quant workgroups) #8552, now merged into this PR): bf16x3 split-K router GEMM for 1-128 rows with a fixed split-K order, so the top-4 ids match the reference bit for bit; tier dispatchrouter_gemm_partials(1-16 / 17-32 / 33-128 rows).Ported from amd-kernels (
moe/mxfp4_h6144_i768_e128_top4, Apache-2.0, credited in the file headers); kernel bodies are unchanged, imports moved to aiter'sbuffer_ops/tensor_shim. Noamd_kernelsimport.Performance (MI355X gfx950, 1 GPU)
These are primitives and a router GEMM that replace the amd-kernels originals, so the goal is parity, not a speedup of their own:
Tests / how to run
pytest op_tests/flydsl_tests/test_decode_id_routing.py: torch oracle for the routing, 8..128 rows, partial blocks, skewed / all-one-expert ids, ids outside[0, E)(40 passed on gfx950). Wired intoaiter_test.sh; the module is collected and skipped (not an empty run) on non-gfx950 GPUs.pytest op_tests/test_decode_router_gemm.py: partials sum tox @ W.T(fp64 reference), 1-128 rows (30 passed).Triton Tests (MI35X) / Shard 4(test_gemm_a16wfp4), see the PR discussion; this PR does not touch Triton.Dependencies / merge order
Merge order of the series: #8548 -> #8553 -> #8555 -> #8676; #8556 is independent. #8553 and #8555 branches contain this PR's commits (merged, not rebased), so their diffs shrink once this one lands. #8548 absorbs the earlier #8551 / #8552 (closed).
PR Self-Review
Reviewed revision
0374946
Behavior and intent
Adds the decode routing / tile primitives and the 1-128 row router GEMM (previously #8548, #8551, #8552) so the MiniMax-M3.1 decode MoE can run without amd-kernels.
Validation and unverified scope
Router partials and the assembled kernel are bit-identical to amd-kernels and at kernel-time parity (see Performance). Not verified: no standalone benchmark of the primitives; CI Triton shards were flaky/pending at this revision.
PR-specific question
This PR touches
.github/scripts/aiter_test.sh/split_tests.shonly to add test files to the existing pytest lists: no workflow, permission or secret change, and no fork-controlled text reaches a privileged step.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.🤖 Generated with Claude Code