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-io direct on a rotational disk: warn at start, setup keeps the table in RAM, the stall report counts disk waits (#605)
Niko1221935ac87a54f1
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex dffa78e77..ce147220d 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -876,6 +876,7 @@ the document, +0.4% on the chat. Details: `bench/results/2026-09-27-esp/`.| Pictures are slow (10-30 s) | The encoder runs on the CPU: run setup again with `--vision gpu` (needs ~1.4 GB of VRAM). || A request never finishes: "reading the prompt", GPU "100%" at low power | The GPU ran out of VRAM (engines before 0.1.9 could end with ~30 MiB free at large contexts). Run `START-HERE.bat` once to get engine 0.1.9 or newer; the log then says `... MiB of VRAM free with everything loaded` (a few hundred) and names the `--vram-reserve-mib` to add if it is low. || Generation stops mid-answer, GPU "100%", one CPU core busy | Fixed in engine 0.1.12 (issue #29, a race in the CPU expert pool on big-VRAM cards). Since then a request that stops moving ends with an error instead of hanging (after 2 minutes; 1 minute from 0.1.13): the log says `no progress for ... s ... (issue #29)` with where it stopped, and the next request starts the engine again. If you see that line, please open an issue with it. Engine 0.1.13 adds a stall report under it (what every expert-pool thread and the GPU handshake were doing, memory and page faults) and, on Windows, a `strata-stall-<pid>.dmp` file with every thread's stack: attach both. (`STRATA_WATCHDOG_S` sets the time in seconds; 0 turns it off.) Engine 0.1.14 fixes the stall those reports found (issue #31: with the IQ packs the host could wait forever inside the NVIDIA driver while copying experts in a verify window; the experts are now copied by a GPU kernel, `--pcie-mode dma` restores the old way). |+| `no progress for 60 s ... reading the prompt` on Linux, and the stall report says `threads waiting on the disk (state D): 16 ...` | The engine waits for the drive, not a deadlock: the n-gram table is read at random (`--ple-io direct`), which a rotational disk cannot keep up with (#605). The engine warns at start when the table is on one; `--ple-io ram` (Linux, needs RAM for the table) or the model on an SSD fixes it. Setup adds `--ple-io ram` itself on a rotational disk when the RAM holds the table (0.1.39). || `the engine said nothing for ... s during the request` or `... did not finish the request after it was stopped (STOP)` | Issue #481: the engine and the server lost step (the engine waits for its next command, the server for the request's end; GPU at 0 %, nothing in the log). The server ends the engine after 300 s without a line from it during a request (while a prompt is read: each chunk may take three times the previous one's time, the first one up to its tokens at 50 tok/s more), the request ends with an error and the next request starts the engine again. `"engine_silence_s": 600` in `strata-<model>.json` sets the time (0 = wait forever, as before). If you see it, please add the end of the engine log to #481. || `out of memory: cudaFuncSetAttribute` in the log (IQ3_XXS, long prompt) | Fixed in engine 0.1.15: CUDA loaded a kernel's code when it was first needed, and mid-prompt there was no VRAM left for it. Run `START-HERE.bat` (Windows) or `./setup.sh` (Linux) once to update. || Anything else | The engine log is `strata-<model>.log` in this folder. |@@ -891,7 +892,8 @@ the document, +0.4% on the chat. Details: `bench/results/2026-09-27-esp/`.the conversation while you chat).- **RAM:** all 24,576 experts, pinned. The CPU computes the experts that are not on the GPU **in place**, at the same timeas the GPU works on the cached ones (AVX-512 / AVX2 kernels, ggml's for the i-quants).-- **SSD:** the 28.8 GB n-gram table, read a few rows per token through the OS cache.+- **SSD:** the 28.8 GB n-gram table, a few rows per token, read unbuffered past the OS cache (`--ple-io direct`, the+ default, made for SSDs; on a rotational disk `--ple-io ram` keeps the table in RAM, #605).- **Speculation:** the model's own MTP layer drafts up to 3 tokens; one pass over all 48 layers checks them. 2.4-3.2tokens per pass on average. When the reply repeats the context (code edits, quoted text), **prompt lookup** (engine0.1.7) drafts up to 5 tokens from the earlier copy, but only where its measured acceptance and cost say it pays:diff --git a/setup.py b/setup.pyindex 69624a11b..d4651fbf3 100644--- a/setup.py+++ b/setup.py@@ -2479,6 +2479,22 @@ def is_wsl() -> bool:return sys.platform.startswith("linux") and "microsoft" in platform.uname().release.lower()+def rotational_disk(path) -> str | None:+ """#605 (Linux): the disk's name when `path` is on a rotational disk (sysfs queue/rotational), else None."""+ if WIN:+ return None+ try:+ st = os.stat(path)+ p = Path(f"/sys/dev/block/{os.major(st.st_dev)}:{os.minor(st.st_dev)}").resolve()+ for q in (p, p.parent): # a partition has its disk's queue+ f = q / "queue" / "rotational"+ if f.exists():+ return q.name if f.read_text().strip() == "1" else None+ except (OSError, ValueError, AttributeError):+ pass+ return None++def hardware_key(cfg: dict) -> str:"""What a calibration is valid for: this GPU, CPU and RAM, and the model with its context and images setting(the context's KV cache and the image encoder take VRAM from the expert cache)."""@@ -3562,6 +3578,19 @@ def main() -> int:"the OS file cache (run setup again after the next engine update)")if low_ram: # the experts from the pack's experts.bin: the ones the GPU does not hold copied into RAM, or mappedargs += ["--resident-experts" if resident else "--mmap-experts"]+ disk = None if is_wsl() else rotational_disk(ple) # #605 (WSL's virtual disk says rotational)+ if disk:+ tensor = next((t for t in GGUFFile(ple).tensors if t.name == "per_layer_token_embd.weight"), None)+ size = getattr(tensor, "expected_bytes", lambda: None)()+ table_gb = size / 1e9 if size else 28.8+ if ram >= MODELS[model]["ram_gb"] + table_gb + 4:+ args += ["--ple-io", "ram"]+ ok(f"the model is on a rotational disk ({disk}): its {table_gb:.0f} GB n-gram table is kept in RAM "+ "(--ple-io ram) - read from the disk at random, it can stall prompts for minutes (#605)")+ else:+ warn(f"the model is on a rotational disk ({disk}): its n-gram table is read from it at random, which can "+ f"stall prompts for minutes (#605). An SSD is recommended; with ~{table_gb:.0f} GB more RAM, "+ "--ple-io ram in the config's args keeps the table in RAM instead")# KV streaming: from 64K up the whole KV cache lives in RAM and only the part the attention reads (32K positions# per layer) stays in VRAM; the VRAM it frees holds more experts (+6% at 128K, +23% at 262K with Q2_0). It# costs ~13.7 KB of RAM per context token with 8-bit KV (1.7 GB at 128K), 7.5 KB with 4-bit, so only when it fits.diff --git a/src/program/generate.cpp b/src/program/generate.cppindex ac250f79a..593825410 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -70,6 +70,8 @@#else#include <unistd.h>#include <cerrno>+#include <sys/stat.h>+#include <sys/sysmacros.h>#endif#include <cuda_runtime.h>@@ -805,6 +807,55 @@ std::string stage_text() {return s;}+#if !defined(_WIN32)+// #605: whether `path` is on a rotational disk (1), not (0) or unknown (-1), from sysfs; `dev` is the disk's name+int on_rotational_disk(const std::string& path, std::string& dev) {+ struct stat st{};+ if (::stat(path.c_str(), &st) != 0) return -1;+ char sys[64];+ std::snprintf(sys, sizeof sys, "/sys/dev/block/%u:%u", (unsigned) major(st.st_dev), (unsigned) minor(st.st_dev));+ std::error_code ec;+ std::filesystem::path p = std::filesystem::canonical(sys, ec);+ for (int up = 0; !ec && up < 2; ++up, p = p.parent_path()) { // a partition has its disk's queue+ std::ifstream q(p / "queue" / "rotational");+ int r = -1;+ if (q >> r) {+ dev = p.filename().string();+ return r;+ }+ }+ return -1;+}++// #605: the engine's threads in uninterruptible sleep (state D - almost always waiting for the disk), and where+// (wchan): 16 threads in blk_io_schedule is a disk that cannot keep up, not a deadlock in the engine+void disk_wait_threads(std::FILE* f) {+ std::map<std::string, int> where;+ int waiting = 0, threads = 0;+ std::error_code ec;+ for (const auto& e : std::filesystem::directory_iterator("/proc/self/task", ec)) {+ ++threads;+ std::ifstream st(e.path() / "stat");+ std::string line;+ std::getline(st, line);+ const size_t rp = line.rfind(')');+ if (rp == std::string::npos || rp + 2 >= line.size() || line[rp + 2] != 'D') continue;+ ++waiting;+ std::ifstream w(e.path() / "wchan");+ std::string wc;+ std::getline(w, wc);+ ++where[wc.empty() || wc == "0" ? "?" : wc];+ }+ if (threads == 0) return;+ std::string list;+ for (const auto& [name, n] : where) list += (list.empty() ? " (" : ", ") + name + " x" + std::to_string(n);+ if (!list.empty()) list += ")";+ std::fprintf(f, " threads waiting on the disk (state D): %d of %d%s%s\n", waiting, threads, list.c_str(),+ waiting > 0 ? " - the engine is waiting for the drive: a rotational or failing disk with --ple-io "+ "direct (#605: --ple-io ram), or a drive too slow for the reads asked of it" : "");+}+#endif+void stall_report(std::FILE* f, uint64_t layers_during) {strata::core::Progress& p = strata::core::progress();std::fprintf(f, "strata serve: stall report (engine %s): stage \"%s\" for %lld s; %llu layers served since the "@@ -818,6 +869,9 @@ void stall_report(std::FILE* f, uint64_t layers_during) {}if (auto fn = strata::core::diag_pool_fn().load()) fn(f);if (auto fn = strata::core::diag_verify_fn().load()) fn(f);+#if !defined(_WIN32)+ disk_wait_threads(f);+#endifconst MemSample m = mem_sample();std::fprintf(f, " memory: %llu MiB resident, %llu MiB %s, %llu MiB RAM available; %llu %s\n", m.rss_mib,m.commit_mib,@@ -2172,6 +2226,18 @@ int main(int argc, char** argv) {std::fprintf(stderr, "strata generate: %s\n", err.c_str());return 1;}+#if !defined(_WIN32)+ if (pio.mode == strata::kernels::PleIo::Direct) {+ // #605: --ple-io direct's random reads (up to --ple-inflight at once) are for SSDs; a rotational disk+ // can take longer than the stall watchdog's 60 s for one prompt chunk's rows. Recommended, not forced.+ std::string dev;+ if (!under_wddm() && on_rotational_disk(o.ple_gguf, dev) == 1) // (WSL's virtual disk says rotational)+ std::fprintf(stderr, "strata generate: WARNING: the n-gram table (%s) is on a rotational disk (%s): "+ "--ple-io direct reads it at random and can stall a prompt for minutes (#605). "+ "--ple-io ram (it then needs RAM for the table) or the model on an SSD is "+ "recommended\n", o.ple_gguf.c_str(), dev.c_str());+ }+#endifif (pio.lock)std::fprintf(stderr, "strata generate: PLE table %s (--ple-io ram) in %.1f s\n",ple_table.locked() ? "locked in RAM" : "loaded (not locked)",diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.pyindex c7736b34a..8f1fe8175 100644--- a/tools/test_setup_choices.py+++ b/tools/test_setup_choices.py@@ -267,6 +267,40 @@ class HipVision(unittest.TestCase):self.assertNotIn("vision_src", meta)+class RotationalDisk(unittest.TestCase):+ """#605: a model on a rotational disk gets --ple-io ram when the n-gram table fits the RAM, else a warning."""++ def install(self, ram, disk):+ from test_setup_golden import PROFILES, install+ _, found = PROFILES["64GB-1x32GB"]+ return install(ram, found, ["--family", "qwen", "--model", "Q2_0", "--no-start"],+ extra=[mock.patch.object(setup, "rotational_disk", lambda p: disk)])++ def test_fits(self):+ code, out, cfg, _ = self.install(127.8, "sdb")+ self.assertEqual(code, 0, out)+ a = cfg["args"]+ self.assertEqual(a[a.index("--ple-io") + 1], "ram")+ self.assertIn("rotational disk (sdb)", out)++ def test_does_not_fit(self):+ code, out, cfg, _ = self.install(63.7, "sdb")+ self.assertEqual(code, 0, out)+ self.assertNotIn("--ple-io", cfg["args"])+ self.assertIn("An SSD is recommended", out)++ def test_ssd(self):+ code, out, cfg, _ = self.install(127.8, None)+ self.assertNotIn("--ple-io", cfg["args"])+ self.assertNotIn("rotational", out)++ def test_sysfs(self):+ if not sys.platform.startswith("linux"):+ self.assertIsNone(setup.rotational_disk(__file__)) # Windows: never+ return+ self.assertIn(setup.rotational_disk(__file__), (None,) + tuple(os.listdir("/sys/block")))++class VramReserve(unittest.TestCase):"""#493: --vram-reserve-mib N - VRAM the engine leaves free for other programs - goes into the config only whengiven (the default config is tools/test_setup_golden.py's, unchanged), at setup and on a start."""diff --git a/tools/test_setup_golden.py b/tools/test_setup_golden.pyindex 054c1c14e..136b156da 100644--- a/tools/test_setup_golden.py+++ b/tools/test_setup_golden.py@@ -102,6 +102,7 @@ def install(ram, found, argv, answers=None, extra=(), avx512=False, configs=()):mock.patch.object(setup, "cpu_info", lambda: ("Test CPU", True, avx512)),mock.patch.object(setup, "page_file_gb", lambda: 16.0),mock.patch.object(setup, "is_wsl", lambda: False),+ mock.patch.object(setup, "rotational_disk", lambda p: None), # #605: the test PC's own diskmock.patch.object(setup, "free_gb", lambda p: 900.0),mock.patch.object(setup, "pip_install", lambda *a, **k: None),mock.patch.object(setup, "get_llama_cpp", lambda: t / "llama.cpp"),