[Bugfix][Multimodal] Scope cache hash kwargs by modality (#54918)

Signed-off-by: waizuichougou <2082431897@qq.com>
This commit is contained in:
waizuichougou
2026-09-02 14:20:26 +00:00
committed by GitHub
parent 872084fb77
commit c6bca6e585
2 changed files with 88 additions and 10 deletions
+47
View File
@@ -1284,3 +1284,50 @@ def test_processor_inputs_hashes_partial_uuids():
),
]
}
def test_processor_inputs_hashes_scope_kwargs_by_modality():
"""Changing one modality's options must not invalidate another item."""
rng = np.random.RandomState(0)
mm_data_items = MultiModalDataParser().parse_mm_data(
{
"image": [random_image(rng, min_wh=8, max_wh=9)],
"video": [np.zeros((2, 8, 8, 3), dtype=np.uint8)],
}
)
mm_uuid_items = {"image": ["image-uuid"], "video": ["video-uuid"]}
def get_hashes(video_frames: int, image_size: int, video_size: int):
return ProcessorInputs(
prompt=[],
mm_data_items=mm_data_items,
mm_uuid_items=mm_uuid_items,
media_io_kwargs={"video": {"num_frames": video_frames}},
hf_processor_mm_kwargs={
"images_kwargs": {"size": {"longest_edge": image_size}},
"videos_kwargs": {"size": {"longest_edge": video_size}},
},
).get_mm_hashes("test-model", "blake3")
base = get_hashes(video_frames=4, image_size=224, video_size=224)
changed_video = get_hashes(video_frames=16, image_size=224, video_size=448)
changed_image = get_hashes(video_frames=4, image_size=448, video_size=224)
assert changed_video["image"] == base["image"]
assert changed_video["video"] != base["video"]
assert changed_image["image"] != base["image"]
assert changed_image["video"] == base["video"]
def test_processor_inputs_hashes_ignore_unrelated_kwargs():
"""An image-only request ignores video-only processing configuration."""
image = random_image(np.random.RandomState(0), min_wh=8, max_wh=9)
inputs = ProcessorInputs(
prompt=[],
mm_data_items=MultiModalDataParser().parse_mm_data({"image": [image]}),
mm_uuid_items={"image": ["image-uuid"]},
media_io_kwargs={"video": {"num_frames": 16}},
hf_processor_mm_kwargs={"videos_kwargs": {"size": {"longest_edge": 448}}},
)
assert inputs.get_mm_hashes("test-model", "blake3") == {"image": ["image-uuid"]}