feat(zmq): teach the direct-backend path to speak TokenSpeed - #2036
Merged
Conversation
Make the ZMQ direct-backend stack engine-neutral and add TokenSpeed as the second wire protocol, speaking its msgpack-native tagged msgspec structs directly — a same-host TokenSpeed scheduler is driven over ipc:// with no Python servicer hop. engine-zmq-client: - EngineProtocol trait seams the shared transport/connector (handshake, ROUTER/DEALER identity framing, output loop, abort) away from the per-engine wire structs; the vLLM protocol keeps its behavior. - TokenSpeed protocol speaks the engine's native tagged structs: the tokenized generate request is emitted as the tagged positional prefix through `stream` (nested native SamplingParams, normalized frontend- side), and the per-step output decodes the tagged slim batch struct (token ids, finish reasons, token counts, sampled-token logprob columns). Tag-validated decode, trailing-field tolerance, and pinned cross-language byte vectors from the Python encoder. - Handshake structs move to a neutral protocol/handshake.rs; a neutral EngineLoad replaces engine-specific stats in the shared seam; max_num_batched_tokens widened to i64 (-1 = disabled). Gateway: - ZmqEngineClient selects the protocol from the worker's explicit runtime_type; unsupported runtimes are rejected before the handshake and at registration. BackendClient reports the actual runtime. - n>1 is fanned out frontend-side: n single-sample wire requests with per-sub rids and deterministic seed derivation, streams interleaved with per-choice proto indexes, cumulative usage counted once, drop aborts every sub. - Streams emit a finish-tick's tokens as a chunk before the cumulative Complete, so streaming never drops the last token. Sampled-token logprobs are wired end-to-end on both ZMQ protocols. - No silent narrowing: structured-output constraints, top-k/prompt logprobs, stop strings, logit_bias, and nonzero data_parallel_rank fail loudly with invalid_argument. - Workers honor an optional WorkerSpec.zmq_handshake_address bind override; the FNV port derivation from the ipc path remains the no-config default (doc + conformance vectors pinned against the Python launcher mirror). - detect_backend/discover_metadata preserve an explicitly configured ZMQ runtime; unspecified still defaults to vLLM with a warning. smg serve / config: - `smg serve --backend tokenspeed --connection-mode zmq` launches the engine headless (`python -m tokenspeed.cli serve --headless` with the derived --data-parallel-rpc-port), mirroring the vLLM zmq launcher; dense data parallelism = N independent workers. - `--backend` pins the startup ZMQ worker runtime through both config conversion paths and the Python bindings; per-user ZMQ socket dir (SMG_ZMQ_SOCKET_DIR override). workflow engine: - Fix a spurious "Workflow deadlocked" failure: completions landing between the drain and the tracker read are now re-drained in the deadlock branch, and the run_if paths send their completion inside the tracker lock scope. Regression tests included. Validated live on GB300 against a real TokenSpeed engine (Qwen3-0.6B): chat (content + reasoning_content), completions, streaming, n=2, sampled-token logprobs, loud rejections, engine-side invalid-request aborts, ENGINE_CORE_DEAD death detection, and the handshake-address override with a bare-default engine. Signed-off-by: Simo Lin <25425177+slin1237@users.noreply.github.com>
slin1237
requested review from
CatherineSue,
gongwei-130 and
key4ng
as code owners
August 3, 2026 15:44
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (31)
📝 WalkthroughSummary by CodeRabbit
WalkthroughChangesTokenSpeed ZMQ integration
Workflow completion signaling
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Aug 3, 2026
4 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.
Description
Problem
The ZMQ direct-backend path (#2000, built on #2015) speaks only vLLM's EngineCore protocol. TokenSpeed (and later sglang) engines need the same same-host
ipc://fast path, but the crate's transport, connector, and gateway adapter all hard-assumed the vLLM wire format — and several workflow steps hard-assumed "ZMQ worker ⇒ vLLM".Solution
Make the ZMQ stack engine-neutral and add TokenSpeed as the second protocol:
engine-zmq-client: a newEngineProtocoltrait seams the shared transport/connector (handshake, ROUTER/DEALER identity framing, output loop, abort-on-drop) away from the per-engine wire structs.VllmProtocolkeeps the existing behavior;TokenSpeedProtocoladds the sglang-family msgpack tuples (WireTokenizedGenerateReq5-tuple,WireSamplingParams13-tuple,WireBatchTokenIDOut8-tuple with sampled-token logprob columns). Handshake structs move to a neutralprotocol/handshake.rs(re-exported for compatibility). A neutralEngineLoadreplaces the vLLM-specific stats type in the shared seam.zmq_client.rs):ZmqEngineClientselects the protocol from the worker's explicitruntime_type(tokenspeedvsvllm; anything else is rejected before the handshake and at registration). Streams map both protocols to the existing vLLM-proto pipeline — chunks carry incremental tokens/logprobs, the terminalCompletecarries the cumulative set, and a finish-tick's tokens are emitted as a chunk first so streaming never loses the last token.invalid_argumentinstead of degrading — structured-output constraints,n>1, top-k/prompt logprobs, stop strings (TokenSpeed),logit_bias(TokenSpeed), nonzerodata_parallel_rank. Sampled-token logprobs are wired end-to-end on both ZMQ protocols.detect_backend/discover_metadatano longer force ZMQ workers to vLLM — an explicitly configuredruntime_typesurvives to the built worker (unspecified still defaults to vLLM with a warning).BackendClient::runtime_type()reports the actual ZMQ backend runtime.wfaasfix: the DAG scheduler could fail a workflow with a spurious "Workflow deadlocked" when a step completed between the completion-drain and the tracker read (instant-completing ZMQ detection steps hit this routinely). The deadlock branch now re-drains the completion channel before failing, and therun_ifpaths send their completion inside the tracker lock scope. Regression tests included.smg serve: per-user ZMQ socket dir (SMG_ZMQ_SOCKET_DIRoverride), FNV handshake-port derivation pinned by conformance vectors against the Python mirror.Changes
crates/engine_zmq_client:protocol/mod.rs(EngineProtocol/EngineOutput/EngineBatch/EngineLoad),protocol/tokenspeed/{mod,request,sampling,output}.rs,protocol/handshake.rs, genericconnector.rs/transport.rs,EngineCoreReadyResponse.max_num_batched_tokenswidened toi64(TokenSpeed sends-1= disabled).model_gateway:routers/grpc/zmq_client.rs(ZmqBackend enum, per-protocol translate/map with loud rejection boundary, logprob accumulation),routers/grpc/backend_client.rs(runtime passthrough),worker/worker.rs(runtime param on connect),workflow/steps/local/{detect_backend,discover_metadata,create_worker}.rs(runtime preservation + ZMQ runtime validation).crates/workflow: deadlock-detector re-drain +run_ifin-lock completion send + regression tests.bindings/python/src/smg/serve.py: per-user socket dir.Test Plan
cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo +nightly fmt --all -- --checkclean;engine-zmq-client(incl. mock-engine e2e for both protocols),wfaas, andsmgzmq_client suites green.msgspec-encoded fixtures decode in the Rust codec and vice versa (field order, arity, float64 logprob columns).lightseekorg/tokenspeed#feat/zmq-msgpack) registered viaPOST /workers {"url":"ipc://...","connection_mode":"zmq","runtime_type":"tokenspeed"}— chat (content + reasoning_content), completions, sampled-token logprobs (--enable-output-logprobs), top-k/prompt-logprob rejections, and repeated worker registration with zero workflow-deadlock failures. The existing vLLM ZMQ path re-validated unchanged.Follow-ups: engine-side handshake retry, DP>1 (coordinator/wave, task tracked), legacy
/v1/completionslogprobs rendering (pre-existing gap for all backends).Checklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspasses