@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 9715f7bb0f
Fork 0

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

[Bugfix] Fix incorrect original shape in hashing (#23672)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>

Cyrus Leung committed Aug 27, 2025 at 03:01 UTC 9715f7bb0fd70fa3dac6f35c824e90e58f0086ce
2 files changed +12 -5
tests/multimodal/test_hasher.py
+4 -3
@@ -45,10 +45,11 @@ def test_hash_collision_image_transpose():
45 assert hasher.hash_kwargs(image=image1) != hasher.hash_kwargs(image=image2)
46
47
48 -def test_hash_collision_tensor_shape():
48 +@pytest.mark.parametrize("dtype", [torch.float32, torch.bfloat16])
49 +def test_hash_collision_tensor_shape(dtype):
50 # The hash should be different though the data is the same when flattened
50 - arr1 = torch.zeros((5, 10, 20, 3))
51 - arr2 = torch.zeros((10, 20, 5, 3))
51 + arr1 = torch.zeros((5, 10, 20, 3), dtype=dtype)
52 + arr2 = torch.zeros((10, 20, 5, 3), dtype=dtype)
53
54 hasher = MultiModalHasher
55 assert hasher.hash_kwargs(data=arr1) != hasher.hash_kwargs(data=arr2)
vllm/multimodal/hasher.py
+8 -2
@@ -45,16 +45,22 @@ class MultiModalHasher:
45 if isinstance(obj, torch.Tensor):
46 tensor_obj: torch.Tensor = obj.cpu()
47 tensor_dtype = tensor_obj.dtype
48 + tensor_shape = tensor_obj.shape
49 +
50 + # NumPy does not support bfloat16.
51 + # Workaround: View the tensor as a contiguous 1D array of bytes
52 if tensor_dtype == torch.bfloat16:
53 tensor_obj = tensor_obj.contiguous()
54 tensor_obj = tensor_obj.view(
55 (tensor_obj.numel(), )).view(torch.uint8)
56 +
57 return cls.item_to_bytes(
58 "tensor", {
59 "original_dtype": str(tensor_dtype),
55 - "original_shape": tuple(tensor_obj.shape),
56 - "data": tensor_obj.numpy()
60 + "original_shape": tuple(tensor_shape),
61 + "data": tensor_obj.numpy(),
62 })
63 +
64 return cls.item_to_bytes("tensor", tensor_obj.numpy())
65 if isinstance(obj, np.ndarray):
66 # If the array is non-contiguous, we need to copy it first