Repository navigation
[Feat] [NVIDIA] megakernels: Qwen3.5 binding and EAGLE entry wiring for NVIDIA megakernel plugins - #45266
Merged
Oasis-Git merged 13 commits intoOct 27, 2026
Conversation
4 of 5 tasks
YAMY1234
force-pushed
the
nv-mega/qwen35-megakernel-binding-main
branch
from
October 20, 2026 20:53
c1c79ac to
dd3b395
Compare
YAMY1234
force-pushed
the
nv-mega/qwen35-megakernel-binding-main
branch
from
October 21, 2026 05:09
4401622 to
aa9f2a8
Compare
4 of 5 tasks
YAMY1234
force-pushed
the
nv-mega/qwen35-megakernel-binding-main
branch
from
October 21, 2026 13:14
aa9f2a8 to
29eb7e9
Compare
…ecture, and agree on the entries it offers - install_megakernel builds the binding SGLang registers for the model's architecture (runtime._BINDINGS), and MegakernelBinding for every other one. It hands the binding over as BuildContext.binding, as before. - spec.ENTRIES names the optional entries of a built object: draft_sampler and the EAGLE entries (draft_loop, draft_extend and begin_draft_round). Every rank must offer the same ones, or every rank refuses. megakernel_entry returns an entry, or None for SGLang's own path. - The startup line of a spec that covers no step names the entries it offers. The API version is unchanged: a built object written without the EAGLE entries offers none of them, and the DSpark draft sampler path is untouched.
megakernels/eagle_binding.py is what binding.py is for DeepSeek-V4.1: the one place the megakernel of a Qwen3.5 target, whose GatedDeltaNet and full-attention layers run under HybridLinearAttnBackend, and of its MTP draft read SGLang's runtime state. runtime._BINDINGS hands EagleBinding to the Qwen3.5 architectures. - A covered step gets EagleForwardView as Step.view: the full-attention metadata (page table, KV lengths, cumulative lengths), the GDN metadata (mamba slots, query offsets, intermediate rows, track slots), the KV pool per full-attention layer with its FP8 scales, and the mamba pool with its ReplaySSM ring. A model without GDN layers, such as the draft, gets no GDN metadata and no mamba pool. - The pools are read once and sealed; assert_live, after the decode graphs are captured, raises once one was reallocated. - The module defines the structs of the EAGLE entries (draft loop, draft extend, draft round) and documents what each entry may write. Its TOLERATED lists name what a megakernel may call or read beyond that data: the TP process groups, SGLang's kernel ops, configuration, and the covered forward's own batch fields. - The installed forward types the binding it holds as BuildContext.binding does: EagleBinding has MegakernelBinding's forward_view and assert_live without subclassing it. test_eagle_binding.py checks that the view holds the backends' own tensors, the sealing, that every struct carries data only, and that every listed name exists.
…nel's draft_loop and draft_extend When the draft model's megakernel offers draft_loop or draft_extend, the EAGLE draft and draft-extend graph runners call the factory once, before capture, with their own outputs: the draft tokens, and the extend's top-1, its probability and its hidden state. For a batch size whose step the factory returns, the graph captures that step in place of SGLang's draft loop, or in place of the draft model step and its top-1. Every rank must serve the same batch sizes, and every other size runs SGLang's code. SGLang keeps the graphs, their replays and the outputs. - begin_draft_round, when offered, runs on the host before a served draft graph replays. It says whether a served draft extend of the same requests produced the round's input. - Draft entries serve graph replays only; an eager draft step runs SGLang's loop. - The EAGLE draft worker looks for entries only with --enable-nvidia-megakernel, at the end of its init_attention_backends, once the pools and both attention backends exist and before any graph is captured. It refuses offered entries it cannot serve: a draft other than a multi-step topk-1 chain, rejection sampling, DP attention, a sliding-window target KV pool, or backends other than GDN with trtllm_mha. - The graph runners read the worker's megakernel, None unless entries are offered. The attention test kit's draft worker harnesses and the inkling checkpoint test's draft worker carry it as None, as EagleDraftWorker does. The inkling test builds its draft-extend runners with cls.__new__, so it sets their megakernel members as __init__ does for a worker without a megakernel. speculative/eagle_megakernel.py holds SGLang's side of the entries: the served batch sizes, the outputs, and the provenance of each draft round's input. It is never handed to a plugin.
…on graph variants in the verify and EAGLE draft graphs
A built megakernel may offer graph_variants: for the target's verify graphs
("target_verify"), the EAGLE draft graphs ("draft_loop") or the EAGLE draft-extend
graphs ("draft_extend"), an AttentionGraphVariants whose capture labels name graphs
that differ in the attention a step runs, and whose select picks one from host state.
At each batch size whose graph runs the megakernel, that runner captures one graph
per label, in order, with the label readable through get_capture_attention_variant()
during the capture, and every replay asks for the graph select picks. Every other
batch size, and every runner without an offer, captures one graph as before.
- ForwardBatch.attention_kv_len_lower_bound: init_new sets it to a one-request
batch's committed KV length (Req.kv.kv_committed_len), which can lag one verify and
so never exceeds the KV the step reads; None for several requests. select reads it
without touching the device.
- The verify graphs take the target's variants at the batch sizes whose rows its
megakernel built, unless SGLang captures variants of its own (DSA, the candidate
indexer). The draft and draft-extend graphs take the draft's at the batch sizes
their entry serves.
- DecodeCudaGraphRunner.attention_variant_sizes limits the capture and the replay of
the variants to those batch sizes; None keeps every size, as SGLang's own variants
have it. The EAGLE draft and draft-extend runners key their graphs by the label.
- Every rank must offer the same runners and labels, or every rank refuses; a key
that names no runner is refused.
- The EAGLE binding tolerates the reads a select makes and the capture-mode query.
- SGLANG_LOG_DECODE_GRAPH_KEY also prints the replayed graph's attention variant.
The API version is unchanged: a built object without graph_variants captures as
before.
YAMY1234
force-pushed
the
nv-mega/qwen35-megakernel-binding-main
branch
from
October 21, 2026 18:46
29eb7e9 to
0de5c03
Compare
…b a model The draft-extend graph runner now asks the draft model for the megakernel's attention graph variants, so the stub model_runner needs a model attribute.
YAMY1234
marked this pull request as ready for review
October 21, 2026 22:42
YAMY1234
requested review from
Fridge003,
Qiaolin-Yu,
Ying1123,
hnyls2002,
ispobock and
merrymercy
as code owners
October 21, 2026 22:42
# Conflicts: # test/registered/unit/layers/test_mamba_prefill_track_metadata.py
nvpohanh
reviewed
Oct 22, 2026
nvpohanh
left a comment
Collaborator
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 GSM8K and TPS/User results have no commands, so nobody can rerun them. The description gives GB300, TP8 and the plugin commit, but not the model checkpoint path or the server flags.
Fix
Add these to the PR description:
- the server launch command for each row (model path, the two-tray TP8 flags,
--enable-nvidia-megakernel, the speculative algorithm and step counts, attention backend, KV cache dtype); - the GSM8K eval command, and how the fixed 250-question subset is chosen;
- the benchmark command for the static 128K decode, and how acceptance is forced to 4.80.
…th bound ForwardBatch.init_new sets attention_kv_len_lower_bound on every one-request batch, and TBO's filter_batch rejects any set field it does not carry, so a two-batch-overlap split of such a batch raised before the forward. The bound belongs to the unsplit batch; the children get None.
…rectly _BINDINGS held "module:attribute" strings that _binding_class resolved with importlib and getattr. EagleBinding is in-tree and eagle_binding.py does not import runtime.py, so runtime.py imports it and _BINDINGS maps each architecture to the class.
…a speculative token map With --speculative-token-map the draft lm_head keeps only the hot tokens, so the draft extend's top-1 is a hot-vocab index that SGLang maps through hot_token_id. The entries get no map and would hand verify hot-vocab ids, so init_eagle_megakernel refuses the setup at startup.
…rnel-binding-main decode_cuda_graph_runner.py: keep main's DSpark class defaults beside the attention-variant defaults, and main's string LoRA variants in the capture loop, which still captures the attention variants only where _attention_varies_at holds.
# Conflicts: # python/sglang/kernels/plugin_kernels/nvidia/spec.py # python/sglang/srt/megakernels/runtime.py # test/registered/unit/kernel_plugins/nvidia/test_eagle_binding.py
YAMY1234
requested review from
BBuf,
DarkSharpness,
HaiShaw,
HydraQYH,
celve and
yuan-luo
as code owners
October 26, 2026 04:20
Collaborator
Author
|
@Oasis-Git Po-Han's comments are addressed and the conflicts are resolved; could you take a look when you have a moment? Thanks! |
nvpohanh
approved these changes
Oct 27, 2026
This was referenced Oct 28, 2026
weireweire
added a commit
to SemiAnalysisAI/InferenceX
that referenced
this pull request
Oct 28, 2026
… 2 plugin nightly-dev-cu13-20261028-586355a8 bundles sgl-nvidia-mega 6fd7ac30 (megakernel API 1), while its SGLang requires API 2 since sgl-project/sglang#45266, so --enable-nvidia-megakernel fails at startup. TP4 c1 keeps its previous engine settings and pins flashmla like the other TP-sharded points.
nvrohanv
added a commit
to nvrohanv/sglang
that referenced
this pull request
Oct 29, 2026
One conflict, in the spec import block of python/sglang/srt/kernel_plugins/nvidia/binding.py: this branch imports FLAG_SETS_ENV and main (sgl-project#45266) imports GRAPH_VARIANT_RUNNERS; both are kept.
nvrohanv
added a commit
to nvrohanv/sglang
that referenced
this pull request
Oct 29, 2026
sgl-project#45266 made the megakernel contract version 2: the binding reads draft_loop, draft_extend, begin_draft_round and graph_variants from every built object. The draft capture test's built object offers none of them, as main's FakeBuilt does.
This was referenced Oct 29, 2026
nvpohanh
added a commit
to SemiAnalysisAI/InferenceX
that referenced
this pull request
Nov 3, 2026
…ly with the tuned low-latency settings and TP4 c1 megakernel / [NVIDIA][AgentX] GB300 DSV4.1-Flash SGLang 升级到 20261030 nightly,采用调优后的低延迟配置并在 TP4 c1 启用 megakernel (#4603) * Update GB300 DSV4.1-Flash SGLang AgentX image to nightly-dev-cu13-20261025-65633129 Move dsv41flash-fp4-gb300-sglang-agentic-dspark from nightly-dev-cu13-20261021-c1c287a4 to the digest-pinned nightly-dev-cu13-20261025-65633129, the image the Dynamo + SGLang agg key already uses. Recipes and search space are unchanged. * Set perf-changelog pr-link to #4603 * Move GB300 DSV4.1-Flash SGLang AgentX to 20261028 nightly with the tuned low-latency settings Use nightly-dev-cu13-20261028-586355a8, which includes sgl-project/sglang#46404 and #46891. TP4 c1 runs as the batch-1 NVIDIA megakernel point of the Dynamo + SGLang aggregated row, without SIM_DRAW_AHEAD so the simulated step does the same work as a real one. TP4 c4/c16 and TP2/EP2 c16/c32 pin the flashmla attention backend instead of auto (MegaAttention pads per-rank heads to 64). * Keep SIM_DRAW_AHEAD on the TP4 c1 megakernel point The gate only moves the simulated-acceptance draw, a host-side sample plus a fill that real acceptance never runs, ahead of the draft launch. It does not skip work that a real-acceptance step performs. * Keep TP4 c1 off the megakernel until the image ships a megakernel API 2 plugin nightly-dev-cu13-20261028-586355a8 bundles sgl-nvidia-mega 6fd7ac30 (megakernel API 1), while its SGLang requires API 2 since sgl-project/sglang#45266, so --enable-nvidia-megakernel fails at startup. TP4 c1 keeps its previous engine settings and pins flashmla like the other TP-sharded points. * Move the GB300 DSV4.1-Flash SGLang curve to the 20261029 nightly and run TP4 c1 on the megakernel nightly-dev-cu13-20261029-c10e0e17 bundles sgl-nvidia-mega 54b428921749 (megakernel API 2), so TP4 c1 returns to its megakernel config. The 16 runtime-optimization variables it set one by one are replaced by SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION (sgl-project/sglang#47105). * Move the GB300 DSV4.1-Flash SGLang key to the 20261030 nightly for the simulated verify accept cost fix Root cause: nightly-dev-cu13-20261029-c10e0e17 predates sgl-project/sglang#46840, so simulated acceptance skipped the real verify accept cost and the TP4 c1 point was not measured on the methodology-conformant path. Fix: pin lmsysorg/sglang:nightly-dev-cu13-20261030-302b78cc by digest. It is 63 commits past the #46840 merge and bundles the same sgl-nvidia-mega 54b428921749 (megakernel API 2). Update this PR's changelog entry to name the image and #46840. Validation: Dynamo + SGLang TP4 c1 megakernel, c4 and c16 started and completed on 302b78cc with target and draft megakernels active on all four ranks. --------- Co-authored-by: weireweire <[email protected]> Co-authored-by: Po-Han Huang <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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
The NVIDIA megakernel for Qwen3.5-397B-A17B (NVFP4) decode on GB300 lives out of tree, in sgl-project/sgl-nvidia-mega#20. #44945 added
--enable-nvidia-megakerneland the plugin layer for DeepSeek-V4.1. This PR adds what the Qwen3.5 megakernel needs on the SGLang side, in the same shape:SGLang keeps every runner, worker, schedule batch and CUDA graph, and everything after a target step (sampling, acceptance, commits). The plugin gets data: the forward's attention and GDN metadata, the KV and mamba pools, and per-entry structs with SGLang-owned outputs. Before capture, every rank must offer the same entries, batch sizes and variants, or SGLang refuses to start.
This PR is based on main and does not depend on #45474 (the runtime changes for the same decode path). Either can merge first; merged in either order, the two give the same tree. Without
--enable-nvidia-megakernelnothing changes.Modifications
One commit per change:
megakernels/runtime.py,spec.py). Qwen3.5'sHybridLinearAttnBackendkeeps its metadata on its two child backends, so it needs its own binding.spec.ENTRIESnames the optional entries (draft_sampler,draft_loop,draft_extend,begin_draft_round), and every rank must offer the same ones.megakernels/eagle_binding.py, new).EagleBindingreturns the view a covered step reads: attention metadata, GDN slots, the KV and mamba pools. Each pool is sealed at its first read, andassert_livefails by name if one is reallocated. The entries' structs carry tensors and numbers only. What a plugin may call or read besides data is listed in literal tuples that the plugin's contract test pins.draft_loopanddraft_extend(speculative/eagle_megakernel.py, new, plus the worker and the two draft graph runners).begin_draft_roundruns on the host before a served draft graph replays.init_attention_backends, before any capture. It refuses setups it cannot serve: a non-chain draft, rejection sampling, DP attention, a sliding-window target KV pool, or backends other than GDN withtrtllm_mha.spec.py,runtime.py,forward_batch_info.py,decode_cuda_graph_runner.py, the draft runners).graph_variantsfortarget_verify,draft_loopordraft_extend: capture labels plus aselectthat picks one from host state. At the batch sizes that run the megakernel, the runner captures one graph per label and replays the oneselectpicks.ForwardBatch.attention_kv_len_lower_boundgivesselecta one-request batch's committed KV length without touching the device.Earlier revisions of this PR were stacked on #45474 and also offered
verify_sampleandgdn_extend. Both are removed: the plugin'sverify_samplehad no kernel and only turned on #45474's post-verify graphs (SGLANG_ENABLE_EAGLE_POST_VERIFY_CUDA_GRAPH=1does the same), and no plugin offeredgdn_extend. They can come back in a follow-up once a plugin has a kernel for them.Known limits: draft entries serve graph replays only; a variant's
selectgets a KV length only for one-request batches; SGLang's images pin a plugin commit without Qwen3.5 (SGL_NVIDIA_MEGA_COMMIT), so sgl-project/sgl-nvidia-mega#20 must be installed until that pin moves.Accuracy Tests
GB300, TP8, real acceptance, GSM8K on a fixed 250-question subset (sampled: temperature 0.6, top-p 0.95, top-k 20).
ForwardBatchfield and one field in theSGLANG_LOG_DECODE_GRAPH_KEYdebug line.Greedy outputs match the reference on 249 / 250 questions in both rows. Every slot, entry and variant capture is active on 8 / 8 ranks.
Speed Tests and Profiling
GB300, TP8 across two 4-GPU trays. Static decode of one request at 128K context with forced acceptance 4.80, about 1,780 rounds per server start. TPS/User = 4.80 tokens / round time. Rows 1–3 are the mean of two pairs of trays run in opposite orders. The plugin was measured at
3509187d74, an earlier revision of sgl-project/sgl-nvidia-mega#20; the PR head differs only by an opt-in for more than one request, off by default.¹ On a third pair of trays, row 3 reaches 101.0% of the reference at P50 at 128K, and 100.8% / 100.6% and 101.9% / 101.6% (P50 / P90) at 8K and 32K.
These results were measured on main
28448a86d4; the branch has since been rebased onto mainb57b5e2286without changes, and the GPU checks are being repeated on the new base.Row 2 gains little because the round becomes host-bound: the verify takes 1.87 ms less, but the gaps between graph segments grow from 0.06 to 1.36 ms per round. Row 3 adds #45474, which removes that host work, and the gaps return to 0.06 ms.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): 🚫 Run #40268603176
Latest PR Test (Extra): ❌ Run #40268603163
Latest PR Test (AMD ROCm 10): ✅ Run #40268603217