[Bugfix][EPD] Preserve explicit multimodal UUIDs with caches disabled (#56432)
Signed-off-by: Tianyu Guo <guoty@inferact.ai>
This commit is contained in:
@@ -176,9 +176,32 @@ def test_multi_modal_uuids_accepts_empty(
|
|||||||
assert processed_mm_uuids == mm_uuids
|
assert processed_mm_uuids == mm_uuids
|
||||||
|
|
||||||
|
|
||||||
def test_multi_modal_uuids_ignored_when_caching_disabled():
|
@pytest.mark.parametrize(
|
||||||
# When both processor cache is 0 and prefix caching disabled, the
|
"mm_uuids, expected",
|
||||||
# processor builds overrides from request id instead of using user UUIDs.
|
[
|
||||||
|
(
|
||||||
|
{"image": ["hash_cherry", "hash_stop"], "video": ["hash_video"]},
|
||||||
|
{"image": ["hash_cherry", "hash_stop"], "video": ["hash_video"]},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"image": [None, "hash_stop"], "video": None},
|
||||||
|
{"image": ["req-42-image-0", "hash_stop"], "video": ["req-42-video-0"]},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{"image": ["", None]},
|
||||||
|
{"image": ["", "req-42-image-1"], "video": ["req-42-video-0"]},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
"image": ["req-42-image-0", "req-42-image-1"],
|
||||||
|
"video": ["req-42-video-0"],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_multi_modal_uuids_preserved_when_caching_disabled(mm_uuids, expected):
|
||||||
|
"""Only missing UUIDs get request-local IDs when both caches are disabled."""
|
||||||
renderer = _build_renderer(mm_cache_gb=0.0, enable_prefix_caching=False)
|
renderer = _build_renderer(mm_cache_gb=0.0, enable_prefix_caching=False)
|
||||||
|
|
||||||
request_id = "req-42"
|
request_id = "req-42"
|
||||||
@@ -186,7 +209,6 @@ def test_multi_modal_uuids_ignored_when_caching_disabled():
|
|||||||
"image": [cherry_pil_image, stop_pil_image],
|
"image": [cherry_pil_image, stop_pil_image],
|
||||||
"video": baby_reading_np_ndarrays,
|
"video": baby_reading_np_ndarrays,
|
||||||
}
|
}
|
||||||
mm_uuids = {"image": ["hash_cherry", "hash_stop"], "video": ["hash_video"]}
|
|
||||||
|
|
||||||
mm_processor = renderer.get_mm_processor()
|
mm_processor = renderer.get_mm_processor()
|
||||||
mm_data_items = mm_processor.info.parse_mm_data(mm_data)
|
mm_data_items = mm_processor.info.parse_mm_data(mm_data)
|
||||||
@@ -196,16 +218,4 @@ def test_multi_modal_uuids_ignored_when_caching_disabled():
|
|||||||
mm_data, mm_data_items, mm_uuid_items, request_id
|
mm_data, mm_data_items, mm_uuid_items, request_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# Expect request-id-based overrides are passed through
|
assert processed_mm_uuids == expected
|
||||||
assert set(mm_uuids.keys()) == {"image", "video"}
|
|
||||||
assert len(mm_uuids["image"]) == 2
|
|
||||||
assert len(mm_uuids["video"]) == 1
|
|
||||||
assert processed_mm_uuids["image"][0].startswith(
|
|
||||||
f"{request_id}-image-"
|
|
||||||
) and processed_mm_uuids["image"][0].endswith("-0")
|
|
||||||
assert processed_mm_uuids["image"][1].startswith(
|
|
||||||
f"{request_id}-image-"
|
|
||||||
) and processed_mm_uuids["image"][1].endswith("-1")
|
|
||||||
assert processed_mm_uuids["video"][0].startswith(
|
|
||||||
f"{request_id}-video-"
|
|
||||||
) and processed_mm_uuids["video"][0].endswith("-0")
|
|
||||||
|
|||||||
+11
-9
@@ -824,20 +824,22 @@ class BaseRenderer(ABC, Generic[_T]):
|
|||||||
) -> MultiModalUUIDItems:
|
) -> MultiModalUUIDItems:
|
||||||
model_config = self.model_config
|
model_config = self.model_config
|
||||||
|
|
||||||
# NOTE: When users explicitly turn off BOTH prefix caching and input
|
# Skip content hashing when both caches are disabled, but preserve
|
||||||
# processing caching, no multimodal features or embeddings will be
|
# explicit UUIDs used to identify embeddings across EC instances.
|
||||||
# reused across requests, therefore identifying multimodal data items
|
|
||||||
# by their content is no longer necessary, and we create uuids with
|
|
||||||
# `<mm_req_id>-<modality>-<index>`, overriding even user-provided ones.
|
|
||||||
if (
|
if (
|
||||||
model_config.multimodal_config
|
model_config.multimodal_config
|
||||||
and model_config.multimodal_config.mm_processor_cache_gb == 0
|
and model_config.multimodal_config.mm_processor_cache_gb == 0
|
||||||
and not self.config.cache_config.enable_prefix_caching
|
and not self.config.cache_config.enable_prefix_caching
|
||||||
):
|
):
|
||||||
mm_uuid_items = {
|
mm_uuid_items = dict(mm_uuid_items)
|
||||||
modality: [f"{mm_req_id}-{modality}-{i}" for i in range(data_count)]
|
for modality, data_count in mm_data_items.get_all_counts().items():
|
||||||
for modality, data_count in mm_data_items.get_all_counts().items()
|
uuids = mm_uuid_items.get(modality)
|
||||||
}
|
if uuids is None:
|
||||||
|
uuids = [None] * data_count
|
||||||
|
mm_uuid_items[modality] = [
|
||||||
|
uuid if uuid is not None else f"{mm_req_id}-{modality}-{i}"
|
||||||
|
for i, uuid in enumerate(uuids)
|
||||||
|
]
|
||||||
|
|
||||||
self._validate_mm_uuids(mm_data, mm_data_items, mm_uuid_items)
|
self._validate_mm_uuids(mm_data, mm_data_items, mm_uuid_items)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user