Repository navigation
server: add strict prompt cache RAM limit - #25070
Conversation
7702d13 to
4782510
Compare
|
IMO amount specified by |
|
@ngxson as explained in the PR description, it is definitely not a max right now. If I set --cache-ram to 1G and my kv + checkpoint data sums to 10G, llama.cpp will happily store that when switching to another prefix conversation. The main reason I noticed this is because I run models very close to my device limit (with I can remove the Should I amend the PR? |
|
I haven't looked deep into the current implementation, but I assume that kv cache should not be counted toward this on top of that, its help message says:
so it should be the hard limit for the cache or checkpoints |
|
@ngxson amended the commit/PR One note though: I ran git blame on the code that ensured always one entry was kept in the cache and it turns out you did that 8 months ago: https://github.com/ggml-org/llama.cpp/blame/master/tools/server/server-task.cpp#L1755C11-L1755C11 Just thought I'd mention in case you want to review if there was some reason for doing that. |
Before this commit, --cache-ram was not a hard limit: - The cache always kept at least one entry, even if that entry exceeded the RAM/token limits. - Old entries were only evicted for the RAM/token limits after saving the new one, which could cause the cache to temporarily exceed the RAM/token limits even if individual entries were below the limit. Now, ensure that the RAM limit is strict with these changes: - Skip saving state to cache if by itself it exceeds the RAM limit. - Evict old entries as necessary to make the new entry fit. Additionally, token-limit cleanup may now evict the last remaining cache entry instead of always preserving one.
Before this commit, --cache-ram was not a hard limit: - The cache always kept at least one entry, even if that entry exceeded the RAM/token limits. - Old entries were only evicted for the RAM/token limits after saving the new one, which could cause the cache to temporarily exceed the RAM/token limits even if individual entries were below the limit. Now, ensure that the RAM limit is strict with these changes: - Skip saving state to cache if by itself it exceeds the RAM limit. - Evict old entries as necessary to make the new entry fit. Additionally, token-limit cleanup may now evict the last remaining cache entry instead of always preserving one.
Before this commit, --cache-ram was not a hard limit: - The cache always kept at least one entry, even if that entry exceeded the RAM/token limits. - Old entries were only evicted for the RAM/token limits after saving the new one, which could cause the cache to temporarily exceed the RAM/token limits even if individual entries were below the limit. Now, ensure that the RAM limit is strict with these changes: - Skip saving state to cache if by itself it exceeds the RAM limit. - Evict old entries as necessary to make the new entry fit. Additionally, token-limit cleanup may now evict the last remaining cache entry instead of always preserving one.
Before this commit, --cache-ram was not a hard limit: - The cache always kept at least one entry, even if that entry exceeded the RAM/token limits. - Old entries were only evicted for the RAM/token limits after saving the new one, which could cause the cache to temporarily exceed the RAM/token limits even if individual entries were below the limit. Now, ensure that the RAM limit is strict with these changes: - Skip saving state to cache if by itself it exceeds the RAM limit. - Evict old entries as necessary to make the new entry fit. Additionally, token-limit cleanup may now evict the last remaining cache entry instead of always preserving one.
| SRV_WRN(" - making room for prompt cache entry, removing oldest entry (size = %.3f MiB)\n", | ||
| states.front().size() / (1024.0 * 1024.0)); | ||
|
|
||
| states.pop_front(); |
There was a problem hiding this comment.
This removes previous entries that match the current prompt; i.e. they would have been restored otherwise. Particularly painful when you have 160k+ token in the context, and - boom - fully reprocessed.
Overview
Modify the caching code to ensure
--cache-ramlimit is respected.Additional information
Before this commit, --cache-ram was not a hard limit:
RAM/token limits.
one, which could cause the cache to temporarily exceed the RAM/token limits
even if individual entries were below the limit.
Now, ensure that the RAM limit is strict with these changes:
Additionally, token-limit cleanup may now evict the last remaining cache entry instead of always preserving one.
Requirements