engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
570201a0dc
commit
87e2633afe
@@ -20,6 +20,7 @@
|
||||
#include <vector>
|
||||
|
||||
using strata::program::conv_cache::eviction_victim;
|
||||
using strata::program::conv_cache::spread_victim;
|
||||
|
||||
namespace {
|
||||
int g_fail = 0;
|
||||
@@ -29,8 +30,52 @@ void check(bool ok, const char* what) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// a conversation of `turns` turns of `turn` tokens each after a `root`-token system prompt, a checkpoint at every turn's
|
||||
// end and at most `cap` kept; returns how many tokens a request whose prompt differs `back` tokens before the end reuses
|
||||
int64_t reuse_after_edit(bool spread, int64_t root, int64_t turn, int turns, int64_t cap, int64_t back) {
|
||||
std::vector<int64_t> lens = {root};
|
||||
std::vector<uint64_t> stamps = {1};
|
||||
for (int t = 1; t <= turns; ++t) {
|
||||
lens.push_back(root + t * turn);
|
||||
stamps.push_back(uint64_t(t + 1));
|
||||
while ((int64_t) lens.size() > cap) {
|
||||
const size_t v = spread ? spread_victim(lens.data(), stamps.data(), lens.size(), cap, nullptr, nullptr)
|
||||
: eviction_victim(stamps.data(), stamps.size(), cap);
|
||||
lens.erase(lens.begin() + (std::ptrdiff_t) v);
|
||||
stamps.erase(stamps.begin() + (std::ptrdiff_t) v);
|
||||
}
|
||||
}
|
||||
const int64_t edit = lens.back() - back;
|
||||
int64_t reuse = 0;
|
||||
for (int64_t l : lens)
|
||||
if (l <= edit) reuse = l;
|
||||
return reuse;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::printf("conv_cache_test\n");
|
||||
{ // --prompt-cache-spread: 200 turns of 1,000 tokens after a 9,525-token system prompt, 6 checkpoints
|
||||
const int64_t end = 9525 + 200 * 1000;
|
||||
const int64_t lru6 = reuse_after_edit(false, 9525, 1000, 200, 6, 6000);
|
||||
const int64_t spread6 = reuse_after_edit(true, 9525, 1000, 200, 6, 6000);
|
||||
std::printf(" an edit 6K before the end: least recent use reuses %lld, spread %lld of %lld\n", (long long) lru6,
|
||||
(long long) spread6, (long long) end);
|
||||
check(lru6 == 9525, "least recent use: an edit 6K back falls through to the root");
|
||||
check(end - spread6 < 4 * 6000, "spread: an edit 6K back reads less than 24K again");
|
||||
const int64_t spread42 = reuse_after_edit(true, 9525, 1000, 200, 6, 42000);
|
||||
check(end - spread42 < 4 * 42000, "spread: an edit 42K back reads less than 168K again");
|
||||
check(reuse_after_edit(true, 9525, 1000, 200, 6, 500) == end - 1000, "spread: the turn before is still kept");
|
||||
}
|
||||
{
|
||||
const std::vector<int64_t> lens = {100, 200, 300, 400};
|
||||
const std::vector<uint64_t> stamps = {1, 2, 3, 4};
|
||||
const bool pinned[] = {false, true, true, false};
|
||||
check(spread_victim(lens.data(), stamps.data(), 4, 3, nullptr, pinned) ==
|
||||
eviction_victim(stamps.data(), 4, 3, nullptr, pinned),
|
||||
"spread: every candidate pinned - the plain policy");
|
||||
check(spread_victim(lens.data(), stamps.data(), 2, 1, nullptr, nullptr) == 0,
|
||||
"spread: two items, one slot - the plain policy");
|
||||
}
|
||||
{
|
||||
const std::vector<uint64_t> stamps = {1, 2, 3, 4, 5, 6, 7}; // chat A: root + six turns, one over
|
||||
check(eviction_victim(stamps.data(), stamps.size(), 6) == 1,
|
||||
@@ -62,6 +107,31 @@ int main() {
|
||||
const size_t b = eviction_victim(stamps.data(), stamps.size(), 4);
|
||||
check(a == 1 && b == 1, "ties among equally stale leaves: the earlier index, deterministically");
|
||||
}
|
||||
{ // --prompt-cache-tail: the tail checkpoint goes first; never the root, never the newest item
|
||||
const std::vector<uint64_t> st = {1, 2, 3, 4, 5, 6, 7};
|
||||
const bool t2[7] = {false, false, false, true, false, false, false};
|
||||
check(eviction_victim(st.data(), st.size(), 6, t2) == 3, "a stale tail checkpoint leaves before the oldest leaf");
|
||||
const bool t3[7] = {false, false, false, false, false, false, true};
|
||||
check(eviction_victim(st.data(), st.size(), 6, t3) == 1, "the newest item, even a tail, is not the victim");
|
||||
const bool t4[7] = {true, false, false, false, false, false, false};
|
||||
check(eviction_victim(st.data(), st.size(), 6, t4) == 1, "the root is never the victim, tail flag or not");
|
||||
check(eviction_victim(st.data(), st.size(), 6, nullptr) == 1, "no tail flags: the plain policy");
|
||||
}
|
||||
{ // pin=N: a pinned shared prefix is never the victim, however stale its stamp
|
||||
const std::vector<uint64_t> st = {1, 2, 30, 4, 5, 6, 7};
|
||||
const bool pin1[7] = {false, true, false, false, false, false, false};
|
||||
check(eviction_victim(st.data(), st.size(), 6, nullptr, pin1) == 3,
|
||||
"the oldest checkpoint is pinned: the next least recently used leaves");
|
||||
check(eviction_victim(st.data(), st.size(), 6, nullptr, nullptr) == 1, "no pin flags: the plain policy");
|
||||
const bool pin2[7] = {false, true, false, true, false, false, false};
|
||||
check(eviction_victim(st.data(), st.size(), 6, nullptr, pin2) == 4, "two pins: the third oldest leaves");
|
||||
const bool tail3[7] = {false, false, false, true, false, false, false};
|
||||
check(eviction_victim(st.data(), st.size(), 6, tail3, pin2) == 4, "a pinned item is not taken as the tail either");
|
||||
const bool all[4] = {false, true, true, true};
|
||||
const std::vector<uint64_t> s4 = {1, 9, 3, 5};
|
||||
check(eviction_victim(s4.data(), s4.size(), 4, nullptr, all) == 2, "everything pinned: the oldest pin leaves, never the root");
|
||||
check(eviction_victim(s4.data(), s4.size(), 1, nullptr, all) == 0, "a one-slot budget keeps no pin: the oldest leaves");
|
||||
}
|
||||
std::printf(g_fail ? "FAIL\n" : "PASS\n");
|
||||
return g_fail ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user