[Perf] Hash videos by source bytes (#49607)
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com> Signed-off-by: Guan-Ming Chiu <105915352+guan404ming@users.noreply.github.com> Co-authored-by: Isotr0py <2037008807@qq.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Isotr0py
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
d2ca3002d9
commit
04502deca2
@@ -9,6 +9,8 @@ import torch
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from vllm.multimodal.hasher import MultiModalHasher
|
||||
from vllm.multimodal.media.base import MediaWithBytes
|
||||
from vllm.multimodal.parse import MultiModalDataParser
|
||||
|
||||
pytestmark = pytest.mark.cpu_test
|
||||
|
||||
@@ -82,6 +84,29 @@ def test_hash_collision_array_shape():
|
||||
assert hasher.hash_kwargs(data=arr1) != hasher.hash_kwargs(data=arr2)
|
||||
|
||||
|
||||
def test_hash_collision_video_num_frames():
|
||||
source = b"x" * 100
|
||||
|
||||
def item_for_hash(num_frames: int):
|
||||
frames: np.ndarray = np.zeros((num_frames, 8, 8, 3), dtype=np.uint8)
|
||||
metadata = {
|
||||
"total_num_frames": 16,
|
||||
"fps": 2.0,
|
||||
"duration": 8.0,
|
||||
"video_backend": "opencv",
|
||||
"frames_indices": list(range(num_frames)),
|
||||
"do_sample_frames": False,
|
||||
}
|
||||
video = MediaWithBytes((frames, metadata), source)
|
||||
items = MultiModalDataParser()._parse_video_data([video])
|
||||
return items.get_all_items_for_hash()[0]
|
||||
|
||||
hasher = MultiModalHasher
|
||||
assert hasher.hash_kwargs(video=item_for_hash(2)) != hasher.hash_kwargs(
|
||||
video=item_for_hash(4)
|
||||
)
|
||||
|
||||
|
||||
def test_hash_non_contiguous_array():
|
||||
arr = np.arange(24).reshape(4, 6).T
|
||||
assert not arr.flags.c_contiguous
|
||||
|
||||
Reference in New Issue
Block a user