Repository navigation
Add sgl-project's NVFP4 MegaMoE as an additive deep_gemm.mega_nvfp4 module - #18
Merged
Merged
Conversation
vipulSharma18
force-pushed
the
vipul/nvfp4-mega-moe-additive
branch
from
October 13, 2026 05:10
246f92c to
ef210f2
Compare
vipulSharma18
changed the base branch from
main
to
vipul/fold-fireworks-build-patches
October 13, 2026 05:10
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ef210f2. Configure here.
There was a problem hiding this comment.
Stale comment
Risk: high. Not approved: this adds a large new SM100 NVFP4 MegaMoE kernel and public
deep_gemm.mega_nvfp4API (thousands of lines of device/host code), which is above the low-risk auto-approve threshold. Human review is needed; no reviewers were assigned.Sent by Cursor Approval Agent: Pull Request Approver
vipulSharma18
force-pushed
the
vipul/nvfp4-mega-moe-additive
branch
from
October 14, 2026 01:12
a914925 to
3a47b8e
Compare
… module Port the SM100 NVFP4 x NVFP4 MegaMoE decode kernel and the fused `mega_moe_pre_dispatch` kernel from sgl-project/DeepGEMM@ec226bc (#27, 593e376, deepseek-ai#80, deepseek-ai#81) so Fireworks can drop the separate `sgl_deep_gemm` wheel. Purely additive: the only change to an existing file is the registration hook in csrc/python_api.cpp. No existing header changes, so no existing kernel's JIT cache key changes. - Device code: sgl's headers copied into deep_gemm/include/deep_gemm/mega_nvfp4/ (kernel, pre-dispatch, layout, scheduler, barrier, math/utils/tma_copy, ptx ld_st/tcgen05/tma/utils, sym_buffer, and the `MmaKind` block of types.cuh), moved into namespace `deep_gemm::mega_nvfp4` with includes redirected and nothing else changed (line numbers kept, so even assert-path SASS matches). - Host code: csrc/apis/mega_nvfp4.hpp plus heuristics/nvfp4_mega_moe.hpp and impls/sm100_nvfp4_mega_moe{,_pre_dispatch}.hpp, in `deep_gemm::mega_nvfp4` with `nvfp4`-marked names. Like the separate sgl library, these kernels keep their own SM count, compile for sgl's `sm_100f` target and launch without PDL, so `deep_gemm.set_num_sms`/`set_pdl` and these kernels never affect each other. Not ported: TRT-LLM weight layout, FP8 combine, BF16 and SM90 paths. - Python: deep_gemm/mega_nvfp4 exposes the sgl_deep_gemm subset Fireworks uses (get_symm_buffer_for_mega_moe, transform_weights_for_mega_moe, mega_moe_pre_dispatch, nvfp4_mega_moe, set_num_sms, get_block_m_for_mega_moe, transform_ue4m3_sf_into_required_layout). - tests/test_mega_moe_nvfp4.py ports sgl's pre-dispatch and NVFP4 alphas tests and adds a bytewise check of the NVFP4 pre-dispatch quantization. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…upstream deepseek-ai#441) Co-Authored-By: Claude Opus 5.5 <[email protected]>
vipulSharma18
force-pushed
the
vipul/nvfp4-mega-moe-additive
branch
from
October 14, 2026 21:17
3a47b8e to
2da6d78
Compare
YLGH
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
This adds sgl-project/DeepGEMM's SM100 NVFP4 × NVFP4 MegaMoE decode kernel and its fused
mega_moe_pre_dispatchkernel, taken fromec226bc(sgl #27,593e376, deepseek-ai#80, deepseek-ai#81). They are exposed as a new module,deep_gemm.mega_nvfp4, which provides the subset of thesgl_deep_gemmAPI that Fireworks uses:transform_ue4m3_sf_into_required_layouttransform_weights_for_mega_moeget_symm_buffer_for_mega_moemega_moe_pre_dispatchnvfp4_mega_moeget_block_m_for_mega_moeset_num_smsWhy
MiniMax-M3.1 decode (
FIREWORKS_DPEP_MEGAMOE=1) currently ships a second DeepGEMM wheel,sgl_deep_gemm, next to ours. With this module in our fork, Fireworks can drop that dependency and its separate build. That also unblocks landing the M3.1 decode stack (fireworks#55221) onmain.Design: purely additive
csrc/python_api.cppgains an include and aregister_apiscall (+2 lines). Every other file is new: 22 files, +7128/−0.deep_gemm/include/deep_gemm/mega_nvfp4/(kernel, pre-dispatch, layout, scheduler, barrier, math/utils/tma_copy, the ptx helpers, sym_buffer, and theMmaKindblock oftypes.cuh). The only edits are the namespacedeep_gemm::mega_nvfp4and the include paths. Line numbers are kept. One deliberate addition: upstream DeepGEMM Fix Mega MoE task info slot release ordering deepseek-ai/DeepGEMM#441 (78b6900, the task-info slot release fence), which sglec226bcpredates and which the fork's existing scheduler already has (a914925)._Centry points have separate,nvfp4-marked names in a newcsrc/apis/mega_nvfp4.hpp,heuristics/nvfp4_mega_moe.hppandimpls/sm100_nvfp4_mega_moe{,_pre_dispatch}.hpp.sm_100ftarget and launch without PDL. Sodeep_gemm.set_num_smsanddeep_gemm.set_pdlnever affect them, and they never affect the existing kernels.deepgemm-situ,-mhc-graph-replay,-sigmoid-bf16or-mhc-capabilitychange. All four apply unchanged on top of this branch.Base branch
This PR is stacked on #19, which folds Fireworks' four build patches into
main, and is rebased onto it (ef210f2). Merge #19 first; this PR then retargets tomain. After both merge, Fireworks buildsmainhead with no patches, so any merge style is fine.Verification (B300)
The first round compared
c2e49f5+ 4 patches against this PR + 4 patches. After the rebase onto #19, the agent re-ran three checks: zero new JIT cache keys for existing kernels vs #19, bitwise equality withsgl_deep_gemmat EP2 (92 tensors) and EP8 (356), andtests/test_mega_moe_nvfp4.pypassing..pyfiles are byte-identical.inspect.signatureacrossdeep_gemm,deep_gemm.mega,_C)_C.*nvfp4*names. Nothing removed or changed.test_mega_moe.pyfp8×fp4 and BF16 at 8 ranks,test_mega_moe_compat.py,test_mega_gate.py,test_mega_mhc.py,test_bf16.py, and the dense and m-grouped-contiguous tests fromtest_fp8_fp4.py.sgl_deep_gemm@ec226bcset_num_sms(120). That is 860 tensors across 6 runs, still bitwise equal after the deepseek-ai#441 fence (EP2 88, EP8 352 tensors), which changes ordering, not values.tests/test_mega_moe_nvfp4.pypasses. It ports sgl's tests: pre-dispatch bytewise for fp8, mxf4 and nvfp4, and the 2-rank alphas test.sgl_deep_gemmand the fork'sfp8_fp4_mega_moe. racecheck: 0 errors; its warnings are the same TMA double-buffer WAR pattern in all three (the tool does not model TMA/mbarrier completion). The tools cannot see cross-GPU NVLink ordering.Not run:
test_fp8_fp4.pyon both sides. An outside process killed the baseline run after 33 minutes, so only its dense and m-grouped-contiguous tests ran.test_mega_moe_training.py.Notes for reviewers
sgl_deep_gemm, the kernels compile on first use, so callers need an eager forward before CUDA-graph capture. Fireworks already does this.Fireworks follow-up (separate PR)
megamoe_nvfp4.py,import deep_gemm.mega_nvfp4 as deep_gemm.fw-ai/DeepGEMMmainhead (Fireworks PR prepared as a draft) with no build patches.sgl_deep_gemmbuild.🤖 Generated with Claude Code
Note
Medium Risk
Large new distributed MoE + quantization kernel surface on SM100; isolated from existing APIs but correctness and multi-GPU behavior depend on careful buffer layout and symmetric-memory use.
Overview
Adds
deep_gemm.mega_nvfp4, a self-contained port of sgl-project’s SM100 NVFP4 MegaMoE decode path so Fireworks can drop the separatesgl_deep_gemmwheel.The only touch to existing code is wiring
mega_nvfp4::register_apisinpython_api.cpp. Everything else is new: host APIs for symmetric-buffer sizing/slicing,nvfp4_mega_moe, and fusednvfp4_mega_moe_pre_dispatch; SM100 JIT launchers with local TMA helpers; heuristics with an isolated SM count andsm_100fcompile target (PDL off); and copied CUDA headers underdeep_gemm/include/deep_gemm/mega_nvfp4/. TRT-LLM weights, FP8 combine, BF16, and SM90 are intentionally not ported.The Python package exposes
SymmBuffer, weight transforms, pre-dispatch, andnvfp4_mega_moeforfp8xfp4/mxf4xmxf4/nvfp4xnvfp4, and rejects legacyDG_USE_FP4_ACTSenv vars in favor ofmma_type.Reviewed by Cursor Bugbot for commit 2da6d78. Bugbot is set up for automated code reviews on this repo. Configure here.