Skip to content

[Fix] qwen3_5: Define speculative_runtime_hooks on every built megakernel - #43

Merged
YAMY1234 merged 1 commit into
sgl-project:mainfrom
YAMY1234:fix/prefill-speculative-runtime-hooks
Nov 9, 2026
Merged

YAMY1234 merged 1 commit into
sgl-project:mainfrom
YAMY1234:fix/prefill-speculative-runtime-hooks

Conversation

@YAMY1234

@YAMY1234 YAMY1234 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Motivation

With SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION=1, SGLang's bind_speculative_runtime_hooks (sgl-project/sglang#47201) reads built.speculative_runtime_hooks from the built megakernel. BuiltMegakernel in sglang/kernels/plugin_kernels/nvidia/spec.py requires every built object to define this member, set to None when it has no factory.

Qwen35Prefill does not define it. A PD prefill worker with MTP, --enable-nvidia-megakernel and the runtime switch therefore fails at scheduler init:

File ".../kernel_plugins/nvidia/binding.py", line 1297, in bind_speculative_runtime_hooks
    factory = None if built is None else built.speculative_runtime_hooks
AttributeError: 'Qwen35Prefill' object has no attribute 'speculative_runtime_hooks'

The DeepSeek-V4.1 draft (DraftProposal, DraftDecode) and BuiltMuseSpark are missing the member too.

Modifications

  • Add speculative_runtime_hooks = None to Qwen35Prefill, deepseek_v41 DraftProposal (and so DraftDecode), and BuiltMuseSpark.
  • test/unit/test_qwen3_5_runtime.py: binds a Qwen35Prefill under the runtime switch and checks that the stock hooks come back. Without the fix it fails with the error above.
  • test/unit/test_contract.py: a static check that every built class in the package (each class with plan, forward and summary) assigns speculative_runtime_hooks, so future builders are covered.

Accuracy Tests

No kernel or forward code changes: the member is None, so the binding keeps SGLang's default speculative hooks.

Tested against SGLang 858073e4 (includes #47201):

  • Unit tests: the new runtime test and the contract test fail without the fix (5 failures) and pass with it. test_qwen3_5_runtime.py, test_contract.py and test_plugin.py pass.
  • Serving: Qwen3.5-397B-A17B NVFP4 on GB300, PD with 3 prefill workers at TP1/PP4 and 1 decode worker at DEP8 with MTP (NEXTN), megakernel and the runtime switch on for both roles. Without the fix, every prefill worker exits at scheduler init with the error above. With the fix, the server starts and serves 5,382 agentic requests over 5 minutes at concurrency 704 with 0 errors, and the measured accept length matches the configured synthetic value.

Speed Tests and Profiling

Not applicable: no change to kernel or forward code.

Checklist

  • pre-commit run --all-files passes.
  • Tests under test/ cover the change.
  • The SGLang commit or PR this was tested against is named above.
  • Accuracy and speed results are attached when kernel or forward code changes.
  • A new model adds one line to .github/CODEOWNERS that names its owner. (No new model.)

🤖 Generated with Claude Code

SGLang's BuiltMegakernel requires every built object to define
speculative_runtime_hooks (None without a factory), and
bind_speculative_runtime_hooks reads it unguarded once
SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION is on (sgl-project/sglang#47201).
Qwen35Prefill did not define it, so a PD prefill worker (TP1/PP4) with MTP,
--enable-nvidia-megakernel and the runtime switch failed at scheduler init
with AttributeError. The DeepSeek-V4.1 draft and Muse Spark built objects
missed it too.

Add the member to the three classes, a CPU test that binds the prefill
object under the switch, and a static contract test over every built class.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@YAMY1234
YAMY1234 requested a review from Oasis-Git as a code owner November 9, 2026 07:55
@YAMY1234
YAMY1234 merged commit 750004e into sgl-project:main Nov 9, 2026
3 checks passed
@YAMY1234 YAMY1234 mentioned this pull request Nov 9, 2026
4 of 5 tasks
wenscarl added a commit to wenscarl/sgl-nvidia-mega that referenced this pull request Nov 9, 2026
Both sides added sgl_nvidia_mega/muse_spark (main via sgl-project#42/sgl-project#43, this branch with
the newer kernel half). Resolved the 12 add/add conflicts by keeping this
branch's newer components and re-applying main's GB300 (sm_103) changes: the
ISAS/GSM8K tolerance in spec.py, draft_gemv.fits() and its check in
draft_boundary, and BuiltMuseSpark.speculative_runtime_hooks = None.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
wenscarl added a commit to nvrohanv/sgl-nvidia-mega that referenced this pull request Nov 10, 2026
Resolve the conflicts with main (Muse Spark, Kimi K3 and the optional-reads
contract):

- CODEOWNERS, plugin.py: keep both the GLM-5.3 and the Muse Spark entries.
- README: keep both the GLM-5.3 and the Kimi K3 rows, notes and sections.
- test_contract.py: combine main's SGLANG_OPTIONAL_READS with the GLM-5.3
  DSA-view / draft-check skips (the per-pattern list is renamed to skipped so
  it no longer shadows optional), and subtract both main's preparation set
  and the binding file's public functions from the untolerated names.

Follow main's API changes in glm5_3:

- Define speculative_runtime_hooks = None on the four built objects
  (GlmMegakernelVerify, FusedDraft, NoDraftStep, ComposedBuiltDraft), as the
  contract test added in sgl-project#43 requires.
- Read ForwardMode.is_target_verify from forward_mode.py (where SGLang now
  defines it), falling back to forward_batch_info.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant