vllm_mlx.mllm_cache¶
MLLM (Multimodal Language Model) Prefix Cache Manager.
View the complete module source at #L1-L459.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
vllm_mlx.mllm_cache
¶
MLLM (Multimodal Language Model) Prefix Cache Manager.
This module provides advanced caching for MLLM inference, implementing the LMCache-style approach for multimodal prefix caching:
Features: - Image content hashing for cache keys (LMCache style) - Vision embedding caching (skip encoder on hit) - KV cache state caching with prefix matching - Token ID tracking for partial prefix reuse - LRU eviction policy with memory limits - Stats tracking (hits, misses, tokens saved, encoder skips)
Based on research from: - LMCache: https://blog.lmcache.ai/2025-07-03-multimodal-models/ - vLLM Prefix Caching: https://docs.vllm.ai/en/stable/design/prefix_caching/ - mlx-lm cache_prompt: https://github.com/ml-explore/mlx-lm
vllm_mlx.mllm_cache.VLMPrefixCacheEntry
module-attribute
¶
VLMPrefixCacheEntry = MLLMPrefixCacheEntry
vllm_mlx.mllm_cache.VLMPrefixCacheManager
module-attribute
¶
VLMPrefixCacheManager = MLLMPrefixCacheManager
vllm_mlx.mllm_cache.MLLMCacheStats
dataclass
¶
MLLMCacheStats(hits: int = 0, misses: int = 0, partial_hits: int = 0, tokens_saved: int = 0, image_cache_hits: int = 0, vision_encoder_skips: int = 0, total_queries: int = 0, evictions: int = 0)
Statistics for MLLM cache performance.
vllm_mlx.mllm_cache.MLLMCacheStats.partial_hits
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.tokens_saved
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.image_cache_hits
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.vision_encoder_skips
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.total_queries
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.evictions
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMCacheStats.to_dict
¶
Convert stats to dictionary.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry
dataclass
¶
MLLMPrefixCacheEntry(image_hash: str, prompt_hash: str, vision_embeddings: Any = None, kv_cache: list[Any] = list(), token_ids: list[int] = list(), num_image_tokens: int = 0, num_text_tokens: int = 0, prompt_tokens: int = 0, created_at: float = time(), hit_count: int = 0, model_name: str = '')
Enhanced cache entry storing vision embeddings, KV cache, and token IDs.
This enables: 1. Skipping vision encoder on image cache hit (saves ~1-2s per image) 2. Skipping prefix computation on token match (saves ~0.5s per 1k tokens) 3. Partial prefix reuse for multi-turn conversations
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.vision_embeddings
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.kv_cache
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.token_ids
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.num_image_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.num_text_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.prompt_tokens
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.created_at
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.hit_count
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.model_name
class-attribute
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.total_tokens
property
¶
Return the number of token IDs represented by this cache entry.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.memory_size
property
¶
Estimate memory usage in bytes.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.get_prefix_match_length
¶
Find how many tokens match between cached prefix and new input.
This is the key to prefix caching - if the first N tokens match, we can skip computing KV states for those N tokens.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager
¶
LRU Cache manager for MLLM prefix states with vision embedding caching.
Implements the LMCache approach for multimodal caching: 1. Hash-based identification of image+prompt combinations 2. Vision embedding caching (skip encoder on hit - saves 1-2s!) 3. KV cache reuse for matching prefixes 4. Token ID tracking for partial prefix matching 5. Memory-based eviction (configurable limit)
Example
cache = MLLMPrefixCacheManager(max_memory_mb=2048)
First request - cache miss, full computation¶
entry, match_len = cache.fetch(["image.jpg"], prompt, token_ids)
... run full forward pass ...¶
cache.store(["image.jpg"], prompt, vision_emb, kv_cache, token_ids)
Second request with same image - cache hit!¶
entry, match_len = cache.fetch(["image.jpg"], prompt, token_ids)
entry.vision_embeddings available - skip encoder!¶
match_len > 0 - skip prefix computation!¶
Performance (Gemma 3 27B, 256 image tokens): - Vision encoder: ~1.5s -> 0s (skip on hit) - Prefix computation: ~0.5s/1k tokens -> 0s (skip on match) - Multi-turn speedup: 8-12x for subsequent turns
Initialize MLLM prefix cache manager.
Parameters:
-
max_entries(int, default:50) –Maximum number of cache entries (default: 50)
-
max_memory_mb(int, default:2048) –Maximum memory in MB (default: 2048)
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.max_memory
instance-attribute
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._cache
instance-attribute
¶
_cache: OrderedDict[str, MLLMPrefixCacheEntry] = OrderedDict()
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._make_cache_key
¶
Create cache key from images and prompt.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._make_image_only_key
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._evict_by_memory
¶
Evict entries until we have enough memory.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._evict_by_count
¶
Evict entries until we're under max_size.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch
¶
fetch(images: list[str], prompt: str, token_ids: list[int] | None = None) -> tuple[MLLMPrefixCacheEntry | None, int]
Fetch cached prefix state with prefix matching.
This is the main entry point for cache lookups. Returns both the cache entry (if found) and the prefix match length.
Parameters:
-
images(list[str]) –List of image paths
-
prompt(str) –Text prompt
-
token_ids(list[int] | None, default:None) –Optional token IDs for prefix matching
Returns:
-
MLLMPrefixCacheEntry | None–Tuple of (entry, prefix_match_length) where:
-
int–- entry: The cache entry if found, None otherwise
-
tuple[MLLMPrefixCacheEntry | None, int]–- prefix_match_length: Number of tokens that match (0 if miss)
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch_cache
¶
Legacy API: Fetch cached KV state for image+prompt combination.
For backwards compatibility with existing code.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store
¶
store(images: list[str], prompt: str, vision_embeddings: Any, kv_cache: list[Any], token_ids: list[int], num_image_tokens: int = 0, model_name: str = '') -> None
Store prefix state in cache.
Parameters:
-
images(list[str]) –List of image paths
-
prompt(str) –Text prompt
-
vision_embeddings(Any) –Output of vision encoder (can be None for text-only)
-
kv_cache(list[Any]) –Language model KV cache states
-
token_ids(list[int]) –Full token sequence
-
num_image_tokens(int, default:0) –Number of image tokens (e.g., 256 for Gemma 3)
-
model_name(str, default:'') –Model name for validation
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store_cache
¶
Legacy API: Store KV cache for future reuse.
For backwards compatibility with existing code.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.get_stats
¶
Get cache statistics.
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.reset_stats
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.clear
¶
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.__len__
¶
vllm_mlx.mllm_cache.compute_image_hash
¶
Compute hash of image content for cache key.
Following LMCache approach: hash the actual image bytes, not the path. This ensures cache hits even when the same image is loaded from different paths or as base64.
Parameters:
-
image_path(str) –Path to image file
Returns:
-
str–SHA256 hash of image content (first 16 chars)
Source code in vllm_mlx/mllm_cache.py
vllm_mlx.mllm_cache.compute_images_hash
¶
Compute combined hash for multiple images.
Parameters:
-
images(list[str]) –List of image paths/URLs
Returns:
-
str–Combined hash string
Source code in vllm_mlx/mllm_cache.py
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
vllm_mlx.mllm_cache.MLLMCacheStats · class
vllm_mlx.mllm_cache.MLLMCacheStats(hits: int = 0, misses: int = 0, partial_hits: int = 0, tokens_saved: int = 0, image_cache_hits: int = 0, vision_encoder_skips: int = 0, total_queries: int = 0, evictions: int = 0)
Statistics for MLLM cache performance.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
misses |
int |
no |
0 |
Optional constructor field; defaults to 0. |
partial_hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
tokens_saved |
int |
no |
0 |
Optional constructor field; defaults to 0. |
image_cache_hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
vision_encoder_skips |
int |
no |
0 |
Optional constructor field; defaults to 0. |
total_queries |
int |
no |
0 |
Optional constructor field; defaults to 0. |
evictions |
int |
no |
0 |
Optional constructor field; defaults to 0. |
Returns
- Constructs:
vllm_mlx.mllm_cache.MLLMCacheStats
Exceptions and behavior
Class MLLMCacheStats declares 2 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMCacheStats.hit_rate · method
Calculate cache hit rate.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
0.0;self.hits / self.total_queries
Exceptions and behavior
Method MLLMCacheStats.hit_rate has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMCacheStats.to_dict · method
Convert stats to dictionary.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'hits': self.hits, 'misses': self.misses, 'partial_hits': self.partial_hits, 'hit_rate': self.hit_rate, 'tokens_saved'…
Exceptions and behavior
Method MLLMCacheStats.to_dict returns {'hits': self.hits, 'misses': self.misses, 'partial_hits': self.partial_hits, 'hit_rate': self.hit_rate, 'tokens_saved'….
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry · class
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry(image_hash: str, prompt_hash: str, vision_embeddings: Any = None, kv_cache: list[Any] = field(default_factory=list), token_ids: list[int] = field(default_factory=list), num_image_tokens: int = 0, num_text_tokens: int = 0, prompt_tokens: int = 0, created_at: float = field(default_factory=time.time), hit_count: int = 0, model_name: str = '')
Enhanced cache entry storing vision embeddings, KV cache, and token IDs.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image_hash |
str |
yes |
none |
Required constructor field. |
prompt_hash |
str |
yes |
none |
Required constructor field. |
vision_embeddings |
Any |
no |
None |
Optional constructor field; defaults to None. |
kv_cache |
list[Any] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
token_ids |
list[int] |
no |
field(default_factory=list) |
Optional constructor field; defaults to field(default_factory=list). |
num_image_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
num_text_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
prompt_tokens |
int |
no |
0 |
Optional constructor field; defaults to 0. |
created_at |
float |
no |
field(default_factory=time.time) |
Optional constructor field; defaults to field(default_factory=time.time). |
hit_count |
int |
no |
0 |
Optional constructor field; defaults to 0. |
model_name |
str |
no |
'' |
Optional constructor field; defaults to ''. |
Returns
- Constructs:
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry
Exceptions and behavior
Class MLLMPrefixCacheEntry declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.total_tokens · method
Return the number of token IDs represented by this cache entry.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
len(self.token_ids)
Exceptions and behavior
Method MLLMPrefixCacheEntry.total_tokens calls len; returns len(self.token_ids).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.memory_size · method
Estimate memory usage in bytes.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
size
Exceptions and behavior
Method MLLMPrefixCacheEntry.memory_size calls hasattr; returns size.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheEntry.get_prefix_match_length · method
Find how many tokens match between cached prefix and new input.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
new_token_ids |
list[int] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
int - Direct return expressions:
match_length
Exceptions and behavior
Method MLLMPrefixCacheEntry.get_prefix_match_length calls enumerate, zip; returns match_length.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.compute_image_hash · function
Compute hash of image content for cache key.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image_path |
str |
yes |
none |
Path to image file |
Returns
- Type:
str - Direct return expressions:
hashlib.sha256(content).hexdigest()[:16];hashlib.sha256(image_path.encode()).hexdigest()[:16];hashlib.sha256(str(image_path).encode()).hexdigest()[:16]
Exceptions and behavior
Function compute_image_hash calls Path, path.exists, path.read_bytes, hashlib.sha256(content).hexdigest; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.compute_images_hash · function
Compute combined hash for multiple images.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
List of image paths/URLs |
Returns
- Type:
str - Direct return expressions:
'no_images';hashlib.sha256(combined.encode()).hexdigest()[:16]
Exceptions and behavior
Function compute_images_hash calls compute_image_hash, '_'.join, sorted, hashlib.sha256(combined.encode()).hexdigest; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager · class
LRU Cache manager for MLLM prefix states with vision embedding caching.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_entries |
int |
no |
50 |
Maximum number of cache entries (default: 50) |
max_memory_mb |
int |
no |
2048 |
Maximum memory in MB (default: 2048) |
Returns
- Constructs:
vllm_mlx.mllm_cache.MLLMPrefixCacheManager
Exceptions and behavior
Class MLLMPrefixCacheManager declares 14 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.__init__ · method
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.__init__(max_entries: int = 50, max_memory_mb: int = 2048) -> not annotated
Initialize MLLM prefix cache manager.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_entries |
int |
no |
50 |
Maximum number of cache entries (default: 50) |
max_memory_mb |
int |
no |
2048 |
Maximum memory in MB (default: 2048) |
Returns
- Type:
not annotated
Exceptions and behavior
Method MLLMPrefixCacheManager.__init__ updates self.max_size, self.max_memory, self._cache, self._current_memory; calls OrderedDict, MLLMCacheStats.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._make_cache_key · method
Create cache key from images and prompt.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
Required positional or keyword input. |
prompt |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
f'{image_hash}_{prompt_hash}'
Exceptions and behavior
Method MLLMPrefixCacheManager._make_cache_key calls compute_images_hash, hashlib.sha256(prompt.encode()).hexdigest, hashlib.sha256, prompt.encode; returns f'{image_hash}_{prompt_hash}'.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._make_image_only_key · method
Create cache key for image-only lookup (vision embedding reuse).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
compute_images_hash(images)
Exceptions and behavior
Method MLLMPrefixCacheManager._make_image_only_key calls compute_images_hash; returns compute_images_hash(images).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._evict_by_memory · method
Evict entries until we have enough memory.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
required_size |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method MLLMPrefixCacheManager._evict_by_memory updates self._current_memory, self.stats.evictions; calls next, iter, self._cache.pop, logger.debug.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager._evict_by_count · method
Evict entries until we're under max_size.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLLMPrefixCacheManager._evict_by_count updates self._current_memory, self.stats.evictions; calls len, next, iter, self._cache.pop.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch · method
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch(images: list[str], prompt: str, token_ids: list[int] | None = None) -> tuple[MLLMPrefixCacheEntry | None, int]
Fetch cached prefix state with prefix matching.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
List of image paths |
prompt |
str |
yes |
none |
Text prompt |
token_ids |
list[int] \| None |
no |
None |
Optional token IDs for prefix matching |
Returns
- Type:
tuple[MLLMPrefixCacheEntry | None, int] - Direct return expressions:
(entry, match_length);(entry, 0);(None, 0)
Exceptions and behavior
Method MLLMPrefixCacheManager.fetch updates self.stats.total_queries, self.stats.hits, self.stats.image_cache_hits, self.stats.vision_encoder_skips; calls self._make_cache_key, self._cache.pop, entry.get_prefix_match_length, logger.debug; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch_cache · method
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.fetch_cache(images: list[str], prompt: str) -> tuple[list[Any] | None, bool]
Legacy API: Fetch cached KV state for image+prompt combination.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
Required positional or keyword input. |
prompt |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[list[Any] | None, bool] - Direct return expressions:
(entry.kv_cache, True);(None, False)
Exceptions and behavior
Method MLLMPrefixCacheManager.fetch_cache calls self.fetch; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store · method
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store(images: list[str], prompt: str, vision_embeddings: Any, kv_cache: list[Any], token_ids: list[int], num_image_tokens: int = 0, model_name: str = '') -> None
Store prefix state in cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
List of image paths |
prompt |
str |
yes |
none |
Text prompt |
vision_embeddings |
Any |
yes |
none |
Output of vision encoder (can be None for text-only) |
kv_cache |
list[Any] |
yes |
none |
Language model KV cache states |
token_ids |
list[int] |
yes |
none |
Full token sequence |
num_image_tokens |
int |
no |
0 |
Number of image tokens (e.g., 256 for Gemma 3) |
model_name |
str |
no |
'' |
Model name for validation |
Returns
- Type:
None
Exceptions and behavior
Method MLLMPrefixCacheManager.store updates self._current_memory; calls self._make_cache_key, MLLMPrefixCacheEntry, compute_images_hash, hashlib.sha256(prompt.encode()).hexdigest.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store_cache · method
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.store_cache(images: list[str], prompt: str, cache: list[Any] | None, num_tokens: int = 0) -> None
Legacy API: Store KV cache for future reuse.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
list[str] |
yes |
none |
Required positional or keyword input. |
prompt |
str |
yes |
none |
Required positional or keyword input. |
cache |
list[Any] \| None |
yes |
none |
Required positional or keyword input. |
num_tokens |
int |
no |
0 |
Optional positional or keyword input; defaults to 0. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method MLLMPrefixCacheManager.store_cache calls isinstance, len, self.store; returns None.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.get_stats · method
Get cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict[str, Any] - Direct return expressions:
stats
Exceptions and behavior
Method MLLMPrefixCacheManager.get_stats calls self.stats.to_dict, len; returns stats.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.reset_stats · method
Reset statistics counters.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLLMPrefixCacheManager.reset_stats updates self.stats; calls MLLMCacheStats.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.clear · method
Clear all cached entries and reset stats.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method MLLMPrefixCacheManager.clear updates self._current_memory; calls self._cache.clear, self.reset_stats.
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.__len__ · method
Return number of cached entries.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
len(self._cache)
Exceptions and behavior
Method MLLMPrefixCacheManager.__len__ calls len; returns len(self._cache).
No direct raise statement appears in this definition.
vllm_mlx.mllm_cache.MLLMPrefixCacheManager.__repr__ · method
Method MLLMPrefixCacheManager.__repr__ calls len; returns f'<MLLMPrefixCacheManager entries={len(self)} memory={mem_mb:.1f}MB>'.
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'<MLLMPrefixCacheManager entries={len(self)} memory={mem_mb:.1f}MB>'
Exceptions and behavior
Method MLLMPrefixCacheManager.__repr__ calls len; returns f'<MLLMPrefixCacheManager entries={len(self)} memory={mem_mb:.1f}MB>'.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
MLLMCacheStats |
class | MLLMCacheStats(hits: int = 0, misses: int = 0, partial_hits: int = 0, tokens_saved: int = 0, image_cache_hits: int = 0, vision_encoder_skips: int = 0, total_queries: int = 0, evictions: int = 0) |
Statistics for MLLM cache performance. | #L34-L65 |
MLLMCacheStats.hit_rate |
method | MLLMCacheStats.hit_rate() -> float |
Calculate cache hit rate. | #L47-L51 |
MLLMCacheStats.to_dict |
method | MLLMCacheStats.to_dict() -> dict |
Convert stats to dictionary. | #L53-L65 |
MLLMPrefixCacheEntry |
class | MLLMPrefixCacheEntry(image_hash: str, prompt_hash: str, vision_embeddings: Any = None, kv_cache: list[Any] = field(default_factory=list), token_ids: list[int] = field(default_factory=list), num_image_tokens: int = 0, num_text_tokens: int = 0, prompt_tokens: int = 0, created_at: float = field(default_factory=time.time), hit_count: int = 0, model_name: str = '') |
Enhanced cache entry storing vision embeddings, KV cache, and token IDs. | #L69-L133 |
MLLMPrefixCacheEntry.total_tokens |
method | MLLMPrefixCacheEntry.total_tokens() -> int |
Return the number of token IDs represented by this cache entry. | #L99-L102 |
MLLMPrefixCacheEntry.memory_size |
method | MLLMPrefixCacheEntry.memory_size() -> int |
Estimate memory usage in bytes. | #L105-L119 |
MLLMPrefixCacheEntry.get_prefix_match_length |
method | MLLMPrefixCacheEntry.get_prefix_match_length(new_token_ids: list[int]) -> int |
Find how many tokens match between cached prefix and new input. | #L121-L133 |
compute_image_hash |
function | compute_image_hash(image_path: str) -> str |
Compute hash of image content for cache key. | #L136-L161 |
compute_images_hash |
function | compute_images_hash(images: list[str]) -> str |
Compute combined hash for multiple images. | #L164-L179 |
MLLMPrefixCacheManager |
class | MLLMPrefixCacheManager(max_entries: int = 50, max_memory_mb: int = 2048) |
LRU Cache manager for MLLM prefix states with vision embedding caching. | #L182-L448 |
MLLMPrefixCacheManager.__init__ |
method | MLLMPrefixCacheManager.__init__(max_entries: int = 50, max_memory_mb: int = 2048) -> not annotated |
Initialize MLLM prefix cache manager. | #L211-L227 |
MLLMPrefixCacheManager._make_cache_key |
method | MLLMPrefixCacheManager._make_cache_key(images: list[str], prompt: str) -> str |
Create cache key from images and prompt. | #L229-L233 |
MLLMPrefixCacheManager._make_image_only_key |
method | MLLMPrefixCacheManager._make_image_only_key(images: list[str]) -> str |
Create cache key for image-only lookup (vision embedding reuse). | #L235-L237 |
MLLMPrefixCacheManager._evict_by_memory |
method | MLLMPrefixCacheManager._evict_by_memory(required_size: int) -> None |
Evict entries until we have enough memory. | #L239-L246 |
MLLMPrefixCacheManager._evict_by_count |
method | MLLMPrefixCacheManager._evict_by_count() -> None |
Evict entries until we're under max_size. | #L248-L255 |
MLLMPrefixCacheManager.fetch |
method | MLLMPrefixCacheManager.fetch(images: list[str], prompt: str, token_ids: list[int] \| None = None) -> tuple[MLLMPrefixCacheEntry \| None, int] |
Fetch cached prefix state with prefix matching. | #L257-L329 |
MLLMPrefixCacheManager.fetch_cache |
method | MLLMPrefixCacheManager.fetch_cache(images: list[str], prompt: str) -> tuple[list[Any] \| None, bool] |
Legacy API: Fetch cached KV state for image+prompt combination. | #L331-L345 |
MLLMPrefixCacheManager.store |
method | MLLMPrefixCacheManager.store(images: list[str], prompt: str, vision_embeddings: Any, kv_cache: list[Any], token_ids: list[int], num_image_tokens: int = 0, model_name: str = '') -> None |
Store prefix state in cache. | #L347-L396 |
MLLMPrefixCacheManager.store_cache |
method | MLLMPrefixCacheManager.store_cache(images: list[str], prompt: str, cache: list[Any] \| None, num_tokens: int = 0) -> None |
Legacy API: Store KV cache for future reuse. | #L398-L421 |
MLLMPrefixCacheManager.get_stats |
method | MLLMPrefixCacheManager.get_stats() -> dict[str, Any] |
Get cache statistics. | #L423-L430 |
MLLMPrefixCacheManager.reset_stats |
method | MLLMPrefixCacheManager.reset_stats() -> None |
Reset statistics counters. | #L432-L434 |
MLLMPrefixCacheManager.clear |
method | MLLMPrefixCacheManager.clear() -> None |
Clear all cached entries and reset stats. | #L436-L440 |
MLLMPrefixCacheManager.__len__ |
method | MLLMPrefixCacheManager.__len__() -> int |
Return number of cached entries. | #L442-L444 |
MLLMPrefixCacheManager.__repr__ |
method | MLLMPrefixCacheManager.__repr__() -> str |
Method MLLMPrefixCacheManager.__repr__ calls len; returns f'<MLLMPrefixCacheManager entries={len(self)} memory={mem_mb:.1f}MB>'. |
#L446-L448 |