Skip to content

[FlyDSL] [CI] mega_moe_tp: decode router GEMM to 128 rows (n-blocks kernel, optional input-quant workgroups) - #8552

Closed
ganyi1996ppo wants to merge 14 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mega-moe-tp-router-gemm-128
Closed

ganyi1996ppo wants to merge 14 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/mega-moe-tp-router-gemm-128

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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_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.
  • pytest op_tests/test_decode_router_gemm.py: 30 passed.
  • CUDA-graph GPU time vs amd-kernels at 1 / 8 / 16 / 17 / 24 / 32 / 48 / 64 / 96 / 128 rows: within +-0.03 us (2.0 .. 3.4 us).

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

ganyi1996ppo and others added 4 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]>
…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]>
@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot November 24, 2026 08:47
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full 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.

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 34f90313cbf6 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What permissions and untrusted-input boundary does this CI change have, and can fork PR code or text reach a privileged execution path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/flydsl_tests/test_decode_id_routing.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_decode_router_gemm.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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

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.

6 open issues
What changed in this PR

This stacked PR extends aiter’s FlyDSL decode MoE router front end to 128 rows, continuing the move away from an amd-kernels runtime dependency.

Changes:

  • Adds the n-blocks router GEMM and extends row-count-based dispatch through 128 rows.
  • Adds optional MXFP4/MXFP8 input-quantization workgroups within the same launch.
  • Expands router tests across row counts and optional gate layouts.
File Description
op_tests/​test_decode_router_gemm.py Checks summed router partials across 1–128 rows and both gate-layout options.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_tile_primitives.py Supplies decode tile, activation, quantization, and tiling helpers.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm.py Selects router kernels and split-K configurations through 128 rows.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm_nblocks.py Implements n-blocks GEMM with optional dual-quantization workgroups.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm_lines.py Provides the line-layout router kernel for 17–32 rows.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm_direct.py Provides the direct router kernel for 1–16 rows.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_common.py Shares weight-splitting and quantization arithmetic.
aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_id_routing.py Supplies small-row expert routing without a separate sort launch.

Review effort: Balanced

Comment on lines +404 to +405
@functools.cache
def _get_kernel(
block_k: int,
waves: int,
nbw: int,
quant: int = 0,
Comment thread op_tests/test_decode_router_gemm.py Outdated
Comment on lines +20 to +23
@pytest.mark.parametrize(
"n", [1, 4, 8, 16, 17, 24, 32, 33, 48, 57, 58, 64, 65, 96, 128]
)
@pytest.mark.parametrize("lines", [True, False])
Copilot AI balanced review requested due to automatic review settings November 24, 2026 08:57

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

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.

7 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Size the input descriptor to cover strided and expanded rows

aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm_nblocks.py:206

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.

Review effort: Balanced

Comment on lines +133 to +134
stream,
)
ganyi1996ppo and others added 2 commits November 24, 2026 03:36
…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]>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:36
…fails without the id-range guard)

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.

🟡 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.

8 open issues
1 previously missed issue

In code that hasn't changed since last review

High severity Key compiled handles by the active CUDA device

aiter/​ops/​flydsl/​kernels/​mega_moe_tp/​decode_router_gemm.py:123

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.

Review effort: Balanced

Comment on lines +132 to +135
@pytest.mark.parametrize("kind", ["uniform", "skewed", "one"])
@pytest.mark.parametrize("m", [8, 15, 16, 17, 24, 32, 33, 64, 65, 96, 97, 128])
def test_canonical_blocks(m, kind):
_check(_ids(kind, m, seed=m).cuda())
ganyi1996ppo and others added 2 commits November 24, 2026 07:46
…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]>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:50
@github-actions github-actions Bot changed the title [FlyDSL] mega_moe_tp: decode router GEMM to 128 rows (n-blocks kernel, optional input-quant workgroups) [FlyDSL] [CI] mega_moe_tp: decode router GEMM to 128 rows (n-blocks kernel, optional input-quant workgroups) Nov 24, 2026
@github-actions github-actions Bot added the CI label Nov 24, 2026
…fails without the id-range guard)

Co-Authored-By: Claude <[email protected]>
ganyi1996ppo added a commit to ganyi1996ppo/aiter that referenced this pull request Nov 24, 2026
…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]>
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

ROCm/aiter PR #8552 — [FlyDSL] mega_moe_tp: decode router GEMM to 128 rows (n-blocks kernel, optional input-quant workgroups)

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.

🤖 Generated with Claude Code

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.

def test_input_quant_workgroups(n, quant, pad):
"""Both quants against torch: scales exactly, codes by their dequantization error bound per element, and the
router partials still sum to the logits (the extra workgroups share the launch)."""
x, w = _inputs(n, 5)
ganyi1996ppo and others added 2 commits November 24, 2026 08:16
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
@ganyi1996ppo
ganyi1996ppo marked this pull request as draft November 25, 2026 02:09
@ganyi1996ppo
ganyi1996ppo marked this pull request as ready for review November 25, 2026 02:21
Copilot AI balanced review requested due to automatic review settings November 25, 2026 02:21

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 on lines +97 to +111
return fx.Int32(
_llvm.call_intrinsic(
_T.i32,
"llvm.amdgcn.cvt.scalef32.pk.fp4.f32",
[
fx.as_ir_value(old),
fx.as_ir_value(a),
fx.as_ir_value(b),
fx.as_ir_value(scale_f32),
fx.as_ir_value(fx.Int32(sel)),
],
[],
[],
)
)
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Merged into #8548 (same router GEMM files, now one branch). Closing in favour of #8548.

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