Repository navigation
Conversation
… FP8 MegaMoE With the MegaMoE all-to-all backend the FP8 expert method did not claim the routed scaling factor, so the top-k left it to the expert runner and run_mega_routed_experts multiplied the weights in a separate elementwise launch on every MoE layer, 40 per DeepSeek-V4.1-Flash prefill step. The fused gate already applies the factor in registers when the top-k config asks for it, and the MegaMoE runner already skips its multiply when the expert method claims the fusion; this joins the two for FP8 experts under MegaMoE. The weights are the same fp32 values, scaled in the gate instead of after it. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Collaborator
Author
|
/rerun-test registered/unit/layers/moe/test_mega_moe_deepgemm_api.py registered/unit/layers/moe/test_flashinfer_megamoe.py registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py |
Contributor
|
🚀 🚀 🚀 |
This was referenced Oct 17, 2026
3 of 5 tasks
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.
Motivation
In a DeepSeek-V4.1-Flash DEP2 prefill step on GB300 (MegaMoE all-to-all backend, FP8 expert method, eager prefill), every MoE layer runs one
vectorized_elementwise_kernelof 2 µs right beforemega_moe_pre_dispatch:topk_weights_in * routed_scaling_factorinrun_mega_routed_experts. 40 launches per 16K-token step, each costing 40 to 65 µs of dispatch on the eager path for 2 µs of GPU work.The multiply exists because
_fuses_routed_scaling_factor_in_topkreturns False forFp8MoEMethodunless the runner is CUTLASS or FlashInfer TRT-LLM routed, so the top-k config getsapply_routed_scaling_factor_on_output=False, the fused gate leaves the weights unscaled, and the MegaMoE runner scales them afterwards.Modifications
fused_moe_triton/layer.py:_fuses_routed_scaling_factor_in_topkalso returns True forFp8MoEMethodwhen the MoE all-to-all backend is MegaMoE. The model then builds its top-k withapply_routed_scaling_factor_on_output=True, the fused gate multiplies the selected weights by the factor in registers (_router_triton_kernel,APPLY_SCALE), andrun_mega_routed_expertstakes its existingrouted_scaling_factor=1.0branch. The FlashInfer MegaMoE and FlyDSL MegaMoE paths read the same flag and already skip their own multiply when it is set.test_mega_moe_deepgemm_api.py: the flag is True for an FP8 method under MegaMoE and False under the plain all-to-all backend.Numerics: the same fp32 weights, scaled inside the gate after renormalization instead of in a separate kernel after it; fused shared-expert slots are not used on this path (
num_fused_shared_expertsis 0 with MegaMoE).Measured
GB300, DEP2 (TP2 + DP attention, EP2), MegaMoE, Mega-mHC, decoder bounded replay, eager prefill, 16K-token prefill budget per rank, same node, on top of #44875 (job 3487) against that plus this change and #44879 together (job 3488; the two landed in the same run because the cluster worktree is a live mount).
topk_weights * routed_scaling_factorlaunchesGPU kernel time is unchanged; the gain is dispatch on the eager path. GSM8K on GB300 (DEP2, DSpark with real acceptance, greedy, 1,314 examples): 0.9741 with all three of #44875, #44878 and #44879 applied (job 3495) and 0.9741 on the same stack without them (job 3496), the same 1,280 correct.
Before and after
Perfetto, GPU stream of rank 0, the MoE prologue of layer 6 (from the Mega-mHC kernel to the MegaMoE kernel).
Before (job 3487): 7 slices; the 2.1 µs
vectorized_elementwise_kernel<4, AUnaryFunctor<float>>between_router_triton_kernelandmega_moe_pre_dispatchis the routed-scaling multiply.After (job 3488): 6 slices; the multiply is inside the gate.
Is the gain significant?
Marginal. It removes 40 launches of 2 µs each per 16K step, about 2 ms of dispatch on the eager path and nothing inside a graph; the step-time change is below what one run can resolve. It is a one-line consistency fix, the gate already had the code path, and it is worth taking for that reason rather than for speed.
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #39021145543
Latest PR Test (Extra): ❌ Run #39021145533
Latest PR Test (AMD ROCm 10): ❌ Run #39021145563