Conversation
…+ RMSNorm Fold the deferred MoE finalize (weighted expert combine + shared add) into the next layer's input-RMSNorm via flashinfer kMoEFinalizeARResidualRMSNorm, keeping residual_out available for Eagle3 aux capture. - Reshape expanded_idx_to_permuted_idx / expert_scale_factor to [token_num, top_k]: the kernel derives top_k from size(-1), so a flat index made it read far OOB (illegal memory access in capture). - Pre-size the MoE-TP lamport workspace for the permuted gemm2_out buffer before CUDA-graph capture; fall back when comm exceeds MAX_COMM_SIZE or the workspace is too small (never grow inside captured graphs). - Force trtllm backend when deferred finalize is on (pattern 7 is trtllm-only, intra-node); folded into _resolve_backend. Co-authored-by: Cursor <cursoragent@cursor.com>
kpham-sgl
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ch-wan,
fzyzcjy,
hnyls2002,
ispobock and
merrymercy
as code owners
June 17, 2026 23:17
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Collaborator
Author
|
flashinfer-ai/flashinfer#4358 supersede this API |
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.
Summary
Fuse the deferred MoE finalize into the next layer's input-RMSNorm via flashinfer
kMoEFinalizeARResidualRMSNorm(pattern 7): weighted expert combine + shared-expert add + all-reduce + residual + RMSNorm in one kernel, while keepingresidual_outavailable for Eagle3 aux capture. Gated bySGLANG_ENABLE_MOE_DEFERRED_FINALIZE. Builds on #28343.Key modifications
gemm2_outacross the layer boundary with a finalize-inputs bundle attached.RMSNorm.forward_with_moe_finalize_allreduce_fusion(falls back to separate finalize + AR+RMSNorm fusion if unavailable).FlashInferTrtllmMoeFinalizeFusionBundleto package deferred outputs.expanded_idx_to_permuted_idx/expert_scale_factorto[token, top_k](kernel derivestop_kfromsize(-1)— flat index caused OOB); force trtllm backend (pattern 7 is trtllm-only); lamport workspace sizing +MAX_COMM_SIZE/capacity fallbacks.Note: pattern 7 is trtllm-only, so the fusion is intra-node (single NVLink domain).
HumanEval (164, K2.5-NVFP4 + EAGLE3, attn_tp8_moe_tp8)
Accept length is unchanged within noise —
residual_outis correctly preserved for Eagle3 (a broken residual would collapse acceptance toward ~1.0).Numerics & speed vs the separate-finalize fallback
Compared the fused kernel against the fallback path (deferred finalize +
kARResidualRMSNorm, which also emitsresidual_out):fp32_accdoesn't reach that step). Negligible on real data — HumanEval accept length 3.02 fused == 3.02 fallback; only OOD random-token GSP shows a small dip (2.18 vs 2.23).15.5 vs 14.4 µs(+1.0), bs=1638.4 vs 26.4 µs(+12.0). Confirmed the kernel'sallreduce_inis the padded permutedgemm2_out(verified runtime rows 256 → 6272, i.e. 64–128× the token count); this is trtllm'sdo_finalize=Falseoutput that the index map gathers from — the intended input, not a mis-sized/bugged input. The cross-rank AR is over the finalized T rows though (timing is invariant to the permuted-buffer size; AR-only is ~12–22 µs, latency-bound), so the slowdown is not AR bandwidth — it's the fused kernel's in-kernel finalize being ~2–4× the cost of the standalone finalize kernel (4–6 µs).Takeaway: under CUDA-graph decode the cheaper fallback is faster, more accurate, and already preserves
residual_out, so it is preferred there; the fused kernel only wins when launch-bound (eager).Made with Cursor
CI States
Latest PR Test (Base): ❌ Run #27725890409
Latest PR Test (Extra): ❌ Run #27725890323