Unverified Commit 7a6c8c3f authored by iAmir97's avatar iAmir97 Committed by GitHub
Browse files

[Chore] Separate out `vllm.utils.network_utils` (#27164)


Signed-off-by: default avatariAmir97 <Amir.balwel@embeddedllm.com>
Co-authored-by: default avatariAmir97 <Amir.balwel@embeddedllm.com>
parent 221bf725
...@@ -33,7 +33,7 @@ import os ...@@ -33,7 +33,7 @@ import os
from time import sleep from time import sleep
from vllm import LLM, SamplingParams from vllm import LLM, SamplingParams
from vllm.utils import get_open_port from vllm.utils.network_utils import get_open_port
def parse_args(): def parse_args():
......
...@@ -38,7 +38,7 @@ from rlhf_utils import stateless_init_process_group ...@@ -38,7 +38,7 @@ from rlhf_utils import stateless_init_process_group
from transformers import AutoModelForCausalLM from transformers import AutoModelForCausalLM
from vllm import LLM, SamplingParams 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): class MyLLM(LLM):
......
...@@ -19,7 +19,7 @@ from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy ...@@ -19,7 +19,7 @@ from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
from vllm import initialize_ray_cluster from vllm import initialize_ray_cluster
from vllm.config import ParallelConfig from vllm.config import ParallelConfig
from vllm.executor.ray_utils import _wait_until_pg_removed 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" VLLM_MULTI_NODE = os.getenv("VLLM_MULTI_NODE", "0") == "1"
......
...@@ -7,7 +7,7 @@ import torch.distributed as dist ...@@ -7,7 +7,7 @@ import torch.distributed as dist
from vllm.distributed.parallel_state import _node_count from vllm.distributed.parallel_state import _node_count
from vllm.distributed.utils import StatelessProcessGroup 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__": if __name__ == "__main__":
dist.init_process_group(backend="gloo") dist.init_process_group(backend="gloo")
......
...@@ -7,7 +7,7 @@ import torch.distributed as dist ...@@ -7,7 +7,7 @@ import torch.distributed as dist
from vllm.distributed.parallel_state import in_the_same_node_as from vllm.distributed.parallel_state import in_the_same_node_as
from vllm.distributed.utils import StatelessProcessGroup 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__": if __name__ == "__main__":
dist.init_process_group(backend="gloo") dist.init_process_group(backend="gloo")
......
...@@ -10,7 +10,8 @@ import torch.distributed as dist ...@@ -10,7 +10,8 @@ import torch.distributed as dist
from vllm.distributed.device_communicators.shm_broadcast import MessageQueue from vllm.distributed.device_communicators.shm_broadcast import MessageQueue
from vllm.distributed.utils import StatelessProcessGroup 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]: def get_arrays(n: int, seed: int = 0) -> list[np.ndarray]:
......
...@@ -10,10 +10,8 @@ import torch ...@@ -10,10 +10,8 @@ import torch
import vllm.envs as envs import vllm.envs as envs
from vllm.distributed.device_communicators.pynccl import PyNcclCommunicator from vllm.distributed.device_communicators.pynccl import PyNcclCommunicator
from vllm.distributed.utils import StatelessProcessGroup from vllm.distributed.utils import StatelessProcessGroup
from vllm.utils import ( from vllm.utils import update_environment_variables
get_open_port, from vllm.utils.network_utils import get_open_port
update_environment_variables,
)
from vllm.utils.torch_utils import cuda_device_count_stateless from vllm.utils.torch_utils import cuda_device_count_stateless
from ..utils import multi_gpu_test from ..utils import multi_gpu_test
......
...@@ -9,7 +9,7 @@ import time ...@@ -9,7 +9,7 @@ import time
import openai import openai
import pytest import pytest
from ...utils import get_open_port from vllm.utils.network_utils import get_open_port
MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM" MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM"
......
...@@ -12,7 +12,7 @@ from typing_extensions import ParamSpec ...@@ -12,7 +12,7 @@ from typing_extensions import ParamSpec
from vllm.config import VllmConfig, set_current_vllm_config from vllm.config import VllmConfig, set_current_vllm_config
from vllm.distributed import init_distributed_environment, initialize_model_parallel 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 ## Parallel Processes Utils
......
...@@ -15,7 +15,8 @@ from torch.distributed import ProcessGroup ...@@ -15,7 +15,8 @@ from torch.distributed import ProcessGroup
from torch.multiprocessing import spawn # pyright: ignore[reportPrivateImportUsage] from torch.multiprocessing import spawn # pyright: ignore[reportPrivateImportUsage]
from typing_extensions import ParamSpec 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(): if has_deep_ep():
from vllm.model_executor.layers.fused_moe.deepep_ht_prepare_finalize import ( from vllm.model_executor.layers.fused_moe.deepep_ht_prepare_finalize import (
......
...@@ -8,7 +8,7 @@ from vllm import LLM, EngineArgs ...@@ -8,7 +8,7 @@ from vllm import LLM, EngineArgs
from vllm.distributed import cleanup_dist_env_and_memory 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 import tensorizer as tensorizer_mod
from vllm.model_executor.model_loader.tensorizer import TensorizerConfig 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.executor.abstract import UniProcExecutor
from vllm.v1.worker.worker_base import WorkerWrapperBase from vllm.v1.worker.worker_base import WorkerWrapperBase
......
...@@ -19,7 +19,8 @@ from vllm.model_executor.models.vision import ( ...@@ -19,7 +19,8 @@ from vllm.model_executor.models.vision import (
run_dp_sharded_vision_model, run_dp_sharded_vision_model,
) )
from vllm.platforms import current_platform 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 pytestmark = pytest.mark.cpu_test
......
...@@ -46,9 +46,9 @@ from vllm.platforms import current_platform ...@@ -46,9 +46,9 @@ from vllm.platforms import current_platform
from vllm.transformers_utils.tokenizer import get_tokenizer from vllm.transformers_utils.tokenizer import get_tokenizer
from vllm.utils import ( from vllm.utils import (
FlexibleArgumentParser, FlexibleArgumentParser,
get_open_port,
) )
from vllm.utils.mem_constants import GB_bytes 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 from vllm.utils.torch_utils import cuda_device_count_stateless
if current_platform.is_rocm(): if current_platform.is_rocm():
......
# 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"
...@@ -6,7 +6,6 @@ import hashlib ...@@ -6,7 +6,6 @@ import hashlib
import json import json
import os import os
import pickle import pickle
import socket
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
...@@ -14,7 +13,6 @@ from unittest.mock import patch ...@@ -14,7 +13,6 @@ from unittest.mock import patch
import pytest import pytest
import torch import torch
import yaml import yaml
import zmq
from transformers import AutoTokenizer from transformers import AutoTokenizer
from vllm_test_utils.monitor import monitor from vllm_test_utils.monitor import monitor
...@@ -24,13 +22,6 @@ from vllm.transformers_utils.detokenizer_utils import convert_ids_list_to_tokens ...@@ -24,13 +22,6 @@ from vllm.transformers_utils.detokenizer_utils import convert_ids_list_to_tokens
from vllm.utils import ( from vllm.utils import (
FlexibleArgumentParser, FlexibleArgumentParser,
bind_kv_cache, bind_kv_cache,
get_open_port,
get_tcp_uri,
join_host_port,
make_zmq_path,
make_zmq_socket,
split_host_port,
split_zmq_path,
unique_filepath, unique_filepath,
) )
from vllm.utils.hashing import sha256 from vllm.utils.hashing import sha256
...@@ -43,18 +34,6 @@ from vllm.utils.mem_utils import MemorySnapshot, memory_profiling ...@@ -43,18 +34,6 @@ from vllm.utils.mem_utils import MemorySnapshot, memory_profiling
from ..utils import create_new_process_for_each_test, flat_product from ..utils import create_new_process_for_each_test, flat_product
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()))
# Tests for FlexibleArgumentParser # Tests for FlexibleArgumentParser
@pytest.fixture @pytest.fixture
def parser(): def parser():
...@@ -573,104 +552,6 @@ def test_sha256(input: tuple): ...@@ -573,104 +552,6 @@ def test_sha256(input: tuple):
assert digest != sha256(input + (1,)) assert digest != sha256(input + (1,))
@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 socket.error:
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"
def test_convert_ids_list_to_tokens(): def test_convert_ids_list_to_tokens():
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct") tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
token_ids = tokenizer.encode("Hello, world!") token_ids = tokenizer.encode("Hello, world!")
......
...@@ -18,7 +18,7 @@ from vllm.model_executor.layers.batch_invariant import ( ...@@ -18,7 +18,7 @@ from vllm.model_executor.layers.batch_invariant import (
vllm_is_batch_invariant, vllm_is_batch_invariant,
) )
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils import get_open_ports_list from vllm.utils.network_utils import get_open_ports_list
from vllm.utils.torch_utils import cuda_device_count_stateless from vllm.utils.torch_utils import cuda_device_count_stateless
if TYPE_CHECKING: if TYPE_CHECKING:
......
...@@ -27,7 +27,7 @@ from zmq import ( # type: ignore ...@@ -27,7 +27,7 @@ from zmq import ( # type: ignore
import vllm.envs as envs import vllm.envs as envs
from vllm.distributed.utils import StatelessProcessGroup, sched_yield from vllm.distributed.utils import StatelessProcessGroup, sched_yield
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.utils import ( from vllm.utils.network_utils import (
get_ip, get_ip,
get_open_port, get_open_port,
get_open_zmq_ipc_path, get_open_zmq_ipc_path,
......
...@@ -40,7 +40,7 @@ from vllm.distributed.utils import divide ...@@ -40,7 +40,7 @@ from vllm.distributed.utils import divide
from vllm.forward_context import ForwardContext from vllm.forward_context import ForwardContext
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.platforms import current_platform from vllm.platforms import current_platform
from vllm.utils import make_zmq_path, make_zmq_socket from vllm.utils.network_utils import make_zmq_path, make_zmq_socket
from vllm.v1.attention.backends.utils import get_kv_cache_layout from vllm.v1.attention.backends.utils import get_kv_cache_layout
from vllm.v1.core.sched.output import SchedulerOutput from vllm.v1.core.sched.output import SchedulerOutput
......
...@@ -25,7 +25,7 @@ from vllm.distributed.device_communicators.pynccl_wrapper import ( ...@@ -25,7 +25,7 @@ from vllm.distributed.device_communicators.pynccl_wrapper import (
from vllm.distributed.kv_transfer.kv_connector.v1.p2p.tensor_memory_pool import ( # noqa: E501 from vllm.distributed.kv_transfer.kv_connector.v1.p2p.tensor_memory_pool import ( # noqa: E501
TensorMemoryPool, TensorMemoryPool,
) )
from vllm.utils import get_ip from vllm.utils.network_utils import get_ip
from vllm.utils.torch_utils import current_stream from vllm.utils.torch_utils import current_stream
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -15,7 +15,7 @@ from safetensors.torch import save as safetensors_save ...@@ -15,7 +15,7 @@ from safetensors.torch import save as safetensors_save
from vllm.config.kv_transfer import KVTransferConfig from vllm.config.kv_transfer import KVTransferConfig
from vllm.distributed.kv_transfer.kv_pipe.base import KVPipeBase from vllm.distributed.kv_transfer.kv_pipe.base import KVPipeBase
from vllm.logger import init_logger from vllm.logger import init_logger
from vllm.utils import join_host_port, make_zmq_path, split_host_port from vllm.utils.network_utils import join_host_port, make_zmq_path, split_host_port
logger = init_logger(__name__) logger = init_logger(__name__)
NONE_INT = -150886311 NONE_INT = -150886311
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment