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: --ple-io mmap prompt gather prefetches its rows a window ahead; on Windows the slow-direct probe warns and keeps direct unless STRATA_PLE_AUTO_MMAP=1 (#1984 #1971)
Niko122162497bff9289
diff --git a/src/kernels/ngram.cpp b/src/kernels/ngram.cppindex 90631b4ed..91de37058 100644--- a/src/kernels/ngram.cpp+++ b/src/kernels/ngram.cpp@@ -545,7 +545,39 @@ bool PleTable::gather_batch(const uint32_t* rows, size_t n_tokens, float* out, sreturn true;}wait_prefetches();- for (size_t i = 0; i < n; ++i) read_row(rows[i], out + i * PLE_HEAD_DIM);+ // #1984 #1971: a mapped table that is not in the file cache served this loop as serial demand faults, one random+ // 4 KiB page at a time (16 rows a token, 16 x the chunk's tokens for a prompt), and the first chunk of a prompt has+ // only layer 0 to hide it behind: a cold 27 GB table at ~0.2-1 ms a fault is minutes with no progress mark, which+ // is what the stall watchdog stops. Ask the OS for the next window's pages in one go (PrefetchVirtualMemory /+ // MADV_WILLNEED, a hint that cannot change a value: an unfetched page is faulted by the read) while this window is read.+ constexpr size_t kWin = 4096; // rows a window+ auto hint = [&](size_t a, size_t b) {+ if (impl_->data == nullptr || !g_ple_prefetch) return;+#if defined(_WIN32)+ WIN32_MEMORY_RANGE_ENTRY ranges[kWin];+ ULONG_PTR k = 0;+ for (size_t i = a; i < b; ++i) {+ if (rows[i] >= impl_->n_rows) continue;+ ranges[k].VirtualAddress = (PVOID) (impl_->data + (size_t) rows[i] * impl_->rb);+ ranges[k].NumberOfBytes = impl_->rb;+ ++k;+ }+ if (k > 0) (void) PrefetchVirtualMemory(GetCurrentProcess(), k, ranges, 0);+#else+ for (size_t i = a; i < b; ++i) {+ if (rows[i] >= impl_->n_rows) continue;+ const uintptr_t r0 = (uintptr_t) (impl_->data + (size_t) rows[i] * impl_->rb);+ const uintptr_t p0 = r0 & ~(uintptr_t) 4095;+ (void) madvise((void*) p0, (size_t) (r0 + impl_->rb - p0), MADV_WILLNEED);+ }+#endif+ };+ hint(0, std::min(n, kWin));+ for (size_t w = 0; w < n; w += kWin) {+ if (w + kWin < n) hint(w + kWin, std::min(n, w + 2 * kWin));+ const size_t e = std::min(n, w + kWin);+ for (size_t i = w; i < e; ++i) read_row(rows[i], out + i * PLE_HEAD_DIM);+ }return true;}diff --git a/src/ngram/ple_reader_test.cpp b/src/ngram/ple_reader_test.cppindex 920847083..4663455f7 100644--- a/src/ngram/ple_reader_test.cpp+++ b/src/ngram/ple_reader_test.cpp@@ -189,6 +189,27 @@ void format_round_trip(const std::string& dir, const k::PleFormatInfo& f, uint32f.dequant(raw.data(), f.needs_scale ? 0.75f : 1.0f, ref);CHECK(std::memcmp(tok + (size_t) h * k::PLE_HEAD_DIM, ref, sizeof ref) == 0, "%s: %s: gather head %d differs", f.name, name, h);}+ // a prompt chunk: gather_batch over more rows than one prefetch window (4096), one of them past the table's end+ {+ const size_t nt = 700, nr = nt * 16; // 11200 rows, three windows+ std::vector<uint32_t> br(nr);+ for (size_t i = 0; i < nr; ++i) br[i] = want[i % want.size()];+ if (mode == k::PleIo::Mmap) br[5000] = rows + 7; // out of range (mapped): zeros, as read_row gives+ std::vector<float> bo(nr * k::PLE_HEAD_DIM);+ std::string e2;+ CHECK(t.gather_batch(br.data(), nt, bo.data(), e2), "%s: %s: gather_batch: %s", f.name, name, e2.c_str());+ size_t bad = 0;+ for (size_t i = 0; i < nr && !g_fail; ++i) {+ if (br[i] >= rows) {+ for (int d = 0; d < k::PLE_HEAD_DIM; ++d) bad += bo[i * k::PLE_HEAD_DIM + d] != 0.0f;+ continue;+ }+ expected_row(br[i], f.row_bytes, raw.data());+ f.dequant(raw.data(), f.needs_scale ? 0.75f : 1.0f, ref);+ bad += std::memcmp(bo.data() + i * k::PLE_HEAD_DIM, ref, sizeof ref) != 0;+ }+ CHECK(bad == 0, "%s: %s: gather_batch differs in %zu rows", f.name, name, bad);+ }}std::filesystem::remove(path);}diff --git a/src/program/generate.cpp b/src/program/generate.cppindex e4c8632ab..9af7f9bcf 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -3177,7 +3177,14 @@ int main(int argc, char** argv) {if (rps >= kSlowRowsPerS)std::fprintf(stderr, "strata generate: PLE direct read probe: %.0f rows/s (fine)\n", rps);if (rps > 0 && rps < kSlowRowsPerS) {- if (!o.ple_io_explicit) {+ // #1984 #1971: on Windows the mapped reads stalled prompts (the first chunk waits for 16 serial page faults+ // a token from a cold table with no progress mark), so there the switch is only made when asked for+ // (STRATA_PLE_AUTO_MMAP=1, the 0.1.42 behaviour); otherwise the slow probe warns and direct is kept.+ bool auto_mmap = !o.ple_io_explicit;+#if defined(_WIN32)+ if (const char* am = std::getenv("STRATA_PLE_AUTO_MMAP"); am == nullptr || std::atoi(am) == 0) auto_mmap = false;+#endif+ if (auto_mmap) {std::fprintf(stderr, "strata generate: --ple-io direct measures slow here (%.0f rows/s, about %.0f MB/s of ""random 4 KiB reads): using --ple-io mmap instead (the OS file cache holds the pages; ""--ple-io direct forces the old mode, --ple-io ram keeps the table in RAM)\n",@@ -3193,7 +3200,8 @@ int main(int argc, char** argv) {std::fprintf(stderr, "strata generate: WARNING: --ple-io direct measures slow here (%.0f rows/s, about %.0f ""MB/s of random 4 KiB reads): a prompt can spend minutes reading layer 1 and trip the ""stall watchdog (#1425, #1629). --ple-io mmap was 40-100x faster on such drives; "- "--ple-io ram needs the RAM for the table\n", rps, rps * 4096.0 / 1e6);+ "--ple-io ram needs the RAM for the table%s\n", rps, rps * 4096.0 / 1e6,+ o.ple_io_explicit ? "" : " (kept direct: pass --ple-io mmap or --ple-io ram to change it)");}}}diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex 0b23795d7..777586af9 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -3003,7 +3003,14 @@ int main(int argc, char **argv) try {if (rps >= kSlowRowsPerS)std::fprintf(stderr, "strata generate: PLE direct read probe: %.0f rows/s (fine)\n", rps);if (rps > 0 && rps < kSlowRowsPerS) {- if (!o.ple_io_explicit) {+ // #1984 #1971: on Windows the mapped reads stalled prompts (the first chunk waits for 16 serial page faults+ // a token from a cold table with no progress mark), so there the switch is only made when asked for+ // (STRATA_PLE_AUTO_MMAP=1, the 0.1.42 behaviour); otherwise the slow probe warns and direct is kept.+ bool auto_mmap = !o.ple_io_explicit;+#if defined(_WIN32)+ if (const char* am = std::getenv("STRATA_PLE_AUTO_MMAP"); am == nullptr || std::atoi(am) == 0) auto_mmap = false;+#endif+ if (auto_mmap) {std::fprintf(stderr, "strata generate: --ple-io direct measures slow here (%.0f rows/s, about %.0f MB/s of ""random 4 KiB reads): using --ple-io mmap instead (the OS file cache holds the pages; ""--ple-io direct forces the old mode, --ple-io ram keeps the table in RAM)\n",@@ -3019,7 +3026,8 @@ int main(int argc, char **argv) try {std::fprintf(stderr, "strata generate: WARNING: --ple-io direct measures slow here (%.0f rows/s, about %.0f ""MB/s of random 4 KiB reads): a prompt can spend minutes reading layer 1 and trip the ""stall watchdog (#1425, #1629). --ple-io mmap was 40-100x faster on such drives; "- "--ple-io ram needs the RAM for the table\n", rps, rps * 4096.0 / 1e6);+ "--ple-io ram needs the RAM for the table%s\n", rps, rps * 4096.0 / 1e6,+ o.ple_io_explicit ? "" : " (kept direct: pass --ple-io mmap or --ple-io ram to change it)");}}}