|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from vllm.utils import cpu_resource_utils as cr_utils |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(autouse=True) |
| 10 | +def _clear_cpu_memory_envs(monkeypatch: pytest.MonkeyPatch) -> None: |
| 11 | + monkeypatch.delenv(cr_utils.DEVICE_CONTROL_ENV_VAR, raising=False) |
| 12 | + monkeypatch.delenv("VLLM_CPU_SIM_MULTI_NUMA", raising=False) |
| 13 | + |
| 14 | + |
| 15 | +def _stub_linux_memory_affinity(monkeypatch: pytest.MonkeyPatch) -> None: |
| 16 | + monkeypatch.setattr(cr_utils.sys, "platform", "linux") |
| 17 | + monkeypatch.setattr(cr_utils, "get_memory_affinity", lambda: [0, 1, 2, 3]) |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.parametrize("sim_multi_numa", [None, "0"]) |
| 21 | +def test_get_visible_memory_node_uses_visible_nodes_when_not_simulating( |
| 22 | + monkeypatch: pytest.MonkeyPatch, sim_multi_numa: str | None |
| 23 | +) -> None: |
| 24 | + _stub_linux_memory_affinity(monkeypatch) |
| 25 | + monkeypatch.setenv(cr_utils.DEVICE_CONTROL_ENV_VAR, "1,3") |
| 26 | + if sim_multi_numa is not None: |
| 27 | + monkeypatch.setenv("VLLM_CPU_SIM_MULTI_NUMA", sim_multi_numa) |
| 28 | + |
| 29 | + assert cr_utils.get_visible_memory_node() == [1, 3] |
| 30 | + |
| 31 | + |
| 32 | +def test_get_visible_memory_node_ignores_visible_nodes_when_simulating( |
| 33 | + monkeypatch: pytest.MonkeyPatch, |
| 34 | +) -> None: |
| 35 | + _stub_linux_memory_affinity(monkeypatch) |
| 36 | + monkeypatch.setenv(cr_utils.DEVICE_CONTROL_ENV_VAR, "1,3") |
| 37 | + monkeypatch.setenv("VLLM_CPU_SIM_MULTI_NUMA", "1") |
| 38 | + |
| 39 | + assert cr_utils.get_visible_memory_node() == [0, 1, 2, 3] |
0 commit comments