[ROCm][CI] Stabilize 400 error return code for invalid schema inputs (#43016)

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
Andreas Karatzas
2026-05-24 10:06:49 +00:00
committed by GitHub
parent 357fddf614
commit 5940590855
11 changed files with 74 additions and 20 deletions
+19 -3
View File
@@ -1818,12 +1818,28 @@ def _postprocess_messages(messages: list[ConversationMessage]) -> None:
continue
for item in tool_calls:
if not isinstance(item, dict):
raise VLLMValidationError(
"assistant tool_calls entries must be objects.",
parameter="tool_calls",
)
function = item.get("function")
if item.get("type", "function") != "function" or not isinstance(
function, dict
):
raise VLLMValidationError(
"chat completions only support assistant tool_calls "
"of type 'function'.",
parameter="tool_calls",
)
# if arguments is None or empty string, set to {}
if content := item["function"].get("arguments"):
if content := function.get("arguments"):
if not isinstance(content, (dict, list)):
item["function"]["arguments"] = json.loads(content)
function["arguments"] = json.loads(content)
else:
item["function"]["arguments"] = {}
function["arguments"] = {}
def parse_chat_messages(
+1 -1
View File
@@ -151,7 +151,7 @@ async def build_async_engine_client_from_engine_args(
yield async_llm
finally:
if async_llm:
async_llm.shutdown()
async_llm.shutdown(timeout=vllm_config.shutdown_timeout)
def build_app(
@@ -218,8 +218,6 @@ class OpenAIServingChatBatch(OpenAIServingChat):
``check_batch_mode`` validator, so neither needs to be handled here.
"""
created_time = int(time.time())
role = self.get_chat_request_role(request) # type: ignore[arg-type]
final_results: dict[int, RequestOutput] = {}
try:
async for prompt_idx, res in merge_async_iterators(*generators):
@@ -275,6 +273,12 @@ class OpenAIServingChatBatch(OpenAIServingChat):
reasoning = None
content = output.text
role = (
self.response_role
if request.add_generation_prompt
else request.messages[prompt_idx][-1]["role"]
)
message = ChatMessage(role=role, reasoning=reasoning, content=content)
if request.echo:
@@ -909,7 +909,9 @@ class BatchChatCompletionRequest(OpenAIBaseModel):
- The ``n`` parameter must be 1 (or omitted).
"""
messages: list[list[ChatCompletionMessageParam]] = Field(..., min_length=1)
messages: list[Annotated[list[ChatCompletionMessageParam], Field(min_length=1)]] = (
Field(..., min_length=1)
)
model: str | None = None
# Shared sampling / generation fields — mirror ChatCompletionRequest.
+1 -1
View File
@@ -68,7 +68,7 @@ class GenerateRequest(BaseModel):
"through out the inference process and return in response."
),
)
token_ids: list[int]
token_ids: list[int] = Field(min_length=1)
"""The token ids to generate text from."""
@field_validator("token_ids")
+13 -1
View File
@@ -8,6 +8,7 @@ import time
from collections.abc import AsyncGenerator
from collections.abc import Sequence as GenericSequence
import msgspec
import numpy as np
import pybase64 as base64
from fastapi import Request
@@ -125,6 +126,18 @@ class ServingTokens(OpenAIServing):
if raw_request:
raw_request.state.request_metadata = request_metadata
sampling_params = request.sampling_params
max_num_seqs = self.engine_client.vllm_config.scheduler_config.max_num_seqs
if sampling_params.n > max_num_seqs:
return self.create_error_response(
f"sampling_params.n must be at most the server's max_num_seqs "
f"({max_num_seqs}), got {sampling_params.n}."
)
try:
msgspec.msgpack.encode(sampling_params)
except (OverflowError, TypeError, ValueError) as e:
return self.create_error_response(e)
engine_input: EngineInput
if features := request.features:
# Convert PlaceholderRangeInfo → PlaceholderRange per modality.
@@ -164,7 +177,6 @@ class ServingTokens(OpenAIServing):
# Schedule the request and get the result generator.
result_generator: AsyncGenerator[RequestOutput, None] | None = None
sampling_params = request.sampling_params
# Apply server-side ``max_tokens`` defaulting when the client did
# not set it, matching the OpenAI-compat endpoints. ``SamplingParams``