"vllm/vscode:/vscode.git/clone" did not exist on "cc6a001704ab20d6b90f981462b9c65fd354ea6a"
test_config_generation.py 3.53 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest

from vllm.engine.arg_utils import EngineArgs
from vllm.model_executor.layers.quantization.quark.utils import deep_compare


def test_cuda_empty_vs_unset_configs(monkeypatch: pytest.MonkeyPatch):
    """Test that configs created with normal (untouched) CUDA_VISIBLE_DEVICES
    and CUDA_VISIBLE_DEVICES="" are equivalent. This ensures consistent
    behavior regardless of whether GPU visibility is disabled via empty string
    or left in its normal state.
    """

    def create_config():
17
18
19
        engine_args = EngineArgs(
            model="deepseek-ai/DeepSeek-V2-Lite", trust_remote_code=True
        )
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        return engine_args.create_engine_config()

    # Create config with CUDA_VISIBLE_DEVICES set normally
    normal_config = create_config()

    # Create config with CUDA_VISIBLE_DEVICES=""
    with monkeypatch.context() as m:
        m.setenv("CUDA_VISIBLE_DEVICES", "")
        empty_config = create_config()

    normal_config_dict = vars(normal_config)
    empty_config_dict = vars(empty_config)

    # Remove instance_id before comparison as it's expected to be different
    normal_config_dict.pop("instance_id", None)
    empty_config_dict.pop("instance_id", None)

    assert deep_compare(normal_config_dict, empty_config_dict), (
38
39
40
        'Configs with normal CUDA_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES=""'
        " should be equivalent"
    )
41
42
43
44
45
46


def test_ray_runtime_env(monkeypatch: pytest.MonkeyPatch):
    # In testing, this method needs to be nested inside as ray does not
    # see the test module.
    def create_config():
47
48
49
        engine_args = EngineArgs(
            model="deepseek-ai/DeepSeek-V2-Lite", trust_remote_code=True
        )
50
51
52
53
54
55
56
        return engine_args.create_engine_config()

    config = create_config()
    parallel_config = config.parallel_config
    assert parallel_config.ray_runtime_env is None

    import ray
57

58
59
60
61
62
    ray.init()

    runtime_env = {
        "env_vars": {
            "TEST_ENV_VAR": "test_value",
63
64
65
66
67
            # In future ray versions, this will be default, so when setting a
            # task or actor with num_gpus=None/0, the visible devices env var
            # won't be overridden resulting in no GPUs being visible on a gpu
            # machine.
            "RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO": "0",
68
69
70
        },
    }

71
    config_ref = ray.remote(create_config).options(runtime_env=runtime_env).remote()
72
73
74
75

    config = ray.get(config_ref)
    parallel_config = config.parallel_config
    assert parallel_config.ray_runtime_env is not None
76
77
78
    assert (
        parallel_config.ray_runtime_env.env_vars().get("TEST_ENV_VAR") == "test_value"
    )
79
80

    ray.shutdown()
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104


def test_unrecognized_env():
    import os

    # Test that if fail_on_environ_validation is True, then an error
    # is raised when an unrecognized vLLM environment variable is set
    os.environ["VLLM_UNRECOGNIZED_ENV_VAR"] = "some_value"
    engine_args = EngineArgs(
        fail_on_environ_validation=True,
    )
    with pytest.raises(ValueError, match="Unknown vLLM environment variable detected"):
        engine_args.create_engine_config()

    # Test that if fail_on_environ_validation is False, then no error is raised
    engine_args = EngineArgs()
    engine_args.create_engine_config()

    # Test that when the unrecognized env var is removed, no error is raised
    os.environ.pop("VLLM_UNRECOGNIZED_ENV_VAR", None)
    engine_args = EngineArgs(
        fail_on_environ_validation=True,
    )
    engine_args.create_engine_config()