Conversation cache: parking an idle --batch slot no longer drops the main session's copy with the shared-prefix checkpoint (#4420)
A batch slot's chain holds one checkpoint (the one its admission copied in). park_slot() went through park_source(), whose drop_superseded() (#342) removes a parked entry when the outgoing chain holds that entry's deepest checkpoint; the main session's copy of the same conversation qualifies, and the root checkpoint at the end of an agent's system prompt went with it. The next overlapping request then read the whole 5 K-token prefix again (323 ms in 0.2.6, 4130 ms in 0.2.7). ConversationCache::supersedes_richer() says when the park would drop an entry that has a checkpoint the slot's chain lacks; park_slot() then leaves the slot unparked (it is overwritten, as in 0.2.6) and says so. A slot with no such parked copy is parked as before. The predicate and its test come from the report (shenmintao, #4420).
This commit is contained in:
1 parent
ea73eab442
commit
c7a0cef13a
3 files changed
+59
No files matched your search
@@ -720,5 +720,30 @@ int main() {
|
||||
check(tiny.put(std::move(p2)), "a pinned one fits an empty cache");
|
||||
check(!tiny.put(image({7,8,9})) && tiny.size() == 1, "nothing else fits beside it: parking is refused, the pin stays");
|
||||
}
|
||||
{
|
||||
// #4420: a batch slot's chain holds one checkpoint (its admission's): parking it must not drop (#342) the main session's copy of the
|
||||
// same conversation that also holds the root a sibling borrows from (an agent's system prompt and tools) - supersedes_richer()
|
||||
// names that case, so the slot is not parked
|
||||
auto cp = [](std::vector<int32_t> ids) { ConversationCheckpoint c; c.ids = std::move(ids); return c; };
|
||||
SavedConversation main_copy = image({1, 2, 3, 4, 10, 11, 12});
|
||||
main_copy.checkpoints = {cp({1, 2, 3, 4}), cp({1, 2, 3, 4, 10, 11})};
|
||||
ConversationCache cache(1 << 20, 4);
|
||||
check(cache.put(std::move(main_copy)), "park the main session's copy with its root and turn checkpoints");
|
||||
const std::vector<int32_t> slot_ids{1, 2, 3, 4, 10, 11, 12, 20, 21}; // the slot decoded the reply
|
||||
const std::vector<ConversationCheckpoint> slot_chain{cp({1, 2, 3, 4, 10, 11})}; // the admission's only one
|
||||
check(cache.supersedes_richer(slot_ids, {}, slot_chain, true), "the slot's park would drop the root checkpoint");
|
||||
const std::vector<ConversationCheckpoint> full_chain{cp({1, 2, 3, 4}), cp({1, 2, 3, 4, 10, 11})};
|
||||
check(!cache.supersedes_richer(slot_ids, {}, full_chain, true), "a chain that holds both loses nothing");
|
||||
check(!cache.supersedes_richer(slot_ids, {}, slot_chain, false), "steering mode is isolated");
|
||||
check(!cache.supersedes_richer(std::vector<int32_t>{1, 2, 3, 4, 30, 31}, {},
|
||||
std::vector<ConversationCheckpoint>{cp({1, 2, 3, 4, 30})}, true),
|
||||
"another conversation on the same root supersedes nothing");
|
||||
check(cache.size() == 1 && cache.superseded() == 0, "the predicate changes nothing");
|
||||
const auto sib = cache.best(std::vector<int64_t>{1, 2, 3, 4, 40}, {}, true);
|
||||
check(sib.tokens == 4 && cache.borrows(sib), "a sibling still borrows the root");
|
||||
// what drop_superseded does with the slot's chain (the park this rule prevents): the root goes
|
||||
check(cache.drop_superseded(slot_ids, {}, slot_chain, true) == 1 && cache.size() == 0,
|
||||
"the slot's chain supersedes the richer copy");
|
||||
}
|
||||
std::printf("conversation_cache_test: %d checks passed\n", checks);
|
||||
}
|
||||
Reference in new issue
Block a user