Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -241,7 +241,8 @@ class TestToolResultContent:
self, tool_result_content
) -> AnthropicMessagesRequest:
"""Build a request with assistant tool_use followed by user
tool_result."""
tool_result.
"""
return _make_request(
[
{
@@ -326,7 +327,8 @@ class TestToolResultContent:
def test_tool_result_with_text_and_image(self):
"""Mixed text+image tool_result: text in tool msg, image in user
msg."""
msg.
"""
request = self._make_tool_result_request(
[
{"type": "text", "text": "Here is the screenshot"},
@@ -423,7 +425,8 @@ class TestToolResultContent:
class TestAttributionHeaderStripping:
def test_billing_header_stripped_from_system(self):
"""Claude Code's x-anthropic-billing-header block should be
stripped to preserve prefix caching."""
stripped to preserve prefix caching.
"""
request = _make_request(
[{"role": "user", "content": "Hello"}],
system=[
@@ -480,7 +483,7 @@ class TestThinkingBlockConversion:
"""
def test_thinking_plus_text_in_assistant_message(self):
"""thinking + text → reasoning field + plain-string content."""
"""Thinking + text → reasoning field + plain-string content."""
request = _make_request(
[
{"role": "user", "content": "Write me some code."},
@@ -542,7 +545,7 @@ class TestThinkingBlockConversion:
assert asst.get("content") is None
def test_thinking_plus_tool_use_in_assistant_message(self):
"""thinking + tool_use: reasoning field set, tool_calls populated."""
"""Thinking + tool_use: reasoning field set, tool_calls populated."""
request = _make_request(
[
{"role": "user", "content": "What is 2+2?"},
@@ -1147,7 +1150,8 @@ class TestMessageStreamConverterToolUseContentBuffering:
async def test_buffered_content_flushed_on_done_without_usage_chunk(self):
"""Content buffered during tool_use must be emitted even if the
stream jumps straight from finish_reason to [DONE], skipping the
empty-choices usage chunk."""
empty-choices usage chunk.
"""
async def sse_input():
yield _make_stream_chunk(
@@ -1251,7 +1255,8 @@ class TestStreamingCacheUsageSemantics:
async def test_streaming_cache_fields_absent_then_populated(self):
"""First chunk lacks prompt_tokens_details (vLLM contract);
message_start omits cache fields. The final chunk carries
prompt_tokens_details, so message_delta carries resolved values."""
prompt_tokens_details, so message_delta carries resolved values.
"""
async def sse_input():
yield _make_stream_chunk(
@@ -1296,7 +1301,8 @@ class TestStreamingCacheUsageSemantics:
@pytest.mark.asyncio
async def test_streaming_no_cache_hit(self):
"""When the final chunk reports cached_tokens=0, message_delta carries
cache fields = 0 (cache miss); message_start still omits them."""
cache fields = 0 (cache miss); message_start still omits them.
"""
async def sse_input():
yield _make_stream_chunk(
@@ -1337,7 +1343,8 @@ class TestStreamingCacheUsageSemantics:
@pytest.mark.asyncio
async def test_streaming_no_prompt_tokens_details_at_all(self):
"""If --enable-prompt-tokens-details is off, no chunk carries cache
info; both message_start and message_delta omit cache fields."""
info; both message_start and message_delta omit cache fields.
"""
async def sse_input():
yield _make_stream_chunk(
@@ -1458,7 +1465,8 @@ class TestMessagesFullConverter:
class TestCacheSalt:
def test_cache_salt_passed_through(self):
"""cache_salt on the Anthropic request reaches the converted
ChatCompletionRequest so prefix-cache isolation works via /v1/messages."""
ChatCompletionRequest so prefix-cache isolation works via /v1/messages.
"""
request = _make_request(
[{"role": "user", "content": "Hello"}],
cache_salt="tenant-abc-secret-salt",
@@ -1663,7 +1671,8 @@ class TestClientErrorResponses:
@staticmethod
def _conversion_error() -> ValidationError:
"""A real pydantic ValidationError like the one ChatCompletionRequest
construction raises when Anthropic input violates the OpenAI schema."""
construction raises when Anthropic input violates the OpenAI schema.
"""
class _StubRequest(BaseModel):
stop: Annotated[list[str], Field(max_length=4)] | None = None
@@ -1674,7 +1683,8 @@ class TestClientErrorResponses:
def test_validation_error_returns_bad_request(self):
"""A pydantic ValidationError during Anthropic->OpenAI conversion is
surfaced as a 400 BadRequestError, not a 500."""
surfaced as a 400 BadRequestError, not a 500.
"""
handler = MagicMock(spec=AnthropicServingMessages)
handler.create_messages.side_effect = self._conversion_error()
@@ -87,7 +87,8 @@ def _make_chunk(
citations: list[Any] | None = None,
) -> str:
"""Build the ``data: {...}\\n\\n`` SSE frame the production code
consumes."""
consumes.
"""
delta: dict[str, Any] = {}
if role is not None:
delta["role"] = role
@@ -135,7 +136,8 @@ async def _stream_from(items: list[str]) -> AsyncGenerator[str, None]:
async def _drain(serving: CohereServingChatV2, items: list[str]) -> list[str]:
"""Drive ``_chat_completion_stream_to_v2`` over ``items`` and collect
the emitted SSE frames."""
the emitted SSE frames.
"""
request = CohereChatV2Request(
model="m", messages=[{"role": "user", "content": "hi"}], stream=True
)
@@ -50,7 +50,8 @@ def update_admission_stats_worker(listen_address, sock, args, client_config):
# importable by `multiprocessing.spawn` (no closures, no nesting).
def defer_addresses_stub_worker(listen_address, sock, args, client_config):
"""Bind ROUTER/PULL with a kernel-assigned port, report the actual
endpoints back via the pipe, then exit."""
endpoints back via the pipe, then exit.
"""
ctx = zmq.Context()
try:
in_sock = make_zmq_socket(
@@ -357,7 +358,8 @@ def test_external_process_monitoring(api_server_args):
def test_gather_actual_addresses_end_to_end():
"""Each child binds ROUTER/PULL with a kernel-picked port and reports
the bound endpoints back via its per-child pipe; the manager surfaces
them via :py:meth:`gather_actual_addresses`."""
them via :py:meth:`gather_actual_addresses`.
"""
host = "127.0.0.1"
num_servers = 4
@@ -407,7 +409,8 @@ def test_gather_actual_addresses_end_to_end():
@pytest.mark.timeout(30)
def test_gather_actual_addresses_child_crash_before_report():
"""A child that exits before sending its endpoints must surface a
clear ``RuntimeError`` rather than hang or return ``None`` slots."""
clear ``RuntimeError`` rather than hang or return ``None`` slots.
"""
host = "127.0.0.1"
num_servers = 2
placeholder_inputs = [
@@ -444,7 +447,8 @@ def test_gather_actual_addresses_child_crash_before_report():
def test_rust_frontend_launch_log_redacts_credentials(monkeypatch, caplog):
"""The Rust frontend command carries every non-default arg as JSON.
Credentials must not reach the log line."""
Credentials must not reach the log line.
"""
import subprocess as subprocess_mod
from vllm.entrypoints.launchers.cli_args import make_arg_parser
+17 -15
View File
@@ -152,7 +152,7 @@ def test_multiple_valid_inputs(serve_parser):
### Tests for serve argument validation that run prior to loading
def test_enable_auto_choice_passes_without_tool_call_parser(serve_parser):
"""Ensure validation fails if tool choice is enabled with no call parser"""
"""Ensure validation fails if tool choice is enabled with no call parser."""
# If we enable-auto-tool-choice, explode with no tool-call-parser
args = serve_parser.parse_args(args=["--enable-auto-tool-choice"])
with pytest.raises(TypeError):
@@ -160,7 +160,7 @@ def test_enable_auto_choice_passes_without_tool_call_parser(serve_parser):
def test_enable_auto_choice_passes_with_tool_call_parser(serve_parser):
"""Ensure validation passes with tool choice enabled with a call parser"""
"""Ensure validation passes with tool choice enabled with a call parser."""
args = serve_parser.parse_args(
args=[
"--enable-auto-tool-choice",
@@ -172,7 +172,7 @@ def test_enable_auto_choice_passes_with_tool_call_parser(serve_parser):
def test_enable_auto_choice_fails_with_enable_reasoning(serve_parser):
"""Ensure validation fails if reasoning is enabled with auto tool choice"""
"""Ensure validation fails if reasoning is enabled with auto tool choice."""
args = serve_parser.parse_args(
args=[
"--enable-auto-tool-choice",
@@ -186,7 +186,8 @@ def test_enable_auto_choice_fails_with_enable_reasoning(serve_parser):
def test_passes_with_reasoning_parser(serve_parser):
"""Ensure validation passes if reasoning is enabled
with a reasoning parser"""
with a reasoning parser
"""
args = serve_parser.parse_args(
args=[
"--reasoning-parser",
@@ -197,7 +198,7 @@ def test_passes_with_reasoning_parser(serve_parser):
def test_chat_template_validation_for_happy_paths(serve_parser):
"""Ensure validation passes if the chat template exists"""
"""Ensure validation passes if the chat template exists."""
args = serve_parser.parse_args(
args=["--chat-template", CHATML_JINJA_PATH.absolute().as_posix()]
)
@@ -205,7 +206,7 @@ def test_chat_template_validation_for_happy_paths(serve_parser):
def test_chat_template_validation_for_sad_paths(serve_parser):
"""Ensure validation fails if the chat template doesn't exist"""
"""Ensure validation fails if the chat template doesn't exist."""
args = serve_parser.parse_args(args=["--chat-template", "does/not/exist"])
with pytest.raises(VLLMValidationError):
validate_parsed_serve_args(args)
@@ -304,13 +305,13 @@ def test_sse_keep_alive_interval_non_integer(serve_parser, value):
],
)
def test_middleware(serve_parser, cli_args, expected_middleware):
"""Ensure multiple middleware args are parsed properly"""
"""Ensure multiple middleware args are parsed properly."""
args = serve_parser.parse_args(args=cli_args)
assert args.middleware == expected_middleware
def test_default_chat_template_kwargs_parsing(serve_parser):
"""Ensure default_chat_template_kwargs JSON is parsed correctly"""
"""Ensure default_chat_template_kwargs JSON is parsed correctly."""
args = serve_parser.parse_args(
args=["--default-chat-template-kwargs", '{"enable_thinking": false}']
)
@@ -318,7 +319,7 @@ def test_default_chat_template_kwargs_parsing(serve_parser):
def test_default_chat_template_kwargs_complex(serve_parser):
"""Ensure complex default_chat_template_kwargs JSON is parsed correctly"""
"""Ensure complex default_chat_template_kwargs JSON is parsed correctly."""
kwargs_json = '{"enable_thinking": false, "custom_param": "value", "num": 42}'
args = serve_parser.parse_args(args=["--default-chat-template-kwargs", kwargs_json])
assert args.default_chat_template_kwargs == {
@@ -329,7 +330,7 @@ def test_default_chat_template_kwargs_complex(serve_parser):
def test_default_chat_template_kwargs_default_none(serve_parser):
"""Ensure default_chat_template_kwargs defaults to None"""
"""Ensure default_chat_template_kwargs defaults to None."""
args = serve_parser.parse_args(args=[])
assert args.default_chat_template_kwargs is None
@@ -355,7 +356,7 @@ def test_resolve_default_chat_template_kwargs(default_kwargs, cohere_format, exp
def test_default_chat_template_kwargs_invalid_json(serve_parser):
"""Ensure invalid JSON raises an error"""
"""Ensure invalid JSON raises an error."""
with pytest.raises(SystemExit):
serve_parser.parse_args(
args=["--default-chat-template-kwargs", "not valid json"]
@@ -381,7 +382,8 @@ def test_default_chat_template_kwargs_invalid_json(serve_parser):
)
def test_served_model_name_parsing(tmp_path, vllm_parser, args, raises):
"""Ensure that users don't misuse --served-model-name and end up with the default
model tag instead of the one they intended to serve."""
model tag instead of the one they intended to serve.
"""
# Call the serve subparser
args.insert(0, "serve")
# Create a dummy config file if the test case includes it
@@ -402,7 +404,7 @@ def test_served_model_name_parsing(tmp_path, vllm_parser, args, raises):
### Tests for LoRA target modules parsing
def test_lora_target_modules_single(serve_parser):
"""Test parsing single lora-target-modules argument"""
"""Test parsing single lora-target-modules argument."""
args = serve_parser.parse_args(
args=["--enable-lora", "--lora-target-modules", "o_proj"]
)
@@ -410,7 +412,7 @@ def test_lora_target_modules_single(serve_parser):
def test_lora_target_modules_multiple(serve_parser):
"""Test parsing multiple lora-target-modules arguments"""
"""Test parsing multiple lora-target-modules arguments."""
args = serve_parser.parse_args(
args=[
"--enable-lora",
@@ -424,6 +426,6 @@ def test_lora_target_modules_multiple(serve_parser):
def test_lora_target_modules_default_none(serve_parser):
"""Test that lora-target-modules defaults to None"""
"""Test that lora-target-modules defaults to None."""
args = serve_parser.parse_args(args=[])
assert args.lora_target_modules is None
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Tests for DPSupervisor: unit tests and lifecycle integration tests.
"""Tests for DPSupervisor: unit tests and lifecycle integration tests.
Lifecycle integration tests replace child vLLM servers with lightweight
aiohttp "fake" servers controlled by the test, so the suite runs without GPUs.
@@ -463,8 +462,7 @@ async def test_start_server_no_log_config_when_no_filter(monkeypatch):
class MockVLLMServer:
"""
Minimal FastAPI server that mimics one vLLM replica.
"""Minimal FastAPI server that mimics one vLLM replica.
GET /health returns 200 when healthy, 503 otherwise.
Health state is toggled by the test via set_healthy().
"""
@@ -582,8 +580,7 @@ def launch_mock_vllm_with_drain(
async def _poll_supervisor_health(expected_status: int, use_ssl: bool = False) -> bool:
"""
GET /health on the supervisor once and check for expected_status.
"""GET /health on the supervisor once and check for expected_status.
Pass expected_status=-1 to assert the supervisor is not listening yet
(a connection error is expected). The supervisor only starts its HTTP
@@ -705,8 +702,7 @@ async def _run_supervisor(
@pytest.mark.asyncio
async def test_basic_lifecycle(monkeypatch):
"""
A) Supervisor is not listening while children are unhealthy.
"""A) Supervisor is not listening while children are unhealthy.
B) /health returns 200 once every child reports healthy.
C) SIGTERM and shutdown
"""
@@ -777,8 +773,7 @@ async def test_basic_lifecycle_with_ssl(monkeypatch):
@pytest.mark.asyncio
async def test_failed_startup(monkeypatch):
"""
A) One of the vLLM servers crashes during startup.
"""A) One of the vLLM servers crashes during startup.
B) DPSupervisor detects this, and cleans up resources.
"""
args = _make_args()
@@ -801,8 +796,7 @@ async def test_failed_startup(monkeypatch):
@pytest.mark.asyncio
async def test_becomes_unhealthy(monkeypatch):
"""
A) Supervisor is not listening while children are unhealthy.
"""A) Supervisor is not listening while children are unhealthy.
B) /health returns 200 once every child reports healthy.
C) Child process becomes unhealthy.
D) Detected and shutdown.
@@ -842,8 +836,7 @@ async def test_becomes_unhealthy(monkeypatch):
@pytest.mark.asyncio
async def test_dp_server_fails(monkeypatch):
"""
A) Supervisor is not listening while children are unhealthy.
"""A) Supervisor is not listening while children are unhealthy.
B) /health returns 200 once every child reports healthy.
C) Child process fails.
D) Detected and shutdown.
@@ -886,8 +879,7 @@ async def test_dp_server_fails(monkeypatch):
@pytest.mark.asyncio
async def test_shutdown_timeout(monkeypatch: pytest.MonkeyPatch):
"""
Child mock servers delay shutdown by 10s on SIGTERM (simulating in-flight
"""Child mock servers delay shutdown by 10s on SIGTERM (simulating in-flight
request drain). The supervisor is configured with shutdown_timeout=10,
so its total wait budget is 10 + CHILD_EXIT_GRACE_S seconds. The
children exit naturally within that window, so no force-kill should occur
@@ -509,9 +509,7 @@ def test_completions():
def test_completions_invalid_input():
"""
Ensure that we fail when the input doesn't conform to the openai api.
"""
"""Ensure that we fail when the input doesn't conform to the openai api."""
with (
tempfile.NamedTemporaryFile("w") as input_file,
tempfile.NamedTemporaryFile("r") as output_file,
@@ -602,9 +600,7 @@ def test_score(input_batch):
def test_reasoning_parser():
"""
Test that reasoning_parser parameter works correctly in run_batch.
"""
"""Test that reasoning_parser parameter works correctly in run_batch."""
with (
tempfile.NamedTemporaryFile("w") as input_file,
tempfile.NamedTemporaryFile("r") as output_file,
@@ -767,8 +763,7 @@ def test_translation():
def test_tool_calling():
"""
Test that tool calling works correctly in run_batch.
"""Test that tool calling works correctly in run_batch.
Verifies that requests with tools return tool_calls in the response.
"""
with (
@@ -134,7 +134,6 @@ async def test_shutdown_on_engine_failure(tmp_path: Path):
Starts a vLLM server, kills it to simulate a crash, then verifies that
subsequent API calls fail appropriately.
"""
port = get_open_port()
# Redirect server output to a file rather than a pipe: nothing drains the
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for HF_HUB_OFFLINE mode"""
"""Tests for HF_HUB_OFFLINE mode."""
import importlib
import sys
+1 -5
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
This file test accuracy of the vLLM server via LMEval.
"""This file test accuracy of the vLLM server via LMEval.
It uses local-completions, which interacts with vLLM
through the OAI API with N concurrent connections.
This simulates real work usage of the API and makes
@@ -33,7 +32,6 @@ EXPECTED_VALUES = {
def run_test(model_name, more_args=None):
"""Run the end to end accuracy test."""
model_args = f"pretrained={model_name},max_model_len=4096"
if more_args is not None:
@@ -64,7 +62,6 @@ TPU_TP_TEST_STR = "" # "tensor_parallel_size=4"
@pytest.mark.parametrize("model", MODEL_NAMES)
def test_lm_eval_accuracy_v1_engine(model):
"""Run with the V1 Engine."""
more_args = None
if current_platform.is_tpu():
# Limit compilation time for TPU V1
@@ -81,7 +78,6 @@ def test_lm_eval_accuracy_v1_engine(model):
@pytest.mark.parametrize("model", FP8_KV_MODEL_NAMES)
def test_lm_eval_accuracy_v1_engine_fp8_kv_cache(model):
"""Run with the V1 Engine."""
more_args = None
if current_platform.is_tpu():
# Limit compilation time for TPU V1
+3 -6
View File
@@ -20,8 +20,7 @@ def text_llm(vllm_runner):
@pytest.fixture(scope="function")
def llm_for_failure_test(vllm_runner):
"""
Fixture for testing issue #26081.
"""Fixture for testing issue #26081.
Uses a small max_model_len to easily trigger length errors.
"""
with vllm_runner(
@@ -67,8 +66,7 @@ def test_multi_chat(text_llm):
def test_llm_chat_tokenization_no_double_bos(text_llm):
"""
LLM.chat() should not add special tokens when using chat templates.
"""LLM.chat() should not add special tokens when using chat templates.
Check we get a single BOS token for llama chat.
"""
messages = [
@@ -127,8 +125,7 @@ def test_chat_extra_kwargs(thinking_llm, enable_thinking):
def test_chat_batch_failure_cleanup(llm_for_failure_test):
"""
Tests that if a batch call to llm.chat() fails mid-way
"""Tests that if a batch call to llm.chat() fails mid-way
(e.g., due to one invalid prompt), the requests that
were already enqueued are properly aborted and do not
pollute the queue for subsequent calls.
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Test that ``InputProcessor.inject_into_mm_cache()`` correctly injects
"""Test that ``InputProcessor.inject_into_mm_cache()`` correctly injects
pre-processed mm_kwargs into the processor cache and reports MM cache
hit rate metrics accurately.
@@ -47,8 +47,7 @@ async def client(server):
async def test_online_audio_in_video(
client: openai.AsyncOpenAI, video_assets: VideoTestAssets
):
"""Test video input with `audio_in_video=True`"""
"""Test video input with `audio_in_video=True`."""
# we don't use video_urls above because they missed audio stream.
video_path = video_assets[0].video_path
with open(video_path, "rb") as f:
@@ -97,8 +96,7 @@ async def test_online_audio_in_video(
async def test_online_audio_in_video_multi_videos(
client: openai.AsyncOpenAI, video_assets: VideoTestAssets
):
"""Test multi-video input with `audio_in_video=True`"""
"""Test multi-video input with `audio_in_video=True`."""
# we don't use video_urls above because they missed audio stream.
video_path = video_assets[0].video_path
with open(video_path, "rb") as f:
@@ -151,8 +149,7 @@ async def test_online_audio_in_video_multi_videos(
async def test_online_audio_in_video_interleaved(
client: openai.AsyncOpenAI, video_assets: VideoTestAssets
):
"""Test interleaved video/audio input with `audio_in_video=True`"""
"""Test interleaved video/audio input with `audio_in_video=True`."""
# we don't use video_urls above because they missed audio stream.
video_path = video_assets[0].video_path
with open(video_path, "rb") as f:
@@ -2,7 +2,8 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""E2E test for mixing `prompt_embeds` with `audio_embeds` in a single
Chat Completions request."""
Chat Completions request.
"""
import json
@@ -68,7 +68,8 @@ async def client(server):
def image_url() -> str:
"""Stable real image as a data URL, kept identical across both the
text and prompt_embeds requests so any output difference must come from
how the text content is delivered."""
how the text content is delivered.
"""
return encode_image_url(ImageAsset("stop_sign").pil_image)
@@ -34,8 +34,7 @@ REQUIRED_BEAM_SEARCH_TERMS = [
def check_output_matches_terms(content: str, term_groups: list[list[str]]) -> bool:
"""
Check if content matches all required term groups.
"""Check if content matches all required term groups.
Each term group requires at least one of its terms to be present.
All term groups must be satisfied.
"""
@@ -146,7 +145,8 @@ def describe_image_messages(
) -> list[dict]:
"""Build the system + user messages used by the completions-with-image
family of tests. *extra_image_fields* is merged into the top-level
image content block (for uuid / bad-key tests)."""
image content block (for uuid / bad-key tests).
"""
image_block: dict = {
"type": "image_url",
"image_url": {"url": image_url},
@@ -176,7 +176,8 @@ async def complete_and_check(
temperature: float = 0.0,
) -> str:
"""Run a chat completion and assert the output is non-empty.
Returns the content string."""
Returns the content string.
"""
chat_completion = await client.chat.completions.create(
model=model_name,
messages=messages,
@@ -259,7 +259,7 @@ async def _generator(prompt_idx: int, text: str) -> AsyncGenerator[RequestOutput
@pytest.mark.asyncio
@pytest.mark.skip_global_cleanup
async def test_batched_echo_does_not_prepend_user_prompt() -> None:
"""echo must only echo the assistant turn, never the user's prompt.
"""Echo must only echo the assistant turn, never the user's prompt.
With `add_generation_prompt` (the default) the response role is `assistant`
while the last conversation message is the user's, so there is nothing to
@@ -121,7 +121,7 @@ def _build_serving_chat(engine: AsyncLLM) -> OpenAIServingChat:
@pytest.mark.asyncio
async def test_chat_error_non_stream():
"""test finish_reason='error' returns 500 InternalServerError (non-streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (non-streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -246,7 +246,7 @@ async def test_renderer_only_chat_request_skips_mm_cache():
@pytest.mark.asyncio
async def test_chat_error_stream():
"""test finish_reason='error' returns 500 InternalServerError (streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -465,7 +465,8 @@ def test_system_message_warns_on_video(video_content):
def test_json_schema_response_format_missing_schema():
"""When response_format type is 'json_schema' but the json_schema field
is not provided, request construction should raise a validation error
so the API returns 400 instead of 500."""
so the API returns 400 instead of 500.
"""
with pytest.raises(Exception, match="json_schema.*must be provided"):
ChatCompletionRequest(
model=MODEL_NAME,
@@ -519,7 +520,8 @@ def test_structured_outputs_structural_tag_invalid(structural_tag):
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "top_logprobs"])
def test_non_numeric_logprobs_rejected(field_name):
"""A non-numeric logprobs value must be a clean 400 validation error, not a
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
"""
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
ChatCompletionRequest(
model=MODEL_NAME,
@@ -81,7 +81,8 @@ async def test_chat_logit_bias_invalid(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_non_integer_key(client):
"""Test that a non-integer logit_bias key is rejected with a clean,
informative error instead of a raw 'invalid literal for int()' message."""
informative error instead of a raw 'invalid literal for int()' message.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -101,7 +102,8 @@ async def test_chat_logit_bias_non_integer_key(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_non_numeric_value(client):
"""Test that a non-numeric logit_bias value is rejected with a message
that names the specific offending token, not just a generic TypeError."""
that names the specific offending token, not just a generic TypeError.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -120,7 +122,8 @@ async def test_chat_logit_bias_non_numeric_value(client):
@pytest.mark.asyncio
async def test_chat_logit_bias_multiple_non_integer_keys(client):
"""Test that ALL invalid logit_bias keys are reported together,
not just the first one encountered."""
not just the first one encountered.
"""
with pytest.raises(openai.BadRequestError) as excinfo:
await client.chat.completions.create(
model=MODEL_NAME,
@@ -451,7 +451,7 @@ async def test_inconsistent_tool_choice_and_tools(
async def test_max_tokens_with_tool_choice_required(
client: openai.AsyncOpenAI, tool_choice
):
""" """
"""Requesting a single token with a required tool choice must not crash."""
models = await client.models.list()
model_name: str = models.data[0].id
@@ -52,9 +52,10 @@ def stop_sign_image_url():
@pytest.mark.asyncio
async def test_translategemma_extra_lang_code_fields(client: openai.AsyncOpenAI):
"""en -> es translation through TranslateGemma's bundled chat template's
"""En -> es translation through TranslateGemma's bundled chat template's
``text`` content branch, which depends on ``source_lang_code`` /
``target_lang_code`` extra fields being preserved on the content part."""
``target_lang_code`` extra fields being preserved on the content part.
"""
completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=[
@@ -92,13 +93,14 @@ async def test_translategemma_image_extra_lang_code_fields(
client: openai.AsyncOpenAI,
stop_sign_image_url: str,
):
"""en -> es OCR-translation through TranslateGemma's bundled chat
"""En -> es OCR-translation through TranslateGemma's bundled chat
template's ``image`` content branch. Exercises the multimodal branch of
``_collect_extra_fields`` in ``_parse_chat_message_content_part``: the
``source_lang_code`` / ``target_lang_code`` extras must survive parsing
and end up alongside the ``{"type": "image"}`` placeholder so the
template's image branch (``content["type"] == 'image'``) renders the
right OCR-translation prompt."""
right OCR-translation prompt.
"""
completion = await client.chat.completions.create(
model=MODEL_NAME,
messages=[
@@ -191,7 +191,8 @@ async def test_logprob_token_ids_stream_with_no_top_k(server):
async def test_logprob_token_ids_default_behavior_unchanged(server):
"""Without `logprob_token_ids`, the response carries the natural top-k
most-likely tokens. This guards against the new field accidentally
changing the default-path output."""
changing the default-path output.
"""
async with server.get_async_client() as client:
resp = await client.chat.completions.create(
model=MODEL_NAME,
@@ -1232,7 +1232,6 @@ async def test_serving_chat_mistral_token_ids_prompt_is_validated():
"""Regression test: when the Mistral tokenizer path returns token IDs
directly, we must still apply input length + max_tokens validation.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig(skip_tokenizer_init=True)
@@ -1271,7 +1270,6 @@ async def test_serving_chat_mistral_token_ids_prompt_too_long_is_rejected():
"""Regression test: MistralTokenizer token-id prompts must still enforce
the max context length for the input itself (token_num >= max_model_len).
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig(skip_tokenizer_init=True)
@@ -1408,7 +1406,8 @@ async def test_serving_chat_did_set_correct_cache_salt(model_type):
@pytest.mark.asyncio
async def test_serving_chat_data_parallel_rank_extraction():
"""Test that data_parallel_rank is properly extracted from header and
passed to engine."""
passed to engine.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -1512,8 +1511,7 @@ async def _render_chat_prompt_token_ids(
class TestServingChatWithHarmony:
"""
These tests ensure Chat Completion requests are being properly converted into
"""These tests ensure Chat Completion requests are being properly converted into
Harmony messages and Harmony response messages back into Chat Completion responses.
These tests are not exhaustive, but each one was created to cover a specific case
that we got wrong but is now fixed.
@@ -1731,7 +1729,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_system_message_without_tools(self, serving_chat, stream):
"""Leading system message produces a developer message with
DeveloperContent (# Instructions header)."""
DeveloperContent (# Instructions header).
"""
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello"},
@@ -1753,7 +1752,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_system_message_with_tools(self, serving_chat, stream, weather_tools):
"""Leading system message is folded into the developer message
alongside tool definitions."""
alongside tool definitions.
"""
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What's the weather?"},
@@ -2168,7 +2168,8 @@ class TestServingChatWithHarmony:
@pytest.mark.asyncio
async def test_tool_choice_validation_without_parser():
"""Test that tool_choice='required' or named tool without tool_parser
returns an appropriate error message."""
returns an appropriate error message.
"""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -33,7 +33,6 @@ def _count_reasoning_decode_token_ids_between_markers(
reasoning_end_ids: list[int],
) -> int | None:
"""Count decode tokens in the thinking span (after last start, before first end)."""
if not reasoning_start_ids or not reasoning_end_ids:
raise ValueError("reasoning marker token id lists must be non-empty")
@@ -152,8 +151,8 @@ async def client(request, server, server_with_auto_reasoning_config):
@pytest.mark.parametrize("client", ["default", "auto_config"], indirect=True)
async def test_thinking_token_budget_mixed_requests(client: openai.AsyncOpenAI):
"""Test that mixed requests (some with thinking_token_budget, some without)
complete successfully without errors."""
complete successfully without errors.
"""
response_with_budget = await client.chat.completions.create(
model=MODEL_NAME,
messages=MESSAGES,
@@ -182,7 +181,6 @@ async def test_thinking_token_budget_limits_reasoning(client: openai.AsyncOpenAI
grouped into streamed chunks (a single chunk can carry several tokens under
async scheduling / stream_interval > 1). Counting chunks under-counts.
"""
tokenizer = get_tokenizer(tokenizer_name=MODEL_NAME)
start_ids = list(tokenizer.encode(REASONING_START_STR, add_special_tokens=False))
end_ids = list(tokenizer.encode(REASONING_END_STR, add_special_tokens=False))
@@ -227,7 +225,6 @@ async def test_thinking_token_budget_qwen35_fp8_mtp_concurrent_mixed_budget_and_
Qwen3.5 FP8 + MTP (TP=2) server. Budgeted calls are checked with
``_count_reasoning_decode_token_ids_between_markers`` on full token ids.
"""
_batch_spec: list[tuple[Literal["budget"], int] | tuple[Literal["plain"], None]] = [
("budget", 1),
("budget", 12),
@@ -350,7 +350,6 @@ async def test_parallel_no_streaming(client: openai.AsyncOpenAI, model_name: str
"""Parallel sampling without streaming.
A single request output contains a list of completions.
"""
prompt = "What is an LLM?"
n = 3
max_tokens = 50
@@ -396,7 +395,6 @@ async def test_parallel_streaming(client: openai.AsyncOpenAI, model_name: str):
The tokens from multiple samples, are flattened into a single stream,
with an index to indicate which sample the token belongs to.
"""
prompt = "What is an LLM?"
n = 3
max_tokens = 50
@@ -303,7 +303,7 @@ def test_completion_metrics_carries_both_timing_and_spec_decode():
@pytest.mark.asyncio
async def test_completion_error_non_stream():
"""test finish_reason='error' returns 500 InternalServerError (non-streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (non-streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -439,7 +439,7 @@ async def test_renderer_only_completion_request_skips_mm_cache():
@pytest.mark.asyncio
async def test_completion_error_stream():
"""test finish_reason='error' returns 500 InternalServerError (streaming)"""
"""Test finish_reason='error' returns 500 InternalServerError (streaming)."""
mock_engine = MagicMock(spec=AsyncLLM)
mock_engine.errored = False
mock_engine.model_config = MockModelConfig()
@@ -521,7 +521,8 @@ async def test_completion_error_stream():
def test_json_schema_response_format_missing_schema():
"""When response_format type is 'json_schema' but the json_schema field
is not provided, request construction should raise a validation error
so the API returns 400 instead of 500."""
so the API returns 400 instead of 500.
"""
with pytest.raises(Exception, match="json_schema.*must be provided"):
CompletionRequest(
model=MODEL_NAME,
@@ -584,7 +585,8 @@ def test_negative_prompt_token_ids_flat():
def test_logprobs_minus_one_allowed():
"""logprobs=-1 means "return all logprobs". The sampling layer and the chat
top_logprobs / prompt_logprobs validators all accept -1, so the completion
logprobs validator must accept it too instead of rejecting it as negative."""
logprobs validator must accept it too instead of rejecting it as negative.
"""
request = CompletionRequest(
model=MODEL_NAME,
prompt="Test prompt",
@@ -744,7 +746,8 @@ class TestCompletionPromptListLimit:
@pytest.mark.parametrize("field_name", ["prompt_logprobs", "logprobs"])
def test_non_numeric_logprobs_rejected(field_name):
"""A non-numeric logprobs value must be a clean 400 validation error, not a
TypeError from the mode='before' comparison (which surfaces as HTTP 500)."""
TypeError from the mode='before' comparison (which surfaces as HTTP 500).
"""
with pytest.raises(VLLMValidationError, match=f"`{field_name}` must be an integer"):
CompletionRequest(
model=MODEL_NAME,
@@ -39,8 +39,7 @@ def server():
@pytest.mark.asyncio
async def test_token_in_token_out_and_logprobs(server):
"""
Test token-in-token-out and token_ids align with prompt_logprobs
"""Test token-in-token-out and token_ids align with prompt_logprobs
& logprobs when return_tokens_as_token_ids is enabled.
"""
tokenizer = get_tokenizer(tokenizer_name=MODEL_NAME)
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
This file test accuracy of the vLLM server via LMEval.
"""This file test accuracy of the vLLM server via LMEval.
It uses local-completions, which interacts with vLLM
through the OAI API with N concurrent connections.
This simulates real work usage of the API and makes
@@ -37,7 +36,6 @@ if current_platform.is_tpu():
def run_test(more_args):
"""Run the end to end accuracy test."""
args = list(DEFAULT_ARGS)
args.extend(more_args)
print(f"Running with: {args}")
@@ -68,7 +66,6 @@ def run_test(more_args):
def test_lm_eval_accuracy_v1_engine():
"""Run with the V1 Engine."""
more_args = []
# Limit compilation time for V1 on TPU
@@ -43,7 +43,8 @@ def _system():
class TestResponseInputToHarmonyRenderParity:
"""Each test drives the same conversation through both APIs and asserts
identical Harmony messages and rendered token sequences."""
identical Harmony messages and rendered token sequences.
"""
# -----------------------------------------------------------------------
# Single-message cases
@@ -51,7 +52,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_developer_message(self):
"""Both APIs must render developer messages identically using
DeveloperContent (with the '# Instructions' header)."""
DeveloperContent (with the '# Instructions' header).
"""
chat_msgs = parse_chat_input_to_harmony_message(
{"role": "developer", "content": "Be concise."}
)
@@ -246,7 +248,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_reasoning_combined_with_function_call(self):
"""Chat API packs reasoning + tool_calls into one dict; responses API
represents them as two separate items. Both must produce the same two
Harmony messages in the same order: analysis then commentary."""
Harmony messages in the same order: analysis then commentary.
"""
chat_msgs = parse_chat_input_to_harmony_message(
{
"role": "assistant",
@@ -529,7 +532,8 @@ class TestResponseInputToHarmonyRenderParity:
def test_completed_turns_drop_reasoning(self):
"""Validates that reasoning from completed turns is dropped, while
reasoning from the current in-progress tool-call turn is preserved
in both chat completions and responses previous_input_messages."""
in both chat completions and responses previous_input_messages.
"""
first_turn_reasoning = "FIRST_TURN_REASONING"
second_turn_reasoning = "SECOND_TURN_REASONING"
@@ -170,7 +170,7 @@ class TestIsFunctionRecipientWithAllowedNames:
"""Tests for is_function_recipient with allowed_function_tool_names."""
def test_prefixed_always_accepted(self):
"""functions. prefix is always accepted regardless of allowed names."""
"""Functions. prefix is always accepted regardless of allowed names."""
fn_names = frozenset({"other_tool"})
assert is_function_recipient("functions.get_weather", fn_names) is True
@@ -252,8 +252,7 @@ class TestExtractFunctionFromRecipient:
class TestCommonParseInputToHarmonyMessage:
"""
Tests for scenarios that are common to both Chat Completion
"""Tests for scenarios that are common to both Chat Completion
parse_chat_input_to_harmony_message and Responses API
response_previous_input_to_harmony functions.
"""
@@ -324,7 +323,8 @@ class TestCommonParseInputToHarmonyMessage:
def test_system_message(self, parse_function):
"""Test parsing system messages, which are parsed into developer messages
with DeveloperContent."""
with DeveloperContent.
"""
chat_msg = {
"role": "system",
"content": "You are a helpful assistant",
@@ -448,8 +448,7 @@ class TestCommonParseInputToHarmonyMessage:
class TestParseChatInputToHarmonyMessage:
"""
Tests for scenarios that are specific to the Chat Completion API
"""Tests for scenarios that are specific to the Chat Completion API
parse_chat_input_to_harmony_message function.
"""
@@ -14,7 +14,7 @@ from vllm.exceptions import GenerationError
@pytest.mark.asyncio
async def test_raise_if_error_raises_generation_error():
"""test _raise_if_error raises GenerationError"""
"""Test _raise_if_error raises GenerationError."""
# create a minimal GenerateBaseServing instance
mock_engine = MagicMock()
mock_engine.model_config = MagicMock()
@@ -42,7 +42,7 @@ async def test_raise_if_error_raises_generation_error():
@pytest.mark.asyncio
async def test_convert_generation_error_to_streaming_response():
"""test _convert_generation_error_to_streaming_response output"""
"""Test _convert_generation_error_to_streaming_response output."""
mock_engine = MagicMock()
mock_engine.model_config = MagicMock()
mock_engine.model_config.max_model_len = 100
@@ -168,8 +168,7 @@ async def test_max_tokens_with_tool_choice_required(
@pytest.mark.asyncio
async def test_named_tool_use(client: openai.AsyncOpenAI):
def get_weather(latitude: float, longitude: float) -> str:
"""
Mock function to simulate getting weather data.
"""Mock function to simulate getting weather data.
In a real application, this would call an external weather API.
"""
return f"Current temperature at ({latitude}, {longitude}) is 20°C."
@@ -12,7 +12,8 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
def test_function_call_dict_converted_to_object():
"""Test that function_call dictionaries are correctly parsed into
ResponseFunctionToolCall objects."""
ResponseFunctionToolCall objects.
"""
# Create a request with function_call as dict
request_data = {
"model": "gpt-oss",
@@ -57,7 +58,6 @@ def test_direct_function_call_object_preservation():
def test_mixed_input_types_with_function_calls():
"""Test parsing with mixed input types including function calls."""
request_data = {
"model": "gpt-oss",
"input": [
@@ -177,7 +177,6 @@ def test_empty_list_input():
def test_function_call_output_not_affected():
"""Test that FunctionCallOutput is not affected by the function_call parsing."""
# Test with FunctionCallOutput as dict (should not be parsed)
request_data = {
"model": "gpt-oss",
@@ -265,7 +264,6 @@ def test_function_call_validation_failure_logs_debug(caplog):
def test_validator_handles_iterator_input():
"""Test that validator can handle ValidatorIterator input (Pydantic internal)."""
# This test simulates when Pydantic passes a ValidatorIterator instead of a list
# This happened with complex nested structures containing reasoning + function_call
@@ -332,7 +330,8 @@ def test_validator_handles_empty_iterator():
def test_assistant_string_content_stays_easyinput():
"""EasyInput assistant message with plain string content is not
coerced into a ResponseOutputMessage."""
coerced into a ResponseOutputMessage.
"""
request_data = {
"model": "test-model",
"input": [
@@ -354,7 +353,8 @@ def test_assistant_string_content_stays_easyinput():
def test_assistant_output_style_content_coerced():
"""Assistant message whose content is output-message-shaped (list of
output_text items) should be coerced to ResponseOutputMessage."""
output_text items) should be coerced to ResponseOutputMessage.
"""
request_data = {
"model": "test-model",
"input": [
@@ -20,8 +20,7 @@ from vllm.exceptions import VLLMValidationError
class TestResponsePreviousInputToHarmony:
"""
Tests for scenarios that are specific to the Responses API
"""Tests for scenarios that are specific to the Responses API
response_previous_input_to_harmony function.
"""
@@ -67,7 +67,8 @@ class TestResponseInputToHarmonyMessage:
def test_system_message(self):
"""System messages carry developer instructions and must be rendered
as developer messages with DeveloperContent."""
as developer messages with DeveloperContent.
"""
msg = response_input_to_harmony(
{"type": "message", "role": "system", "content": "Be helpful."},
prev_responses=[],
@@ -89,7 +90,8 @@ class TestResponseInputToHarmonyMessage:
def test_developer_message_gets_instructions_prefix(self):
"""Developer messages must use DeveloperContent which adds the
'# Instructions' header the model was trained on."""
'# Instructions' header the model was trained on.
"""
msg = response_input_to_harmony(
{"type": "message", "role": "developer", "content": "Be concise."},
prev_responses=[],
@@ -119,7 +121,8 @@ class TestResponseInputToHarmonyMessage:
def test_developer_message_array_content_concatenated(self):
"""Array content in developer messages is flattened and rendered
via DeveloperContent with the '# Instructions' header."""
via DeveloperContent with the '# Instructions' header.
"""
msg = response_input_to_harmony(
{
"type": "message",
@@ -210,7 +213,8 @@ class TestResponseInputToHarmonyMessage:
def test_function_call_output_uses_most_recent_matching_call(self):
"""When multiple prev_responses share a call_id, the last one wins
because the search is reversed."""
because the search is reversed.
"""
earlier = ResponseFunctionToolCall(
id="fc_old",
call_id="call_test",
@@ -839,11 +839,13 @@ class TestConstructChatMessagesCombinePolicy:
class TestConstructInputMessagesInstructionsLeak:
"""Regression tests for #37697: instructions from a prior response
should NOT leak through previous_response_id."""
should NOT leak through previous_response_id.
"""
def test_old_instructions_stripped_from_prev_msg(self):
"""System message in prev_msg must be dropped so the new request's
instructions are the only system message in the conversation."""
instructions are the only system message in the conversation.
"""
prev = [
{"role": "system", "content": "old instructions"},
{"role": "user", "content": "What is 2+2?"},
@@ -860,7 +862,8 @@ class TestConstructInputMessagesInstructionsLeak:
def test_no_instructions_in_new_request(self):
"""If the new request has no instructions, old ones should still
be stripped -- they must not carry over."""
be stripped -- they must not carry over.
"""
prev = [
{"role": "system", "content": "old instructions"},
{"role": "user", "content": "Hi"},
@@ -81,7 +81,7 @@ def _new_online_renderer() -> OnlineRenderer:
class MockConversationContext(ConversationContext):
"""Mock conversation context for testing"""
"""Mock conversation context for testing."""
def __init__(self):
self.init_tool_sessions_called = False
@@ -123,7 +123,7 @@ def test_serialize_message_pydantic_model_returns_dict() -> None:
@pytest.fixture
def mock_serving_responses():
"""Create a mock OpenAIServingResponses instance"""
"""Create a mock OpenAIServingResponses instance."""
serving_responses = MagicMock(spec=OpenAIServingResponses)
serving_responses.tool_server = MagicMock(spec=ToolServer)
return serving_responses
@@ -131,13 +131,13 @@ def mock_serving_responses():
@pytest.fixture
def mock_context():
"""Create a mock conversation context"""
"""Create a mock conversation context."""
return MockConversationContext()
@pytest.fixture
def mock_exit_stack():
"""Create a mock async exit stack"""
"""Create a mock async exit stack."""
return MagicMock(spec=AsyncExitStack)
@@ -550,7 +550,7 @@ def test_responses_render_result_rejects_non_single_prompt(engine_inputs):
class TestInitializeToolSessions:
"""Test class for _initialize_tool_sessions method"""
"""Test class for _initialize_tool_sessions method."""
@pytest.fixture(params=[ParsableContext, HarmonyContext])
def tool_context(self, request):
@@ -635,7 +635,7 @@ class TestInitializeToolSessions:
@pytest_asyncio.fixture
async def serving_responses_instance(self):
"""Create a real OpenAIServingResponses instance for testing"""
"""Create a real OpenAIServingResponses instance for testing."""
# Create minimal mocks for required dependencies
engine_client = MagicMock()
@@ -802,8 +802,7 @@ class TestInitializeToolSessions:
async def test_initialize_tool_sessions(
self, serving_responses_instance, mock_context, mock_exit_stack
):
"""Test that method works correctly with only MCP tools"""
"""Test that method works correctly with only MCP tools."""
request = ResponsesRequest(input="test input", tools=[])
# Call the method
@@ -852,11 +851,11 @@ class TestInitializeToolSessions:
class TestValidateGeneratorInput:
"""Test class for _validate_generator_input method"""
"""Test class for _validate_generator_input method."""
@pytest_asyncio.fixture
async def serving_responses_instance(self):
"""Create a real OpenAIServingResponses instance for testing"""
"""Create a real OpenAIServingResponses instance for testing."""
# Create minimal mocks for required dependencies
engine_client = MagicMock()
@@ -884,7 +883,7 @@ class TestValidateGeneratorInput:
return instance
def test_validate_generator_input(self, serving_responses_instance):
"""Test _validate_generator_input with valid prompt length"""
"""Test _validate_generator_input with valid prompt length."""
# Create an engine prompt with valid length (less than max_model_len)
valid_prompt_token_ids = list(range(5)) # 5 tokens < 100 max_model_len
engine_input = tokens_input(valid_prompt_token_ids)
@@ -999,7 +998,7 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
class TestExtractAllowedToolsFromMcpRequests:
"""Test class for _extract_allowed_tools_from_mcp_requests function"""
"""Test class for _extract_allowed_tools_from_mcp_requests function."""
def test_extract_allowed_tools_basic_formats(self):
"""Test extraction with list format, object format, and None."""
@@ -1113,7 +1112,7 @@ class TestHarmonyPreambleStreaming:
return item
def test_preamble_delta_emits_text_events(self) -> None:
"""commentary + recipient=None should emit output_text.delta events."""
"""Commentary + recipient=None should emit output_text.delta events."""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_content_delta_events,
)
@@ -1146,7 +1145,7 @@ class TestHarmonyPreambleStreaming:
assert "response.output_item.added" not in type_names
def test_commentary_with_function_recipient_not_preamble(self) -> None:
"""commentary + recipient='functions.X' must NOT use preamble path."""
"""Commentary + recipient='functions.X' must NOT use preamble path."""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_content_delta_events,
)
@@ -1164,7 +1163,8 @@ class TestHarmonyPreambleStreaming:
def test_preamble_done_emits_text_done_events(self) -> None:
"""Completed preamble should emit text done + content_part done +
output_item done, same shape as final channel."""
output_item done, same shape as final channel.
"""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_previous_item_done_events,
)
@@ -1184,8 +1184,9 @@ class TestHarmonyPreambleStreaming:
assert "response.output_item.done" in type_names
def test_commentary_with_recipient_no_preamble_done(self) -> None:
"""commentary + recipient='functions.X' should route to function call
done, not preamble done."""
"""Commentary + recipient='functions.X' should route to function call
done, not preamble done.
"""
from vllm.entrypoints.openai.responses.streaming_events import (
emit_previous_item_done_events,
)
@@ -1331,7 +1332,8 @@ def _mock_parser_with_reasoning(serving, delta_sequence: list[DeltaMessage]):
class TestStreamingReasoningToContentTransition:
"""Tests for _process_simple_streaming_events reasoning-to-content
transition, specifically the fix for mixed deltas that carry both
reasoning and content simultaneously."""
reasoning and content simultaneously.
"""
@pytest.mark.asyncio
async def test_mixed_delta_reasoning_and_content_emits_reasoning_delta(
@@ -1341,8 +1343,8 @@ class TestStreamingReasoningToContentTransition:
and content set (e.g. reasoning end and content start in the same
chunk), the trailing reasoning text must be emitted as a
ResponseReasoningTextDeltaEvent and included in the
ResponseReasoningTextDoneEvent text."""
ResponseReasoningTextDoneEvent text.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -1411,8 +1413,8 @@ class TestStreamingReasoningToContentTransition:
self, monkeypatch
):
"""When the transition from reasoning to content is clean (no mixed
delta), no extra reasoning delta event should be emitted."""
delta), no extra reasoning delta event should be emitted.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -1473,8 +1475,8 @@ class TestStreamingReasoningToContentTransition:
async def test_reasoning_only_stream_no_content(self, monkeypatch):
"""When the stream has only reasoning deltas and no content, the
reasoning done event should be emitted at finalization with the
full accumulated text, and no text delta events should appear."""
full accumulated text, and no text delta events should appear.
"""
monkeypatch.setattr(envs, "VLLM_USE_EXPERIMENTAL_PARSER_CONTEXT", False)
serving = _make_serving_instance_with_reasoning()
@@ -143,7 +143,8 @@ async def test_streaming_output_consistency(client: OpenAI, model_name: str):
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_streaming_logprobs(client: OpenAI, model_name: str):
"""Test that streaming with logprobs returns valid logprob data on
output_text.delta events and that top_logprobs has the requested count."""
output_text.delta events and that top_logprobs has the requested count.
"""
response = await client.responses.create(
model=model_name,
input="Say hello.",
@@ -124,7 +124,8 @@ class TestProcessorCompoundDeltas:
def test_split_name_and_args_same_index(self):
"""Regression: parsers like KimiK2 emit name and args as separate
DeltaToolCalls at the same index within one DeltaMessage."""
DeltaToolCalls at the same index within one DeltaMessage.
"""
tc_name = _make_tool_call(0, name="get_weather")
tc_args = _make_tool_call(0, arguments='{"city":"SF"}')
delta = DeltaMessage(tool_calls=[tc_name, tc_args])
@@ -140,7 +141,8 @@ class TestProcessorCompoundDeltas:
def test_reasoning_to_content_transition(self):
"""Regression: the old special case in emit_delta handled this;
now split_delta handles it generically."""
now split_delta handles it generically.
"""
processor = SimpleStreamingEventProcessor()
_run_through_processor(processor, DeltaMessage(reasoning="think"))
assert processor.state.current_state == _StateType.REASONING
@@ -83,8 +83,7 @@ def before_generate_case(context: schemathesis.HookContext, strategy):
assert op is not None
def no_invalid_types(case: schemathesis.Case):
"""
Skips tool_calls with `"type": "custom"` which schemathesis incorrectly
"""Skips tool_calls with `"type": "custom"` which schemathesis incorrectly
generates instead of the valid `"type": "function"`.
Example test case that is skipped:
@@ -25,7 +25,8 @@ def _model_config() -> Mock:
def test_completion_flag_forwarded_to_tok_params():
"""build_tok_params must forward return_token_offsets, defaulting to
False (zero behavioral change for existing callers) and coercing JSON
null to False via the bool() guard."""
null to False via the bool() guard.
"""
cfg = _model_config()
default = CompletionRequest(model="m", prompt="hi")
@@ -40,7 +41,8 @@ def test_completion_flag_forwarded_to_tok_params():
def test_chat_flag_forwarded_to_tok_params():
"""Chat build_tok_params has its own (max_completion_tokens) branch, so
its return_token_offsets forwarding is verified independently."""
its return_token_offsets forwarding is verified independently.
"""
cfg = _model_config()
messages = [{"role": "user", "content": "hi"}]
@@ -64,7 +66,8 @@ def test_generate_request_token_offsets_default_none():
def test_generate_request_token_offsets_survive_json_round_trip():
"""GenerateRequest crosses the disagg serialization boundary; the
tuple[int, int] offsets must survive model_dump and re-validate."""
tuple[int, int] offsets must survive model_dump and re-validate.
"""
req = GenerateRequest(
token_ids=[10, 20],
sampling_params=SamplingParams(),
@@ -189,8 +189,7 @@ async def test_chat_completion_with_tool_use(server):
@pytest.mark.asyncio
async def test_comparison_with_prompt_logprobs_and_logprobs(server):
"""
Test that token_ids align with prompt_logprobs and
"""Test that token_ids align with prompt_logprobs and
logprobs when return_tokens_as_token_ids is enabled.
"""
async with server.get_async_client() as client:
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for stop_token_ids propagation from default_sampling_params
"""Unit tests for stop_token_ids propagation from default_sampling_params
to SamplingParams in ChatCompletionRequest and CompletionRequest.
Regression test for https://github.com/vllm-project/vllm/issues/22519
+1 -2
View File
@@ -16,8 +16,7 @@ from vllm.entrypoints.serve.engine.protocol import UsageInfo
async def accumulate_streaming_response(
stream_generator: AsyncGenerator[str, None],
) -> ChatCompletionResponse:
"""
Accumulate streaming SSE chunks into a complete ChatCompletionResponse.
"""Accumulate streaming SSE chunks into a complete ChatCompletionResponse.
This helper parses the SSE format and builds up the complete response
by combining all the delta chunks.
@@ -30,8 +30,7 @@ def llm(vllm_runner):
@pytest.mark.skip_global_cleanup
def test_tiling_engine_basic(llm):
"""
Basic test with a small number of prompts (less than max_num_seqs).
"""Basic test with a small number of prompts (less than max_num_seqs).
No tiling should be triggered, but the engine still processes correctly.
"""
prompts = ["Hello", "World"]
@@ -41,8 +40,7 @@ def test_tiling_engine_basic(llm):
@pytest.mark.skip_global_cleanup
def test_tiling_engine_many_requests(llm):
"""
Test with a large number of prompts that exceeds max_num_seqs.
"""Test with a large number of prompts that exceeds max_num_seqs.
This verifies that _run_tiling_engine correctly chunks requests,
processes all of them, and returns outputs in the correct order.
"""
@@ -54,8 +52,7 @@ def test_tiling_engine_many_requests(llm):
@pytest.mark.skip_global_cleanup
def test_tiling_engine_with_pooling_params(llm):
"""
Test the tiling engine when different PoolingParams are provided.
"""Test the tiling engine when different PoolingParams are provided.
The engine must handle a list of params that matches the number of prompts.
"""
num_prompts = 10
@@ -77,8 +74,7 @@ def test_tiling_engine_with_pooling_params(llm):
@pytest.mark.skip_global_cleanup
def test_tiling_engine_abort_on_exception(llm):
"""
Test that abort_request IS called with the correct arguments when an
"""Test that abort_request IS called with the correct arguments when an
exception occurs inside the engine's step() loop.
"""
prompts = ["Prompt 0", "Prompt 1", "Prompt 2"]
@@ -111,7 +111,8 @@ def test_basic_embed(server: RemoteOpenAIServer, model_name: str):
def test_unsupported_input_type_rejected(server: RemoteOpenAIServer, model_name: str):
"""An input_type not defined in the model's prompt config should be
rejected with a 400 error."""
rejected with a 400 error.
"""
body = {
"model": model_name,
"input_type": "nonexistent_type",
@@ -138,7 +139,8 @@ def test_omitted_input_type_accepted(server: RemoteOpenAIServer, model_name: str
def test_v1_v2_parity(server: RemoteOpenAIServer, model_name: str):
"""v1 (OpenAI) and v2 (Cohere) endpoints should produce the same
float embeddings for a generic model."""
float embeddings for a generic model.
"""
texts = ["hello world"]
v2 = _cohere_embed(server, model_name, texts=texts, embedding_types=["float"])
v1 = _openai_embed(server, model_name, texts)
@@ -76,7 +76,8 @@ def test_single_text_parity(server: RemoteOpenAIServer):
def test_batch_parity(server: RemoteOpenAIServer):
"""A batch of texts should produce equivalent embeddings via both APIs,
in the same order."""
in the same order.
"""
texts = [
"machine learning",
"deep learning",
@@ -241,7 +241,8 @@ class TestResolveTruncation:
def test_truncate_none_with_max_tokens(self):
"""truncate=NONE should NOT set truncate_prompt_tokens; the
max_tokens limit is enforced separately via _check_max_tokens."""
max_tokens limit is enforced separately via _check_max_tokens.
"""
req = self._make_request(truncate="NONE", max_tokens=10)
tokens, side = EmbedIOProcessor._resolve_cohere_truncation(req)
assert tokens is None
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Run `pytest tests/entrypoints/openai/test_embedding_dimensions.py`.
"""
"""Run `pytest tests/entrypoints/openai/test_embedding_dimensions.py`."""
import openai
import pytest
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Test cases for long text embedding with automatic chunking mechanism.
"""Test cases for long text embedding with automatic chunking mechanism.
This test suite validates vLLM's automatic chunking functionality for handling
text inputs that exceed the model's maximum token length, specifically targeting
@@ -241,8 +240,8 @@ async def test_long_text_embedding_1500_chars(
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
):
"""Test embedding processing for ~1500 character long text
(~1028 tokens, exceeding 512 token limit)."""
(~1028 tokens, exceeding 512 token limit).
"""
# Verify text length
# Verify text has sufficient word count (approximately 1500 words)
word_count = len(LONG_TEXT_1500_WORDS.split())
@@ -290,8 +289,8 @@ async def test_long_text_embedding_2500_chars(
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
):
"""Test embedding processing for ~2500 character long text
(~2048 tokens, requiring multiple chunks)."""
(~2048 tokens, requiring multiple chunks).
"""
# Verify text length
# Verify text has sufficient word count (approximately 2500 words)
word_count = len(LONG_TEXT_2500_WORDS.split())
@@ -339,7 +338,6 @@ async def test_batch_long_text_embedding(
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
):
"""Test batch long text embedding processing."""
input_texts = [
LONG_TEXT_1500_WORDS,
LONG_TEXT_2500_WORDS,
@@ -384,8 +382,8 @@ async def test_chunked_vs_normal_consistency(
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
):
"""Test consistency between chunked and
normal processing (using short text)."""
normal processing (using short text).
"""
# Use a short text within the 512 token limit
short_text = (
"Artificial intelligence technology is changing our world, "
@@ -424,7 +422,6 @@ async def test_chunked_processing_response_format(
client_with_chunked_processing: openai.AsyncOpenAI, model_name: str
):
"""Test response format and structure during chunked processing."""
# Test with long text to trigger chunking
embedding_response = await client_with_chunked_processing.embeddings.create(
model=model_name,
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Unit tests for Cohere embed protocol: build_typed_embeddings and its
underlying packing helpers, plus Cohere-specific serving helpers."""
underlying packing helpers, plus Cohere-specific serving helpers.
"""
import struct
@@ -454,7 +454,8 @@ async def test_derender_completion_empty_generate_responses(client):
@pytest.mark.asyncio
async def test_derender_completion_logprobs(client):
"""token_id:N placeholders in logprobs are resolved; CompletionLogProbs
flat-list structure is returned with non-empty tokens and text_offsets."""
flat-list structure is returned with non-empty tokens and text_offsets.
"""
gr1 = await _render_completion(client, "Hello world")
ids1 = gr1["token_ids"][:3]
token_id = ids1[0]
@@ -555,7 +556,7 @@ async def test_derender_chat_oversized_token_ids_rejected(client):
@pytest.mark.asyncio
async def test_derender_chat_too_many_choices_rejected(client):
"""choices count exceeding VLLM_MAX_N_SEQUENCES returns 400."""
"""Choices count exceeding VLLM_MAX_N_SEQUENCES returns 400."""
# Default VLLM_MAX_N_SEQUENCES is 16384; use a larger count.
oversized_choices = [
{"index": i, "token_ids": [42], "finish_reason": "stop"} for i in range(20_000)
@@ -121,7 +121,8 @@ async def _disagg(
def _tool_sig(response_choice: dict) -> list[tuple[str, dict]]:
"""[(name, json normalized args)] so key ordering / whitespace don't
cause false negatives."""
cause false negatives.
"""
return [
(tc["function"]["name"], json.loads(tc["function"]["arguments"]))
for tc in (response_choice["message"].get("tool_calls") or [])
@@ -143,7 +144,8 @@ async def _run_parity_case(
client: httpx.AsyncClient, messages: list[dict], **extra
) -> tuple[dict, dict]:
"""Run the coupled request then feed its generated tokens into the
disaggregated derender endpoint. Returns (coupled, disagg)."""
disaggregated derender endpoint. Returns (coupled, disagg).
"""
coupled = await _coupled(client, messages, **extra)
ch = coupled["choices"][0]
chat_request = {"model": MODEL, "messages": messages, **extra}
@@ -203,7 +205,8 @@ async def test_parity_tool_call(client):
@pytest.mark.asyncio
async def test_parity_reasoning_and_tool_call(client):
"""Combined reasoning + tool call parity means the highest drift risk
since it exercises both parser branches on the same output."""
since it exercises both parser branches on the same output.
"""
messages = [{"role": "user", "content": "What's the weather in Paris?"}]
coupled, disagg = await _run_parity_case(
client,
@@ -41,7 +41,6 @@ def _make_stream_chunk(
usage: dict | None = None,
) -> GenerateStreamResponse:
"""Build a GenerateStreamResponse SSE chunk."""
return GenerateStreamResponse(
request_id=request_id,
choices=[
@@ -61,7 +60,6 @@ def _make_usage_chunk(
request_id: str = "test-req",
) -> GenerateStreamResponse:
"""Build a usage only final SSE chunk (empty choices)."""
return GenerateStreamResponse(
request_id=request_id,
choices=[],
@@ -531,7 +529,6 @@ async def client(server):
async def _render_chat(client) -> dict:
"""Render a minimal chat request and return the GenerateRequest dict."""
resp = await client.post(
"/v1/chat/completions/render",
json={
@@ -337,7 +337,6 @@ async def test_chat_completion_render_multi_turn(client):
@pytest.mark.asyncio
async def test_chat_completion_render_with_stream_true(client):
"""Render accepts stream params but still returns JSON (non-streamed)."""
response = await client.post(
"/v1/chat/completions/render",
json={
@@ -456,7 +455,8 @@ async def test_chat_completion_render_with_sampling_params(client):
@pytest.mark.asyncio
async def test_completion_render_emits_token_offsets(client):
"""With return_token_offsets, /v1/completions/render returns per-token
(start, end) char offsets aligned with token_ids."""
(start, end) char offsets aligned with token_ids.
"""
prompt = "Hello, world."
response = await client.post(
"/v1/completions/render",
@@ -481,7 +481,8 @@ async def test_completion_render_emits_token_offsets(client):
@pytest.mark.asyncio
async def test_completion_render_default_no_token_offsets(client):
"""Without the flag, token_offsets must be null (existing responses
unchanged)."""
unchanged).
"""
response = await client.post(
"/v1/completions/render",
json={
@@ -498,7 +499,8 @@ async def test_completion_render_default_no_token_offsets(client):
@pytest.mark.asyncio
async def test_chat_render_emits_token_offsets(client):
"""With return_token_offsets, /v1/chat/completions/render returns
per-token offsets relative to the templated prompt string."""
per-token offsets relative to the templated prompt string.
"""
response = await client.post(
"/v1/chat/completions/render",
json={
@@ -672,7 +674,8 @@ async def test_chat_completion_render_assistant_tokens_mask_with_generation_tags
client,
):
"""With a ``{% generation %}``-enabled template, the mask marks assistant
tokens and the masked tokens decode to the assistant content."""
tokens and the masked tokens decode to the assistant content.
"""
response = await client.post(
"/v1/chat/completions/render",
json={
@@ -16,7 +16,6 @@ VISION_MODEL_NAME = "Qwen/Qwen3-VL-2B-Instruct"
@pytest.fixture(scope="module")
def vision_server():
"""Vision-capable server used for multimodal /render tests."""
args = [
"--enforce-eager",
"--max-model-len",
@@ -48,7 +47,6 @@ async def test_chat_completion_render_with_base64_image_url(
local_asset_server,
):
"""Render a multimodal chat request and verify tokens are returned."""
image = local_asset_server.get_image_asset("RGBA_comp.png")
data_url = encode_image_url(image, format="PNG")
@@ -112,7 +110,6 @@ async def test_tokenize_matches_render_for_multimodal_input(
local_asset_server,
):
"""`/tokenize` should match `/v1/chat/completions/render` token output."""
image = local_asset_server.get_image_asset("RGBA_comp.png")
data_url = encode_image_url(image, format="PNG")
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Roundtrip tests for multimodal serde used by the
"""Roundtrip tests for multimodal serde used by the
token_in_token_out generate endpoint.
"""
@@ -25,7 +25,8 @@ def _base_payload() -> dict:
def test_omitted_max_tokens_is_not_provided():
"""Body without ``max_tokens`` must surface as 'not provided' so the
server can apply its own default instead of the dataclass 16."""
server can apply its own default instead of the dataclass 16.
"""
req = GenerateRequest.model_validate(_base_payload())
# SamplingParams' dataclass default leaks through the parsed instance —
# this is exactly the bug the server-side defaulting works around.
@@ -35,7 +36,8 @@ def test_omitted_max_tokens_is_not_provided():
def test_explicit_max_tokens_is_provided():
"""Even when the client picks the same value as the dataclass default,
it must register as explicitly set so the server won't override it."""
it must register as explicitly set so the server won't override it.
"""
payload = _base_payload()
payload["sampling_params"] = {"max_tokens": 16}
req = GenerateRequest.model_validate(payload)
@@ -67,7 +69,8 @@ def test_json_roundtrip_preserves_provided_keys():
def test_internal_instance_construction_treats_all_as_provided():
"""When internal callers build ``GenerateRequest`` from a pre-resolved
``SamplingParams`` instance, every field is considered explicitly set
so server-side defaulting can't clobber values resolved upstream."""
so server-side defaulting can't clobber values resolved upstream.
"""
sp = SamplingParams(max_tokens=500, temperature=0.0)
req = GenerateRequest(token_ids=[1, 2, 3], sampling_params=sp)
assert req.is_sampling_param_provided("max_tokens")
+2 -2
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Shared fixtures and helpers for the RL lifecycle test suite.
"""Shared fixtures and helpers for the RL lifecycle test suite.
All test modules under this directory import from here to avoid duplication.
@@ -92,6 +91,7 @@ def server(
port: HTTP port to bind (caller is responsible for uniqueness).
timeout: Seconds to wait for /health before giving up.
dummy_weights: If True, use --load-format dummy (fast, no real weights).
"""
env = {**os.environ, "VLLM_SERVER_DEV_MODE": "1"}
base = _DUMMY_ARGS if dummy_weights else _BASE_ARGS
@@ -25,7 +25,7 @@ class TestWorkerExtension:
)
def return_none(self, *args, **kwargs) -> None:
"""Test method that does not return anything"""
"""Test method that does not return anything."""
return
@@ -48,7 +48,7 @@ def server():
def test_get_model_name(server):
"""Test basic response"""
"""Test basic response."""
response = requests.post(
server.url_for("collective_rpc"), json={"method": "get_model_name"}
)
@@ -59,7 +59,7 @@ def test_get_model_name(server):
def test_return_none(server):
"""Test return none"""
"""Test return none."""
response = requests.post(
server.url_for("collective_rpc"), json={"method": "return_none"}
)
@@ -69,7 +69,7 @@ def test_return_none(server):
def test_echo_args_kwargs(server):
"""Test args, kwargs, and dict response"""
"""Test args, kwargs, and dict response."""
args = ["arg1", "arg2"]
kwargs = {"key1": "value1", "key2": "value2"}
response = requests.post(
+1 -2
View File
@@ -87,8 +87,7 @@ def test_sleep_mode():
def _get_sleep_metrics_from_api(response: requests.Response):
"""Return (awake, weights_offloaded, discard_all)"""
"""Return (awake, weights_offloaded, discard_all)."""
awake, weights_offloaded, discard_all = None, None, None
for family in text_string_to_metric_families(response.text):
@@ -22,7 +22,8 @@ def test_sanitize_message():
class TestSanitizeMessageFilePaths:
"""sanitize_message should also strip file paths and traceback
frames, not just memory addresses - see #31683."""
frames, not just memory addresses - see #31683.
"""
def test_strips_traceback_style_frame(self):
msg = (
@@ -44,7 +45,8 @@ class TestSanitizeMessageFilePaths:
def test_strips_single_parent_container_path(self):
"""Regression: /app/server.py and /workspace/server.py (common in
container deployments) were missed by the original {2,} quantifier."""
container deployments) were missed by the original {2,} quantifier.
"""
assert "/app/" not in sanitize_message("Error in /app/server.py")
assert "/workspace/" not in sanitize_message("Error in /workspace/server.py")
@@ -24,7 +24,8 @@ from vllm.entrypoints.serve.exception_handling.handlers.validation import (
def _fake_request(log_error_stack: bool = False) -> SimpleNamespace:
"""Minimal stand-in for a FastAPI Request - just enough for the
handler to read req.app.state.args.log_error_stack."""
handler to read req.app.state.args.log_error_stack.
"""
return SimpleNamespace(
app=SimpleNamespace(
state=SimpleNamespace(args=SimpleNamespace(log_error_stack=log_error_stack))
@@ -35,7 +36,8 @@ def _fake_request(log_error_stack: bool = False) -> SimpleNamespace:
class TestValidationErrorParamFallback:
"""Ensure `param` falls back to the Pydantic error's `loc` when no
custom VLLMValidationError context is present."""
custom VLLMValidationError context is present.
"""
@pytest.mark.parametrize(
("error_type", "msg"),
@@ -59,7 +61,8 @@ class TestValidationErrorParamFallback:
async def test_param_fallback_does_not_crash_on_non_dict_error(self):
"""Schemathesis fuzzing found that errors[0] isn't always a dict.
The fallback must not crash in that case - it should just leave
param as None instead of raising."""
param as None instead of raising.
"""
exc = RequestValidationError(["some unexpected non-dict error"])
response = await validation_exception_handler(_fake_request(), exc)
@@ -97,7 +100,8 @@ class TestCleanLocForParam:
def test_all_internal_falls_back_to_raw_join(self):
"""If every loc segment looks internal, fall back to the raw
dot-join rather than returning an empty string."""
dot-join rather than returning an empty string.
"""
loc = ("function-wrap[__log_extra_fields__()]",)
assert clean_loc_for_param(loc) == "function-wrap[__log_extra_fields__()]"
@@ -105,7 +109,8 @@ class TestCleanLocForParam:
class TestValidationErrorDoesNotLeakServerPaths:
"""FastAPI sets endpoint_file/line/function/path on the exception
during routing, not in the constructor - so we set them manually
here to reproduce the real leak. See #31683."""
here to reproduce the real leak. See #31683.
"""
@pytest.mark.asyncio
async def test_handler_strips_endpoint_file_context(self):
@@ -21,7 +21,7 @@ MODEL_NAME = "Qwen/Qwen3-0.6B"
@pytest.fixture(scope="module")
def server_args(request: pytest.FixtureRequest) -> list[str]:
"""Provide extra arguments to the server via indirect parametrization
"""Provide extra arguments to the server via indirect parametrization.
Usage:
@@ -403,8 +403,7 @@ async def _poll_until(
def _get_running_metrics_from_api(server: RemoteOpenAIServer):
"""Return (running_count, waiting_count, kv_cache_usage)"""
"""Return (running_count, waiting_count, kv_cache_usage)."""
response = requests.get(server.url_for("metrics"))
assert response.status_code == HTTPStatus.OK
@@ -245,7 +245,8 @@ async def test_multiple_lora_adapters(
client: openai.AsyncOpenAI, tmp_path, qwen3_lora_files
):
"""Validate that many loras can be dynamically registered and inferenced
with concurrently"""
with concurrently
"""
# This test file configures the server with --max-cpu-loras=2 and this test
# will concurrently load 10 adapters, so it should flex the LRU cache
@@ -72,7 +72,8 @@ class MockModelConfig:
@pytest.fixture(params=get_args(SupportedTask))
def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]:
"""For each supported task, build an app with only that task's routers,
extract all routes, and return the task name and routes."""
extract all routes, and return the task name and routes.
"""
task = request.param
# Enable development mode to register all routes (including dev-only routes).
monkeypatch.setenv("VLLM_SERVER_DEV_MODE", "1")
@@ -98,7 +99,8 @@ def task_routes(request, monkeypatch) -> tuple[str, list[tuple[str, list[str]]]]
def test_auto_discovered_protected_routes_require_auth(task_routes):
"""For every auto-discovered route that starts with a guarded prefix,
verify that authentication is enforced."""
verify that authentication is enforced.
"""
task, routes = task_routes
app = _create_app_with_mock_routes(routes)
client = TestClient(app)
@@ -132,7 +134,8 @@ def test_auto_discovered_protected_routes_require_auth(task_routes):
def test_auto_discovered_unprotected_routes_no_auth(task_routes):
"""For every auto-discovered route that does NOT start with a guarded
prefix, verify that no authentication is required."""
prefix, verify that no authentication is required.
"""
task, routes = task_routes
app = _create_app_with_mock_routes(routes)
client = TestClient(app)
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Tests for middleware that's off by default and can be toggled through
"""Tests for middleware that's off by default and can be toggled through
server arguments, mainly --api-key and --enable-request-id-headers.
"""
@@ -114,7 +114,8 @@ class TestHandlerOverrideIntegration:
def test_customer_script_functions_auto_loaded(self, monkeypatch, tmp_path):
"""Test customer scenario: script functions automatically override
framework defaults."""
framework defaults.
"""
try:
from model_hosting_container_standards.sagemaker.config import (
SageMakerEnvVars,
@@ -175,7 +176,8 @@ async def custom_sagemaker_invocation_handler(request: Request):
def test_customer_decorator_usage(self, monkeypatch, tmp_path):
"""Test customer scenario: using @custom_ping_handler and
@custom_invocation_handler decorators."""
@custom_invocation_handler decorators.
"""
try:
from model_hosting_container_standards.sagemaker.config import (
SageMakerEnvVars,
@@ -231,7 +233,8 @@ async def my_invoke(request: Request):
def test_handler_priority_order(self, monkeypatch, tmp_path):
"""Test priority: @custom_ping_handler/@custom_invocation_handler
decorators vs script functions."""
decorators vs script functions.
"""
try:
from model_hosting_container_standards.sagemaker.config import (
SageMakerEnvVars,
@@ -304,7 +307,8 @@ async def custom_sagemaker_invocation_handler(request: Request):
def test_environment_variable_script_loading(self, monkeypatch, tmp_path):
"""Test that environment variables correctly specify script location
and loading."""
and loading.
"""
try:
from model_hosting_container_standards.sagemaker.config import (
SageMakerEnvVars,
@@ -416,7 +420,8 @@ async def custom_sagemaker_invocation_handler(request: Request):
def test_handler_env_var_override(self, monkeypatch, tmp_path):
"""Test CUSTOM_FASTAPI_PING_HANDLER and CUSTOM_FASTAPI_INVOCATION_HANDLER
environment variable overrides."""
environment variable overrides.
"""
try:
from model_hosting_container_standards.common.fastapi.config import (
FastAPIEnvVars,
@@ -510,7 +515,8 @@ async def custom_sagemaker_invocation_handler(request: Request):
def test_env_var_priority_over_decorator_and_script(self, monkeypatch, tmp_path):
"""Test that environment variables have highest priority over decorators
and script functions for both ping and invocation handlers."""
and script functions for both ping and invocation handlers.
"""
try:
from model_hosting_container_standards.common.fastapi.config import (
FastAPIEnvVars,
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Regression test: ``/tokenize`` must expand image placeholders for VLM models.
"""Regression test: ``/tokenize`` must expand image placeholders for VLM models.
Fixed by PR #34560 ("Move InputPreprocessor into Renderer (2/2)").
Before that change, ``/tokenize`` returned ~26 tokens for a message with an
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Regression test: calling ``/tokenize`` with multimodal data followed by
"""Regression test: calling ``/tokenize`` with multimodal data followed by
``/v1/chat/completions`` with the same data must not cause an error.
Ensures that the ``/tokenize`` endpoint does not pollute internal caches
@@ -52,8 +51,8 @@ async def test_tokenize_then_chat_completion_with_image(
local_asset_server,
):
"""Tokenize a multimodal message, then send the same message to chat
completions. The chat completion must succeed (not 500)."""
completions. The chat completion must succeed (not 500).
"""
image_url = local_asset_server.url_for("stop_sign.jpg")
messages = [
{
@@ -36,11 +36,13 @@ def test_should_include_usage_force_enables_continuous_usage(stream_options, exp
class TestGetMaxTokens:
"""Tests for get_max_tokens() to ensure generation_config's max_tokens
acts as a default when from model author, and as a ceiling when
explicitly set by the user."""
explicitly set by the user.
"""
def test_default_sampling_params_used_when_no_request_max_tokens(self):
"""When user doesn't specify max_tokens, generation_config default
should apply."""
should apply.
"""
result = get_max_tokens(
max_model_len=24000,
max_tokens=None,
@@ -51,7 +53,8 @@ class TestGetMaxTokens:
def test_request_max_tokens_not_capped_by_default_sampling_params(self):
"""When user specifies max_tokens in request, model author's
generation_config max_tokens must NOT cap it (fixes #34005)."""
generation_config max_tokens must NOT cap it (fixes #34005).
"""
result = get_max_tokens(
max_model_len=24000,
max_tokens=5000,
@@ -94,7 +97,8 @@ class TestGetMaxTokens:
def test_request_max_tokens_smaller_than_default(self):
"""When user explicitly requests fewer tokens than gen_config default,
that should be respected."""
that should be respected.
"""
result = get_max_tokens(
max_model_len=24000,
max_tokens=512,
@@ -239,7 +239,8 @@ def test_request_logger_log_outputs_integration():
def test_streaming_complete_logs_full_text_content():
"""Test that streaming complete logging includes
full accumulated text, not just token count."""
full accumulated text, not just token count.
"""
mock_logger = MagicMock()
with patch("vllm.entrypoints.serve.utils.request_logger.logger", mock_logger):
@@ -17,7 +17,8 @@ from vllm.entrypoints.serve.utils.sse_keep_alive import (
def test_disabled_returns_same_generator():
"""For 0, negative, and NaN intervals the exact same generator object must
be returned (identity), proving no wrapper or per-chunk overhead when
disabled."""
disabled.
"""
async def gen():
yield "x"
@@ -33,7 +34,8 @@ def test_disabled_returns_same_generator():
@pytest.mark.asyncio
async def test_keep_alive_during_silent_start():
"""A silent start (queue wait / prefill) emits keep-alive comments before
the first real chunk."""
the first real chunk.
"""
release = asyncio.Event()
async def gen():
@@ -55,7 +57,8 @@ async def test_keep_alive_during_silent_start():
@pytest.mark.asyncio
async def test_no_keep_alive_when_streaming_is_fast():
"""If chunks arrive faster than the interval, no comment is emitted and all
data is forwarded."""
data is forwarded.
"""
async def gen():
for chunk in ["a", "b", "c"]:
@@ -69,7 +72,8 @@ async def test_no_keep_alive_when_streaming_is_fast():
@pytest.mark.asyncio
async def test_keep_alive_between_chunks_does_not_drop_data():
"""Keep-alives interleaved with real chunks must never drop or reorder
data."""
data.
"""
release_b = asyncio.Event()
release_c = asyncio.Event()
@@ -135,7 +139,8 @@ async def test_upstream_cancelled_error_propagates():
@pytest.mark.asyncio
async def test_aclose_closes_upstream():
"""Closing a wrapper that is mid-stream must complete promptly and close
the upstream generator (regression for the earlier leaked-task hang)."""
the upstream generator (regression for the earlier leaked-task hang).
"""
finalized = asyncio.Event()
async def gen():
@@ -154,7 +159,8 @@ async def test_aclose_closes_upstream():
@pytest.mark.asyncio
async def test_client_disconnect_cancels_upstream():
"""Cancelling the consumer mid-stream must cancel the pending anext and
close the upstream generator so its cleanup runs."""
close the upstream generator so its cleanup runs.
"""
finalized = asyncio.Event()
async def gen():
@@ -181,7 +187,8 @@ async def test_client_disconnect_cancels_upstream():
@pytest.mark.asyncio
async def test_streaming_response_emits_comment():
"""A keep-alive comment must reach the client through the real
StreamingResponse used by the routers."""
StreamingResponse used by the routers.
"""
release = asyncio.Event()
async def gen():
@@ -220,7 +227,8 @@ async def test_streaming_response_emits_comment():
async def test_streaming_response_disconnect_closes_upstream():
"""On the ASGI 2.3 disconnect path used by the pinned Uvicorn, Starlette
cancels streaming and the wrapper's finally must close the upstream
generator."""
generator.
"""
finalized = asyncio.Event()
async def gen():
@@ -11,6 +11,7 @@ def add_attention_backend(server_args, attention_config):
Args:
server_args: List of server arguments to extend in-place.
attention_config: Dict with 'backend' key, or None.
"""
if attention_config and "backend" in attention_config:
server_args.extend(["--attention-backend", attention_config["backend"]])
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Evaluate Transcription API correctness by computing Word Error Rate (WER)
"""Evaluate Transcription API correctness by computing Word Error Rate (WER)
on a given ASR dataset. When provided, it will also compare the WER against
a baseline.
This simulates real work usage of the API and makes sure that the frontend and
@@ -295,7 +295,8 @@ async def test_session_update_invalid_model_returns_error(model_name):
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_commit_without_session_update_returns_error(model_name):
"""Test that committing before validating the model returns an error
and does not fall through to processing."""
and does not fall through to processing.
"""
server_args = ["--enforce-eager", "--max-model-len", "2048"]
if model_name.startswith("mistralai"):
@@ -18,9 +18,8 @@ _PATCH = "vllm.entrypoints.speech_to_text.base.serving"
@pytest.mark.asyncio
async def test_chunk_offsets_are_cumulative_not_nominal():
"""
chunk_start_offsets must be cumulative actual chunk lengths, not the old approach of
'idx * max_audio_clip_s'. When split_audio places a boundary before the
"""chunk_start_offsets must be cumulative actual chunk lengths, not the old approach
of 'idx * max_audio_clip_s'. When split_audio places a boundary before the
nominal 30 s mark, the old formula drifts; the fixed formula stays exact.
"""
# Chunks shorter than exactly 30 s, as split_audio produces when a quiet
@@ -238,8 +238,7 @@ async def test_stream_options(winning_call, whisper_client):
@pytest.mark.asyncio
async def test_sampling_params(mary_had_lamb, whisper_client):
"""
Compare sampling with params and greedy sampling to assert results
"""Compare sampling with params and greedy sampling to assert results
are different when extreme sampling parameters values are picked.
"""
transcription = await whisper_client.audio.transcriptions.create(
@@ -150,7 +150,6 @@ async def test_non_streaming_tool_call(
client: openai.AsyncOpenAI, server_config: ServerConfig
):
"""Test tool call in non-streaming mode."""
response = await client.chat.completions.create(
model=server_config["model_arg"],
messages=MESSAGES,
@@ -183,7 +182,6 @@ async def test_streaming_tool_call(
client: openai.AsyncOpenAI, server_config: ServerConfig
):
"""Test tool call in streaming mode."""
stream = await client.chat.completions.create(
model=server_config["model_arg"],
messages=MESSAGES,
@@ -230,7 +228,6 @@ async def test_non_streaming_product_tool_call(
client: openai.AsyncOpenAI, server_config: ServerConfig
):
"""Test tool call integer and boolean parameters in non-streaming mode."""
response = await client.chat.completions.create(
model=server_config["model_arg"],
messages=PRODUCT_MESSAGES,
@@ -272,7 +269,6 @@ async def test_streaming_product_tool_call(
client: openai.AsyncOpenAI, server_config: ServerConfig
):
"""Test tool call integer and boolean parameters in streaming mode."""
stream = await client.chat.completions.create(
model=server_config["model_arg"],
messages=PRODUCT_MESSAGES,
@@ -127,8 +127,7 @@ FUNC_ARGS_TIME = '{"city": "New York"}'
# Utility to extract reasoning and tool calls
# ==========================================================
def extract_reasoning_and_calls(chunks: list) -> tuple[str, list[str], list[str]]:
"""
Extract accumulated reasoning text and tool call arguments
"""Extract accumulated reasoning text and tool call arguments
from streaming chunks.
"""
reasoning: str = ""
@@ -165,7 +164,6 @@ def extract_reasoning_and_calls(chunks: list) -> tuple[str, list[str], list[str]
@pytest.mark.asyncio
async def test_calculator_tool_call_and_argument_accuracy(client: openai.AsyncOpenAI):
"""Verify calculator tool call is made and arguments are accurate."""
response = await client.chat.completions.create(
model=MODEL_NAME,
messages=MESSAGES_CALC,
@@ -205,7 +203,6 @@ async def test_calculator_tool_call_and_argument_accuracy(client: openai.AsyncOp
@pytest.mark.asyncio
async def test_streaming_tool_call_get_time_with_reasoning(client: openai.AsyncOpenAI):
"""Verify streamed reasoning and tool call behavior for get_time."""
stream = await client.chat.completions.create(
model=MODEL_NAME,
messages=MESSAGES_GET_TIME,
@@ -258,8 +255,7 @@ async def test_streaming_multiple_tools(client: openai.AsyncOpenAI):
@pytest.mark.asyncio
async def test_invalid_tool_call(client: openai.AsyncOpenAI):
"""
Verify that ambiguous instructions that should not trigger a tool
"""Verify that ambiguous instructions that should not trigger a tool
do not produce any tool calls.
"""
response = await client.chat.completions.create(
@@ -283,8 +279,7 @@ async def test_invalid_tool_call(client: openai.AsyncOpenAI):
@pytest.mark.asyncio
async def test_tool_call_with_temperature(client: openai.AsyncOpenAI):
"""
Verify model produces valid tool or text output
"""Verify model produces valid tool or text output
under non-deterministic sampling.
"""
response = await client.chat.completions.create(
@@ -940,7 +940,6 @@ def test_parse_chat_messages_audio_embeds_with_string(
audio_embeds_model_config,
):
"""Test audio_embeds with base64 string embedding data."""
import torch
# Create a sample audio embedding tensor
@@ -983,7 +982,6 @@ async def test_parse_chat_messages_audio_embeds_async(
audio_embeds_model_config,
):
"""Test audio_embeds with async futures."""
import torch
# Create a sample audio embedding tensor
@@ -2986,7 +2984,6 @@ def test_postprocess_messages_null_arguments_string():
@pytest.mark.asyncio
async def test_resolve_items_runs_modalities_concurrently_and_preserves_order():
"""Media fetches overlap while modality and item order are preserved."""
active_fetches = 0
max_active_fetches = 0
+14 -8
View File
@@ -51,7 +51,8 @@ async def generate_mock_outputs(
num_turns, prompt_token_counts, output_token_counts, cached_token_counts=None
):
"""Generate a sequence of mock RequestOutput objects to simulate multiple
turns."""
turns.
"""
if cached_token_counts is None:
cached_token_counts = [0] * num_turns
@@ -270,7 +271,8 @@ def test_reasoning_tokens_counting():
def test_preamble_tokens_not_counted_as_reasoning():
"""Preambles (commentary with no recipient) are visible user text,
not hidden reasoning. They must NOT inflate num_reasoning_tokens."""
not hidden reasoning. They must NOT inflate num_reasoning_tokens.
"""
context, parser = make_harmony_context()
parser.enqueue_chunk_result(reasoning_token_count=0)
@@ -287,7 +289,8 @@ def test_preamble_tokens_not_counted_as_reasoning():
def test_commentary_with_recipient_counted_as_reasoning():
"""Commentary directed at a tool (recipient != None) is hidden from
the user, so it should still count as reasoning tokens."""
the user, so it should still count as reasoning tokens.
"""
context, parser = make_harmony_context()
parser.enqueue_chunk_result(reasoning_token_count=3)
@@ -346,7 +349,8 @@ async def test_single_turn_no_tool_output():
@pytest.mark.asyncio
async def test_negative_tool_tokens_edge_case():
"""Test edge case where calculation could result in negative tool
tokens. We should log an error and clamp the value to 0."""
tokens. We should log an error and clamp the value to 0.
"""
# Use patch to check if logger.error was called
with patch("vllm.entrypoints.openai.responses.context.logger.error") as mock_log:
context, _ = make_harmony_context(available_tools=["browser"])
@@ -544,7 +548,6 @@ async def test_streaming_multi_turn_token_counting():
@pytest.mark.asyncio
async def test_streaming_message_synchronization():
"""Completed messages from append-local and flush segments sync into context."""
# Create a streaming context with some initial messages
initial_messages = [
Message(
@@ -687,7 +690,8 @@ def create_simple_context_output(
finished=True,
):
"""Helper to create a RequestOutput with customizable text for
SimpleContext tests."""
SimpleContext tests.
"""
if token_ids is None:
token_ids = []
return RequestOutput(
@@ -871,7 +875,8 @@ def test_simple_context_final_output():
def test_simple_context_output_messages_empty_text_with_tokens():
"""output_messages should be returned when tokens exist even if text is
empty (e.g. special tokens)."""
empty (e.g. special tokens).
"""
context = SimpleContext()
context.append_output(
create_simple_context_output(
@@ -889,7 +894,8 @@ def test_simple_context_output_messages_empty_text_with_tokens():
def test_simple_context_output_messages_no_mutation():
"""Each call to output_messages returns a fresh list; callers can't
corrupt internal state."""
corrupt internal state.
"""
context = SimpleContext()
context.append_output(
create_simple_context_output(
@@ -121,7 +121,8 @@ def test_get_world_size_tp1(vllm_runner):
@create_new_process_for_each_test()
def test_init_weight_transfer_engine_calls_engine(vllm_runner):
"""Test that init_weight_transfer_engine calls the engine's
init_transfer_engine method."""
init_transfer_engine method.
"""
if torch.accelerator.device_count() < 1:
pytest.skip("Need at least 1 GPU for this test")