Unverified Commit 49eca14b authored by zhongdaor-nv's avatar zhongdaor-nv Committed by GitHub
Browse files

fix: optimize uuid calculation (#6596)


Signed-off-by: default avatarzhongdaor <zhongdaor@nvidia.com>
parent a6d970e9
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import hashlib
import io
import logging import logging
from typing import Any, Sequence from typing import Any, Sequence
import blake3
import numpy as np
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -16,32 +17,18 @@ def image_to_bytes(img: Any) -> bytes: ...@@ -16,32 +17,18 @@ def image_to_bytes(img: Any) -> bytes:
if isinstance(img, bytes): if isinstance(img, bytes):
return img return img
if isinstance(img, Image.Image): if isinstance(img, Image.Image | np.ndarray):
buf = io.BytesIO() return img.tobytes()
img.save(buf, format="PNG")
return buf.getvalue()
# Frontend-decoding can provide image tensors as numpy arrays.
try:
import numpy as np
if isinstance(img, np.ndarray):
pil_img = Image.fromarray(img)
buf = io.BytesIO()
pil_img.save(buf, format="PNG")
return buf.getvalue()
except ImportError:
pass
raise TypeError(f"Unsupported image type for hashing: {type(img)}") raise TypeError(f"Unsupported image type for hashing: {type(img)}")
def compute_mm_uuids_from_images(images: Sequence[Any]) -> list[str]: def compute_mm_uuids_from_images(images: Sequence[Any]) -> list[str]:
""" """
Compute SHA256 hex UUIDs for image inputs. Compute blake3 hex UUIDs for image inputs.
""" """
uuids: list[str] = [] uuids: list[str] = []
for img in images: for img in images:
raw_bytes = image_to_bytes(img) raw_bytes = image_to_bytes(img)
uuids.append(hashlib.sha256(raw_bytes).hexdigest()) uuids.append(blake3.blake3(raw_bytes).hexdigest())
return uuids return uuids
...@@ -59,6 +59,7 @@ vllm = [ ...@@ -59,6 +59,7 @@ vllm = [
"nixl[cu12]<=0.9.0", "nixl[cu12]<=0.9.0",
"vllm[flashinfer,runai]==0.15.1", "vllm[flashinfer,runai]==0.15.1",
"vllm-omni==0.14.0", "vllm-omni==0.14.0",
"blake3>=1.0.0,<2.0.0",
] ]
sglang = [ sglang = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment