server: bound the 'unlimited' prompt cache by free host memory and log its size - #350
Merged
TheTom merged 2 commits intoSep 5, 2026
Merged
Conversation
…g its size --cache-ram -1 meant no limit at all. Every cached prompt is a full copy of a sequence's KV state in host memory (14 GiB for a 220k-token f16 cache on a 27B model), so an unbounded cache swaps the box to death long before it helps anyone: bigtime reached 60 GB resident and every new GPU process died with 'SVM mapping failed'. Unlimited now means half of the free host memory at server start, and the cache prints one info line per update with its entry count and size, since that was invisible below trace level. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR (cherry picked from commit a836dadd1332d79c166085cb4a88a27b23f467a6)
Owner
|
Agree with the change; it is exactly the failure mode in #325 and LocalAI's |
TheTom
merged commit Sep 5, 2026
f193682
into
TheTom:feature/turboquant-kv-cache
10 of 26 checks passed
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.
What
--cache-ram -1("no limit") now means half of the free host memory at server start, and the prompt cache prints one info line per update with its entry count and size.Why
Every cached prompt is a full copy of a sequence's KV state in host memory. For a 220k-token f16 cache on Qwen3.8-27B that is 14 GiB per entry. LocalAI's llama.cpp backend passes
-1by default, so on a single-slot server every request that displaces a long session (OpenCode's title and summary calls, for example) saves another 14 GiB copy and nothing ever evicts it. On a 60 GB box the backend reached 59.7 GB resident plus 5 GB of swap within an hour; from that point every new GPU process on the machine died withamdgpu: SVM mapping failed, exceeds resident system memory limit, and the session itself fell back to full re-prefills of 220k tokens (seven minutes each).The cache state was only logged at trace level, which is how this went unnoticed; it is now an info line.
Behaviour
--cache-ram N: unchanged--cache-ram 0: unchanged, disabled--cache-ram -1: bounded tofree_host / 2(falls back to 8192 MiB when the host memory cannot be read); the chosen bound is logged at startupTest
Production, before (bigtime, MI210, Qwen3.8-27B with a 220k-token OpenCode session,
cache_ram=-1via LocalAI): backend at 59.7 GB RSS + 5 GB swap after ~1 h; two 14.2 GB and one 26.5 GB anonymous mappings (full KV copies of the session); 10 LRU slot selections in 2 h; every new HIP process on the box failed withSVM mapping failed.Standalone, after (moonage, CPU backend to stay off the production GPUs, qwen2.5-coder-14b,
-c 8192, a 2.8k-token session interleaved with four unrelated short requests):--cache-ram -1bounding it to 32103 MiB (half of the 62.7 GiB of free host memory)--cache-ram 64size limit: 64 MiBprompt state size 552 MiB exceeds cache size limit), each return re-prefills ~2.8k tokens: the failure mode the bound prevents at scaleThe per-update line reads e.g.
prompt cache: 1 prompts, 552.0 MiB (limit 32103.0 MiB, 8192 tokens).🤖 Generated with Claude Code
https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR