22# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33from collections .abc import Mapping
44from dataclasses import dataclass
5+ from functools import lru_cache
56from typing import TYPE_CHECKING , Generic , Optional , Protocol , TypeVar
67
78import torch .nn as nn
@@ -86,6 +87,13 @@ def build_processor(
8687 return self .processor (info , dummy_inputs_builder , cache = cache )
8788
8889
90+ # Make sure a different cache is used for each model config
91+ # NOTE: ModelConfig is not hashable so it cannot be passed directly
92+ @lru_cache (maxsize = 1 )
93+ def _get_processor_cache (model_id : str , capacity_gb : int ):
94+ return ProcessingCache (capacity_gb ) if capacity_gb > 0 else None
95+
96+
8997class MultiModalRegistry :
9098 """
9199 A registry that dispatches data processing according to the model.
@@ -95,22 +103,15 @@ def __init__(self) -> None:
95103 self ._processor_factories = ClassRegistry [nn .Module ,
96104 _ProcessorFactories ]()
97105
98- self ._processor_cache : Optional [ProcessingCache ] = None
99-
100106 def _get_processor_cache (self , model_config : "ModelConfig" ):
107+ model_id = model_config .model
101108 capacity_gb = model_config .mm_processor_cache_gb
102- if capacity_gb is None :
103- return None # Overrides `disable_cache` argument
104-
105- if self ._processor_cache is None :
106- self ._processor_cache = ProcessingCache (capacity_gb )
107-
108- return self ._processor_cache
109+ return _get_processor_cache (model_id , capacity_gb )
109110
110- def reset_processor_cache (self ) -> bool :
111+ def reset_processor_cache (self , model_config : "ModelConfig" ) -> bool :
111112 """Reset the multi-modal processing cache."""
112- if self ._processor_cache :
113- self . _processor_cache .reset ()
113+ if processor_cache := self ._get_processor_cache ( model_config ) :
114+ processor_cache .reset ()
114115
115116 return True # Success
116117
0 commit comments