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
Second of three stacked PRs moving the decode MoE router front end (E128 top-4, H6144, 1-128 rows) from amd-kernels into aiter. Stacked on #8548 (the _fp8 / _e8m0_fp8 quant primitives) and on #8551 (the 1-32 row router GEMM, included here as its first commit until it merges); the diff of this PR alone is the last commit, 525 lines.
Change
decode_router_gemm_nblocks.py: the 33-128 row router GEMM (split-48 to 64 rows, split-16 above; two waves to 32 rows, 4 / 8 waves above), optionally with MXFP4 + MXFP8 input-quant workgroups appended or prepended to the same launch (the quant is consumed by the top-4 + quant chain in the next PR).
decode_router_gemm.py: router_gemm_partials extended to 128 rows (the gate line-layout copy stays optional).
decode_router_common.py: fp32/int32 bit casts and the Quark-even e8m0 / FP4 convert arithmetic used by the quant group.
op_tests/test_decode_router_gemm.py: rows 1-128.
Ported from amd-kernels' moe/mxfp4_h6144_i768_e128_top4/router_gemm_nblocks.py and the tier logic of router_gemm.py (Apache-2.0, "Copyright contributors to the amd-kernels project"); kernel bodies unchanged. No amd_kernels import.
Verification (MI355X gfx950)
Partials bit-identical to amd-kernels' router_gemm_partials for every row count 1..128, three input kinds, with and without the line-layout gate: 672/672.
…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]>
…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]>
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 8552 --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
Unresolved critical defects can corrupt quantization for padded row strides, reuse device-bound launch state across GPUs, and dispatch kernels exceeding gfx942 shared-memory limits.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical launch-safety issues remain: the raw-weight path accepts CPU or mismatched-device pointers, compiled handles are reused across GPUs, and unsupported configurations exceed gfx942 shared-memory limits.
A nonzero BF16 row expanded to [33, 6144] passes the wrapper's stride checks, but stride(0)=0 makes this input descriptor contain zero records, so the repeated row's loads are out of bounds. Other overlapping row layouts can also have their valid data truncated by this bound. Size the descriptor through the last logical element, ((m - 1) * sx + H) * 2, or explicitly reject these layouts in the wrapper.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Critical defects remain in quantization stride handling, GPU tensor-device validation, and device-specific launcher caching, while key correctness tests are not exercised by CI.
Calling the same 33-row configuration on GPU 0 and then GPU 1, each under its correct device context, reuses the first device's compiled handle: the cached factory returns the same launcher, and _run_compiled stores one exe._cf without a specialization key (tensor_shim.py:370-384). This violates the device-bound handle contract in aiter/ops/flydsl/AGENTS.md:20-31 and can leave the second GPU's output unwritten. Add specialization_key=(torch.cuda.current_device(),) to this _run_compiled call and the line-layout calls at lines 97 and 109.
…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]>
…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]>
Extends the decode router GEMM from 32 to 128 rows with an LDS-staged n-blocks kernel that can also quantize x to MXFP4 and MXFP8 in the same launch.
Review (advisory): ⚠️ NEEDS WORK — the findings below were fixed in 82bc259 (pushed to the PR branch); reviewed on the PR's own commit 4c653cb only; not independently refuted
Validation (deterministic): NOT RUN — the auto-run had no GPU on the review host (INCONCLUSIVE, and the report was rejected for a missing jsonschema); by hand on MI355X gfx950 (node 035 GPU 0) the post-fix tree passes op_tests/test_decode_router_gemm.py 63/63, and the original quant helper fails all 10 padded-stride quant cases
Perf (advisory): NOT RUN — no in-tree timing harness and the PR adds new kernels (no base to time against); the PR's "within +-0.03 us versus amd-kernels" figures come from a harness that imports amd-kernels and is not in the tree, so they are [unverified]
Size: 1673 lines / 9 files — over the review bar (the PR's own commit is 525 lines; the rest is #8548 and #8551, included until they merge)
Design (advisory): SPLIT — already split by stack: #8548 decode primitives / #8551 the 1-32 row GEMM / this commit's 33-128 row kernel; the optional input-quant workgroups (decode_router_gemm_nblocks.py quant 1 and 2) could land after the GEMM tier with the chain PR that consumes them
Human: recommend zufayu review whether PR #8552's input-quant workgroups should live in the router GEMM launch (appended or prepended) or stay a separate quant kernel for the chain
⚠️ [verified] aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm.py router_gemm_partials has no arch or device gate: the 65-128 row tier allocates 69632 B of LDS (w 36864 + x 32768 in aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm_nblocks.py) against gfx942's 65536 and issues mfma_f32_16x16x32_bf16 (gfx950 only), and lines_ok accepts a CPU or foreign-device line-layout copy as a raw GPU address. Impact: on gfx942 the 65-128 row call fails at compile or launch instead of returning None for a fallback; a host copy becomes an invalid GPU pointer. Author must return None off gfx950 and unless every tensor is CUDA storage on one device. Fixed: on_supported_device over x, gate and the copy, launch under that device and stream. ⚠️ [verified] aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm_nblocks.py _dual_quant_group ignores the row stride that the same kernel's GEMM path honors: x is read at blk * 16 dwords with a m * 6144 * 2 descriptor, so for a [m, 6144] view with row stride 6176 the quant of row 1 reads row 0's padding while the GEMM reads the right values (reachable through _get_kernel(..., quant=1|2, ...), which the chain PR calls with a contiguous x). Impact: silently wrong MXFP4/MXFP8 inputs for any strided caller. Author must pass i32_sx to the quant group. Fixed (rows addressed as row * i32_sx, group offset separate); a mutation run of the original helper fails 10 of 10 padded-stride cases and passes the 10 packed ones. ⚠️ [verified] op_tests/test_decode_router_gemm.py never exercises quant 1 or quant 2 (every case goes through router_gemm_partials, which passes quant=0), cannot see split-slot permutation, and CI runs it as python3 file, which collects no pytest case. Impact: the stores, the e8m0 scale arithmetic and the appended/prepended workgroup indexing can regress unseen. Author must test both modes and run the file under pytest. Fixed: test_input_quant_workgroups (scales exactly against a torch rule, elementwise e4m3/e2m1 error bounds, per-row reconstruction, partials still sum to the logits; packed and padded rows, 5 row counts, both placements), per-chunk oracle, aiter_test.sh pytest dispatch. ⚠️ [inferred] aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm_nblocks.py _get_kernel is functools.cached on constants and _run_compiled is called without a specialization key, so the same configuration on cuda:0 then cuda:1 reuses one compiled handle (aiter/ops/flydsl/AGENTS.md: it does not launch on the other device and the error is printed, not raised). Impact: unwritten partials in a single-process multi-GPU run. Author must keep one launcher per GPU. Fixed through kernels/topk/topk_launch._launcher_on; a second GPU was not available, the single-GPU path is verified.
📝 [verified] aiter/ops/flydsl/kernels/mega_moe_tp/decode_router_gemm.py router_gemm_partials reads router_weight for 33-128 rows and router_weight_lines for 1-32 rows, so a gate and a copy that differ give tier-dependent results that no kernel can detect. Reviewer should ask whether one argument should be derived from the other; the contract is documented in the docstring.
Triage of the existing Copilot comments: gfx942 LDS (69632 B vs 65536), CPU/cross-device line-layout copy, _run_compiled specialization/device handle, stream: real, fixed in 82bc259 via an arch/device gate and a per-GPU launcher. Quant ignoring i32_sx: real (mutation-confirmed), fixed. Quant modes untested: real, test_input_quant_workgroups added (both placements, packed and padded rows). Test not run by CI: fixed through the pytest dispatch in aiter_test.sh. Also cherry-picked the #8548 test follow-up 264be23 (test-only) so the stack stays consistent.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The routing regressions are not wired into CI, quantization tests omit zero and tiny groups needed to exercise the scale floor, and the router suite lacks the required reproducible performance harness.
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
ganyi1996ppo
added a commit
to ganyi1996ppo/aiter
that referenced
this pull request
Nov 24, 2026
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
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The decode router duplicates an existing FP4 conversion helper with a raw LLVM intrinsic without the required justification and should reuse _fp4 instead.
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.
Motivation
Second of three stacked PRs moving the decode MoE router front end (E128 top-4, H6144, 1-128 rows) from amd-kernels into aiter. Stacked on #8548 (the
_fp8/_e8m0_fp8quant primitives) and on #8551 (the 1-32 row router GEMM, included here as its first commit until it merges); the diff of this PR alone is the last commit, 525 lines.Change
decode_router_gemm_nblocks.py: the 33-128 row router GEMM (split-48 to 64 rows, split-16 above; two waves to 32 rows, 4 / 8 waves above), optionally with MXFP4 + MXFP8 input-quant workgroups appended or prepended to the same launch (the quant is consumed by the top-4 + quant chain in the next PR).decode_router_gemm.py:router_gemm_partialsextended to 128 rows (the gate line-layout copy stays optional).decode_router_common.py: fp32/int32 bit casts and the Quark-even e8m0 / FP4 convert arithmetic used by the quant group.op_tests/test_decode_router_gemm.py: rows 1-128.Ported from amd-kernels'
moe/mxfp4_h6144_i768_e128_top4/router_gemm_nblocks.pyand the tier logic ofrouter_gemm.py(Apache-2.0, "Copyright contributors to the amd-kernels project"); kernel bodies unchanged. No amd_kernels import.Verification (MI355X gfx950)
router_gemm_partialsfor every row count 1..128, three input kinds, with and without the line-layout gate: 672/672.pytest op_tests/test_decode_router_gemm.py: 30 passed.Merge order
Stack: #8548 -> #8551 -> #8552 -> #8553 -> #8555. Merge after #8551. The branch contains #8551's commits (merged, not rebased), so after #8551 lands its diff against main shrinks to this PR's own content; until then GitHub shows the parents' files too. This PR's own delta now: ganyi1996ppo/aiter@ganyi/mega-moe-tp-router-gemm-small...ganyi/mega-moe-tp-router-gemm-128
🤖 Generated with Claude Code