Repository navigation
Add copy() to KVCache protocol and all implementations - #158
Merged
Merged
Conversation
Add an independent deep-copy method to enable reusing a prefix cache across multiple ChatSession instances without reloading from disk. - Add copy() requirement to KVCache protocol - Implement on KVCacheSimple, RotatingKVCache, QuantizedKVCache, ChunkedKVCache, ArraysCache, MambaCache, and CacheList - Guard against empty state in all copy() methods to avoid fatalError from state setters that reject empty arrays - Preserve leftPadding in ArraysCache/MambaCache copies - Add CacheList array-based initializer to support copy() - Change ArraysCache.leftPadding from private to internal for subclass access in MambaCache.copy() Tests: - testCacheCopyIsIndependent: parameterized across 6 cache types, verifies copy has same state and mutation of copy leaves original unchanged - testCacheCopyOnEmptyCache: verifies copy of unpopulated cache does not crash - testCacheListCopyIsIndependent: verifies CacheList with heterogeneous sub-caches copies independently
Picks up the fix for array[.ellipsis] returning self instead of a copy (ml-explore/mlx-swift#367), plus mlx 0.31.1 C++ updates.
alankessler
force-pushed
the
kvcache-copy-clean
branch
from
March 26, 2026 20:29
04d8efb to
3ad6704
Compare
davidkoski
approved these changes
Mar 26, 2026
davidkoski
approved these changes
Mar 26, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Looks good but we need to wait for ml-explore/mlx-swift#376 -- the fmt C++ library is failing to build on the new Xcode.
davidkoski
approved these changes
Mar 27, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Changes look good, thank you!
Member
|
Oops, per my previous s comment, waiting on a new tag for mlx-swift. |
Member
|
And that is tagged, let's go! |
3 of 4 tasks
TheTom
referenced
this pull request
in TheTom/mlx-swift-lm
Apr 5, 2026
* Add copy() to KVCache protocol and all implementations Add an independent deep-copy method to enable reusing a prefix cache across multiple ChatSession instances without reloading from disk. - Add copy() requirement to KVCache protocol - Implement on KVCacheSimple, RotatingKVCache, QuantizedKVCache, ChunkedKVCache, ArraysCache, MambaCache, and CacheList - Guard against empty state in all copy() methods to avoid fatalError from state setters that reject empty arrays - Preserve leftPadding in ArraysCache/MambaCache copies - Add CacheList array-based initializer to support copy() - Change ArraysCache.leftPadding from private to internal for subclass access in MambaCache.copy() Tests: - testCacheCopyIsIndependent: parameterized across 6 cache types, verifies copy has same state and mutation of copy leaves original unchanged - testCacheCopyOnEmptyCache: verifies copy of unpopulated cache does not crash - testCacheListCopyIsIndependent: verifies CacheList with heterogeneous sub-caches copies independently * Bump mlx-swift dependency to 0.31.1 Picks up the fix for array[.ellipsis] returning self instead of a copy (ml-explore/mlx-swift#367), plus mlx 0.31.1 C++ updates.
mikedoise
added a commit
to mikedoise/mlx-swift-lm
that referenced
this pull request
Apr 6, 2026
Enables cache cloning for speculative decoding and session management. Upstream commit 807885c. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
davidtai
added a commit
to davidtai/mlx-swift-lm
that referenced
this pull request
Oct 6, 2026
The fork does not merge or rebase onto upstream. base.hash stays fixed. Upstream fixes are ported one commit at a time, each described in its own fork.yaml section. This replaces the rebase instructions, which no longer apply. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on the discussion in #151 — with
consumingon the cache init, there's no way to reuse a prefix cache across multiple sessions without reloading from disk. This addscopy()so you can docache.map { $0.copy() }instead.Implementation uses constructor params +
state/metaStateroundtrip, so there's no dependency on a new mlx-swift tag. Empty caches are handled (the state setters fatalError on empty arrays, so copy() guards against that).One visibility change:
ArraysCache.leftPaddinggoes fromprivatetointernalsoMambaCache.copy()can preserve it.Tests: