[Feat] Override single stage CLI args when stage_configs_path is set in OmniEngineArgs (#2684)
Signed-off-by: Zhengyuan Su <su.zhengyuan@u.nus.edu> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2dce028541
commit
eb1a801b21
3 files changed
+171
-1
No files matched your search
@@ -4,6 +4,7 @@ invariant to the specific attributes of vLLM config except in cases where we
|
||||
explicitly patch values that differ from vLLM.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
from unittest.mock import Mock
|
||||
|
||||
@@ -14,6 +15,7 @@ from vllm.engine.arg_utils import EngineArgs
|
||||
|
||||
from vllm_omni.config.model import OmniModelConfig
|
||||
from vllm_omni.engine.arg_utils import OmniEngineArgs
|
||||
from vllm_omni.engine.async_omni_engine import AsyncOmniEngine
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
@@ -116,6 +118,26 @@ def test_qwen3_tts_codec_frame_rate_patching():
|
||||
assert omni_config.codec_frame_rate_hz == 12.3
|
||||
|
||||
|
||||
def test_stage_configs_path_blocks_create_model_config():
|
||||
"""create_model_config() should raise when stage_configs_path is set."""
|
||||
args = OmniEngineArgs(stage_configs_path="/some/path.yaml")
|
||||
with pytest.raises(RuntimeError, match="stage_configs_path"):
|
||||
args.create_model_config()
|
||||
|
||||
|
||||
def test_from_cli_args_picks_up_stage_configs_path():
|
||||
"""from_cli_args should pick up stage_configs_path from namespace."""
|
||||
ns = argparse.Namespace(
|
||||
model="facebook/opt-125m",
|
||||
stage_configs_path="/some/path.yaml",
|
||||
custom_pipeline_args=None,
|
||||
)
|
||||
|
||||
args = OmniEngineArgs.from_cli_args(ns)
|
||||
assert args.stage_configs_path == "/some/path.yaml"
|
||||
assert args.custom_pipeline_args is None
|
||||
|
||||
|
||||
def test_stage_specific_text_config_override():
|
||||
"""Ensure dependent attributes are updated when using stage-specific config."""
|
||||
vllm_config = EngineArgs().create_model_config()
|
||||
@@ -144,3 +166,74 @@ def test_stage_specific_text_config_override():
|
||||
assert omni_config.attention_chunk_size == 2048
|
||||
assert omni_config.max_model_len == 4096
|
||||
assert omni_config.hf_text_config.sliding_window is None
|
||||
|
||||
|
||||
def test_stage_configs_path_field():
|
||||
"""OmniEngineArgs with stage_configs_path should construct without error."""
|
||||
args = OmniEngineArgs(stage_configs_path="/some/path.yaml")
|
||||
assert args.stage_configs_path == "/some/path.yaml"
|
||||
|
||||
|
||||
def test_strip_single_engine_args():
|
||||
"""_strip_single_engine_args should remove EngineArgs fields but keep omni fields."""
|
||||
kwargs = {
|
||||
# Parent EngineArgs fields — should be stripped
|
||||
"compilation_config": '{"cudagraph_mode": "FULL_AND_PIECEWISE"}',
|
||||
"tensor_parallel_size": 4,
|
||||
"gpu_memory_utilization": 0.9,
|
||||
"model": "some/model",
|
||||
# Parent field that should be kept (allowlisted)
|
||||
"worker_extension_cls": "some.Extension",
|
||||
# OmniEngineArgs-only / non-engine fields — should pass through
|
||||
"stage_configs_path": "/path/to/yaml",
|
||||
"custom_pipeline_args": {"pipeline_class": "my.Pipeline"},
|
||||
"mode": "text-to-image",
|
||||
"lora_path": "/some/lora",
|
||||
}
|
||||
|
||||
filtered = AsyncOmniEngine._strip_single_engine_args(kwargs)
|
||||
|
||||
# Stripped — parent EngineArgs fields
|
||||
assert "compilation_config" not in filtered
|
||||
assert "tensor_parallel_size" not in filtered
|
||||
assert "gpu_memory_utilization" not in filtered
|
||||
assert "model" not in filtered
|
||||
|
||||
# Stripped — orchestrator-level OmniEngineArgs field
|
||||
assert "stage_configs_path" not in filtered
|
||||
|
||||
# Kept
|
||||
assert filtered["worker_extension_cls"] == "some.Extension"
|
||||
assert filtered["custom_pipeline_args"] == {"pipeline_class": "my.Pipeline"}
|
||||
assert filtered["mode"] == "text-to-image"
|
||||
assert filtered["lora_path"] == "/some/lora"
|
||||
|
||||
|
||||
def test_strip_single_engine_args_model_does_not_trigger_warning(mocker):
|
||||
"""model is always in kwargs (callers set it via from_cli_args/asdict),
|
||||
so it should not cause the override warning by itself or appear in it."""
|
||||
mock_warn = mocker.patch("vllm_omni.engine.async_omni_engine.logger.warning")
|
||||
|
||||
# Typical caller kwargs: model is always present, no other parent
|
||||
# EngineArgs fields are explicitly overridden.
|
||||
AsyncOmniEngine._strip_single_engine_args(
|
||||
{
|
||||
"model": "some/model",
|
||||
"custom_pipeline_args": {"pipeline_class": "my.Pipeline"},
|
||||
}
|
||||
)
|
||||
mock_warn.assert_not_called()
|
||||
|
||||
# When there *are* genuinely surprising overrides alongside model,
|
||||
# the warning should mention them but not model.
|
||||
AsyncOmniEngine._strip_single_engine_args(
|
||||
{
|
||||
"model": "some/model",
|
||||
"tensor_parallel_size": 4,
|
||||
"custom_pipeline_args": {"pipeline_class": "my.Pipeline"},
|
||||
}
|
||||
)
|
||||
mock_warn.assert_called_once()
|
||||
warned_args = mock_warn.call_args[0][-1] # the formatted arg list
|
||||
assert "tensor_parallel_size" in warned_args
|
||||
assert "model" not in warned_args
|
||||
@@ -124,6 +124,9 @@ class OmniEngineArgs(EngineArgs):
|
||||
(e.g. ["text", "audio"]). If None, all modalities supported by
|
||||
the model are used.
|
||||
log_stats: Whether to log engine statistics. Defaults to False.
|
||||
custom_pipeline_args: Dictionary of arguments for custom pipeline
|
||||
initialization (e.g., ``{"pipeline_class": "my.Module"}``).
|
||||
Passed through to the diffusion stage engine.
|
||||
"""
|
||||
|
||||
stage_id: int = 0
|
||||
@@ -143,6 +146,7 @@ class OmniEngineArgs(EngineArgs):
|
||||
stage_configs_path: str | None = None
|
||||
output_modalities: list[str] | None = None
|
||||
log_stats: bool = False
|
||||
custom_pipeline_args: dict[str, Any] | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
load_omni_general_plugins()
|
||||
@@ -190,6 +194,11 @@ class OmniEngineArgs(EngineArgs):
|
||||
Returns:
|
||||
OmniModelConfig instance with all configuration fields set
|
||||
"""
|
||||
if self.stage_configs_path is not None:
|
||||
raise RuntimeError(
|
||||
"create_model_config() should not be called when stage_configs_path is set. "
|
||||
"Per-stage model configs are resolved from the stage config YAML."
|
||||
)
|
||||
# register omni models to avoid model not found error
|
||||
self._ensure_omni_models_registered()
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from typing import TYPE_CHECKING, Any
|
||||
import janus
|
||||
import torch
|
||||
from omegaconf import OmegaConf
|
||||
from vllm.engine.arg_utils import EngineArgs
|
||||
from vllm.inputs import PromptType
|
||||
from vllm.logger import init_logger
|
||||
from vllm.tokenizers import cached_tokenizer_from_config
|
||||
@@ -1258,6 +1259,68 @@ class AsyncOmniEngine:
|
||||
default_stage_cfg[0]["engine_args"]["model_stage"] = "diffusion"
|
||||
return default_stage_cfg
|
||||
|
||||
@staticmethod
|
||||
def _strip_single_engine_args(kwargs: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Remove parent ``EngineArgs`` fields from *kwargs*.
|
||||
|
||||
When ``stage_configs_path`` is set, per-stage engine args are defined
|
||||
in the YAML. Top-level single-engine fields (``compilation_config``,
|
||||
``tensor_parallel_size``, …) must not leak into per-stage configs via
|
||||
the ``base_engine_args`` merge in ``load_stage_configs_from_yaml`` —
|
||||
they can cause type errors (e.g. ``compilation_config`` as a JSON
|
||||
string rejected by ``VllmConfig``) or silently override YAML values.
|
||||
|
||||
Logs a warning for any parent field whose value differs from the
|
||||
dataclass default, so users know their explicit overrides are ignored.
|
||||
"""
|
||||
# worker_extension_cls is a parent field but must pass through to
|
||||
# diffusion stages for colocate worker setup.
|
||||
_keep = {"worker_extension_cls"}
|
||||
# Orchestrator-level OmniEngineArgs fields that are consumed by
|
||||
# _resolve_stage_configs and must not leak into per-stage configs
|
||||
# (stage_configs_path would trigger the create_model_config guard).
|
||||
_strip_omni = {"stage_configs_path"}
|
||||
# Fields that are always set by callers (via from_cli_args / asdict)
|
||||
# and would always appear as overridden — suppress from the warning
|
||||
# so it only surfaces genuinely surprising overrides.
|
||||
_no_warn = {"model"}
|
||||
|
||||
parent_fields: dict[str, dataclasses.Field] = {f.name: f for f in dataclasses.fields(EngineArgs)}
|
||||
overridden: list[str] = []
|
||||
result: dict[str, Any] = {}
|
||||
for k, v in kwargs.items():
|
||||
if k in _strip_omni:
|
||||
continue
|
||||
if k not in parent_fields or k in _keep:
|
||||
result[k] = v
|
||||
continue
|
||||
# Detect explicitly-set values that differ from the default.
|
||||
# Values may have been through asdict() which converts dataclass
|
||||
# defaults to dicts, so normalise before comparing.
|
||||
field = parent_fields[k]
|
||||
if field.default is not dataclasses.MISSING:
|
||||
default = field.default
|
||||
elif field.default_factory is not dataclasses.MISSING:
|
||||
default = field.default_factory()
|
||||
else:
|
||||
default = dataclasses.MISSING
|
||||
if default is dataclasses.MISSING or v is None:
|
||||
continue
|
||||
# Normalise dataclass defaults to dicts for comparison
|
||||
if dataclasses.is_dataclass(default) and not isinstance(default, type):
|
||||
default = dataclasses.asdict(default)
|
||||
if v != default and k not in _no_warn:
|
||||
overridden.append(k)
|
||||
|
||||
if overridden:
|
||||
logger.warning(
|
||||
"stage_configs_path is set — the following top-level engine "
|
||||
"args are ignored (per-stage YAML takes precedence): %s",
|
||||
", ".join(sorted(overridden)),
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
def _resolve_stage_configs(self, model: str, kwargs: dict[str, Any]) -> tuple[str, list[Any]]:
|
||||
"""Resolve stage configs and inject defaults shared by orchestrator/headless."""
|
||||
|
||||
@@ -1269,12 +1332,17 @@ class AsyncOmniEngine:
|
||||
"Ignoring it and resolving stages from stage_configs_path/model factory."
|
||||
)
|
||||
|
||||
if stage_configs_path is not None:
|
||||
base_kwargs = self._strip_single_engine_args(kwargs)
|
||||
else:
|
||||
base_kwargs = kwargs
|
||||
|
||||
# Use the legacy config loading path (load_and_resolve_stage_configs).
|
||||
# StageConfigFactory wiring will be done in config refactor [2/N].
|
||||
config_path, stage_configs = load_and_resolve_stage_configs(
|
||||
model,
|
||||
stage_configs_path,
|
||||
kwargs,
|
||||
base_kwargs,
|
||||
default_stage_cfg_factory=lambda: self._create_default_diffusion_stage_cfg(kwargs),
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user