test_platform_plugins.py 1.25 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
import pytest
5
6
7
import torch

from vllm.attention.selector import get_attn_backend
8
from vllm.utils import STR_BACKEND_ENV_VAR, STR_INVALID_VAL
9
10


11
12
13
14
15
16
17
def test_platform_plugins():
    # simulate workload by running an example
    import runpy
    current_file = __file__
    import os
    example_file = os.path.join(
        os.path.dirname(os.path.dirname(os.path.dirname(current_file))),
18
        "examples", "offline_inference/basic/basic.py")
19
20
21
22
23
24
25
26
    runpy.run_path(example_file)

    # check if the plugin is loaded correctly
    from vllm.platforms import _init_trace, current_platform
    assert current_platform.device_name == "DummyDevice", (
        f"Expected DummyDevice, got {current_platform.device_name}, "
        "possibly because current_platform is imported before the plugin"
        f" is loaded. The first import:\n{_init_trace}")
27
28


29
def test_oot_attention_backend(monkeypatch: pytest.MonkeyPatch):
30
    # ignore the backend env variable if it is set
31
32
    with monkeypatch.context() as m:
        m.setenv(STR_BACKEND_ENV_VAR, STR_INVALID_VAL)
33
        backend = get_attn_backend(16, torch.float16, "auto", 16, False)
34
        assert backend.get_name() == "Dummy_Backend"