diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index e35adb5d..bf9a9343 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/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 2bbe60fc..95fc5441 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/dsv41/ds4_experts_rule.hpp b/src/dsv41/ds4_experts_rule.hpp index fecba633..103e986e 100644 --- a/src/dsv41/ds4_experts_rule.hpp +++ b/src/dsv41/ds4_experts_rule.hpp @@ -186,10 +186,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/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 2e83e1fe..beb07610 100644 --- a/src/dsv41/ds4_model.cu +++ b/src/dsv41/ds4_model.cu @@ -7059,10 +7059,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; @@ -7106,6 +7111,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(); @@ -10629,6 +10659,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); diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 956d2c56..ba5497e1 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -708,6 +708,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). @@ -3371,7 +3375,27 @@ 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 + // 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(); @@ -3705,7 +3729,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}; diff --git a/tests/dsv41/experts_rule_test.cpp b/tests/dsv41/experts_rule_test.cpp index 8277b85d..e43c2094 100644 --- a/tests/dsv41/experts_rule_test.cpp +++ b/tests/dsv41/experts_rule_test.cpp @@ -271,12 +271,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);