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++
prefill: the CPU share is on by default on CUDA, one GPU, no batch slots, chunks below 1024 tokens (STRATA_PREFILL_CPU_SHARE=0 turns it off); start line; docs
Niko1221162ce64eff9d
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex 7abe3e338..4cc983775 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -1376,7 +1376,7 @@ test images.**Stager threads for a GGUF read in place (0.1.41, #1353):** a native pack read from its GGUF shards in place (UD-Q4_K_XL, a Q8_0 pack) copies each expert with 32 threads and a 128-deep ring when the bytes are page faults on an SSD. If the shards' pages are already in the page cache (a big-RAM box, a warm start) those copies are memory copies and the same profile ran 4-7x slower than the 4-thread default (a 124K-token Q8 prompt: 57 -> 350-410 tok/s with the default). The engine now checks a sample of the experts with `mincore` at the first prompt (Linux) and takes the RAM profile when 90% or more of their pages are resident, saying so in its log; a cold or partly cached GGUF keeps the SSD profile. `STRATA_STAGER_SSD=1` / `0` forces either profile; `STRATA_STAGER_THREADS` still wins. The bytes copied are the same.-## Short prompts: let the CPU share the experts (opt-in, `STRATA_PREFILL_CPU_SHARE`)+## Short prompts: the CPU shares the experts (on by default on one NVIDIA GPU, `STRATA_PREFILL_CPU_SHARE`)A prompt chunk of a few thousand tokens (an agent's tool result, a test's output, a short follow-up) streams every routedexpert that is not in VRAM over PCIe, while the CPU pool that decodes sits idle and RAM already holds those experts.@@ -1384,6 +1384,8 @@ expert that is not in VRAM over PCIe, while the CPU pool that decodes sits idlelong each side takes and gives the CPU the share at which both end together (`STRATA_PREFILL_CPU_SHARE=0.4` fixes ashare). `auto` also checks that sharing pays: it times layers with the share and without it (the first ones alternate until three comparisons are in, then one in 29 runs the other way) and shares only while the layers that share are the faster ones. Where sharing is slower (every share was, on an RX 7900 GRE with a Ryzen 7 5700X3D under ROCm, #1282), the experts stay on the GPU apart from those measuring layers. It is off unless you set it, and then the output is byte-identical to the build without it.+**0.1.41: on by default** on CUDA builds with one GPU and no `--batch` slots, for prompt chunks below 1,024 tokens: unset behaves as `auto` with `STRATA_PREFILL_CPU_SHARE_MAX=1024`, and the engine prints one line at start saying so. Measured (interleaved whole-engine runs, 8 rounds, medians): 512 tokens -28..-34% and 1,000 tokens -20..-26% prompt time on an RTX 3060, a Tesla P100 and an RTX 5070, 8/8 pairs each; mean KL against the share off 0.004 (max 0.025). The answers can differ slightly from 0.1.40.3. **`STRATA_PREFILL_CPU_SHARE=0` turns it off and gives 0.1.40.3's exact bytes.** The layer split, batch slots and AMD (HIP) builds keep it off unless you set the variable; `STRATA_PREFILL_CPU_SHARE_MAX=3072` (the extension to larger chunks) also stays opt-in: it lost 2% at 2,048 tokens on the 5070.+With it on, chunks below 3,072 tokens are staged after their routing (only those can hand the CPU a share) instead ofstreaming every expert from 1,024 tokens on; `STRATA_PREFILL_CPU_SHARE_MAX=1024` keeps the old limit. The CPU takesexperts it reads from RAM as they are: the arena, the page-locked copy of the resident RAM mode, or the mappeddiff --git a/include/strata/prefill/prefill.hpp b/include/strata/prefill/prefill.hppindex 22fba8dbf..c1b0a9118 100644--- a/include/strata/prefill/prefill.hpp+++ b/include/strata/prefill/prefill.hpp@@ -177,7 +177,9 @@ public:/// With STRATA_PREFILL_CPU_SHARE set and `applies` (a pool will be set): the chunks staged after their routing - the/// only ones the share applies to - go up to STRATA_PREFILL_CPU_SHARE_MAX tokens (default 3072) instead of 1024./// Before any `bytes_needed` (the ring and the small-chunk buffers follow the limit); `init` also sets it.- static void arm_cpu_share(bool applies);+ /// `by_default`: this path is one the share was measured on (CUDA, one GPU, no batch slots), so with the variable unset+ /// the share is on for chunks below 1024 tokens (STRATA_PREFILL_CPU_SHARE=0 turns it off).+ static void arm_cpu_share(bool applies, bool by_default = false);private:static uint64_t bytes_needed_impl(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk,diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cppindex 02a04dcb1..66cc48ba5 100644--- a/src/prefill/prefill.cpp+++ b/src/prefill/prefill.cpp@@ -152,15 +152,25 @@ inline int64_t stream_all_min() {// gate at cpu_maybe). x: a fixed x. Unset or 0: every expert on the GPU (the default). RTX 5090 + 9950X3D,// 600-token prompts: UD-Q4_K_XL 1,528-1,548 -> 1,296-1,369 ms (share 0.65), Q2_0 472-491 -> 445-448, IQ2_XS 507 -> 490// (250 tokens 402 -> 368); IQ2_XS on 2 AVX2 workers 512 -> 487 (share 0.49).-inline double cpu_share_env() { // -1: measured+// 0.1.41: ON BY DEFAULT where it was measured (CUDA builds, one GPU, no batch slots): STRATA_PREFILL_CPU_SHARE unset+// behaves as `auto` with STRATA_PREFILL_CPU_SHARE_MAX=1024 (chunks below 1024 tokens: -20..-35% at 512 and 1000 tokens+// on an RTX 3060, a Tesla P100 and an RTX 5070, 8/8 pairs each; mean KL against the share off about 0.004).+// STRATA_PREFILL_CPU_SHARE=0 turns it off: the output is then the 0.1.40.3 bytes. g_share_default is set by+// Prefill::arm_cpu_share(.., true) from the paths that qualify; the layer split, batch slots and HIP stay off.+bool g_share_default = false;+inline double cpu_share_explicit() { // -2: the variable is not set; -1: measuredstatic const double v = [] {const char* e = std::getenv("STRATA_PREFILL_CPU_SHARE");- if (e == nullptr) return 0.0;+ if (e == nullptr) return -2.0;if (std::strcmp(e, "auto") == 0) return -1.0;return std::clamp(std::atof(e), 0.0, 1.0);}();return v;}+inline double cpu_share_env() { // -1: measured+ const double v = cpu_share_explicit();+ return v == -2.0 ? (g_share_default ? -1.0 : 0.0) : v;+}inline bool cpu_share_on() { return cpu_share_env() != 0.0; }// STRATA_PREFILL_CPU_SHARE_MAX (default 3072, at least 1024): with the share on, chunks below it are staged after their// routing - so they can hand the CPU its share - instead of streaming every expert the cards do not hold. The share pays@@ -170,6 +180,8 @@ inline int64_t cpu_share_max() {const char* e = std::getenv("STRATA_PREFILL_CPU_SHARE_MAX");return e ? std::max<int64_t>(1024, (int64_t) std::atoll(e)) : (int64_t) 3072;}();+ static const bool explicit_max = std::getenv("STRATA_PREFILL_CPU_SHARE_MAX") != nullptr;+ if (g_share_default && cpu_share_explicit() == -2.0 && !explicit_max) return 1024; // the default's measured rangereturn v;}// On a layer split every stage may have the pool (set_cpu_pool), and the stages read different chunks at the same time:@@ -1714,7 +1726,17 @@ int64_t Prefill::ring_max_slots() {int64_t Prefill::ring_slots_for(int64_t chunk) { return ring_slots((size_t) chunk); }void Prefill::set_cpu_pool(kernels::cpu::ExpertPool* pool) { cpu_pool_ = pool; }-void Prefill::arm_cpu_share(bool applies) {+void Prefill::arm_cpu_share(bool applies, bool by_default) {+#if !defined(STRATA_USE_HIP)+ if (applies && by_default && cpu_share_explicit() == -2.0 && !g_share_default) {+ g_share_default = true;+ std::fprintf(stderr, "prefill: the CPU share is ON by default for prompt chunks below 1024 tokens (the idle CPU "+ "takes some of the experts the GPU would stream; answers can differ slightly from 0.1.40.3, "+ "mean KL ~0.004). STRATA_PREFILL_CPU_SHARE=0 turns it off.\n");+ }+#else+ (void) by_default;+#endifif (applies && cpu_share_on()) g_stream_min_share = cpu_share_max();}diff --git a/src/program/generate.cpp b/src/program/generate.cppindex 9280fe11f..87ab6456d 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -6105,7 +6105,7 @@ int main(int argc, char** argv) {// the pool is idle while a prompt is read unless batch slots decode between its parts; with// STRATA_PREFILL_CPU_SHARE the staged-chunk limit before the chunk below sizes the loans (bytes_needed reads it)const bool share_pool = o.batch <= 0 && !o.no_pool;- strata::prefill::Prefill::arm_cpu_share(share_pool);+ strata::prefill::Prefill::arm_cpu_share(share_pool, share_pool && stages.empty() && !multi_gpu);void* borrow = nullptr;uint64_t borrow_bytes = 0;int32_t lend_first = -1; // the first slot the prompt path may borrow (its largest chunk)@@ -10941,7 +10941,7 @@ int main(int argc, char** argv) {int64_t pos_start = 0;int64_t spec_pos = 0; // plan v0.3 P6: where the speculative loop starts (0 = not used)strata::prefill::Prefill prefill;- strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool); // before the chunk below sizes the loan+ strata::prefill::Prefill::arm_cpu_share(!multi_gpu && !o.no_pool, !multi_gpu && !o.no_pool && o.batch <= 0); // before the chunk below sizes the loanbool kvg_started = false; // the elastic K/V took this run's cellsdouble prefill_batched_ms = 0;std::FILE* final_r = o.dump_final_r.empty() ? nullptr : std::fopen(o.dump_final_r.c_str(), "wb");