Conversation cache: --conversation-cache-park-gain N stops a turn that grew a few hundred tokens from rewriting a whole snapshot (RTX 5090 Laptop, IQ3_XXS: 1,418 parks -> 1, 2,251.9 GB -> 3.26 GB host copy at 4.7 % read back; decode -3.4 %, inside the run-to-run spread)
A conversation that only advanced a few hundred tokens since its last park does not need a fresh 3 GB copy: the entry it would supersede still holds this conversation's prefix, and the next turn drops the copy anyway (drop_superseded). Reported in #2264 over 1,418 park events on one long single conversation. The flag is opt-in and defaults to 0, which parks every turn exactly as before. What this adds is a way to ask for the gate without a rebuild: on the reporter's rig it is 3.26 GB instead of 9.79 GB per benchmark, the superseded class disappears, and the decode median moves -3.4 %, inside that arm's 92.2-124.1 tok/s spread. parked_prefix_tokens() reports exactly the entries drop_superseded() would remove - it finds them the same way, by the deepest checkpoint the outgoing chain still holds - so the gate cannot name a different entry than the park would drop. conversation_cache_test covers it (7 checks; 4,226 pass). Fixes #2264
This commit is contained in:
1 parent
53f72571fb
commit
d9cb22d287
3 files changed
+70
-2
No files matched your search
@@ -282,6 +282,33 @@ int main() {
|
||||
check(!cache.put(std::move(huge)) && cache.size() == 5 && cache.superseded() == 1,
|
||||
"an oversized put drops nothing");
|
||||
}
|
||||
{
|
||||
// --conversation-cache-park-gain N: parked_prefix_tokens reports what a park now would supersede, so a
|
||||
// conversation that advanced fewer than N tokens since that copy keeps it instead of writing the whole
|
||||
// snapshot again for the next turn to drop. It must name exactly the entries drop_superseded() would remove.
|
||||
auto cp = [](std::vector<int32_t> ids) { ConversationCheckpoint c; c.ids = std::move(ids); return c; };
|
||||
ConversationCache cache(1 << 20, 8);
|
||||
check(cache.parked_prefix_tokens({1, 2, 3}, {}, {}, true) == 0, "an empty cache supersedes nothing");
|
||||
|
||||
const std::vector<int32_t> live_ids = {1, 2, 3, 4, 60, 70};
|
||||
const std::vector<ConversationCheckpoint> chain = {cp({1, 2, 3, 4}), cp({1, 2, 3, 4, 60})};
|
||||
SavedConversation same = image({1, 2, 3, 4, 60, 70});
|
||||
same.checkpoints = chain;
|
||||
check(cache.put(std::move(same)), "park a conversation with a checkpoint chain");
|
||||
check(cache.parked_prefix_tokens(live_ids, {}, chain, true) == 5,
|
||||
"the entry the outgoing chain supersedes is reported by its deepest checkpoint");
|
||||
|
||||
const std::vector<ConversationCheckpoint> other_chain = {cp({1, 2, 3})};
|
||||
check(cache.parked_prefix_tokens({1, 2, 3, 40, 50}, {}, other_chain, true) == 0,
|
||||
"a conversation sharing only the root supersedes nothing");
|
||||
check(cache.parked_prefix_tokens(live_ids, {}, chain, false) == 0,
|
||||
"the other steering mode is a different entry");
|
||||
check(cache.parked_prefix_tokens({1, 2, 3, 4, 60, 70, 71}, {}, chain, true) == 5,
|
||||
"an appended tail keeps the reported depth at the parked one");
|
||||
SavedConversation no_cp = image({1, 2, 3, 9});
|
||||
check(cache.put(std::move(no_cp)) && cache.parked_prefix_tokens({1, 2, 3, 9}, {}, {}, true) == 0,
|
||||
"an entry without checkpoints is never reported");
|
||||
}
|
||||
{
|
||||
ConversationCache disabled(0,4), no_slots(1024,0);
|
||||
check(!disabled.enabled() && !no_slots.enabled(), "both disable switches");
|
||||
|
||||
Reference in new issue
Block a user