Add embedding input functionality for disabled modalities [remake] (#32493)
Signed-off-by: Reagan Lee <“reaganjlee@gmail.com”> Signed-off-by: Reagan Lee <reaganjlee@gmail.com> Signed-off-by: Reagan Lee <96998476+reaganjlee@users.noreply.github.com> Co-authored-by: Reagan Lee <“reaganjlee@gmail.com”> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Reagan Lee
gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
parent
785cf28fff
commit
c4df59ad43
@@ -3,11 +3,14 @@
|
||||
from collections.abc import Mapping
|
||||
|
||||
from vllm.config import ModelConfig, VllmConfig
|
||||
from vllm.logger import init_logger
|
||||
from vllm.multimodal.processing import BaseMultiModalProcessor
|
||||
from vllm.multimodal.registry import MultiModalRegistry
|
||||
from vllm.utils.torch_utils import set_default_torch_num_threads
|
||||
from vllm.v1.core.encoder_cache_manager import compute_mm_encoder_budget
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def get_mm_max_toks_per_item(
|
||||
model_config: ModelConfig,
|
||||
@@ -59,11 +62,26 @@ class MultiModalBudget:
|
||||
processor = mm_registry.create_processor(model_config, cache=cache)
|
||||
|
||||
self.cache = cache
|
||||
mm_config = model_config.get_multimodal_config()
|
||||
enable_mm_embeds = mm_config is not None and mm_config.enable_mm_embeds
|
||||
|
||||
supported_mm_limits = processor.info.supported_mm_limits
|
||||
self.mm_limits = mm_limits = processor.info.allowed_mm_limits
|
||||
|
||||
active_modalities = {
|
||||
modality for modality, limit in mm_limits.items() if limit > 0
|
||||
# Modalities that pass through the MM encoder tower
|
||||
tower_modalities = {
|
||||
modality
|
||||
for modality in supported_mm_limits
|
||||
if mm_limits.get(modality, 0) > 0
|
||||
}
|
||||
# Modalities that bypass the tower (pre-computed embeddings only)
|
||||
embed_only_modalities = {
|
||||
modality
|
||||
for modality in supported_mm_limits
|
||||
if enable_mm_embeds and mm_limits.get(modality, 0) == 0
|
||||
}
|
||||
|
||||
active_modalities = tower_modalities | embed_only_modalities
|
||||
|
||||
all_mm_max_toks_per_item = get_mm_max_toks_per_item(
|
||||
model_config,
|
||||
@@ -72,19 +90,32 @@ class MultiModalBudget:
|
||||
mm_counts=dict.fromkeys(active_modalities, 1),
|
||||
)
|
||||
|
||||
if embed_only_modalities:
|
||||
logger.info_once(
|
||||
"enable_mm_embeds is True; modalities handled as embedding-only: %s",
|
||||
tuple(embed_only_modalities),
|
||||
)
|
||||
|
||||
# Some models (e.g., Qwen3Omni with use_audio_in_video=True) share
|
||||
# placeholders between modalities, so not all active modalities will
|
||||
# have their own entry in the returned dict. We filter to only include
|
||||
# modalities that have independent placeholder tokens.
|
||||
mm_max_toks_per_item = {
|
||||
active_mm_max_toks_per_item = {
|
||||
modality: all_mm_max_toks_per_item[modality]
|
||||
for modality in active_modalities
|
||||
if modality in all_mm_max_toks_per_item
|
||||
}
|
||||
tower_mm_max_toks_per_item = {
|
||||
modality: active_mm_max_toks_per_item[modality]
|
||||
for modality in tower_modalities
|
||||
if modality in active_mm_max_toks_per_item
|
||||
}
|
||||
|
||||
# Encoder budget is computed from all active modalities (including
|
||||
# embedding-only ones that need encoder cache space).
|
||||
encoder_compute_budget, encoder_cache_size = compute_mm_encoder_budget(
|
||||
scheduler_config,
|
||||
mm_max_toks_per_item,
|
||||
active_mm_max_toks_per_item,
|
||||
)
|
||||
|
||||
self.encoder_compute_budget = encoder_compute_budget
|
||||
@@ -93,13 +124,15 @@ class MultiModalBudget:
|
||||
mm_max_items_per_prompt = dict[str, int]()
|
||||
mm_max_items_per_batch = dict[str, int]()
|
||||
|
||||
for modality, max_toks_per_item in mm_max_toks_per_item.items():
|
||||
# Per-prompt/per-batch limits are only relevant for tower modalities
|
||||
# (embedding-only modalities don't go through the encoder tower).
|
||||
for modality, max_toks_per_item in tower_mm_max_toks_per_item.items():
|
||||
(
|
||||
mm_max_items_per_prompt[modality],
|
||||
mm_max_items_per_batch[modality],
|
||||
) = self._get_max_items(modality, max_toks_per_item)
|
||||
|
||||
self.mm_max_toks_per_item = mm_max_toks_per_item
|
||||
self.mm_max_toks_per_item = tower_mm_max_toks_per_item
|
||||
self.mm_max_items_per_prompt: Mapping[str, int] = mm_max_items_per_prompt
|
||||
self.mm_max_items_per_batch: Mapping[str, int] = mm_max_items_per_batch
|
||||
|
||||
|
||||
@@ -681,16 +681,22 @@ class BaseProcessingInfo:
|
||||
mm_items = self.data_parser.parse_mm_data(mm_data)
|
||||
|
||||
if validate:
|
||||
mm_config = self.ctx.model_config.get_multimodal_config()
|
||||
if not mm_config.enable_mm_embeds:
|
||||
for modality, items in mm_items.items():
|
||||
if isinstance(items, (EmbeddingItems, DictEmbeddingItems)):
|
||||
mm_config = self.ctx.get_mm_config()
|
||||
|
||||
for modality, items in mm_items.items():
|
||||
if isinstance(items, (EmbeddingItems, DictEmbeddingItems)):
|
||||
if not mm_config.enable_mm_embeds:
|
||||
raise ValueError(
|
||||
f"You must set `--enable-mm-embeds` to input "
|
||||
f"`{modality}_embeds`"
|
||||
)
|
||||
|
||||
for modality, items in mm_items.items():
|
||||
if mm_config.get_limit_per_prompt(modality) == 0:
|
||||
logger.debug(
|
||||
"Skipping count validation for modality "
|
||||
"'%s' (embeddings with limit=0)",
|
||||
modality,
|
||||
)
|
||||
continue
|
||||
self.validate_num_items(modality, len(items))
|
||||
|
||||
return mm_items
|
||||
|
||||
@@ -95,7 +95,7 @@ class BaseDummyInputsBuilder(ABC, Generic[_I]):
|
||||
"""
|
||||
dummy_text = self.get_dummy_text(mm_counts)
|
||||
dummy_mm_data = self.get_dummy_mm_data(seq_len, mm_counts, mm_options)
|
||||
dummy_mm_items = self.info.parse_mm_data(dummy_mm_data)
|
||||
dummy_mm_items = self.info.parse_mm_data(dummy_mm_data, validate=False)
|
||||
|
||||
tokenization_kwargs = {"truncation": False}
|
||||
|
||||
|
||||
@@ -1395,7 +1395,7 @@ class BaseMultiModalProcessor(ABC, Generic[_I]):
|
||||
missing_modality_data.append(data)
|
||||
mm_missing_data[modality] = missing_modality_data
|
||||
|
||||
mm_missing_items = self.info.parse_mm_data(mm_missing_data)
|
||||
mm_missing_items = self.info.parse_mm_data(mm_missing_data, validate=False)
|
||||
|
||||
return mm_is_cached, mm_missing_items
|
||||
|
||||
|
||||
@@ -138,6 +138,11 @@ class MultiModalRegistry:
|
||||
mm_config.get_limit_per_prompt(modality) == 0
|
||||
for modality in info.supported_mm_limits
|
||||
):
|
||||
# If enable_mm_embeds is True, we still need MM infrastructure
|
||||
# to process pre-computed embeddings even though encoder won't run
|
||||
if mm_config.enable_mm_embeds:
|
||||
return True
|
||||
|
||||
logger.info_once(
|
||||
"All limits of multimodal modalities supported by the model "
|
||||
"are set to 0, running in text-only mode."
|
||||
|
||||
Reference in New Issue
Block a user