[Mini-vLLM] Cut dead subsystems: models, entrypoints, backends, utils, tests

- Drop dead model modules, keeping files live imports require
- Remove anthropic, cohere, codegen entrypoints and batch STT modes
- Delete unused attention backends, MoE experts, and NPU/XPU util leaves
- Strip dead third_party trees and ROCm leaves with no CUDA path
- Remove mooncake EC connectors: dependency missing since branch base
- Re-audit verified by full import sweep and Qwen3.5 smoke test

Co-authored-by: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-19 00:20:48 +07:00
co-authored by Hinata
parent 6a95f62e2f
commit 81074e94a3
940 changed files with 11 additions and 380533 deletions
-189
View File
@@ -1,189 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Cgroup memory readers and SHM allocation preflight checks."""
import sys
from io import StringIO
from unittest import mock
import pytest
from vllm.utils import cpu_resource_utils as cru
from vllm.utils.mem_constants import GiB_bytes
_V2_LIMIT_PATH = "/sys/fs/cgroup/memory.max"
_V2_USAGE_PATH = "/sys/fs/cgroup/memory.current"
_V1_LIMIT_PATH = "/sys/fs/cgroup/memory/memory.limit_in_bytes"
_V1_USAGE_PATH = "/sys/fs/cgroup/memory/memory.usage_in_bytes"
@pytest.fixture(autouse=True)
def _clear_cgroup_cache():
cru.get_cgroup_memory_limit.cache_clear()
yield
cru.get_cgroup_memory_limit.cache_clear()
def _stub_files(monkeypatch, files: dict):
"""Stub ``open()`` for a fixed set of paths; ``None`` -> OSError."""
real_open = open
def fake_open(path, *args, **kwargs):
if path in files:
content = files[path]
if content is None:
raise OSError(f"no such file: {path}")
return StringIO(content)
return real_open(path, *args, **kwargs)
monkeypatch.setattr("builtins.open", fake_open)
def test_cgroup_v2_limit_and_usage(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
_stub_files(
monkeypatch,
{
_V2_LIMIT_PATH: f"{20 * GiB_bytes}\n",
_V2_USAGE_PATH: f"{5 * GiB_bytes}\n",
},
)
assert cru.get_cgroup_memory_limit() == 20 * GiB_bytes
assert cru.get_cgroup_memory_usage() == 5 * GiB_bytes
def test_cgroup_v2_unlimited_falls_back_to_v1(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
_stub_files(
monkeypatch,
{
_V2_LIMIT_PATH: "max\n",
_V1_LIMIT_PATH: f"{8 * GiB_bytes}\n",
_V1_USAGE_PATH: f"{1 * GiB_bytes}\n",
},
)
assert cru.get_cgroup_memory_limit() == 8 * GiB_bytes
assert cru.get_cgroup_memory_usage() == 1 * GiB_bytes
def test_cgroup_v1_limit_and_usage(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
_stub_files(
monkeypatch,
{
_V2_LIMIT_PATH: None,
_V1_LIMIT_PATH: f"{8 * GiB_bytes}\n",
_V1_USAGE_PATH: f"{2 * GiB_bytes}\n",
},
)
assert cru.get_cgroup_memory_limit() == 8 * GiB_bytes
assert cru.get_cgroup_memory_usage() == 2 * GiB_bytes
def test_cgroup_v1_unlimited_sentinel_is_ignored(monkeypatch):
"""An unlimited cgroup v1 sentinel must not be treated as a real limit."""
monkeypatch.setattr(sys, "platform", "linux")
_stub_files(
monkeypatch,
{_V2_LIMIT_PATH: None, _V1_LIMIT_PATH: f"{(1 << 63) - 1}\n"},
)
assert cru.get_cgroup_memory_limit() is None
assert cru.get_cgroup_memory_usage() is None
def test_cgroup_no_limit_files_present(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
_stub_files(monkeypatch, {_V2_LIMIT_PATH: None, _V1_LIMIT_PATH: None})
assert cru.get_cgroup_memory_limit() is None
assert cru.get_cgroup_memory_usage() is None
def test_cgroup_skipped_on_non_linux(monkeypatch):
monkeypatch.setattr(sys, "platform", "darwin")
_stub_files(monkeypatch, {_V2_LIMIT_PATH: f"{1 * GiB_bytes}\n"})
assert cru.get_cgroup_memory_limit() is None
assert cru.get_cgroup_memory_usage() is None
def test_cgroup_limit_is_cached_until_explicitly_cleared(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
files = {
_V2_LIMIT_PATH: f"{1 * GiB_bytes}\n",
_V2_USAGE_PATH: f"{512 << 20}\n",
}
_stub_files(monkeypatch, files)
assert cru.get_cgroup_memory_limit() == 1 * GiB_bytes
files[_V2_LIMIT_PATH] = f"{2 * GiB_bytes}\n"
assert cru.get_cgroup_memory_limit() == 1 * GiB_bytes
cru.get_cgroup_memory_limit.cache_clear()
assert cru.get_cgroup_memory_limit() == 2 * GiB_bytes
def test_cgroup_usage_is_read_without_cache(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
files = {
_V2_LIMIT_PATH: f"{1 * GiB_bytes}\n",
_V2_USAGE_PATH: f"{512 << 20}\n",
}
_stub_files(monkeypatch, files)
assert cru.get_cgroup_memory_usage() == 512 << 20
files[_V2_USAGE_PATH] = f"{768 << 20}\n"
assert cru.get_cgroup_memory_usage() == 768 << 20
def test_check_cgroup_memory_available_warns_on_low_headroom(monkeypatch):
monkeypatch.setattr(cru, "get_cgroup_memory_limit", lambda: 1 << 30)
monkeypatch.setattr(cru, "get_cgroup_memory_usage", lambda: 512 << 20)
with (
mock.patch.object(cru.logger, "debug") as log_debug,
mock.patch.object(cru.logger, "warning") as log_warning,
):
cru.check_cgroup_memory_available(600 << 20, "mmap")
log_debug.assert_not_called()
log_warning.assert_called_once()
assert "current headroom is below" in log_warning.call_args.args[-1]
def test_check_cgroup_memory_available_logs_success_at_debug(monkeypatch):
monkeypatch.setattr(cru, "get_cgroup_memory_limit", lambda: 1 << 30)
monkeypatch.setattr(cru, "get_cgroup_memory_usage", lambda: 512 << 20)
with (
mock.patch.object(cru.logger, "debug") as log_debug,
mock.patch.object(cru.logger, "warning") as log_warning,
):
cru.check_cgroup_memory_available(256 << 20, "mmap")
log_debug.assert_called_once()
log_warning.assert_not_called()
@pytest.mark.parametrize(
("limit", "usage"),
[(None, 512 << 20), (1 << 30, None)],
)
def test_check_cgroup_memory_available_skips_without_snapshot(
monkeypatch, limit, usage
):
monkeypatch.setattr(cru, "get_cgroup_memory_limit", lambda: limit)
monkeypatch.setattr(cru, "get_cgroup_memory_usage", lambda: usage)
with (
mock.patch.object(cru.logger, "debug") as log_debug,
mock.patch.object(cru.logger, "warning") as log_warning,
):
cru.check_cgroup_memory_available(1 << 60, "mmap")
log_debug.assert_not_called()
log_warning.assert_not_called()
-298
View File
@@ -1,298 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import socket
import threading
import pytest
import zmq
from vllm.utils import network_utils
from vllm.utils.network_utils import (
get_file_store_init_method,
get_open_port,
get_open_ports_list,
get_tcp_uri,
join_host_port,
make_zmq_listener,
make_zmq_path,
make_zmq_socket,
split_host_port,
split_zmq_path,
)
def test_get_file_store_init_method_is_unique():
init_methods = {get_file_store_init_method() for _ in range(2)}
assert len(init_methods) == 2
assert all(method.startswith("file://") for method in init_methods)
def _call_with_timeout(func, timeout: float = 10.0):
"""Run func in a daemon thread so a livelock regression fails the test
quickly instead of hanging the suite."""
result: dict = {}
def target():
try:
result["value"] = func()
except BaseException as e:
result["error"] = e
thread = threading.Thread(target=target, daemon=True)
thread.start()
thread.join(timeout)
assert not thread.is_alive(), f"call did not finish within {timeout}s"
if "error" in result:
raise result["error"]
return result["value"]
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()))
def test_get_open_port_vllm_port_in_dp_reserved_range(
monkeypatch: pytest.MonkeyPatch,
):
# VLLM_PORT falling inside the data-parallel reserved window used to make
# get_open_port() loop forever (issue #50024). It must instead return a
# port outside the reserved range.
with monkeypatch.context() as m:
m.setenv("VLLM_DP_MASTER_PORT", "5680")
# 5682 is inside [5680, 5690).
m.setenv("VLLM_PORT", "5682")
port = _call_with_timeout(get_open_port)
assert port not in range(5680, 5690)
def test_get_open_ports_list_with_vllm_port(monkeypatch: pytest.MonkeyPatch):
with monkeypatch.context() as m:
m.setenv("VLLM_PORT", "5678")
ports = get_open_ports_list(5)
assert len(ports) == 5
assert len(set(ports)) == 5, "ports must be unique"
# verify every port is actually bindable
sockets = []
try:
for p in ports:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", p))
sockets.append(s)
finally:
for s in sockets:
s.close()
def test_get_open_port_skips_reserved_dp_master_ports(
monkeypatch: pytest.MonkeyPatch,
):
"""VLLM_PORT == VLLM_DP_MASTER_PORT must not livelock by returning the
same free-but-reserved port forever (upstream issue #50024)."""
base = 42123
with monkeypatch.context() as m:
m.setenv("VLLM_PORT", str(base))
m.setenv("VLLM_DP_MASTER_PORT", str(base))
port = _call_with_timeout(get_open_port)
assert port >= base + 10
def test_get_open_ports_list_skips_reserved_dp_master_ports(
monkeypatch: pytest.MonkeyPatch,
):
"""The VLLM_PORT band scan must not hand out ports inside the window
reserved for the data parallel master process."""
base = 42223
reserved = range(base, base + 10)
with monkeypatch.context() as m:
m.setenv("VLLM_PORT", str(base))
m.setenv("VLLM_DP_MASTER_PORT", str(base))
ports = _call_with_timeout(lambda: get_open_ports_list(5))
assert len(ports) == 5
assert len(set(ports)) == 5, "ports must be unique"
assert all(p not in reserved for p in ports)
def test_get_open_port_ephemeral_skips_reserved_range(
monkeypatch: pytest.MonkeyPatch,
):
"""An ephemeral port that happens to fall in the reserved range is
replaced by a rescan starting past the range."""
base = 42323
with monkeypatch.context() as m:
m.delenv("VLLM_PORT", raising=False)
m.setenv("VLLM_DP_MASTER_PORT", str(base))
m.setattr(
network_utils,
"_get_open_port",
lambda start_port=None, max_attempts=None: (
base if start_port is None else start_port
),
)
assert _call_with_timeout(get_open_port) == base + 10
def test_get_open_port_ephemeral_without_dp_master_port(
monkeypatch: pytest.MonkeyPatch,
):
"""Without VLLM_PORT and VLLM_DP_MASTER_PORT, an ephemeral port is
returned as before."""
with monkeypatch.context() as m:
m.delenv("VLLM_PORT", raising=False)
m.delenv("VLLM_DP_MASTER_PORT", raising=False)
port = _call_with_timeout(get_open_port)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("localhost", 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()
@pytest.mark.parametrize("scheme", ["tcp", "ipc"])
def test_make_zmq_socket_adopts_listener(tmp_path, scheme):
path = (
"tcp://127.0.0.1:0" if scheme == "tcp" else f"ipc://{tmp_path}/inherited.sock"
)
listener = make_zmq_listener(path, zmq.ROUTER)
ctx = zmq.Context()
router = dealer = None
try:
router = make_zmq_socket(
ctx,
listener.address,
zmq.ROUTER,
bind=True,
listener=listener.socket,
)
assert listener.socket.fileno() == -1
dealer = make_zmq_socket(
ctx, listener.address, zmq.DEALER, bind=False, identity=b"client"
)
dealer.send(b"ping")
assert router.recv_multipart() == [b"client", b"ping"]
finally:
if router is not None:
router.close(linger=0)
if dealer is not None:
dealer.close(linger=0)
ctx.term()
listener.cleanup()
def test_make_zmq_listener_failed_ipc_bind_keeps_existing_path(tmp_path):
path = tmp_path / "taken.sock"
owner = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
owner.bind(str(path))
owner.listen()
try:
with pytest.raises(OSError, match="Address already in use"):
make_zmq_listener(f"ipc://{path}", zmq.ROUTER)
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
client.connect(str(path))
finally:
owner.close()
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"
-595
View File
@@ -1,595 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import os
from functools import partial
from types import SimpleNamespace
import pytest
from vllm.config import ParallelConfig
from vllm.utils import numa_utils
@pytest.fixture(autouse=True)
def _disable_pct_by_default(monkeypatch):
"""Force PCT detection OFF unless a test opts in via ``_patch_pct_gates``.
The CI / dev machines themselves can be Xeon 6776P with PCT enabled, so a
plain ``cache_clear`` would let the gate auto-detect ``True`` from the
live filesystem and silently re-route "baseline" tests through the PCT
path. Stub ``/proc/cpuinfo`` and ``acpi_cppc/highest_perf`` to a state
that fails the gate; ``_patch_pct_gates`` re-stubs on top when needed.
"""
from io import StringIO
real_open = open
def _no_pct_open(path, *args, **kwargs):
if path == numa_utils._PROC_CPUINFO_PATH:
return StringIO("processor\t: 0\nmodel name\t: Generic Test CPU\n")
if path == numa_utils._PCT_HIGHEST_PERF_PATH:
raise OSError("PCT disabled by autouse fixture")
return real_open(path, *args, **kwargs)
monkeypatch.setattr("builtins.open", _no_pct_open)
numa_utils._pct_sku_config.cache_clear()
yield
numa_utils._pct_sku_config.cache_clear()
def _make_config(**parallel_kwargs):
parallel_defaults = dict(
numa_bind=False,
numa_bind_nodes=None,
numa_bind_cpus=None,
distributed_executor_backend="mp",
data_parallel_backend="mp",
nnodes_within_dp=1,
data_parallel_rank_local=0,
data_parallel_index=0,
pipeline_parallel_size=1,
tensor_parallel_size=1,
prefill_context_parallel_size=1,
)
parallel_defaults.update(parallel_kwargs)
parallel_config = SimpleNamespace(**parallel_defaults)
parallel_config.world_size = (
parallel_config.tensor_parallel_size
* parallel_config.prefill_context_parallel_size
* parallel_config.pipeline_parallel_size
)
parallel_config.get_local_gpu_index = partial(
ParallelConfig.get_local_gpu_index, parallel_config
)
return SimpleNamespace(parallel_config=parallel_config)
def test_get_numactl_args_with_node_binding():
vllm_config = _make_config(numa_bind=True, numa_bind_nodes=[0, 1])
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--cpunodebind=1 --membind=1"
)
def test_get_numactl_args_with_cpu_binding():
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 1],
numa_bind_cpus=["0-3", "4-7"],
)
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--physcpubind=4-7 --membind=1"
)
def _patch_pct_gates(
monkeypatch,
*,
model_match: bool,
highest_perf: int | None,
cpulist: str | None = "0-31,64-95",
cpulist_by_node: dict[int, str | None] | None = None,
sku: str = "6776P",
):
"""Force `_pct_sku_config` and node cpulist read to deterministic state.
``cpulist`` is the default returned for any node not present in
``cpulist_by_node``. ``cpulist_by_node`` lets a test return different
cpulists for different NUMA nodes (e.g. node 0 vs node 1). ``sku`` lets
the test pick which Granite Rapids SKU appears in the fake
``/proc/cpuinfo`` ``model name`` (only used when ``model_match=True``).
"""
import pathlib
from io import StringIO
import regex as re
cpuinfo = (
f"processor\t: 0\nmodel name\t: Intel(R) Xeon(R) Platinum {sku} CPU @ 2.40GHz\n"
if model_match
else "processor\t: 0\nmodel name\t: Intel(R) Xeon(R) Platinum 8480+\n"
)
real_open = open
def fake_open(path, *args, **kwargs):
if path == numa_utils._PROC_CPUINFO_PATH:
return StringIO(cpuinfo)
if path == numa_utils._PCT_HIGHEST_PERF_PATH:
if highest_perf is None:
raise OSError("missing")
return StringIO(f"{highest_perf}\n")
return real_open(path, *args, **kwargs)
real_read_text = pathlib.Path.read_text
cpulist_by_node = cpulist_by_node or {}
def fake_read_text(self, *args, **kwargs):
path_str = str(self)
if path_str.endswith("/cpulist") and "/sys/devices/system/node" in path_str:
match = re.search(r"/node(\d+)/cpulist$", path_str)
if match:
node_id = int(match.group(1))
if node_id in cpulist_by_node:
val = cpulist_by_node[node_id]
if val is None:
raise OSError(f"missing cpulist for node{node_id}")
return val
if cpulist is None:
raise OSError("missing cpulist")
return cpulist
return real_read_text(self, *args, **kwargs)
monkeypatch.setattr("builtins.open", fake_open)
monkeypatch.setattr("pathlib.Path.read_text", fake_read_text)
numa_utils._pct_sku_config.cache_clear()
def test_pct_binding_filters_cpus(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46)
assert numa_utils._maybe_get_pct_cpu_binding([0]) == [0, 1, 16, 17, 64, 65, 80, 81]
@pytest.mark.parametrize(
"sku,expected_cpus",
[
# 64-core SKUs (stride 16): cpus from "0-31,64-95" with cpu_id % 16
# in (0, 1) -> 0, 1, 16, 17, 64, 65, 80, 81.
("6776P", [0, 1, 16, 17, 64, 65, 80, 81]),
("6774P", [0, 1, 16, 17, 64, 65, 80, 81]),
# 72-core SKU (stride 18): cpus from "0-31,64-95" with cpu_id % 18
# in (0, 1) -> 0, 1, 18, 19, 72, 73, 90, 91.
("6962P", [0, 1, 18, 19, 72, 73, 90, 91]),
],
)
def test_pct_binding_fires_on_every_capable_sku(monkeypatch, sku, expected_cpus):
"""Each SKU in ``_PCT_CAPABLE_SKUS`` engages the gate at its own
expected ``highest_perf`` and uses its own priority-core stride."""
sku_config = numa_utils._PCT_CAPABLE_SKUS[sku]
_patch_pct_gates(
monkeypatch,
model_match=True,
highest_perf=sku_config.highest_perf,
sku=sku,
)
assert numa_utils._maybe_get_pct_cpu_binding([0]) == expected_cpus
def test_pct_binding_fails_closed_when_sku_perf_mismatch(monkeypatch):
"""6962P with 6776P's highest_perf (46 vs expected 44) must fail closed."""
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46, sku="6962P")
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_pct_binding_disabled_when_cpu_model_mismatch(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=False, highest_perf=46)
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_pct_binding_disabled_when_highest_perf_does_not_match(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=42)
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_pct_binding_disabled_when_files_missing(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=None)
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_pct_binding_returns_none_when_node_cpulist_filter_empty(monkeypatch):
_patch_pct_gates(
monkeypatch,
model_match=True,
highest_perf=46,
cpulist="2-15,18-31",
)
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_pct_binding_returns_none_when_node_cpulist_missing(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46, cpulist=None)
assert numa_utils._maybe_get_pct_cpu_binding([0]) is None
def test_get_numactl_args_uses_pct_when_user_did_not_specify_cpus(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46)
vllm_config = _make_config(numa_bind=True, numa_bind_nodes=[0, 1])
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--physcpubind=0,1,16,17,64,65,80,81 --membind=1"
)
def test_get_numactl_args_engine_core_baseline_single_node_shard():
"""Baseline (no PCT): single-NUMA shard -> single-node bind."""
vllm_config = _make_config(numa_bind=True, numa_bind_nodes=[0, 1])
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== "--cpunodebind=0 --membind=0"
)
def test_get_numactl_args_engine_core_baseline_spans_shard_numa_nodes():
"""Baseline (no PCT): a TP=4 shard spanning both NUMA nodes -> bind to both."""
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 1, 1],
tensor_parallel_size=4,
)
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== "--cpunodebind=0,1 --membind=0,1"
)
def test_get_numactl_args_engine_core_pct_spans_shard_numa_nodes(monkeypatch):
"""PCT: EngineCore for a multi-NUMA shard binds to the union of priority
cores across all shard nodes, so worker `--physcpubind` is always a
subset of EngineCore's `cpus_allowed`."""
_patch_pct_gates(
monkeypatch,
model_match=True,
highest_perf=46,
cpulist_by_node={0: "0-31,128-159", 1: "64-95,192-223"},
)
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 1, 1],
tensor_parallel_size=4,
)
assert numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
) == (
"--physcpubind="
"0,1,16,17,64,65,80,81,128,129,144,145,192,193,208,209"
" --membind=0,1"
)
def test_get_numactl_args_engine_core_pct_dp_shard_picks_local_nodes(monkeypatch):
"""With DP=2, each shard's EngineCore binds only to its own NUMA nodes."""
_patch_pct_gates(
monkeypatch,
model_match=True,
highest_perf=46,
cpulist_by_node={0: "0-31,128-159", 1: "64-95,192-223"},
)
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 1, 1],
tensor_parallel_size=2,
data_parallel_rank_local=1,
)
# Shard 1 owns gpu_indices 2 and 3 -> nodes [1, 1] -> {1}.
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== "--physcpubind=64,65,80,81,192,193,208,209 --membind=1"
)
def test_get_numactl_args_engine_core_pct_external_launcher_spans_local_nodes(
monkeypatch,
):
"""external_launcher (or multi-node-within-DP, or Ray) hits the
fallback branch. EngineCore must still span every local NUMA node
so it can mp-spawn its local workers without ``--physcpubind``
strict-validation failures."""
_patch_pct_gates(
monkeypatch,
model_match=True,
highest_perf=46,
cpulist_by_node={0: "0-31,128-159", 1: "64-95,192-223"},
)
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 0, 0, 1, 1, 1, 1],
distributed_executor_backend="external_launcher",
tensor_parallel_size=8,
)
assert numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
) == (
"--physcpubind="
"0,1,16,17,64,65,80,81,128,129,144,145,192,193,208,209"
" --membind=0,1"
)
def test_get_numactl_args_engine_core_baseline_multi_node_within_dp_spans_locals():
"""Multi-node-within-DP fallback: bind EngineCore to all local NUMA
nodes that the visible ``numa_bind_nodes`` reference."""
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 0, 0, 1, 1, 1, 1],
nnodes_within_dp=2,
tensor_parallel_size=8,
)
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== "--cpunodebind=0,1 --membind=0,1"
)
def test_get_numactl_args_engine_core_skips_user_cpu_list(monkeypatch):
"""EngineCore ignores ``--numa-bind-cpus``.
Those are per-worker lists; binding EngineCore to any of them would
shrink its ``cpus_allowed`` below the strict-superset workers'
``--physcpubind`` spawns need. We fall back to ``--cpunodebind`` over
the shard's NUMA nodes instead. PCT auto-detect is also bypassed when
the user is explicit (its priority-core union may not be a superset
of the user's per-worker cores)."""
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46)
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 1, 1],
numa_bind_cpus=["0-3", "4-7", "64-67", "68-71"],
tensor_parallel_size=4,
)
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== "--cpunodebind=0,1 --membind=0,1"
)
def test_get_numactl_args_user_cpus_override_pct(monkeypatch):
_patch_pct_gates(monkeypatch, model_match=True, highest_perf=46)
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 1],
numa_bind_cpus=["0-3", "4-7"],
)
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--physcpubind=4-7 --membind=1"
)
@pytest.mark.parametrize("pcp,pp", [(1, 1), (2, 1), (2, 2)])
def test_get_numactl_args_uses_dp_offset(pcp, pp):
workers_per_dp = 2 * pcp * pp
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0] * workers_per_dp + [1] * workers_per_dp,
data_parallel_rank_local=1,
pipeline_parallel_size=pp,
tensor_parallel_size=2,
prefill_context_parallel_size=pcp,
)
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--cpunodebind=1 --membind=1"
)
@pytest.mark.parametrize(
"local_dp_rank,global_dp_rank,launch_dp_rank",
[(1, 3, None), (None, 1, None), (0, 0, 1)],
ids=["local-rank", "global-fallback", "launch-override"],
)
def test_pcp_worker_cpu_binding_uses_dp_gpu_index(
local_dp_rank, global_dp_rank, launch_dp_rank
):
"""CPU overrides use the same PCP-aware GPU index as device selection."""
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0] * 4 + [1] * 4,
numa_bind_cpus=[f"{4 * i}-{4 * i + 3}" for i in range(8)],
tensor_parallel_size=2,
prefill_context_parallel_size=2,
data_parallel_rank_local=local_dp_rank,
data_parallel_index=global_dp_rank,
)
assert (
numa_utils._get_numactl_worker_args(
vllm_config.parallel_config, local_rank=1, dp_local_rank=launch_dp_rank
)
== "--physcpubind=20-23 --membind=1"
)
@pytest.mark.parametrize("dp_rank,expected_nodes", [(0, "0,1"), (1, "2,3")])
def test_pcp_engine_core_covers_all_shard_workers(dp_rank, expected_nodes):
"""EngineCore includes every PCP worker's NUMA node in its DP shard."""
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 0, 1, 1, 2, 2, 3, 3],
tensor_parallel_size=2,
prefill_context_parallel_size=2,
data_parallel_rank_local=dp_rank,
)
assert (
numa_utils._get_numactl_enginecore_args(
vllm_config.parallel_config, local_rank=0
)
== f"--cpunodebind={expected_nodes} --membind={expected_nodes}"
)
@pytest.mark.parametrize(
"parallel_kwargs",
[
{"distributed_executor_backend": "ray"},
{"distributed_executor_backend": "external_launcher"},
{"data_parallel_backend": "ray"},
{"nnodes_within_dp": 2},
],
ids=["ray-executor", "external-launcher", "ray-dp", "multi-node-dp"],
)
def test_pcp_worker_keeps_local_gpu_index_without_dp_offset(parallel_kwargs):
"""Node-local launcher ranks do not acquire a colocated DP offset."""
vllm_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0, 1],
tensor_parallel_size=2,
prefill_context_parallel_size=2,
data_parallel_rank_local=1,
**parallel_kwargs,
)
assert (
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=1)
== "--cpunodebind=1 --membind=1"
)
def test_get_numactl_args_requires_detectable_nodes(monkeypatch):
vllm_config = _make_config(numa_bind=True)
monkeypatch.setattr(numa_utils, "get_auto_numa_nodes", lambda: None)
with pytest.raises(RuntimeError):
numa_utils._get_numactl_worker_args(vllm_config.parallel_config, local_rank=0)
def test_configure_subprocess_rejects_unknown_process_kind():
"""configure_subprocess only knows 'worker' and 'EngineCore'; anything
else must raise ValueError instead of silently routing to the worker
path."""
vllm_config = _make_config(numa_bind=True, numa_bind_nodes=[0])
with (
pytest.raises(ValueError, match="process_kind"),
numa_utils.configure_subprocess(
vllm_config, local_rank=0, process_kind="bogus"
),
):
pass
def test_log_numactl_show(monkeypatch):
log_lines = []
def fake_debug(msg, *args):
log_lines.append(msg % args)
monkeypatch.setattr(numa_utils.logger, "debug", fake_debug)
monkeypatch.setattr(
numa_utils.subprocess,
"run",
lambda *args, **kwargs: SimpleNamespace(
stdout="policy: bind\nphyscpubind: 0 1 2 3\n", returncode=0
),
)
assert numa_utils._log_numactl_show("Worker_0") is True
assert log_lines == [
"Worker_0 affinity: policy: bind, physcpubind: 0 1 2 3",
]
def test_get_numactl_executable_points_to_fixed_wrapper(monkeypatch):
monkeypatch.setattr("shutil.which", lambda name: "/usr/bin/numactl")
executable, debug_str = numa_utils._get_numactl_executable()
assert executable.endswith("/vllm/utils/numa_wrapper.sh")
assert "_VLLM_INTERNAL_NUMACTL_ARGS" in debug_str
def test_set_numa_wrapper_env_restores_previous_values():
os.environ[numa_utils._NUMACTL_ARGS_ENV] = "old-args"
os.environ[numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV] = "old-python"
with numa_utils._set_numa_wrapper_env("new-args", "new-python"):
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "new-args"
assert os.environ[numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV] == "new-python"
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "old-args"
assert os.environ[numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV] == "old-python"
def test_set_numa_wrapper_env_clears_values_when_unset():
os.environ.pop(numa_utils._NUMACTL_ARGS_ENV, None)
os.environ.pop(numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV, None)
with numa_utils._set_numa_wrapper_env("new-args", "new-python"):
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "new-args"
assert os.environ[numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV] == "new-python"
assert numa_utils._NUMACTL_ARGS_ENV not in os.environ
assert numa_utils._NUMACTL_PYTHON_EXECUTABLE_ENV not in os.environ
def test_parallel_config_validates_numa_bind_nodes():
with pytest.raises(ValueError, match="non-negative"):
ParallelConfig(numa_bind_nodes=[0, -1])
@pytest.mark.parametrize("cpuset", ["", "abc", "1-", "4-1", "1,,2", "1:2"])
def test_parallel_config_rejects_invalid_numa_bind_cpus(cpuset):
with pytest.raises(ValueError, match="numa_bind_cpus"):
ParallelConfig(numa_bind_cpus=[cpuset])
def _fake_numactl_run(rejected_args):
"""Fake ``numactl`` that fails when any of ``rejected_args`` is present."""
def run(cmd, *args, **kwargs):
arg_str = " ".join(cmd[1:-1])
ok = not any(bad in arg_str for bad in rejected_args)
return SimpleNamespace(returncode=0 if ok else 1)
return run
def test_configure_subprocess_numa_fallback(monkeypatch):
import multiprocessing
monkeypatch.setattr("shutil.which", lambda name: "/usr/bin/numactl")
monkeypatch.setattr(numa_utils.envs, "VLLM_WORKER_MULTIPROC_METHOD", "spawn")
node_config = _make_config(numa_bind=True, numa_bind_nodes=[0])
monkeypatch.setattr(numa_utils.subprocess, "run", _fake_numactl_run([]))
with numa_utils.configure_subprocess(node_config, local_rank=0):
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "--cpunodebind=0 --membind=0"
membind_fails = _fake_numactl_run(["--membind="])
monkeypatch.setattr(numa_utils.subprocess, "run", membind_fails)
with numa_utils.configure_subprocess(node_config, local_rank=0):
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "--cpunodebind=0"
cpu_config = _make_config(
numa_bind=True,
numa_bind_nodes=[0],
numa_bind_cpus=["0-3"],
)
with numa_utils.configure_subprocess(cpu_config, local_rank=0):
assert os.environ[numa_utils._NUMACTL_ARGS_ENV] == "--physcpubind=0-3"
before = multiprocessing.spawn.get_executable()
monkeypatch.setattr(
numa_utils.subprocess,
"run",
_fake_numactl_run(["--cpunodebind=", "--membind="]),
)
with numa_utils.configure_subprocess(node_config, local_rank=0):
assert multiprocessing.spawn.get_executable() == before
assert numa_utils._NUMACTL_ARGS_ENV not in os.environ
-80
View File
@@ -1,80 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import contextlib
import io
import os
import signal
import subprocess
import sys
import tempfile
from pathlib import Path
import psutil
from vllm.utils import system_utils
from vllm.utils.system_utils import (
_maybe_force_spawn,
suppress_stdout,
unique_filepath,
)
def test_unique_filepath():
temp_dir = tempfile.mkdtemp()
path_fn = lambda i: Path(temp_dir) / f"file_{i}.txt"
paths = set()
for i in range(10):
path = unique_filepath(path_fn)
path.write_text("test")
paths.add(path)
assert len(paths) == 10
assert len(list(Path(temp_dir).glob("*.txt"))) == 10
def test_numa_bind_forces_spawn(monkeypatch):
monkeypatch.delenv("VLLM_WORKER_MULTIPROC_METHOD", raising=False)
monkeypatch.setattr("sys.argv", ["vllm", "serve", "--numa-bind"])
_maybe_force_spawn()
assert os.environ["VLLM_WORKER_MULTIPROC_METHOD"] == "spawn"
def test_suppress_stdout_when_sys_stdout_has_no_fd(capfd):
with contextlib.redirect_stdout(io.StringIO()), suppress_stdout():
os.write(1, b"c library output\n")
assert "c library output" not in capfd.readouterr().out
def test_suppress_stdout_keeps_stderr_when_sys_stdout_is_stderr(capfd, monkeypatch):
monkeypatch.setattr(sys, "stdout", sys.stderr)
with suppress_stdout():
os.write(1, b"c library output\n")
os.write(sys.stderr.fileno(), b"error message\n")
out, err = capfd.readouterr()
assert "c library output" not in out
assert "error message" in err
def test_kill_process_tree_skips_child_that_exits_mid_walk(monkeypatch):
sleep = [sys.executable, "-c", "import time; time.sleep(60)"]
target, *children = procs = [subprocess.Popen(sleep) for _ in range(4)]
try:
# List the children while they are alive, then let one exit and be
# reaped before the walk reaches it, so psutil's name() raises.
listed = [psutil.Process(p.pid) for p in children]
children[1].terminate()
children[1].wait(timeout=10)
monkeypatch.setattr(
psutil.Process, "children", lambda self, recursive=False: listed
)
system_utils.kill_process_tree(target.pid)
# The exited child died from our SIGTERM; the rest were SIGKILLed.
assert children[1].returncode == -signal.SIGTERM
for p in (children[0], children[2], target):
assert p.wait(timeout=10) == -signal.SIGKILL
finally:
for p in procs:
p.kill()
p.wait()