Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
PLE: lift the stale Q5_0 + --ple-io direct refusal (#296)
Rhonstin98bb94d7525d
diff --git a/src/kernels/ngram.cpp b/src/kernels/ngram.cppindex 1a1552bfc..a533dbf51 100644--- a/src/kernels/ngram.cpp+++ b/src/kernels/ngram.cpp@@ -209,13 +209,9 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoOclose();return false;}- // The direct reader has fixed 90-byte rows. Keep it for IQ4_NL; Q5_0's- // 110-byte rows use the mapped path until that reader supports variable rows.- if (impl_->q5_0 && io.mode == PleIo::Direct) {- err = "Q5_0 PLE requires --ple-io mmap";- close();- return false;- }+ // PleReader's row_bytes has been a runtime parameter since the FP8 table (160 B rows) needed it; Q5_0's+ // 110 B rows go through the exact same generic path (ple_reader_test --selftest covers both 90 and 110 B+ // rows: straddling, caching, in-flight tickets, keep-alive). This refusal was stale.impl_->n_rows = t->shape[1];impl_->data = impl_->file->tensor_data(*t);diff --git a/src/ngram/ple_reader_test.cpp b/src/ngram/ple_reader_test.cppindex 86b48624a..87270fdc6 100644--- a/src/ngram/ple_reader_test.cpp+++ b/src/ngram/ple_reader_test.cpp@@ -41,33 +41,33 @@ int g_fail = 0;constexpr uint64_t HEADER = 192; // the real shard's data offset, so rows are misaligned the same way-void expected_row(uint32_t row, uint8_t* out) {- for (uint32_t b = 0; b < ng::ROW_BYTES; ++b) out[b] = (uint8_t) ((row * 2654435761u + b * 97u) >> 7);+void expected_row(uint32_t row, uint32_t rb, uint8_t* out) {+ for (uint32_t b = 0; b < rb; ++b) out[b] = (uint8_t) ((row * 2654435761u + b * 97u) >> 7);std::memcpy(out, &row, 4);}-bool make_table(const std::string& path, uint32_t rows) {+bool make_table(const std::string& path, uint32_t rows, uint32_t rb) {std::ofstream f(path, std::ios::binary);std::vector<uint8_t> head(HEADER, 0xAB);f.write((const char*) head.data(), (std::streamsize) head.size());- uint8_t r[ng::ROW_BYTES];+ std::vector<uint8_t> r(rb);for (uint32_t i = 0; i < rows; ++i) {- expected_row(i, r);- f.write((const char*) r, ng::ROW_BYTES);+ expected_row(i, rb, r.data());+ f.write((const char*) r.data(), rb);}return (bool) f;}-bool check_rows(ng::PleReader& rd, const std::vector<uint32_t>& rows, uint32_t n_rows, const char* what) {- std::vector<uint8_t> out(rows.size() * ng::ROW_BYTES, 0xCC);+bool check_rows(ng::PleReader& rd, const std::vector<uint32_t>& rows, uint32_t n_rows, uint32_t rb, const char* what) {+ std::vector<uint8_t> out(rows.size() * rb, 0xCC);std::string err;const auto t = rd.issue(rows.data(), rows.size(), out.data());if (!rd.collect(t, err)) { CHECK(false, "%s: collect failed: %s", what, err.c_str()); return false; }- uint8_t want[ng::ROW_BYTES];+ std::vector<uint8_t> want(rb);for (size_t i = 0; i < rows.size(); ++i) {- if (rows[i] >= n_rows) std::memset(want, 0, sizeof want);- else expected_row(rows[i], want);- if (std::memcmp(want, &out[i * ng::ROW_BYTES], ng::ROW_BYTES) != 0) {+ if (rows[i] >= n_rows) std::memset(want.data(), 0, rb);+ else expected_row(rows[i], rb, want.data());+ if (std::memcmp(want.data(), &out[i * rb], rb) != 0) {CHECK(false, "%s: row %u (index %zu) differs", what, rows[i], i);return false;}@@ -75,50 +75,53 @@ bool check_rows(ng::PleReader& rd, const std::vector<uint32_t>& rows, uint32_t nreturn true;}-int selftest(const std::string& dir) {+// row_bytes: ng::ROW_BYTES (90, IQ4_NL) is the production default; 110 (#296, OrcaRouter's Q5_0 PLE rows) is+// run too, through the exact same generic row_bytes path -- nothing here is IQ4_NL-specific, so a second row+// size run here is the correctness evidence for lifting ngram.cpp's "Q5_0 PLE requires --ple-io mmap" refusal.+int selftest(const std::string& dir, uint32_t rb) {const uint32_t N = 500000; // 45 MB: large enough for thousands of distinct pages- const std::string path = dir + "/ple_reader_selftest.bin";- if (!make_table(path, N)) { std::fprintf(stderr, "cannot write %s\n", path.c_str()); return 2; }+ const std::string path = dir + "/ple_reader_selftest_" + std::to_string(rb) + ".bin";+ if (!make_table(path, N, rb)) { std::fprintf(stderr, "cannot write %s\n", path.c_str()); return 2; }std::mt19937 rng(7);for (bool thr : {false, true})for (uint64_t cache : {0ull, 4096ull}) {for (uint32_t inflight : {1u, 8u, 64u}) {ng::PleReader rd;std::string err;- CHECK(rd.open(path, HEADER, N, inflight, cache, err, thr), "open: %s", err.c_str());+ CHECK(rd.open(path, HEADER, N, inflight, cache, err, thr, rb), "open: %s", err.c_str());// decode-shaped tickets: 16 random rowsfor (int t = 0; t < 200; ++t) {std::vector<uint32_t> rows(16);for (auto& r : rows) r = rng() % N;- check_rows(rd, rows, N, "decode");+ check_rows(rd, rows, N, rb, "decode");}- // rows that straddle a 4 KiB boundary: byte offset of row r is HEADER + 90 r+ // rows that straddle a 4 KiB boundary: byte offset of row r is HEADER + rb * rstd::vector<uint32_t> straddle;for (uint32_t r = 0; r < N && straddle.size() < 64; ++r) {- const uint64_t a = HEADER + (uint64_t) r * ng::ROW_BYTES;- if (a / 4096 != (a + ng::ROW_BYTES - 1) / 4096) straddle.push_back(r);+ const uint64_t a = HEADER + (uint64_t) r * rb;+ if (a / 4096 != (a + rb - 1) / 4096) straddle.push_back(r);}- check_rows(rd, straddle, N, "straddle");+ check_rows(rd, straddle, N, rb, "straddle");// duplicates, neighbours on one page, the first and last rows, and out-of-range rows- check_rows(rd, {5, 5, 6, 7, 5, 0, N - 1, N, 0xFFFFFFFFu, 44, 45}, N, "dedup/edges");+ check_rows(rd, {5, 5, 6, 7, 5, 0, N - 1, N, 0xFFFFFFFFu, 44, 45}, N, rb, "dedup/edges");// a prefill-shaped ticket much larger than the in-flight windowstd::vector<uint32_t> bulk(20000);for (auto& r : bulk) r = rng() % N;- check_rows(rd, bulk, N, "bulk");+ check_rows(rd, bulk, N, rb, "bulk");// two tickets in flight at once, collected in reverse orderstd::vector<uint32_t> a(16), b(16);for (auto& r : a) r = rng() % N;for (auto& r : b) r = rng() % N;- std::vector<uint8_t> oa(16 * ng::ROW_BYTES), ob(16 * ng::ROW_BYTES);+ std::vector<uint8_t> oa(16 * rb), ob(16 * rb);const auto ta = rd.issue(a.data(), 16, oa.data());const auto tb = rd.issue(b.data(), 16, ob.data());CHECK(rd.collect(tb, err) && rd.collect(ta, err), "two tickets: %s", err.c_str());- uint8_t want[ng::ROW_BYTES];+ std::vector<uint8_t> want(rb);for (int i = 0; i < 16; ++i) {- expected_row(a[i], want);- CHECK(!std::memcmp(want, &oa[i * ng::ROW_BYTES], ng::ROW_BYTES), "ticket a row %d", i);- expected_row(b[i], want);- CHECK(!std::memcmp(want, &ob[i * ng::ROW_BYTES], ng::ROW_BYTES), "ticket b row %d", i);+ expected_row(a[i], rb, want.data());+ CHECK(!std::memcmp(want.data(), &oa[i * rb], rb), "ticket a row %d", i);+ expected_row(b[i], rb, want.data());+ CHECK(!std::memcmp(want.data(), &ob[i * rb], rb), "ticket b row %d", i);}if (cache > 0) CHECK(rd.stats().cache_hits > 0, "the row cache never hit");CHECK(rd.cache_size() <= rd.cache_capacity(), "row cache exceeded its bound");@@ -128,12 +131,12 @@ int selftest(const std::string& dir) {for (bool thr : {false, true}) {ng::PleReader rd;std::string err;- CHECK(rd.open(path, HEADER, N, 16, 0, err, thr), "open: %s", err.c_str());+ CHECK(rd.open(path, HEADER, N, 16, 0, err, thr, rb), "open: %s", err.c_str());rd.set_injected_delay_us(3000);std::vector<uint32_t> rows(16);for (auto& r : rows) r = rng() % N;const double t0 = now_us();- check_rows(rd, rows, N, "delayed");+ check_rows(rd, rows, N, rb, "delayed");CHECK(now_us() - t0 >= 3000, "injected delay not observed (%.0f us)", now_us() - t0);CHECK(rd.stats().late_injected > 0, "no read was held back");}@@ -143,11 +146,11 @@ int selftest(const std::string& dir) {{ng::PleReader rd;std::string err;- CHECK(rd.open(path, HEADER, N, 16, 4096, err, true), "open: %s", err.c_str());+ CHECK(rd.open(path, HEADER, N, 16, 4096, err, true, rb), "open: %s", err.c_str());rd.set_keepalive(20.0, 0.5);std::vector<uint32_t> rows(16);for (auto& r : rows) r = rng() % N;- check_rows(rd, rows, N, "keep-alive, first ticket");+ check_rows(rd, rows, N, rb, "keep-alive, first ticket");const uint64_t reads0 = rd.snapshot().reads;const auto nap = [](int ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); };nap(300);@@ -161,14 +164,14 @@ int selftest(const std::string& dir) {CHECK(k3 == k2, "keep-alive went on after the window (%llu -> %llu)", (unsigned long long) k2,(unsigned long long) k3);CHECK(k2 <= k1 + 20, "keep-alive: %llu reads by the end of a 0.5 s window", (unsigned long long) k2);- check_rows(rd, rows, N, "keep-alive, cached ticket"); // the row cache serves all 16: no row read+ check_rows(rd, rows, N, rb, "keep-alive, cached ticket"); // the row cache serves all 16: no row readCHECK(rd.snapshot().reads == reads0, "cached rows were read again");nap(200);CHECK(rd.snapshot().keepalive_reads >= k3 + 5, "the keep-alive did not start again (%llu -> %llu)",(unsigned long long) k3, (unsigned long long) rd.snapshot().keepalive_reads);std::vector<uint32_t> more(2000);for (auto& r : more) r = rng() % N;- check_rows(rd, more, N, "keep-alive, rows afterwards");+ check_rows(rd, more, N, rb, "keep-alive, rows afterwards");rd.set_keepalive(0, 0.5); // offconst uint64_t k4 = rd.snapshot().keepalive_reads;nap(200);@@ -179,16 +182,16 @@ int selftest(const std::string& dir) {{ // the caller's thread does the reads: no worker, so no keep-aliveng::PleReader rd;std::string err;- CHECK(rd.open(path, HEADER, N, 16, 0, err, false), "open: %s", err.c_str());+ CHECK(rd.open(path, HEADER, N, 16, 0, err, false, rb), "open: %s", err.c_str());rd.set_keepalive(20.0, 1.0);std::vector<uint32_t> rows(16);for (auto& r : rows) r = rng() % N;- check_rows(rd, rows, N, "keep-alive, caller thread");+ check_rows(rd, rows, N, rb, "keep-alive, caller thread");std::this_thread::sleep_for(std::chrono::milliseconds(150));CHECK(rd.snapshot().keepalive_reads == 0, "keep-alive without the worker thread");}std::filesystem::remove(path);- std::printf("ple_reader selftest: %s\n", g_fail ? "FAILED" : "OK");+ std::printf("ple_reader selftest (row_bytes=%u): %s\n", rb, g_fail ? "FAILED" : "OK");return g_fail ? 1 : 0;}@@ -282,7 +285,13 @@ int main(int argc, char** argv) {else if (a == "--sync") sync_submit = true;else { std::fprintf(stderr, "usage: ple_reader_test --selftest [--dir D] | --gguf SHARD2 [--rows N] [--tokens F]\n"); return 2; }}- if (self) return selftest(dir);+ if (self) {+ // ng::ROW_BYTES (90, IQ4_NL, production default) and 110 (#296, OrcaRouter's Q5_0 PLE rows) through the+ // same generic row_bytes path -- see the comment on selftest().+ const int r90 = selftest(dir, ng::ROW_BYTES);+ const int r110 = selftest(dir, 110);+ return r90 != 0 ? r90 : r110;+ }if (!gguf.empty()) return real(gguf, rows, tokens, inflight, direct_first, direct_only, sync_submit);std::fprintf(stderr, "nothing to do\n");return 2;