Repository navigation
Conversation
…-finalize # Conflicts: # python/sglang/srt/models/deepseek_v2.py
…-finalize # Conflicts: # python/sglang/srt/layers/moe/moe_runner/flashinfer_trtllm.py
…nner Follow-up 1 of sgl-project#42654, stacked on it. - FusedMoE: supports_routed_deferred_finalize also accepts Fp8MoEMethod with MXFP8 experts (not converted to block FP8), under the same env, no-A2A and routed-scaling-in-top-k conditions as NVFP4. - FP8 runner: the routed branch builds one kwargs set; with deferral on and MXFP8 experts it calls FlashInfer trtllm_fp8_block_scale_routed_moe with do_finalize=False and wraps the result. Block FP8 and per-tensor routed calls still reject deferral. - The deferred routed call passes a [T, hidden] bf16 buffer it never writes, the same flashinfer-ai/flashinfer#6077 workaround as NVFP4. - Precomputed routing returns the caller's top-k weights unchanged, so the routed scaling factor folded into them is applied once, by the finalize.
wenchen76
force-pushed
the
mxfp8-routed-deferred-finalize
branch
from
October 25, 2026 06:18
26c5b18 to
ac5cde8
Compare
This was referenced Oct 25, 2026
Contributor
|
Thanks @wenchen76. Closing this because it is still a draft and has not been updated in 22 days. Reopen it if the work is still relevant. Some directories moved recently, so an older branch may need retargeting: |
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
This PR covers the MXFP8 case of #39299. #42654 covers the NVFP4 case, and this is its follow-up 1: MXFP8 experts on the routed runner (
Fp8MoEMethodwithuse_mxfp8, the RL rollout path from #28676). The scope, limited to MXFP8, and the kernel-level comparison at V4.1-Flash shapes (worst max abs diff / max abs ref 4.9e-3) come from @vincentzed's description in #42654. This PR adds the wiring and an end-to-end run on an MXFP8 checkpoint.Routed deferred finalize applies to the same models as NVFP4 in #42654.
Modifications
FusedMoE:supports_routed_deferred_finalizealso acceptsFp8MoEMethodwith MXFP8 experts. Experts converted to block FP8 (convert_mxfp8_to_block) are excluded. The other conditions are the same as NVFP4:SGLANG_ENABLE_MOE_DEFERRED_FINALIZE, no A2A backend, and the routed scaling factor fused into the top-k weights.fused_experts_none_to_flashinfer_trtllm_fp8, routed branch:trtllm_fp8_block_scale_routed_moewithdo_finalize=Falseand wraps the result with_make_deferred_finalize_output.[T, hidden]BF16 buffer that the op never writes. This is the same [Bug] trtllm-gen MoE with do_finalize=False misses the tuned autotune entry (key includes output shape) flashinfer-ai/flashinfer#6077 workaround as the NVFP4 path, and it can be deleted once that issue is fixed.Accuracy Tests
Environment: 1x B200,
lmsysorg/sglang:nightly-dev-cu13-20261018-b234b5c3, FlashInfer 0.7.2, this branch atac5cde8.Model:
zianglih/JoyAI-LLM-Flash-MXFP8-last-6-BF16. It isDeepseekV3ForCausalLMwith one shared expert androuted_scaling_factor2.5. MoE layers 1-33 are MXFP8 and layers 34-39 are BF16. The serve flags follow CI'sTestFlashinferTrtllmRoutedMxfp8MixedBF16, except TP1 instead of TP4:SGLANG_ENABLE_JIT_DEEPGEMM=False SGLANG_ENABLE_MOE_DEFERRED_FINALIZE={0,1} \ python -m sglang.launch_server --model-path zianglih/JoyAI-LLM-Flash-MXFP8-last-6-BF16 \ --trust-remote-code --tp-size 1 --kv-cache-dtype bf16 \ --fp8-gemm-backend flashinfer_trtllm --moe-runner-backend flashinfer_trtllm_routedPath check. GPU profile of 20 forward steps: 4 requests, 48 greedy tokens each.
sglang::moeFinalizeKernel(moe_finalize_fuse_shared)moe::dev::finalize::finalizeKernelDeepseekV2MoEonly takes the deferred path inforward_normal_dual_stream, which is unchanged from [Perf] moe: Enable deferred finalize for NVFP4 on the routed TRT-LLM runner #42654.No tuned config covers.GSM8K, 500 questions, greedy, one server launch per arm:
SGLANG_ENABLE_MOE_DEFERRED_FINALIZE=0)The gap is 1 question; one standard error is about 0.011. Both arms are above CI's 0.92 threshold for this model.
Unit tests:
test/registered/unit/layers/moe/test_flashinfer_trtllm_routed_deferred_finalize.py: 5 passed.test/registered/unit/models/test_deepseek_v4_amd_tp4.py: skipped on NVIDIA. It only runs through its four-GPU gfx950 entry point.Speed Tests and Profiling
Not measured yet. On TP1 there is no all-reduce to fuse, so deferring only removes the separate finalize step and the result is expected to be within noise. The gain #42654 reports on V4.1 comes from the fused finalize + all-reduce kernel, which needs TP > 1.
Remaining before ready for review
These follow #42654's test flow, run on DeepSeek-V4.1-Flash MXFP8 on multiple GPUs. "Off" means the same code with
SGLANG_ENABLE_MOE_DEFERRED_FINALIZE=0.moe_finalize_all_reduce_mhc_post, the fused finalize + shared add + all-reduce kernel. Confirm that noNo tuned config coversfallback is logged.--max-tokens 2048, run twice with the arm order swapped.TestServerUpdateWeightsFromDiskMXFP8, the [RL] fix deepseek v4 MXFP8 flashinfer_trtllm_routed MoE weight update #28676 use case, with the deferred path on.