[disagg] Fix KV-event publisher port collision under pure data parallelism (#29211)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kangyan-Zhou
2026-07-01 10:57:34 -07:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 03b9278da0
commit 30c9801b39
3 changed files with 125 additions and 1 deletions
@@ -36,6 +36,28 @@ from pydantic import BaseModel
logger = logging.getLogger(__name__)
def select_kv_publisher_dp_rank(
attn_dp_size: int, attn_dp_rank: int, dp_rank: Optional[int]
) -> int:
"""Index used to offset this scheduler's KV-event publisher port.
Each independent KV cache must publish on its own port so a consumer can
subscribe per replica. There are always ``dp_size`` such publishers; which
rank distinguishes them depends on the parallelism mode:
- DP-attention (``attn_dp_size > 1``): each attention-DP rank owns a KV
cache shard, so distinguish by ``attn_dp_rank``.
- Pure DP (``attn_dp_size == 1``): every worker has ``attn_dp_rank == 0``,
so distinguish by ``dp_rank`` (the data-parallel replica index).
Both span ``0..dp_size-1``, matching the ``dp_size`` advertised in
``/server_info`` and the per-rank ports the router subscribes to.
"""
if attn_dp_size > 1:
return attn_dp_rank
return dp_rank or 0
class EventBatch(
msgspec.Struct,
array_like=True, # type: ignore[call-arg]
@@ -15,6 +15,7 @@ import zmq
from sglang.srt.disaggregation.kv_events import (
EventPublisherFactory,
KVEventBatch,
select_kv_publisher_dp_rank,
)
from sglang.srt.managers.io_struct import hook_custom_types, sock_send
@@ -69,7 +70,10 @@ class SchedulerKvEventsPublisher:
if self.enable_kv_cache_events:
self.kv_event_publisher = EventPublisherFactory.create(
kv_events_config, self.ps.attn_dp_rank
kv_events_config,
select_kv_publisher_dp_rank(
self.ps.attn_dp_size, self.ps.attn_dp_rank, self.ps.dp_rank
),
)
def emit_kv_metrics(self):