[Core][Frontend] Bind KV-event publishers at port 0 and expose the bound endpoints (#55844)
Signed-off-by: aoshen02 <aoshen02@users.noreply.github.com> Co-authored-by: mukeshbhandarkar <shell00035@gmail.com> Co-authored-by: aoshen02 <aoshen02@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
co-authored by
mukeshbhandarkar
aoshen02
Claude Fable 5.1
aoshen02
parent
729ebac498
commit
90531daf6d
@@ -17,6 +17,12 @@ import zmq
|
||||
|
||||
from vllm.config.kv_events import KVEventsConfig
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.network_utils import (
|
||||
get_ip,
|
||||
get_tcp_uri,
|
||||
is_valid_ipv6_address,
|
||||
split_zmq_path,
|
||||
)
|
||||
from vllm.v1.core.kv_cache_utils import ExternalBlockHash
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -349,6 +355,8 @@ class ZmqEventPublisher(EventPublisher):
|
||||
replay_endpoint, self._dp_rank
|
||||
)
|
||||
assert self._endpoint is not None
|
||||
self._hwm = hwm
|
||||
self._socket_setup()
|
||||
self._publisher_config = KVEventsConfig(
|
||||
enable_kv_cache_events=True,
|
||||
publisher="zmq",
|
||||
@@ -359,8 +367,6 @@ class ZmqEventPublisher(EventPublisher):
|
||||
max_queue_size=max_queue_size,
|
||||
topic=topic,
|
||||
)
|
||||
self._hwm = hwm
|
||||
self._socket_setup()
|
||||
|
||||
# Payload
|
||||
self._seq_gen = count()
|
||||
@@ -423,16 +429,10 @@ class ZmqEventPublisher(EventPublisher):
|
||||
if self._pub is None:
|
||||
self._pub = self._ctx.socket(zmq.PUB)
|
||||
self._pub.set_hwm(self._hwm)
|
||||
# Heuristic: bind if wildcard / * present, else connect.
|
||||
# bind stable, connect volatile convention
|
||||
if self._endpoint is not None and (
|
||||
"*" in self._endpoint
|
||||
or "::" in self._endpoint
|
||||
or self._endpoint.startswith("ipc://")
|
||||
or self._endpoint.startswith("inproc://")
|
||||
):
|
||||
self._pub.bind(self._endpoint)
|
||||
elif self._endpoint is not None:
|
||||
assert self._endpoint is not None
|
||||
if self._is_bind_endpoint(self._endpoint):
|
||||
self._endpoint = self._bind(self._pub, self._endpoint)
|
||||
else:
|
||||
self._pub.connect(self._endpoint)
|
||||
|
||||
# Set up replay socket: use ROUTER
|
||||
@@ -441,7 +441,31 @@ class ZmqEventPublisher(EventPublisher):
|
||||
# 3) works in our non‑blocking poll loop alongside PUB
|
||||
if self._replay_endpoint is not None:
|
||||
self._replay = self._ctx.socket(zmq.ROUTER)
|
||||
self._replay.bind(self._replay_endpoint)
|
||||
self._replay_endpoint = self._bind(self._replay, self._replay_endpoint)
|
||||
|
||||
@staticmethod
|
||||
def _is_bind_endpoint(endpoint: str) -> bool:
|
||||
"""Bind wildcard and ipc/inproc endpoints; connect to the rest."""
|
||||
return (
|
||||
"*" in endpoint
|
||||
or "::" in endpoint
|
||||
or endpoint.startswith(("ipc://", "inproc://"))
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _bind(sock: zmq.Socket, endpoint: str) -> str:
|
||||
"""Bind; tcp://*:0 binds this node's IP and returns the bound endpoint."""
|
||||
if endpoint != "tcp://*:0":
|
||||
sock.bind(endpoint)
|
||||
return endpoint
|
||||
ip = get_ip()
|
||||
if ip in ("0.0.0.0", "::"):
|
||||
raise ValueError("tcp://*:0 needs a node IP; set VLLM_HOST_IP")
|
||||
if is_valid_ipv6_address(ip):
|
||||
sock.setsockopt(zmq.IPV6, 1)
|
||||
sock.bind(get_tcp_uri(ip, 0))
|
||||
_, _, port = split_zmq_path(sock.getsockopt_string(zmq.LAST_ENDPOINT))
|
||||
return get_tcp_uri(ip, int(port))
|
||||
|
||||
def _publisher_thread(self) -> None:
|
||||
"""Background thread that processes the event queue."""
|
||||
@@ -514,7 +538,7 @@ class ZmqEventPublisher(EventPublisher):
|
||||
|
||||
Returns:
|
||||
The endpoint with the port offset by data_parallel_rank
|
||||
or suffix appended
|
||||
or suffix appended; a tcp port of 0 is left for the OS.
|
||||
|
||||
"""
|
||||
# Do nothing if input is None or data_parallel_rank is 0
|
||||
@@ -529,6 +553,8 @@ class ZmqEventPublisher(EventPublisher):
|
||||
last_colon_idx = endpoint.rfind(":")
|
||||
base_addr = endpoint[:last_colon_idx]
|
||||
base_port = int(endpoint[last_colon_idx + 1 :])
|
||||
if base_port == 0:
|
||||
return endpoint
|
||||
new_port = base_port + data_parallel_rank
|
||||
return f"{base_addr}:{new_port}"
|
||||
return endpoint
|
||||
|
||||
@@ -7,6 +7,7 @@ from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from vllm.config import ModelConfig, VllmConfig
|
||||
from vllm.config.kv_events import KVEventsConfig
|
||||
from vllm.distributed.weight_transfer.base import (
|
||||
WeightTransferInitRequest,
|
||||
WeightTransferUpdateRequest,
|
||||
@@ -62,6 +63,10 @@ class EngineClient(ABC):
|
||||
@abstractmethod
|
||||
def dead_error(self) -> BaseException: ...
|
||||
|
||||
def get_kv_event_sources(self) -> dict[int, KVEventsConfig]:
|
||||
"""KV-event publisher config of each engine, keyed by DP rank."""
|
||||
return {}
|
||||
|
||||
def check_admission( # noqa: B027
|
||||
self, n: int = 1, request_id: str | None = None
|
||||
) -> None:
|
||||
|
||||
@@ -54,3 +54,10 @@ async def get_server_load_metrics(request: Request):
|
||||
async def show_version():
|
||||
ver = {"version": VLLM_VERSION}
|
||||
return JSONResponse(content=ver)
|
||||
|
||||
|
||||
@router.get("/kv_event_sources")
|
||||
async def kv_event_sources(raw_request: Request):
|
||||
"""KV-event publisher config per DP rank; empty on render-only servers."""
|
||||
client: EngineClient | None = raw_request.app.state.engine_client
|
||||
return client.get_kv_event_sources() if client is not None else {}
|
||||
|
||||
@@ -12,6 +12,7 @@ from typing import Any
|
||||
import vllm.envs as envs
|
||||
from vllm import TokensPrompt
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config.kv_events import KVEventsConfig
|
||||
from vllm.distributed.weight_transfer.base import (
|
||||
WeightTransferInitRequest,
|
||||
WeightTransferUpdateRequest,
|
||||
@@ -1282,3 +1283,6 @@ class AsyncLLM(EngineClient):
|
||||
async def get_weight_version(self) -> str:
|
||||
"""Return the latest committed weight version."""
|
||||
return await self.engine_core.get_weight_version_async()
|
||||
|
||||
def get_kv_event_sources(self) -> dict[int, KVEventsConfig]:
|
||||
return self.engine_core.get_kv_event_sources()
|
||||
|
||||
@@ -23,6 +23,7 @@ import zmq.asyncio
|
||||
|
||||
from vllm import envs
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.config.kv_events import KVEventsConfig
|
||||
from vllm.envs import VLLM_ENGINE_READY_TIMEOUT_S
|
||||
from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
@@ -86,6 +87,10 @@ class EngineCoreClient(ABC):
|
||||
* AsyncMPClient: ZMQ + background proc EngineCore w/ asyncio (for AsyncLLM)
|
||||
"""
|
||||
|
||||
def get_kv_event_sources(self) -> dict[int, KVEventsConfig]:
|
||||
"""KV-event publisher config of each ready engine, keyed by DP rank."""
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def make_client(
|
||||
multiprocess_mode: bool,
|
||||
@@ -572,6 +577,7 @@ class MPClient(EngineCoreClient):
|
||||
self.vllm_config = vllm_config
|
||||
self._renderer: BaseRenderer | None = renderer
|
||||
self._effective_attention_block_sizes: set[int | None] = set()
|
||||
self._kv_event_sources: dict[int, KVEventsConfig] = {}
|
||||
|
||||
# ZMQ setup.
|
||||
sync_ctx = zmq.Context(io_threads=2)
|
||||
@@ -860,6 +866,14 @@ class MPClient(EngineCoreClient):
|
||||
else:
|
||||
assert response.dp_stats_address == self.stats_update_address
|
||||
|
||||
if response.kv_events_config is not None:
|
||||
self._kv_event_sources[response.data_parallel_rank] = (
|
||||
response.kv_events_config
|
||||
)
|
||||
|
||||
def get_kv_event_sources(self) -> dict[int, KVEventsConfig]:
|
||||
return dict(self._kv_event_sources)
|
||||
|
||||
|
||||
def _process_utility_output(
|
||||
output: UtilityOutput, utility_results: dict[int, AnyFuture]
|
||||
@@ -1944,6 +1958,8 @@ class DPLBAsyncMPClient(DPAsyncMPClient):
|
||||
self.lb_engines = self.lb_engines[:new_data_parallel_size]
|
||||
# Pending coordinator snapshots must use the surviving ranks too.
|
||||
self.engine_ranks_managed = self.engine_ranks_managed[:new_data_parallel_size]
|
||||
for rank in range(new_data_parallel_size, cur_data_parallel_size):
|
||||
self._kv_event_sources.pop(rank, None)
|
||||
removed_dp_size = cur_data_parallel_size - new_data_parallel_size
|
||||
pause_modes = ["keep"] * new_data_parallel_size + ["abort"] * removed_dp_size
|
||||
pause_futures = [
|
||||
|
||||
Reference in New Issue
Block a user