vllm.multimodal.cache
¶
Modules:
-
base– -
factories– -
lru–Implementation of Key-Replicated Cache (see docs/configuration/optimization.md).
-
shm–Implementation of Shared Memory Cache (see docs/configuration/optimization.md).
Classes:
-
BaseMultiModalProcessorCache–The required interface for caches on P0.
-
BaseMultiModalReceiverCache–The required interface for caches on P1.
-
LruKeyReplicatedReceiverCache–The cache which is used on P1 when LRU caching is enabled.
-
LruKeyReplicatedSenderCache–The cache which is used on P0 when LRU caching is enabled.
-
MultiModalCacheMissError–Raised by the P1 receiver cache when items are requested with no data and
-
MultiModalProcessorOnlyCache–The cache which is used on P0 when IPC caching is disabled.
-
ShmObjectStoreReceiverCache–The cache which is used on P1 Worker Process when SHM caching is enabled.
-
ShmObjectStoreSenderCache–The cache which is used on P0 when SHM caching is enabled.
Functions:
-
engine_receiver_cache_from_config–Return a
BaseMultiModalReceiverCachefor the engine process. -
processor_cache_from_config–Return a
BaseMultiModalProcessorCache, if enabled. -
processor_only_cache_from_config–Return a
MultiModalProcessorOnlyCache, if enabled. -
worker_receiver_cache_from_config–Return a
BaseMultiModalReceiverCachefor the worker process.
BaseMultiModalProcessorCache
¶
Bases: BaseMultiModalCache[MultiModalProcessorCacheInItem, MultiModalProcessorCacheOutItem]
The required interface for caches on P0.
Methods:
-
close–Close the underlying cache, if needed.
-
get_cached_item–Return a locally stored payload without updating eviction order.
-
invalidate–Drop
mm_hashfrom this P0 shadow cache to recover from P0/P1 drift. -
is_cached–Check whether a sequence of multi-modal items are
-
is_cached_item–Check whether a multi-modal item is
-
make_stats–Get (and reset) the multi-modal cache stats.
-
release_sender_touches–Release the items that were touched but not updated afterwards.
-
touch_sender_cache_item–Update the cache eviction order for a multi-modal item.
-
validate_input_item–Validate externally supplied cache metadata before engine handoff.
close()
¶
Close the underlying cache, if needed.
get_cached_item(mm_hash)
¶
Return a locally stored payload without updating eviction order.
Metadata-only and shared-memory sender caches do not retain a local
payload, so they return None.
invalidate(mm_hash)
¶
Drop mm_hash from this P0 shadow cache to recover from P0/P1 drift.
No-op by default; shadow caches that can drift from P1 override this.
is_cached(mm_hashes)
¶
is_cached_item(mm_hash)
abstractmethod
¶
make_stats(*, delta=False)
abstractmethod
¶
Get (and reset) the multi-modal cache stats.
Returns:
-
CacheInfo–The current multi-modal caching stats.
release_sender_touches()
¶
Release the items that were touched but not updated afterwards.
touch_sender_cache_item(mm_hash)
abstractmethod
¶
validate_input_item(mm_item, mm_hash)
¶
Validate externally supplied cache metadata before engine handoff.
BaseMultiModalReceiverCache
¶
Bases: BaseMultiModalCache[MultiModalKwargsItem | None, MultiModalKwargsItem]
The required interface for caches on P1.
Methods:
-
get_and_update_features–Update multimodal features with cached encoder outputs.
-
touch_receiver_cache_item–Update the cache eviction order for a multi-modal item.
get_and_update_features(mm_features)
¶
Update multimodal features with cached encoder outputs. Touch all identifier at first before update to avoid item in updated list evict during update.
Uses mm_hash for cache key to share across LoRAs (falls back to identifier for backward compatibility).
touch_receiver_cache_item(mm_hash, mm_item=None)
abstractmethod
¶
Update the cache eviction order for a multi-modal item.
This is used to touch the item in the cache without changing its value.
Parameters:
-
(mm_hash¶str) –The hash of the multi-modal item.
-
(mm_item¶MultiModalKwargsItem | None, default:None) –The multi-modal item itself. This is optional and may not be needed by some cache implementations.
LruKeyReplicatedReceiverCache
¶
Bases: BaseMultiModalReceiverCache
The cache which is used on P1 when LRU caching is enabled.
How to update each item:
- If the caller sent tensor data, store it (replacing any cached item under the same key) and return that data. P0 can miss after independent LRU eviction and resend a different item for the same identity.
- If the caller sent no data and the item is cached, return the cached item.
- If the caller sent no data and the item is not cached, raise
MultiModalCacheMissError. - A payload with only placeholder metadata (an EC consumer's metadata-only item) bypasses the cache: it must not replace, or later stand in for, an item that the encoder can run on.
LruKeyReplicatedSenderCache
¶
Bases: BaseMultiModalProcessorCache
The cache which is used on P0 when LRU caching is enabled.
How to update each item:
-
If the item is already in the cache, clear the input to avoid unnecessary IPC.
-
If the item is not in the cache, store the metadata of that item so that the eviction policy remains the same as the cache on P1, and return the input. By only storing the metadata, we avoid keeping the data itself in memory inside P0.
MultiModalCacheMissError
¶
Bases: RuntimeError
Raised by the P1 receiver cache when items are requested with no data and are not cached.
P0 (frontend) keeps a metadata-only shadow of P1 (engine) and sends
data=None on a shadow hit. The two caches are updated in different orders
across processes, so they can drift -- leaving P0 referencing items P1 has
evicted. Raising (instead of asserting) lets the engine return a retryable
response and have P0 drop the stale entries
(BaseMultiModalProcessorCache.invalidate) so the client resends the data.
Carries every drifted mm_hash in the request so P0 can drop them all in one
pass -- one retry then recovers the whole request, not one item per retry.
MultiModalProcessorOnlyCache
¶
Bases: BaseMultiModalProcessorCache
The cache which is used on P0 when IPC caching is disabled.
How to update each item:
- If the item is in the cache, replace the input with the cached item.
- If the item is not in the cache, store that item (which includes tensor data and metadata) into the cache, and return the input.
ShmObjectStoreReceiverCache
¶
Bases: BaseMultiModalReceiverCache
The cache which is used on P1 Worker Process when SHM caching is enabled.
How to update each item:
- If the item has an address, replace the input with the cached item.
- If not, return the input.
Methods:
-
touch_receiver_cache_item–Validate the item's handle in shared memory cache.
touch_receiver_cache_item(mm_hash, mm_item=None)
¶
Validate the item's handle in shared memory cache.
ShmObjectStoreSenderCache
¶
Bases: BaseMultiModalProcessorCache
The cache which is used on P0 when SHM caching is enabled.
How to update each item:
-
If the item is already in the cache, clear the input to avoid unnecessary IPC.
-
If the item is not in the cache, store the data in shared memory.
Methods:
-
remove_dangling_items–Remove items that are no longer in the shared memory cache.
-
touch_sender_cache_item–Touch the item in shared memory cache to prevent eviction.
engine_receiver_cache_from_config(vllm_config)
¶
Return a BaseMultiModalReceiverCache for the engine process.
processor_cache_from_config(vllm_config)
¶
Return a BaseMultiModalProcessorCache, if enabled.
processor_only_cache_from_config(vllm_config)
¶
Return a MultiModalProcessorOnlyCache, if enabled.
worker_receiver_cache_from_config(vllm_config, shared_worker_lock)
¶
Return a BaseMultiModalReceiverCache for the worker process.