Repository navigation
feat(capture): run server-side spec capture as an SGLang plugin - #945
Merged
Merged
Conversation
Add `plugins/sglang-spec-capture` (`specforge-sglang-capture`), an SGLang plugin that performs the spec-capture patch's work on SGLang builds with the generic forward-observer, deferred-output and --aux-hidden-state-capture extension points, so capture servers no longer need a patched SGLang: - the forward observer selects capture requests' prefill rows (aux concatenation and post-norm last hidden, with the muP restoration); - the auxiliary output copies them with the generation result, hands each finished request to the background Mooncake sink (ported from the patch, including the Ascend mount) and holds its response; - the deferred-output source releases requests in order once their objects are durable, and a streamer subclass returns the result in `meta_info["spec_capture"]`; - the scheduler refuses to start without --aux-hidden-state-capture, --return-hidden-states-mode full and --chunked-prefill-size -1. `deployment.disaggregated.server_capture: plugin` selects it (default `patch`, unchanged): the adapter sends each spec as JSON in `sampling_params.custom_params`, managed-local servers are launched with the plugin flags and SPECFORGE_SPEC_CAPTURE=1, and preflight checks the plugin and SGLang hooks instead of the patch. External producers can also set DISAGG_SERVER_CAPTURE=plugin. The live server-capture gate runs against whichever backend is installed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port the NvlinkArena from the v0.5.18 capture patch (#938 at 9ad9ff8) into the plugin's sink. With MOONCAKE_PROTOCOL=nvlink the sink copies each batch into one fabric-memory arena that the Mooncake TransferEngine allocates on the writer GPU, sized by the required SGLANG_SPEC_CAPTURE_NVLINK_ARENA_BYTES. Results gain "nvlink": {"session", "control"} and a per-feature "address". Clients free objects by writing JSON key lists to the control TCP connection, which the writer thread drains before it allocates. NVLink always selects device publication, and SGLANG_SPEC_CAPTURE_GPU_PUT=0 is rejected. The scheduler now checks the arena size at startup, like the plugin's flag checks, instead of failing every capture batch. The tcp and rdma paths are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
maocheng23
requested review from
FlamingoPg,
FrankLeeeee,
shuaills and
sleepcoo
as code owners
October 10, 2026 00:23
This was referenced Oct 10, 2026
sgl-project/sglang#43449 renamed the server argument. The plugin, the launcher, the schema's reserved-flag list, the docs and the tests follow. SpecForge's own model.aux_hidden_state_layer_ids config field is unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
sgl-project/sglang#43449 replaced --aux-hidden-state-capture <method> with a bool flag; --speculative-algorithm now names the capture convention and SGLang resets it, so no draft runs. The launcher renders the new pair, both flags are launcher-owned, and the plugin's messages, docs and tests follow. The plugin still reads the resolved method from the non-CLI aux_hidden_state_capture field. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Collaborator
|
Perhaps we should nudge the sglang team to handle these PRs? @maocheng23 |
…pture-plugin-nvlink
…in-nvlink feat(capture): NVLink publication in the SGLang capture plugin's sink
jiapingW
self-requested a review
October 18, 2026 11:04
3 tasks done
This was referenced Oct 20, 2026
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
Online disaggregated training needs SGLang capture servers that write prefill hidden states straight into Mooncake. Today that requires a patched SGLang:
sgl-project/sglang#43448, sgl-project/sglang#43449 and sgl-project/sglang#43450 add generic, off-by-default extension points to SGLang. This PR runs the same capture as an SGLang plugin on top of them, so capture servers no longer need a patched SGLang.
Modifications
plugins/sglang-spec-capture. A new, separately installed distribution,specforge-sglang-capture. Install it into the server environment withpip install --no-deps. Entry pointsglang.srt.plugins: specforge_spec_capture; it is inert unlessSPECFORGE_SPEC_CAPTURE=1.CaptureObserverModelRunner.forward_observerlogits_mup_width_multiplierrestoration. Copies rows out of CUDA-graph outputs and rejects cached prefixes, partial prefills and subset outputs.CaptureDeviceOutput/CaptureHostOutputDeviceAuxiliaryOutput/HostAuxiliaryOutputReq.defer_output).PendingCapturesDeferredOutputSourceSGLANG_SPEC_CAPTURE_MAX_PENDING_BATCHES.Scheduler.get_output_streamer_class+build_additional_customized_infometa_info["spec_capture"].sink.pylocation="cpu"mount.install()Scheduler.__init__--aux-hidden-state-capture,--return-hidden-states-mode fullor--chunked-prefill-size -1, or on an SGLang without the extension points. Errors raised inregister()are only logged by SGLang, so validation lives here.SpecForge wiring.
deployment.disaggregated.server_capture: patch | plugin. The default ispatch, so existing recipes are unchanged. External producers can also setDISAGG_SERVER_CAPTURE=plugin.sampling_params.custom_params["spec_capture"], becausecustom_paramsvalues must be JSON scalars. The adapter already unwrapped list-shaped results.--speculative-algorithm <METHOD> --enable-return-aux-hidden-states --return-aux-hidden-state-layer-ids … --return-hidden-states-mode fullplusSPECFORGE_SPEC_CAPTURE=1. Preflight checks the plugin and SGLang hook modules instead of the patch. The new flags and env are launcher-owned, so passthrough args cannot repeat them.test_server_capture_gate.pyruns against whichever backend is installed (SPECFORGE_SERVER_CAPTURE=patch|pluginto force one).Related Issues
spec-capture/integrationon maocheng23/sglang (all three combined on current main).Accuracy Test
GPU. One GB300 (CUDA 13), image
lmsysorg/sglang:nightly-dev-cu13-20261006-f3fe7534with SGLang main8c273d6813+ sgl-project/sglang#43448, sgl-project/sglang#43449 and sgl-project/sglang#43450 (maocheng23/sglangspec-capture/integration) overlaid; realmooncake_master, TCP.SPECFORGE_RUN_SERVER_CAPTURE_TESTS=1 SPECFORGE_SERVER_CAPTURE=plugin, tiny Llama target): 3/3 pass.lm_headof the captured last hidden state reproduces HF's logits; one EAGLE3 train step on the server-captured features gives a finite loss.MooncakeFeatureStore:input_idspass through for prompt lengths 7 to 4096;return_hidden_statesoutput exactly (max abs diff 0.0);lm_headof the captured last hidden state picks the served greedy token.return_hidden_statesexactly andlm_headpicks the served token. 16/flush_cachecalls during 64 concurrent captures gave no errors, and the same prompt captured bit-identically afterwards.CPU (macOS, torch CPU):
test_sglang_capture_plugin.py: 26 unit tests with SGLang fakes.test_sglang_capture_plugin_integration.py: drives the plugin through SGLang's real generation-result copy,consume, deferred release, output streamer and tokenizermeta_infoaccumulation into this adapter's result parsing. The objects written to the Mooncake stand-in match the captured rows byte for byte. It is skipped on SGLang builds without the extension points.tests/test_config,tests/test_runtime,tests/test_scriptsandtests/test_application: 929 passed, with no new failures compared withmainon the same machine. The remaining failures are local SGLang-version mismatches thatmainalso has.Benchmark & Profiling
batch_put_fromtakes about 88 ms of that. It runs on the sink thread, not the scheduler.bench_servingA/B in [Feat] scheduler: Add forward observer and deferred responses for plugins sglang#43450.Checklist
🤖 Generated with Claude Code