serve: the conversation cache is sized from the free RAM when --conversation-cache-mib is not given (#3493): 40% of what is left above the parking floor, at most 8192, off under 1024, one log line; an explicit value (0 too) is kept; harness_reuse_probe.py; docs

This commit is contained in:
Niko1221 committed 2026-10-22 16:06:17 +02:00
1 parent f8f4e8a7df
commit f0010a607f
6 files changed
+129 -7

No files matched your search

+20 -2
View File
@@ -722,7 +722,7 @@ struct Options {
/// prompt again, the v0.1.2 behaviour). One is the GDN recurrence of the 36 layers, the QSA indexer tails and
/// the PLE history (~118 MB of host RAM); the KV cache itself is positional and stays where it is.
int prompt_cache = 6;
int64_t conversation_cache_mib = 0; // opt-in host RAM for independent conversations
int64_t conversation_cache_mib = -1; // host RAM for independent conversations; -1: not given, --serve sizes it from the free RAM (#3493), 0: off
int conversation_cache_slots = 4;
int64_t conversation_cache_min_free_mib = 2560;
/// --serve: park only conversations of at least this many tokens. Every parked conversation costs one of
@@ -881,7 +881,7 @@ void usage() {
" --vision --serve takes images too (GENI requests; embeddings from strata-vision)\n"
" --prompt-cache N --serve: keep N conversation checkpoints between requests (default 6, ~118 MB\n"
" of RAM each; 0 = read every prompt from the start)\n"
" --conversation-cache-mib N --serve: RAM budget for parked conversations (default 0 = off)\n"
" --conversation-cache-mib N --serve: RAM budget for parked conversations (default: sized from the free RAM, up to 8192; 0 = off)\n"
" --conversation-cache-slots N --serve: at most N parked conversations (default 4)\n"
" --conversation-cache-min-free-mib N --serve: RAM floor (under MemAvailable, the cgroup limits and\n"
" --memory-limit-mib) when parking, saving or restoring a session (default 2560)\n"
@@ -9280,6 +9280,24 @@ int main(int argc, char** argv) {
bool cvec_cached = true; // the control vector's state the live session and the checkpoints were read with
// without --mtp the conversation cache stays on: a parked image carries the draft layer's K/V only when there is one
// (the snapshots accept a null draft)
// #3493: no --conversation-cache-mib given: size the cache for agent use from the RAM that is free now that the model is
// loaded (an agent Harness alternates a long main conversation with shorter ones; with the cache off every request read
// its whole prompt again, Reused 0 on 12 of 12). An explicit value, 0 included, is never touched.
if (o.conversation_cache_mib < 0) {
if (o.serve && o.prompt_cache > 0 && o.conversation_cache_slots > 0) {
o.conversation_cache_mib = strata::core::auto_conversation_cache_mib(strata::core::available_host_bytes(),
o.conversation_cache_min_free_mib);
if (o.conversation_cache_mib > 0)
std::fprintf(stderr, "strata serve: conversation cache sized from the free RAM: %lld MiB for up to %d parked "
"conversations, so an agent's next turn reuses its prompt (--conversation-cache-mib N sets it, 0 turns it off)\n",
(long long) o.conversation_cache_mib, o.conversation_cache_slots);
else
std::fprintf(stderr, "strata serve: conversation cache off: not enough free RAM to park conversations "
"(--conversation-cache-mib N asks for one anyway)\n");
} else {
o.conversation_cache_mib = 0;
}
}
strata::core::ConversationCache conversations(
o.prompt_cache > 0 ? (size_t) o.conversation_cache_mib * 1024 * 1024 : 0,
(size_t) o.conversation_cache_slots, o.conversation_cache_min_tokens);