[Core] Keep attention backends eligible for text-only serving of prefix-LM models (#48796)
Signed-off-by: qtris123 <voquangtri2021@gmail.com> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
+43
-1
@@ -758,6 +758,10 @@ class ModelConfig:
|
||||
"disable the cache with --mm-processor-cache-gb 0."
|
||||
)
|
||||
|
||||
# Rebuild after multimodal_config exists so text-only mm_prefix
|
||||
# clearing is applied (and cached for later with_hf_config calls).
|
||||
self.model_arch_config = self.get_model_arch_config()
|
||||
|
||||
if self.disable_sliding_window:
|
||||
# Set after get_and_verify_max_len to ensure that max_model_len
|
||||
# can be correctly capped to sliding window size
|
||||
@@ -770,6 +774,42 @@ class ModelConfig:
|
||||
self._verify_cuda_graph()
|
||||
self._verify_bnb_config()
|
||||
|
||||
def _supports_multimodal_for_mm_prefix(self) -> bool:
|
||||
"""Whether multimodal inputs can still appear for this deployment.
|
||||
|
||||
This runs more than once per config: once early in ``__post_init__``
|
||||
(before ``multimodal_config`` exists), again after it is created, and
|
||||
then for every ``get_model_arch_config`` regeneration -- notably
|
||||
``with_hf_config``, which deep-copies this ``ModelConfig`` and swaps
|
||||
``hf_config`` for a text-only submodule (e.g. ``Gemma4ForCausalLM``).
|
||||
|
||||
The result is cached for correctness, not just to save work: on the
|
||||
``with_hf_config`` copy the submodule architecture has no registered
|
||||
multimodal processor, so re-querying the registry would raise and be
|
||||
treated as text-only, wrongly clearing ``is_mm_prefix_lm`` even when a
|
||||
vision modality is still enabled (e.g. ``image=0`` but video allowed).
|
||||
The deep-copied cache preserves the top-level decision instead.
|
||||
"""
|
||||
cached = getattr(self, "_supports_multimodal_inputs_cached", None)
|
||||
if cached is not None:
|
||||
return cached
|
||||
|
||||
if self.multimodal_config is None:
|
||||
# Early call before multimodal init — do not clear mm_prefix yet.
|
||||
return True
|
||||
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
|
||||
supports_mm = MULTIMODAL_REGISTRY.supports_multimodal_inputs(self)
|
||||
self._supports_multimodal_inputs_cached = supports_mm
|
||||
if not supports_mm:
|
||||
logger.info_once(
|
||||
"Disabled mm_prefix attention mode because multimodal inputs "
|
||||
"are configuration-disabled. Attention backends without "
|
||||
"mm_prefix support may now be selected."
|
||||
)
|
||||
return supports_mm
|
||||
|
||||
def get_model_arch_config(
|
||||
self,
|
||||
) -> ModelArchitectureConfig:
|
||||
@@ -777,7 +817,9 @@ class ModelConfig:
|
||||
self.hf_config.model_type, ModelArchConfigConvertorBase
|
||||
)
|
||||
convertor = convertor_cls(self.hf_config, self.hf_text_config)
|
||||
return convertor.convert()
|
||||
return convertor.convert(
|
||||
supports_multimodal=self._supports_multimodal_for_mm_prefix()
|
||||
)
|
||||
|
||||
@field_validator("tokenizer", "max_model_len", mode="wrap")
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user