vllm_mlx.vision_embedding_cache¶
Vision Embedding Cache for MLLM continuous batching.
View the complete module source at #L1-L413.
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.vision_embedding_cache
¶
Vision Embedding Cache for MLLM continuous batching.
This module provides caching for vision embeddings to avoid redundant computation when the same images are processed multiple times.
Cache Levels: 1. Pixel Values Cache - Caches processed image tensors (prepare_inputs output) 2. Vision Encoding Cache - Caches VLM forward pass output (logits + cache state)
Performance Impact: - Without cache: ~2s per image for vision encoding - With cache hit: ~0.01s (100x speedup for repeated images)
vllm_mlx.vision_embedding_cache.VisionCacheStats
dataclass
¶
VisionCacheStats(pixel_cache_hits: int = 0, pixel_cache_misses: int = 0, encoding_cache_hits: int = 0, encoding_cache_misses: int = 0, total_time_saved: float = 0.0, total_images_processed: int = 0)
Statistics for vision cache performance.
vllm_mlx.vision_embedding_cache.VisionCacheStats.pixel_cache_hits
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.pixel_cache_misses
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.encoding_cache_hits
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.encoding_cache_misses
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.total_time_saved
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.total_images_processed
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionCacheStats.pixel_hit_rate
property
¶
Return successful pixel-cache lookups divided by all pixel lookups.
vllm_mlx.vision_embedding_cache.VisionCacheStats.encoding_hit_rate
property
¶
Return successful encoding lookups divided by all encoding lookups.
vllm_mlx.vision_embedding_cache.VisionCacheStats.to_dict
¶
Return pixel, encoding, timing, and image counters.
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.PixelCacheEntry
dataclass
¶
PixelCacheEntry(pixel_values: array, input_ids: array, attention_mask: Optional[array], image_grid_thw: Optional[array], extra_kwargs: Dict[str, Any], processing_time: float = 0.0)
Cached pixel values from prepare_inputs.
vllm_mlx.vision_embedding_cache.PixelCacheEntry.pixel_values
instance-attribute
¶
vllm_mlx.vision_embedding_cache.PixelCacheEntry.attention_mask
instance-attribute
¶
vllm_mlx.vision_embedding_cache.PixelCacheEntry.image_grid_thw
instance-attribute
¶
vllm_mlx.vision_embedding_cache.PixelCacheEntry.extra_kwargs
instance-attribute
¶
vllm_mlx.vision_embedding_cache.PixelCacheEntry.processing_time
class-attribute
instance-attribute
¶
vllm_mlx.vision_embedding_cache.PixelOnlyCacheEntry
dataclass
¶
PixelOnlyCacheEntry(pixel_values: array, image_grid_thw: Optional[array], processing_time: float = 0.0)
Cached pixel values only (prompt-independent).
This cache stores only the image-dependent data that doesn't change with different prompts. Useful when the same images are used with different prompts.
vllm_mlx.vision_embedding_cache.EncodingCacheEntry
dataclass
¶
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache
¶
VisionEmbeddingCache(max_pixel_entries: int = 100, max_encoding_entries: int = 50, enabled: bool = True)
Two-level cache for vision processing in MLLM.
Level 1 (Pixel Cache): - Caches output of prepare_inputs() (pixel_values, input_ids, etc.) - Key: hash(images) + hash(prompt) - Saves: Image loading, resizing, normalization time (~0.5-1s)
Level 2 (Encoding Cache): - Caches output of VLM forward pass (logits, first token) - Key: hash(images) + hash(prompt) - Saves: Vision encoder computation time (~1-2s)
Example
cache = VisionEmbeddingCache(max_pixel_entries=50, max_encoding_entries=20)
First request - cache miss¶
pixel_entry = cache.get_pixel_cache(images, prompt) if pixel_entry is None: ... # Process images... ... cache.set_pixel_cache(images, prompt, pixel_values, ...)
Second request with same image - cache hit!¶
pixel_entry = cache.get_pixel_cache(images, prompt) # Returns cached data
Initialize the vision embedding cache.
Parameters:
-
max_pixel_entries(int, default:100) –Max entries in pixel cache (LRU eviction)
-
max_encoding_entries(int, default:50) –Max entries in encoding cache
-
enabled(bool, default:True) –Whether caching is enabled
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.max_pixel_entries
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.max_encoding_entries
instance-attribute
¶
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._pixel_cache
instance-attribute
¶
_pixel_cache: OrderedDict[str, PixelCacheEntry] = OrderedDict()
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._pixel_only_cache
instance-attribute
¶
_pixel_only_cache: OrderedDict[str, PixelOnlyCacheEntry] = OrderedDict()
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._encoding_cache
instance-attribute
¶
_encoding_cache: OrderedDict[str, EncodingCacheEntry] = OrderedDict()
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.stats
instance-attribute
¶
stats = VisionCacheStats()
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._make_key
¶
Create cache key from images and prompt.
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._make_image_only_key
¶
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_cache
¶
get_pixel_cache(images: List[str], prompt: str) -> Optional[PixelCacheEntry]
Get cached pixel values for images+prompt.
Returns:
-
Optional[PixelCacheEntry]–PixelCacheEntry if found, None otherwise
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_cache
¶
set_pixel_cache(images: List[str], prompt: str, pixel_values: array, input_ids: array, attention_mask: Optional[array] = None, image_grid_thw: Optional[array] = None, extra_kwargs: Optional[Dict[str, Any]] = None, processing_time: float = 0.0) -> None
Store pixel values in cache.
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_values
¶
get_pixel_values(images: List[str]) -> Optional[PixelOnlyCacheEntry]
Get cached pixel values for images (prompt-independent).
This is useful when the same images are used with different prompts. Only the pixel_values and image_grid_thw are cached (no input_ids).
Returns:
-
Optional[PixelOnlyCacheEntry]–PixelOnlyCacheEntry if found, None otherwise
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_values
¶
set_pixel_values(images: List[str], pixel_values: array, image_grid_thw: Optional[array] = None, processing_time: float = 0.0) -> None
Store pixel values in cache (prompt-independent).
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_encoding_cache
¶
get_encoding_cache(images: List[str], prompt: str) -> Optional[EncodingCacheEntry]
Get cached vision encoding output.
Returns:
-
Optional[EncodingCacheEntry]–EncodingCacheEntry if found, None otherwise
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_encoding_cache
¶
set_encoding_cache(images: List[str], prompt: str, logits: array, first_token: int, logprobs: array, encoding_time: float = 0.0) -> None
Store vision encoding output in cache.
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_stats
¶
Get cache statistics.
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.clear
¶
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.__repr__
¶
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.compute_image_hash
¶
Compute hash of image content.
For files: hash the actual content For URLs/base64: hash the string
Source code in vllm_mlx/vision_embedding_cache.py
vllm_mlx.vision_embedding_cache.compute_images_hash
¶
Compute combined hash for multiple images.
Source code in vllm_mlx/vision_embedding_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.vision_embedding_cache.VisionCacheStats · class
vllm_mlx.vision_embedding_cache.VisionCacheStats(pixel_cache_hits: int = 0, pixel_cache_misses: int = 0, encoding_cache_hits: int = 0, encoding_cache_misses: int = 0, total_time_saved: float = 0.0, total_images_processed: int = 0)
Statistics for vision cache performance.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
pixel_cache_hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
pixel_cache_misses |
int |
no |
0 |
Optional constructor field; defaults to 0. |
encoding_cache_hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
encoding_cache_misses |
int |
no |
0 |
Optional constructor field; defaults to 0. |
total_time_saved |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
total_images_processed |
int |
no |
0 |
Optional constructor field; defaults to 0. |
Returns
- Constructs:
vllm_mlx.vision_embedding_cache.VisionCacheStats
Exceptions and behavior
Class VisionCacheStats declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionCacheStats.pixel_hit_rate · method
Return successful pixel-cache lookups divided by all pixel lookups.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
self.pixel_cache_hits / total if total > 0 else 0.0
Exceptions and behavior
Method VisionCacheStats.pixel_hit_rate returns self.pixel_cache_hits / total if total > 0 else 0.0.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionCacheStats.encoding_hit_rate · method
Return successful encoding lookups divided by all encoding lookups.
Parameters
This callable has no explicit inputs.
Returns
- Type:
float - Direct return expressions:
self.encoding_cache_hits / total if total > 0 else 0.0
Exceptions and behavior
Method VisionCacheStats.encoding_hit_rate returns self.encoding_cache_hits / total if total > 0 else 0.0.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionCacheStats.to_dict · method
Return pixel, encoding, timing, and image counters.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'pixel_cache_hits': self.pixel_cache_hits, 'pixel_cache_misses': self.pixel_cache_misses, 'pixel_hit_rate': self.pixel…
Exceptions and behavior
Method VisionCacheStats.to_dict returns {'pixel_cache_hits': self.pixel_cache_hits, 'pixel_cache_misses': self.pixel_cache_misses, 'pixel_hit_rate': self.pixel….
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.PixelCacheEntry · class
vllm_mlx.vision_embedding_cache.PixelCacheEntry(pixel_values: mx.array, input_ids: mx.array, attention_mask: Optional[mx.array], image_grid_thw: Optional[mx.array], extra_kwargs: Dict[str, Any], processing_time: float = 0.0)
Cached pixel values from prepare_inputs.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
pixel_values |
mx.array |
yes |
none |
Required constructor field. |
input_ids |
mx.array |
yes |
none |
Required constructor field. |
attention_mask |
Optional[mx.array] |
yes |
none |
Required constructor field. |
image_grid_thw |
Optional[mx.array] |
yes |
none |
Required constructor field. |
extra_kwargs |
Dict[str, Any] |
yes |
none |
Required constructor field. |
processing_time |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
Returns
- Constructs:
vllm_mlx.vision_embedding_cache.PixelCacheEntry
Exceptions and behavior
Class PixelCacheEntry declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.PixelOnlyCacheEntry · class
vllm_mlx.vision_embedding_cache.PixelOnlyCacheEntry(pixel_values: mx.array, image_grid_thw: Optional[mx.array], processing_time: float = 0.0)
Cached pixel values only (prompt-independent).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
pixel_values |
mx.array |
yes |
none |
Required constructor field. |
image_grid_thw |
Optional[mx.array] |
yes |
none |
Required constructor field. |
processing_time |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
Returns
- Constructs:
vllm_mlx.vision_embedding_cache.PixelOnlyCacheEntry
Exceptions and behavior
Class PixelOnlyCacheEntry declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.EncodingCacheEntry · class
vllm_mlx.vision_embedding_cache.EncodingCacheEntry(logits: mx.array, first_token: int, logprobs: mx.array, encoding_time: float = 0.0)
Cached vision encoding output.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
logits |
mx.array |
yes |
none |
Required constructor field. |
first_token |
int |
yes |
none |
Required constructor field. |
logprobs |
mx.array |
yes |
none |
Required constructor field. |
encoding_time |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
Returns
- Constructs:
vllm_mlx.vision_embedding_cache.EncodingCacheEntry
Exceptions and behavior
Class EncodingCacheEntry declares 0 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.compute_image_hash · function
Compute hash of image content.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
image_path |
str |
yes |
none |
Required positional or keyword input. |
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.is_file, open; has 3 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.compute_images_hash · function
Compute combined hash for multiple images.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
List[str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
'no_images';hashlib.sha256('_'.join(hashes).encode()).hexdigest()[:16]
Exceptions and behavior
Function compute_images_hash calls sorted, compute_image_hash, hashlib.sha256('_'.join(hashes).encode()).hexdigest, hashlib.sha256; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache · class
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache(max_pixel_entries: int = 100, max_encoding_entries: int = 50, enabled: bool = True)
Two-level cache for vision processing in MLLM.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_pixel_entries |
int |
no |
100 |
Max entries in pixel cache (LRU eviction) |
max_encoding_entries |
int |
no |
50 |
Max entries in encoding cache |
enabled |
bool |
no |
True |
Whether caching is enabled |
Returns
- Constructs:
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache
Exceptions and behavior
Class VisionEmbeddingCache declares 12 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.__init__ · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.__init__(max_pixel_entries: int = 100, max_encoding_entries: int = 50, enabled: bool = True) -> not annotated
Initialize the vision embedding cache.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max_pixel_entries |
int |
no |
100 |
Max entries in pixel cache (LRU eviction) |
max_encoding_entries |
int |
no |
50 |
Max entries in encoding cache |
enabled |
bool |
no |
True |
Whether caching is enabled |
Returns
- Type:
not annotated
Exceptions and behavior
Method VisionEmbeddingCache.__init__ updates self.max_pixel_entries, self.max_encoding_entries, self.enabled, self._pixel_cache; calls OrderedDict, VisionCacheStats.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._make_key · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._make_key(images: List[str], prompt: str) -> str
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'{img_hash}_{prompt_hash}'
Exceptions and behavior
Method VisionEmbeddingCache._make_key calls compute_images_hash, hashlib.sha256(prompt.encode()).hexdigest, hashlib.sha256, prompt.encode; returns f'{img_hash}_{prompt_hash}'.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache._make_image_only_key · method
Create cache key from images only (prompt-independent).
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 VisionEmbeddingCache._make_image_only_key calls compute_images_hash; returns compute_images_hash(images).
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_cache · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_cache(images: List[str], prompt: str) -> Optional[PixelCacheEntry]
Get cached pixel values for images+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:
Optional[PixelCacheEntry] - Direct return expressions:
None;entry
Exceptions and behavior
Method VisionEmbeddingCache.get_pixel_cache updates self.stats.pixel_cache_hits, self.stats.total_time_saved, self.stats.pixel_cache_misses; calls self._make_key, self._pixel_cache.pop, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_cache · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_cache(images: List[str], prompt: str, pixel_values: mx.array, input_ids: mx.array, attention_mask: Optional[mx.array] = None, image_grid_thw: Optional[mx.array] = None, extra_kwargs: Optional[Dict[str, Any]] = None, processing_time: float = 0.0) -> None
Store pixel values in cache.
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. |
pixel_values |
mx.array |
yes |
none |
Required positional or keyword input. |
input_ids |
mx.array |
yes |
none |
Required positional or keyword input. |
attention_mask |
Optional[mx.array] |
no |
None |
Optional positional or keyword input; defaults to None. |
image_grid_thw |
Optional[mx.array] |
no |
None |
Optional positional or keyword input; defaults to None. |
extra_kwargs |
Optional[Dict[str, Any]] |
no |
None |
Optional positional or keyword input; defaults to None. |
processing_time |
float |
no |
0.0 |
Optional positional or keyword input; defaults to 0.0. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method VisionEmbeddingCache.set_pixel_cache updates self.stats.total_images_processed; calls self._make_key, len, next, iter; returns None.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_values · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_pixel_values(images: List[str]) -> Optional[PixelOnlyCacheEntry]
Get cached pixel values for images (prompt-independent).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
List[str] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
Optional[PixelOnlyCacheEntry] - Direct return expressions:
None;entry
Exceptions and behavior
Method VisionEmbeddingCache.get_pixel_values updates self.stats.pixel_cache_hits, self.stats.total_time_saved, self.stats.pixel_cache_misses; calls self._make_image_only_key, self._pixel_only_cache.pop, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_values · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_pixel_values(images: List[str], pixel_values: mx.array, image_grid_thw: Optional[mx.array] = None, processing_time: float = 0.0) -> None
Store pixel values in cache (prompt-independent).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
images |
List[str] |
yes |
none |
Required positional or keyword input. |
pixel_values |
mx.array |
yes |
none |
Required positional or keyword input. |
image_grid_thw |
Optional[mx.array] |
no |
None |
Optional positional or keyword input; defaults to None. |
processing_time |
float |
no |
0.0 |
Optional positional or keyword input; defaults to 0.0. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method VisionEmbeddingCache.set_pixel_values calls self._make_image_only_key, len, next, iter; returns None.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_encoding_cache · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_encoding_cache(images: List[str], prompt: str) -> Optional[EncodingCacheEntry]
Get cached vision encoding output.
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:
Optional[EncodingCacheEntry] - Direct return expressions:
None;entry
Exceptions and behavior
Method VisionEmbeddingCache.get_encoding_cache updates self.stats.encoding_cache_hits, self.stats.total_time_saved, self.stats.encoding_cache_misses; calls self._make_key, self._encoding_cache.pop, logger.debug; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_encoding_cache · method
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.set_encoding_cache(images: List[str], prompt: str, logits: mx.array, first_token: int, logprobs: mx.array, encoding_time: float = 0.0) -> None
Store vision encoding output in cache.
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. |
logits |
mx.array |
yes |
none |
Required positional or keyword input. |
first_token |
int |
yes |
none |
Required positional or keyword input. |
logprobs |
mx.array |
yes |
none |
Required positional or keyword input. |
encoding_time |
float |
no |
0.0 |
Optional positional or keyword input; defaults to 0.0. |
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method VisionEmbeddingCache.set_encoding_cache calls self._make_key, len, next, iter; returns None.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.get_stats · method
Get cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
stats
Exceptions and behavior
Method VisionEmbeddingCache.get_stats calls self.stats.to_dict, len; returns stats.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.clear · method
Clear all caches and reset stats.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method VisionEmbeddingCache.clear updates self.stats; calls self._pixel_cache.clear, self._pixel_only_cache.clear, self._encoding_cache.clear, VisionCacheStats.
No direct raise statement appears in this definition.
vllm_mlx.vision_embedding_cache.VisionEmbeddingCache.__repr__ · method
Method VisionEmbeddingCache.__repr__ calls len; returns f'<VisionEmbeddingCache pixel={len(self._pixel_cache)}/{self.max_pixel_entries} pixel_only={len(self._pixel_only_cache)….
Parameters
This callable has no explicit inputs.
Returns
- Type:
str - Direct return expressions:
f'<VisionEmbeddingCache pixel={len(self._pixel_cache)}/{self.max_pixel_entries} pixel_only={len(self._pixel_only_cache)…
Exceptions and behavior
Method VisionEmbeddingCache.__repr__ calls len; returns f'<VisionEmbeddingCache pixel={len(self._pixel_cache)}/{self.max_pixel_entries} pixel_only={len(self._pixel_only_cache)….
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 |
|---|---|---|---|---|
VisionCacheStats |
class | VisionCacheStats(pixel_cache_hits: int = 0, pixel_cache_misses: int = 0, encoding_cache_hits: int = 0, encoding_cache_misses: int = 0, total_time_saved: float = 0.0, total_images_processed: int = 0) |
Statistics for vision cache performance. | #L30-L66 |
VisionCacheStats.pixel_hit_rate |
method | VisionCacheStats.pixel_hit_rate() -> float |
Return successful pixel-cache lookups divided by all pixel lookups. | #L41-L45 |
VisionCacheStats.encoding_hit_rate |
method | VisionCacheStats.encoding_hit_rate() -> float |
Return successful encoding lookups divided by all encoding lookups. | #L48-L52 |
VisionCacheStats.to_dict |
method | VisionCacheStats.to_dict() -> dict |
Return pixel, encoding, timing, and image counters. | #L54-L66 |
PixelCacheEntry |
class | PixelCacheEntry(pixel_values: mx.array, input_ids: mx.array, attention_mask: Optional[mx.array], image_grid_thw: Optional[mx.array], extra_kwargs: Dict[str, Any], processing_time: float = 0.0) |
Cached pixel values from prepare_inputs. | #L70-L78 |
PixelOnlyCacheEntry |
class | PixelOnlyCacheEntry(pixel_values: mx.array, image_grid_thw: Optional[mx.array], processing_time: float = 0.0) |
Cached pixel values only (prompt-independent). | #L82-L92 |
EncodingCacheEntry |
class | EncodingCacheEntry(logits: mx.array, first_token: int, logprobs: mx.array, encoding_time: float = 0.0) |
Cached vision encoding output. | #L96-L102 |
compute_image_hash |
function | compute_image_hash(image_path: str) -> str |
Compute hash of image content. | #L105-L124 |
compute_images_hash |
function | compute_images_hash(images: List[str]) -> str |
Compute combined hash for multiple images. | #L127-L132 |
VisionEmbeddingCache |
class | VisionEmbeddingCache(max_pixel_entries: int = 100, max_encoding_entries: int = 50, enabled: bool = True) |
Two-level cache for vision processing in MLLM. | #L135-L413 |
VisionEmbeddingCache.__init__ |
method | VisionEmbeddingCache.__init__(max_pixel_entries: int = 100, max_encoding_entries: int = 50, enabled: bool = True) -> not annotated |
Initialize the vision embedding cache. | #L162-L185 |
VisionEmbeddingCache._make_key |
method | VisionEmbeddingCache._make_key(images: List[str], prompt: str) -> str |
Create cache key from images and prompt. | #L187-L192 |
VisionEmbeddingCache._make_image_only_key |
method | VisionEmbeddingCache._make_image_only_key(images: List[str]) -> str |
Create cache key from images only (prompt-independent). | #L194-L196 |
VisionEmbeddingCache.get_pixel_cache |
method | VisionEmbeddingCache.get_pixel_cache(images: List[str], prompt: str) -> Optional[PixelCacheEntry] |
Get cached pixel values for images+prompt. | #L200-L229 |
VisionEmbeddingCache.set_pixel_cache |
method | VisionEmbeddingCache.set_pixel_cache(images: List[str], prompt: str, pixel_values: mx.array, input_ids: mx.array, attention_mask: Optional[mx.array] = None, image_grid_thw: Optional[mx.array] = None, extra_kwargs: Optional[Dict[str, Any]] = None, processing_time: float = 0.0) -> None |
Store pixel values in cache. | #L231-L264 |
VisionEmbeddingCache.get_pixel_values |
method | VisionEmbeddingCache.get_pixel_values(images: List[str]) -> Optional[PixelOnlyCacheEntry] |
Get cached pixel values for images (prompt-independent). | #L268-L299 |
VisionEmbeddingCache.set_pixel_values |
method | VisionEmbeddingCache.set_pixel_values(images: List[str], pixel_values: mx.array, image_grid_thw: Optional[mx.array] = None, processing_time: float = 0.0) -> None |
Store pixel values in cache (prompt-independent). | #L301-L326 |
VisionEmbeddingCache.get_encoding_cache |
method | VisionEmbeddingCache.get_encoding_cache(images: List[str], prompt: str) -> Optional[EncodingCacheEntry] |
Get cached vision encoding output. | #L330-L358 |
VisionEmbeddingCache.set_encoding_cache |
method | VisionEmbeddingCache.set_encoding_cache(images: List[str], prompt: str, logits: mx.array, first_token: int, logprobs: mx.array, encoding_time: float = 0.0) -> None |
Store vision encoding output in cache. | #L360-L388 |
VisionEmbeddingCache.get_stats |
method | VisionEmbeddingCache.get_stats() -> dict |
Get cache statistics. | #L392-L398 |
VisionEmbeddingCache.clear |
method | VisionEmbeddingCache.clear() -> None |
Clear all caches and reset stats. | #L400-L405 |
VisionEmbeddingCache.__repr__ |
method | VisionEmbeddingCache.__repr__() -> str |
Method VisionEmbeddingCache.__repr__ calls len; returns f'<VisionEmbeddingCache pixel={len(self._pixel_cache)}/{self.max_pixel_entries} pixel_only={len(self._pixel_only_cache)…. |
#L407-L413 |