Improve multimodal hasher performance for re-used Image prompts (#22825)

Signed-off-by: Staszek Pasko <staszek@gmail.com>
This commit is contained in:
Staszek Paśko
2025-08-15 12:32:56 +00:00
committed by GitHub
parent 49252cf59e
commit 22341b996e
2 changed files with 26 additions and 0 deletions
+6
View File
@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pickle
import uuid
from collections.abc import Iterable, Mapping
from typing import Union
@@ -34,6 +35,11 @@ class MultiModalHasher:
return np.array(obj).tobytes()
if isinstance(obj, Image.Image):
exif = obj.getexif()
if Image.ExifTags.Base.ImageID in exif and isinstance(
exif[Image.ExifTags.Base.ImageID], uuid.UUID):
# If the image has exif ImageID tag, use that
return exif[Image.ExifTags.Base.ImageID].bytes
return cls.item_to_bytes(
"image", np.asarray(convert_image_mode(obj, "RGBA")))
if isinstance(obj, torch.Tensor):