fix(sm90): support parameterized SwiGLU in FP8 MegaMoE - #445
shiyang814-cpu wants to merge 2 commits into
Conversation
🤖 ds-review-bot Code Reviewv6JIT 格式串缺失占位符会阻断新增功能及现有标准 SwiGLU 路径。其余参数接口和激活公式与关联 MR 一致;当前环境无 CUDA 工具链,未复跑 GPU 数值测试。 v5本 MR 将 DeepGEMM #87 的参数化 SwiGLU(swigluoai)支持移植到 nv_dev 的 SM90 FP8 MegaMoE。跨仓契约核对结果:Python 入口 但存在一个阻塞性问题: 另有两处非阻塞建议: v4Cross-repo contract with sgl-project#87 is consistent at the public API level. deep_gemm.mega.fp8_mega_moe (re-exported as deep_gemm.fp8_mega_moe) exposes activation_alpha (default 1.0) and activation_up_bias (default 0.0) in exactly the same position/order as the upstream sgl_deep_gemm.fp8_mega_moe change (inserted after 'activation' and before 'activation_clamp'), the pybind binding in csrc/apis/sm90_mega.hpp forwards them in the same order, and both get_symm_buffer_size_for_sm90_mega_moe and fp8_mega_moe accept activation in {'swiglu','swigluoai'}. The kernel math matches the upstream contract: clamp_gate(g)=min(g,c), clamp_up(u)=clamp(u,-c,c), result = clamp_gate(g)sigmoid(alphaclamp_gate(g))*(clamp_up(u)+up_bias), with alpha=1.0/up_bias=0.0 reducing exactly to the old swiglu path. The reference/test wiring is also consistent. However, the port introduces one actionable code-generation defect that violates the host->kernel template calling convention in csrc/jit_kernels/impls/sm90_fp8_mega_moe.hpp. Files reviewed: 5 |
Summary
This PR adds parameterized SwiGLU support to the SM90 FP8 MegaMoE kernel.
The existing implementation assumes standard SwiGLU:
Some MoE models use parameterized OAI-SwiGLU instead:
For example, MiniMax-M3 uses:
Without these parameters, the SM90 MegaMoE kernel applies standard SwiGLU semantics to models that require OAI-SwiGLU, which produces incorrect model outputs.
Root Cause
The SM90 FP8 MegaMoE epilogues currently hardcode:
Although the activation clamp is configurable, the sigmoid alpha and up-projection bias are not represented by the Python API, host API, or JIT kernel template.
As a result, the generated kernel cannot reproduce parameterized SwiGLU semantics. This affects both the optimized swapAB epilogue and the non-swapAB epilogue.
Changes
activation_alphaandactivation_up_biasto the Python SM90 FP8 MegaMoE API.swigluoaiin the SM90 buffer allocation and execution APIs.activation_alpha=1.702activation_up_bias=1.0activation_clamp=7.0Compatibility
The new parameters default to standard SwiGLU behavior:
Therefore, existing callers that do not provide the new parameters retain the original behavior:
The new activation name is additive, and no behavior change is expected for existing SM90 MegaMoE workloads.
Validation
The change was validated on Hopper GPUs in a real two-node prefill/decode disaggregated deployment.
Environment
MiniMax-M3 uses the following OAI-SwiGLU parameters:
Kernel Accuracy
The SM90 MegaMoE kernel output was compared against the reference implementation on 8 Hopper GPUs.
Both the swapAB and non-swapAB epilogues therefore preserve the expected parameterized SwiGLU semantics.
End-to-End P/D Validation
The patched kernel was also validated in a two-node P/D deployment:
DeepEP normal was active on the prefill node.
SM90 FP8 MegaMoE was active on the decode node.
No fallback to Triton or another MoE backend occurred.
Deterministic English generation passed.
Deterministic Chinese generation passed.
MMLU smoke evaluation passed:
8/8.No corrupted output, scheduler exception, or kernel traceback was observed.
The DeepGEMM JIT cache was cleared before validation to ensure that the generated SM90 kernels were rebuilt from the patched headers.
Static Checks