Repository navigation
Enforce and expose effective maxKVSize cache policy - #514
Merged
Merged
Conversation
aleroot
force-pushed
the
avoid_maxKVSize_ignored
branch
from
August 7, 2026 03:55
de7edc4 to
20ec2df
Compare
davidkoski
reviewed
Aug 7, 2026
davidkoski
reviewed
Aug 7, 2026
davidkoski
reviewed
Aug 7, 2026
davidkoski
requested changes
Aug 7, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Looks good! See what you think about the error case -- given the recent work in turning some fatals into throws this might be worth fixing.
aleroot
force-pushed
the
avoid_maxKVSize_ignored
branch
2 times, most recently
from
August 10, 2026 19:20
cc3cf77 to
9f83553
Compare
davidkoski
approved these changes
Aug 12, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
I think this is ready to go -- just needs a rebase to fix a conflict. Thank you!
Honor maxKVSize across full, sliding-window, and hybrid model caches. Report the realized per-layer policy through model containers and chat sessions, rebuild structured session caches when the limit changes, and add broad regression coverage and documentation.
aleroot
force-pushed
the
avoid_maxKVSize_ignored
branch
from
August 12, 2026 23:32
9f83553 to
b186838
Compare
5 tasks done
3 of 5 tasks
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.
Proposed changes
GenerateParameters.maxKVSizecan currently be silently ignored by models that provide customnewCache(parameters:)implementations. This is particularly problematic for hybrid architectures, where attention and state-space layers use different cache types.A caller may request a bounded KV cache while the model continues allocating an unbounded attention cache, with no public API for detecting that the requested policy was not applied. This makes memory usage unpredictable during long conversations and forces downstream applications to inspect private cache implementation details.
This PR makes the requested and effective KV-cache policies explicit and reliable.
What
maxKVSizeacross the audited model-specific cache implementations.maxKVSize.EffectiveCacheConfigurationAPI that describes:LanguageModel,ModelContainer, andChatSession.ChatSessionreport the realized cache configuration rather than allocating and inspecting probe caches.maxKVSizechanges, ensuring the new policy is actually applied without losing the conversation transcript.maxKVSize = 1.Why
maxKVSizeis a memory-management contract. Silently ignoring it can cause unexpectedly high memory pressure, especially during long-running conversations and on memory-constrained Apple Silicon devices.The new API also lets applications distinguish between:
This distinction is important because state-space caches do not grow per token in the same way as attention KV caches and should not be reported as bounded attention caches.
With this change, an App using the library can:
maxKVSizebeing enforced for supported attention layers;Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes