Skip to content

Commit

Permalink
fix get_ip error in pure ipv6 environment (vllm-project#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingru authored and jimpang committed Mar 4, 2024
1 parent 2efefa9 commit 88bf558
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,33 @@ 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:
return f"tcp://{ip}:{port}"


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:
Expand Down

0 comments on commit 88bf558

Please sign in to comment.