[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
|
||||
|
||||
Reference in New Issue
Block a user