Skip to content

Commit de86db1

Browse files
yuekaizhanggemini-code-assist[bot]ywang96DarkLight1337
authored andcommitted
[Bugfix] fix bf16 multimodal model hash (vllm-project#23623)
Signed-off-by: Yuekai Zhang <zhangyuekai@foxmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk> Signed-off-by: Xiao Yu <xiao.yu@amd.com>
1 parent 0a60424 commit de86db1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

vllm/multimodal/hasher.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ def serialize_item(cls, obj: object) -> Union[bytes, memoryview]:
4343
return cls.item_to_bytes(
4444
"image", np.asarray(convert_image_mode(obj, "RGBA")))
4545
if isinstance(obj, torch.Tensor):
46-
return cls.item_to_bytes("tensor", obj.cpu().numpy())
46+
tensor_obj: torch.Tensor = obj.cpu()
47+
tensor_dtype = tensor_obj.dtype
48+
if tensor_dtype == torch.bfloat16:
49+
tensor_obj = tensor_obj.contiguous()
50+
tensor_obj = tensor_obj.view(
51+
(tensor_obj.numel(), )).view(torch.uint8)
52+
return cls.item_to_bytes(
53+
"tensor", {
54+
"original_dtype": str(tensor_dtype),
55+
"original_shape": tuple(tensor_obj.shape),
56+
"data": tensor_obj.numpy()
57+
})
58+
return cls.item_to_bytes("tensor", tensor_obj.numpy())
4759
if isinstance(obj, np.ndarray):
4860
# If the array is non-contiguous, we need to copy it first
4961
arr_data = obj.data if obj.flags.c_contiguous else obj.tobytes()

0 commit comments

Comments
 (0)