Repository navigation
[FlyDSL] MegaMoEV2: SwiGLU-OAI GEMM1 activation - #8920
Conversation
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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
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]>
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 positiveswiglu_limit: the gate is clamped above, the up projection to plus or minus the limit, then gate * sigmoid(1.702 * gate) * (up + 1).gated_act_f32ingemm_util.py, serves both GEMM1 epilogues:SiluQuantEpilogue(staged route) andmake_ring_gemm1(fused small-input kernel). The small-input kernel name carries the activation.--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.m31network and an MX rounding emulation (_reference(quantize=...)).Review focus
gated_act_f32reusesact.swiglu_mul_batch, the activation's existing FlyDSL definition, so it matchesaiter.fused_moe'sswiglu.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
combine_wire: [FlyDSL] MegaMoEV2: combine_wire option that every route honours #8922.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'saiter/ops/flydsl,aiter/aot,aiter/utility,op_tests/multigpu_testsandtestsover the image's aiter. Fromop_tests/multigpu_tests: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_gemm1given "silu" instead ofact) gave 55 of 64 cases FAIL.PR Self-Review
Reviewed revision
c884cde9c144Behavior and intent
MegaMoEV2(act="swigluoai")is new and requires a positiveswiglu_limit. Both GEMM1 epilogues compute it throughgated_act_f32:SiluQuantEpilogueon the staged route andmake_ring_gemm1in 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_f32calls the samesilu_mul_f32for 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'saiter/ops/flydsl,aiter/aot,aiter/utility,op_tests/multigpu_testsandtestscopied over the image's aiter. Commands run fromop_tests/multigpu_tests.GPU runs on
ef6599c43, which contains this layer's kernel commit unchanged. The kernel code is the same as atef6599c43, where the GPU tests ran; the AOT commits change onlyaiter/aot/flydsl/mega_moe.pyandtests/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.tests/test_aot_drivers.py::MegaMoEProductionJobsTestatc884cde9c: 4 passed, including the newtest_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:
ef6599c43ran.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, andMegaMoEV2(act="swigluoai")raisedValueError, 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(outsideop_tests/):test_swigluoai_job_is_its_own_profilewould pass on main too:default_jobsalready names any non-SiLU act. It pins the job fields the new--act swigluoaichoice 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 them31network (M3.1 EP4 shapes, SwiGLU-OAI at 7) and the SwiGLU-OAI branch of the fp32 reference. It also adds_mx_roundand_reference(quantize=(input, hidden)), which emulate the op's MX rounding of its input and GEMM1 output.tests/test_aot_drivers.py(outsideop_tests/): the SwiGLU-OAI job test above.🤖 Generated with Claude Code