vllm_mlx.ssd_cache¶
SSD KV cache tiering for vllm-mlx.
View the complete module source at #L1-L1248.
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.ssd_cache
¶
SSD KV cache tiering for vllm-mlx.
This module provides a cold-tier disk cache that sits behind MemoryAwarePrefixCache. Evicted entries spill to NVMe instead of being discarded, and cold-tier fetches reload from disk asynchronously with RAM budget reservation before the read completes.
Key design: - SQLite for atomic metadata index (no mutable JSON) - Async writer thread for non-blocking spills - Per-layer serializer interface for hybrid cache types - Atomic temp-file + rename writes for crash consistency - Metrics exposed from day one
vllm_mlx.ssd_cache.SERIALIZER_SUPPORT_MATRIX
module-attribute
¶
SERIALIZER_SUPPORT_MATRIX = {'KVCache': 'supported', 'RotatingKVCache': 'supported', 'ArraysCache': 'supported', 'MambaCache': 'supported', '_QuantizedCacheWrapper': 'supported_via_dequant_on_spill', 'QuantizedKVCache': 'supported_via_dequant_on_spill'}
vllm_mlx.ssd_cache.SSDCacheConfig
dataclass
¶
SSDCacheConfig(cache_dir: str | None = None, max_size_gb: float = 10.0, max_entries: int = 10000, file_permissions: int = 384, dir_permissions: int = 448, spill_queue_size: int = 64, retention_seconds: int | None = None)
Configuration for SSD cache tier.
Attributes:
-
cache_dir(str | None) –Directory for SSD cache files. None = auto-detect (~/.cache/vllm-mlx/ssd_cache/{model}/).
-
max_size_gb(float) –Maximum total size of SSD cache in GB.
-
max_entries(int) –Maximum number of entries in SSD cache.
-
file_permissions(int) –Unix permission bits for cache data files.
-
dir_permissions(int) –Unix permission bits for cache directories.
-
spill_queue_size(int) –Max pending spill operations before dropping.
-
retention_seconds(int | None) –Optional max age for cache entries (None = no expiry).
vllm_mlx.ssd_cache.SSDCacheConfig.cache_dir
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.max_size_gb
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.max_entries
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.file_permissions
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.dir_permissions
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.spill_queue_size
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.retention_seconds
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheConfig.max_size_bytes
property
¶
Maximum cache size in bytes.
vllm_mlx.ssd_cache.SSDCacheConfig.__post_init__
¶
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheStats
dataclass
¶
SSDCacheStats(spill_count: int = 0, spill_bytes: int = 0, ssd_hits: int = 0, ssd_misses: int = 0, reload_latency_sum: float = 0.0, reload_bytes: int = 0, promotion_failures: int = 0)
Statistics for SSD cache tier — exposed from day one.
Attributes:
-
spill_count(int) –Number of entries spilled to SSD.
-
spill_bytes(int) –Total bytes written to SSD.
-
ssd_hits(int) –Number of successful SSD cache lookups.
-
ssd_misses(int) –Number of SSD cache lookup misses.
-
reload_latency_sum(float) –Sum of reload latencies in seconds.
-
reload_bytes(int) –Total bytes read from SSD.
-
promotion_failures(int) –Number of failed promotions (RAM budget exhausted).
vllm_mlx.ssd_cache.SSDCacheStats.spill_count
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.spill_bytes
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.ssd_misses
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.reload_latency_sum
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.reload_bytes
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.promotion_failures
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheStats.to_dict
¶
Return spill, lookup, reload, and promotion statistics.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex
¶
SQLite-backed index for SSD cache entries.
Uses SQLite for atomic metadata operations instead of mutable JSON. The token sequence is stored as a binary blob for prefix-searchable representation. The primary key is a SHA-256 hash of the token sequence.
Thread safety: All operations are serialized through a threading.Lock. The SQLite connection uses WAL mode for concurrent read/write safety.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex._SCHEMA_VERSION
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.SSDIndex._conn
instance-attribute
¶
vllm_mlx.ssd_cache.SSDIndex._create_tables
¶
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex._ensure_column
¶
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex._backfill_prefix_hashes
¶
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.insert_entry
¶
insert_entry(tokens_key: tuple[int, ...], file_path: str, memory_bytes: int, num_tokens: int) -> None
Insert or replace a cache entry in the index.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.lookup_exact
¶
Look up an exact token sequence. Returns dict or None.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.lookup_prefix
¶
Find entries whose token sequence is a prefix of query_tokens.
Uses a bounded token-prefix hash to avoid scanning all entries, then compares the full stored token blob against the corresponding prefix of query_tokens.
Returns list of dicts sorted by num_tokens descending (longest prefix first).
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.delete_entry
¶
Delete an entry by token sequence.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.get_lru
¶
Get the least recently used entries, ordered oldest first.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.get_total_bytes
¶
Get total memory_bytes across all entries.
vllm_mlx.ssd_cache.SSDIndex.get_entry_count
¶
vllm_mlx.ssd_cache.SSDIndex.touch
¶
Update accessed_at timestamp for an entry (marks as recently used).
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDIndex.all_entries
¶
Return all entries (for startup reconciliation).
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.LayerSerializer
¶
Bases: ABC
Interface for per-layer cache serialization.
Spill is split across two threads: snapshot_layer runs on the
producer (request handler) thread so the mx→numpy materialization
happens where the per-request Stream(gpu, N) is registered;
serialize_layer then runs on the SSD writer thread with numpy only.
vllm_mlx.ssd_cache.LayerSerializer.snapshot_layer
abstractmethod
¶
vllm_mlx.ssd_cache.LayerSerializer.serialize_layer
abstractmethod
¶
Writer-thread: persist a snapshot to safetensors at file_path.
Returns metadata dict with at least 'layer_type'.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.LayerSerializer.deserialize_layer
abstractmethod
¶
vllm_mlx.ssd_cache.KVCacheSerializer
¶
Bases: LayerSerializer
Serializer for KVCache and RotatingKVCache layers.
Handles layers with .keys, .values, .offset attributes. RotatingKVCache also has .max_size, .keep, .step, ._idx.
vllm_mlx.ssd_cache.KVCacheSerializer._ROTATING_ATTRS
class-attribute
instance-attribute
¶
vllm_mlx.ssd_cache.KVCacheSerializer.snapshot_layer
¶
Copy a KV cache layer into NumPy-backed writer-thread data.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.KVCacheSerializer.serialize_layer
¶
Write one KV layer to safetensors and return reconstruction metadata.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.KVCacheSerializer.deserialize_layer
¶
Load one KV layer as arrays plus cache reconstruction metadata.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.ArraysCacheSerializer
¶
Bases: LayerSerializer
Serializer for ArraysCache (Mamba/linear attention) layers.
Handles layers with .state attribute containing a list of arrays.
vllm_mlx.ssd_cache.ArraysCacheSerializer.snapshot_layer
¶
Copy an arrays-cache state into NumPy-backed writer-thread data.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.ArraysCacheSerializer.serialize_layer
¶
Write arrays-cache state to safetensors and return its metadata.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.ArraysCacheSerializer.deserialize_layer
¶
Load arrays-cache state and any original dtype hints.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier
¶
SSDCacheTier(config: SSDCacheConfig)
Cold-tier disk cache for KV cache entries.
Manages a SQLite-indexed on-disk cache directory. Evicted RAM entries are spilled here via an async writer thread. Cold-tier fetches reload from disk asynchronously with RAM budget reservation.
Directory layout::
cache_dir/
index.db # SQLite metadata index
data/ # safetensors files per entry
{hash}/ # one directory per entry
layer_0.safetensors
layer_1.safetensors
manifest.json # per-entry layer metadata
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier._writer_thread
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheTier._data_dir
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheTier._spill_queue
instance-attribute
¶
vllm_mlx.ssd_cache.SSDCacheTier._entry_hash
staticmethod
¶
vllm_mlx.ssd_cache.SSDCacheTier.get_stats
¶
vllm_mlx.ssd_cache.SSDCacheTier.start_writer
¶
Start the background spill writer thread.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier._writer_loop
¶
Drain spill queue and persist entries. Numpy-only — no MLX here.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier.enqueue_spill
¶
Enqueue a cache entry for async spill to SSD.
Must be called on the producer thread (the request handler that owns the layer's Stream(gpu, N)) — the snapshot below materializes MLX → numpy here so the writer thread never has to.
Returns True if enqueued, False if queue is full (entry dropped).
Source code in vllm_mlx/ssd_cache.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | |
vllm_mlx.ssd_cache.SSDCacheTier._write_entry
¶
_write_entry(tokens_key: tuple[int, ...], layer_snapshots: list[tuple[LayerSerializer, dict[str, Any]]], memory_bytes: int) -> None
Atomically persist one entry (writer thread; numpy-only input).
Source code in vllm_mlx/ssd_cache.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
vllm_mlx.ssd_cache.SSDCacheTier.lookup_ssd
¶
Synchronous check whether tokens exist in SSD tier.
This is fast (SQLite lookup only, no disk I/O for data). Called from synchronous fetch() to report an SSD candidate.
Returns:
-
dict | None–Dict with entry metadata if found, None otherwise.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier.lookup_ssd_prefix
¶
Find the longest prefix match in the SSD tier.
Returns the longest-prefix entry metadata or None.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier.async_promote
async
¶
Promote an entry from SSD to RAM asynchronously.
CRITICAL: Reserves RAM budget BEFORE the disk read, to avoid thrash when multiple promotions race.
Parameters:
-
tokens(tuple[int, ...]) –Token sequence to promote.
-
reserve_budget_fn–Callable(nbytes) -> bool. Must return True if budget is available and reserved, False otherwise.
-
release_budget_fn–Callable(nbytes) -> None. Called to release budget on failure.
Returns:
-
list | None–List of deserialized cache layers, or None if promotion failed.
Source code in vllm_mlx/ssd_cache.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | |
vllm_mlx.ssd_cache.SSDCacheTier._read_entry
¶
Read a cache entry from disk. Called from thread pool.
Returns list of deserialized layer dicts, or None on corruption.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier._quarantine_entry
¶
Move a corrupt entry to quarantine and remove from index.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier._enforce_capacity
¶
Evict oldest SSD entries until within capacity limits.
Called after each spill write. Removes entries by LRU order until both entry count and total bytes are within bounds.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier.reconcile
¶
Reconcile index with files on disk.
Removes index entries whose data files are missing. Removes data directories not in the index.
Returns number of entries cleaned up.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.SSDCacheTier.close
¶
Close the SSD cache tier and release resources.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache._tokens_to_blob
¶
Serialize token tuple to a compact binary blob for SQLite storage.
Uses the full token sequence as a binary blob for prefix matching.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache._blob_to_tokens
¶
vllm_mlx.ssd_cache._tokens_hash
¶
Compute SHA-256 hex digest of a token sequence for use as primary key.
vllm_mlx.ssd_cache._prefix_hash
¶
vllm_mlx.ssd_cache._mx_to_numpy_safe
¶
mx.array → np.ndarray, upcasting numpy-unsupported dtypes (bf16) to fp32.
Returns (numpy_array, original_dtype_name_or_None). The name is only set when an upcast happened, so the SSD-promote path can cast back.
Source code in vllm_mlx/ssd_cache.py
vllm_mlx.ssd_cache.get_serializer_for_layer
¶
get_serializer_for_layer(layer: Any) -> LayerSerializer
Return the appropriate serializer for a cache layer.
Dispatches based on duck-typing: - If layer has .keys and .values and .offset -> KVCacheSerializer - If layer has .state and it's a list -> ArraysCacheSerializer
Raises ValueError for unsupported layer types.
Source code in vllm_mlx/ssd_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.ssd_cache.SSDCacheConfig · class
vllm_mlx.ssd_cache.SSDCacheConfig(cache_dir: str | None = None, max_size_gb: float = 10.0, max_entries: int = 10000, file_permissions: int = 384, dir_permissions: int = 448, spill_queue_size: int = 64, retention_seconds: int | None = None)
Configuration for SSD cache tier.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str \| None |
no |
None |
Optional constructor field; defaults to None. |
max_size_gb |
float |
no |
10.0 |
Optional constructor field; defaults to 10.0. |
max_entries |
int |
no |
10000 |
Optional constructor field; defaults to 10000. |
file_permissions |
int |
no |
384 |
Optional constructor field; defaults to 384. |
dir_permissions |
int |
no |
448 |
Optional constructor field; defaults to 448. |
spill_queue_size |
int |
no |
64 |
Optional constructor field; defaults to 64. |
retention_seconds |
int \| None |
no |
None |
Optional constructor field; defaults to None. |
Returns
- Constructs:
vllm_mlx.ssd_cache.SSDCacheConfig
Exceptions and behavior
Class SSDCacheConfig declares 2 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheConfig.__post_init__ · method
Method SSDCacheConfig.__post_init__ calls ValueError; can raise ValueError.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheConfig.__post_init__ calls ValueError; can raise ValueError.
Directly raised exceptions: ValueError.
vllm_mlx.ssd_cache.SSDCacheConfig.max_size_bytes · method
Maximum cache size in bytes.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
int(self.max_size_gb * _BYTES_PER_GB)
Exceptions and behavior
Method SSDCacheConfig.max_size_bytes calls int; returns int(self.max_size_gb * _BYTES_PER_GB).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheStats · class
vllm_mlx.ssd_cache.SSDCacheStats(spill_count: int = 0, spill_bytes: int = 0, ssd_hits: int = 0, ssd_misses: int = 0, reload_latency_sum: float = 0.0, reload_bytes: int = 0, promotion_failures: int = 0)
Statistics for SSD cache tier — exposed from day one.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
spill_count |
int |
no |
0 |
Optional constructor field; defaults to 0. |
spill_bytes |
int |
no |
0 |
Optional constructor field; defaults to 0. |
ssd_hits |
int |
no |
0 |
Optional constructor field; defaults to 0. |
ssd_misses |
int |
no |
0 |
Optional constructor field; defaults to 0. |
reload_latency_sum |
float |
no |
0.0 |
Optional constructor field; defaults to 0.0. |
reload_bytes |
int |
no |
0 |
Optional constructor field; defaults to 0. |
promotion_failures |
int |
no |
0 |
Optional constructor field; defaults to 0. |
Returns
- Constructs:
vllm_mlx.ssd_cache.SSDCacheStats
Exceptions and behavior
Class SSDCacheStats declares 1 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheStats.to_dict · method
Return spill, lookup, reload, and promotion statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
{'spill_count': self.spill_count, 'spill_bytes': self.spill_bytes, 'ssd_hits': self.ssd_hits, 'ssd_misses': self.ssd_mi…
Exceptions and behavior
Method SSDCacheStats.to_dict calls round; returns {'spill_count': self.spill_count, 'spill_bytes': self.spill_bytes, 'ssd_hits': self.ssd_hits, 'ssd_misses': self.ssd_mi….
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache._tokens_to_blob · function
Serialize token tuple to a compact binary blob for SQLite storage.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bytes - Direct return expressions:
arr.tobytes()
Exceptions and behavior
Function _tokens_to_blob calls _array.array, arr.tobytes; returns arr.tobytes().
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache._blob_to_tokens · function
Deserialize binary blob back to token tuple.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
blob |
bytes |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[int, ...] - Direct return expressions:
tuple(arr)
Exceptions and behavior
Function _blob_to_tokens calls _array.array, arr.frombytes, tuple; returns tuple(arr).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache._tokens_hash · function
Compute SHA-256 hex digest of a token sequence for use as primary key.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
hashlib.sha256(_tokens_to_blob(tokens)).hexdigest()
Exceptions and behavior
Function _tokens_hash calls hashlib.sha256(_tokens_to_blob(tokens)).hexdigest, hashlib.sha256, _tokens_to_blob; returns hashlib.sha256(_tokens_to_blob(tokens)).hexdigest().
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache._prefix_hash · function
Hash the bounded token prefix used to prefilter prefix lookups.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
_tokens_hash(tokens[:_PREFIX_FILTER_TOKENS])
Exceptions and behavior
Function _prefix_hash calls _tokens_hash; returns _tokens_hash(tokens[:_PREFIX_FILTER_TOKENS]).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex · class
SQLite-backed index for SSD cache entries.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.ssd_cache.SSDIndex
Exceptions and behavior
Class SSDIndex declares 14 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.__init__ · method
Method SSDIndex.__init__ updates self._cache_dir, self._db_lock, self._conn, self._conn.row_factory; calls threading.Lock, os.path.join, sqlite3.connect, self._conn.execute.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
cache_dir |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex.__init__ updates self._cache_dir, self._db_lock, self._conn, self._conn.row_factory; calls threading.Lock, os.path.join, sqlite3.connect, self._conn.execute.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex._create_tables · method
Method SSDIndex._create_tables calls self._conn.executescript, self._ensure_column, self._conn.execute, cur.fetchone.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex._create_tables calls self._conn.executescript, self._ensure_column, self._conn.execute, cur.fetchone.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex._ensure_column · method
Method SSDIndex._ensure_column calls self._conn.execute, cur.fetchall.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table |
str |
yes |
none |
Required positional or keyword input. |
column |
str |
yes |
none |
Required positional or keyword input. |
definition |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex._ensure_column calls self._conn.execute, cur.fetchall.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex._backfill_prefix_hashes · method
Method SSDIndex._backfill_prefix_hashes calls self._conn.execute, cur.fetchall, _blob_to_tokens, _prefix_hash.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex._backfill_prefix_hashes calls self._conn.execute, cur.fetchall, _blob_to_tokens, _prefix_hash.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.insert_entry · method
vllm_mlx.ssd_cache.SSDIndex.insert_entry(tokens_key: tuple[int, ...], file_path: str, memory_bytes: int, num_tokens: int) -> None
Insert or replace a cache entry in the index.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens_key |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
file_path |
str |
yes |
none |
Required positional or keyword input. |
memory_bytes |
int |
yes |
none |
Required positional or keyword input. |
num_tokens |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex.insert_entry calls time.time, _tokens_hash, _prefix_hash, _tokens_to_blob.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.lookup_exact · method
Look up an exact token sequence.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens_key |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict | None - Direct return expressions:
None;{'file_path': row['file_path'], 'memory_bytes': row['memory_bytes'], 'num_tokens': row['num_tokens']}
Exceptions and behavior
Method SSDIndex.lookup_exact calls _tokens_hash, self._conn.execute, cur.fetchone; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.lookup_prefix · method
Find entries whose token sequence is a prefix of query_tokens.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
query_tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list[dict] - Direct return expressions:
[];results
Exceptions and behavior
Method SSDIndex.lookup_prefix calls len, _tokens_to_blob, _tokens_hash, range; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.delete_entry · method
Delete an entry by token sequence.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens_key |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex.delete_entry calls _tokens_hash, self._conn.execute, self._conn.commit.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.get_lru · method
Get the least recently used entries, ordered oldest first.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
limit |
int |
no |
10 |
Optional positional or keyword input; defaults to 10. |
Returns
- Type:
list[dict] - Direct return expressions:
results
Exceptions and behavior
Method SSDIndex.get_lru calls self._conn.execute, cur.fetchall, results.append; returns results.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.get_total_bytes · method
Get total memory_bytes across all entries.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
cur.fetchone()[0]
Exceptions and behavior
Method SSDIndex.get_total_bytes calls self._conn.execute, cur.fetchone; returns cur.fetchone()[0].
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.get_entry_count · method
Get number of entries in the index.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
cur.fetchone()[0]
Exceptions and behavior
Method SSDIndex.get_entry_count calls self._conn.execute, cur.fetchone; returns cur.fetchone()[0].
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.touch · method
Update accessed_at timestamp for an entry (marks as recently used).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens_key |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex.touch calls _tokens_hash, self._conn.execute, time.time, self._conn.commit.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.all_entries · method
Return all entries (for startup reconciliation).
Parameters
This callable has no explicit inputs.
Returns
- Type:
list[dict] - Direct return expressions:
results
Exceptions and behavior
Method SSDIndex.all_entries calls self._conn.execute, cur.fetchall, results.append; returns results.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDIndex.close · method
Close the SQLite connection.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDIndex.close calls self._conn.close.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.LayerSerializer · class
Interface for per-layer cache serialization.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.ssd_cache.LayerSerializer
Exceptions and behavior
Class LayerSerializer derives from ABC and declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.LayerSerializer.snapshot_layer · method
Producer-thread CPU snapshot of an MLX-backed cache layer.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any]
Exceptions and behavior
Method LayerSerializer.snapshot_layer contains no state mutation, call, raise, return, await, or yield.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.LayerSerializer.serialize_layer · method
vllm_mlx.ssd_cache.LayerSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any]
Writer-thread: persist a snapshot to safetensors at file_path.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
snapshot |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
layer_idx |
int |
yes |
none |
Required positional or keyword input. |
file_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any]
Exceptions and behavior
Method LayerSerializer.serialize_layer contains no state mutation, call, raise, return, await, or yield.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.LayerSerializer.deserialize_layer · method
vllm_mlx.ssd_cache.LayerSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict
Read a layer back from disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_path |
str |
yes |
none |
Required positional or keyword input. |
metadata |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict
Exceptions and behavior
Method LayerSerializer.deserialize_layer contains no state mutation, call, raise, return, await, or yield.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache._mx_to_numpy_safe · function
mx.array → np.ndarray, upcasting numpy-unsupported dtypes (bf16) to fp32.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
arr |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
tuple[np.ndarray, str | None] - Direct return expressions:
(np.array(arr), None);(np.array(upcast), original_dtype)
Exceptions and behavior
Function _mx_to_numpy_safe calls np.array, str, str(arr.dtype).rsplit, arr.astype; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.KVCacheSerializer · class
Serializer for KVCache and RotatingKVCache layers.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.ssd_cache.KVCacheSerializer
Exceptions and behavior
Class KVCacheSerializer derives from LayerSerializer and declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.KVCacheSerializer.snapshot_layer · method
Copy a KV cache layer into NumPy-backed writer-thread data.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
snapshot
Exceptions and behavior
Method KVCacheSerializer.snapshot_layer calls _mx_to_numpy_safe, getattr, hasattr; returns snapshot.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.KVCacheSerializer.serialize_layer · method
vllm_mlx.ssd_cache.KVCacheSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any]
Write one KV layer to safetensors and return reconstruction metadata.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
snapshot |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
layer_idx |
int |
yes |
none |
Required positional or keyword input. |
file_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
metadata
Exceptions and behavior
Method KVCacheSerializer.serialize_layer calls save_file; returns metadata.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.KVCacheSerializer.deserialize_layer · method
vllm_mlx.ssd_cache.KVCacheSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict
Load one KV layer as arrays plus cache reconstruction metadata.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_path |
str |
yes |
none |
Required positional or keyword input. |
metadata |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict - Direct return expressions:
result
Exceptions and behavior
Method KVCacheSerializer.deserialize_layer calls load_file; returns result.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.ArraysCacheSerializer · class
Serializer for ArraysCache (Mamba/linear attention) layers.
Parameters
This callable has no explicit inputs.
Returns
- Constructs:
vllm_mlx.ssd_cache.ArraysCacheSerializer
Exceptions and behavior
Class ArraysCacheSerializer derives from LayerSerializer and declares 3 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.ArraysCacheSerializer.snapshot_layer · method
Copy an arrays-cache state into NumPy-backed writer-thread data.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
snapshot
Exceptions and behavior
Method ArraysCacheSerializer.snapshot_layer calls _mx_to_numpy_safe, state_np.append, original_dtypes.append, any; returns snapshot.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.ArraysCacheSerializer.serialize_layer · method
vllm_mlx.ssd_cache.ArraysCacheSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any]
Write arrays-cache state to safetensors and return its metadata.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
snapshot |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
layer_idx |
int |
yes |
none |
Required positional or keyword input. |
file_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict[str, Any] - Direct return expressions:
metadata
Exceptions and behavior
Method ArraysCacheSerializer.serialize_layer calls enumerate, save_file, len; returns metadata.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.ArraysCacheSerializer.deserialize_layer · method
vllm_mlx.ssd_cache.ArraysCacheSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict
Load arrays-cache state and any original dtype hints.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_path |
str |
yes |
none |
Required positional or keyword input. |
metadata |
dict[str, Any] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict - Direct return expressions:
result
Exceptions and behavior
Method ArraysCacheSerializer.deserialize_layer calls load_file, range, state.append; returns result.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.get_serializer_for_layer · function
Return the appropriate serializer for a cache layer.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
Any |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
LayerSerializer - Direct return expressions:
KVCacheSerializer();ArraysCacheSerializer()
Exceptions and behavior
Function get_serializer_for_layer calls hasattr, KVCacheSerializer, isinstance, getattr; can raise ValueError; has 2 explicit return paths.
Directly raised exceptions: ValueError.
vllm_mlx.ssd_cache.SSDCacheTier · class
Cold-tier disk cache for KV cache entries.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
config |
SSDCacheConfig |
yes |
none |
Required positional or keyword input. |
Returns
- Constructs:
vllm_mlx.ssd_cache.SSDCacheTier
Exceptions and behavior
Class SSDCacheTier declares 15 direct member(s).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.__init__ · method
Method SSDCacheTier.__init__ updates self._config, self._closed, self._writer_thread, self._cache_dir; calls ValueError, os.path.join, os.makedirs, SSDIndex; can raise ValueError.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
config |
SSDCacheConfig |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheTier.__init__ updates self._config, self._closed, self._writer_thread, self._cache_dir; calls ValueError, os.path.join, os.makedirs, SSDIndex; can raise ValueError.
Directly raised exceptions: ValueError.
vllm_mlx.ssd_cache.SSDCacheTier._entry_hash · method
Compute deterministic hash for a token sequence.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
str - Direct return expressions:
_tokens_hash(tokens)
Exceptions and behavior
Method SSDCacheTier._entry_hash calls _tokens_hash; returns _tokens_hash(tokens).
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.get_stats · method
Return current SSD cache statistics.
Parameters
This callable has no explicit inputs.
Returns
- Type:
dict - Direct return expressions:
self._stats.to_dict()
Exceptions and behavior
Method SSDCacheTier.get_stats calls self._stats.to_dict; returns self._stats.to_dict().
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.start_writer · method
Start the background spill writer thread.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method SSDCacheTier.start_writer updates self._writer_thread; calls self._writer_stop.clear, threading.Thread, self._writer_thread.start, logger.info; returns None.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier._writer_loop · method
Drain spill queue and persist entries.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheTier._writer_loop calls self._writer_stop.is_set, self._spill_queue.get, self._write_entry, logger.exception.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.enqueue_spill · method
vllm_mlx.ssd_cache.SSDCacheTier.enqueue_spill(tokens: tuple[int, ...], cache: list[Any], memory_bytes: int) -> bool
Enqueue a cache entry for async spill to SSD.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
cache |
list[Any] |
yes |
none |
Required positional or keyword input. |
memory_bytes |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
bool - Direct return expressions:
False;True
Exceptions and behavior
Method SSDCacheTier.enqueue_spill calls any, _is_quantized_layer, isinstance, converted.extend; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.enqueue_spill._is_quantized_layer · nested function
Nested Function SSDCacheTier.enqueue_spill._is_quantized_layer calls isinstance, getattr; has 2 explicit return paths.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
layer |
not annotated |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
True;isinstance(keys, (tuple, list))
Exceptions and behavior
Nested Function SSDCacheTier.enqueue_spill._is_quantized_layer calls isinstance, getattr; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier._write_entry · method
vllm_mlx.ssd_cache.SSDCacheTier._write_entry(tokens_key: tuple[int, ...], layer_snapshots: list[tuple[LayerSerializer, dict[str, Any]]], memory_bytes: int) -> None
Atomically persist one entry (writer thread; numpy-only input).
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens_key |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
layer_snapshots |
list[tuple[LayerSerializer, dict[str, Any]]] |
yes |
none |
Required positional or keyword input. |
memory_bytes |
int |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheTier._write_entry updates self._stats.spill_count, self._stats.spill_bytes; calls self._entry_hash, os.path.join, os.path.exists, shutil.rmtree.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.lookup_ssd · method
Synchronous check whether tokens exist in SSD tier.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict | None - Direct return expressions:
result;None
Exceptions and behavior
Method SSDCacheTier.lookup_ssd calls self._index.lookup_exact; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.lookup_ssd_prefix · method
Find the longest prefix match in the SSD tier.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
dict | None - Direct return expressions:
results[0];None
Exceptions and behavior
Method SSDCacheTier.lookup_ssd_prefix calls self._index.lookup_prefix; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.async_promote · method
async vllm_mlx.ssd_cache.SSDCacheTier.async_promote(tokens: tuple[int, ...], reserve_budget_fn, release_budget_fn) -> list | None
Promote an entry from SSD to RAM asynchronously.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Token sequence to promote. |
reserve_budget_fn |
not annotated |
yes |
none |
Callable(nbytes) -> bool. Must return True if budget is available and reserved, False otherwise. |
release_budget_fn |
not annotated |
yes |
none |
Callable(nbytes) -> None. Called to release budget on failure. |
Returns
- Type:
list | None - Direct return expressions:
None;cache_layers
Exceptions and behavior
Method SSDCacheTier.async_promote updates self._stats.ssd_misses, self._stats.promotion_failures, self._stats.ssd_hits, self._stats.reload_latency_sum; calls self._index.lookup_exact, reserve_budget_fn, logger.warning, time.time; awaits asynchronous work; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier._read_entry · method
vllm_mlx.ssd_cache.SSDCacheTier._read_entry(tokens: tuple[int, ...], relative_path: str) -> list | None
Read a cache entry from disk.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
relative_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
list | None - Direct return expressions:
None;cache_layers
Exceptions and behavior
Method SSDCacheTier._read_entry calls os.path.join, open, json.load, logger.warning; has 2 explicit return paths.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier._quarantine_entry · method
vllm_mlx.ssd_cache.SSDCacheTier._quarantine_entry(tokens: tuple[int, ...], relative_path: str) -> None
Move a corrupt entry to quarantine and remove from index.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tokens |
tuple[int, ...] |
yes |
none |
Required positional or keyword input. |
relative_path |
str |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheTier._quarantine_entry calls os.path.join, os.path.exists, os.makedirs, os.path.dirname.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier._enforce_capacity · method
Evict oldest SSD entries until within capacity limits.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None
Exceptions and behavior
Method SSDCacheTier._enforce_capacity calls self._index.get_entry_count, self._index.get_total_bytes, self._index.get_lru, _blob_to_tokens.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.reconcile · method
Reconcile index with files on disk.
Parameters
This callable has no explicit inputs.
Returns
- Type:
int - Direct return expressions:
cleaned
Exceptions and behavior
Method SSDCacheTier.reconcile calls self._index.all_entries, os.path.join, os.path.isdir, os.path.exists; returns cleaned.
No direct raise statement appears in this definition.
vllm_mlx.ssd_cache.SSDCacheTier.close · method
Close the SSD cache tier and release resources.
Parameters
This callable has no explicit inputs.
Returns
- Type:
None - Direct return expressions:
None
Exceptions and behavior
Method SSDCacheTier.close updates self._closed, self._writer_thread; calls self._writer_stop.set, self._spill_queue.put_nowait, self._writer_thread.join, self._index.close; returns None.
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 |
|---|---|---|---|---|
SSDCacheConfig |
class | SSDCacheConfig(cache_dir: str \| None = None, max_size_gb: float = 10.0, max_entries: int = 10000, file_permissions: int = 384, dir_permissions: int = 448, spill_queue_size: int = 64, retention_seconds: int \| None = None) |
Configuration for SSD cache tier. | #L43-L78 |
SSDCacheConfig.__post_init__ |
method | SSDCacheConfig.__post_init__() -> None |
Method SSDCacheConfig.__post_init__ calls ValueError; can raise ValueError. |
#L65-L73 |
SSDCacheConfig.max_size_bytes |
method | SSDCacheConfig.max_size_bytes() -> int |
Maximum cache size in bytes. | #L76-L78 |
SSDCacheStats |
class | SSDCacheStats(spill_count: int = 0, spill_bytes: int = 0, ssd_hits: int = 0, ssd_misses: int = 0, reload_latency_sum: float = 0.0, reload_bytes: int = 0, promotion_failures: int = 0) |
Statistics for SSD cache tier — exposed from day one. | #L82-L123 |
SSDCacheStats.to_dict |
method | SSDCacheStats.to_dict() -> dict |
Return spill, lookup, reload, and promotion statistics. | #L103-L123 |
_tokens_to_blob |
function | _tokens_to_blob(tokens: tuple[int, ...]) -> bytes |
Serialize token tuple to a compact binary blob for SQLite storage. | #L126-L132 |
_blob_to_tokens |
function | _blob_to_tokens(blob: bytes) -> tuple[int, ...] |
Deserialize binary blob back to token tuple. | #L135-L139 |
_tokens_hash |
function | _tokens_hash(tokens: tuple[int, ...]) -> str |
Compute SHA-256 hex digest of a token sequence for use as primary key. | #L142-L144 |
_prefix_hash |
function | _prefix_hash(tokens: tuple[int, ...]) -> str |
Hash the bounded token prefix used to prefilter prefix lookups. | #L147-L149 |
SSDIndex |
class | SSDIndex(cache_dir: str) |
SQLite-backed index for SSD cache entries. | #L152-L405 |
SSDIndex.__init__ |
method | SSDIndex.__init__(cache_dir: str) -> None |
Method SSDIndex.__init__ updates self._cache_dir, self._db_lock, self._conn, self._conn.row_factory; calls threading.Lock, os.path.join, sqlite3.connect, self._conn.execute. |
#L165-L173 |
SSDIndex._create_tables |
method | SSDIndex._create_tables() -> None |
Method SSDIndex._create_tables calls self._conn.executescript, self._ensure_column, self._conn.execute, cur.fetchone. |
#L175-L213 |
SSDIndex._ensure_column |
method | SSDIndex._ensure_column(table: str, column: str, definition: str) -> None |
Method SSDIndex._ensure_column calls self._conn.execute, cur.fetchall. |
#L215-L218 |
SSDIndex._backfill_prefix_hashes |
method | SSDIndex._backfill_prefix_hashes() -> None |
Method SSDIndex._backfill_prefix_hashes calls self._conn.execute, cur.fetchall, _blob_to_tokens, _prefix_hash. |
#L220-L230 |
SSDIndex.insert_entry |
method | SSDIndex.insert_entry(tokens_key: tuple[int, ...], file_path: str, memory_bytes: int, num_tokens: int) -> None |
Insert or replace a cache entry in the index. | #L232-L263 |
SSDIndex.lookup_exact |
method | SSDIndex.lookup_exact(tokens_key: tuple[int, ...]) -> dict \| None |
Look up an exact token sequence. | #L265-L280 |
SSDIndex.lookup_prefix |
method | SSDIndex.lookup_prefix(query_tokens: tuple[int, ...]) -> list[dict] |
Find entries whose token sequence is a prefix of query_tokens. | #L282-L324 |
SSDIndex.delete_entry |
method | SSDIndex.delete_entry(tokens_key: tuple[int, ...]) -> None |
Delete an entry by token sequence. | #L326-L333 |
SSDIndex.get_lru |
method | SSDIndex.get_lru(limit: int = 10) -> list[dict] |
Get the least recently used entries, ordered oldest first. | #L335-L355 |
SSDIndex.get_total_bytes |
method | SSDIndex.get_total_bytes() -> int |
Get total memory_bytes across all entries. | #L357-L363 |
SSDIndex.get_entry_count |
method | SSDIndex.get_entry_count() -> int |
Get number of entries in the index. | #L365-L369 |
SSDIndex.touch |
method | SSDIndex.touch(tokens_key: tuple[int, ...]) -> None |
Update accessed_at timestamp for an entry (marks as recently used). | #L371-L379 |
SSDIndex.all_entries |
method | SSDIndex.all_entries() -> list[dict] |
Return all entries (for startup reconciliation). | #L381-L400 |
SSDIndex.close |
method | SSDIndex.close() -> None |
Close the SQLite connection. | #L402-L405 |
LayerSerializer |
class | LayerSerializer() |
Interface for per-layer cache serialization. | #L419-L446 |
LayerSerializer.snapshot_layer |
method | LayerSerializer.snapshot_layer(layer: Any) -> dict[str, Any] |
Producer-thread CPU snapshot of an MLX-backed cache layer. | #L429-L431 |
LayerSerializer.serialize_layer |
method | LayerSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any] |
Writer-thread: persist a snapshot to safetensors at file_path. | #L434-L441 |
LayerSerializer.deserialize_layer |
method | LayerSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict |
Read a layer back from disk. | #L444-L446 |
_mx_to_numpy_safe |
function | _mx_to_numpy_safe(arr: Any) -> tuple[np.ndarray, str \| None] |
mx.array → np.ndarray, upcasting numpy-unsupported dtypes (bf16) to fp32. | #L449-L467 |
KVCacheSerializer |
class | KVCacheSerializer() |
Serializer for KVCache and RotatingKVCache layers. | #L470-L564 |
KVCacheSerializer.snapshot_layer |
method | KVCacheSerializer.snapshot_layer(layer: Any) -> dict[str, Any] |
Copy a KV cache layer into NumPy-backed writer-thread data. | #L481-L515 |
KVCacheSerializer.serialize_layer |
method | KVCacheSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any] |
Write one KV layer to safetensors and return reconstruction metadata. | #L517-L542 |
KVCacheSerializer.deserialize_layer |
method | KVCacheSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict |
Load one KV layer as arrays plus cache reconstruction metadata. | #L544-L564 |
ArraysCacheSerializer |
class | ArraysCacheSerializer() |
Serializer for ArraysCache (Mamba/linear attention) layers. | #L567-L627 |
ArraysCacheSerializer.snapshot_layer |
method | ArraysCacheSerializer.snapshot_layer(layer: Any) -> dict[str, Any] |
Copy an arrays-cache state into NumPy-backed writer-thread data. | #L573-L587 |
ArraysCacheSerializer.serialize_layer |
method | ArraysCacheSerializer.serialize_layer(snapshot: dict[str, Any], layer_idx: int, file_path: str) -> dict[str, Any] |
Write arrays-cache state to safetensors and return its metadata. | #L589-L610 |
ArraysCacheSerializer.deserialize_layer |
method | ArraysCacheSerializer.deserialize_layer(file_path: str, metadata: dict[str, Any]) -> dict |
Load arrays-cache state and any original dtype hints. | #L612-L627 |
get_serializer_for_layer |
function | get_serializer_for_layer(layer: Any) -> LayerSerializer |
Return the appropriate serializer for a cache layer. | #L630-L646 |
SSDCacheTier |
class | SSDCacheTier(config: SSDCacheConfig) |
Cold-tier disk cache for KV cache entries. | #L649-L1248 |
SSDCacheTier.__init__ |
method | SSDCacheTier.__init__(config: SSDCacheConfig) -> None |
Method SSDCacheTier.__init__ updates self._config, self._closed, self._writer_thread, self._cache_dir; calls ValueError, os.path.join, os.makedirs, SSDIndex; can raise ValueError. |
#L667-L705 |
SSDCacheTier._entry_hash |
method | SSDCacheTier._entry_hash(tokens: tuple[int, ...]) -> str |
Compute deterministic hash for a token sequence. | #L708-L710 |
SSDCacheTier.get_stats |
method | SSDCacheTier.get_stats() -> dict |
Return current SSD cache statistics. | #L712-L714 |
SSDCacheTier.start_writer |
method | SSDCacheTier.start_writer() -> None |
Start the background spill writer thread. | #L716-L725 |
SSDCacheTier._writer_loop |
method | SSDCacheTier._writer_loop() -> None |
Drain spill queue and persist entries. | #L727-L744 |
SSDCacheTier.enqueue_spill |
method | SSDCacheTier.enqueue_spill(tokens: tuple[int, ...], cache: list[Any], memory_bytes: int) -> bool |
Enqueue a cache entry for async spill to SSD. | #L746-L867 |
SSDCacheTier.enqueue_spill._is_quantized_layer |
nested function | SSDCacheTier.enqueue_spill._is_quantized_layer(layer) -> not annotated |
Nested Function SSDCacheTier.enqueue_spill._is_quantized_layer calls isinstance, getattr; has 2 explicit return paths. |
#L772-L776 |
SSDCacheTier._write_entry |
method | SSDCacheTier._write_entry(tokens_key: tuple[int, ...], layer_snapshots: list[tuple[LayerSerializer, dict[str, Any]]], memory_bytes: int) -> None |
Atomically persist one entry (writer thread; numpy-only input). | #L869-L944 |
SSDCacheTier.lookup_ssd |
method | SSDCacheTier.lookup_ssd(tokens: tuple[int, ...]) -> dict \| None |
Synchronous check whether tokens exist in SSD tier. | #L946-L958 |
SSDCacheTier.lookup_ssd_prefix |
method | SSDCacheTier.lookup_ssd_prefix(tokens: tuple[int, ...]) -> dict \| None |
Find the longest prefix match in the SSD tier. | #L960-L968 |
SSDCacheTier.async_promote |
method | async SSDCacheTier.async_promote(tokens: tuple[int, ...], reserve_budget_fn, release_budget_fn) -> list \| None |
Promote an entry from SSD to RAM asynchronously. | #L970-L1076 |
SSDCacheTier._read_entry |
method | SSDCacheTier._read_entry(tokens: tuple[int, ...], relative_path: str) -> list \| None |
Read a cache entry from disk. | #L1078-L1121 |
SSDCacheTier._quarantine_entry |
method | SSDCacheTier._quarantine_entry(tokens: tuple[int, ...], relative_path: str) -> None |
Move a corrupt entry to quarantine and remove from index. | #L1123-L1142 |
SSDCacheTier._enforce_capacity |
method | SSDCacheTier._enforce_capacity() -> None |
Evict oldest SSD entries until within capacity limits. | #L1144-L1181 |
SSDCacheTier.reconcile |
method | SSDCacheTier.reconcile() -> int |
Reconcile index with files on disk. | #L1183-L1229 |
SSDCacheTier.close |
method | SSDCacheTier.close() -> None |
Close the SSD cache tier and release resources. | #L1231-L1248 |