Skip to content

Commit

Permalink
Also cache by model ID
Browse files Browse the repository at this point in the history
Signed-off-by: DarkLight1337 <[email protected]>
  • Loading branch information
DarkLight1337 committed Dec 25, 2024
1 parent 93bba0a commit ea9f888
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vllm/multimodal/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,23 +676,27 @@ def _hash_kwargs(self, **kwargs: object) -> str:

def get(
self,
model_id: str,
modality: str,
input_item: object,
input_kwargs: Mapping[str, object],
) -> Optional[Mapping[str, MultiModalFieldItem]]:
self._maybe_log_cache_stats()

cache_key = self._hash_kwargs(**{modality: input_item}, **input_kwargs)
cache_key = self._hash_kwargs(model_id=model_id,
**{modality: input_item}, **input_kwargs)
return self._cache.get(cache_key)

def put(
self,
model_id: str,
modality: str,
input_item: object,
input_kwargs: Mapping[str, object],
output_kwargs: Mapping[str, MultiModalFieldItem],
) -> None:
cache_key = self._hash_kwargs(**{modality: input_item}, **input_kwargs)
cache_key = self._hash_kwargs(model_id=model_id,
**{modality: input_item}, **input_kwargs)
self._cache.put(cache_key, output_kwargs)


Expand Down Expand Up @@ -886,6 +890,7 @@ def _cached_apply_hf_processor(
caching the results and reusing cached results.
"""
cache = self.cache
model_id = self.ctx.model_config.model

if cache is None or mm_data_items.has_embedding_inputs():
return self._apply_hf_processor(
Expand All @@ -896,7 +901,7 @@ def _cached_apply_hf_processor(

mm_maybe_cached_field_items = {
modality: [
cache.get(modality, item, hf_processor_mm_kwargs)
cache.get(model_id, modality, item, hf_processor_mm_kwargs)
for item in items
]
for modality, items in mm_data_items.items()
Expand Down Expand Up @@ -936,6 +941,7 @@ def _cached_apply_hf_processor(
)

cache.put(
model_id,
modality,
mm_data_items[modality][idx],
hf_processor_mm_kwargs,
Expand Down

0 comments on commit ea9f888

Please sign in to comment.