From 02a64abf15dcd8d1e7b029f413e5515f27efcf47 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 7 Oct 2026 02:25:35 +0200 Subject: [PATCH] io prefetch: warn (never force) on an AMD iGPU with the adaptive tier and on the staging variant; docs note with the measured table --- docs/DETAILS.md | 22 ++++++++++++++++++++++ src/program/generate.cpp | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/docs/DETAILS.md b/docs/DETAILS.md index f225d8a6..38f75fbe 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -206,6 +206,28 @@ from the GGUF gave identical tokens and logits. An expert read from the GGUF is engine fetches a layer's missing experts on 8 threads (`STRATA_FETCH_THREADS`) with one batched page request (Windows `PrefetchVirtualMemory`). With an `experts.bin` in the pack, nothing changes. Setup does not use this yet. +**Linux file-tier I/O path (opt in, `STRATA_IO_PREFETCH=1`; 0.1.40.2):** the mapped file tier reads experts through +page faults. With this on, the layer's uncached experts and the router-predicted ones of the next layer (`STRATA_LOOKAHEAD_K`, +`STRATA_IO_PREFETCH_DEPTH`, default 2 when on) are read by I/O threads (`STRATA_IO_PF_THREADS`, default 8) with whole-blob +`pread`s into the page cache, and the CPU kernels read the mapping as before. The bytes are the same, so the output is the +same (greedy IQ3_XXS and Q2_0 hashes identical, prefetch off vs on). `STRATA_IO_PF_STAGE=1` instead stages every uncached +expert in a buffer and makes the layer wait for them; `STRATA_IO_PF_AHEAD=0` keeps only the demand reads. The per-request +log line "file tier I/O" shows what the OS read from the drive (/proc/self/io, major faults) against the engine's expert +reads; `STRATA_IO_STATS=1` (or prefetch on) adds the page-cache hit / miss split (mincore) and the read-ahead used / unused counts. +Measured (interleaved A/B, 10 pairs, 200-token greedy medians, page cache dropped before each run, memory limit by cgroup): + +| box, lane | default (fill) | `STRATA_IO_PF_STAGE=1` | +|---|---|---| +| RTX 3060, 32 GB, IQ3_XXS | -3.4% | **+25.7%** | +| RTX 3060, 16 GB, IQ3_XXS | -1.8% | -32.6% | +| Radeon 780M iGPU, 16 GB, Q2_0 (adaptive tier off) | -0.7% (story +3.8%, code +4.1%) | -19% | + +With the experts warm in the page cache (46 GB on the 3060, 60 GB on the iGPU box) the file tier already runs at the +resident speed, so there is nothing to win; the gap is the cold start and the low-RAM lanes. So it is off by default, and +the staging variant is worth trying only on a 32 GB-class box. **iGPU caveat:** on a Radeon 780M, prefetch together with the +adaptive tier (`--adapt-every`, on by default) under memory pressure reset the GPU in about 7 of 9 runs (the engine +prints a warning and runs as asked); with `--adapt-every 100000` there were no resets in ~40 runs. The cause is not found. + **A RAM budget (engine 0.1.31, `--resident-budget-gib N`):** the resident variant for a model whose experts do not all fit: the N GiB of experts the GPU cache does not hold that the expert profile ranks hottest are copied into RAM at start (locked; page-locked when the driver allows the whole budget), and the rest are read from the files. diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 9e9e3711..04b30939 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -3758,6 +3758,23 @@ int main(int argc, char** argv) { else std::fprintf(stderr, "strata generate: STRATA_IO_PREFETCH=1 is not available here (Linux mapped file tier " "only, not with unbuffered reads); the file tier reads as before\n"); + if (src.io_prefetch()) { // recommend, never force: the engine runs as asked + const char* st = std::getenv("STRATA_IO_PF_STAGE"); + if (st != nullptr && std::atoi(st) != 0) + std::fprintf(stderr, "strata generate: note: STRATA_IO_PF_STAGE=1 (staging) measured faster only on a 32 GB-class " + "box (+25%% on an RTX 3060, 32 GB); it was slower at 16 GB and on an iGPU (docs/DETAILS.md, file tier I/O)\n"); +#if defined(STRATA_USE_HIP) + int igpu_dev = 0; + cudaDeviceProp igpu_p{}; + if (cudaGetDevice(&igpu_dev) == cudaSuccess && cudaGetDeviceProperties(&igpu_p, igpu_dev) == cudaSuccess && + igpu_p.integrated != 0 && o.adapt_every > 0 && o.adapt_swaps > 0) + std::fprintf(stderr, "strata generate: WARNING: STRATA_IO_PREFETCH=1 with the adaptive tier on an AMD iGPU (%s): " + "GPU resets were seen with this combination under memory pressure (Radeon 780M); " + "--adapt-every 100000 avoided them. Continuing as asked.\n", igpu_p.gcnArchName); + else + (void) cudaGetLastError(); +#endif + } } else if (const char* sv = std::getenv("STRATA_IO_STATS"); sv != nullptr && std::atoi(sv) != 0) { src.set_io_stats(true); }