serve: --prompt-cache-spread, checkpoints kept spread back from the conversation's end (opt-in)
Least recent use keeps the newest checkpoints and every turn adds one, so after a few short turns all 6 sit in the last 1-2K tokens. An agent client that rewrites its history a few thousand tokens back then resumes from the system prompt: on 2x CMP 50HX with the pi coding agent a 210,528-token prompt that was the same as the session for 204,349 tokens resumed at 9,525 and read 201,003 again (100 s). With the flag the victim is the checkpoint whose removal leaves the smallest gap for its distance from the newest, so the kept points thin out geometrically: after 200 turns of 1,000 tokens they sit 0, 1K, 3K, 8K, 43K and 200K before the end, and an edit 6K back reads 8K again (least recent use: 200K), 42K back 43K. The same number of checkpoints, no more RAM; never the root, the newest or a pinned one, the tail rule first, the plain policy without a candidate. The resume is the usual exact-prefix match. On the box: an 82,593-token conversation grown turn by turn, a turn ~6 steps back rewritten, resumed at 73,610 tokens in 10.2 s against 40.0 s read in full; with the expert placement fixed (--adapt-swaps 0, --pcie-frac 0.17) the greedy answer was the same text as the full read. conv_cache_test: the spread cases (a 200-turn simulation against least recent use, the fallbacks). docs/DETAILS.md: a paragraph after the prompt cache's options.
This commit is contained in:
1 parent
d9cb22d287
commit
a7d4b75443
4 files changed
+93
-2
No files matched your search
@@ -651,6 +651,7 @@ struct Options {
|
||||
/// --serve: also keep a checkpoint every N freshly read prompt tokens (0 = only at the last turn boundary)
|
||||
int64_t prompt_cache_every = 16384;
|
||||
bool prompt_cache_tail = false; // optional extra checkpoint at an existing near-tail chunk boundary
|
||||
bool prompt_cache_spread = false; ///< --prompt-cache-spread: keep checkpoints spread back from the end, not the latest
|
||||
/// --serve: a prompt read from token 0 is also checkpointed at its first turn boundary - the end of the system
|
||||
/// prompt, which every chat of the same client shares - when that is at least N tokens (0 = never)
|
||||
int64_t prompt_cache_root = 2048;
|
||||
@@ -820,6 +821,9 @@ void usage() {
|
||||
" --prompt-cache-every N --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off)\n"
|
||||
" --prompt-cache-tail --serve, single GPU: one extra checkpoint near the prompt's end, at an existing\n"
|
||||
" chunk boundary (default off; requires --prompt-cache and --prompt-cache-every > 0)\n"
|
||||
" --prompt-cache-spread --serve: keep the checkpoints spread back from the conversation's end (dense\n"
|
||||
" near it, thinner further back) instead of the most recently used: a client that\n"
|
||||
" rewrites its history N tokens back reads about N again, not the whole conversation\n"
|
||||
" --turn-token ID --serve: the token that opens a chat turn (default 248045, <|im_start|>)\n"
|
||||
" --tail-role-token ID --serve: a turn of this role right before the last turn is left out of\n"
|
||||
" the conversation checkpoint (a trailing effort turn; default -1 = off)\n"
|
||||
@@ -2135,6 +2139,7 @@ int main(int argc, char** argv) {
|
||||
else o.conversation_cache_slots = (int) number;
|
||||
}
|
||||
else if (a == "--prompt-cache-tail") o.prompt_cache_tail = true;
|
||||
else if (a == "--prompt-cache-spread") o.prompt_cache_spread = true;
|
||||
else if (a == "--prompt-cache-every") o.prompt_cache_every = std::max(0LL, std::atoll(next("--prompt-cache-every")));
|
||||
else if (a == "--prompt-cache-root") o.prompt_cache_root = std::max(0LL, std::atoll(next("--prompt-cache-root")));
|
||||
else if (a == "--turn-token") o.turn_token = std::atoll(next("--turn-token"));
|
||||
@@ -8506,8 +8511,13 @@ int main(int argc, char** argv) {
|
||||
for (size_t i = 0; i < checks.size(); ++i) pin_flags[i] = checks[i].pinned;
|
||||
break;
|
||||
}
|
||||
const size_t victim = strata::program::conv_cache::eviction_victim(
|
||||
stamps.data(), stamps.size(), o.prompt_cache, tail_flags.get(), pin_flags.get());
|
||||
std::vector<int64_t> lens;
|
||||
for (const ConvCheckpoint& k : checks) lens.push_back((int64_t) k.ids.size());
|
||||
const size_t victim = o.prompt_cache_spread
|
||||
? strata::program::conv_cache::spread_victim(lens.data(), stamps.data(), stamps.size(),
|
||||
o.prompt_cache, tail_flags.get(), pin_flags.get())
|
||||
: strata::program::conv_cache::eviction_victim(stamps.data(), stamps.size(), o.prompt_cache,
|
||||
tail_flags.get(), pin_flags.get());
|
||||
checks.erase(checks.begin() + (std::ptrdiff_t) victim);
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user