Skip to content

[Feat] [NVIDIA] muse_spark: Add the Muse Spark Open kernel half as opt-in hooks on SGLang's forward - #39

Open
wenscarl wants to merge 8 commits into
sgl-project:mainfrom
wenscarl:muse-spark-kernels
Open

wenscarl wants to merge 8 commits into
sgl-project:mainfrom
wenscarl:muse-spark-kernels

Conversation

@wenscarl

@wenscarl wenscarl commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Muse Spark Open (MuseSparkForConditionalGeneration) runs on SGLang today with stock kernels. This PR carries NVIDIA's fused
kernels for the model, developed and measured as an out-of-tree plugin (muse_vr_plugin), into this repository so that they ship
with the other megakernels and follow its license, notice and CI rules.

It takes the kernel half only. SGLang splits a megakernel in two: --enable-nvidia-megakernel loads the plugin, and where the
plugin's spec covers a step its kernels replace SGLang's operations; SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION switches SGLang's own
host-side optimizations (CPU work between GPU launches) and never switches the kernels. This PR is the first half. The host-side
runtime modules the plugin also carries stay out of this repository; they belong in SGLang, one optimization per pull request (see
"Not included").

It is deliberately not shaped like deepseek_v41. That spec replaces a whole decode step with a rewritten forward. The Muse Spark
kernels are separate optimizations at separate points inside SGLang's own forward (a norm, an attention call, a MoE finalize, a
boundary reduction, a sampler), so there is no single step function to hand over, and writing one would be a rewrite of the model
rather than a port of the kernels.

Authorship and credit

The kernels and hook components are the work of Rohan Varma (@nvrohanv), developed in muse_vr_plugin. Shu Wang (@wenscarl)
ported them into this repository: the spec/plan/runtime skeleton, the registry and entry points, the SGLang-source pin handling, the
license, NOTICE and header work, and the import fixes. Every commit carries Co-authored-by: Rohan Varma <rohanv@nvidia.com>; some
also carry an AI-assistant trailer. Both authors' contributions are NVIDIA's; source headers carry the NVIDIA copyright line.

Modifications

All new code is under sgl_nvidia_mega/muse_spark/; outside it the PR touches plugin.py (registration), NOTICE,
.codespellrc and .github/CODEOWNERS.

  • Spec, plan, runtime skeleton. Registers MuseSparkForConditionalGeneration through the same interface as deepseek_v41
    (MEGAKERNEL_API_VERSION = 2), scoped to the target-verify step. The requirements are the configuration the kernels were measured
    on (NVFP4 KV with modelopt_fp4 weights, DFLASH speculative decoding, FlashInfer TRT-LLM MoE runner with the FlashInfer
    all-to-all, trtllm_mha, sm_107, TP4); a different setup is refused. build() offers no step width yet, so with
    --enable-nvidia-megakernel the server keeps running SGLang's own forward and says the spec covers no step. NUMERICS still has
    empty tolerances.
  • 47 components as hooks, registered through sglang.srt.plugins.hook_registry:
    • NVFP4 KV: nvfp4_kv, kv4_dec, kv_draftwin, ctx_kv_counter
    • MoE: moe_ld, bf16_ldw, moe_tail, proj_publish, unorm_boundary, fin2, fin_2shot, hb0_rr, mid_rs, moe_tactic,
      prefill_moe_tactic, prefill_moe_x, sp_combine_inplace, pfin, sp_fp4_dispatch
    • GEMM and projections: gemm_pick, gemm_lt, draft_head_lt, fp8_prefill (MXFP8 prefill projections), o_rowshard, rs_samem
    • Attention and boundaries: verify_attn, small_extend_attn, xattn_b, prefill_attn, prefill_qkn, ar_attn_boundary, input_norm,
      final_norm, car_table, pull_bounded
    • Draft and sampling: draft_candidates, draft_boundary, draft_attn, draft_kv_append, draft_topk, verify_topk_sample,
      verify_logits_gather, spec_sample_split, softmax_split, ctx_proj_overlap, ctx_proj_prefill, sp_gate
    • Kernels are in components/csrc (61 .cuh, 1 .cu), Python entry points in components/ops.
  • Contract with SGLang. Every module that imports from sglang.* declares what it reads in SGLANG_READS, as
    test/unit/test_contract.py requires, so a rename in SGLang fails that test instead of a GPU server's startup. Two import forms
    the test cannot express were rewritten without changing what they bind (from P import sub to import P.sub as sub, and
    from M import a as b to a module import plus b = module.a). Reads the code guards (hasattr, getattr with a default, or
    "branch layout only") are not declared; one real rename, MuseSpark1xForCausalLM to MuseSparkTextForCausalLM, is declared as
    either name, and sp_gate still uses the old one and steps aside by its source pin on the new layout.
  • Safe by default. Every component is opt-in (MUSE_VR_* environment switches) and off by default, so a server that sets none of
    them runs stock SGLang. A registration failure is recorded and leaves SGLang stock instead of taking the server down. Each component
    pins the SGLang source files it hooks by sha256 and steps aside if they have moved. The order of COMPONENTS is load-bearing
    (several hook the same call and must wrap each other in a fixed order; the comments give it).
  • components/vendor/. Two components bind SGLang pull requests that the SGLang revision this package pins does not contain:
    #47174 (fused all-reduce + norm, used by ar_attn_boundary) and #46724 (fused finalize + two-shot push, used by fin_2shot). Their
    files are carried as Apache-2.0 copies with their provenance in vendor/README.md; two are unchanged, the others carry a
    "Modified by NVIDIA" header (a bounded slot poll that traps instead of hanging). They can be dropped once SGLang has the pull requests.
  • Licensing. Every source file carries SPDX-License-Identifier and a copyright line. Files adapted from SGLang also carry
    Portions Copyright 2023-2024 SGLang Team (Apache-2.0) plus an origin and "Modified by NVIDIA" note. NOTICE gains the SGLang- and
    FlashInfer-derived paragraphs, and the four license texts FlashInfer's NOTICE points to are included under
    components/include/licenses/. Three moe_x_kernels files keep their BSD-3-Clause header.
  • Not included.
    • The host-side runtime half, which belongs in SGLang under SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION: sampling_graph,
      eager_commit, dflash_prefill_async, sb_lite, kv_hostbook, swa_hostsplit, kv_accounting, and rust_treecore.
      softmax_split and spec_sample_split consulted sampling_graph only to allow a CUDA-graph capture inside its own capture;
      without it a capture is always refused, which is what they did whenever it was not engaged.
    • The plugin's validation instruments (graph_audit, teacher_force, draft_probe, kv_evict_probe, kv_tap); they are never served.
    • The plugin's low-concurrency TP4 and TP8 sites, which are separate lineages and follow in later pull requests.

