From bf4adc41470e9e6ea46ef5ccf6f86572996e2ca6 Mon Sep 17 00:00:00 2001 From: Jingru Date: Wed, 21 Feb 2024 02:36:06 +0000 Subject: [PATCH 1/2] fix get_ip/get_open_port failure in pure ipv6 environment --- vllm/utils.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/vllm/utils.py b/vllm/utils.py index d7a3a3a2a9ef9..d2b1008be6033 100644 --- a/vllm/utils.py +++ b/vllm/utils.py @@ -162,9 +162,16 @@ def _async_wrapper(*args, **kwargs) -> asyncio.Future: def get_ip() -> str: + # try ipv4 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect(("8.8.8.8", 80)) # Doesn't need to be reachable - return s.getsockname()[0] + try: + s.connect(("dns.google", 80)) # Doesn't need to be reachable + return s.getsockname()[0] + except OSError: + # try ipv6 + s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + s.connect(("dns.google", 80)) + return s.getsockname()[0] def get_distributed_init_method(ip: str, port: int) -> str: @@ -172,10 +179,16 @@ def get_distributed_init_method(ip: str, port: int) -> str: def get_open_port() -> int: - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - s.bind(("", 0)) - return s.getsockname()[1] - + # try ipv4 + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind(("", 0)) + return s.getsockname()[1] + except OSError: + # try ipv6 + with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: + s.bind(("", 0)) + return s.getsockname()[1] def set_cuda_visible_devices(device_ids: List[int]) -> None: os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, device_ids)) From 26754569640bdf5a4850fe889ce41c93366e12a9 Mon Sep 17 00:00:00 2001 From: Jingru Date: Wed, 21 Feb 2024 03:32:38 +0000 Subject: [PATCH 2/2] fix get_ip/get_open_port failure in pure ipv6 environment --- vllm/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vllm/utils.py b/vllm/utils.py index d2b1008be6033..01997fed48a7c 100644 --- a/vllm/utils.py +++ b/vllm/utils.py @@ -190,6 +190,7 @@ def get_open_port() -> int: s.bind(("", 0)) return s.getsockname()[1] + def set_cuda_visible_devices(device_ids: List[int]) -> None: os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, device_ids))