Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/offline_inference/data_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from time import sleep

from vllm import LLM, SamplingParams
from vllm.utils import get_open_port
from vllm.utils.network_utils import get_open_port


def parse_args():
Expand Down
2 changes: 1 addition & 1 deletion examples/offline_inference/rlhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from transformers import AutoModelForCausalLM

from vllm import LLM, SamplingParams
from vllm.utils import get_ip, get_open_port
from vllm.utils.network_utils import get_ip, get_open_port


class MyLLM(LLM):
Expand Down
2 changes: 1 addition & 1 deletion tests/distributed/test_multi_node_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from vllm import initialize_ray_cluster
from vllm.config import ParallelConfig
from vllm.executor.ray_utils import _wait_until_pg_removed
from vllm.utils import get_ip
from vllm.utils.network_utils import get_ip

VLLM_MULTI_NODE = os.getenv("VLLM_MULTI_NODE", "0") == "1"

Expand Down
2 changes: 1 addition & 1 deletion tests/distributed/test_node_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from vllm.distributed.parallel_state import _node_count
from vllm.distributed.utils import StatelessProcessGroup
from vllm.utils import get_ip, get_open_port
from vllm.utils.network_utils import get_ip, get_open_port

if __name__ == "__main__":
dist.init_process_group(backend="gloo")
Expand Down
2 changes: 1 addition & 1 deletion tests/distributed/test_same_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from vllm.distributed.parallel_state import in_the_same_node_as
from vllm.distributed.utils import StatelessProcessGroup
from vllm.utils import get_ip, get_open_port
from vllm.utils.network_utils import get_ip, get_open_port

if __name__ == "__main__":
dist.init_process_group(backend="gloo")
Expand Down
3 changes: 2 additions & 1 deletion tests/distributed/test_shm_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from vllm.distributed.device_communicators.shm_broadcast import MessageQueue
from vllm.distributed.utils import StatelessProcessGroup
from vllm.utils import get_open_port, update_environment_variables
from vllm.utils import update_environment_variables
from vllm.utils.network_utils import get_open_port


def get_arrays(n: int, seed: int = 0) -> list[np.ndarray]:
Expand Down
6 changes: 2 additions & 4 deletions tests/distributed/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import vllm.envs as envs
from vllm.distributed.device_communicators.pynccl import PyNcclCommunicator
from vllm.distributed.utils import StatelessProcessGroup
from vllm.utils import (
get_open_port,
update_environment_variables,
)
from vllm.utils import update_environment_variables
from vllm.utils.network_utils import get_open_port
from vllm.utils.torch_utils import cuda_device_count_stateless

from ..utils import multi_gpu_test
Expand Down
2 changes: 1 addition & 1 deletion tests/entrypoints/openai/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import openai
import pytest

from ...utils import get_open_port
from vllm.utils.network_utils import get_open_port

MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM"

Expand Down
2 changes: 1 addition & 1 deletion tests/kernels/moe/modular_kernel_tools/parallel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from vllm.config import VllmConfig, set_current_vllm_config
from vllm.distributed import init_distributed_environment, initialize_model_parallel
from vllm.utils import get_open_port
from vllm.utils.network_utils import get_open_port

## Parallel Processes Utils

Expand Down
3 changes: 2 additions & 1 deletion tests/kernels/moe/parallel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from torch.multiprocessing import spawn # pyright: ignore[reportPrivateImportUsage]
from typing_extensions import ParamSpec

from vllm.utils import get_open_port, has_deep_ep
from vllm.utils import has_deep_ep
from vllm.utils.network_utils import get_open_port

if has_deep_ep():
from vllm.model_executor.layers.fused_moe.deepep_ht_prepare_finalize import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from vllm.distributed import cleanup_dist_env_and_memory
from vllm.model_executor.model_loader import tensorizer as tensorizer_mod
from vllm.model_executor.model_loader.tensorizer import TensorizerConfig
from vllm.utils import get_distributed_init_method, get_ip, get_open_port
from vllm.utils.network_utils import get_distributed_init_method, get_ip, get_open_port
from vllm.v1.executor.abstract import UniProcExecutor
from vllm.v1.worker.worker_base import WorkerWrapperBase

Expand Down
3 changes: 2 additions & 1 deletion tests/models/test_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
run_dp_sharded_vision_model,
)
from vllm.platforms import current_platform
from vllm.utils import get_open_port, update_environment_variables
from vllm.utils import update_environment_variables
from vllm.utils.network_utils import get_open_port