Depends on SGLang changes that are not merged

Tested against: no GPU run of this branch has been made. The kernels were
developed and measured, as the out-of-tree plugin, on SGLang 306ccf6 (the 2026-10-20 nightly image). The unit-test workflow pins SGLang aa3e34aa; the
components' sha256 pins name 306ccf6-era sources, so on aa3e34aa they step aside rather than engage. Run statically against the
aa3e34aa sources, test/unit/test_contract.py passes for every muse_spark module (three qwen3_5 cases fail there on unmodified main
too). No GPU run of this branch has been made.

Accuracy Tests

None from this branch yet. Accuracy with each component group on and off, on the same server, still has to be run and
attached; the template asks for it because this PR changes kernel and forward code.

Speed Tests and Profiling

None from this branch yet. The kernels were measured in the out-of-tree plugin, but those numbers were not produced from
this branch, and the plugin runs include the host-side runtime modules left out here, so the kernel half alone should not be expected
to reproduce the plugin's numbers.

Checklist

  • pre-commit run --all-files passes (isort, ruff, ruff-format, codespell; pres, ot, optin, nown, kOwn are on the codespell ignore list).
  • Tests under test/ cover the change. [No new tests; the existing contract test now covers the muse_spark modules' SGLang reads.]
  • The SGLang commit or PR this was tested against is named above. [No: not tested on a GPU yet; see the note under Modifications.]
  • Accuracy and speed results are attached. [Not yet.]
  • A new model adds one line to .github/CODEOWNERS that names its owner (**/*muse_spark* @wenscarl @nvrohanv).

Review and Merge Process

  1. The lint and Check PR title checks must pass.
  2. Ask a code owner from .github/CODEOWNERS to review.
  3. Merge with "Squash and merge": the PR title becomes the commit title on main.

@wenscarl

wenscarl commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Results: Muse Spark TEP8 c1 megakernel (TRT-LLM port) on Rubin

Scope note. These numbers come from the TRT-LLM port of the Muse Spark TEP8 c1 megakernel (muse_spark_tep8): layers 1–60 as one persistent kernel at TP8 / EP8. That is not the TP4 hook components in this PR's muse_spark/ package, so they are not a test of this branch. They are posted here as related Muse Spark megakernel results on Rubin.

Summary

  • Accuracy: GSM8K accuracy equals stock (117/128 for both).
  • Acceptance length: AL is 1.2% lower than stock.

Setup

Hardware 2 nodes × 4 Rubin GPUs (sm_107), TP8 / EP8, HBM clock locked
Megakernel mode lean_icfpoxaft_rt16_ld479_ue10_et5_nb3_bh3_pb15_ah391_s4, 8 rows, layers 1–60, attached through MuseSpark1xModel.layer_span_runner
Speculative decoding DFlash, verify width 8
A/B Same job, same nodes, same server flags; the only difference is SGL_MUSE_MK=1

GSM8K accuracy

Protocol:

  • The first 128 GSM8K test questions, temperature 0, chat API.
  • Real DFlash acceptance; nothing is simulated.
Metric stock megakernel Δ
Correct 117 / 128 117 / 128 0
Truncated (hit max_new) 24 24 0
Acceptance length 5.063 5.003 −1.2%
Decode throughput (client end-to-end) 896 tok/s 1250 tok/s +40%
  • Disagreements are symmetric. The arms disagree on 10 questions: 5 that only the megakernel gets right and 5 that only stock gets right. This looks like numeric divergence in long reasoning, not a systematic loss.
  • No output is token-identical between arms (0 / 128). This is expected from the per-layer numeric differences below.

Per-layer numerics

  • KV-cache bytes written by the megakernel are bit-exact against stock.
  • Hidden-state relative error on layers 1–60, against stock:
    • lean_s4: worst layer 6.7%.
    • no-rl: median about 1%; worst is L21 at 9.9%.

Known gaps

  • AL −1.2% is just outside a 1% gate. No stock-vs-stock rerun yet shows the run-to-run AL noise.
  • 19% of GSM8K answers hit max_new in both arms. A rerun with a larger max_new would be a cleaner accuracy check.
  • bench_gsm8k.py crashed in its summary step. The server's meta_info has no first_token_latency, so the GSM8K numbers were computed offline from the per-question JSONL. A fix and rerun are in progress.

🤖 Generated with Claude Code

@rohithrr9

Copy link
Copy Markdown

Added verify_mk on top (520c27b): TensorRT-LLM's sm_107 decode megakernel for the TP8 one-request target-verify step, as an opt-in component (MUSE_VR_VERIFY_MK=1, default off). It adds new files and small entries to six existing files, and refuses to boot next to moe_ld, moe_tail, mid_rs or full_attn_wide.

Kernel off vs on, same server arguments: SGLang 306ccf6, Muse Spark Open 816B-A42B NVFP4 with the DFlash2 draft (8 draft tokens), TP8 = EP8 over two nodes of sm_107 GPUs, FP8 KV with pages of 128, trtllm_mha, CUDA graphs, real draft acceptance. The run used the same component code on main; the commit here differs only in its refusal list.

MUSE_VR_VERIFY_MK=0 MUSE_VR_VERIFY_MK=1
GSM8K, 1319 questions (zero-shot chat, greedy, one request at a time) 1230 (93.25 %) 1230 (93.25 %)
c1 (--max-running-requests 1): output tok/s 703.7 1058.2
c1: median TPOT (ms) 0.80 0.55
c1: median TTFT (ms) 138.7 138.1
c1: accept length 5.09 5.09
c2 (--max-running-requests 2): median TPOT (ms) 1.12 1.10

Speed: python3 -m sglang.bench_serving --dataset-name random-ids --random-input-len 8192 --random-output-len 512 --random-range-ratio 1.0 --num-prompts 16*c --max-concurrency c --warmup-requests 2 --seed 1. The kernel serves one request, so c2 matches by design.

Compare mode (each layer against the stock layer on the same inputs, 4 verify forwards, 8 ranks, layers 1-60): worst residual-stream relative error 8.8 %; the KV-cache rows the kernel writes match stock's except for at most 2 bytes per layer; no non-finite values.

@wenscarl
wenscarl marked this pull request as ready for review November 12, 2026 18:02
@wenscarl
wenscarl requested a review from Oasis-Git as a code owner November 12, 2026 18:02
rohithrr9 added a commit to rohithrr9/sgl-nvidia-mega that referenced this pull request Nov 13, 2026
verify_mk (sgl-project#39) runs TensorRT-LLM's Muse Spark decode megakernel on the one-request verify step on Rubin (sm_107).
This adds its GB300 (sm_103a) port as a plug-in on top of sgl-project#39, in the per-hardware layout:
sgl_nvidia_mega/muse_spark/sm103. Rubin's files (components/verify_mk, components/vendor/trtllm_ab93b78) are
unchanged, and every device other than compute capability 10.3 loads what it loads today.

- sm103/trtllm_ab93b78: a copy of components/vendor/trtllm_ab93b78 (NVIDIA/TensorRT-LLM
  ab93b785a476f01d2f1e1907c930780fc6d7832e) with sm_103a as the build target: one CTA per SM of GB300's 152
  (MSO_MK_CTAS=152), TensorRT-LLM's 212 QKV runs kept (MSO_MK_QKV_RUNS=212), and every launch planned for 212 CTAs
  and folded onto 152 by fold.py (added; MUSE_VR_VERIFY_MK_FOLD_SPREAD=1 moves the second o_proj unit of a
  sliding-window host CTA to an attention CTA, so no CTA runs two). Dev-only builds (MUSE_VR_VERIFY_MK_BUILD):
  single-lever variations of the served build and their combinations, an expert-weight L2 prefetch prototype
  (MSO_MK_XPF) and the stamped twin (per-unit timelines, MUSE_VR_VERIFY_MK_STAMPS). Changed TensorRT-LLM blocks are
  marked verify_mk; pre-commit skips the directory, as it skips the vendored original.
- sm103/verify_mk: a copy of components/verify_mk that imports that kernel, plus MUSE_VR_VERIFY_MK_TAPS (the kernel
  writes the DFlash taps of layers 1-60).
- components/__init__.py: on compute capability 10.3 (read through NVML, so CUDA is not initialized) the loader
  imports sm103.verify_mk in place of components.verify_mk (ARCH_MODULES).
- pyproject.toml ships the copy's license and stage headers.
- Tests: test_muse_spark_sm103_verify_mk.py (the verify_mk contracts on the sm103 copy, and the loader's choice) and
  test_muse_spark_sm103_verify_mk_fold.py (the 212-to-152 fold of the served build's plans).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rohithrr9 added a commit to rohithrr9/sgl-nvidia-mega that referenced this pull request Nov 13, 2026
verify_mk (sgl-project#39) runs TensorRT-LLM's Muse Spark decode megakernel on the one-request verify step on Rubin (sm_107).
This adds its GB300 (sm_103a) port as a plug-in on top of sgl-project#39, in the per-hardware layout:
sgl_nvidia_mega/muse_spark/sm103. Rubin's files (components/verify_mk, components/vendor/trtllm_ab93b78) are
unchanged, and every device other than compute capability 10.3 loads what it loads today.

- sm103/trtllm_ab93b78: a copy of components/vendor/trtllm_ab93b78 (NVIDIA/TensorRT-LLM
  ab93b785a476f01d2f1e1907c930780fc6d7832e) with sm_103a as the build target: one CTA per SM of GB300's 152
  (MSO_MK_CTAS=152), TensorRT-LLM's 212 QKV runs kept (MSO_MK_QKV_RUNS=212), and every launch planned for 212 CTAs
  and folded onto 152 by fold.py (added; MUSE_VR_VERIFY_MK_FOLD_SPREAD=1 moves the second o_proj unit of a
  sliding-window host CTA to an attention CTA, so no CTA runs two). Dev-only builds (MUSE_VR_VERIFY_MK_BUILD):
  single-lever variations of the served build and their combinations, an expert-weight L2 prefetch prototype
  (MSO_MK_XPF) and the stamped twin (per-unit timelines, MUSE_VR_VERIFY_MK_STAMPS). Changed TensorRT-LLM blocks are
  marked verify_mk; pre-commit skips the directory, as it skips the vendored original.
- sm103/verify_mk: a copy of components/verify_mk that imports that kernel, plus MUSE_VR_VERIFY_MK_TAPS (the kernel
  writes the DFlash taps of layers 1-60).
- components/__init__.py: on compute capability 10.3 (read through NVML, so CUDA is not initialized) the loader
  imports sm103.verify_mk in place of components.verify_mk (ARCH_MODULES).
- pyproject.toml ships the copy's license and stage headers.
- Tests: test_muse_spark_sm103_verify_mk.py (the verify_mk contracts on the sm103 copy, and the loader's choice) and
  test_muse_spark_sm103_verify_mk_fold.py (the 212-to-152 fold of the served build's plans).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t-in hooks on SGLang's forward

Adds NVIDIA's fused kernels for Muse Spark Open (MuseSparkForConditionalGeneration) under
sgl_nvidia_mega/muse_spark/:

- the spec, plan and runtime skeleton for the target-verify step, registered through the same
  interface as deepseek_v41;
- the components, as hooks on SGLang's own forward: each is opt-in (MUSE_VR_* switches, off by
  default), pins the SGLang sources it hooks by sha256 and steps aside if they moved, and declares
  the SGLang names it reads (SGLANG_READS) for test/unit/test_contract.py;
- verify_mk (MUSE_VR_VERIFY_MK=1, off by default): TensorRT-LLM's sm_107 decode megakernel on the
  one-request target-verify step, vendored from NVIDIA/TensorRT-LLM
  ab93b785a476f01d2f1e1907c930780fc6d7832e;
- the vendored SGLang pull-request files the components bind, the license texts, NOTICE paragraphs,
  SPDX and copyright headers, and the code owners.

The host-side runtime half stays out of this repository.

Co-authored-by: Rohan Varma <rohanv@nvidia.com>
Co-authored-by: Rohith Rachala <rrachala@nvidia.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rohithrr9 added a commit to rohithrr9/sgl-nvidia-mega that referenced this pull request Nov 13, 2026
verify_mk (sgl-project#39) runs TensorRT-LLM's Muse Spark decode megakernel on the one-request verify step on Rubin (sm_107).
This adds its GB300 (sm_103a) port as a plug-in on top of sgl-project#39, in the per-hardware layout:
sgl_nvidia_mega/muse_spark/sm103. Rubin's files (components/verify_mk, components/vendor/trtllm_ab93b78) are
unchanged, and every device other than compute capability 10.3 loads what it loads today.

- sm103/trtllm_ab93b78: a copy of components/vendor/trtllm_ab93b78 (NVIDIA/TensorRT-LLM
  ab93b785a476f01d2f1e1907c930780fc6d7832e) with sm_103a as the build target: one CTA per SM of GB300's 152
  (MSO_MK_CTAS=152), TensorRT-LLM's 212 QKV runs kept (MSO_MK_QKV_RUNS=212), and every launch planned for 212 CTAs
  and folded onto 152 by fold.py (added; MUSE_VR_VERIFY_MK_FOLD_SPREAD=1 moves the second o_proj unit of a
  sliding-window host CTA to an attention CTA, so no CTA runs two). Dev-only builds (MUSE_VR_VERIFY_MK_BUILD):
  single-lever variations of the served build and their combinations, an expert-weight L2 prefetch prototype
  (MSO_MK_XPF) and the stamped twin (per-unit timelines, MUSE_VR_VERIFY_MK_STAMPS). Changed TensorRT-LLM blocks are
  marked verify_mk; pre-commit skips the directory, as it skips the vendored original.
- sm103/verify_mk: a copy of components/verify_mk that imports that kernel, plus MUSE_VR_VERIFY_MK_TAPS (the kernel
  writes the DFlash taps of layers 1-60).
- components/__init__.py: on compute capability 10.3 (read through NVML, so CUDA is not initialized) the loader
  imports sm103.verify_mk in place of components.verify_mk (ARCH_MODULES).
- pyproject.toml ships the copy's license and stage headers.
- Tests: test_muse_spark_sm103_verify_mk.py (the verify_mk contracts on the sm103 copy, and the loader's choice) and
  test_muse_spark_sm103_verify_mk_fold.py (the 212-to-152 fold of the served build's plans).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wenscarl and others added 4 commits November 13, 2026 16:19
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NOTICE: keep both new paragraphs (the Kimi K3.1 DCP top-k merge adapted from SGLang, and the TensorRT-LLM copy
verify_mk runs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_binding_limit made a new positions buffer for each of its five bindings and dropped the previous one. Bindings
are keyed by buffer address, so on the CI runner a freed buffer's address came back for a later binding, matched an
earlier one, and the fifth binding was taken instead of refused. The test now holds every buffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rubin's (sm_107) verify_mk code moves to its architecture's folder, as the other models keep their GB300 code in
<model>/sm103: components/verify_mk -> sm107/verify_mk and components/vendor/trtllm_ab93b78 -> sm107/trtllm_ab93b78
(git mv; the files change only in their imports and paths). The component loader imports verify_mk from sm107
(components.MODULES). The TensorRT-LLM part of components/vendor/README.md moves to sm107/README.md, and NOTICE,
pyproject.toml's package data and the pre-commit exclude follow the new paths. The test moves to
test_muse_spark_sm107_verify_mk.py, imports the real sm107 package before its stand-ins (so it also passes on its
own), and checks the loader's choice. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rohithrr9 added a commit to rohithrr9/sgl-nvidia-mega that referenced this pull request Nov 18, 2026
verify_mk (sgl-project#39) runs TensorRT-LLM's Muse Spark decode megakernel on the one-request verify step on Rubin (sm_107),
from sgl_nvidia_mega/muse_spark/sm107. This adds its GB300 (sm_103a) port as a plug-in on top of sgl-project#39, in the same
per-hardware layout: sgl_nvidia_mega/muse_spark/sm103. Rubin's files are unchanged, and every device other than
compute capability 10.3 loads what it loads today.

- sm103/trtllm_ab93b78: a copy of sm107/trtllm_ab93b78 (NVIDIA/TensorRT-LLM
  ab93b785a476f01d2f1e1907c930780fc6d7832e) with sm_103a as the build target: one CTA per SM of GB300's 152
  (MSO_MK_CTAS=152), TensorRT-LLM's 212 QKV runs kept (MSO_MK_QKV_RUNS=212), and every launch planned for 212 CTAs
  and folded onto 152 by fold.py (added; MUSE_VR_VERIFY_MK_FOLD_SPREAD=1 moves the second o_proj unit of a
  sliding-window host CTA to an attention CTA, so no CTA runs two). Dev-only builds (MUSE_VR_VERIFY_MK_BUILD):
  single-lever variations of the served build and their combinations, an expert-weight L2 prefetch prototype
  (MSO_MK_XPF) and the stamped twin (per-unit timelines, MUSE_VR_VERIFY_MK_STAMPS). Changed TensorRT-LLM blocks are
  marked verify_mk; pre-commit skips the directory, as it skips the vendored original.
- sm103/verify_mk: a copy of sm107/verify_mk that imports that kernel, plus MUSE_VR_VERIFY_MK_TAPS (the kernel
  writes the DFlash taps of layers 1-60).
- components/__init__.py: on compute capability 10.3 (read through NVML, so CUDA is not initialized) the loader
  imports sm103.verify_mk in place of sm107.verify_mk (ARCH_MODULES).
- pyproject.toml ships the copy's license and stage headers; NOTICE names the copy.
- Tests: test_muse_spark_sm103_verify_mk.py (the verify_mk contracts on the sm103 copy, and the loader's choice) and
  test_muse_spark_sm103_verify_mk_fold.py (the 212-to-152 fold of the served build's plans).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rohithrr9

Copy link
Copy Markdown

Pushed three commits on top of b9bc352: merged main (NOTICE keeps both new paragraphs), fixed the failing unit test (test_binding_limit now holds every positions buffer: bindings are keyed by address, and CI's allocator reused a freed one), and moved Rubin's verify_mk to the per-hardware layout, muse_spark/sm107/verify_mk and muse_spark/sm107/trtllm_ab93b78 (git mv, paths only; the loader takes verify_mk from sm107). #61 adds muse_spark/sm103 on top.

rohithrr9 and others added 2 commits November 20, 2026 01:28
verify_mk (TensorRT-LLM's Rubin decode megakernel on the one-request verify step: its host runner and the copied
TensorRT-LLM tree in muse_spark/sm107, 35.4k lines, 33.4k of them the TensorRT-LLM copy) moves to its own pull request
on main; it needs nothing of the components here. This pull request keeps every component.

- Removed: muse_spark/sm107/ and test/unit/test_muse_spark_sm107_verify_mk.py, the registry's verify_mk entry and its
  module path, sgl_compat's alias of SGLang's megakernel runtime module, and the NOTICE paragraph, package data and
  pre-commit exclusion of the TensorRT-LLM copy (those four files match the branch's base on main again).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-scope operations

The plugin's later fix to the two MoE-LD-W kernels, ported as is. The CTA abort flag (g_abort) was set with a C++ volatile
store in fail(), polled with a C++ volatile load in aborted() and reset by thread 0 with a plain store at kernel start. Every
access is now an explicit strong operation at CTA scope on the shared state space, in both files:
- aborted(): ld.relaxed.cta.shared.u32 (one load, as before);
- fail(): atom.relaxed.cta.shared.exch.b32 after the error-word atomicOr (failure path only);
- the kernel-start reset by thread 0: st.relaxed.cta.shared.u32 (abort_reset()).
The setter and the pollers are then morally strong and do not form a data race under the PTX ISA memory consistency model.
Every other use of the flag goes through aborted() and fail(), and the flag's values and the points where it is read or
written are unchanged, so outputs are unchanged on every path.

Co-authored-by: Rohan Varma <rohanv@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rohithrr9

rohithrr9 commented Nov 20, 2026 •

Copy link
Copy Markdown

Updated description for this pull request at 890d0b6: the review changes (last commit) and the absolute speed numbers:

Motivation

Muse Spark Open (MuseSparkForConditionalGeneration) runs on SGLang today with stock kernels. #42 brought NVIDIA's fused kernels for the model into sgl_nvidia_mega/muse_spark for GB300 (sm_103): 24 hook components. This PR adds the rest of the Rubin (sm_107) TP4 set on top: 23 more components and their kernels, taken from NVIDIA's out-of-tree plugin (muse_vr_plugin) that serves the model at TP4 on Rubin at 80 to 112 concurrent requests, so they ship with the other megakernels and follow this repository's license, notice and CI rules.

It takes the kernel half only. SGLang splits a megakernel in two: --enable-nvidia-megakernel loads the plugin, and where the plugin's spec covers a step its kernels replace SGLang's operations; SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION switches SGLang's own host-side optimizations (CPU work between GPU launches) and never switches the kernels. This PR is the first half. The host-side runtime modules the plugin also carries stay out of this repository; they belong in SGLang, one optimization per pull request (see "Not included").

It is deliberately not shaped like deepseek_v41. That spec replaces a whole decode step with a rewritten forward. The Muse Spark kernels are separate optimizations at separate points inside SGLang's own forward (a norm, an attention call, a MoE finalize, a boundary reduction, a sampler), so there is no single step function to hand over, and writing one would be a rewrite of the model rather than a port of the kernels.

Authorship and credit

The kernels and hook components are the work of Rohan Varma (@nvrohanv), developed in muse_vr_plugin. Shu Wang (@wenscarl) ported them into this repository: the spec/plan/runtime skeleton, the registry and entry points, the SGLang-source pin handling, the license, NOTICE and header work, and the import fixes. Rohith Rachala (@rohithrr9) kept the branch current with main, fixed CI and measured it on Rubin (below). The commits that bring his code (the port and the abort-flag fix) carry Co-authored-by: Rohan Varma <rohanv@nvidia.com>, which the squash merge keeps; some commits also carry an AI-assistant trailer. All contributions are NVIDIA's; source headers carry the NVIDIA copyright line.

Modifications

All changes are under sgl_nvidia_mega/muse_spark/: 103 new files and 4 changed ones, +54,326 / -9 lines (37 CUDA / C++ files with 24.0k lines, 69 Python files with 30.4k lines including the CuTe DSL kernels, one tactic data file). Nothing outside the package changes.

  • 23 components as hooks, added to main's 24 through the same registry (components/__init__.py, whose COMPONENTS order is load-bearing: several hook the same call and must wrap each other in a fixed order; the comments give it):
    • NVFP4 KV: ctx_kv_counter
    • MoE: moe_ld, bf16_ldw, moe_tail, proj_publish, unorm_boundary, fin2, fin_2shot, hb0_rr, mid_rs, moe_tactic, prefill_moe_tactic, prefill_moe_x
    • GEMM and projections: draft_head_lt, fp8_prefill (MXFP8 prefill projections), o_rowshard, rs_samem
    • Attention: prefill_attn, car_table
    • Draft and sampling: draft_attn, draft_topk, verify_logits_gather, softmax_split
    • Kernels are in components/csrc (61 .cuh and 1 .cu, against 25 on main), Python entry points in components/ops.
    • At the settings measured below, 12 of the 23 engage: bf16_ldw, fin_2shot, fp8_prefill, moe_ld, prefill_moe_x and proj_publish at 80, 96 and 112 concurrent requests, draft_attn, draft_head_lt, draft_topk, o_rowshard and rs_samem at 96 and 112, and ctx_kv_counter at 96. car_table acts on 8-rank communicators only; fin2, hb0_rr, mid_rs, moe_tactic, moe_tail, prefill_attn, prefill_moe_tactic, softmax_split, unorm_boundary and verify_logits_gather are not switched on by these settings.
    • prefill_moe_x is for Rubin and also needs MUSE_VR_MOE_X_MMA_HELPERS=cutlass.utils.rubin_helpers, the CuTe DSL module that builds its block-scaled MMAs; the SGLang image's nvidia-cutlass-dsl 4.8.0 ships it, and the measured runs set it. Switched on against off on the same nodes (1-hour runs), it raises p90 per-user output speed by 11 to 15.5 % and lowers p90 time to first token by 17 to 26 % at 80, 96 and 112 concurrent requests.
  • Changes to main's files. components/__init__.py registers the 23; pull_bounded pins the digest of its file as shipped (with its copyright lines); spec.py and ops/swa_t.py change comments only. The debug shadow checks and xattn_b's dump mode that [Feat] [NVIDIA] muse_spark: Serve the Muse Spark Open kernels on GB300 (sm_103) #42 removed stay out.
  • Safe by default. As on main: every component is opt-in (MUSE_VR_* environment switches) and off by default, so a server that sets none of them runs stock SGLang; a registration failure is recorded and leaves SGLang stock instead of taking the server down; each component pins the SGLang source files it hooks by sha256 and steps aside if they have moved; every module that imports from sglang.* declares what it reads in SGLANG_READS, which test/unit/test_contract.py checks.
  • MoE-LD-W abort flag. The last commit ports the plugin's later fix to moe_ldw.cuh and moe_ldwb.cuh: every access to the CTA abort flag becomes an explicit strong CTA-scope operation on shared memory (ld.relaxed.cta to poll, atom.relaxed.cta.exch to set, st.relaxed.cta for the reset at kernel start), so the setter and the pollers no longer form a data race under the PTX memory model; the flag's values and the points where it is read or written are unchanged, so outputs are unchanged.
  • Licensing. Every new source file carries SPDX-License-Identifier and a copyright line; files adapted from SGLang also carry Portions Copyright 2023-2024 SGLang Team (Apache-2.0) plus an origin and "Modified by NVIDIA" note. NOTICE and the vendored SGLang copies (components/vendor/) are main's.
  • Moved out. verify_mk (TensorRT-LLM's Rubin decode megakernel on the TP8 one-request verify step, with its 33.4k-line TensorRT-LLM copy, 36.6k lines in all) moves to its own pull request; it needs none of the components here. The TP8 single-request results in the comments below belong to it.
  • Not included.

SGLang pull requests these components bind

Tested against: SGLang 306ccf6 (the 2026-10-20 nightly image) with sgl-project/sglang#48950, #48947, #48948 and #48949 ported onto it, on Rubin (sm_107), with this branch at 859fee2 for the speed table and at e6bbe20 (with the abort-flag fix) for the accuracy test and a speed check at 96; see the tests below. 890d0b6 only takes out debug code that is off in every measured run. The unit suite passes on a CUDA-less host apart from the cases that fail on main in the same environment.

Accuracy Tests

GSM8K, all 1,319 test questions (zero-shot chat: "Please reason step by step, and put your final answer within \boxed{}.", temperature 0, up to 4,096 generated tokens, real draft acceptance), at 96 concurrent requests on Rubin with the 96 settings of the speed table and this branch at e6bbe20; both arms on the same node pair, the baseline with the speed table's baseline settings at 96. Comparison rule: an exact two-sided McNemar test on per-question correctness; p < 0.05 is a difference.

Model / hardware / configuration Test Native SGLang baseline Mega candidate Difference / variation Verdict and evidence
Muse Spark NVFP4 + DFlash2 / 4 Rubin (sm_107) / TP4 = EP4, 96 concurrent requests GSM8K, 1,319 questions; answer = last \boxed{}, else last number 0.9545 (1,259 / 1,319) 0.9204 (1,214 / 1,319) -3.41 pt; per question 65 baseline-only against 20 candidate-only correct, exact McNemar p < 0.0001 Lower

Most of the difference is answers that reach the 4,096-token limit while repeating themselves (45 in the candidate, 14 in the baseline). The candidate's NVFP4 KV cache accounts for most of it: the same settings on an FP8 KV cache (--kv-cache-dtype fp8_e4m3, main's NVFP4 KV components off) read 0.9447 against the baseline's 0.9545 at 96 (-0.99 pt, p = 0.14) and 0.9530 against 0.9500 at 80 (+0.30 pt, p = 0.71), at a cost in speed: per-user output speed about 12 % lower at 80 and 22 % lower at 96 than the NVFP4 runs of the speed table (other node pairs).

Speed Tests and Profiling

Measured on Rubin (sm_107): each server on one node of 4 GPUs, TP4 = EP4, with the benchmark client on a second node; Muse-Spark-Open-816B-A42B-NVFP4 with the DFlash2 draft; SGLang 306ccf6f57bcd6efc9edc626e39a9673e22cb9d6 with sgl-project/sglang#48950, #48947, #48948 and #48949 ported onto it; this pull request's tree at 859fee2 (for that SGLang build the components' pinned SGLang file digests were extended by the build's own, nothing else changed). Workload: an agentic multi-turn benchmark (coding-agent conversations; prompts of 73k-90k tokens at the median and 247k-301k at p90). For each arm and concurrency, on the same node pair: a warm-up server that runs the workload for 10 minutes, then a fresh server and a 1-hour run; synthetic draft acceptance (accept length 4.05) in both arms. Baseline: SGLang without the plugin, at its best stock settings for each concurrency. Candidate: this pull request with each concurrency's settings. Relative change, candidate over baseline (in brackets: the 10-minute warm-up runs):

Concurrency p90 per-user output speed Total token throughput per GPU (prompt + generated) 1 / p90 end-to-end latency per output token
80 ×2.97 (×2.20) ×1.74 (×1.45) ×6.89 (×4.24)
96 ×2.92 (×1.86) ×1.96 (×1.63) ×12.27 (×7.34)
112 ×2.26 (×1.52) ×2.14 (×2.12) ×14.16 (×6.83)

Absolute values of the 1-hour runs, baseline → candidate:

Concurrency p90 per-user output speed (tok/s) p90 inter-token latency (ms) Total token throughput per GPU, prompt + generated (tok/s) 1 / p90 end-to-end latency per output token (tok/s)
80 38.51 → 114.42 25.97 → 8.74 75,280 → 130,933 12.91 → 88.91
96 33.99 → 99.40 29.42 → 10.06 73,178 → 143,522 6.32 → 77.56
112 34.03 → 76.98 29.39 → 12.99 71,101 → 152,410 4.22 → 59.81

The arms differ in more than the plugin, so these are recipe-to-recipe numbers: besides the components, the candidate runs an NVFP4 KV cache (baseline FP8), prefill-decode interval 3 (baseline 0), HiCache 220 GB per rank (baseline 205), the FlashInfer all-to-all, the fa4 draft attention backend, the context-projection overlap, SWA host ratio 0.2 and SWA full-token ratio 0.06 (baseline 0.1), sequence parallelism from 1,536 tokens, SGLang's DFLASH eager commit (SGLANG_OPT_DFLASH_EAGER_COMMIT=1) and a larger custom all-reduce (SGLANG_CUSTOM_ALL_REDUCE_V2_MAX_SIZE_KB=131072); the baseline runs SGLang's MegaMoE layer-norm SP path (--enable-megamoe-for-layernorm-sp, sgl-deep-gemm 0.2.3). Both arms run the Rust radix-tree core; at 80 and 96 they capture the same decode CUDA-graph sizes, and at 112 the baseline uses SGLang's default sizes.

Every component the candidate's settings switch on engaged, as in the plugin's own records of these settings (checked at boot and after each 1-hour run). At 80 the baseline ran about 7 % slower per user than our earlier stock measurement at that concurrency on other nodes (at 96 it matched it, at 112 it ran 5 % faster); against that earlier baseline the 80 row reads ×2.77 / ×1.68 / ×6.17. At 80 and 112 the candidate is within 1.1 % of earlier measurements of the same settings on all three metrics; at 96 it ran 4.5 % lower on per-user speed, 1.4 % on throughput and 5.6 % on latency, where an earlier run of the same engaged components on other nodes was 1.9 % lower on per-user speed. Being faster, the candidate gets further into the conversations within the hour, so its prompts run longer (median 84k-90k tokens against the baseline's 73k-77k).

Speed check of the abort-flag fix. The 96 settings at e6bbe20, one 1-hour run on another node pair, against the same settings at 859fee2 in the table above: per-user output speed +1.8 %, total token throughput per GPU +0.6 %, 1 / p90 end-to-end latency per output token +1.6 %, with every component engaged as recorded (run-to-run spread across node pairs is a few percent), so the fix costs nothing measurable.

Checklist

  • pre-commit run --all-files passes (isort, ruff, ruff-format, codespell).
  • Tests under test/ cover the change. [No new tests; the existing contract test covers the new modules' SGLang reads.]
  • The SGLang commit or PR this was tested against is named above.
  • Accuracy and speed results are attached.
  • A new model adds one line to .github/CODEOWNERS that names its owner (**/*muse_spark* @wenscarl @nvrohanv, on main since [Feat] [NVIDIA] muse_spark: Serve the Muse Spark Open kernels on GB300 (sm_103) #42).

Review and Merge Process

  1. The lint and Check PR title checks must pass.
  2. Ask a code owner from .github/CODEOWNERS to review.
  3. Merge with "Squash and merge": the PR title becomes the commit title on main.

🤖 Generated with Claude Code

@YAMY1234 YAMY1234 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rohith for splitting verify_mk out (now #76). Three things from my side:

  1. Debug code. #42 removed the *_SHADOW checks (ar_attn_boundary, ctx_proj_overlap, nvfp4_kv_verify, spec_sample_split, verify_topk_sample) and xattn_b's dump mode on purpose, and this PR brings them back. Could you drop them and keep main's versions of these six files?

  2. prefill_moe_x / moe_x_kernels (~9.5k lines). They only turn on when MUSE_VR_MOE_X_MMA_HELPERS names an MMA helper module that isn't in this repo, and #42 notes they can't run on sm_103 (they issue K=128 block-scaled MMAs with operand collectors). So nobody using this repo can turn them on. Could you leave them out of this PR, as #42 did, and bring them back once the helper module can ship here?

  3. Tests. Not a blocker for this PR. Once it lands, an SGLang integration test for muse_spark would be a good follow-up.

…hecks, no xattn_b dump mode)

Review: sgl-project#42 removed the debug shadow checks (MUSE_VR_<NAME>_SHADOW in ar_attn_boundary, ctx_proj_overlap,
nvfp4_kv_verify, spec_sample_split and verify_topk_sample) and xattn_b's dump mode (MUSE_VR_XATTN_B_MODE=dump) on
purpose; this pull request had brought them back. The six files are main's again. Both were debug only and off by
default, so the served paths do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rohithrr9

Copy link
Copy Markdown

Thanks for the review.

  1. Done in 890d0b6: the six files are main's again, without the shadow checks and the dump mode.
  2. I'd like to keep prefill_moe_x. It can be turned on from this repo with the stock SGLang image: the helper module is cutlass.utils.rubin_helpers, which the image's nvidia-cutlass-dsl 4.8.0 already ships, so MUSE_VR_PREFILL_MOE_X=1 MUSE_VR_MOE_X_MMA_HELPERS=cutlass.utils.rubin_helpers turns it on (Rubin only, as [Feat] [NVIDIA] muse_spark: Serve the Muse Spark Open kernels on GB300 (sm_103) #42 notes). It also pays for its size: switched on against off on the same nodes, it raises p90 per-user output speed by 11 to 15.5 % and lowers p90 time to first token by 17 to 26 % at 80, 96 and 112 concurrent requests (table below), because faster prefill chunks hold decoding up less. The description now names the setting. If you'd still rather have it out, I'll take it out.
  3. Agreed, an SGLang integration test for muse_spark will follow once this lands.

prefill_moe_x off → on, same nodes and settings otherwise, 1-hour runs of the agentic benchmark from the description:

Concurrency p90 per-user output speed (tok/s) Total token throughput per GPU, prompt + generated (tok/s) 1 / p90 end-to-end latency per output token (tok/s) p90 time to first token (s)
80 100.30 → 111.36 (+11.0 %) 126,135 → 129,214 (+2.4 %) 77.28 → 87.82 (+13.6 %) 0.917 → 0.678 (−26.1 %)
96 89.37 → 102.04 (+14.2 %) 139,997 → 144,859 (+3.5 %) 69.32 → 80.25 (+15.8 %) 1.050 → 0.873 (−16.9 %)
112 67.25 → 77.70 (+15.5 %) 148,926 → 154,073 (+3.5 %) 52.23 → 61.18 (+17.1 %) 1.580 → 1.212 (−23.3 %)

The description now also gives the absolute speed numbers, baseline → this pull request (the same 1-hour runs as the relative table):

Concurrency p90 per-user output speed (tok/s) p90 inter-token latency (ms) Total token throughput per GPU, prompt + generated (tok/s) 1 / p90 end-to-end latency per output token (tok/s)
80 38.51 → 114.42 25.97 → 8.74 75,280 → 130,933 12.91 → 88.91
96 33.99 → 99.40 29.42 → 10.06 73,178 → 143,522 6.32 → 77.56
112 34.03 → 76.98 29.39 → 12.99 71,101 → 152,410 4.22 → 59.81

rohithrr9 added a commit to rohithrr9/sgl-nvidia-mega that referenced this pull request Nov 23, 2026
…d the one-request components

Stacked on sgl-project#39: it extends sgl-project#39's draft_attn, verify_logits_gather and softmax_split and uses its registry. Everything is
opt-in and off by default; the one-request pieces refuse, or step aside on, every other batch.

- verify_mk (MUSE_VR_VERIFY_MK=1): TensorRT-LLM's Muse Spark decode megakernel (target layers 1-60 as one persistent
  kernel) on SGLang's one-request target-verify step at TP8 = EP8. muse_spark/sm107/verify_mk is the host runner: it
  hooks SGLang's install_megakernel, binds the kernel to SGLang's KV cache, TP group and weights (layer facades,
  workspaces), refuses the forwards it does not cover (they run stock) and has a compare mode that checks forwards layer
  by layer against the stock layers. The kernel also writes the DFlash taps of layers 1-60, and when every capture is a
  kernel tap the text model returns the taps' buffer itself (their concatenation), so no tap copies run.
  muse_spark/sm107/trtllm_ab93b78 is TensorRT-LLM's kernel and host code at ab93b785a476f01d2f1e1907c930780fc6d7832e,
  unchanged apart from four files marked "Modified by NVIDIA" (SGLang's paged KV cache as a build option, SM-stable CTA
  roles as a build option); sm107/README.md lists what is copied.
- The plugin's one-request components, ported from its one-request TP8 line: new host_ingest, req_bcast,
  token_count_fill, embed_gather, step_graphs, eager_commit, selector_fused, selector_proj_overlap, rust_treecore and
  graph_meta_par, with the kernels batch_copy, dflash_commit, draft_gemv_push, pull_gather_rows, selector_fused,
  sparse_final, verify_topk_fast and final_norm_split; the plugin's later versions 3-way merged into ar_norm_residual,
  ctx_proj_overlap, draft_attn, draft_boundary, final_norm, pull_bounded, verify_attn, verify_topk_sample and the ops
  draft_ar_norm, draft_attn, draft_gemv, draft_qk, full_verify_attn and swa_verify_attn (new paths behind new switches;
  the existing defaults are unchanged).
- One-request step optimizations, each behind its own switch: multimem logits gather with a fused argmax
  (verify_logits_gather), the split softmax captured in the step graphs, the step graphs' simulated-acceptance fold,
  Triton accept and late launch, the layer-0 input-norm table (and its stream), the drafter's layer-0 table, token-count
  reuse, parallel graph metadata and the final-norm split.
- components/__init__.py registers them in the plugin's order; the loader takes verify_mk from muse_spark/sm107 (and on
  GB300 from muse_spark/sm103, which a separate pull request adds with the same loader lines); sgl_compat maps SGLang's
  megakernel runtime module; NOTICE, the pyproject package data and the pre-commit exclusion cover the copied tree.
- test/unit/test_muse_spark_sm107_verify_mk.py: install, refusals, binding, launches, the taps and the packed capture,
  the compare mode and the loader on CPU stand-ins; test_muse_spark_sm107_verify_mk_i2b.py: the SM-stable claim
  protocol.

Co-authored-by: Rohan Varma <rohanv@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants