mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[PR #409] [MERGED] Add SM100 NVFP4 MegaMoE with fused BF16 shared experts #425
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#425
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/409
Author: @zhou9402
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/27/2026
Merged by: @RayWang96
Base:
nv_dev← Head:codex/nvfp4-fused-shared-oss-pr📝 Commits (10+)
9d96576Add NVFP4 MegaMoE with fused BF16 shared expertsd0fdd21Add accurate fused shared experts to NVFP4 MegaMoEa76eedeTrim NVFP4 MegaMoE integration surfacecb1f99dAddress NVFP4 MegaMoE review feedback4d73079Fix NVFP4 MegaMoE ring reuse and edge cases2deb26aTighten NVFP4 MegaMoE validation67f0168Guard byte-based GEMM heuristics from sub-byte types1807590Keep legacy MegaMoE metadata compact814d9bcValidate NVFP4 MegaMoE buffer layout0c067edClarify NVFP4 heuristic and combine-slot invariants📊 Changes
16 files changed (+2909 additions, -51 deletions)
View changed files
📝
csrc/apis/mega.hpp(+232 -15)📝
csrc/jit_kernels/heuristics/common.hpp(+7 -0)📝
csrc/jit_kernels/heuristics/mega_moe.hpp(+28 -13)📝
csrc/jit_kernels/heuristics/sm100.hpp(+3 -2)📝
csrc/jit_kernels/heuristics/sm120.hpp(+3 -3)📝
csrc/jit_kernels/heuristics/sm90.hpp(+1 -1)📝
csrc/jit_kernels/impls/runtime_utils.hpp(+2 -0)➕
csrc/jit_kernels/impls/sm100_fp4_fp4_mega_moe.hpp(+306 -0)📝
deep_gemm/__init__.py(+1 -0)📝
deep_gemm/include/deep_gemm/common/types.cuh(+7 -1)➕
deep_gemm/include/deep_gemm/impls/sm100_fp4_fp4_mega_moe.cuh(+1778 -0)📝
deep_gemm/include/deep_gemm/layout/mega_moe.cuh(+37 -13)📝
deep_gemm/include/deep_gemm/ptx/tcgen05.cuh(+24 -0)📝
deep_gemm/include/deep_gemm/scheduler/mega_moe.cuh(+3 -2)📝
deep_gemm/mega/__init__.py(+62 -1)➕
tests/test_nvfp4_mega_moe.py(+415 -0)📄 Description
Summary
Design highlights
Native NVFP4 routed path. Both routed activations and weights use packed E2M1 data with per-16-element E4M3 scale factors. This requires a bit-aware symmetric-buffer layout, NVFP4-specific TMA/UTCCP handling, and an in-kernel L1 requantization epilogue.
Post-L2 top-k weighting. Top-k routing weights are stored in a new NVFP4-specific buffer and applied to the BF16 routed output after L2, immediately before the combine write. Applying top-k weights directly in the L1 epilogue can reduce the intermediate magnitude before NVFP4 quantization and introduce additional precision loss.
ModelOpt scale handling. Per-expert gate/up scales are applied before SwiGLU. The down-projection input scale normalizes the in-kernel NVFP4 intermediate quantization and is folded back into the L2 output scale:
l2_scale = l2_alpha * a2_scale.Correct routed/shared ordering. The kernel accumulates the routed top-k outputs, rounds the routed sum to BF16, applies
routed_scaling_factor, and then adds the BF16 shared-expert output.BF16 shared expert inside MegaMoE. Optional BF16 shared L1 and L2 work is inserted into the existing scheduler as
SharedLinear1andSharedLinear2phases. These tasks reuse the existing TMA-load, MMA, and epilogue warp roles; shared computation uses ordinary BF16 UMMA without scale factors or UTCCP.Separate shared K tiling. Routed NVFP4 and shared BF16 tasks reuse the same shared-memory byte tiles but contain different numbers of elements, so
SHARED_BLOCK_Kdescribes the BF16 K extent independently from the routed NVFP4 K extent.Fused shared epilogues. Shared L1 applies SwiGLU and stores a BF16 intermediate. Shared L2 writes to an additional local combine slot, allowing the final combine phase to perform routed scaling and the shared add without separate shared-expert launches.
Compatibility. The new NVFP4 path does not affect the existing BF16 or FP8 x FP4 MegaMoE paths.
Validation
Performance
Pure CUDA-kernel time on 8x GB300 with EP8. All three arms have the same BF16-input to BF16-output model boundary and include routed computation, dispatch/combine, routed scaling, the BF16 shared expert, and the final add.
sm100_fp4_fp4_mega_moe-> routed scaling -> serial DeepGEMM BF16 shared expert -> add.sm100_fp4_fp4_mega_moekernel containing the routed path, routed scaling, BF16 shared expert, and final add.Fusion gaincompares the two DeepGEMM arms.Fused vs FIcompares against the modular, non-MegaMoE FlashInfer baseline.Complete test recipe
Revisions and environment
2.13.0+cu130, vLLM0.17.2rc1.dev4473+g3ada0d7f1, FlashInfer0.6.16rc5Build and correctness
The boundary, zero-token, masked-routing, and shared-only cases use the same command with the corresponding
--num-tokens,--zero-token-rank,--masked-ratio,--routing-hot-rank, and--num-shared-expertssettings.Performance shape and inputs
61442048256; top-k:8; BF16 shared experts:10.751, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 163841651220260811Timed call graphs
Timing
deep_gemm.testing.bench_kinetoand reports selected CUDA-kernel time only.wait=0, warmup=1, active=1with 30 calls in the measured phase.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.