pytestmark = pytest.mark.cpu_test

Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
from vllm.transformers_utils.tokenizer import get_tokenizer
from vllm.utils import (
FlexibleArgumentParser,
get_open_port,
)
from vllm.utils.mem_constants import GB_bytes
from vllm.utils.network_utils import get_open_port
from vllm.utils.torch_utils import cuda_device_count_stateless

if current_platform.is_rocm():
Expand Down
126 changes: 126 additions & 0 deletions tests/utils_/test_network_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import socket

import pytest
import zmq

from vllm.utils.network_utils import (
get_open_port,
get_tcp_uri,
join_host_port,
make_zmq_path,
make_zmq_socket,
split_host_port,
split_zmq_path,
)


def test_get_open_port(monkeypatch: pytest.MonkeyPatch):
with monkeypatch.context() as m:
m.setenv("VLLM_PORT", "5678")
# make sure we can get multiple ports, even if the env var is set
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s1:
s1.bind(("localhost", get_open_port()))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s2:
s2.bind(("localhost", get_open_port()))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s3:
s3.bind(("localhost", get_open_port()))


@pytest.mark.parametrize(
"path,expected",
[
("ipc://some_path", ("ipc", "some_path", "")),
("tcp://127.0.0.1:5555", ("tcp", "127.0.0.1", "5555")),
("tcp://[::1]:5555", ("tcp", "::1", "5555")), # IPv6 address
("inproc://some_identifier", ("inproc", "some_identifier", "")),
],
)
def test_split_zmq_path(path, expected):
assert split_zmq_path(path) == expected


@pytest.mark.parametrize(
"invalid_path",
[
"invalid_path", # Missing scheme
"tcp://127.0.0.1", # Missing port
"tcp://[::1]", # Missing port for IPv6
"tcp://:5555", # Missing host
],
)
def test_split_zmq_path_invalid(invalid_path):
with pytest.raises(ValueError):
split_zmq_path(invalid_path)


def test_make_zmq_socket_ipv6():
# Check if IPv6 is supported by trying to create an IPv6 socket
try:
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.close()
except OSError:
pytest.skip("IPv6 is not supported on this system")

ctx = zmq.Context()
ipv6_path = "tcp://[::]:5555" # IPv6 loopback address
socket_type = zmq.REP # Example socket type

# Create the socket
zsock: zmq.Socket = make_zmq_socket(ctx, ipv6_path, socket_type)

# Verify that the IPV6 option is set
assert zsock.getsockopt(zmq.IPV6) == 1, (
"IPV6 option should be enabled for IPv6 addresses"
)

# Clean up
zsock.close()
ctx.term()


def test_make_zmq_path():
assert make_zmq_path("tcp", "127.0.0.1", "5555") == "tcp://127.0.0.1:5555"
assert make_zmq_path("tcp", "::1", "5555") == "tcp://[::1]:5555"


def test_get_tcp_uri():
assert get_tcp_uri("127.0.0.1", 5555) == "tcp://127.0.0.1:5555"
assert get_tcp_uri("::1", 5555) == "tcp://[::1]:5555"


def test_split_host_port():
# valid ipv4
assert split_host_port("127.0.0.1:5555") == ("127.0.0.1", 5555)
# invalid ipv4
with pytest.raises(ValueError):
# multi colon
assert split_host_port("127.0.0.1::5555")
with pytest.raises(ValueError):
# tailing colon
assert split_host_port("127.0.0.1:5555:")
with pytest.raises(ValueError):
# no colon
assert split_host_port("127.0.0.15555")
with pytest.raises(ValueError):
# none int port
assert split_host_port("127.0.0.1:5555a")

# valid ipv6
assert split_host_port("[::1]:5555") == ("::1", 5555)
# invalid ipv6
with pytest.raises(ValueError):
# multi colon
assert split_host_port("[::1]::5555")
with pytest.raises(IndexError):
# no colon
assert split_host_port("[::1]5555")
with pytest.raises(ValueError):
# none int port
assert split_host_port("[::1]:5555a")


def test_join_host_port():
assert join_host_port("127.0.0.1", 5555) == "127.0.0.1:5555"
assert join_host_port("::1", 5555) == "[::1]:5555"
Loading