A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
Improve multimodal hasher performance for re-used Image prompts (#22825)
Signed-off-by: Staszek Pasko <staszek@gmail.com>
Staszek Paśko committed
Aug 15, 2025 at 14:32 UTC
22341b996e7b6361624dd2909df0d9b37ae6e41e
2 files changed
+26
tests/multimodal/test_hasher.py
+20
@@ -1,5 +1,6 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+import uuid
4
from pathlib import Path
5
6
import numpy as np
@@ -72,3 +73,22 @@ def test_hash_non_contiguous_array():
73
hasher = MultiModalHasher
74
# Both should be hashable and produce the same hashes
75
assert hasher.hash_kwargs(data=arr) == hasher.hash_kwargs(data=arr_c)
76
+
77
+
78
+def test_hash_image_exif_id():
79
+ # Test that EXIF ImageId tag can be used to store UUID
80
+ # and the hasher will use that instead of the image data.
81
+ image1 = image2 = Image.new("1", size=(10, 20))
82
+ id = uuid.uuid4()
83
+ image1.getexif()[Image.ExifTags.Base.ImageID] = id
84
+ image2 = Image.open(ASSETS_DIR / "image1.png")
85
+ image2.getexif()[Image.ExifTags.Base.ImageID] = "Not a UUID"
86
+ image2a = Image.open(ASSETS_DIR / "image1.png")
87
+
88
+ hasher = MultiModalHasher
89
+ # first image has UUID in ImageID, so it should hash to that UUID
90
+ assert hasher.hash_kwargs(image=image1) == hasher.hash_kwargs(
91
+ image=id.bytes)
92
+ # second image has non-UUID in ImageID, so it should hash to the image data
93
+ assert hasher.hash_kwargs(image=image2) == hasher.hash_kwargs(
94
+ image=image2a)
vllm/multimodal/hasher.py
+6
@@ -2,6 +2,7 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import pickle
5
+import uuid
6
from collections.abc import Iterable, Mapping
7
from typing import Union
8
@@ -34,6 +35,11 @@ class MultiModalHasher:
35
return np.array(obj).tobytes()
36
37
if isinstance(obj, Image.Image):
38
+ exif = obj.getexif()
39
+ if Image.ExifTags.Base.ImageID in exif and isinstance(
40
+ exif[Image.ExifTags.Base.ImageID], uuid.UUID):
41
+ # If the image has exif ImageID tag, use that
42
+ return exif[Image.ExifTags.Base.ImageID].bytes
43
return cls.item_to_bytes(
44
"image", np.asarray(convert_image_mode(obj, "RGBA")))
45
if isinstance(obj, torch.Tensor):