Repository navigation
[Feat] [GB300] deepseek_v41: NVIDIA megakernel plugin for DeepSeek-V4.1 decode on GB300 - #1
Merged
Merged
Conversation
Closed
1 of 5 tasks
YAMY1234
added a commit
to YAMY1234/sgl-nvidia-mega-fork
that referenced
this pull request
Oct 18, 2026
…e MoE step The MoE package builds PR sgl-project#1's routed-expert GEMM pair for every MoE layer (slot moe) and its fast top-k (slot gate), reading SGLang's loaded MXFP4 experts in place; every rank agrees or none is built. At widths whose plan routes, the step runs the dual-stream order with the pair: the fast gate takes the top-k on SGLang's router logits, the pair replaces the routed call and returns the deferred-finalize output, and the gate, the routed-input quant stream and the shared expert on the alternate stream stay as SGLang issues them.
YAMY1234
added a commit
to YAMY1234/sgl-nvidia-mega-fork
that referenced
this pull request
Oct 18, 2026
YAMY1234
added a commit
to YAMY1234/sgl-nvidia-mega-fork
that referenced
this pull request
Oct 18, 2026
…blished wo_b boundary/hop_a.py owns PR sgl-project#1's hop-A unit for the executor: the Lamport mailbox, the publishing wo_b GEMM precompiled for each width up to 8 rows, and the consumer. The attention step publishes through Boundaries.publish_wo_b; the attention post then collects a published partial with the triplet SGLang's post computes and the FFN norm, in place of SGLang's fused collective. Off unless the hop_a slot is on; any other partial takes SGLang's post. The boundary module is renamed boundaries.py.
This was referenced Oct 18, 2026
Merged
….1 decode on GB300
YAMY1234
force-pushed
the
deepseek-v41-gb300
branch
from
October 19, 2026 05:01
e0c1a2d to
f1874f6
Compare
…red steps The covered step is validated only under FULL decode CUDA graphs (one graphs-off run read needle 15/27, under investigation). The spec now accepts only FULL decode CUDA graphs and refuses a launch without them at argument resolution, with the reason. The target and draft plan a covered step only while SGLang captures the decode graphs (the warm-up runs included), so an eager step at a covered width runs SGLang's forward. The stock-parity and hop-fault serving tests step eagerly by design; their test-only switches still allow it.
YAMY1234
marked this pull request as ready for review
October 19, 2026 05:43
Oasis-Git
approved these changes
Oct 19, 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
At 1 to 8 concurrent requests, a DeepSeek-V4.1-Flash DSpark decode step on GB300 is bound by small GEMMs, per-layer kernel boundaries, the two TP all-reduces per layer and the host work between kernels, not by HBM bandwidth.
This PR adds the NVIDIA megakernel for that step as an SGLang plugin (package
sgl_nvidia_mega).sglang.srt.megakernels([Feat] [NVIDIA] megakernels: Add --enable-nvidia-megakernel and a layer for NVIDIA megakernel plugins sglang#44945, which this PR needs), and--enable-nvidia-megakernelturns it on.SGLANG_SPEC_TP_SYNC=rng,-dspark-accept-sample: the spec-decode rank sync every measurement ran with. It removes a sync in SGLang's stock accept path. The target spec requires it, so a launch without it stops withSGLANG_SPEC_TP_SYNC 'all' is not 'rng,-dspark-accept-sample'.SGLANG_ENABLE_DSV41_ENGRAM_HOST_TABLE=1,SGLANG_DSV41_ENGRAM_HOST_TABLE_LAYOUT=per_rank: SGLang's per-rank Engram host table, which the Engram prefetch reads. The target spec requires both; a launch without them stops, naming each.SGLANG_NUMA_BIND_V2) only; no per-table Engram placement.Measured with exactly this launch (GB300, TP4, static ISL 8K / OSL 1K, order-balanced on one node):
Details below.
Modifications
How SGLang runs it
sgl_nvidia_mega/plugin.py, every SGLang process). SGLang's plugin loader callsregister(), which registers two specs withsglang.srt.megakernels: the target (DeepseekV4ForCausalLM) and the DSpark draft (DeepseekV4ForCausalLMDSpark). The spec modules are imported only on a server with the flag.deepseek_v41/spec.py) states, as data: SM103, TP 4, 152 SMs, bf16, FP8 KV cache, DSpark,--dsv4-attn-backend flashmla, the measured launch's environment (the TP sync setting and the per-rank Engram host table), no MoE all-to-all, serial weight loading, FULL decode CUDA graphs (required), and the model's HF config.buildwith aBuildContext, whosebindingis the model'sMegakernelBinding.wkv(embed(ids))at every width it serves; on a mismatch it stays off on every rank, with the reason logged.forwardon that model instance only.plancovers a DSpark verify step whose rows are a built width, while SGLang captures the decode graphs. It decides from host state alone, so every rank decides the same, and a captured CUDA graph replays the decision made at capture.ForwardViewasStep.view. Every other step, including any step SGLang runs outside a graph, runs the model's own forward.binding.forward_view().sglang/srt/megakernels/binding.py, #44945):ForwardView: the attention backend's forward metadata, the KV pool (KvPoolView, under the pool's own method names), and the backend's attention, KV-write, SWA-location and compressor / indexer calls.MegakernelBinding: the Engram history and the per-layer host tables.test/unit/test_contract.pypins SGLang'sTOLERATED_CALLABLES,TOLERATED_WRITESandTOLERATED_READSlists, so anything new fails a CPU test.NVIDIA megakernel: active (...)line per spec with the slots built and their widths;hop A attention post serves N rowsandfast gate top-k serves N rowscome from the kernels' own dispatch, once per width.The plugin reads SGLang's modules and ops by name.
test/unit/test_contract.pypins every name it reads, on CPU, so an SGLang rename fails a CPU test that names the file to repair, not a server at startup.Test only:
sgl_nvidia_mega/plugin.pyregisters ONEAROUNDhook,runtime/parity.py:around_attention_forwardonDeepseekV4AttnBackend.forward, and only withSGLANG_NVIDIA_MEGAKERNEL_PARITY_SORT_TOPK=1. It sorts the sparse-attention indices in both forwards for the parity compare. It is never registered in a normal launch.The covered step
The executor (
deepseek_v41/runtime/) runs the target step from one package per part of the layer (Engram, boundary, attention, MoE, logits). Each part runs over SGLang's loaded weights and caches. Each has a stock implementation that reproduces SGLang's step from SGLang's own ops. The slot plan (plan.py) swaps in this package's kernels where they pay off.The default build runs these 36 slots:
hop_a,hop_a_batch2,hop_b,hop_b_start_trigger,early_trigger,two_shotwo_bon FlashInfer's low-latency MXFP8 GEMM, storing each row into a Lamport mailbox on every rank; a Lamport consumer reduces and runs the mHC post, combine and RMSNorm. Hop A is the attention post: 1-8 rows, and 9-16 rows (batch 2) on the fusedwo_a's row-tile scales. Hop B is the MoE post, with its start and early triggers. The two-shot all-reduce + mHC covers the rows past the routed pair (49-384).moe,gate,gate_wideattn,attn_qkv_a,attn_qkv_a_bf16,index_q_mxfp8_in,kv_before_wait,hc_prenormembed,engram,aux_mean_stats,sched_ahead,req_pos_oncedraft,draft_attn,draft_moe,draft_gate,draft_tail,draft_post,draft_seam,draft_qkv_a,draft_qfront,draft_wo_a,draft_swapab,draft_prenorm,draft_qkv_a_ll,draft_wo_b_ll,markov,draft_lm_headThe sorted list of these 36 names has sha256 prefix
22c638c8af6e(the slot-set identity the GPU runs were checked against).Outside the default list, opt-in:
draft_embed.The kernels stay separate launches chained with programmatic dependent launch (PDL). On GB300, a kernel boundary with PDL costs less than an exchange between all blocks of one persistent grid.
Not in this PR:
SGLANG_NVIDIA_MEGAKERNEL_SLOTSoverrides the default list for tests and bisecting (empty: every step function's stock code). An unknown slot, or a requested slot that builds at no width, stops the server. For example, droppinghop_a_batch2restores hop A at 1-8 rows with the 8-row mailbox; droppinggate_widerestores the fast gate's earlier widths.Build and failure behavior
NOTICElists SGLang.--watchdog-timeout, at most 60 s. A rank that misses it faults, so no output of the failed step is used.Accuracy Tests
GB300, TP4, EP 1, DSpark block 5, FP8 KV cache, the launch above (the default 36 slots), SGLang #44945 with the megakernel binding. Measured on this PR's plugin code (identical to the measured tree).
spec.NUMERICS) and by the serving accuracy runs.test/kernels, GB300): the routed pair against FlashInfer's routed MoE (1-48 rows, eager and CUDA graph); the top-k against SGLang's fused gate (bitwise, including ties, NaN logits, padded rows and vision-token routing); the publishingwo_b(including the 9-16-row tiles), the Lamport consumers and the wait deadline; the Markov proposal and the low-M LM heads. On the same plugin code before the test files were consolidated, on four GB300s: 568 passed, 0 failed, plus 40 / 40 cases of the poisoned-memorywq_btest. A re-run on this head's consolidated test files is in progress. The multi-GPU tests (hop B, the two-shot all-reduce,wo_bpublish) run through their own 4-GPU entry points. 67 are skipped: 64 fusedwo_awidths above the 32 rows SGLang serves, 2 that need the model checkpoint, and 1 benchmark.test/unit, against #44945 with the binding): 238 passed, 0 skipped, includingtest_deepseek_v41_binding_reach, which drives the real build path and checks every package receives the binding.__init__.pyincluded).pre-commit run --all-filespasses on a fresh copy.Speed Tests and Profiling
GB300, TP4, DeepSeek-V4.1-Flash, DSpark, static ISL 8K / OSL 1K, the launch above. One node, fresh launches in the order pre-binding → this PR → this PR → pre-binding, two rounds each. Every number is the mean of the four runs' decode-step p50 (range in brackets); each rank is bound to its GPU's NUMA node.
Batch-1 tok/s/user: 1,038 for this PR vs 1,067 for the pre-binding build (-2.7 %).
Reproduce:
benchmark/README.md.