Skip to content

[Fix] Restore PD disaggregation R3 routed_experts patches for SGLang - #2554

Open
lnkerr wants to merge 2 commits into
THUDM:mainfrom
lnkerr:fix/pd-r3-routed-experts
Open

lnkerr wants to merge 2 commits into
THUDM:mainfrom
lnkerr:fix/pd-r3-routed-experts

Conversation

@lnkerr

@lnkerr lnkerr commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #2546.

Root Cause

R3 (--use-rollout-routing-replay) with PD disaggregation expects sglang_router to concatenate prefill's [routed_experts_start_len, prompt_len) rows with decode's [prompt_len, seqlen - 1) rows. Both SGLang patch hunks originally added in #2173 were dropped during the v0.5.15.post1 / v0.5.21 patch refreshes:

  1. prefill.py no longer called self.batch_result_processor._maybe_collect_routed_experts(req) on KVPoll.Success (upstream SGLang added this after v0.5.21 in [Disagg] Return prompt routed experts from the PD prefill server sgl-project/sglang#44002).
  2. scheduler.py no longer set req.routed_experts_start_len = len(req.origin_input_ids) under DisaggregationMode.DECODE, so decode returned prompt_len - start_len leading rows of zeros/stale data before the decode tokens (upstream companion fix: [Fix] disaggregation: Clamp routed_experts_start_len to prompt length on PD decode sgl-project/sglang#51942).

Changes

  • Restore both PD R3 hunks in docker/patch/v0.5.15.post1/sglang.patch, docker/patch/v0.5.21/sglang.patch, and docker/patch/latest/sglang.patch (verified clean git apply --check against upstream v0.5.15.post1 and v0.5.21).
  • Add regression tests in tests/test_rollout_metrics.py guarding both patch hunks across the three patch versions and verifying Sample.append_response_tokens + validate_routed_experts_tensor on PD-merged routed experts (initial + continuation turns).

Verification

  • pytest tests/test_rollout_metrics.py tests/test_rollout_data_utils.py tests/test_sample.py: 45 passed.
  • Verified live on 2× H100 (1P+1D Mooncake RDMA + sglang_router 0.3.2+slime + Slime R3 validator) across Qwen3MoeForCausalLM, Qwen3_5MoeForCausalLM (21/21 exact vs non-PD baseline), and Qwen/Qwen3.5-35B-A3B-FP8 (4/4 passed, 0 zero rows).

…g patches

Restore the two PD disaggregation R3 hunks originally introduced in THUDM#2173
that were dropped during the SGLang v0.5.15.post1 / v0.5.21 patch refreshes:

1. prefill.py: collect prompt routed experts via _maybe_collect_routed_experts
   on KVPoll.Success before releasing the KV cache.
2. scheduler.py: clamp req.routed_experts_start_len to len(req.origin_input_ids)
   under DisaggregationMode.DECODE so decode only returns [prompt_len, seqlen - 1)
   rather than stale/zero prompt rows.

Add unit tests guarding both patch hunks across v0.5.15.post1, v0.5.21, and
latest, and verifying Sample + validate_routed_experts_tensor on PD-merged
routed experts across initial and continuation turns.
@lnkerr

lnkerr commented Nov 21, 2026

Copy link
Copy Markdown
Author

Hi @zhuzilin, could you take a look when you have time? This restores the PD R3 SGLang patch hunks from #2173 (alongside the upstream SGLang decode fix in sgl-project/sglang#51942). Thanks!

This branch has not been deployed

No deployments
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.

[Bug] systematic routing capture failure with MoE for R3 + PD disaggregation

1 participant