| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | import pytest_asyncio |
| 6 | |
| 7 | from tests.utils import RemoteOpenAIServer |
| 8 | from vllm.platforms import current_platform |
| 9 | from vllm.transformers_utils.repo_utils import hf_api |
| 10 | |
| 11 | from .utils import ARGS, CONFIGS, ServerConfig |
| 12 | |
| 13 | |
| 14 | # select models to test based on command line arguments |
| 15 | def pytest_addoption(parser): |
| 16 | parser.addoption("--models", nargs="+", help="Specify one or more models to test") |
| 17 | parser.addoption( |
| 18 | "--extended", |
| 19 | action="store_true", |
| 20 | default=False, |
| 21 | help="invoke extended tests requiring large GPUs", |
| 22 | ) |
| 23 | |
| 24 | |
| 25 | # for each server config, download the model and return the config |
| 26 | @pytest.fixture(scope="session", params=CONFIGS.keys()) |
| 27 | def server_config(request): |
| 28 | extended = request.config.getoption("--extended") |
| 29 | models = request.config.getoption("--models") |
| 30 | |
| 31 | config_keys_to_test = [ |
| 32 | key |
| 33 | for key in CONFIGS |
| 34 | if (models is None or key in models) |
| 35 | and (extended or not CONFIGS[key].get("extended", False)) |
| 36 | ] |
| 37 | |
| 38 | config_key = request.param |
| 39 | if config_key not in config_keys_to_test: |
| 40 | pytest.skip(f"Skipping config '{config_key}'") |
| 41 | |
| 42 | config = CONFIGS[config_key] |
| 43 | |
| 44 | if current_platform.is_rocm() and not config.get("supports_rocm", True): |
| 45 | pytest.skip( |
| 46 | "The {} model can't be tested on the ROCm platform".format(config["model"]) |
| 47 | ) |
| 48 | |
| 49 | # download model and tokenizer using transformers |
| 50 | hf_api().snapshot_download(config["model"]) |
| 51 | yield CONFIGS[request.param] |
| 52 | |
| 53 | |
| 54 | # run this for each server config |
| 55 | @pytest.fixture(scope="session") |
| 56 | def server(request, server_config: ServerConfig): |
| 57 | model = server_config["model"] |
| 58 | args_for_model = server_config["arguments"] |
| 59 | with RemoteOpenAIServer( |
| 60 | model, ARGS + args_for_model, max_wait_seconds=480 |
| 61 | ) as server: |
| 62 | yield server |
| 63 | |
| 64 | |
| 65 | @pytest_asyncio.fixture |
| 66 | async def client(server: RemoteOpenAIServer): |
| 67 | async with server.get_async_client() as async_client: |
| 68 | yield async_client |