[Frontend] Use engine argument to control MM cache size (#22441)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Generic, Optional, Protocol, TypeVar
|
||||
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.envs import VLLM_MM_INPUT_CACHE_GIB
|
||||
from vllm.inputs import InputProcessingContext
|
||||
from vllm.logger import init_logger
|
||||
from vllm.transformers_utils.tokenizer import (AnyTokenizer,
|
||||
@@ -96,11 +95,22 @@ class MultiModalRegistry:
|
||||
self._processor_factories = ClassRegistry[nn.Module,
|
||||
_ProcessorFactories]()
|
||||
|
||||
self._processing_cache = ProcessingCache(VLLM_MM_INPUT_CACHE_GIB)
|
||||
self._processor_cache: Optional[ProcessingCache] = None
|
||||
|
||||
def _get_processor_cache(self, model_config: "ModelConfig"):
|
||||
capacity_gb = model_config.mm_processor_cache_gb
|
||||
if capacity_gb is None:
|
||||
return None # Overrides `disable_cache` argument
|
||||
|
||||
if self._processor_cache is None:
|
||||
self._processor_cache = ProcessingCache(capacity_gb)
|
||||
|
||||
return self._processor_cache
|
||||
|
||||
def reset_processor_cache(self) -> bool:
|
||||
"""Reset the multi-modal processing cache."""
|
||||
self._processing_cache.reset()
|
||||
if self._processor_cache:
|
||||
self._processor_cache.reset()
|
||||
|
||||
return True # Success
|
||||
|
||||
@@ -244,14 +254,14 @@ class MultiModalRegistry:
|
||||
if tokenizer is None and not model_config.skip_tokenizer_init:
|
||||
tokenizer = cached_tokenizer_from_config(model_config)
|
||||
if disable_cache is None:
|
||||
mm_config = model_config.get_multimodal_config()
|
||||
disable_cache = mm_config.disable_mm_preprocessor_cache
|
||||
disable_cache = not model_config.enable_mm_processor_cache
|
||||
|
||||
model_cls = self._get_model_cls(model_config)
|
||||
factories = self._processor_factories[model_cls]
|
||||
|
||||
ctx = InputProcessingContext(model_config, tokenizer)
|
||||
cache = None if disable_cache else self._processing_cache
|
||||
cache = None if disable_cache else self._get_processor_cache(
|
||||
model_config)
|
||||
|
||||
return factories.build_processor(ctx, cache=cache)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user