From 27f8e6b9c15369dcf9ff25cfc58b4abfbe63a316 Mon Sep 17 00:00:00 2001 From: huangtingwei <141888744+huangtingwei9988@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:43:23 +0800 Subject: [PATCH] fix multimodal hash feature (#5083) --- python/sglang/srt/managers/schedule_batch.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/sglang/srt/managers/schedule_batch.py b/python/sglang/srt/managers/schedule_batch.py index 26b6b91b7..736df1a7b 100644 --- a/python/sglang/srt/managers/schedule_batch.py +++ b/python/sglang/srt/managers/schedule_batch.py @@ -198,8 +198,15 @@ class MultimodalDataItem: Set the pad value after first hashign the data """ + def tensor_hash(f): + f_list = flatten_nested_list(f) + f_cat = torch.concat(f_list).contiguous().numpy().tobytes() + return hash(f_cat) + def hash_feature(f): if isinstance(f, list): + if isinstance(f[0], torch.Tensor): + return tensor_hash(f) return hash(tuple(flatten_nested_list(f))) elif isinstance(f, np.ndarray): arr = np.ascontiguousarray(f)