Files
vllm-omni/vllm_omni/config/model.py
T

142 lines
6.0 KiB
Python
Raw Normal View History

from dataclasses import field
2025-12-19 16:42:02 +08:00
from typing import Any
2025-11-04 22:06:41 +08:00
from pydantic import ConfigDict
2026-02-05 10:52:28 +00:00
from vllm.config import ModelConfig
from vllm.config.multimodal import MMCacheType, MMEncoderTPMode
from vllm.config.utils import config
2025-11-30 04:44:01 +08:00
from vllm.logger import init_logger
2026-02-05 10:52:28 +00:00
from vllm.transformers_utils.config import get_hf_text_config
+13
2026-01-21 00:25:25 +08:00
from vllm.v1.attention.backends.registry import AttentionBackendEnum
2025-11-04 22:06:41 +08:00
import vllm_omni.model_executor.models as me_models
2025-11-30 04:44:01 +08:00
logger = init_logger(__name__)
2025-11-04 22:06:41 +08:00
2026-02-05 10:52:28 +00:00
@config(config=ConfigDict(arbitrary_types_allowed=True))
2025-11-04 22:06:41 +08:00
class OmniModelConfig(ModelConfig):
"""Configuration for Omni models, extending the base ModelConfig.
This configuration class extends the base vLLM ModelConfig with
omni-specific fields for multi-stage pipeline processing.
Attributes:
stage_id: Identifier for the stage in a multi-stage pipeline (default: 0)
async_chunk: If set to True, perform async chunk
model_stage: Stage type identifier, e.g., "thinker" or "talker"
(default: "thinker")
model_arch: Model architecture name
(default: "Qwen2_5OmniForConditionalGeneration")
engine_output_type: Optional output type specification for the engine.
Used to route outputs to appropriate processors (e.g., "image",
"audio", "latents"). If None, output type is inferred.
stage_connector_config: Stage connector configuration dictionary.
Contains "name" (connector name), "extra" (extra connector config).
Example:
>>> config = OmniModelConfig(
... stage_id=0,
... model_stage="thinker",
... model_arch="Qwen2_5OmniForConditionalGeneration"
... )
"""
2025-11-04 22:06:41 +08:00
stage_id: int = 0
async_chunk: bool = False
2025-11-04 22:06:41 +08:00
model_stage: str = "thinker"
model_arch: str = "Qwen2_5OmniForConditionalGeneration"
engine_output_type: str | None = None
hf_config_name: str | None = None
custom_process_next_stage_input_func: str | None = None
stage_connector_config: dict[str, Any] = field(
default_factory=lambda: {
"name": "SharedMemoryConnector",
"extra": {},
}
)
2026-01-22 18:09:55 +08:00
omni_kv_config: dict | None = None
2025-11-04 22:06:41 +08:00
@property
def registry(self):
return me_models.OmniModelRegistry
@property
def architectures(self) -> list[str]:
return [self.model_arch]
2025-11-30 04:44:01 +08:00
2026-02-09 03:07:43 +00:00
@property
def embedding_size(self):
if self.hf_config_name is not None:
stage_config = getattr(self.hf_config, self.hf_config_name, None)
override = getattr(stage_config, "embedding_size", None)
if override is not None:
return override
return super().embedding_size
2025-11-30 04:44:01 +08:00
def draw_hf_text_config(self):
# transformers' get_text_config method is used to get the text config from thinker_config.
# to handle the case that each model stage has their own text config,
# we need to draw the text config from the corresponding model stage.
if self.hf_config_name is None:
return get_hf_text_config(self.hf_config)
try:
# Try to get the stage-specific config (e.g., thinker_config, talker_config)
stage_config = getattr(self.hf_config, self.hf_config_name)
return stage_config.get_text_config()
except AttributeError:
# Fallback: if the attribute doesn't exist, use the default get_hf_text_config
logger.warning(
f"Config attribute '{self.hf_config_name}' not found in hf_config, "
"falling back to default get_hf_text_config"
)
return get_hf_text_config(self.hf_config)
2025-11-30 04:44:01 +08:00
def __post_init__(
self,
# Multimodal config init vars
2026-02-10 03:36:09 +00:00
language_model_only: bool,
2025-12-19 16:42:02 +08:00
limit_mm_per_prompt: dict[str, int | dict[str, int]] | None,
enable_mm_embeds: bool | None,
media_io_kwargs: dict[str, dict[str, Any]] | None,
mm_processor_kwargs: dict[str, Any] | None,
mm_processor_cache_gb: float | None,
mm_processor_cache_type: MMCacheType | None,
mm_shm_cache_max_object_size_mb: int | None,
mm_encoder_only: bool | None,
mm_encoder_tp_mode: MMEncoderTPMode | None,
2025-12-19 16:42:02 +08:00
mm_encoder_attn_backend: AttentionBackendEnum | str | None,
interleave_mm_strings: bool | None,
skip_mm_profiling: bool | None,
video_pruning_rate: float | None,
2025-11-30 04:44:01 +08:00
) -> None:
2026-02-05 10:52:28 +00:00
# Call parent's __post_init__ to handle all standard ModelConfig initialization
super().__post_init__(
2026-02-10 03:36:09 +00:00
language_model_only=language_model_only,
2026-02-05 10:52:28 +00:00
limit_mm_per_prompt=limit_mm_per_prompt,
enable_mm_embeds=enable_mm_embeds,
media_io_kwargs=media_io_kwargs,
mm_processor_kwargs=mm_processor_kwargs,
mm_processor_cache_gb=mm_processor_cache_gb,
mm_processor_cache_type=mm_processor_cache_type,
mm_shm_cache_max_object_size_mb=mm_shm_cache_max_object_size_mb,
mm_encoder_only=mm_encoder_only,
mm_encoder_tp_mode=mm_encoder_tp_mode,
mm_encoder_attn_backend=mm_encoder_attn_backend,
interleave_mm_strings=interleave_mm_strings,
skip_mm_profiling=skip_mm_profiling,
video_pruning_rate=video_pruning_rate,
2025-12-19 16:42:02 +08:00
)
2025-11-30 04:44:01 +08:00
2026-02-05 10:52:28 +00:00
# Override hf_text_config with omni-specific logic for multi-stage models
# (e.g., thinker_config, talker_config)
new_hf_text_config = self.draw_hf_text_config()
if new_hf_text_config is not self.hf_text_config:
self.hf_text_config = new_hf_text_config
# Recalculate dependent attributes
self.attention_chunk_size = getattr(self.hf_text_config, "attention_chunk_size", None)
# Recalculate max_model_len since it depends on hf_text_config
self.max_model_len = self.get_and_verify_max_len(self.original_max_model_len)
# Reset sliding_window if needed
if self.disable_sliding_window:
self.hf_text_config.sliding_window = None