[Frontend] Add vllm launch command for GPU-less preprocessing serving (#34551)

Signed-off-by: HyunKyun Moon <mhg5303@gmail.com>
This commit is contained in:
Hyunkyun Moon
2026-03-04 18:41:52 +00:00
committed by GitHub
parent 32224f568a
commit bc6be89d16
10 changed files with 776 additions and 65 deletions
@@ -7,7 +7,7 @@ import httpx
import pytest
import pytest_asyncio
from ...utils import RemoteOpenAIServer
from tests.utils import RemoteOpenAIServer
MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM"
@@ -0,0 +1,199 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""E2E tests for render endpoints via `vllm launch` (GPU-less serving)."""
import httpx
import pytest
import pytest_asyncio
from ...utils import RemoteLaunchRenderServer
MODEL_NAME = "hmellor/tiny-random-LlamaForCausalLM"
@pytest.fixture(scope="module")
def server():
args: list[str] = []
with RemoteLaunchRenderServer(MODEL_NAME, args, max_wait_seconds=120) as srv:
yield srv
@pytest_asyncio.fixture
async def client(server):
async with httpx.AsyncClient(
base_url=server.url_for(""), timeout=30.0
) as http_client:
yield http_client
# -- Chat Completion Render --
@pytest.mark.asyncio
async def test_chat_render_basic(client):
response = await client.post(
"/v1/chat/completions/render",
json={
"model": MODEL_NAME,
"messages": [{"role": "user", "content": "Hello, how are you?"}],
},
)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) == 2
conversation, engine_prompts = data
assert isinstance(conversation, list)
assert conversation[0]["role"] == "user"
assert isinstance(engine_prompts, list)
assert len(engine_prompts) > 0
first_prompt = engine_prompts[0]
assert "prompt_token_ids" in first_prompt
assert "prompt" in first_prompt
assert isinstance(first_prompt["prompt_token_ids"], list)
assert all(isinstance(t, int) for t in first_prompt["prompt_token_ids"])
@pytest.mark.asyncio
async def test_chat_render_multi_turn(client):
response = await client.post(
"/v1/chat/completions/render",
json={
"model": MODEL_NAME,
"messages": [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi there!"},
{"role": "user", "content": "How are you?"},
],
},
)
assert response.status_code == 200
conversation, engine_prompts = response.json()
assert len(conversation) == 3
assert conversation[0]["role"] == "user"
assert conversation[1]["role"] == "assistant"
assert conversation[2]["role"] == "user"
assert len(engine_prompts) > 0
assert len(engine_prompts[0]["prompt_token_ids"]) > 0
@pytest.mark.asyncio
async def test_chat_render_invalid_model(client):
response = await client.post(
"/v1/chat/completions/render",
json={
"model": "nonexistent-model",
"messages": [{"role": "user", "content": "Hello"}],
},
)
assert response.status_code == 404
assert "error" in response.json()
# -- Completion Render --
@pytest.mark.asyncio
async def test_completion_render_basic(client):
response = await client.post(
"/v1/completions/render",
json={
"model": MODEL_NAME,
"prompt": "Once upon a time",
},
)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) > 0
first_prompt = data[0]
assert "prompt_token_ids" in first_prompt
assert "prompt" in first_prompt
assert isinstance(first_prompt["prompt_token_ids"], list)
assert len(first_prompt["prompt_token_ids"]) > 0
assert "Once upon a time" in first_prompt["prompt"]
@pytest.mark.asyncio
async def test_completion_render_multiple_prompts(client):
response = await client.post(
"/v1/completions/render",
json={
"model": MODEL_NAME,
"prompt": ["Hello world", "Goodbye world"],
},
)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) == 2
for prompt in data:
assert "prompt_token_ids" in prompt
assert "prompt" in prompt
assert len(prompt["prompt_token_ids"]) > 0
@pytest.mark.asyncio
async def test_completion_render_invalid_model(client):
response = await client.post(
"/v1/completions/render",
json={
"model": "nonexistent-model",
"prompt": "Hello",
},
)
assert response.status_code == 404
assert "error" in response.json()
@pytest.mark.asyncio
async def test_render_is_fast(client):
"""Render should complete quickly since there is no inference."""
import time
start = time.perf_counter()
response = await client.post(
"/v1/completions/render",
json={
"model": MODEL_NAME,
"prompt": "Tell me a very long story about " * 10,
},
)
elapsed = time.perf_counter() - start
assert response.status_code == 200
assert elapsed < 2.0
# -- Health & Models --
@pytest.mark.asyncio
async def test_health_endpoint(client):
response = await client.get("/health")
assert response.status_code == 200
@pytest.mark.asyncio
async def test_models_endpoint(client):
response = await client.get("/v1/models")
assert response.status_code == 200
data = response.json()
assert "data" in data
model_ids = [m["id"] for m in data["data"]]
assert MODEL_NAME in model_ids
+111
View File
@@ -0,0 +1,111 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Unit tests for the `vllm launch` CLI subcommand."""
import argparse
from unittest.mock import patch
import pytest
from vllm.entrypoints.cli.launch import (
LaunchSubcommand,
RenderSubcommand,
cmd_init,
)
from vllm.utils.argparse_utils import FlexibleArgumentParser
@pytest.fixture
def launch_parser():
parser = FlexibleArgumentParser(description="test")
subparsers = parser.add_subparsers(required=False, dest="subparser")
LaunchSubcommand().subparser_init(subparsers)
return parser
def test_subcommand_name():
assert LaunchSubcommand().name == "launch"
def test_cmd_init_returns_subcommand():
result = cmd_init()
assert len(result) == 1
assert isinstance(result[0], LaunchSubcommand)
# -- Parsing: `vllm launch render` --
def test_parse_launch_render(launch_parser):
args = launch_parser.parse_args(["launch", "render", "--model", "test-model"])
assert args.launch_component == "render"
def test_parse_launch_requires_component(launch_parser):
with pytest.raises(SystemExit):
launch_parser.parse_args(["launch", "--model", "test-model"])
def test_parse_launch_invalid_component(launch_parser):
with pytest.raises(SystemExit):
launch_parser.parse_args(["launch", "unknown", "--model", "test-model"])
# -- Dispatch --
def test_cmd_launch_render_calls_run():
args = argparse.Namespace(model_tag=None, model="test-model")
with patch("vllm.entrypoints.cli.launch.uvloop.run") as mock_uvloop_run:
RenderSubcommand.cmd(args)
mock_uvloop_run.assert_called_once()
def test_cmd_launch_model_tag_overrides():
args = argparse.Namespace(
model_tag="tag-model",
model="original-model",
launch_command=lambda a: None,
)
LaunchSubcommand.cmd(args)
assert args.model == "tag-model"
def test_cmd_launch_model_tag_none():
args = argparse.Namespace(
model_tag=None,
model="original-model",
launch_command=lambda a: None,
)
LaunchSubcommand.cmd(args)
assert args.model == "original-model"
def test_cmd_dispatches():
called = {}
def fake_dispatch(args):
called["args"] = args
args = argparse.Namespace(launch_command=fake_dispatch)
LaunchSubcommand.cmd(args)
assert "args" in called
# -- Module registration --
def test_subparser_init_returns_parser():
parser = FlexibleArgumentParser(description="test")
subparsers = parser.add_subparsers(required=False, dest="subparser")
result = LaunchSubcommand().subparser_init(subparsers)
assert isinstance(result, FlexibleArgumentParser)
def test_launch_registered_in_main():
"""Verify that launch module is importable as a CLI module."""
import vllm.entrypoints.cli.launch as launch_module
assert hasattr(launch_module, "cmd_init")
subcmds = launch_module.cmd_init()
assert any(s.name == "launch" for s in subcmds)