"...ssh:/git@developer.sourcefind.cn:2222/OpenDAS/dynamo.git" did not exist on "a9e0891c0383e7db38d3e4794d86accb16b8fe6e"
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-License-Identifier: Apache-2.0
import hashlib
import io
import logging
from typing import Any, Sequence
import blake3
import numpy as np
logger = logging.getLogger(__name__)
......@@ -16,32 +17,18 @@ def image_to_bytes(img: Any) -> bytes:
if isinstance(img, bytes):
return img
if isinstance(img, Image.Image):
buf = io.BytesIO()
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
if isinstance(img, Image.Image | np.ndarray):
return img.tobytes()
raise TypeError(f"Unsupported image type for hashing: {type(img)}")
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] = []
for img in images:
raw_bytes = image_to_bytes(img)
uuids.append(hashlib.sha256(raw_bytes).hexdigest())
uuids.append(blake3.blake3(raw_bytes).hexdigest())
return uuids
......@@ -59,6 +59,7 @@ vllm = [
"nixl[cu12]<=0.9.0",
"vllm[flashinfer,runai]==0.15.1",
"vllm-omni==0.14.0",
"blake3>=1.0.0,<2.0.0",
]
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