Skip to content

R3 Support on PD Disaggregation (mini_lb) - #22916

Merged
yueming-yuan merged 2 commits into
sgl-project:sglang-milesfrom
zyzshishui:sglang-miles-pd-r3
Apr 16, 2026
Merged

yueming-yuan merged 2 commits into
sgl-project:sglang-milesfrom
zyzshishui:sglang-miles-pd-r3

Conversation

@zyzshishui

@zyzshishui zyzshishui commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Support R3 in PD Disaggregation.
Note: only non-streaming generate and /chat/completions endpoints are supported.
Gateway version: radixark/sgl-router-for-miles#4

Modifications

Add maybe_collect_routed_experts on PD prefill side

Accuracy Tests

Launch commands

Deterministic flags shared by all services:

COMMON_FLAGS=(
  --model-path Qwen/Qwen3-30B-A3B
  --host 127.0.0.1
  --trust-remote-code
  --attention-backend fa3
  --tp 2
  --enable-deterministic-inference
  --disable-overlap-schedule
  --disable-cuda-graph
  --disable-radix-cache
  --enable-return-routed-experts
  --mem-fraction-static 0.9
)

Non-PD baseline on GPUs 4,5:

PYTHONPATH=/data/sglang/python CUDA_VISIBLE_DEVICES=4,5 python -m sglang.launch_server \
  "${COMMON_FLAGS[@]}" \
  --port 28380

PD

prefill worker on GPUs 4,5:

PYTHONPATH=/data/sglang/python CUDA_VISIBLE_DEVICES=4,5 python -m sglang.launch_server \
  "${COMMON_FLAGS[@]}" \
  --port 28180 \
  --disaggregation-mode prefill \
  --disaggregation-transfer-backend mooncake \
  --disaggregation-bootstrap-port 28580 \
  --disaggregation-ib-device mlx5_6,mlx5_7

decode worker on GPUs 6,7:

PYTHONPATH=/data/sglang/python CUDA_VISIBLE_DEVICES=6,7 python -m sglang.launch_server \
  "${COMMON_FLAGS[@]}" \
  --port 28280 \
  --disaggregation-mode decode \
  --disaggregation-transfer-backend mooncake \
  --disaggregation-bootstrap-port 28580 \
  --disaggregation-ib-device mlx5_8,mlx5_9

Router with mini_lb.py:

PYTHONPATH=/data/sglang/sgl-model-gateway/bindings/python/src \
python -m sglang_router.launch_router \
  --host 127.0.0.1 \
  --port 28080 \
  --pd-disaggregation \
  --mini-lb \
  --prefill http://127.0.0.1:28180 \
  --decode http://127.0.0.1:28280

Send Request

Generate:

curl -s http://127.0.0.1:28380/generate -H 'Content-Type: application/json' -d '{
  "text": "Hello, my name is guapisolo.",
  "sampling_params": {"temperature": 0, "max_new_tokens": 32},
  "return_routed_experts": true
}' > ./baseline_generate.json

curl -s http://127.0.0.1:28080/generate -H 'Content-Type: application/json' -d '{
  "text": "Hello, my name is guapisolo.",
  "sampling_params": {"temperature": 0, "max_new_tokens": 32},
  "return_routed_experts": true
}' > ./pd_generate.json

Chat completions:

curl -s http://127.0.0.1:28380/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "Qwen/Qwen3-30B-A3B",
  "messages": [{"role": "user", "content": "Hello, my name is guapisolo."}],
  "temperature": 0,
  "max_tokens": 32,
  "stream": false,
  "return_routed_experts": true
}' > ./baseline_chat.json

curl -s http://127.0.0.1:28080/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "Qwen/Qwen3-30B-A3B",
  "messages": [{"role": "user", "content": "Hello, my name is guapisolo."}],
  "temperature": 0,
  "max_tokens": 32,
  "stream": false,
  "return_routed_experts": true
}' > ./pd_chat.json

comparison script

python - <<'PY'
import base64, json, numpy as np

def load(path):
    with open(path) as f:
        return json.load(f)

def extract(obj, kind):
    if kind == "generate":
        text = obj["text"]
        blob = obj["meta_info"]["routed_experts"]
    else:
        text = obj["choices"][0]["message"]["content"]
        blob = obj["sglext"]["routed_experts"]
    arr = np.frombuffer(base64.b64decode(blob), dtype=np.int32)
    return text, arr

for kind, a_path, b_path in [
    ("generate", "./baseline_generate.json", "./pd_generate.json"),
    ("chat", "./baseline_chat.json", "./pd_chat.json"),
]:
    ta, aa = extract(load(a_path), kind)
    tb, bb = extract(load(b_path), kind)
    assert aa.shape == bb.shape, (kind, aa.shape, bb.shape)
    same = aa == bb
    print(kind)
    print("  same_text =", ta == tb)
    print("  exact_value_match_ratio =", float(same.mean()))
    print("  mismatch_count =", int((~same).sum()))
PY

Result

generate
  same_text = True
  exact_value_match_ratio = 1.0
  mismatch_count = 0
chat
  same_text = True
  exact_value_match_ratio = 1.0
  mismatch_count = 0

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file model-gateway labels Apr 16, 2026
@yueming-yuan
yueming-yuan merged commit a5bfbcb into sgl-project:sglang-miles Apr 16, 2026
1 check passed
@zyzshishui
zyzshishui deleted the sglang-miles-pd-r3 branch April 16, 2026 22:20
JessicaJiang-123 pushed a commit to JessicaJiang-123/sglang that referenced this pull request Jun 21, 2026
XinyuJiangCMU pushed a commit to XinyuJiangCMU/sglang that referenced this pull request Jul 17, 2026
…oject#22916)

Rewired prefill routed-experts collection to the v0.5.15
batch_result_processor._maybe_collect_routed_experts API.
imvladikon pushed a commit to imvladikon/sglang that referenced this pull request Aug 31, 2026
Kh4L pushed a commit to Kh4L/sglang that referenced this pull request Sep 8, 2026
Zhichenzzz pushed a commit that referenced this pull request Sep 19, 2026
(cherry picked from commit d669fb3)
(cherry picked from commit e18e48c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file model-gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants