[NIXL][PCP][DCP] Expose PCP producer KV shards as transfer ranks (#56645)
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
71888f507a
commit
7fe8fc803d
@@ -63,6 +63,12 @@ class NixlBaseConnectorScheduler:
|
||||
kv_cache_config: "KVCacheConfig",
|
||||
):
|
||||
self.vllm_config = vllm_config
|
||||
parallel_config = vllm_config.parallel_config
|
||||
# TP1 PCP+DCP exposes its DCP shards as transfer ranks.
|
||||
self.transfer_tp_size = max(
|
||||
parallel_config.tensor_parallel_size,
|
||||
parallel_config.decode_context_parallel_size,
|
||||
)
|
||||
self.block_size = vllm_config.cache_config.block_size
|
||||
self.engine_id: EngineId = engine_id
|
||||
self.kv_cache_config = kv_cache_config
|
||||
|
||||
@@ -548,9 +548,15 @@ class NixlBaseConnectorWorker:
|
||||
self.dcp_size = vllm_config.parallel_config.decode_context_parallel_size
|
||||
self.pcp_rank = get_pcp_group().rank_in_group if self.pcp_size > 1 else 0
|
||||
|
||||
# DCP support is scoped to MLA, with dcp_size in (1, tp_size): either fully
|
||||
# replicated or fully sharded. A DCP rank is always derivable this way.
|
||||
self.dcp_rank = self.tp_rank % self.dcp_size
|
||||
# TP1 PCP+DCP owns distinct KV shards; replicated PCP uses rank zero.
|
||||
self.pcp_dcp_sharded = self.pcp_size > 1 and self.dcp_size > 1
|
||||
self.transfer_tp_size = (
|
||||
self.pcp_size if self.pcp_dcp_sharded else self.world_size
|
||||
)
|
||||
self.transfer_tp_rank = self.pcp_rank if self.pcp_dcp_sharded else self.tp_rank
|
||||
|
||||
# MLA is either fully replicated or fully sharded across transfer ranks.
|
||||
self.dcp_rank = self.transfer_tp_rank % self.dcp_size
|
||||
|
||||
self.num_blocks = kv_cache_config.num_blocks
|
||||
self.enable_permute_local_kv = False
|
||||
@@ -781,12 +787,16 @@ class NixlBaseConnectorWorker:
|
||||
local_dcp_size = self.dcp_size
|
||||
remote_pcp_size = agent_metadata.pcp_size
|
||||
remote_dcp_size = agent_metadata.dcp_size
|
||||
if (local_pcp_size > 1 and remote_dcp_size > 1) or (
|
||||
remote_pcp_size > 1 and local_dcp_size > 1
|
||||
if remote_pcp_size > 1 and remote_dcp_size not in (1, remote_pcp_size):
|
||||
raise NotImplementedError(
|
||||
"Remote NixlConnector PCP+DCP does not span the full PCP group. "
|
||||
f"Remote PCP/DCP={remote_pcp_size}/{remote_dcp_size}."
|
||||
)
|
||||
if (local_pcp_size > 1 and local_dcp_size == 1 and remote_dcp_size > 1) or (
|
||||
remote_pcp_size > 1 and remote_dcp_size == 1 and local_dcp_size > 1
|
||||
):
|
||||
raise NotImplementedError(
|
||||
"NixlConnector PCP requires decode_context_parallel_size=1 "
|
||||
"on both instances. "
|
||||
"Replicated PCP cannot be paired with a DCP-sharded NIXL peer. "
|
||||
f"Local PCP/DCP={local_pcp_size}/{local_dcp_size}; "
|
||||
f"remote PCP/DCP={remote_pcp_size}/{remote_dcp_size}."
|
||||
)
|
||||
@@ -1210,8 +1220,8 @@ class NixlBaseConnectorWorker:
|
||||
"""Register the KV Cache data in nixl."""
|
||||
|
||||
self.transfer_topo = TransferTopology(
|
||||
tp_rank=self.tp_rank,
|
||||
tp_size=self.world_size,
|
||||
tp_rank=self.transfer_tp_rank,
|
||||
tp_size=self.transfer_tp_size,
|
||||
block_size=self.block_size,
|
||||
engine_id=self.engine_id,
|
||||
is_mla=self.use_mla,
|
||||
|
||||
@@ -108,10 +108,15 @@ class NixlBaseConnector(KVConnectorBase_V1, SupportsHMA):
|
||||
"Consumers and kv_both require "
|
||||
"prefill_context_parallel_size=1."
|
||||
)
|
||||
if pcp_size > 1 and parallel_config.decode_context_parallel_size > 1:
|
||||
dcp_size = parallel_config.decode_context_parallel_size
|
||||
if (
|
||||
pcp_size > 1
|
||||
and dcp_size > 1
|
||||
and (parallel_config.tensor_parallel_size != 1 or dcp_size != pcp_size)
|
||||
):
|
||||
raise NotImplementedError(
|
||||
"NixlConnector PCP producers currently require "
|
||||
"decode_context_parallel_size=1."
|
||||
"NixlConnector PCP+DCP requires TP1 with DCP spanning "
|
||||
"the full PCP group."
|
||||
)
|
||||
# TODO: Support PCP with bidirectional KV transfer by tracking separate
|
||||
# send and receive completion counts.
|
||||
@@ -243,6 +248,7 @@ class NixlBaseConnector(KVConnectorBase_V1, SupportsHMA):
|
||||
if (
|
||||
self.kv_transfer_config.kv_role == "kv_producer"
|
||||
and self.connector_worker.pcp_rank > 0
|
||||
and not self.connector_worker.pcp_dcp_sharded
|
||||
):
|
||||
results.finished_sending.clear()
|
||||
return results
|
||||
@@ -324,6 +330,7 @@ class NixlBaseConnector(KVConnectorBase_V1, SupportsHMA):
|
||||
if (
|
||||
self.kv_transfer_config.kv_role == "kv_producer"
|
||||
and self.connector_worker.pcp_rank > 0
|
||||
and not self.connector_worker.pcp_dcp_sharded
|
||||
):
|
||||
return None
|
||||
return self.connector_worker.xfer_handshake_metadata
|
||||
|
||||
@@ -282,7 +282,7 @@ class NixlPullConnectorScheduler(NixlBaseConnectorScheduler):
|
||||
remote_request_id=request.request_id,
|
||||
remote_host=self.side_channel_host,
|
||||
remote_port=self.side_channel_port,
|
||||
tp_size=self.vllm_config.parallel_config.tensor_parallel_size,
|
||||
tp_size=self.transfer_tp_size,
|
||||
dcp_size=self.vllm_config.parallel_config.decode_context_parallel_size,
|
||||
pp_size=self.vllm_config.parallel_config.pipeline_parallel_size,
|
||||
remote_num_tokens=remote_num_tokens,
|
||||
|
||||
@@ -80,7 +80,7 @@ class NixlPullConnectorWorker(NixlBaseConnectorWorker):
|
||||
while not self._ready_requests.empty():
|
||||
self._read_blocks_for_req(*self._ready_requests.get_nowait())
|
||||
|
||||
if self.pcp_rank > 0:
|
||||
if self.pcp_rank > 0 and not self.pcp_dcp_sharded:
|
||||
# Replicated-KV PCP: only PCP rank 0 serves the KV, so this rank
|
||||
# has nothing to send. Report the requests as sent right away so
|
||||
# the scheduler-side aggregation (world_size workers, and any
|
||||
|
||||
@@ -286,7 +286,8 @@ class NixlPushConnectorScheduler(NixlBaseConnectorScheduler):
|
||||
remote_request_id=request.request_id,
|
||||
remote_host=self.side_channel_host,
|
||||
remote_port=self.side_channel_port,
|
||||
tp_size=self.vllm_config.parallel_config.tensor_parallel_size,
|
||||
tp_size=self.transfer_tp_size,
|
||||
dcp_size=self.vllm_config.parallel_config.decode_context_parallel_size,
|
||||
pp_size=self.vllm_config.parallel_config.pipeline_parallel_size,
|
||||
remote_num_tokens=remote_num_tokens,
|
||||
transfer_mode=self._TRANSFER_MODE,
|
||||
|
||||
@@ -166,7 +166,7 @@ class NixlPushConnectorWorker(NixlBaseConnectorWorker):
|
||||
|
||||
def start_load_kv(self, metadata: NixlConnectorMetadata):
|
||||
"""Pre-process metadata; defer NIXL ops to the writer thread."""
|
||||
if self.pcp_rank > 0:
|
||||
if self.pcp_rank > 0 and not self.pcp_dcp_sharded:
|
||||
return
|
||||
|
||||
# D-side: track reqs waiting for P to push.
|
||||
|
||||
Reference in New Issue
Block a user