Skip to content

[FlyDSL] MegaMoEV2: SwiGLU-OAI GEMM1 activation - #8920

Merged
zufayu merged 2 commits into
mainfrom
mengqing/megamoe-swiglu-oai
Dec 2, 2026
Merged

zufayu merged 2 commits into
mainfrom
mengqing/megamoe-swiglu-oai

Conversation

@MengqingCao

@MengqingCao MengqingCao commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review. No blocking issues. Bottom of a stack of three (gh stack): the M3.1 EP4 layout and combine_wire PRs build on this branch. Replaces #8916 (same commit, now from a ROCm/aiter branch so the stack can be linked).

Why

MiniMax-M3.1's experts use SwiGLU-OAI, but MegaMoEV2 accepts only SiLU or SiTUv2 as its gated activation. An M3.1 caller cannot run its experts through MegaMoEV2 with the right numerics.

What changed

  • MegaMoEV2(act="swigluoai") with a positive swiglu_limit: the gate is clamped above, the up projection to plus or minus the limit, then gate * sigmoid(1.702 * gate) * (up + 1).
  • One helper, gated_act_f32 in gemm_util.py, serves both GEMM1 epilogues: SiluQuantEpilogue (staged route) and make_ring_gemm1 (fused small-input kernel). The small-input kernel name carries the activation.
  • AOT driver: --act swigluoai, clamped at --swiglu-limit; the job name carries the act, so it does not collide with a SiLU job of the same shape.
  • Test: the fp32 reference gains the activation, an m31 network and an MX rounding emulation (_reference(quantize=...)).

Review focus

  • gated_act_f32 reuses act.swiglu_mul_batch, the activation's existing FlyDSL definition, so it matches aiter.fused_moe's swiglu.

Testing

