[Feature] Support output modalities control per request (#298)

Signed-off-by: Gaohan123 <hgaoaf@connect.ust.hk>
This commit is contained in:
Gao Han authored and GitHub committed 2025-12-17 17:19:56 +08:00
1 parent 2b6d8f17ba
commit 8722c6374c
30 files changed
+349 -61

No files matched your search

+46
View File
@@ -5,6 +5,7 @@ from pathlib import Path
from typing import Any
from omegaconf import OmegaConf
from vllm.logger import init_logger
from vllm.transformers_utils.config import get_config
from vllm_omni.utils import detect_device_type
@@ -12,6 +13,8 @@ from vllm_omni.utils import detect_device_type
# Get the project root directory (2 levels up from this file)
PROJECT_ROOT = Path(__file__).parent.parent.parent
logger = init_logger(__name__)
def _convert_dataclasses_to_dict(obj: Any) -> Any:
"""Recursively convert non-serializable objects to OmegaConf-compatible types.
@@ -143,3 +146,46 @@ def load_stage_configs_from_yaml(config_path: str, base_engine_args: dict | None
base_engine_args_tmp = OmegaConf.merge(base_engine_args_tmp, stage_arg.engine_args)
stage_arg.engine_args = base_engine_args_tmp
return stage_args
def get_final_stage_id_for_e2e(output_modalities: list[str], default_modalities: list[str], stage_list: list) -> int:
"""Get the final stage id for e2e.
Args:
stage_list: List of stage configurations
Returns:
Final stage id for e2e
"""
last_stage_id = len(stage_list) - 1
if output_modalities is not None:
prompt_modalities = []
for modality in output_modalities:
if modality not in default_modalities:
logger.warning(f"Invalid output modality: {modality}, ignoring it")
continue
prompt_modalities.append(modality)
output_modalities = prompt_modalities
else:
output_modalities = default_modalities
try:
for _sid in range(last_stage_id, -1, -1):
if (
getattr(stage_list[_sid], "final_output", False)
and stage_list[_sid].final_output_type in output_modalities
):
final_stage_id_for_e2e = _sid
break
if final_stage_id_for_e2e < 0:
final_stage_id_for_e2e = last_stage_id
except Exception as e:
logger.debug(
"[Orchestrator] Failed to determine final stage for E2E; \
falling back to last: %s",
e,
exc_info=True,
)
final_stage_id_for_e2e = last_stage_id
return final_stage_id_for_e2e