2024-07-19 11:55:13 +08:00
|
|
|
from http import HTTPStatus
|
2024-10-08 18:38:40 +02:00
|
|
|
from typing import List
|
2024-07-19 11:55:13 +08:00
|
|
|
|
|
|
|
import pytest
|
2024-08-26 21:33:17 -07:00
|
|
|
import pytest_asyncio
|
2024-07-19 11:55:13 +08:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from vllm.version import __version__ as VLLM_VERSION
|
|
|
|
|
|
|
|
from ...utils import RemoteOpenAIServer
|
|
|
|
|
|
|
|
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
|
|
|
|
|
|
|
|
|
2024-10-08 18:38:40 +02:00
|
|
|
@pytest.fixture(scope='module')
|
|
|
|
def server_args(request: pytest.FixtureRequest) -> List[str]:
|
|
|
|
""" Provide extra arguments to the server via indirect parametrization
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
>>> @pytest.mark.parametrize(
|
|
|
|
>>> "server_args",
|
|
|
|
>>> [
|
|
|
|
>>> ["--disable-frontend-multiprocessing"],
|
|
|
|
>>> [
|
|
|
|
>>> "--model=NousResearch/Hermes-3-Llama-3.1-70B",
|
|
|
|
>>> "--enable-auto-tool-choice",
|
|
|
|
>>> ],
|
|
|
|
>>> ],
|
|
|
|
>>> indirect=True,
|
|
|
|
>>> )
|
|
|
|
>>> def test_foo(server, client):
|
|
|
|
>>> ...
|
|
|
|
|
|
|
|
This will run `test_foo` twice with servers with:
|
|
|
|
- `--disable-frontend-multiprocessing`
|
|
|
|
- `--model=NousResearch/Hermes-3-Llama-3.1-70B --enable-auto-tool-choice`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not hasattr(request, "param"):
|
|
|
|
return []
|
|
|
|
|
|
|
|
val = request.param
|
|
|
|
|
|
|
|
if isinstance(val, str):
|
|
|
|
return [val]
|
|
|
|
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2024-07-19 11:55:13 +08:00
|
|
|
@pytest.fixture(scope="module")
|
2024-10-08 18:38:40 +02:00
|
|
|
def server(server_args):
|
2024-07-19 11:55:13 +08:00
|
|
|
args = [
|
|
|
|
# use half precision for speed and memory savings in CI environment
|
|
|
|
"--dtype",
|
|
|
|
"bfloat16",
|
|
|
|
"--max-model-len",
|
|
|
|
"8192",
|
|
|
|
"--enforce-eager",
|
|
|
|
"--max-num-seqs",
|
|
|
|
"128",
|
2024-10-08 18:38:40 +02:00
|
|
|
*server_args,
|
2024-07-19 11:55:13 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
|
|
|
|
yield remote_server
|
|
|
|
|
|
|
|
|
2024-08-26 21:33:17 -07:00
|
|
|
@pytest_asyncio.fixture
|
|
|
|
async def client(server):
|
|
|
|
async with server.get_async_client() as async_client:
|
|
|
|
yield async_client
|
2024-07-19 11:55:13 +08:00
|
|
|
|
|
|
|
|
2024-10-08 18:38:40 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"server_args",
|
|
|
|
[
|
|
|
|
pytest.param([], id="default-frontend-multiprocessing"),
|
|
|
|
pytest.param(["--disable-frontend-multiprocessing"],
|
|
|
|
id="disable-frontend-multiprocessing")
|
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2024-07-19 11:55:13 +08:00
|
|
|
@pytest.mark.asyncio
|
2024-11-01 16:13:35 +08:00
|
|
|
async def test_show_version(server: RemoteOpenAIServer):
|
|
|
|
response = requests.get(server.url_for("version"))
|
2024-07-19 11:55:13 +08:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
assert response.json() == {"version": VLLM_VERSION}
|
|
|
|
|
|
|
|
|
2024-10-08 18:38:40 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"server_args",
|
|
|
|
[
|
|
|
|
pytest.param([], id="default-frontend-multiprocessing"),
|
|
|
|
pytest.param(["--disable-frontend-multiprocessing"],
|
|
|
|
id="disable-frontend-multiprocessing")
|
|
|
|
],
|
|
|
|
indirect=True,
|
|
|
|
)
|
2024-07-19 11:55:13 +08:00
|
|
|
@pytest.mark.asyncio
|
2024-11-01 16:13:35 +08:00
|
|
|
async def test_check_health(server: RemoteOpenAIServer):
|
|
|
|
response = requests.get(server.url_for("health"))
|
2024-07-19 11:55:13 +08:00
|
|
|
|
|
|
|
assert response.status_code == HTTPStatus.OK
|