The staged route at M3.1 shapes matches the fp32 SwiGLU-OAI reference, both quants. The fused route uses it in the next PR of the stack.
ef6599c43 (this branch's kernel code plus the next two layers): M3.1 size suite bs 1/104/512 relL2 0.053, graph replay PASS. c884cde9c: AOT driver tests 4 passed. ruff, black clean.

Follow-ups

Dev record

Found. none

Decided. The large-input kernel's epilogue stays SiLU only: no fused layout needs another activation there.

Surprised. none

Left undone. This commit alone was not run on GPU; the stack head was, and it contains this commit unchanged. Not run: MI300X, MI250X, EP8.

Evidence

4 x MI355X (gfx950), image mengqing-108/agx:c2f06e01-mega-a40489a9e (FlyDSL 0.5.3), the stack head's aiter/ops/flydsl, aiter/aot, aiter/utility, op_tests/multigpu_tests and tests over the image's aiter. From op_tests/multigpu_tests:

torchrun --nproc-per-node 4 test_mega_moe_v2.py --network m31 --bs-list 1,104,512 --accuracy-max-bs 512
[MEGA-V2] bs=1 relL2=0.053168 path=compact graph_replay=PASS p2p_quant=none
[MEGA-V2] bs=104 relL2=0.053423 path=compact graph_replay=PASS p2p_quant=none
[MEGA-V2] bs=512 relL2=0.053476 path=compact graph_replay=PASS p2p_quant=none

SwiGLU-OAI on the ring GEMM1 (from the next PR's routes suite): every fused call equals the staged route at relL2 0.000000 (a8w4). The pre-merge revert-red on the same code (make_ring_gemm1 given "silu" instead of act) gave 55 of 64 cases FAIL.

PR Self-Review

Reviewed revision

c884cde9c144

Behavior and intent

MegaMoEV2(act="swigluoai") is new and requires a positive swiglu_limit. Both GEMM1 epilogues compute it through gated_act_f32: SiluQuantEpilogue on the staged route and make_ring_gemm1 in the fused small-input kernel. The gate is clamped above at the limit, the up projection to plus or minus the limit, then gate * sigmoid(1.702 * gate) * (up + 1).

Before this PR, MegaMoEV2 rejected any activation but SiLU and SiTUv2. MiniMax-M3.1's experts use SwiGLU-OAI, so M3.1 could not run through MegaMoE with its own numerics. SiLU and SiTUv2 are unchanged: gated_act_f32 calls the same silu_mul_f32 for SiLU. The small-input kernel name changes only when the activation is not SiLU.

Validation and unverified scope

Hardware and config: 4 x MI355X (gfx950, pit2-p03-g07 GPUs 4-7), image mengqing-108/agx:c2f06e01-mega-a40489a9e (FlyDSL 0.5.3), the tree's aiter/ops/flydsl, aiter/aot, aiter/utility, op_tests/multigpu_tests and tests copied over the image's aiter. Commands run from op_tests/multigpu_tests.
GPU runs on ef6599c43, which contains this layer's kernel commit unchanged. The kernel code is the same as at ef6599c43, where the GPU tests ran; the AOT commits change only aiter/aot/flydsl/mega_moe.py and tests/test_aot_drivers.py.

  • torchrun --nproc-per-node 4 test_mega_moe_v2.py --network m31 --bs-list 1,104,512 --accuracy-max-bs 512: staged route relL2 against the fp32 SwiGLU-OAI reference 0.0532 / 0.0534 / 0.0535, graph replay PASS.
  • torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152: 64 PASS, 0 FAIL each. The a8w4 fused output (ring GEMM1 with SwiGLU-OAI) equals the staged output at relL2 0.000000.
  • torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network v41_flash --quant a8w4 --time-bs 104 (SiLU, unchanged path): 57 PASS.
  • black 26.10.1 and ruff 0.16.0 clean on the changed files.
  • tests/test_aot_drivers.py::MegaMoEProductionJobsTest at c884cde9c: 4 passed, including the new test_swigluoai_job_is_its_own_profile. The PA-Gluon import at the file's top needs a GPU for Triton's arch probe, so on the CPU node it was stubbed.

Unverified:

  • This layer alone on GPU: only the stack's kernel code at ef6599c43 ran.
  • EP8 and EP2 layouts; MI300X and MI250X.
  • Main moved two commits since the base (to 4349c99ce); neither touches MegaMoE or its tests.

PR-specific question

The only changed op test is op_tests/multigpu_tests/test_mega_moe_v2.py. Before this PR it had no --network m31, and MegaMoEV2(act="swigluoai") raised ValueError, so the M3.1 size-suite run fails at construction. With this PR, that run checks the op's output against an fp32 SwiGLU-OAI reference. No canonical test covers it: every other MegaMoEV2 network uses SiLU (v4_pro, v41_flash, glm52, r1_v3) or SiTUv2 (kimi_k3_route). aiter.fused_moe's SwiGLU tests exercise a different kernel.

tests/test_aot_drivers.py (outside op_tests/): test_swigluoai_job_is_its_own_profile would pass on main too: default_jobs already names any non-SiLU act. It pins the job fields the new --act swigluoai choice feeds (act, limit, a name apart from SiLU's), which #8921's profile relies on.

Changed op tests

  • op_tests/multigpu_tests/test_mega_moe_v2.py: adds the m31 network (M3.1 EP4 shapes, SwiGLU-OAI at 7) and the SwiGLU-OAI branch of the fp32 reference. It also adds _mx_round and _reference(quantize=(input, hidden)), which emulate the op's MX rounding of its input and GEMM1 output.
  • tests/test_aot_drivers.py (outside op_tests/): the SwiGLU-OAI job test above.

🤖 Generated with Claude Code

MiniMax-M3.1's experts use SwiGLU-OAI: the gate clamped above and the
up projection to +-swiglu_limit, then gate * sigmoid(1.702 * gate) *
(up + 1). MegaMoEV2 accepts act="swigluoai" (with a positive
swiglu_limit) and applies it in both GEMM1 epilogues through one helper,
gated_act_f32: the shared SiluQuantEpilogue (staged route) and the ring
GEMM1 of the fused small-input kernel, which takes act and keys its
kernel name on it.

The test reference gains the activation, an "m31" network and an MX
rounding emulation (_reference(quantize=(input, hidden))) for an error
check against the op's own quantization.

Co-Authored-By: Claude <[email protected]>
@MengqingCao
MengqingCao added this pull request to stack #8923 November 30, 2026 08:23
@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 8920 --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.

@MengqingCao
MengqingCao marked this pull request as ready for review November 30, 2026 08:32
@MengqingCao
MengqingCao requested a review from a team November 30, 2026 08:32
@aiter-bot

aiter-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision c884cde9c144 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

`MegaMoEV2(act="swigluoai")` is new and requires a positive `swiglu_limit`. Both GEMM1 epilogues compute it through `gated_act_f32`: `SiluQuantEpilogue` on the staged route and `make_ring_gemm1` in the fused small-input kernel. The gate is clamped above at the limit, the up projection to plus or minus the limit, then gate * sigmoid(1.702 * gate) * (up + 1).

Before this PR, MegaMoEV2 rejected any activation but SiLU and SiTUv2. MiniMax-M3.1's experts use SwiGLU-OAI, so M3.1 could not run through MegaMoE with its own numerics. SiLU and SiTUv2 are unchanged: `gated_act_f32` calls the same `silu_mul_f32` for SiLU. The small-input kernel name changes only when the activation is not SiLU.

Validation and unverified scope

Hardware and config: 4 x MI355X (gfx950, pit2-p03-g07 GPUs 4-7), image `mengqing-108/agx:c2f06e01-mega-a40489a9e` (FlyDSL 0.5.3), the tree's `aiter/ops/flydsl`, `aiter/aot`, `aiter/utility`, `op_tests/multigpu_tests` and `tests` copied over the image's aiter. Commands run from `op_tests/multigpu_tests`.
GPU runs on `ef6599c43`, which contains this layer's kernel commit unchanged. The kernel code is the same as at `ef6599c43`, where the GPU tests ran; the AOT commits change only `aiter/aot/flydsl/mega_moe.py` and `tests/test_aot_drivers.py`.
- `torchrun --nproc-per-node 4 test_mega_moe_v2.py --network m31 --bs-list 1,104,512 --accuracy-max-bs 512`: staged route relL2 against the fp32 SwiGLU-OAI reference 0.0532 / 0.0534 / 0.0535, graph replay PASS.
- `torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network m31 --quant {a8w4,a4w4} --mtpr 1024 --combine-wire bf16 --check-time-acc --time-bs 104,144,152`: 64 PASS, 0 FAIL each. The a8w4 fused output (ring GEMM1 with SwiGLU-OAI) equals the staged output at relL2 0.000000.
- `torchrun --nproc-per-node 4 test_mega_moe_v2.py --suite routes --network v41_flash --quant a8w4 --time-bs 104` (SiLU, unchanged path): 57 PASS.
- black 26.10.1 and ruff 0.16.0 clean on the changed files.
- `tests/test_aot_drivers.py::MegaMoEProductionJobsTest` at `c884cde9c`: 4 passed, including the new `test_swigluoai_job_is_its_own_profile`. The PA-Gluon import at the file's top needs a GPU for Triton's arch probe, so on the CPU node it was stubbed.

Unverified:
- This layer alone on GPU: only the stack's kernel code at `ef6599c43` ran.
- EP8 and EP2 layouts; MI300X and MI250X.
- Main moved two commits since the base (to `4349c99ce`); neither touches MegaMoE or its tests.

PR-specific question

The only changed op test is `op_tests/multigpu_tests/test_mega_moe_v2.py`. Before this PR it had no `--network m31`, and `MegaMoEV2(act="swigluoai")` raised `ValueError`, so the M3.1 size-suite run fails at construction. With this PR, that run checks the op's output against an fp32 SwiGLU-OAI reference. No canonical test covers it: every other MegaMoEV2 network uses SiLU (v4_pro, v41_flash, glm52, r1_v3) or SiTUv2 (kimi_k3_route). `aiter.fused_moe`'s SwiGLU tests exercise a different kernel.

`tests/test_aot_drivers.py` (outside `op_tests/`): `test_swigluoai_job_is_its_own_profile` would pass on main too: `default_jobs` already names any non-SiLU act. It pins the job fields the new `--act swigluoai` choice feeds (act, limit, a name apart from SiLU's), which #8921's profile relies on.

Changed op tests

- `op_tests/multigpu_tests/test_mega_moe_v2.py`: adds the `m31` network (M3.1 EP4 shapes, SwiGLU-OAI at 7) and the SwiGLU-OAI branch of the fp32 reference. It also adds `_mx_round` and `_reference(quantize=(input, hidden))`, which emulate the op's MX rounding of its input and GEMM1 output.
  - Not redundant: no existing network runs SwiGLU-OAI.
  - The fp32 comparison (tolerance 0.08) cannot see a rounding-scale bug. The emulation can: the op's error against it is about 0.0024. #8921's bench gates on it.
- `tests/test_aot_drivers.py` (outside `op_tests/`): the SwiGLU-OAI job test above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

The AOT driver's --act takes swigluoai, clamped at --swiglu-limit (its
alpha, 1.702, is fixed in the kernel). The job name carries the act, so
a SwiGLU-OAI profile does not collide with a SiLU one of the same shape.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants