Repository navigation
feat(sglang): relay node-local KV events from headless sidecars #14908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
09d47e5
feat(sglang): relay node-local KV events from headless sidecars
jain-ria 7dd5ea7
refactor(sglang): launch sidecars directly from their context mode
jain-ria 9e46ddb
refactor(sglang): configure telemetry-only sidecars over gRPC
jain-ria 0d41b47
refactor(sglang): reuse shared sidecar arguments
jain-ria 35dcc9e
docs(sglang): shorten multinode KV sidecar guidance
jain-ria d2061af
fix(sglang): bind local KV publishers and ready follower sidecars
jain-ria 4d35ab4
fix(sglang): mark multinode KV router launcher executable
jain-ria 12ed73f
fix(sglang): restrict local KV events and stabilize group discovery
jain-ria 50cb6a1
fix(sglang): gate frontend readiness on connected KV relays
jain-ria 8866697
fix(sglang): address multinode launcher review feedback
jain-ria d088cda
revert(sglang): remove KV relay readiness expansion
jain-ria abcc065
Update lib/sidecar/sglang/src/lib.rs
jain-ria 9ab5001
fix(sglang): infer sidecar mode from engine metadata
jain-ria e470729
docs(sglang): add multinode disaggregated sidecar launcher
jain-ria 24579af
test(sglang): assert advertised KV source identity
jain-ria e8d6858
fix(sglang): merge main and resolve sidecar review blockers
jain-ria 551cbf2
fix(sglang): reuse startup deadline for leader discovery
jain-ria a9d386e
fix(sglang): bound rendezvous DNS without blocking startup cancellation
jain-ria 4da4ccb
Merge branch 'main' into codex/sglang-headless-sidecars
jain-ria File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
36 changes: 36 additions & 0 deletions
36
lib/sidecar/sglang/launch/multinode_disagg_kv_router_sidecar.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/bin/bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # One node of a multinode prefill or decode group with NIXL transfer and KV routing. | ||
| # Defaults: two nodes per role, one GPU per node, Qwen/Qwen3-32B. | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
|
|
||
| if [[ "${1:-}" == --help || "${1:-}" == -h ]]; then | ||
| echo "Usage: NODE_RANK=<rank> DIST_INIT_ADDR=<role-leader:port> bash $0 <prefill|decode> [SGLang options...]" | ||
| echo "Run once per node, with separate rendezvous addresses for prefill and decode." | ||
| echo "All nodes and the frontend must share Dynamo namespace, discovery and event services." | ||
| echo | ||
| echo "Example: run each command on its respective node (four nodes total):" | ||
| echo " NODE_RANK=0 DIST_INIT_ADDR=prefill-leader:29500 SGLANG_BOOTSTRAP_HOST=prefill-leader bash $0 prefill" | ||
| echo " NODE_RANK=1 DIST_INIT_ADDR=prefill-leader:29500 bash $0 prefill" | ||
| echo " NODE_RANK=0 DIST_INIT_ADDR=decode-leader:29500 bash $0 decode" | ||
| echo " NODE_RANK=1 DIST_INIT_ADDR=decode-leader:29500 bash $0 decode" | ||
| echo | ||
| echo "Start the frontend separately: python3 -m dynamo.frontend --router-mode kv" | ||
| echo "Use reachable leader addresses; NIXL requires connectivity between the two groups." | ||
| echo "For model, topology and port overrides: bash $SCRIPT_DIR/multinode_kv_router_sidecar.sh --help" | ||
| exit 0 | ||
| fi | ||
|
|
||
| case "${1:-}" in | ||
| prefill|decode) export ROLE="$1"; shift ;; | ||
| *) echo "First argument must be prefill or decode; use --help for examples" >&2; exit 1 ;; | ||
| esac | ||
|
|
||
| # Reuse per-node engine/sidecar startup, validation, GPU budgeting and cleanup. | ||
| # ROLE enables NIXL; node 0 serves requests and followers relay local KV events. | ||
| exec bash "$SCRIPT_DIR/multinode_kv_router_sidecar.sh" "$@" |
114 changes: 114 additions & 0 deletions
114
lib/sidecar/sglang/launch/multinode_kv_router_sidecar.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/bin/bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # One node of an externally managed SGLang attention-DP group with local KV events. | ||
| # Requires node-local KV source discovery and this Dynamo sidecar on every node. | ||
| # Start the frontend separately. | ||
| # Defaults: two nodes, one GPU per node, global TP=2 / attention DP=2. | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
| export DYNAMO_HOME="${DYNAMO_HOME:-$(readlink -f "$SCRIPT_DIR/../../../..")}" | ||
| # shellcheck disable=SC1091 # Resolved relative to this script at runtime. | ||
| source "$DYNAMO_HOME/examples/common/gpu_utils.sh" | ||
| # shellcheck disable=SC1091 # Resolved relative to this script at runtime. | ||
| source "$DYNAMO_HOME/examples/common/launch_utils.sh" | ||
|
|
||
| if [[ "${1:-}" == --help || "${1:-}" == -h ]]; then | ||
| echo "Usage: NODE_RANK=<rank> DIST_INIT_ADDR=<leader-ip:port> bash $0 [SGLang options...]" | ||
| echo "Run once per node; use the same Dynamo namespace, discovery and event services." | ||
| echo "Required: NODE_RANK, DIST_INIT_ADDR" | ||
| echo "Topology: NNODES=2, TP_SIZE=NNODES, DP_SIZE=NNODES (global sizes; PP=1)" | ||
| echo " DP_SIZE must be divisible by NNODES so every node owns publishers." | ||
| echo "Model: MODEL=Qwen/Qwen3-32B, MAX_MODEL_LEN=4096, MAX_CONCURRENT_SEQS=32" | ||
| echo "Role: ROLE=aggregated|prefill|decode (default: aggregated)" | ||
| echo "PD: SGLANG_BOOTSTRAP_HOST=<reachable prefill leader IP> on prefill node 0" | ||
| echo "Ports: SGLANG_HTTP_PORT=30000, SGLANG_GRPC_PORT=30001, SGLANG_KV_EVENT_PORT=5557" | ||
| echo " SGLANG_DISAGGREGATION_BOOTSTRAP_PORT=8998, DYN_SYSTEM_PORT=8081" | ||
| echo " DYN_HTTP_PORT=8000 is the separately launched frontend's port." | ||
| echo "Other: SGLANG_PYTHON=python3, SGLANG_HOST=0.0.0.0, SGLANG_PAGE_SIZE=64" | ||
| echo " CUDA_VISIBLE_DEVICES is inherited. Extra arguments go to SGLang only." | ||
| exit 0 | ||
| fi | ||
|
|
||
| : "${NODE_RANK:?Set NODE_RANK to the local node rank within the engine group}" | ||
| : "${DIST_INIT_ADDR:?Set DIST_INIT_ADDR to the reachable engine leader host:port}" | ||
| NNODES="${NNODES:-2}" | ||
| TP_SIZE="${TP_SIZE:-$NNODES}" | ||
| DP_SIZE="${DP_SIZE:-$NNODES}" | ||
| for size in "$NNODES" "$TP_SIZE" "$DP_SIZE"; do | ||
| if [[ ! "$size" =~ ^[1-9][0-9]*$ ]]; then | ||
| echo "NNODES, TP_SIZE and DP_SIZE must be positive integers" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
| if [[ ! "$NODE_RANK" =~ ^(0|[1-9][0-9]*)$ ]] || (( NODE_RANK >= NNODES )); then | ||
| echo "NODE_RANK must be in [0, NNODES)" >&2 | ||
| exit 1 | ||
| fi | ||
| if (( NNODES < 2 || TP_SIZE % DP_SIZE != 0 || DP_SIZE % NNODES != 0 )); then | ||
| echo "This example requires NNODES >= 2, TP_SIZE divisible by DP_SIZE, and DP_SIZE divisible by NNODES" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| MODEL="${MODEL:-Qwen/Qwen3-32B}" | ||
| ROLE="${ROLE:-aggregated}" | ||
|
jain-ria marked this conversation as resolved.
Resolved
|
||
| SGLANG_PYTHON="${SGLANG_PYTHON:-python3}" | ||
| SGLANG_HOST="${SGLANG_HOST:-0.0.0.0}" | ||
| SGLANG_HTTP_PORT="${SGLANG_HTTP_PORT:-30000}" | ||
| SGLANG_GRPC_PORT="${SGLANG_GRPC_PORT:-30001}" | ||
| SGLANG_KV_EVENT_PORT="${SGLANG_KV_EVENT_PORT:-5557}" | ||
| SGLANG_PAGE_SIZE="${SGLANG_PAGE_SIZE:-64}" | ||
| MAX_MODEL_LEN="${MAX_MODEL_LEN:-4096}" | ||
| MAX_CONCURRENT_SEQS="${MAX_CONCURRENT_SEQS:-32}" | ||
| HTTP_PORT="${DYN_HTTP_PORT:-8000}" | ||
| GPU_MEM_ARGS=$(build_sglang_gpu_mem_args) | ||
| ENGINE_ROLE_ARGS=() | ||
| SIDECAR_ARGS=() | ||
| case "$SGLANG_HOST" in | ||
| 0.0.0.0) SIDECAR_HOST=127.0.0.1 ;; | ||
| ::) SIDECAR_HOST='[::1]' ;; | ||
| *:*) SIDECAR_HOST="[$SGLANG_HOST]" ;; | ||
| *) SIDECAR_HOST="$SGLANG_HOST" ;; | ||
| esac | ||
|
|
||
| case "$ROLE" in | ||
| aggregated) ;; | ||
| prefill|decode) | ||
| ENGINE_ROLE_ARGS=(--disaggregation-mode "$ROLE" --disaggregation-transfer-backend nixl | ||
| --disaggregation-bootstrap-port "${SGLANG_DISAGGREGATION_BOOTSTRAP_PORT:-8998}") | ||
| if [[ "$ROLE" == prefill && "$NODE_RANK" == 0 ]]; then | ||
| : "${SGLANG_BOOTSTRAP_HOST:?Set SGLANG_BOOTSTRAP_HOST to the reachable prefill leader address}" | ||
| SIDECAR_ARGS+=(--bootstrap-host "$SGLANG_BOOTSTRAP_HOST") | ||
| fi | ||
| ;; | ||
| *) echo "ROLE must be aggregated, prefill or decode" >&2; exit 1 ;; | ||
| esac | ||
| print_launch_banner --no-curl "SGLang multinode KV sidecar ($ROLE, node $NODE_RANK)" "$MODEL" "$HTTP_PORT" \ | ||
| "Topology: NNODES=$NNODES, TP_SIZE=$TP_SIZE, DP_SIZE=$DP_SIZE (attention DP)" \ | ||
| "Rendezvous: $DIST_INIT_ADDR; local gRPC: $SGLANG_GRPC_PORT" \ | ||
| "Start the frontend separately. Restart all nodes and sidecars together after failure." | ||
|
|
||
| trap dynamo_exit_trap EXIT | ||
|
|
||
| # Sidecars retry gRPC startup; no sleep or inference health check is needed on followers. | ||
| # Bind KV events only on loopback; engine and sidecar share a network namespace. | ||
| # shellcheck disable=SC2086 # GPU_MEM_ARGS intentionally expands into multiple flags. | ||
| "$SGLANG_PYTHON" -m sglang.launch_server \ | ||
| --model-path "$MODEL" \ | ||
| --host "$SGLANG_HOST" --port "$SGLANG_HTTP_PORT" --grpc-port "$SGLANG_GRPC_PORT" \ | ||
| --incremental-streaming-output \ | ||
| --nnodes "$NNODES" --node-rank "$NODE_RANK" --dist-init-addr "$DIST_INIT_ADDR" \ | ||
| --tp-size "$TP_SIZE" --dp-size "$DP_SIZE" --enable-dp-attention \ | ||
| --kv-events-config "{\"publisher\":\"zmq\",\"endpoint\":\"tcp://127.0.0.1:${SGLANG_KV_EVENT_PORT}\",\"bind\":true,\"topic\":\"\"}" \ | ||
| --page-size "$SGLANG_PAGE_SIZE" --context-length "$MAX_MODEL_LEN" \ | ||
| --max-running-requests "$MAX_CONCURRENT_SEQS" \ | ||
| "${ENGINE_ROLE_ARGS[@]}" $GPU_MEM_ARGS "$@" & | ||
|
|
||
| DYN_SYSTEM_PORT="${DYN_SYSTEM_PORT:-8081}" \ | ||
| python3 -m dynamo.sglang.sidecar \ | ||
| --grpc-endpoint "http://$SIDECAR_HOST:$SGLANG_GRPC_PORT" "${SIDECAR_ARGS[@]}" & | ||
|
|
||
| wait_any_exit | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.