[Rebase] Rebase to vllm v0.19.0 (#2475)

This commit is contained in:
Zhou Taichang authored and GitHub committed 2026-04-04 15:03:32 +08:00
1 parent 4c031580cf
commit 2804a85e58
52 files changed
+437 -142

No files matched your search

+11 -2
View File
@@ -9,7 +9,7 @@ from __future__ import annotations
import asyncio
import time
from collections.abc import AsyncGenerator, Iterable, Sequence
from collections.abc import AsyncGenerator, Iterable, Mapping, Sequence
from typing import TYPE_CHECKING, Any
from vllm import TokensPrompt
@@ -88,7 +88,12 @@ class AsyncOmni(EngineClient, OmniBase):
else:
vllm_config = self.engine.stage_vllm_configs[stage_index]
io_processor_plugin = vllm_config.model_config.io_processor_plugin
self.io_processor = get_io_processor(vllm_config, io_processor_plugin)
renderer = self.renderer
if renderer is None:
from vllm.renderers import renderer_from_config
renderer = renderer_from_config(vllm_config)
self.io_processor = get_io_processor(vllm_config, renderer, io_processor_plugin)
def _get_comprehension_stage_index(self) -> int | None:
fallback_idx: int | None = None
@@ -159,6 +164,10 @@ class AsyncOmni(EngineClient, OmniBase):
tokenization_kwargs: dict[str, Any] | None = None,
sampling_params_list: Sequence[OmniSamplingParams] | None = None,
output_modalities: list[str] | None = None,
trace_headers: Mapping[str, str] | None = None,
priority: int = 0,
data_parallel_rank: int | None = None,
reasoning_ended: bool | None = None,
) -> AsyncGenerator[OmniRequestOutput, None]:
"""Generate outputs for the given prompt(s) asynchronously.
+4
View File
@@ -28,6 +28,10 @@ def main():
cli_env_setup()
from vllm_omni.entrypoints.cli.serve import _ensure_vllm_platform
_ensure_vllm_platform()
parser = FlexibleArgumentParser(
description="vLLM OMNI CLI",
epilog=VLLM_SUBCMD_PARSER_EPILOG.format(subcmd="[subcommand]"),
+32
View File
@@ -42,6 +42,37 @@ Search by using: `--help=<ConfigGroup>` to explore options by section (e.g.,
"""
def _ensure_vllm_platform():
"""Ensure vLLM's current_platform is valid before arg parsing.
Upstream vLLM's argument parser now instantiates DeviceConfig during
``make_arg_parser``, which requires a resolved platform with a non-empty
``device_type``. In some environments (e.g. editable installs with
broken package metadata), vLLM's own platform auto-detection may fail
and fall back to ``UnspecifiedPlatform``. When that happens, use the
Omni platform (which has its own detection logic) as a drop-in
replacement so that argument parsing succeeds.
"""
from vllm import platforms as vllm_platforms
if vllm_platforms.current_platform.is_unspecified():
from vllm_omni.platforms import current_omni_platform
if not current_omni_platform.is_unspecified():
vllm_platforms.current_platform = current_omni_platform
logger.debug(
"Replaced vLLM UnspecifiedPlatform with omni platform %s",
type(current_omni_platform).__name__,
)
else:
from vllm.platforms.cpu import CpuPlatform
vllm_platforms.current_platform = CpuPlatform()
logger.debug(
"Both vLLM and omni platforms are unspecified, falling back to CpuPlatform for arg parsing",
)
class OmniServeCommand(CLISubcommand):
"""The `serve` subcommand for the vLLM CLI."""
@@ -82,6 +113,7 @@ class OmniServeCommand(CLISubcommand):
usage="vllm serve [model_tag] --omni [options]",
)
_ensure_vllm_platform()
serve_parser = make_arg_parser(serve_parser)
serve_parser.epilog = VLLM_SUBCMD_PARSER_EPILOG.format(subcmd=self.name)
+6 -1
View File
@@ -639,6 +639,7 @@ async def omni_init_app_state(
OpenAIServingResponses(
engine_client,
state.openai_serving_models,
openai_serving_render=state.openai_serving_render,
request_logger=request_logger,
chat_template=resolved_chat_template,
chat_template_content_format=args.chat_template_content_format,
@@ -699,7 +700,8 @@ async def omni_init_app_state(
OpenAIServingPooling(
engine_client,
state.openai_serving_models,
supported_tasks=supported_tasks,
state.openai_serving_render,
supported_tasks=tuple(supported_tasks),
request_logger=request_logger,
chat_template=resolved_chat_template,
chat_template_content_format=args.chat_template_content_format,
@@ -746,6 +748,7 @@ async def omni_init_app_state(
state.openai_serving_tokenization = OpenAIServingTokenization(
engine_client,
state.openai_serving_models,
state.openai_serving_render,
request_logger=request_logger,
chat_template=resolved_chat_template,
chat_template_content_format=args.chat_template_content_format,
@@ -787,6 +790,7 @@ async def omni_init_app_state(
reasoning_parser=args.structured_outputs_config.reasoning_parser,
enable_prompt_tokens_details=args.enable_prompt_tokens_details,
enable_force_include_usage=args.enable_force_include_usage,
default_chat_template_kwargs=args.default_chat_template_kwargs,
)
if "generate" in supported_tasks
else None
@@ -795,6 +799,7 @@ async def omni_init_app_state(
ServingTokens(
engine_client,
state.openai_serving_models,
state.openai_serving_render,
request_logger=request_logger,
return_tokens_as_token_ids=args.return_tokens_as_token_ids,
enable_prompt_tokens_details=args.enable_prompt_tokens_details,
+18 -18
View File
@@ -62,7 +62,7 @@ from vllm.entrypoints.openai.parser.harmony_utils import (
from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
from vllm.entrypoints.openai.utils import maybe_filter_parallel_tool_calls
from vllm.entrypoints.utils import should_include_usage
from vllm.inputs.data import PromptType
from vllm.inputs import PromptType
from vllm.logger import init_logger
from vllm.outputs import RequestOutput
from vllm.reasoning import ReasoningParser
@@ -818,7 +818,7 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
# Prepare the tool parser if it's needed
try:
if tool_choice_auto and self.tool_parser:
tool_parsers: list[ToolParser | None] = [self.tool_parser(tokenizer)] * num_choices
tool_parsers: list[ToolParser | None] = [self.tool_parser(tokenizer, request.tools)] * num_choices
else:
tool_parsers = [None] * num_choices
except Exception as e:
@@ -1639,12 +1639,12 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
logprobs = None
if self.use_harmony:
reasoning_content, content, _ = parse_chat_output(token_ids)
reasoning, content, _ = parse_chat_output(token_ids)
if not request.include_reasoning:
reasoning_content = None
reasoning = None
if self.tool_parser is not None:
tool_parser = self.tool_parser(tokenizer)
tool_parser = self.tool_parser(tokenizer, request.tools)
# NOTE: We use token_ids for openai tool parser
tool_call_info = tool_parser.extract_tool_calls(
"",
@@ -1654,14 +1654,14 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
content = tool_call_info.content
message = ChatMessage(
role=role,
reasoning_content=reasoning_content,
reasoning=reasoning,
content=content,
tool_calls=tool_call_info.tool_calls,
)
else:
message = ChatMessage(
role=role,
reasoning_content=reasoning_content,
reasoning=reasoning,
content=content,
)
@@ -1682,11 +1682,11 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
if reasoning_parser:
# If the reasoning parser is enabled,
# tool calls are extracted exclusively from the content.
reasoning_content, content = reasoning_parser.extract_reasoning(output.text, request=request)
reasoning, content = reasoning_parser.extract_reasoning(output.text, request=request)
if not request.include_reasoning:
reasoning_content = None
reasoning = None
else:
reasoning_content = None
reasoning = None
content = output.text
auto_tools_called = False
@@ -1696,14 +1696,14 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
not isinstance(request.tool_choice, ChatCompletionNamedToolChoiceParam)
and request.tool_choice != "required"
):
message = ChatMessage(role=role, reasoning_content=reasoning_content, content=content)
message = ChatMessage(role=role, reasoning=reasoning, content=content)
# if the request uses tools and specified a tool choice
elif request.tool_choice and type(request.tool_choice) is ChatCompletionNamedToolChoiceParam:
tool_call_class = MistralToolCall if isinstance(tokenizer, MistralTokenizer) else ToolCall
message = ChatMessage(
role=role,
reasoning_content=reasoning_content,
reasoning=reasoning,
content="",
tool_calls=[
tool_call_class(
@@ -1745,13 +1745,13 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
)
for i, tool_call in enumerate(tool_calls)
],
reasoning_content=reasoning_content,
reasoning=reasoning,
)
# if the request doesn't use tool choice
# OR specifies to not use a tool
elif not request.tool_choice or request.tool_choice == "none":
message = ChatMessage(role=role, reasoning_content=reasoning_content, content=content)
message = ChatMessage(role=role, reasoning=reasoning, content=content)
# handle when there are tools and tool choice is auto
elif (
@@ -1761,7 +1761,7 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
and self.tool_parser
):
try:
tool_parser = self.tool_parser(tokenizer)
tool_parser = self.tool_parser(tokenizer, request.tools)
except RuntimeError as e:
logger.exception("Error in tool parser creation.")
return self.create_error_response(e)
@@ -1774,7 +1774,7 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
if tool_call_info.tools_called:
message = ChatMessage(
role=role,
reasoning_content=reasoning_content,
reasoning=reasoning,
content=tool_call_info.content,
tool_calls=tool_call_info.tool_calls,
)
@@ -1790,7 +1790,7 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
ret_content = tool_call_info.content
message = ChatMessage(
role=role,
reasoning_content=reasoning_content,
reasoning=reasoning,
content=ret_content,
)
@@ -1800,7 +1800,7 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
"Error in chat_completion_full_generator - cannot determine if tools should be extracted. "
"Returning a standard chat completion."
)
message = ChatMessage(role=role, reasoning_content=reasoning_content, content=content)
message = ChatMessage(role=role, reasoning=reasoning, content=content)
choice_data = ChatCompletionResponseChoice(
index=output.index,
@@ -1642,3 +1642,6 @@ class OmniOpenAIServingSpeech(OpenAIServing, AudioMixin):
succeeded=succeeded,
failed=len(final_results) - succeeded,
)
ServingSpeech = OmniOpenAIServingSpeech
+16 -7
View File
@@ -1,7 +1,7 @@
import os
import types
from collections import Counter
from dataclasses import asdict, fields, is_dataclass
from dataclasses import fields, is_dataclass
from pathlib import Path
from typing import Any, get_args, get_origin
@@ -145,12 +145,21 @@ def _convert_dataclasses_to_dict(obj: Any) -> Any:
if isinstance(obj, set):
return list(obj)
# Handle dataclass objects
# Note: asdict() recursively converts nested dataclasses but not Counter objects,
# so we need to recursively process the result
if is_dataclass(obj):
result = asdict(obj)
# Recursively process the result to convert any Counter objects
return _convert_dataclasses_to_dict(result)
# Use field iteration instead of asdict() to:
# 1. Only include init fields (non-init fields cause "unexpected kwarg" errors)
# 2. Skip None values matching field defaults (avoids Pydantic validation
# failures when None is explicitly passed for non-Optional typed fields,
# e.g. CompilationConfig.cudagraph_capture_sizes: list[int] = None)
if is_dataclass(obj) and not isinstance(obj, type):
result = {}
for f in fields(obj):
if not f.init:
continue
value = getattr(obj, f.name)
if value is None and f.default is None:
continue
result[f.name] = _convert_dataclasses_to_dict(value)
return result
# Handle dictionaries (recurse into values) and filter out callables(cause error in OmegaConf.create)
# Note: This must come AFTER Counter check since Counter is a dict subclass
if isinstance(obj, dict):