From 1493781e91d6ed1cc6172bf06bbd40ccc7256a8a Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 11:15:18 +0100 Subject: [PATCH 1/5] gfx1151 on Windows: the matrix-core prompt set by default, and the prompt keeps its own buffers Two prompt defaults for Strix Halo (gfx1151) on Windows, measured on the strix box with the 0.1.52 engine and Qwen3.8-Flash-Next IQ3_S (ids prompts of 4,095 / 8,190 / 11,999 tokens, interleaved pairs, one engine at a time): 1. The matrix-core prompt set (HIP_WMMA, PF_GEMM, PA_FAST, HC_UPMIX, PF_FUSED) is on by default, as it has been on the Radeon 780M since 021-minipc: 4K 688.8 -> 1,192.8 tok/s, 8K 787.0 -> 1,283.5, 12K 750.4 -> 1,256.5 (x1.63 to x1.72). SELECT_WMMA stays out (x1.003 at 8K on the f-024-strix-pp branch); PF_F16 was measured and adds nothing on this pack, so the bit-changing surface is the five switches the branch gated. First-token KL against the 0.2.7 default 0.00210 / 0.00039 / 0.00214 at 4K / 8K / 12K, top-1 the same, noise floor 0.00000 (the accepted HC_Q8 bar is 0.0228 mean). 2. The prompt path keeps its own buffers instead of lending expert-cache slots. A lent slot's expert is re-read from the host arena during every chunk at ~0.5 GB/s here (the arena is unregistered in UMA mode): 823 slots = 2.75 s of a 3.3 s 4K prompt in the issuer thread. With own buffers every expert stays resident (24,576 slots, 'experts streamed 0') and the prompt is 8.5% (4K) to 8.9% (8K) faster. STRATA_PREFILL_BORROW=1 keeps 0.2.7's lending, STRATA_GFX1151_DEFAULTS=0 the whole block; --prefill auto keeps the 8,192-token chunk the gfx1151 rule chose instead of falling back to 2,048. arch_defaults_test: the Windows gfx1151 expectations and the new opt-outs. --- src/core/arch_defaults.cpp | 19 +++++++++ src/core/arch_defaults_test.cpp | 72 +++++++++++++++++++++++++++++++-- src/program/generate.cpp | 23 ++++++++++- 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp index 7f2a89fd..9d6a447b 100644 --- a/src/core/arch_defaults.cpp +++ b/src/core/arch_defaults.cpp @@ -102,6 +102,13 @@ bool igpu_prompt_set_enabled(const char* gcn_arch, bool windows) { const char* e = std::getenv("STRATA_IGPU_PROMPT_SET"); if (e != nullptr && e[0] == '1') return true; if (e != nullptr && e[0] == '0') return false; + // 0.2.8: Strix Halo (gfx1151) gets the matrix-core prompt set on Windows by default. Measured on the strix box + // (Qwen3.8-Flash-Next IQ3_S, engine 0.1.52, ids prompts of 4,095 / 8,191 tokens, interleaved pairs, one engine at a + // time): 4K 690 -> 1,090 and 8K 785 -> 1,183 on the f-024-strix-pp branch (0.2.3 engine, the same switches as + // environment variables), i.e. x1.58 / x1.51; the first-token KL against the accepted HC_Q8 bar was 0.0088 mean + // (0.0228 allowed), top-1 the same on every prompt. Linux gfx1151 stays opt-in until it is measured there; gfx1103 + // keeps its own rule below. + if (windows && strata::kernels::gfx_arch_is(gcn_arch, "gfx1151")) return true; return kIgpuPromptSetDefaultOn && !windows && strata::kernels::gfx_arch_is(gcn_arch, "gfx1103"); } @@ -135,6 +142,18 @@ std::vector> igpu_default_env(const char* gc {"STRATA_SELECT_WMMA", "1"}, // the block scorer on matrix cores {"STRATA_HC_UPMIX", "1"}, // the hyper-connection up projection with its epilogue }; + // gfx1151 (Strix Halo) on Windows: SELECT_WMMA measured x1.003 at 8K on the branch and is left out, and PF_FUSED (the + // fused int8 gate/up prompt experts, #136) measured x1.12 there and joins the set. The 780M and the 890M keep the + // table above exactly as measured on them. + if (win && strata::kernels::gfx_arch_is(gcn_arch, "gfx1151")) { + t = { + {"STRATA_HIP_WMMA", "1"}, + {"STRATA_PF_GEMM", "1"}, + {"STRATA_PA_FAST", "1"}, + {"STRATA_HC_UPMIX", "1"}, + {"STRATA_PF_FUSED", "1"}, + }; + } return t; } diff --git a/src/core/arch_defaults_test.cpp b/src/core/arch_defaults_test.cpp index e13e76b1..7a4d9cb7 100644 --- a/src/core/arch_defaults_test.cpp +++ b/src/core/arch_defaults_test.cpp @@ -182,7 +182,10 @@ int main() { for (const Mock& m : mocks) { const bool want = m.expect_on && std::string(m.gcn).rfind("gfx1103", 0) == 0; #if defined(_WIN32) - CHECK(igpu_default_env(m.gcn, m.integrated).empty()); + // 0.2.8: Strix Halo (gfx1151, integrated) gets the matrix-core prompt set on Windows; the 780M and the 890M are + // not measured there and stay off + const bool win_on = m.expect_on && m.integrated && std::string(m.gcn).rfind("gfx1151", 0) == 0; + CHECK(igpu_default_env(m.gcn, m.integrated).size() == (win_on ? 5u : 0u)); #else CHECK(igpu_default_env(m.gcn, m.integrated).size() == (want ? 5u : 0u)); #endif @@ -213,13 +216,20 @@ int main() { CHECK(t.empty() == !m.expect_on); if (m.expect_on) { CHECK(t.size() == 5); - const char* want[] = {"STRATA_HIP_WMMA", "STRATA_PF_GEMM", "STRATA_PA_FAST", "STRATA_SELECT_WMMA", "STRATA_HC_UPMIX"}; + bool halo_win = false; +#if defined(_WIN32) + halo_win = std::string(m.gcn).rfind("gfx1151", 0) == 0; +#endif + std::vector want = {"STRATA_HIP_WMMA", "STRATA_PF_GEMM", "STRATA_PA_FAST", "STRATA_HC_UPMIX"}; + want.push_back(halo_win ? "STRATA_PF_FUSED" : "STRATA_SELECT_WMMA"); for (const char* w : want) { bool found = false; for (const auto& kv : t) found = found || (kv.first == w && kv.second == "1"); CHECK(found); } - for (const auto& kv : t) CHECK(kv.first != "STRATA_PF_FUSED" && kv.first != "STRATA_HC_Q8" && kv.first != "STRATA_PF_HCDOWN"); + for (const auto& kv : t) CHECK(kv.first != "STRATA_HC_Q8" && kv.first != "STRATA_PF_HCDOWN"); + if (halo_win) { for (const auto& kv : t) CHECK(kv.first != "STRATA_SELECT_WMMA"); } + else { for (const auto& kv : t) CHECK(kv.first != "STRATA_PF_FUSED"); } } if (!m.expect_on) std::printf(" (not on) %s\n", m.name); } @@ -260,6 +270,62 @@ int main() { CHECK(std::getenv("STRATA_HC_UPMIX") != nullptr && std::string(std::getenv("STRATA_HC_UPMIX")) == "0"); for (const char* k : five) unset(k); unset("STRATA_IGPU_PROMPT_SET"); +#if defined(_WIN32) + // 0.2.8: Strix Halo (gfx1151) on Windows gets the matrix-core prompt set with nothing asked. Measured on the strix + // box (Qwen3.8-Flash-Next IQ3_S, engine 0.1.52, 4K / 8K ids prompts): 4K 690 -> 1,090, 8K 785 -> 1,183 (x1.58 / + // x1.51), KL 0.0088 mean against the HC_Q8 bar of 0.0228. The set is HIP_WMMA + PF_GEMM + PA_FAST + HC_UPMIX + + // PF_FUSED; SELECT_WMMA (x1.003) is left out, and the 780M / 890M keep exactly what was measured on them. + unset("STRATA_IGPU_DEFAULTS"); + unset("STRATA_GFX1151_DEFAULTS"); // the 19-switch gfx1151 table is live in this block (the checks above turned it off) + CHECK(igpu_prompt_set_enabled("gfx1151", true)); + CHECK(igpu_prompt_set_enabled("gfx1151:sramecc-:xnack-", true)); + CHECK(!igpu_prompt_set_enabled("gfx1151", false)); // Linux gfx1151: still opt-in + CHECK(!igpu_prompt_set_enabled("gfx1150", true)); + CHECK(!igpu_prompt_set_enabled("gfx1103", true)); + { + const auto t = igpu_default_env("gfx1151", true); + CHECK(t.size() == 5); + auto has = [&t](const char* k) { + for (const auto& kv : t) if (kv.first == k) return kv.second == "1"; + return false; + }; + CHECK(has("STRATA_HIP_WMMA") && has("STRATA_PF_GEMM") && has("STRATA_PA_FAST") && has("STRATA_HC_UPMIX") && + has("STRATA_PF_FUSED")); + CHECK(!has("STRATA_SELECT_WMMA")); + CHECK(igpu_default_env("gfx1151", false).empty()); // a gfx1151 reported as a discrete card + CHECK(igpu_default_env("gfx1150", true).empty()); // 890M: unchanged + CHECK(igpu_default_env("gfx1103", true).empty()); // 780M on Windows: unchanged + } + { + const char* halo[] = {"STRATA_HIP_WMMA", "STRATA_PF_GEMM", "STRATA_PA_FAST", "STRATA_HC_UPMIX", "STRATA_PF_FUSED"}; + for (const char* k : halo) unset(k); + unset("STRATA_SELECT_WMMA"); + const auto set = apply_arch_defaults("gfx1151", true); + for (const char* k : halo) { + bool in = false; + for (const auto& n : set) in = in || n == k; + CHECK(in); + CHECK(std::getenv(k) != nullptr && std::string(std::getenv(k)) == "1"); + } + for (const auto& n : set) CHECK(n != "STRATA_SELECT_WMMA"); + // a switch the user set (even to 0) is kept, and the whole set turns off with either switch + for (const char* k : halo) unset(k); + put("STRATA_HC_UPMIX", "0"); + const auto set2 = apply_arch_defaults("gfx1151", true); + CHECK(std::getenv("STRATA_HC_UPMIX") != nullptr && std::string(std::getenv("STRATA_HC_UPMIX")) == "0"); + for (const auto& n : set2) CHECK(n != "STRATA_HC_UPMIX"); + CHECK(std::getenv("STRATA_PF_FUSED") != nullptr); + unset("STRATA_HC_UPMIX"); + for (const char* k : halo) unset(k); + put("STRATA_IGPU_PROMPT_SET", "0"); + CHECK(igpu_default_env("gfx1151", true).empty()); + unset("STRATA_IGPU_PROMPT_SET"); + put("STRATA_IGPU_DEFAULTS", "0"); + CHECK(igpu_default_env("gfx1151", true).empty()); + unset("STRATA_IGPU_DEFAULTS"); + put("STRATA_GFX1151_DEFAULTS", "0"); // back to the state this block found (the 026 checks below rely on it) + } +#endif // 021-minipc: UMA mode is NOT a default (slower, resets not fixed): off with nothing asked; the logic below runs with on=true CHECK(!kIgpuUmaArenaDefaultOn); CHECK(!igpu_uma_arena_default("gfx1103", true, false)); diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 824bd19d..7bc782a7 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -706,6 +706,10 @@ struct Options { int64_t prefill_auto_cap = 0; /// a bare `--prefill auto` (no ":N", no STRATA_PREFILL_AUTO_MAX): the gfx12 Linux rule below may raise its ceiling bool prefill_auto_bare = false; + /// 0.2.8 (Strix Halo on Windows): the prompt path keeps its own buffers by default (no lending), so `--prefill auto` + /// must not fall back to 2048 ("reserved buffers, keep them small") - the gfx1151 rule above has already chosen a + /// chunk that fits this box's carve-out. + bool prefill_own_keep_chunk = false; bool prefill_gfx12_16k = false; ///< the gfx12 default raised the auto chunk ceiling to 16384 (a layer split takes 8192 back, 0.1.44) /// --prefill-pipe (opt-in): a layer split's prompt chunks sized for its pipeline (Prefill::pipeline_chunk): 0 off, /// 1 today's chunk count evened out, a number > 1 the rig's b/a in tokens (setup's --calibrate measures it). @@ -3372,6 +3376,21 @@ int main(int argc, char** argv) { o.prefill_chunk = std::max(o.prefill_chunk, 8192); } } + // 0.2.8: the Strix Halo prompt path keeps its own buffers instead of lending cache slots. A lent slot's expert + // is re-read from the host arena during every chunk, and on this box that copy runs at ~0.5 GB/s (the arena is + // unregistered in UMA mode): measured on strix, engine 0.1.52, IQ3_S, 2026-10-27 - 823 slots = 2.75 s of a + // 3.3 s 4K prompt, 1,408 slots = 5.5 s of a 6.1 s 8K prompt. Without lending every expert stays in the cache + // (24,576 slots) and the prompt reads VRAM only; the buffers' VRAM is reserved up front instead (the cache + // still fits: 46.84 GiB of experts against a 63.6 GB carve-out). STRATA_PREFILL_BORROW=1 keeps 0.2.7's + // lending, STRATA_GFX1151_DEFAULTS=0 turns the whole gfx1151 block off. + if (win_host && all_igpu && std::strncmp(ad.gcnArchName, "gfx1151", 7) == 0) { + const char* pb = std::getenv("STRATA_PREFILL_BORROW"); + const char* pd = std::getenv("STRATA_GFX1151_DEFAULTS"); + if (!(pb != nullptr && pb[0] == '1') && !(pd != nullptr && pd[0] == '0')) { + o.no_prefill_borrow = true; + o.prefill_own_keep_chunk = true; + } + } } else (void) cudaGetLastError(); } #endif @@ -3703,7 +3722,9 @@ int main(int argc, char** argv) { #endif if (o.prefill_auto && (o.no_prefill_borrow || o.expert_profile.empty())) { o.prefill_auto = false; // nothing to lend from: the buffers are reserved for the session, so keep them small - o.prefill_chunk = 2048; + // 0.2.8 Strix Halo: the gfx1151 rule above chose a chunk that fits this box; the "keep them small" 2048 would throw + // the whole 8K prompt back into 4 chunks (measured: 2048 against 8192 costs ~26% of an 8K prompt on this box). + o.prefill_chunk = o.prefill_own_keep_chunk ? o.prefill_chunk : 2048; } if (!have_tokens && o.serve) { // plan v0.3 P8: requests bring their own tokens o.tokens = {248045}; From 20bba22af7e94b3a3648b53b7380e8e0b017e843 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 11:15:18 +0100 Subject: [PATCH 2/5] gfx1151 on Windows: a 16,384-token prompt chunk, and the docs for the two new prompt defaults - src/program/generate.cpp: the gfx1151 Windows prompt chunk goes from 8,192 to 16,384. The prompt reads every expert once per chunk, so a bigger chunk reads them fewer times: 32K 1,250.6-1,260.0 -> 1,286.3-1,307.9 tok/s, 64K 1,188.4-1,191.0 -> 1,234.3-1,238.2 (+3.0% / +3.9%, interleaved pairs); at 4K and 8K the chunk is the prompt and nothing changes. The buffers' reserve grows to ~10.9 GiB and the cache keeps all 24,576 slots (84.7 GiB free at a 64K context). STRATA_GFX1151_CHUNK=0 keeps 6,144; auto:32768 is another ~2% at 64K and stays opt-in. - docs/STRIX_HALO_WINDOWS.md section 4: what 0.2.8 turns on for gfx1151 on Windows (the five-switch matrix-core set and the prompt keeping its own buffers), the measured prompt table with the opt-outs, the chunk. - docs/STRIX_HALO.md section 5: the Windows gfx1151 exception to 'the set is opt-in on an integrated Radeon'. Numbers: Qwen3.8-Flash-Next IQ3_S, engine 0.1.52, prompts 4K to 64K, x1.59 to x1.72 over 0.2.7; first-token KL 0.0014 mean (bar 0.0228); the own-buffer path is bit-exact (KL 0.00000 against the lending engine with the same switches). --- docs/STRIX_HALO.md | 8 ++++++++ docs/STRIX_HALO_WINDOWS.md | 19 +++++++++++++++++++ src/program/generate.cpp | 7 ++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index b113096a..ad8ffa51 100644 --- a/docs/STRIX_HALO.md +++ b/docs/STRIX_HALO.md @@ -214,6 +214,14 @@ export STRATA_PREFILL_STREAM_MIN=128 # prompt reads of 128-1,023 tokens on the integrated Radeon: `STRATA_IGPU_PROMPT_SET=1` ([AMD_HIP.md](AMD_HIP.md), "Integrated GPUs"), measured on a Radeon 780M only, where it is the default. `STRATA_PF_FUSED`, `STRATA_PF_SWITCH_MIN_T` and `STRATA_PREFILL_STREAM_MIN` stay opt-in as well. +**On Windows the Strix Halo is the exception** (engine 0.1.52 and later): `gfx1151` takes the matrix-core set by itself - +`STRATA_HIP_WMMA`, `STRATA_PF_GEMM`, `STRATA_PA_FAST`, `STRATA_HC_UPMIX` and `STRATA_PF_FUSED`, without `STRATA_SELECT_WMMA` +(x1.003 there) - and the prompt keeps its own buffers instead of lending expert-cache slots. Measured on Qwen3.8-Flash-Next +IQ3_S, prompts of 4K to 64K: x1.59 to x1.72 over 0.2.7. The whole block is off with `STRATA_GFX1151_DEFAULTS=0`; the set with +`STRATA_IGPU_PROMPT_SET=0`, the buffers with `STRATA_PREFILL_BORROW=1` +([STRIX_HALO_WINDOWS.md](STRIX_HALO_WINDOWS.md#4-what-is-on-by-default)). Linux `gfx1151` keeps the opt-in above until it is +measured there. + | Switch | What it does | | --- | --- | | `STRATA_PREFILL_STREAM_MIN=N` | `STRATA_PF_FUSED=1` reaches only chunks of N tokens or more (1,024 by default, the floor measured on a discrete card). With every expert in unified memory nothing streams and MMQ is the slow part, so a smaller N (128) speeds up an agent's turn (a tool result of about 1,000 tokens on a cached conversation: 3.1 to 6.0 s at 1,024 against 0.9 to 2.5 s at 128). | diff --git a/docs/STRIX_HALO_WINDOWS.md b/docs/STRIX_HALO_WINDOWS.md index 7aff4b65..93335963 100644 --- a/docs/STRIX_HALO_WINDOWS.md +++ b/docs/STRIX_HALO_WINDOWS.md @@ -85,6 +85,23 @@ environment and the package's `rocm/bin` folder on the library path. about 9% faster, near-tie tokens can differ); `STRATA_HC_Q8=0` keeps the old read. - The hipBLASLt table for `gfx1151` ships in the package and is chosen without a setting (`prefill gemm: hipBLASLt tuning enabled (32 rows, gfx1151, version 100500)` in the log). A hand-built engine has to be pointed at it: [AMD_HIP.md](AMD_HIP.md). +- **The matrix-core prompt set is on by default on `gfx1151` on Windows** (engine 0.1.52 and the build after it): `STRATA_HIP_WMMA`, + `STRATA_PF_GEMM`, `STRATA_PA_FAST`, `STRATA_HC_UPMIX` and `STRATA_PF_FUSED`. It is the set that has been on the Radeon 780M since + 021-minipc, and the start line lists it (`integrated GPU (gfx1151): the matrix-core prompt set is on ...`). Prompts on Qwen IQ3_S: + 4K 688.8 -> 1,192.8 tok/s, 8K 787.0 -> 1,283.5, 12K 750.4 -> 1,256.5, 32K 775.4 -> 1,245.1, 64K 748.5 -> 1,188.9 (x1.59 to x1.72; + interleaved pairs, one engine at a time). The answers differ in the last bits: the first-token KL against the 0.2.7 default is + 0.0014 mean over four prompts of 4K to 24K, top-1 the same everywhere, and the measured noise floor is 0.00000 - against the + accepted `HC_Q8` bar of 0.0228 mean. `STRATA_IGPU_PROMPT_SET=0` turns it off, `STRATA_SELECT_WMMA=1` adds the block scorer back + (it measured x1.003), a single switch can be turned off on its own (`STRATA_HC_UPMIX=0`). +- **The prompt keeps its own buffers instead of lending expert-cache slots** (`--no-prefill-borrow`, engine 0.1.52 and after, on + `gfx1151` Windows only). A lent slot's expert has to be read back from the host arena during every prompt chunk, and on this PC + that copy runs at about 0.5 GB/s (the arena is not registered with the driver in UMA mode): 823 slots took 2.75 s of a 3.3 s 4K + prompt inside the copy thread. With its own buffers every expert stays in the cache (`experts streamed 0 ... resident 24576` in the + log) and prompts are 8.5% (4K) to 8.9% (8K) faster. `STRATA_PREFILL_BORROW=1` brings lending back. `--prefill auto` keeps a + 16,384-token chunk on this PC instead of falling back to 2,048: the prompt reads every expert once per chunk, so a bigger chunk reads + them fewer times (32K 1,250.6-1,260.0 -> 1,286.3-1,307.9 tok/s, 64K 1,188.4-1,191.0 -> 1,234.3-1,238.2; at 4K and 8K the chunk is + the prompt itself and nothing changes). `STRATA_GFX1151_CHUNK=0` keeps 6,144, and `--prefill auto:32768` is another ~2% at 64K for + about 12.8 GiB of prompt buffers. - `--mmap-experts` is not needed. The first Windows guide found that without it the pinned expert arena used up the graphics memory budget and decode fell to 28 tok/s on engine 0.1.41; the engine on this page sizes the cache from the shared pool and reaches every slot. - DeepSeek runs in "Faster" mode here: 5 of 6 experts per word. The app and `strata launch` say so; the quality change is small. @@ -134,3 +151,5 @@ python tools/strata_bench.py --url http://127.0.0.1:8080 --runs 3 --long `--long` adds the 32K prompt. For DeepSeek add `--context 64k` to `strata launch` first; the default 8K context skips the 16K prompt and the agent session. + + diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 7bc782a7..fb0dc54e 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -3373,7 +3373,12 @@ int main(int argc, char** argv) { const char* d1 = std::getenv("STRATA_GFX1151_DEFAULTS"); if (!(c1 != nullptr && c1[0] == '0') && !(d1 != nullptr && d1[0] == '0')) { o.prefill_auto_cap = 0; - o.prefill_chunk = std::max(o.prefill_chunk, 8192); + // 0.2.8: 16,384 rather than 8,192. The prompt reads every expert once per chunk, so a bigger chunk + // reads them fewer times: measured on strix (engine 0.1.52, own prompt buffers, IQ3_S) 32K 1,260.0 -> + // 1,307.9 tok/s and 64K 1,191.0 -> 1,238.2 (+3.8% / +4.0%); at 4K and 8K the chunk is the prompt, so + // nothing changes there. The buffers' reserve grows to ~10.9 GiB and the cache keeps all 24,576 slots + // (the box reports 84.7 GiB free at a 64K context). STRATA_GFX1151_CHUNK=0 keeps 6,144. + o.prefill_chunk = std::max(o.prefill_chunk, 16384); } } // 0.2.8: the Strix Halo prompt path keeps its own buffers instead of lending cache slots. A lent slot's expert From 2ea46ded73ef490e586b29de400fd8e50139b355 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 14:04:52 +0100 Subject: [PATCH 3/5] dsv41: the post-prompt cache settle's budget 6,000 -> 800 ms on every platform The settle sits inside the prompt's own time: prompt: N tokens in X ms includes it, so a 6 s budget was 6 s of every DeepSeek first token. Measured on Strix Halo 2026-10-28 (p4k fixture, three interleaved rounds each, --dspark off): 6,000 ms -> 153.1 tok/s, 800 ms -> 190.0 (+24.1%), 0 -> 197.4 (+29.0%); the decode of the 256-token answer that follows pays 2.9% at 800 ms and 3.8% at 0. 800 ms keeps 1,412-1,436 swaps against the 6,000's 987-1,046, so it is still moving the hot experts in, it just stops paying for the last 5 s. An agent turn's answer is 50-300 tokens (where the swaps buy nothing) and its first token is the 800 ms, so this is the plan's WP-8 option (2) without the server-loop work of the idle settle (option 1, still the better answer and not done here). DS4_SETTLE_MS still overrides it (0 = off, any value in ms). --- src/dsv41/ds4_model.cu | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dsv41/ds4_model.cu b/src/dsv41/ds4_model.cu index 7ffa7cc4..dadc0bf1 100644 --- a/src/dsv41/ds4_model.cu +++ b/src/dsv41/ds4_model.cu @@ -6933,10 +6933,15 @@ struct Model::Impl { // after a chunked prompt: the expert cache catches up with what the prompt picked at once - a window prompt gets // its swaps one tick at a time over its hundreds of windows, a chunked one has a single tick - so the decode that // follows finds the hot experts in VRAM. Rounds of the ordinary swap rule (the hottest CPU-lane pick of each layer - // in, its coldest VRAM expert out) until nothing is worth moving or DS4_SETTLE_MS (6000) is spent + // in, its coldest VRAM expert out) until nothing is worth moving or DS4_SETTLE_MS is spent. + // The budget was 6,000 ms, and it sits inside the prompt's own time ("prompt: N tokens in X ms"): measured on Strix Halo + // 2026-10-28, the same p4k fixture took 26.6 s with it and 20.4 s without, +30.5% on the prompt (153.9 -> 200.8 tok/s). + // What the swaps buy is decode: about 10% on a 256-token answer, i.e. 6.2 s of prompt against 1.6 s of decode on that + // answer and nothing at all on a 50-300-token tool-call answer. 800 ms keeps the hottest of them and gives the prompt + // back about 5 s (the plan's own table: prompt + 256 tokens, 27.2 s at 6,000 ms, 23.9 s at 800, 23.4 s at 0). void cache_settle() { if (!o.expert_cache || cache_ths.empty()) return; - static const double budget = env_f("DS4_SETTLE_MS", 6000.0f); + static const double budget = env_f("DS4_SETTLE_MS", 800.0f); if (budget <= 0.0) return; const double t0 = now_ms(); const int64_t s0 = st.swaps; From c697e859e94318ca24adf2656dcc30ca49420df5 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 14:04:44 +0100 Subject: [PATCH 4/5] dsv41: the matrix-core prompt attention (DS4_FAST_ATTN) on by default for gfx1151 on Windows The switch was on for gfx12 only, and ds4_kernels.cu said why: "gfx11 and gfx1151 (Strix Halo) are untested and keep the scalar kernels". Measured on Strix Halo 2026-10-28 (2.00 bpw, 32K prompt, the synchronised chunk profile): the sparse-attention stage is 43.3% of the prompt's GPU time and runs at 2.3 TFLOPS effective; with DS4_FAST_ATTN=1 the stage falls from 38,340 ms to 6,976 ms and the prompt from 101.6 s to 70.8 s - +43.6%, 322.5 -> 463.0 tok/s - with the same greedy first token (27408,). The plan's D-P3a had closed this on +1.6 / -0.2 / +1.2 / -2.8% end to end, which is what 4K-8K shows; at 32K the term is five times its 4K size and the switch is the whole difference. fast_attn_default() takes the gfx1151-on-Windows flag as its own argument (the existing three-argument calls in the test are updated), ds4_kernels.cu decides it from the device name once, and experts_rule_test covers the new cell: gfx1151 Windows on, 0.2.6 arithmetic off, DS4_FAST_ATTN=0 off, =1 on anywhere. --- src/dsv41/ds4_experts_rule.hpp | 8 +++++--- src/dsv41/ds4_kernels.cu | 28 +++++++++++++++++++++++++--- tests/dsv41/experts_rule_test.cpp | 14 ++++++++------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/dsv41/ds4_experts_rule.hpp b/src/dsv41/ds4_experts_rule.hpp index 79e9c4b9..af2b774b 100644 --- a/src/dsv41/ds4_experts_rule.hpp +++ b/src/dsv41/ds4_experts_rule.hpp @@ -176,10 +176,12 @@ inline bool copy_hugetlb_default(int env, double pool_free_bytes, double copy_by return pool_free_bytes > 0.0 && pool_free_bytes >= copy_bytes; } -// DS4_FAST_ATTN (the chunked prompt's attention on the matrix cores): env -1 unset, else 0 / 1; 0.2.6: opt-in; 0.2.7: on for gfx1200 / gfx1201. -inline bool fast_attn_default(int env, bool gfx12, bool v026 = false) { +// DS4_FAST_ATTN (the chunked prompt's attention on the matrix cores): env -1 unset, else 0 / 1; 0.2.6: opt-in; 0.2.7: on for +// gfx1200 / gfx1201, and (this change) on for gfx1151 on Windows, where it measured +43.6% on a 32K prompt (101.6 -> 70.8 s, +// sparse attention 38.3 -> 7.0 s), the same greedy first token and a first-token KL far under the 0.0228 bar. +inline bool fast_attn_default(int env, bool gfx12, bool gfx1151win = false, bool v026 = false) { if (env >= 0) return env != 0; - return !v026 && gfx12; + return !v026 && (gfx12 || gfx1151win); } // The drafter's cumulative confidence cut (STRATA_DS4_DSPARK_CUM, a request's dspark_cum): the variable when set; 0.2.6: 0; 0.2.7: 0.5 on gfx1200 / gfx1201. diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu index 13bda6e8..f598f52d 100644 --- a/src/dsv41/ds4_kernels.cu +++ b/src/dsv41/ds4_kernels.cu @@ -2038,7 +2038,9 @@ bool split_enabled() { // 0.006 gate, ids identical); gfx11 and gfx1151 (Strix Halo) are untested and keep the scalar kernels. DS4_FAST_ATTN=0 is the // off switch (exactly the 0.2.6 arithmetic), DS4_FAST_ATTN=1 turns it on elsewhere. Decided per device (the first call there). // The Marlin stream measured it ON on 4x R9700 (gfx1201), 2.25 bpw, 8K code prompts: 1180 -> 1354 ppts (+14.7%), the same ids, -// KL 0.10833 against 0.10925 for the scalar path. It stays gfx12-only until Strix Halo (gfx1151) is tested. +// KL 0.10833 against 0.10925 for the scalar path. gfx1151 on Windows was the untested part; measured on Strix Halo 2026-10-28 +// (32K prompt, 2.00 bpw): 101.6 -> 70.8 s (+43.6%), the sparse-attention stage 38.3 -> 7.0 s, the same greedy first token +// (27408,), so it joins the default there and stays opt-in on every other gfx11 part. #if defined(STRATA_USE_HIP) bool device_is_gfx12() { static std::atomic cache[64]; // 0 unknown, 1 no, 2 yes @@ -2055,6 +2057,22 @@ bool device_is_gfx12() { } return c == 2; } +#if defined(_WIN32) +bool device_is_gfx1151win() { + static std::atomic cache[64]; // 0 unknown, 1 no, 2 yes + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64) return false; + int c = cache[dev].load(); + if (c == 0) { + cudaDeviceProp prop{}; + const bool yes = cudaGetDeviceProperties(&prop, dev) == cudaSuccess && std::strncmp(prop.gcnArchName, "gfx1151", 7) == 0; + c = yes ? 2 : 1; + cache[dev].store(c); + } + return c == 2; +} +#endif #endif bool fast_attn_enabled() { static const int env = [] { @@ -2062,9 +2080,13 @@ bool fast_attn_enabled() { return e == nullptr ? -1 : (std::atoi(e) != 0 ? 1 : 0); }(); #if defined(STRATA_USE_HIP) - return strata::ds4::fast_attn_default(env, device_is_gfx12(), strata::ds4::defaults_026()); +#if defined(_WIN32) + return strata::ds4::fast_attn_default(env, device_is_gfx12(), device_is_gfx1151win(), strata::ds4::defaults_026()); #else - return strata::ds4::fast_attn_default(env, false, strata::ds4::defaults_026()); + return strata::ds4::fast_attn_default(env, device_is_gfx12(), false, strata::ds4::defaults_026()); +#endif +#else + return strata::ds4::fast_attn_default(env, false, false, strata::ds4::defaults_026()); #endif } attnsplit::AttnSplitScratch split_scratch(cudaStream_t s, int heads) { diff --git a/tests/dsv41/experts_rule_test.cpp b/tests/dsv41/experts_rule_test.cpp index 895df7f0..3e2c17fb 100644 --- a/tests/dsv41/experts_rule_test.cpp +++ b/tests/dsv41/experts_rule_test.cpp @@ -270,12 +270,14 @@ int main() { CHECK_EQ(copy_hugetlb_default(-1, 90 * GB, 100 * GB, false), 0); CHECK_EQ(copy_hugetlb_default(1, 0.0, 100 * GB, true), 1); CHECK_EQ(copy_hugetlb_default(0, 120 * GB, 100 * GB, false), 0); // the old DS4_COPY_HUGETLB=0 - // the matrix-core attention: opt-in again - CHECK_EQ(fast_attn_default(-1, true, true), 0); - CHECK_EQ(fast_attn_default(-1, true, false), 1); - CHECK_EQ(fast_attn_default(-1, false, false), 0); - CHECK_EQ(fast_attn_default(1, false, true), 1); - CHECK_EQ(fast_attn_default(0, true, false), 0); // the old DS4_FAST_ATTN=0 + // the matrix-core attention: opt-in again, except on gfx12 and (since 2026-10-28) on gfx1151 on Windows + CHECK_EQ(fast_attn_default(-1, true, false, true), 0); + CHECK_EQ(fast_attn_default(-1, true, false, false), 1); + CHECK_EQ(fast_attn_default(-1, false, false, false), 0); + CHECK_EQ(fast_attn_default(-1, false, true, false), 1); // gfx1151 on Windows + CHECK_EQ(fast_attn_default(-1, false, true, true), 0); // ... but never for 0.2.6's arithmetic + CHECK_EQ(fast_attn_default(1, false, false, true), 1); + CHECK_EQ(fast_attn_default(0, true, true, false), 0); // the old DS4_FAST_ATTN=0 // the drafter's cumulative cut: 0 again; STRATA_DS4_DSPARK_CUM wins CHECK_EQ((int) (dspark_cum_value(false, 0.0f, true, true) * 100), 0); CHECK_EQ((int) (dspark_cum_value(false, 0.0f, true, false) * 100), 50); From b2dbd9420d7860b79d553afd977ba2e70cff9d52 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 16:19:15 +0100 Subject: [PATCH 5/5] dsv41 serve: the cache settle runs in the idle between requests (WP-8's option 1) The prompt-side settle is 800 ms because it sits inside the prompt's own time, and for a run with no next request (the CLI, a one-shot tool call) that is the right price. In a server it is not: an agent's turn ends, it runs its tool for a second or ten, and that time is free for the swap rounds the *next* answer needs. Measured why it matters (job d18-attrib, 2026-10-28): the same candidate engine with the settle at 6,000 ms decodes a 256-token code answer at 10.92 / 11.14 tok/s, at 800 ms at 9.82 / 9.62 - 12% paid for the prompt. The idle settle is meant to give that back without returning the 6 s to the prompt. How: Model::settle_idle(cancel) runs cache_settle's swap rounds on its own thread, without the RAM store preload, for at most DS4_SETTLE_IDLE_MS (6,000) and stopping between rounds when cancel is set. The serve loop starts it at the top of each iteration (nothing in flight), and cancels and joins it the moment a line arrives, before any request work touches the cache. DS4_SETTLE_IDLE=0 turns it off; the prompt-side budget is unchanged. Not measured yet: the benefit needs a serve-path harness (two GEN requests with an idle between them). On the CLI the thread is never started, so no CLI number moves. --- src/dsv41/ds4_main.cpp | 26 +++++++++++++++++++++++++- src/dsv41/ds4_model.cu | 26 ++++++++++++++++++++++++++ src/dsv41/ds4_model.hpp | 4 ++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/dsv41/ds4_main.cpp b/src/dsv41/ds4_main.cpp index c4354749..47214cfe 100644 --- a/src/dsv41/ds4_main.cpp +++ b/src/dsv41/ds4_main.cpp @@ -713,7 +713,30 @@ int serve(strata::ds4::Model& m, const std::string& eos_list, bool spec, float c std::signal(SIGPIPE, SIG_IGN); #endif } - while (in.next(line)) { + // WP-8's option (1): the post-prompt cache settle runs in the gaps between requests and gives way the moment one arrives + // (DS4_SETTLE_IDLE=0 turns it off). An agent's turn ends, its tool runs, and the swaps the next answer wants go in during + // that idle - which is what the 800 ms prompt-side budget cannot do for a run that has no next request. + std::atomic settle_cancel{false}; + std::thread settle_th; + const bool settle_idle_on = [] { + const char* v = std::getenv("DS4_SETTLE_IDLE"); + return v == nullptr || std::atoi(v) != 0; + }(); + const auto settle_stop = [&] { + if (!settle_th.joinable()) return; + settle_cancel.store(true, std::memory_order_release); + settle_th.join(); + }; + const auto settle_start = [&] { + if (!settle_idle_on || settle_th.joinable()) return; + settle_cancel.store(false, std::memory_order_release); + settle_th = std::thread([&m, &settle_cancel] { m.settle_idle(settle_cancel); }); + }; + for (;;) { + settle_start(); // (nothing in flight: this is the idle) + const bool have_line = in.next(line); + settle_stop(); // (a line arrived, or the input closed) + if (!have_line) break; if (line == "QUIT") break; const bool geni = line.rfind("GENI ", 0) == 0; if (!geni && line.rfind("GEN ", 0) != 0) { @@ -1024,6 +1047,7 @@ int serve(strata::ds4::Model& m, const std::string& eos_list, bool spec, float c note(msg); } } + settle_stop(); // (the idle thread must be off the cache before the profile is saved and the engine ends) m.save_profile(); return 0; } diff --git a/src/dsv41/ds4_model.cu b/src/dsv41/ds4_model.cu index dadc0bf1..dd95fc73 100644 --- a/src/dsv41/ds4_model.cu +++ b/src/dsv41/ds4_model.cu @@ -6985,6 +6985,31 @@ struct Model::Impl { std::fprintf(stderr, "ds4: expert cache: %lld swaps after the prompt (%.0f ms)\n", (long long) (st.swaps - s0), now_ms() - t0); } + // WP-8's option (1): the same swap rounds, run on a thread while the server has no request in flight, stopped by `cancel`. + // The prompt path keeps its 800 ms (a run with no server has no idle to use), so this is pure addition: an agent's turn + // ends, the swaps go in while it runs its tool, and the next turn's answer finds them. Interrupting costs one round (a + // swap of ~9 MB, a millisecond or two) because cancel is tested between rounds, and cache_tick_swaps is the same call the + // prompt path makes, so the state it leaves is the state a decode window already handles. + void cache_settle_idle(const std::atomic& cancel) { + if (!o.expert_cache || cache_ths.empty()) return; + static const double budget = env_f("DS4_SETTLE_IDLE_MS", 6000.0f); + const double t0 = now_ms(); + const int64_t s0 = st.swaps; + while (!cancel.load(std::memory_order_acquire) && now_ms() - t0 < budget) { + for (Layer& l : L) { + if (l.mtp || l.spare_vram < 0 || l.swap_pending) continue; + l.cpu_hits.clear(); + for (int e = 0; e < l.n_exp; ++e) + if (l.slot[(size_t) e] < 0 && l.heat[(size_t) e] >= 2.0f) l.cpu_hits.push_back(e); + } + cache_tick_swaps(0); + if (sw_inflight == 0) break; // (nothing queued: no layer's best CPU-lane expert is hotter than its coldest VRAM one) + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } + if (o.verbose) + std::fprintf(stderr, "ds4: expert cache: %lld swaps in the idle (%.0f ms, cancelled %d)\n", + (long long) (st.swaps - s0), now_ms() - t0, cancel.load() ? 1 : 0); + } void cache_tick(int T) { cache_tick_swaps(T); store_sync(); @@ -10497,6 +10522,7 @@ bool Model::slot_load(const uint8_t* data, size_t bytes, int64_t n_pos, std::str return p_->slot_load(data, bytes, n_pos, err); } std::string Model::slot_identity() const { return p_->slot_identity(); } +void Model::settle_idle(const std::atomic& cancel) { p_->cache_settle_idle(cancel); } void Model::save_profile() const { p_->save_profile(); } const Stats& Model::stats() const { Stats& st = p_->st; diff --git a/src/dsv41/ds4_model.hpp b/src/dsv41/ds4_model.hpp index 6cf65dba..20fdf519 100644 --- a/src/dsv41/ds4_model.hpp +++ b/src/dsv41/ds4_model.hpp @@ -157,6 +157,10 @@ public: const std::vector& tokens() const; // what the state has consumed, in order void reset(); + /// The post-prompt cache settle run on a thread of its own while the server waits for its next request (WP-8's option 1): + /// the swap rounds of cache_settle without the store preload, stopped early when `cancel` goes true. `done` is set when + /// the thread has nothing left to do. Only one such run at a time; the caller joins the thread after setting cancel. + void settle_idle(const std::atomic& cancel); /// Keep the state at the current position in checkpoint slot 0 or 1 (the end of a prompt, the position before it); /// restore(limit) goes back to the latest one at or before limit (-1: none). void checkpoint(int slot = 0);