[MM] Move supports_multimodal_inputs and cache out of registry (#57913)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -10,20 +10,23 @@ import torch
|
||||
|
||||
from vllm.config import ModelConfig, ParallelConfig, VllmConfig
|
||||
from vllm.config.multimodal import MultiModalConfig
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.multimodal.cache import (
|
||||
BaseMultiModalProcessorCache,
|
||||
BaseMultiModalReceiverCache,
|
||||
MultiModalCache,
|
||||
LruKeyReplicatedReceiverCache,
|
||||
LruKeyReplicatedSenderCache,
|
||||
MultiModalCacheMissError,
|
||||
MultiModalProcessorOnlyCache,
|
||||
ShmObjectStoreReceiverCache,
|
||||
ShmObjectStoreSenderCache,
|
||||
engine_receiver_cache_from_config,
|
||||
processor_cache_from_config,
|
||||
)
|
||||
from vllm.multimodal.cache.base import (
|
||||
MultiModalCache,
|
||||
MultiModalProcessorCacheInItem,
|
||||
MultiModalProcessorCacheItem,
|
||||
MultiModalProcessorCacheItemMetadata,
|
||||
MultiModalProcessorOnlyCache,
|
||||
MultiModalProcessorSenderCache,
|
||||
MultiModalReceiverCache,
|
||||
ShmObjectStoreReceiverCache,
|
||||
ShmObjectStoreSenderCache,
|
||||
)
|
||||
from vllm.multimodal.hasher import MultiModalHasher
|
||||
from vllm.multimodal.inputs import (
|
||||
@@ -137,10 +140,10 @@ def _compare_caches(
|
||||
n_iter: int = 100,
|
||||
seed: int = 0,
|
||||
):
|
||||
cache_0_p0 = MULTIMODAL_REGISTRY.processor_cache_from_config(config_0)
|
||||
cache_0_p1 = MULTIMODAL_REGISTRY.engine_receiver_cache_from_config(config_0)
|
||||
cache_1_p0 = MULTIMODAL_REGISTRY.processor_cache_from_config(config_1)
|
||||
cache_1_p1 = MULTIMODAL_REGISTRY.engine_receiver_cache_from_config(config_1)
|
||||
cache_0_p0 = processor_cache_from_config(config_0)
|
||||
cache_0_p1 = engine_receiver_cache_from_config(config_0)
|
||||
cache_1_p0 = processor_cache_from_config(config_1)
|
||||
cache_1_p1 = engine_receiver_cache_from_config(config_1)
|
||||
|
||||
cache_size_gb = max(
|
||||
config_0.model_config.multimodal_config.mm_processor_cache_gb,
|
||||
@@ -275,8 +278,8 @@ def test_oversized_item_is_served_uncached():
|
||||
assert p0_only.get_and_update_item((small, []), "small")[0] is small
|
||||
assert p0_only.is_cached_item("small")
|
||||
|
||||
p0 = MultiModalProcessorSenderCache(model_config) # type: ignore[arg-type]
|
||||
p1 = MultiModalReceiverCache(model_config) # type: ignore[arg-type]
|
||||
p0 = LruKeyReplicatedSenderCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
assert p0.get_and_update_item((item, []), "big")[0] is item
|
||||
assert not p0.is_cached_item("big")
|
||||
assert p1.get_and_update_item(item, "big") is item
|
||||
@@ -296,8 +299,8 @@ def test_mm_cache_miss_raises_and_recovers():
|
||||
model or network.
|
||||
"""
|
||||
model_config = _StubModelConfig(mm_processor_cache_gb=1)
|
||||
p0 = MultiModalProcessorSenderCache(model_config) # type: ignore[arg-type]
|
||||
p1 = MultiModalReceiverCache(model_config) # type: ignore[arg-type]
|
||||
p0 = LruKeyReplicatedSenderCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
|
||||
mm_hash = "image_A"
|
||||
item = MultiModalKwargsItem.dummy(nbytes=64)
|
||||
@@ -338,7 +341,7 @@ def test_receiver_cache_replaces_stale_item_when_payload_resent():
|
||||
and kills EngineCore. Prefer the fresh payload and keep it for later hits.
|
||||
"""
|
||||
model_config = _StubModelConfig(mm_processor_cache_gb=1)
|
||||
p1 = MultiModalReceiverCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
small = MultiModalKwargsItem.dummy(nbytes=64)
|
||||
large = MultiModalKwargsItem.dummy(nbytes=256)
|
||||
mm_hash = "shared-id"
|
||||
@@ -351,7 +354,7 @@ def test_receiver_cache_replaces_stale_item_when_payload_resent():
|
||||
def test_receiver_cache_features_keep_resent_payload():
|
||||
"""EngineCore updates features through get_and_update_features."""
|
||||
model_config = _StubModelConfig(mm_processor_cache_gb=1)
|
||||
p1 = MultiModalReceiverCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
small = MultiModalKwargsItem.dummy(nbytes=64)
|
||||
large = MultiModalKwargsItem.dummy(nbytes=256)
|
||||
mm_hash = "shared-id"
|
||||
@@ -384,7 +387,7 @@ def test_mm_cache_miss_batches_all_drifted_hashes():
|
||||
non-drifted items in the same request are still ingested.
|
||||
"""
|
||||
model_config = _StubModelConfig(mm_processor_cache_gb=1)
|
||||
p1 = MultiModalReceiverCache(model_config) # type: ignore[arg-type]
|
||||
p1 = LruKeyReplicatedReceiverCache(model_config) # type: ignore[arg-type]
|
||||
item = MultiModalKwargsItem.dummy(nbytes=64)
|
||||
|
||||
def _feature(
|
||||
@@ -582,8 +585,8 @@ def test_cache_eviction_lru_cache():
|
||||
model="llava-hf/llava-onevision-qwen2-0.5b-ov-hf",
|
||||
mm_processor_cache_gb=6 / GiB_bytes,
|
||||
)
|
||||
sender_cache = MultiModalProcessorSenderCache(model_config)
|
||||
receiver_cache = MultiModalReceiverCache(model_config)
|
||||
sender_cache = LruKeyReplicatedSenderCache(model_config)
|
||||
receiver_cache = LruKeyReplicatedReceiverCache(model_config)
|
||||
|
||||
_run_test_cache_eviction_lru(sender_cache, receiver_cache, base_item_size=1)
|
||||
|
||||
@@ -775,7 +778,7 @@ def test_processor_cache_shared_across_loras():
|
||||
model="llava-hf/llava-onevision-qwen2-0.5b-ov-hf",
|
||||
mm_processor_cache_gb=1,
|
||||
)
|
||||
receiver_cache = MultiModalReceiverCache(model_config)
|
||||
receiver_cache = LruKeyReplicatedReceiverCache(model_config)
|
||||
|
||||
base_mm_hash = "image_hash_abc123"
|
||||
lora_a_identifier = f"12345:{base_mm_hash}"
|
||||
@@ -827,8 +830,8 @@ async def test_release_kv_cache_resends_mm_payload(use_async, release_error):
|
||||
)
|
||||
model_config = ctx.model_config
|
||||
|
||||
sender = MultiModalProcessorSenderCache(model_config)
|
||||
receiver = MultiModalReceiverCache(model_config)
|
||||
sender = LruKeyReplicatedSenderCache(model_config)
|
||||
receiver = LruKeyReplicatedReceiverCache(model_config)
|
||||
item = _dummy_item({"pixel_values": 16})
|
||||
mm_hash = "image_A"
|
||||
payload, _ = sender.get_and_update_item((item, []), mm_hash)
|
||||
|
||||
Reference in New Issue
Block a user