Repository navigation
[Fix] [NVIDIA] moe: keep the tuned autotune key for deferred-finalize FP4 TRT-LLM MoE calls - #50195
Conversation
7b79ede to
fb7e9d6
Compare
|
/rerun-test registered/unit/layers/quantization/test_mxfp4_trtllm_autotune_key.py |
|
🚀 |
…E calls With deferred finalize, the logits-bypassed NVFP4 TRT-LLM MoE path called trtllm_fp4_block_scale_moe(do_finalize=False) without an output. FlashInfer then allocates an (N, 0) placeholder, which is the first input of its AutoTuner key, while the entries tuned at startup (do_finalize=True) are keyed on (N, hidden). The lookup misses and the call runs FlashInfer's default tactic. At 512 experts and top-10 that is the tile-8 kernel pair for every N up to 819 rows: the default tile follows the average rows per expert (N * top_k / num_experts) and moves to 16 only once that average exceeds 16. The routed path already passes an (N, hidden) bf16 buffer at every TP size (the flashinfer-ai/flashinfer#6077 workaround from sgl-project#42654). The deferred-finalize block now allocates that buffer for bypassed inputs too, and the bypassed call passes it. FlashInfer does not write it when do_finalize is False, so only the autotune key changes. symm_output is now always set, so its None default and the routed path's None check go away. Test: TestNvfp4BypassedAutotuneKey in test_mxfp4_trtllm_autotune_key.py; it fails on main, where the deferred call passes no output. Gain: deferred FP4 MoE kernel time per call 159 -> 124 us at 256 rows, 212 -> 128 us at 512 rows (one VR200 GPU, Qwen3.8-Flash-Next NVFP4 MoE shapes, TP1, FlashInfer 0.7.4; torch profiler after startup-style autotuning). Co-Authored-By: Claude Opus 5.5 <[email protected]>
fb7e9d6 to
6d8fbb6
Compare
|
/rerun-test registered/unit/layers/quantization/test_mxfp4_trtllm_autotune_key.py |
|
🚀 |
|
cc @leejnau |
nvpohanh
left a comment
There was a problem hiding this comment.
[by Claude Code] This review is done by agents. Please feel free to disagree if they do not make sense.
[by Claude Code] Severity: style | Confidence: High
Issue
The PR has no accuracy result. The Accuracy Tests section gives a reason and a mocked CPU test only. But the change can change model outputs. Your speed table shows deferred calls moving from the tile-8 default tactic to tuned tile-16 and tile-32 kernels. That changes the GEMM kernels and the padded gemm2_out layout. The SGLang finalize kernels then read that layout through expanded_idx_to_permuted_idx.
Fix
Add one before/after accuracy result, such as GSM8K, on a model whose NVFP4 MoE takes the bypassed deferred-finalize path. The Qwen3.8-Flash-Next setup from the speed table is fine. Name the model and GPU.
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
|
All NV pipeline passed |
…PI v3 and contract (#103) * [Fix] minimax_m31: Speak megakernel API version 3 and follow SGLang main's contract #66 merged after #81 moved the unit tests to SGLang main, but its last unit run was against the old pinned SGLang, where the MiniMax-M3.1 checks are skipped. On SGLang main the spec is refused at registration and four contract checks fail, so main's unit job has been red since #66. - Megakernel API 3 (sgl-project/sglang#52054 replaced the verify penalty tables with step_penalties): declare 3, as #81 did for the other specs. The package reads no verify sampling penalties (its slots are the verify forward and the DSpark draft proposal), so nothing else changes. - sgl-project/sglang#52870 moved minimax_sparse_nvfp4_backend.py to minimax_sparse/msa_v1_backend.py; msa_v1_decode_plan is the same field. Name the new file first and keep the old one as the alternative. - fused_experts_none_to_flashinfer_trtllm_fp4: sgl-project/sglang#50195 passes the ignored output buffer on the logits-routed path too; the routed-top-k path moe_nofill follows already passed it. Re-pin. - _draft_step and _markov_sample_partial_kernel: sgl-project/sglang#51298 adds a step softcap and vocab limit that only Inkling2's MTP head sets, and #52728 a folded-bias kernel path _draft_step never takes. The chain serves only VanillaMarkov, which leaves both None. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Follow SGLang main's GDNAttnBackend.forward_extend sgl-project/sglang#39595 (FlyDSL GDN prefill on AMD) passes prefill_metadata=self.kernel_prefill_metadata to the extend kernel in the prefill arm of forward_extend, None for every kernel but FlyDSL, and adds kernel_prefill_metadata = None to GDNAttnBackend. - gdn/prefill.py serves only the Triton prefill kernel (view.kernel_id), and gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin both mirrors. - The runtime tests' fake GDN backend gains kernel_prefill_metadata=None, as SGLang's class now defines it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] kimi_k31: Follow SGLang main's verify sampling stages in the DFlash runtime sgl-project/sglang#52406 deleted sampling_batch_info.adjusts_logits and speculative/target_verify.py (adjust_verify_logits). SGLang's DFlash round now reads VerifyRoute.adjusts_logits and calls VerifyStep.adjust from SamplingPipeline.plan_verify. The K3.1 DFlash runtime imported both old names, so it no longer imported on SGLang main. - _unserved: VerifyRoute.derive(...).adjusts_logits is the same predicate as adjusts_logits (grammar, watermark, penalties, logit bias or a custom logit processor), so the same rounds go back to SGLang. - _accept, greedy round on gathered logits: the target's sampling_pipeline.plan_verify(batch, watermark_full_mask=False).adjust() runs the same stages in the same order as adjust_verify_logits did: penalties along the chain, logit bias and the custom logit processor, each width rows per request, with no grammar mask. DFlash refuses the watermark, so none is bound. As before, _unserved already refuses every round these stages would change. - The test fakes gain the target's sampling_pipeline and need_min_p_sampling, which SGLang's SamplingBatchInfo defines. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] qwen3_5: Re-pin GDNAttnBackend.forward_extend after sgl-project/sglang#44195 sgl-project/sglang#44195 gives the Triton GDN kernel an FP32 track snapshot and gates the snapshot in forward_extend's prefill arm on use_track_state_snapshot(): a snapshot-capable kernel in batch-invariant mode. - gdn/prefill.py: only --enable-deterministic-inference turns on batch-invariant mode, and it refuses the trtllm_mha attention backend this spec requires. The served prefill arm still writes checkpoints from the per-chunk states, as the slot does. Re-pin. - gdn/verify.py mirrors the target-verify arm, which the change does not touch. Re-pin. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Motivation
With deferred finalize, the logits-bypassed NVFP4 TRT-LLM MoE path calls
trtllm_fp4_block_scale_moe(do_finalize=False)without anoutput. FlashInfer then allocates an(N, 0)placeholder, which is the first input of its AutoTuner key (flashinfer-ai/flashinfer#6077, still open). The entries tuned at startup (do_finalize=True) are keyed on(N, hidden), so the deferred call misses them and runs FlashInfer's default tactic. At 512 experts and top-10 that is the tile-8 kernel pair for every N up to 819 rows.The routed path already works around #6077 (#42654): its deferred call passes an
(N, hidden)BF16 buffer at every TP size, and FlashInfer does not write it whendo_finalizeis False.Modifications
if defer_finalize:block now allocates the optimize pad operations in fa3 to accelarate 100+us #6077 buffer for both routed and bypassed inputs, and the bypassed call passes it asoutput, as the routed call does. As on the routed path, this does not depend on the TP size.symm_outputis now always set, so itsNonedefault and the routed path'sis not Nonecheck are removed.Accuracy Tests
The buffer is not written; deferred calls now pick the same tuned tactic the finalized call uses at that shape.
New CPU test
TestNvfp4BypassedAutotuneKeyintest/registered/unit/layers/quantization/test_mxfp4_trtllm_autotune_key.py. It runs the deferred bypassed path at 8 and 64 rows with the FlashInfer call mocked and checks that the call passes an(N, hidden)output instead of none (which FlashInfer turns into its(N, 0)placeholder). It fails onmain; the whole file passes with this change.Speed Tests and Profiling
Kernel time per
trtllm_fp4_block_scale_moecall (all kernels of the call), on one VR200 GPU at Qwen3.8-Flash-Next NVFP4 MoE shapes (512 experts, top-10, hidden 2560, MoE intermediate 640), TP1, FlashInfer 0.7.4. The kernel is tuned first as at server startup (autotune on,do_finalize=Truewith a full-width output), then each case runs 30 calls under the torch profiler.main)(N, hidden)output (this PR)On
mainFlashInfer logsNo tuned config covers ... input_shapes=((N, 0), ...)at every row count. The finalized column includes the ~13 us finalize kernel that deferred calls leave to the caller.Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #43767267026
Latest PR Test (Extra): ❌ Run #43767266752
Latest PR Test (AMD ROCm 10): ❌ Run #43767266689
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: