[Bugfix] Forward all vllm-omni serve command parameters to model (#985)
Signed-off-by: Junhong Liu <98734602+LJH-LBJ@users.noreply.github.com> Signed-off-by: Junhong Liu <ljh_lbj@163.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
a8cec43ce6
commit
c0908dd3fa
8 files changed
+682
-17
No files matched your search
@@ -38,7 +38,6 @@ from vllm_omni.entrypoints.omni_stage import OmniStage
|
||||
from vllm_omni.entrypoints.stage_utils import SHUTDOWN_TASK, OmniStageTaskType
|
||||
from vllm_omni.entrypoints.stage_utils import maybe_load_from_ipc as _load
|
||||
from vllm_omni.entrypoints.utils import (
|
||||
build_base_engine_args,
|
||||
get_final_stage_id_for_e2e,
|
||||
inject_omni_kv_config,
|
||||
load_and_resolve_stage_configs,
|
||||
@@ -255,7 +254,6 @@ class OmniBase:
|
||||
# TODO(wuhang):
|
||||
# Remove kwargs as parameters in the future.
|
||||
# Use dataclass directly for engine args.
|
||||
base_engine_args = build_base_engine_args(kwargs)
|
||||
|
||||
stage_configs_path = kwargs.get("stage_configs_path", None)
|
||||
|
||||
@@ -263,7 +261,7 @@ class OmniBase:
|
||||
config_path, stage_configs = load_and_resolve_stage_configs(
|
||||
model,
|
||||
stage_configs_path,
|
||||
base_engine_args,
|
||||
kwargs,
|
||||
default_stage_cfg_factory=lambda: self._create_default_diffusion_stage_cfg(kwargs),
|
||||
)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ from vllm_omni.engine.arg_utils import OmniEngineArgs
|
||||
from vllm_omni.engine.input_processor import OmniInputProcessor
|
||||
from vllm_omni.engine.output_processor import MultimodalOutputProcessor
|
||||
from vllm_omni.entrypoints.utils import (
|
||||
filter_dataclass_kwargs,
|
||||
load_stage_configs_from_model,
|
||||
load_stage_configs_from_yaml,
|
||||
resolve_model_config_path,
|
||||
@@ -151,7 +152,7 @@ class OmniLLM(LLM):
|
||||
compilation_config=compilation_config_instance,
|
||||
structured_outputs_config=structured_outputs_instance,
|
||||
omni_kv_config=omni_kv_config,
|
||||
**kwargs,
|
||||
**filter_dataclass_kwargs(OmniEngineArgs, kwargs),
|
||||
)
|
||||
|
||||
# Create the Engine (autoselects V0 vs V1)
|
||||
|
||||
@@ -36,7 +36,7 @@ from vllm_omni.distributed.omni_connectors import build_stage_connectors
|
||||
from vllm_omni.distributed.omni_connectors.adapter import try_recv_via_connector
|
||||
from vllm_omni.distributed.omni_connectors.connectors.base import OmniConnectorBase
|
||||
from vllm_omni.distributed.ray_utils.utils import kill_ray_actor, start_ray_actor
|
||||
from vllm_omni.engine.arg_utils import AsyncOmniEngineArgs
|
||||
from vllm_omni.engine.arg_utils import AsyncOmniEngineArgs, OmniEngineArgs
|
||||
from vllm_omni.entrypoints.async_omni_diffusion import AsyncOmniDiffusion
|
||||
from vllm_omni.entrypoints.async_omni_llm import AsyncOmniLLM
|
||||
from vllm_omni.entrypoints.omni_diffusion import OmniDiffusion
|
||||
@@ -49,7 +49,7 @@ from vllm_omni.entrypoints.stage_utils import (
|
||||
maybe_dump_to_shm,
|
||||
set_stage_devices,
|
||||
)
|
||||
from vllm_omni.entrypoints.utils import detect_pid_host
|
||||
from vllm_omni.entrypoints.utils import detect_pid_host, filter_dataclass_kwargs
|
||||
from vllm_omni.entrypoints.zmq_utils import (
|
||||
ZmqQueue,
|
||||
create_zmq_queue,
|
||||
@@ -212,7 +212,8 @@ def _resolve_worker_cls(engine_args: dict[str, Any]) -> None:
|
||||
worker_type = engine_args.get("worker_type", None)
|
||||
if not worker_type:
|
||||
return
|
||||
if engine_args.get("worker_cls"):
|
||||
worker_cls = engine_args.get("worker_cls")
|
||||
if worker_cls is not None and worker_cls != "auto":
|
||||
return
|
||||
from vllm_omni.platforms import current_omni_platform
|
||||
|
||||
@@ -268,6 +269,12 @@ class OmniStage:
|
||||
self.is_comprehension = getattr(stage_config, "is_comprehension", False)
|
||||
# Support for different stage types: "llm" (default) or "diffusion"
|
||||
self.stage_type: Literal["llm", "diffusion"] = getattr(stage_config, "stage_type", "llm")
|
||||
if (
|
||||
"stage_id" in stage_config.engine_args
|
||||
and stage_config.engine_args.stage_id != self.stage_id
|
||||
and self.stage_id is not None
|
||||
):
|
||||
stage_config.engine_args.stage_id = self.stage_id
|
||||
if hasattr(stage_config, "custom_process_input_func"):
|
||||
# Import the module specified in the config (already a full module path)
|
||||
module_path, func_name = stage_config.custom_process_input_func.rsplit(".", 1)
|
||||
@@ -746,6 +753,7 @@ def _stage_worker(
|
||||
engine_args["stage_connector_spec"] = stage_connector_spec
|
||||
engine_args["stage_id"] = stage_id
|
||||
if stage_type == "diffusion":
|
||||
engine_args = filter_dataclass_kwargs(OmniDiffusionConfig, engine_args)
|
||||
engine_args.pop("model_stage", None)
|
||||
engine_args.pop("model", None)
|
||||
stage_engine = OmniDiffusion(
|
||||
@@ -755,6 +763,8 @@ def _stage_worker(
|
||||
**engine_args,
|
||||
)
|
||||
else:
|
||||
engine_args = filter_dataclass_kwargs(OmniEngineArgs, engine_args)
|
||||
engine_args.pop("model", None)
|
||||
# Default to LLM engine
|
||||
stage_engine = OmniLLM(model=model, **engine_args)
|
||||
|
||||
@@ -1162,6 +1172,7 @@ async def _stage_worker_async(
|
||||
engine_args["stage_id"] = stage_id
|
||||
if stage_type == "diffusion":
|
||||
# For diffusion, we need to extract diffusion-specific config
|
||||
engine_args = filter_dataclass_kwargs(OmniDiffusionConfig, engine_args)
|
||||
od_config = _build_od_config(engine_args, model)
|
||||
|
||||
# Inject omni config for worker to access stage info
|
||||
@@ -1178,6 +1189,8 @@ async def _stage_worker_async(
|
||||
)
|
||||
vllm_config = None # Diffusion doesn't use vllm_config
|
||||
else:
|
||||
engine_args = filter_dataclass_kwargs(AsyncOmniEngineArgs, engine_args)
|
||||
engine_args.pop("model", None)
|
||||
omni_engine_args = AsyncOmniEngineArgs(model=model, **engine_args)
|
||||
usage_context = UsageContext.OPENAI_API_SERVER
|
||||
vllm_config = omni_engine_args.create_engine_config(usage_context=usage_context)
|
||||
|
||||
+125
-10
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
import types
|
||||
from collections import Counter
|
||||
from dataclasses import asdict, is_dataclass
|
||||
from dataclasses import asdict, fields, is_dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, get_args, get_origin
|
||||
|
||||
from omegaconf import OmegaConf
|
||||
from vllm.logger import init_logger
|
||||
@@ -68,6 +69,52 @@ def _try_get_class_name_from_diffusers_config(model: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _filter_dict_like_object(obj: dict | Any) -> dict:
|
||||
"""Filter dict-like object by removing callables and recursively converting values.
|
||||
|
||||
Converts dict-like objects to regular dicts while filtering out callable values
|
||||
that are incompatible with OmegaConf. Recursively processes values through
|
||||
_convert_dataclasses_to_dict for nested object conversion.
|
||||
|
||||
Args:
|
||||
obj: Dict or dict-like object to filter
|
||||
|
||||
Returns:
|
||||
Regular dict with callables filtered out and values recursively converted
|
||||
|
||||
Raises:
|
||||
TypeError: If obj doesn't support .items() method
|
||||
ValueError: If dict conversion fails unexpectedly
|
||||
"""
|
||||
|
||||
def _is_callable_value(value: Any) -> bool:
|
||||
if callable(value):
|
||||
return True
|
||||
return isinstance(
|
||||
value,
|
||||
(
|
||||
types.FunctionType,
|
||||
types.MethodType,
|
||||
types.BuiltinFunctionType,
|
||||
types.BuiltinMethodType,
|
||||
),
|
||||
)
|
||||
|
||||
result = {}
|
||||
filtered_keys = []
|
||||
for k, v in obj.items():
|
||||
if _is_callable_value(v):
|
||||
filtered_keys.append(str(k))
|
||||
else:
|
||||
result[k] = _convert_dataclasses_to_dict(v)
|
||||
if filtered_keys:
|
||||
logger.warning(
|
||||
f"Filtered out {len(filtered_keys)} callable object(s) from base_engine_args "
|
||||
f"that are not compatible with OmegaConf: {filtered_keys}. "
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _convert_dataclasses_to_dict(obj: Any) -> Any:
|
||||
"""Recursively convert non-serializable objects to OmegaConf-compatible types.
|
||||
|
||||
@@ -75,6 +122,7 @@ def _convert_dataclasses_to_dict(obj: Any) -> Any:
|
||||
- Dataclass objects with Literal type annotations (e.g., StructuredOutputsConfig)
|
||||
- Counter objects (from collections or vllm.utils)
|
||||
- Set objects
|
||||
- Callable objects (functions, methods, etc.)
|
||||
- Other non-primitive types
|
||||
"""
|
||||
# IMPORTANT: Check Counter BEFORE dict, since Counter is a subclass of dict
|
||||
@@ -99,17 +147,21 @@ def _convert_dataclasses_to_dict(obj: Any) -> Any:
|
||||
result = asdict(obj)
|
||||
# Recursively process the result to convert any Counter objects
|
||||
return _convert_dataclasses_to_dict(result)
|
||||
# Handle dictionaries (recurse into values)
|
||||
# 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):
|
||||
return {k: _convert_dataclasses_to_dict(v) for k, v in obj.items()}
|
||||
return _filter_dict_like_object(obj)
|
||||
# Handle callable objects (functions, methods, etc.) - skip them
|
||||
# Note: This comes after dict/list checks to avoid misclassifying dict-like objects
|
||||
if callable(obj):
|
||||
return None
|
||||
# Handle lists and tuples (recurse into items)
|
||||
if isinstance(obj, (list, tuple)):
|
||||
return type(obj)(_convert_dataclasses_to_dict(item) for item in obj)
|
||||
return type(obj)(_convert_dataclasses_to_dict(item) for item in obj if not callable(item))
|
||||
# Try to convert any dict-like object (has keys/values methods) to dict
|
||||
if hasattr(obj, "keys") and hasattr(obj, "values") and not isinstance(obj, (str, bytes)):
|
||||
try:
|
||||
return {k: _convert_dataclasses_to_dict(v) for k, v in obj.items()}
|
||||
return _filter_dict_like_object(obj)
|
||||
except (TypeError, ValueError, AttributeError):
|
||||
# If conversion fails, return as-is
|
||||
return obj
|
||||
@@ -239,7 +291,7 @@ def load_stage_configs_from_yaml(config_path: str, base_engine_args: dict | None
|
||||
def load_and_resolve_stage_configs(
|
||||
model: str,
|
||||
stage_configs_path: str | None,
|
||||
base_engine_args: dict | None,
|
||||
kwargs: dict | None,
|
||||
default_stage_cfg_factory: Any = None,
|
||||
) -> tuple[str, list]:
|
||||
"""Load stage configurations from model or YAML file with fallback to defaults.
|
||||
@@ -247,7 +299,7 @@ def load_and_resolve_stage_configs(
|
||||
Args:
|
||||
model: Model name or path
|
||||
stage_configs_path: Optional path to YAML file containing stage configurations
|
||||
base_engine_args: Base engine arguments to merge with stage configs
|
||||
kwargs: Engine arguments to merge with stage configs
|
||||
default_stage_cfg_factory: Optional callable that takes no args and returns
|
||||
default stage config list when no configs are found
|
||||
|
||||
@@ -256,7 +308,7 @@ def load_and_resolve_stage_configs(
|
||||
"""
|
||||
if stage_configs_path is None:
|
||||
config_path = resolve_model_config_path(model)
|
||||
stage_configs = load_stage_configs_from_model(model, base_engine_args=base_engine_args)
|
||||
stage_configs = load_stage_configs_from_model(model, base_engine_args=kwargs)
|
||||
if not stage_configs:
|
||||
if default_stage_cfg_factory is not None:
|
||||
default_stage_cfg = default_stage_cfg_factory()
|
||||
@@ -265,7 +317,7 @@ def load_and_resolve_stage_configs(
|
||||
stage_configs = []
|
||||
else:
|
||||
config_path = stage_configs_path
|
||||
stage_configs = load_stage_configs_from_yaml(stage_configs_path, base_engine_args=base_engine_args)
|
||||
stage_configs = load_stage_configs_from_yaml(stage_configs_path, base_engine_args=kwargs)
|
||||
|
||||
return config_path, stage_configs
|
||||
|
||||
@@ -316,6 +368,69 @@ def get_final_stage_id_for_e2e(
|
||||
return final_stage_id_for_e2e
|
||||
|
||||
|
||||
def filter_dataclass_kwargs(cls: Any, kwargs: dict) -> dict:
|
||||
"""Filter kwargs to only include fields defined in the dataclass.
|
||||
|
||||
Args:
|
||||
cls: Dataclass type
|
||||
kwargs: Keyword arguments to filter
|
||||
|
||||
Returns:
|
||||
Filtered keyword arguments containing only valid dataclass fields
|
||||
"""
|
||||
if not is_dataclass(cls):
|
||||
raise ValueError(f"{cls} is not a dataclass")
|
||||
if not isinstance(kwargs, dict):
|
||||
raise ValueError("kwargs must be a dictionary")
|
||||
|
||||
def _filter_value(value: Any, annotation: Any) -> Any:
|
||||
"""Recursively filter nested dict/list values based on dataclass annotations."""
|
||||
if annotation is None:
|
||||
return value
|
||||
|
||||
origin = get_origin(annotation)
|
||||
if origin is None:
|
||||
if isinstance(annotation, type) and is_dataclass(annotation) and isinstance(value, dict):
|
||||
return filter_dataclass_kwargs(annotation, value)
|
||||
return value
|
||||
|
||||
if origin in (list, tuple, set):
|
||||
args = get_args(annotation)
|
||||
inner = args[0] if args else None
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return type(value)(_filter_value(v, inner) for v in value)
|
||||
return value
|
||||
|
||||
if origin is dict:
|
||||
args = get_args(annotation)
|
||||
val_type = args[1] if len(args) > 1 else None
|
||||
if isinstance(value, dict):
|
||||
return {k: _filter_value(v, val_type) for k, v in value.items()}
|
||||
return value
|
||||
|
||||
if origin is types.UnionType or origin is getattr(types, "UnionType", None):
|
||||
for arg in get_args(annotation):
|
||||
if isinstance(arg, type) and is_dataclass(arg) and isinstance(value, dict):
|
||||
return filter_dataclass_kwargs(arg, value)
|
||||
# Try container-style filtering for union members
|
||||
filtered = _filter_value(value, arg)
|
||||
if filtered is not value:
|
||||
return filtered
|
||||
return value
|
||||
|
||||
return value
|
||||
|
||||
valid_fields = {f.name: f for f in fields(cls) if f.init}
|
||||
filtered_kwargs = {}
|
||||
for k, v in kwargs.items():
|
||||
if k not in valid_fields:
|
||||
continue
|
||||
field = valid_fields[k]
|
||||
filtered_kwargs[k] = _filter_value(v, field.type)
|
||||
|
||||
return filtered_kwargs
|
||||
|
||||
|
||||
# TODO(wuhang): Remove after PR #1115.
|
||||
def build_base_engine_args(source: Any) -> dict[str, Any] | None:
|
||||
"""Build base engine args with tokenizer and parallel configuration.
|
||||
|
||||
Reference in new issue
Block a user