[KVConnector] Support worker -> scheduler metadata (#31964)
Signed-off-by: Or Ozeri <oro@il.ibm.com> Co-authored-by: Nicolò Lucchesi <nlucches@redhat.com>
This commit is contained in:
co-authored by
Nicolò Lucchesi
parent
741f4e046b
commit
a1a3523a56
@@ -85,6 +85,7 @@ class KVOutputAggregator:
|
||||
finished_sending = set[str]()
|
||||
finished_recving = set[str]()
|
||||
aggregated_kv_connector_stats = None
|
||||
aggregated_kv_connector_worker_meta = None
|
||||
combined_kv_cache_events = None
|
||||
invalid_block_ids = set[int]()
|
||||
for model_runner_output in outputs:
|
||||
@@ -127,6 +128,17 @@ class KVOutputAggregator:
|
||||
aggregated_kv_connector_stats.aggregate(kv_connector_stats)
|
||||
)
|
||||
|
||||
# Aggregate kv_connector_worker_meta from all workers.
|
||||
if aggregated_kv_connector_worker_meta is None:
|
||||
# Use the first worker's kv_connector_worker_meta as accumulator.
|
||||
aggregated_kv_connector_worker_meta = kv_output.kv_connector_worker_meta
|
||||
elif kv_connector_worker_meta := kv_output.kv_connector_worker_meta:
|
||||
aggregated_kv_connector_worker_meta = (
|
||||
aggregated_kv_connector_worker_meta.aggregate(
|
||||
kv_connector_worker_meta
|
||||
)
|
||||
)
|
||||
|
||||
# Combine kv_cache_events from all workers.
|
||||
if combined_kv_cache_events is None:
|
||||
# Use the first worker's kv_cache events as start event list.
|
||||
@@ -151,6 +163,7 @@ class KVOutputAggregator:
|
||||
finished_recving=finished_recving or None,
|
||||
kv_connector_stats=aggregated_kv_connector_stats or None,
|
||||
kv_cache_events=combined_kv_cache_events or None,
|
||||
kv_connector_worker_meta=aggregated_kv_connector_worker_meta or None,
|
||||
invalid_block_ids=invalid_block_ids,
|
||||
expected_finished_count=self._expected_finished_count,
|
||||
)
|
||||
|
||||
@@ -36,6 +36,8 @@ The class provides the following primitives:
|
||||
|
||||
get_finished() - called with ids of finished requests, returns
|
||||
ids of requests that have completed async sending/recving.
|
||||
build_connector_worker_meta() - builds metadata to be sent
|
||||
back to the scheduler-side connector
|
||||
"""
|
||||
|
||||
import enum
|
||||
@@ -137,13 +139,34 @@ class KVConnectorHandshakeMetadata(ABC): # noqa: B024
|
||||
|
||||
class KVConnectorMetadata(ABC): # noqa: B024
|
||||
"""
|
||||
Abstract Metadata used to communicate between the
|
||||
Scheduler KVConnector and Worker KVConnector.
|
||||
Abstract Metadata used to communicate
|
||||
Scheduler KVConnector -> Worker KVConnector.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class KVConnectorWorkerMetadata(ABC):
|
||||
"""
|
||||
Abstract Metadata used to communicate back
|
||||
Worker KVConnector -> Scheduler KVConnector.
|
||||
|
||||
Each worker can output its own metadata.
|
||||
For a single engine step, all metadata objects returned by workers
|
||||
will be aggregated using the `aggregate` method below, before
|
||||
being passed to the Scheduler KVConnector.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def aggregate(
|
||||
self, other: "KVConnectorWorkerMetadata"
|
||||
) -> "KVConnectorWorkerMetadata":
|
||||
"""
|
||||
Aggregate metadata with another `KVConnectorWorkerMetadata` object.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class KVConnectorBase_V1(ABC):
|
||||
"""
|
||||
Base class for KV connectors.
|
||||
@@ -409,6 +432,16 @@ class KVConnectorBase_V1(ABC):
|
||||
"""
|
||||
return None
|
||||
|
||||
def build_connector_worker_meta(self) -> KVConnectorWorkerMetadata | None:
|
||||
"""
|
||||
Build the KVConnector worker metadata for this engine step.
|
||||
|
||||
Returns:
|
||||
KVConnectorWorkerMetadata: the worker metadata.
|
||||
None if no worker metadata is available.
|
||||
"""
|
||||
return None
|
||||
|
||||
# ==============================
|
||||
# Scheduler-side methods
|
||||
# ==============================
|
||||
|
||||
@@ -17,6 +17,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.base import (
|
||||
KVConnectorHandshakeMetadata,
|
||||
KVConnectorMetadata,
|
||||
KVConnectorRole,
|
||||
KVConnectorWorkerMetadata,
|
||||
)
|
||||
from vllm.distributed.kv_transfer.kv_connector.v1.metrics import (
|
||||
KVConnectorPromMetrics,
|
||||
@@ -45,6 +46,26 @@ class MultiKVConnectorMetadata(KVConnectorMetadata):
|
||||
extra_async_saves: dict[str, int] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class MultiKVConnectorWorkerMetadata(KVConnectorWorkerMetadata):
|
||||
metadata: tuple[KVConnectorWorkerMetadata | None, ...]
|
||||
|
||||
def aggregate(self, other: KVConnectorWorkerMetadata) -> KVConnectorWorkerMetadata:
|
||||
assert isinstance(other, MultiKVConnectorWorkerMetadata)
|
||||
|
||||
assert len(self.metadata) == len(other.metadata)
|
||||
metadata_list = []
|
||||
for metadata1, metadata2 in zip(self.metadata, other.metadata):
|
||||
if metadata1 is None:
|
||||
metadata_list.append(metadata2)
|
||||
elif metadata2 is None:
|
||||
metadata_list.append(metadata1)
|
||||
else:
|
||||
metadata_list.append(metadata1.aggregate(metadata2))
|
||||
|
||||
return MultiKVConnectorWorkerMetadata(metadata=tuple(metadata_list))
|
||||
|
||||
|
||||
@dataclass
|
||||
class MultiKVConnectorStats(KVConnectorStats):
|
||||
"""
|
||||
@@ -304,6 +325,18 @@ class MultiConnector(KVConnectorBase_V1):
|
||||
# Currently no connectors return non-None
|
||||
return None
|
||||
|
||||
def build_connector_worker_meta(self) -> KVConnectorWorkerMetadata | None:
|
||||
metadata_list: list[KVConnectorWorkerMetadata | None] | None = None
|
||||
for i, c in enumerate(self._connectors):
|
||||
kv_connector_worker_meta = c.build_connector_worker_meta()
|
||||
if metadata_list is None and kv_connector_worker_meta is not None:
|
||||
metadata_list = [None] * i
|
||||
if metadata_list is not None:
|
||||
metadata_list.append(kv_connector_worker_meta)
|
||||
if metadata_list is None:
|
||||
return None
|
||||
return MultiKVConnectorWorkerMetadata(metadata=tuple(metadata_list))
|
||||
|
||||
# TODO: Add a generic implementation of 'get_kv_connector_kv_cache_events'
|
||||
# method for the MultiConnector. It should be able to get events from
|
||||
# multiple connectors, handling the case where only a subset of the
|
||||
@@ -361,8 +394,25 @@ class MultiConnector(KVConnectorBase_V1):
|
||||
return metadata
|
||||
|
||||
def update_connector_output(self, connector_output: KVConnectorOutput):
|
||||
for c in self._connectors:
|
||||
c.update_connector_output(connector_output)
|
||||
multi_connector_worker_meta: MultiKVConnectorWorkerMetadata | None = None
|
||||
if connector_output.kv_connector_worker_meta is not None:
|
||||
assert isinstance(
|
||||
connector_output.kv_connector_worker_meta,
|
||||
MultiKVConnectorWorkerMetadata,
|
||||
)
|
||||
multi_connector_worker_meta = connector_output.kv_connector_worker_meta
|
||||
|
||||
try:
|
||||
for i, c in enumerate(self._connectors):
|
||||
if multi_connector_worker_meta is not None:
|
||||
# set the connector-specific worker metadata
|
||||
connector_output.kv_connector_worker_meta = (
|
||||
multi_connector_worker_meta.metadata[i]
|
||||
)
|
||||
c.update_connector_output(connector_output)
|
||||
finally:
|
||||
# restore kv_connector_worker_meta
|
||||
connector_output.kv_connector_worker_meta = multi_connector_worker_meta
|
||||
|
||||
def get_handshake_metadata(self) -> KVConnectorHandshakeMetadata | None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user