[PD] Publish prefill DP rank whenever forced lookup is enabled (#41786)

This commit is contained in:
Aurick Qiao
2026-10-04 11:46:20 +08:00
committed by GitHub
parent 169e6223ef
commit f24db66729
2 changed files with 66 additions and 15 deletions
+15 -15
View File
@@ -1799,27 +1799,27 @@ class CommonKVSender(BaseKVSender):
self.kv_mgr.update_status(self.bootstrap_room, KVPoll.Bootstrapping)
if get_parallel().num_dp_ranks > 1 and not req_has_disagg_prefill_dp_rank:
if get_parallel().load_balance_method != "follow_bootstrap_room":
if (
get_parallel().load_balance_method != "follow_bootstrap_room"
or envs.SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK.get()
):
self._register_prefill_dp_rank()
elif (
self.kv_mgr.attn_dp_rank
!= self.bootstrap_room % get_parallel().num_dp_ranks
):
# follow_bootstrap_room was overridden by external routed_dp_rank
if envs.SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK.get():
self._register_prefill_dp_rank()
else:
self.kv_mgr.record_failure(
self.bootstrap_room,
f"follow_bootstrap_room conflict: dispatched to dp_rank "
f"{self.kv_mgr.attn_dp_rank} but bootstrap_room "
f"{self.bootstrap_room} implies dp_rank "
f"{self.bootstrap_room % get_parallel().num_dp_ranks}. "
f"Set SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK=1 "
f"to allow mixed routing.",
)
self.kv_mgr.update_status(self.bootstrap_room, KVPoll.Failed)
return
self.kv_mgr.record_failure(
self.bootstrap_room,
f"follow_bootstrap_room conflict: dispatched to dp_rank "
f"{self.kv_mgr.attn_dp_rank} but bootstrap_room "
f"{self.bootstrap_room} implies dp_rank "
f"{self.bootstrap_room % get_parallel().num_dp_ranks}. "
f"Set SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK=1 "
f"to allow mixed routing.",
)
self.kv_mgr.update_status(self.bootstrap_room, KVPoll.Failed)
return
def _register_prefill_dp_rank(self):
"""Register this request's prefill dp_rank to the bootstrap server."""
@@ -26,6 +26,57 @@ class TestRegisterToBootstrap(CustomTestCase):
override.install()
self.addCleanup(override.restore)
def test_sender_dp_rank_registration(self):
from sglang.srt.disaggregation.base.conn import KVPoll
from sglang.srt.disaggregation.common.conn import CommonKVSender
for force_query in (False, True):
for dp_rank in (0, 1):
with self.subTest(force_query=force_query, dp_rank=dp_rank):
mgr = MagicMock(is_dummy_cp_rank=False, attn_dp_rank=dp_rank)
sender = MagicMock(spec=CommonKVSender)
sender._register_prefill_dp_rank = (
CommonKVSender._register_prefill_dp_rank.__get__(sender)
)
with (
patch(
"sglang.srt.disaggregation.common.conn.requests.post"
) as mock_post,
get_context().override_server_args(
dp_size=4, load_balance_method="follow_bootstrap_room"
),
envs.SGLANG_DISAGGREGATION_FORCE_QUERY_PREFILL_DP_RANK.override(
force_query
),
):
mock_post.return_value.status_code = 200
CommonKVSender.__init__(
sender,
mgr=mgr,
bootstrap_addr="127.0.0.1:8765",
bootstrap_room=4,
dest_tp_ranks=[0],
pp_rank=0,
)
self.assertEqual(
mock_post.call_args_list,
[
call(
"http://127.0.0.1:8765/register_dp_rank",
json={"bootstrap_room": 4, "dp_rank": dp_rank},
timeout=5,
)
]
if force_query
else [],
)
conflict = not force_query and dp_rank != 0
self.assertEqual(mgr.record_failure.call_count, int(conflict))
mgr.update_status.assert_called_with(
4, KVPoll.Failed if conflict else KVPoll.Bootstrapping
)
@patch("sglang.srt.disaggregation.common.conn.time")
@patch("sglang.srt.disaggregation.common.conn.requests.put")
def test_succeeds_on_first_attempt(self, mock_put, mock_time):