veloxquant_mlx.cache.sliding_window_cache module¶
Sliding-window eviction decorator wrapping any standalone KVCache.
SlidingWindowKVCache composes over another
KVCache instance to cap it at the
most recent window_size tokens. Because the wrapped caches (TurboQuant,
PolarQuant, QJL, etc.) don’t support random deletion, eviction is
implemented by keeping raw key/value vectors in ring buffers and, each time
the window advances, resetting the inner cache to empty (via its own
reset()) and re-feeding it the current window — correct but O(window)
per eviction, so it targets inference rather than training. Only compatible
with STANDALONE_METHODS (see
KVCacheFactory.create’s sliding_window handling).
- class veloxquant_mlx.cache.sliding_window_cache.SlidingWindowKVCache(inner, window_size)[source]¶
Bases:
KVCacheWraps any KVCache with sliding-window token eviction.
Maintains a RingBuffer of the most recent
window_sizetoken slots. When the window is full, the oldest token is evicted.Because the inner cache does not support random deletion, we maintain the window by resetting the inner cache to empty and re-feeding it the current window’s tokens each time one is evicted. This simple strategy is correct but rebuilds the cache every
window_sizetokens; suitable for inference not training.We cache all key-value vectors in our own ring buffer so they’re available to re-feed on each window advance.
- Parameters: