Add experimental KAR PLE model quality arm

This commit is contained in:
Pavlo Ratushnyi
2026-10-03 10:58:14 +02:00
parent 6f57ac7f45
commit 80f66707bd
10 changed files with 460 additions and 5 deletions
+30 -3
View File
@@ -220,6 +220,8 @@ struct Options {
std::string embd_gguf;
/// Plan v0.3 P2: how the n-gram table is read. Direct (default) = unbuffered SSD reads, table never in RAM.
std::string ple_io = "direct";
std::string ple_kar; ///< experimental PLE-only KAR quality arm; all other weights stay native
uint32_t ple_kar_level = 2;
int64_t ple_row_cache = 1 << 20; ///< bounded row cache (rows of 90 B); 0 disables
int ple_inflight = 64;
double ple_delay_us = 0; ///< fault injection: every row read completes no earlier than this
@@ -423,6 +425,8 @@ void usage() {
" --tokens-file PATH pretokenized prompt, commas or whitespace (alternative to --tokens)\n"
" --ple-gguf PATH required PLE table (original second GGUF shard); with --native, the model's\n"
" shard that holds per_layer_token_embd.weight when not given\n"
" --ple-kar PATH experimental PLE-only KAR CPU quality arm (requires a KAR-enabled build)\n"
" --ple-kar-level N precision of the experimental PLE KAR arm (default 2)\n"
" --no-ple explicit diagnostic ablation of the PLE layer\n"
" --ple-io direct|mmap|ram n-gram table reads (plan v0.3 P2). direct (default): unbuffered SSD\n"
" reads, the table never enters RAM or the file cache; mmap: A/B arm;\n"
@@ -1053,6 +1057,18 @@ int main(int argc, char** argv) {
else if (a == "--dump-halves") o.dump_halves = next("--dump-halves");
else if (a == "--dump-routing") o.dump_routing = next("--dump-routing");
else if (a == "--ple-gguf") o.ple_gguf = next("--ple-gguf");
else if (a == "--ple-kar") o.ple_kar = next("--ple-kar");
else if (a == "--ple-kar-level") {
const std::string value = next("--ple-kar-level");
unsigned level = 0;
const auto parsed = std::from_chars(value.data(), value.data() + value.size(), level);
if (parsed.ec != std::errc{} || parsed.ptr != value.data() + value.size() ||
level < 1 || level > 8) {
std::fprintf(stderr, "strata generate: --ple-kar-level must be an integer from 1 to 8\n");
return 2;
}
o.ple_kar_level = level;
}
else if (a == "--no-ple") o.no_ple = true;
else if (a == "--ple-io") o.ple_io = next("--ple-io");
else if (a == "--ple-row-cache") o.ple_row_cache = std::atoll(next("--ple-row-cache"));
@@ -1547,6 +1563,11 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: --no-ple and --ple-gguf are mutually exclusive\n");
return 2;
}
if ((o.no_ple && !o.ple_kar.empty()) || (o.ple_kar.empty() && o.ple_kar_level != 2) ||
(!o.ple_kar.empty() && (o.ple_kar_level < 1 || o.ple_kar_level > 8 || o.ple_io != "direct"))) {
std::fprintf(stderr, "strata generate: --ple-kar requires PLE, level 1..8, and default --ple-io\n");
return 2;
}
if (o.native_ple_postops && o.no_ple) {
std::fprintf(stderr, "strata generate: --native-ple-postops requires PLE enabled\n");
return 2;
@@ -2041,7 +2062,9 @@ int main(int argc, char** argv) {
pio.keepalive_window_s = kw != nullptr && *kw ? std::clamp(std::atof(kw), 1.0, 86400.0) : 60.0;
if (pio.mode != strata::kernels::PleIo::Direct || !pio.io_thread) pio.keepalive_ms = 0;
}
if (!ple_table.open(o.ple_gguf, err, pio)) {
const bool ple_open = o.ple_kar.empty() ? ple_table.open(o.ple_gguf, err, pio)
: ple_table.open_kar(o.ple_kar, o.ple_kar_level, err);
if (!ple_open) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;
}
@@ -2049,7 +2072,10 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: PLE table %s (--ple-io ram) in %.1f s\n",
ple_table.locked() ? "locked in RAM" : "loaded (not locked)",
std::chrono::duration<double>(Clock::now() - tpl).count());
if (pio.keepalive_ms > 0)
if (!o.ple_kar.empty())
std::fprintf(stderr, "strata generate: experimental PLE KAR CPU quality arm at level %u\n",
o.ple_kar_level);
else if (pio.keepalive_ms > 0)
std::fprintf(stderr, "strata generate: the SSD is kept awake while rows are read: one page of the table after "
"%.0f ms without a read, until %.0f s after the last request "
"(STRATA_SSD_KEEPALIVE=0 turns it off)\n", pio.keepalive_ms, pio.keepalive_window_s);
@@ -2468,7 +2494,8 @@ int main(int argc, char** argv) {
return 1;
}
std::fprintf(stderr, "strata generate: PLE on, table %llu rows of %s\n",
(unsigned long long) ple_table.rows(), o.ple_gguf.c_str());
(unsigned long long) ple_table.rows(),
o.ple_kar.empty() ? o.ple_gguf.c_str() : o.ple_kar.c_str());
}
}
for (size_t i = 0; i < stages.size(); ++i) {