Skip to content

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++

Master switches DS4_DEFAULTS=026 (DeepSeek) and STRATA_DEFAULTS=026 (Qwen): every default changed since v0.2.6 gives v0.2.6's behaviour; explicit per-feature variables and flags still win; every rule is a pure function with a v026 argument and a test

Niko1221a3ab37fc039c
diff --git a/include/strata/core/arch_defaults.hpp b/include/strata/core/arch_defaults.hpp
index 969e4cee3..7062f4b22 100644
--- a/include/strata/core/arch_defaults.hpp
+++ b/include/strata/core/arch_defaults.hpp
@@ -18,7 +18,9 @@
namespace strata::core {
/// The environment settings that are the defaults of `gcn_arch` (hipDeviceProp_t::gcnArchName; "gfx1151" or
-/// "gfx1151:sramecc-:xnack-"): empty for every other architecture.
+/// "gfx1151:sramecc-:xnack-"): empty for every other architecture. `defaults026` (STRATA_DEFAULTS=026, defaults_026.hpp): the gfx12 table of
+/// v0.2.6 (the five prompt switches only, without the four 0.2.7 decode switches); the one-argument form asks the environment.
+std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch, bool defaults026);
std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch);
/// The integrated Radeons (Phoenix / Hawk Point 780M gfx1103, Strix Point 890M / 880M gfx1150, Strix Halo gfx1151) whose
diff --git a/include/strata/core/defaults_026.hpp b/include/strata/core/defaults_026.hpp
new file mode 100644
index 000000000..84221a540
--- /dev/null
+++ b/include/strata/core/defaults_026.hpp
@@ -0,0 +1,39 @@
+// include/strata/core/defaults_026.hpp - STRATA_DEFAULTS=026: the master switch of the Qwen engine's 0.2.7 defaults.
+//
+// Every default the Qwen engine (`strata`) changed since v0.2.6 goes back to what v0.2.6 did when STRATA_DEFAULTS=026 is in the
+// environment (the app's "off" for its speed switches sends it): the residency-biased routing (STRATA_ROUTE_PRIOR), the wide
+// hyper-connection up read (STRATA_GR_UP_WIDE), the stream-split hyper-connection read (STRATA_GR_V3), the int8 prompt attention
+// (STRATA_PROMPT_ATTN_IMMA), the four gfx12 decode switches of the arch table, the PLE residency policy (STRATA_PLE_AUTO_RAM), and the
+// gfx12 decode miss split of 0.15 (back to 0.55). KVA is off by default in 0.2.7 and stays whatever STRATA_KVA says.
+// An explicit per-feature variable (STRATA_ROUTE_PRIOR=2, STRATA_GR_V3=1, STRATA_PLE_AUTO_RAM=1, ...) or flag (--pcie-frac, --ple-io)
+// still wins over the master switch. Each rule is a pure function that takes the answer of qwen_defaults_026() as its `v026`
+// argument, so a test can check both settings without touching the environment (src/core/arch_defaults_test.cpp,
+// src/core/ple_residency_test.cpp).
+#pragma once
+
+#include <cstdlib>
+#include <cstring>
+
+namespace strata {
+
+/// "026", "0.2.6" and "v0.2.6" name version 0.2.6; anything else (unset, "", "0", "027") does not.
+inline bool is_026_token(const char* v) {
+ return v != nullptr && (std::strcmp(v, "026") == 0 || std::strcmp(v, "0.2.6") == 0 || std::strcmp(v, "v0.2.6") == 0);
+}
+
+/// STRATA_DEFAULTS=026 (read once).
+inline bool qwen_defaults_026() {
+ static const bool on = is_026_token(std::getenv("STRATA_DEFAULTS"));
+ return on;
+}
+
+/// The decode miss split's start value (the share of a native pack's missing experts the CPU pool takes) when --pcie-frac is not given:
+/// NVFP4 packs 0.25, other native packs 0.55 (the x16 share), and 0.15 on gfx12 (0.2.7) unless STRATA_PCIE_FRAC_DEFAULT=old or the master
+/// switch is 026; a canonical pack 0.2.
+inline double pcie_start_frac(bool nvfp4_pack, bool native_pack, bool gfx12_default, bool pf_old, bool v026 = false) {
+ if (nvfp4_pack) return 0.25;
+ if (!native_pack) return 0.2;
+ return gfx12_default && !pf_old && !v026 ? 0.15 : 0.55;
+}
+
+} // namespace strata
diff --git a/include/strata/core/ple_residency.hpp b/include/strata/core/ple_residency.hpp
index 1135b89ec..b9e3829e2 100644
--- a/include/strata/core/ple_residency.hpp
+++ b/include/strata/core/ple_residency.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
+#include <cstdlib>
#include <optional>
#include "strata/core/conversation_memory.hpp"
@@ -26,4 +27,11 @@ inline bool ple_resident_admit(std::optional<uint64_t> available, uint64_t table
return conversation_memory_admit(available, table_bytes + experts_ram_bytes, headroom_bytes);
}
+/// May the residency policy run at all? STRATA_PLE_AUTO_RAM when it is set (0 off, anything else on: an explicit value wins), otherwise on
+/// except under STRATA_DEFAULTS=026 (`v026`: v0.2.6 had no such policy, the direct reads stayed).
+inline bool ple_auto_ram_allowed(const char* env_value, bool v026) {
+ if (env_value != nullptr) return std::atoi(env_value) != 0;
+ return !v026;
+}
+
} // namespace strata::core
diff --git a/include/strata/core/sm120_series.hpp b/include/strata/core/sm120_series.hpp
index b1cc11925..8a6932a65 100644
--- a/include/strata/core/sm120_series.hpp
+++ b/include/strata/core/sm120_series.hpp
@@ -44,25 +44,31 @@ inline bool sm120_default(int major, int minor) { return is_sm120(major, minor)
// ---- 0.2.7 defaults of the CUDA speed work (pure rules; the engine reads the device and calls these; tests in arch_defaults_test)
// `hip`: a HIP build, where a gfx1200 / gfx1201 reports compute capability 12.0 as well and none of these is measured or wanted.
+// `v026`: STRATA_DEFAULTS=026 (defaults_026.hpp qwen_defaults_026()): every one of these is then off, as in v0.2.6. An explicit variable
+// (STRATA_ROUTE_PRIOR=2, STRATA_GR_V3=1, ...) is decided by the caller before it asks the rule, so it still wins.
// `total_bytes`: the card's memory (cudaDeviceProp::totalGlobalMem); `integrated`: a GPU that shares the PC's memory.
constexpr double kSmallCardGiB = 13.0; // "a 12 GB card": 12 GB cards report 11.6 - 12.0 GiB, 16 GB ones 15.6 - 16.0
/// STRATA_ROUTE_PRIOR when the user set nothing: 2.0 (residency-biased routing, changes which experts run; owner-approved for 12 GB cards) on a
/// discrete CUDA card of 13 GiB or less, 0 everywhere else. Measured on an RTX 3060 12 GB only.
-inline float route_prior_default(bool hip, bool integrated, double total_bytes) {
- return !hip && !integrated && total_bytes > 0.0 && total_bytes / 1073741824.0 <= kSmallCardGiB ? 2.0f : 0.0f;
+inline float route_prior_default(bool hip, bool integrated, double total_bytes, bool v026 = false) {
+ return !v026 && !hip && !integrated && total_bytes > 0.0 && total_bytes / 1073741824.0 <= kSmallCardGiB ? 2.0f : 0.0f;
}
/// STRATA_GR_V3 (the stream-split hyper-connection read, another summation order) when the user set nothing: ON for a discrete compute capability
/// 12.0 card (STRATA_SM120_PERF=0 turns the set off) with more than 13 GiB, CUDA builds only. Measured: RTX PRO 5000 72 GB +1.2% decode clean,
/// -3.0% / -5.9% on 2x RTX A4000 (sm_86), +1.0% / -3.4% on an RTX 3060 (sm_86): so not those; a 12 GB sm_120 card is unmeasured.
-inline bool gr_v3_default(bool hip, int major, int minor, bool integrated, double total_bytes) {
- return !hip && !integrated && sm120_default(major, minor) && total_bytes / 1073741824.0 > kSmallCardGiB;
+inline bool gr_v3_default(bool hip, int major, int minor, bool integrated, double total_bytes, bool v026 = false) {
+ return !v026 && !hip && !integrated && sm120_default(major, minor) && total_bytes / 1073741824.0 > kSmallCardGiB;
}
/// STRATA_PROMPT_ATTN_IMMA (the prompt attention on int8 tensor cores, another summation order) when the user set nothing: ON for every CUDA card of
/// compute capability 8.0 or newer (the int8 m16n8k32 MMA), not Turing / Volta / Pascal, not HIP. `cc` = 10 * major + minor as the engine
/// resolves it (an emulated or forced Turing counts as 75). Measured on sm_120 (RTX PRO 5000) and sm_86 (2x RTX A4000): +1.1 .. +1.8% prompt.
-inline bool prompt_attn_imma_default(bool hip, int cc) { return !hip && cc >= 80; }
+inline bool prompt_attn_imma_default(bool hip, int cc, bool v026 = false) { return !v026 && !hip && cc >= 80; }
+
+/// STRATA_GR_UP_WIDE (the hyper-connection up projection, one warp a row; bitwise the old kernel) when the user set nothing: ON for a compute
+/// capability 12.0 card (STRATA_SM120_PERF=0 turns the set off), CUDA builds only.
+inline bool gr_up_wide_default(bool hip, int major, int minor, bool v026 = false) { return !v026 && !hip && sm120_default(major, minor); }
} // namespace strata
diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp
index efacbdad0..47b9ba7ac 100644
--- a/src/core/arch_defaults.cpp
+++ b/src/core/arch_defaults.cpp
@@ -1,5 +1,6 @@
// src/core/arch_defaults.cpp - see include/strata/core/arch_defaults.hpp.
#include "strata/core/arch_defaults.hpp"
+#include "strata/core/defaults_026.hpp"
#include "strata/kernels/gfx_arch.hpp"
@@ -10,6 +11,10 @@
namespace strata::core {
std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch) {
+ return arch_default_env(gcn_arch, strata::qwen_defaults_026());
+}
+
+std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gcn_arch, bool defaults026) {
std::vector<std::pair<std::string, std::string>> t;
if (strata::kernels::gfx_arch_is_gfx12(gcn_arch)) {
// gfx1200 / gfx1201 (RDNA4): the PROMPT half of the gfx1151 table (reported exact on an R9700 in #1478, re-checked
@@ -30,12 +35,13 @@ std::vector<std::pair<std::string, std::string>> arch_default_env(const char* gc
{"STRATA_GDN_CONVL2", "1"},
{"STRATA_GDN_NOY", "1"},
{"STRATA_CVEC_FUSE", "1"},
- // decode (bit-identical on the R9700 measurement above)
- {"STRATA_ATTN_LANECELL", "1"},
- {"STRATA_ATTN_MERGE_V2", "1"},
- {"STRATA_TSUM", "1"},
- {"STRATA_EXPDEC", "1"},
};
+ if (defaults026) return t; // STRATA_DEFAULTS=026: v0.2.6's table, the prompt half only
+ // decode (bit-identical on the R9700 measurement above)
+ t.push_back({"STRATA_ATTN_LANECELL", "1"});
+ t.push_back({"STRATA_ATTN_MERGE_V2", "1"});
+ t.push_back({"STRATA_TSUM", "1"});
+ t.push_back({"STRATA_EXPDEC", "1"});
return t;
}
if (!strata::kernels::gfx_arch_is_gfx1151(gcn_arch)) return t;
diff --git a/src/core/arch_defaults_test.cpp b/src/core/arch_defaults_test.cpp
index 9723b2b78..db193a7f7 100644
--- a/src/core/arch_defaults_test.cpp
+++ b/src/core/arch_defaults_test.cpp
@@ -2,6 +2,7 @@
#include "strata/core/arch_defaults.hpp"
#include "strata/core/gfx12_platform_defaults.hpp"
#include "strata/core/sm120_series.hpp"
+#include "strata/core/defaults_026.hpp"
#include <cstdio>
#include <cstdlib>
@@ -226,6 +227,54 @@ int main() {
CHECK(!igpu_uma_arena_default("gfx1103", true, false, true)); // the user registers the arena as before
unset("STRATA_UMA_REGISTER");
// both platforms: no Windows guard on the iGPU set (the owner wants it there too; untested on Windows is only said in the log)
+ // ---- STRATA_DEFAULTS=026 (defaults_026.hpp): every 0.2.7 Qwen default gives v0.2.6's answer; an explicit variable is decided by the caller first
+ {
+ const double GiB = 1073741824.0;
+ using namespace strata;
+ CHECK(is_026_token("026") && is_026_token("0.2.6") && is_026_token("v0.2.6"));
+ CHECK(!is_026_token(nullptr) && !is_026_token("") && !is_026_token("0") && !is_026_token("027"));
+ // residency-biased routing: 0 under 026 on the card that gets 2.0 otherwise
+ CHECK(route_prior_default(false, false, 12.0 * GiB, false) == 2.0f);
+ CHECK(route_prior_default(false, false, 12.0 * GiB, true) == 0.0f);
+ CHECK(route_prior_default(false, false, 8.0 * GiB, true) == 0.0f);
+ // the wide HC up read: on for a 12.0 card on CUDA, off under 026, off in HIP, off on sm_86 / sm_121
+ CHECK(gr_up_wide_default(false, 12, 0));
+ CHECK(!gr_up_wide_default(false, 12, 0, true));
+ CHECK(!gr_up_wide_default(true, 12, 0));
+ CHECK(!gr_up_wide_default(false, 8, 6));
+ CHECK(!gr_up_wide_default(false, 12, 1));
+ // GR_V3 and IMMA
+ CHECK(gr_v3_default(false, 12, 0, false, 72.0 * GiB, false));
+ CHECK(!gr_v3_default(false, 12, 0, false, 72.0 * GiB, true));
+ CHECK(prompt_attn_imma_default(false, 86, false));
+ CHECK(!prompt_attn_imma_default(false, 86, true));
+ CHECK(!prompt_attn_imma_default(false, 120, true));
+ // the gfx12 decode switches: the arch table is v0.2.6's five prompt switches under 026, nine otherwise; gfx1151 and the others do not move
+ {
+ const auto t26 = strata::core::arch_default_env("gfx1201", true);
+ const auto t27 = strata::core::arch_default_env("gfx1201", false);
+ auto has = [](const std::vector<std::pair<std::string, std::string>>& t, const char* k) {
+ for (const auto& kv : t) if (kv.first == k) return true;
+ return false;
+ };
+ CHECK(t26.size() == 5 && t27.size() == 9);
+ CHECK(has(t26, "STRATA_GDN_HEAD") && has(t26, "STRATA_CVEC_FUSE"));
+ CHECK(!has(t26, "STRATA_ATTN_LANECELL") && !has(t26, "STRATA_ATTN_MERGE_V2") && !has(t26, "STRATA_TSUM") && !has(t26, "STRATA_EXPDEC"));
+ CHECK(has(t27, "STRATA_ATTN_LANECELL") && has(t27, "STRATA_ATTN_MERGE_V2") && has(t27, "STRATA_TSUM") && has(t27, "STRATA_EXPDEC"));
+ CHECK(strata::core::arch_default_env("gfx1200", true).size() == 5);
+ CHECK(strata::core::arch_default_env("gfx1151", true) == strata::core::arch_default_env("gfx1151", false));
+ CHECK(strata::core::arch_default_env("gfx1100", true).empty() && strata::core::arch_default_env("gfx1100", false).empty());
+ }
+ // the decode miss split start value: 0.15 on gfx12 native packs, 0.55 under 026 or STRATA_PCIE_FRAC_DEFAULT=old; the others do not move
+ CHECK(pcie_start_frac(false, true, true, false, false) == 0.15);
+ CHECK(pcie_start_frac(false, true, true, false, true) == 0.55);
+ CHECK(pcie_start_frac(false, true, true, true, false) == 0.55);
+ CHECK(pcie_start_frac(false, true, false, false, false) == 0.55);
+ CHECK(pcie_start_frac(true, true, true, false, true) == 0.25);
+ CHECK(pcie_start_frac(true, true, true, false, false) == 0.25);
+ CHECK(pcie_start_frac(false, false, true, false, true) == 0.2);
+ CHECK(pcie_start_frac(false, false, true, false, false) == 0.2);
+ }
std::printf(fails ? "arch_defaults_test: %d FAILED\n" : "arch_defaults_test: OK\n", fails);
// ---- 0.2.7 CUDA defaults (sm120_series.hpp): which cards get which, and which never do
{
diff --git a/src/core/ple_residency_test.cpp b/src/core/ple_residency_test.cpp
index 4673b7adc..fedfb9f2d 100644
--- a/src/core/ple_residency_test.cpp
+++ b/src/core/ple_residency_test.cpp
@@ -21,6 +21,12 @@ int main() {
// (table + 8 GiB) admitted it and the expert load then failed with error 1453. Not admitted now.
check(!ple_resident_admit(45ull * GiB + (1ull << 28), table, arena, 8 * GiB), "64 GB PC with the IQ3_S arena: not admitted");
check(!ple_resident_admit(40ull * GiB, table, arena, 8 * GiB), "40 GiB: not admitted");
+ // STRATA_DEFAULTS=026: the policy does not run (v0.2.6 had none); an explicit STRATA_PLE_AUTO_RAM wins either way
+ check(ple_auto_ram_allowed(nullptr, false), "policy on by default");
+ check(!ple_auto_ram_allowed(nullptr, true), "policy off under STRATA_DEFAULTS=026");
+ check(ple_auto_ram_allowed("1", true), "STRATA_PLE_AUTO_RAM=1 wins over 026");
+ check(!ple_auto_ram_allowed("0", false), "STRATA_PLE_AUTO_RAM=0 is the old off switch");
+ check(!ple_auto_ram_allowed("0", true), "STRATA_PLE_AUTO_RAM=0 under 026");
// a PC that holds the table, the arena and 8 GiB
check(ple_resident_admit(table + arena + 8 * GiB, table, arena, 8 * GiB), "exactly table + arena + headroom is admitted");
check(!ple_resident_admit(table + arena + 8 * GiB - 1, table, arena, 8 * GiB), "one byte below is not");
diff --git a/src/core/verify.cpp b/src/core/verify.cpp
index f99dc9e8b..ac3f874a1 100644
--- a/src/core/verify.cpp
+++ b/src/core/verify.cpp
@@ -2,6 +2,7 @@
#include "strata/core/batch_rows.hpp"
#include "strata/core/sm75_series.hpp"
#include "strata/core/sm120_series.hpp"
+#include "strata/core/defaults_026.hpp"
#include "strata/kernels/gfx_arch.hpp"
#include "strata/core/verify.hpp"
#include "strata/core/pin_budget.hpp"
@@ -225,7 +226,7 @@ inline float g_route_prior() {
cudaDeviceProp p;
const bool ok = cudaGetDeviceProperties(&p, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
- per_dev[dev] = 1.0f + (ok ? strata::route_prior_default(false, p.integrated != 0, (double) p.totalGlobalMem) : 0.0f);
+ per_dev[dev] = 1.0f + (ok ? strata::route_prior_default(false, p.integrated != 0, (double) p.totalGlobalMem, strata::qwen_defaults_026()) : 0.0f);
}
return per_dev[dev] - 1.0f;
#endif
diff --git a/src/dsv41/ds4_experts_rule.hpp b/src/dsv41/ds4_experts_rule.hpp
index ae872def0..79e9c4b9b 100644
--- a/src/dsv41/ds4_experts_rule.hpp
+++ b/src/dsv41/ds4_experts_rule.hpp
@@ -9,9 +9,24 @@
#include <cstdint>
#include <algorithm>
#include <cstdlib>
+#include <cstring>
namespace strata::ds4 {
+// DS4_DEFAULTS=026: the master switch. Every default the DeepSeek engine changed since v0.2.6 goes back to what v0.2.6 did, so "off" in the app's
+// "DeepSeek speed-ups" really is version 0.2.6. Each rule below takes `v026` (the engine passes defaults_026()); an explicit per-feature variable or
+// flag (DS4_ATTN_SLAB=N, DS4_COPY_PIN=1, DS4_FAST_ATTN=1, --experts N, --prefill-chunk N, ...) still wins over it. The list, from
+// `git diff v0.2.6..f-027-int2 -- src/dsv41`: the staging ring, the prompt chunk rule, the attention slab (base and growth), the pinned copy,
+// the huge-page arena, the matrix-core attention, the drafter's cumulative cut, the 5-experts default, the store's spare slots and put, the
+// store settle after a prompt, the dense dequantizer, the F16 gate/up operand, the markov head in Q8, the head's column count, the RDNA3 WMMA GEMM.
+inline bool is_026_token(const char* v) {
+ return v != nullptr && (std::strcmp(v, "026") == 0 || std::strcmp(v, "0.2.6") == 0 || std::strcmp(v, "v0.2.6") == 0);
+}
+inline bool defaults_026() {
+ static const bool on = is_026_token(std::getenv("DS4_DEFAULTS"));
+ return on;
+}
+
constexpr uint64_t kFasterModeVramMax = 16ull << 30; // GiB of graphics memory in all, at most
constexpr int kFasterModeExperts = 5;
@@ -21,8 +36,10 @@ constexpr int kFasterModeExperts = 5;
// multi_rdna4: two or more RDNA4 cards (gfx1200 / gfx1201: R9700, RX 9000) that together hold at least half of the routed experts - the 4 x R9700 box
// the Marlin stream measured: 5 against 6 experts, 2.25 bpw, 8K prompt 1339 -> 1419 ppts (+6%) and decode 78.1 -> 81.2 tok/s (+4%), reference KL
// 0.10987 against 0.10833 and top-1 87.59% against 87.53% (the gate is 0.006). Faster mode there too, by default.
-inline int experts_per_word(int requested, uint64_t vram_bytes, int model_k, bool integrated = false, bool multi_rdna4 = false) {
+inline int experts_per_word(int requested, uint64_t vram_bytes, int model_k, bool integrated = false, bool multi_rdna4 = false,
+ bool v026 = false) {
if (model_k <= 1) return model_k;
+ if (v026) multi_rdna4 = false; // 0.2.6: Faster by default on a small card or an integrated GPU only
int n = requested;
if (n < 1) n = integrated || multi_rdna4 || (vram_bytes != 0 && vram_bytes <= kFasterModeVramMax) ? kFasterModeExperts : model_k;
if (n > model_k) n = model_k;
@@ -45,7 +62,8 @@ constexpr uint64_t kChunkInPlace4096Below = 16ull << 30;
// gguf_copy: a GGUF pack with --mmap-experts off; file_experts: the experts stay in the files; hip: a HIP build; min_vram_bytes: the
// smallest card; big: the chunk of the streamed case (the engine's kVlRows, 8192)
inline int prefill_chunk_default(bool own_default, double gpu_share, bool gguf_copy, bool file_experts, bool hip, uint64_t min_vram_bytes,
- int big = 8192, bool multi_tp = false) {
+ int big = 8192, bool multi_tp = false, bool v026 = false) {
+ if (v026) multi_tp = false; // 0.2.6: the 1024 chunk for a --tp 1 run only
// The cards hold most of the experts: the small chunk is the measured one. Two datapoints, both on 4 x R9700: with `--tp 1` (what
// `strata launch` writes for 4 or more AMD cards), share 0.86: 1024 370 against 214 tok/s at 8192; and with the engine's own default tp
// (2, pairs of cards, nothing written), where the rule used to fall through to 2048/8192: 2.25 bpw, --dspark auto, ids 5705e1164a, 8K
@@ -86,8 +104,10 @@ inline bool copy_all_fits(double lane_bytes, uint64_t ram_avail, double ram_marg
// experts), and never less than the base; the automatic growth on top of it still applies where the room is there. A unified-memory GPU
// (the caller passes env 0 there) and DS4_ATTN_SLAB=0 never take either branch. The caller passes 0 for `expert_share` in a build that is not
// HIP: that branch is the 4 x R9700 measurement.
-inline int attn_slab_rows(int env, int chunk, int base, double spare_bytes, double bytes_per_row, double expert_share = 0.0) {
+inline int attn_slab_rows(int env, int chunk, int base, double spare_bytes, double bytes_per_row, double expert_share = 0.0,
+ bool v026 = false) {
auto clampn = [&](int a) { return std::max(64, std::min(chunk, a) / 64 * 64); };
+ if (v026 && env < 0) env = 0; // 0.2.6: DS4_ATTN_SLAB unset gave the base; DS4_ATTN_SLAB=N still asks for N rows
if (env == 0) return base;
if (env > 0) return clampn(env);
int rows = base;
@@ -113,7 +133,8 @@ inline int attn_slab_rows(int env, int chunk, int base, double spare_bytes, doub
// A unified-memory GPU never takes the small ring (its datapoint is the 1200 MB one): it keeps the 16 MB "fit" rule at 1/1.3.
// `hip`: the 0.5..0.82 band and the 0.82 threshold are the 4 x R9700 measurements, so only an RDNA4 system (every device a gfx1200 or gfx1201; the parameter is named hip) takes them; any other build keeps main's
// rule there (16 MB from 1/1.3, the streamed ring below it) until a CUDA multi-card rig is measured.
-inline int staging_ring_mb(double share, double room_bytes, int n_dev, bool integrated, bool hip) {
+inline int staging_ring_mb(double share, double room_bytes, int n_dev, bool integrated, bool hip, bool v026 = false) {
+ if (v026) return share >= 1.0 / 1.3 ? 16 : 400; // 0.2.6: 16 MB where the cards hold the experts, a fixed 400 MB otherwise
const double GB = 1e9;
const double per_dev = n_dev > 0 ? room_bytes / (double) n_dev : 0.0;
const double streamed = std::min(1200.0, std::max(400.0, room_bytes / GB * 64.0));
@@ -132,4 +153,70 @@ inline int experts_test_override(int chosen, int model_k) {
return chosen;
}
+
+// The base of the attention slab, MB of q (rows = MB / the heads' width, rounded to 64): STRATA_DS4_A_MB when given; 0.2.6 and a discrete card 8 MB;
+// a unified-memory GPU 32 MB (main's 3133160ed, Strix Halo).
+inline size_t attn_slab_base_mb(bool unified, size_t env_mb, bool v026 = false) {
+ if (env_mb != 0) return env_mb;
+ return !v026 && unified ? 32 : 8;
+}
+
+// DS4_COPY_PIN (pin the CPU lane's RAM copy so the prompt DMAs it in place): env -1 unset, else 0 / 1. Explicit wins; 0.2.6: opt-in, so unset = off;
+// 0.2.7: on when the whole arena is on explicit huge pages OR (RDNA4 and the cards hold at least half the experts).
+inline bool copy_pin_default(int env, bool arena_all_huge, bool rdna4, double share, bool have_chunks, bool v026 = false) {
+ if (env >= 0) return env != 0;
+ if (v026) return false;
+ return (arena_all_huge || (rdna4 && share >= 0.5)) && have_chunks;
+}
+
+// DS4_COPY_HUGETLB (the copy arena on explicit 2 MB pages): env -1 unset, else 0 / 1; 0.2.6: opt-in; 0.2.7: on when the reserved pool already holds the whole copy.
+inline bool copy_hugetlb_default(int env, double pool_free_bytes, double copy_bytes, bool v026 = false) {
+ if (env >= 0) return env != 0;
+ if (v026) return false;
+ 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) {
+ if (env >= 0) return env != 0;
+ return !v026 && gfx12;
+}
+
+// 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.
+inline float dspark_cum_value(bool has_env, float env_value, bool gfx12, bool v026 = false) {
+ if (has_env) return env_value;
+ return !v026 && gfx12 ? 0.5f : 0.0f;
+}
+
+// DS4_STORE_SPARE (the RAM store takes the spare slots) and DS4_STORE_PUT (an expert the VRAM cache gives back is put into the store from memory):
+// env -1 unset, else 0 / 1; 0.2.6: neither existed (off); 0.2.7: on.
+inline bool store_feature_default(int env, bool v026 = false) {
+ if (env >= 0) return env != 0;
+ return !v026;
+}
+
+// DS4_SETTLE_STORE (the RAM store's post-prompt preload) when the variable is unset: 0.2.6 ran it (1), 0.2.7 does not (0: it cost a 4K prompt 4.7 s).
+inline float settle_store_default(bool v026 = false) { return v026 ? 1.0f : 0.0f; }
+// The preload skips the experts the CPU lane already holds as a RAM copy (0.2.7); 0.2.6 did not.
+inline bool settle_skips_copy_experts(bool v026 = false) { return !v026; }
+
+// The chunked prompt's dense dequantizer: the row-per-lane dq_rows_kernel (0.2.6's values, bit for bit) or dq_rows_kernel2 (the coalesced transpose).
+// DS4_DQ_OLD (-1 unset, else 0 / 1) wins; 0.2.6: the old one; 0.2.7: the old one on gfx11 only.
+inline bool dq_old_default(int env, bool gfx11, bool v026 = false) {
+ if (env >= 0) return env != 0;
+ return v026 || gfx11;
+}
+
+// The head's columns a pass for a GGUF head (DS4_HEAD_PER overrides): 0.2.6 4, 0.2.7 8 (the same logits per column).
+inline int head_per_default(bool v026 = false) { return v026 ? 4 : 8; }
+// The drafter's markov head quantised to Q8_0 as it loads (0.2.7) or read as F16 (0.2.6).
+inline bool markov_head_q8_default(bool v026 = false) { return !v026; }
+// The gate/up tiles read the layer's F16 copy of the activations (0.2.7, bit-identical) or the F32 rows (0.2.6).
+inline bool gate_up_x16_default(bool v026 = false) { return !v026; }
+// STRATA_DENSE_PFGEMM (the RDNA3 WMMA dense GEMM before hipBLAS; -1 unset, else 0 / 1): 0.2.6 did not have it.
+inline bool dense_pfgemm_default(int env, bool v026 = false) {
+ if (env >= 0) return env != 0;
+ return !v026;
+}
+
} // namespace strata::ds4
diff --git a/src/dsv41/ds4_iq.cu b/src/dsv41/ds4_iq.cu
index 931e3d33b..da5e8e5d7 100644
--- a/src/dsv41/ds4_iq.cu
+++ b/src/dsv41/ds4_iq.cu
@@ -4,6 +4,7 @@
// ggml's (ggml-common.h, MIT, third_party/ggml/LICENSE); the sign and grid tricks are llama.cpp's vecdotq.cuh.
#include "ds4_iq.cuh"
#include "ds4_numerics.cuh"
+#include "ds4_experts_rule.hpp"
#include <cuda_fp16.h>
#if !defined(STRATA_USE_HIP)
@@ -1393,7 +1394,10 @@ __global__ void __launch_bounds__(kThreads) dq_rows_kernel(const uint8_t* __rest
// prompt 79.5 -> 88.5 tok/s with it, so a gfx11 device defaults to it. DS4_DQ_OLD=1 forces it anywhere, DS4_DQ_OLD=0 forces kernel2
// anywhere. The detection is the device's gcnArchName (HIP only; a CUDA build has no gfx11). Decided once per device.
static bool dq_use_old_kernel() {
- if (const char* e = std::getenv("DS4_DQ_OLD"); e != nullptr && *e != '\0') return std::atoi(e) != 0;
+ const char* dq_env = std::getenv("DS4_DQ_OLD");
+ const int env = dq_env != nullptr && *dq_env != '\0' ? (std::atoi(dq_env) != 0 ? 1 : 0) : -1;
+ const bool v026 = strata::ds4::defaults_026(); // DS4_DEFAULTS=026: 0.2.6's row-per-lane dequantizer (the same values, bit for bit)
+ if (env >= 0 || v026) return strata::ds4::dq_old_default(env, false, v026);
#if defined(STRATA_USE_HIP)
static std::atomic<int> cache[64]; // 0 unknown, 1 no, 2 yes
int dev = 0;
diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu
index a05091f01..baf63dccd 100644
--- a/src/dsv41/ds4_kernels.cu
+++ b/src/dsv41/ds4_kernels.cu
@@ -7,6 +7,7 @@
#include "ds4_q6k.cuh"
#include "ds4_attn_split.cuh"
#include "ds4_wmma.cuh"
+#include "ds4_experts_rule.hpp"
#include <cuda_fp16.h>
@@ -2056,11 +2057,10 @@ bool fast_attn_enabled() {
const char* e = std::getenv("DS4_FAST_ATTN");
return e == nullptr ? -1 : (std::atoi(e) != 0 ? 1 : 0);
}();
- if (env >= 0) return env == 1;
#if defined(STRATA_USE_HIP)
- return device_is_gfx12();
+ return strata::ds4::fast_attn_default(env, device_is_gfx12(), strata::ds4::defaults_026());
#else
- return false;
+ return strata::ds4::fast_attn_default(env, 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 2c11b8761..3b259b2af 100644
--- a/src/dsv41/ds4_main.cpp
+++ b/src/dsv41/ds4_main.cpp
@@ -19,6 +19,7 @@
// read stops there for a checkpoint, so a request behind the same start - another agent - goes back to it instead of
// reading it again (also without slots). STRATA_DS4_REUSE=0 turns every reuse off (each request reads its whole prompt).
#include "ds4_model.hpp"
+#include "ds4_experts_rule.hpp"
#include "ds4_os.hpp"
#include "ds4_packinfo.hpp"
#include "ds4_slotmeta.hpp"
@@ -158,8 +159,8 @@ static int g_round_nd = 0;
// Strix keeps 0 until it is; the CUDA measurements in 0.2.7 had it flat, so CUDA keeps 0. STRATA_DS4_DSPARK_CUM overrides everywhere.
float dspark_cum_default(const strata::ds4::Model& m) {
static const char* const e = std::getenv("STRATA_DS4_DSPARK_CUM");
- if (e != nullptr) return (float) std::atof(e);
- return m.gpus_are_gfx12() ? 0.5f : 0.0f;
+ return strata::ds4::dspark_cum_value(e != nullptr, e != nullptr ? (float) std::atof(e) : 0.0f, m.gpus_are_gfx12(),
+ strata::ds4::defaults_026());
}
// One round of decoding after `tok` (the token at pos(), not fed yet): with the drafter, its drafts while their
diff --git a/src/dsv41/ds4_model.cu b/src/dsv41/ds4_model.cu
index 9c3596441..91d29a266 100644
--- a/src/dsv41/ds4_model.cu
+++ b/src/dsv41/ds4_model.cu
@@ -85,6 +85,12 @@ constexpr bool kHipBuild = true;
constexpr bool kHipBuild = false;
#endif
+// an environment variable as 0 / 1, or -1 when it is not set (the rules in ds4_experts_rule.hpp take this form)
+int env_tri(const char* name) {
+ const char* v = std::getenv(name);
+ return v != nullptr ? (std::atoi(v) != 0 ? 1 : 0) : -1;
+}
+
double now_ms() {
return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now().time_since_epoch()).count();
}
@@ -2067,7 +2073,7 @@ struct Model::Impl {
#else
const bool hip_build = false;
#endif
- const int rule_chunk = prefill_chunk_default(own_default, gpu_expert_share(), gguf_copy, file_experts, hip_build, vmin_bytes, kVlRows, multi_tp);
+ const int rule_chunk = prefill_chunk_default(own_default, gpu_expert_share(), gguf_copy, file_experts, hip_build, vmin_bytes, kVlRows, multi_tp, defaults_026());
chunk = prompt_par ? (o.prefill_chunk >= 0 ? o.prefill_chunk : rule_chunk) : 0;
if (prompt_par && o.prefill_chunk < 0 && rule_chunk == 4096 && gguf_copy)
std::fprintf(stderr, "ds4: prompts in chunks of 4096 tokens (the experts are copied into RAM, %.0f GiB of graphics memory; --prefill-chunk N changes it)\n",
@@ -2134,7 +2140,7 @@ struct Model::Impl {
}
// two or more RDNA4 cards holding at least half of the experts (the 4 x R9700 class): Faster by default too
const bool multi_rdna4 = rdna4() && devs.size() >= 2 && gpu_expert_share() >= 0.5;
- const int n = experts_test_override(experts_per_word(o.experts, vram_all, l.k_exp, integrated, multi_rdna4), l.k_exp);
+ const int n = experts_test_override(experts_per_word(o.experts, vram_all, l.k_exp, integrated, multi_rdna4, defaults_026()), l.k_exp);
experts_used = n;
if (n < l.k_exp)
std::fprintf(stderr, "ds4: experts per word: %d (%s; full quality: --experts %d)\n", n,
@@ -3002,7 +3008,7 @@ struct Model::Impl {
cudaDeviceProp ip{};
if (cudaGetDeviceProperties(&ip, d.id) == cudaSuccess && ip.integrated != 0) unified = true;
}
- const size_t mb = (size_t) strata::ds4::staging_ring_mb(exp_b > 0 ? share : 0.0, room, (int) devs.size(), unified, rdna4());
+ const size_t mb = (size_t) strata::ds4::staging_ring_mb(exp_b > 0 ? share : 0.0, room, (int) devs.size(), unified, rdna4(), defaults_026());
if (o.verbose)
std::fprintf(stderr, "ds4: staging ring: experts %.1f GB, VRAM room %.1f GB, dense %.1f GB -> %d MB\n", exp_b / 1e9,
room / 1e9, other_b / 1e9, (int) mb);
@@ -3039,7 +3045,7 @@ struct Model::Impl {
const char* v = std::getenv("STRATA_DS4_A_MB");
return (size_t) (v != nullptr ? std::max(1, std::atoi(v)) : 0);
}();
- const size_t a_mb = a_mb_env != 0 ? a_mb_env : (unified ? 32 : 8);
+ const size_t a_mb = strata::ds4::attn_slab_base_mb(unified, a_mb_env, defaults_026());
c.A = std::max(64, (int) ((a_mb << 20) / (size_t) HQ) / 64 * 64);
// DS4_ATTN_SLAB=N: the attention slab's rows. The dense projections (q_b, wo_a/b) are dequantized and GEMM'd
// once a slab, so a slab of 256 rows dequantizes the same weights 32 times for an 8K prompt (measured: the
@@ -3062,7 +3068,7 @@ struct Model::Impl {
const int base = c.A;
// one rule (ds4_experts_rule.hpp: attn_slab_rows): the chunk's whole slab (<= 1024 rows) where the cards hold half the
// experts or more (4 x R9700, +9% prompt), up to 2048 rows where the VRAM is spare, the base otherwise
- c.A = strata::ds4::attn_slab_rows(env, chunk, base, spare, bpr, rdna4() ? share : 0.0);
+ c.A = strata::ds4::attn_slab_rows(env, chunk, base, spare, bpr, rdna4() ? share : 0.0, defaults_026());
if (env < 0 && c.A > base) {
slab_auto_grew_ = true;
if (di == 0 && o.verbose) {
@@ -3153,10 +3159,7 @@ struct Model::Impl {
std::string& err) {
if (rows <= 0) return true;
#if defined(STRATA_USE_HIP) // (wmma_gemm.cu is part of the AMD builds only: a CUDA build has no such kernel and keeps cuBLAS)
- static const bool pf = [] {
- const char* v = std::getenv("STRATA_DENSE_PFGEMM");
- return v == nullptr || v[0] != '0';
- }();
+ static const bool pf = strata::ds4::dense_pfgemm_default(env_tri("STRATA_DENSE_PFGEMM"), defaults_026());
#endif
const int cols = std::max(128, (int) std::min<size_t>((size_t) m.n, c.w16_elems / (size_t) m.k) / 128 * 128);
for (int c0 = 0; c0 < m.n; c0 += cols) {
@@ -3790,7 +3793,7 @@ struct Model::Impl {
sa.limit = g.lim;
// gate / up read the layer's F16 copy of the activations (the same rounding the tiles make for their
// shared tile): with 18-36 column blocks an expert the F32 rows were read that many times
- sa.x16 = c.x16;
+ sa.x16 = strata::ds4::gate_up_x16_default(defaults_026()) ? c.x16 : nullptr;
EkMark ek{};
const bool ekp = prof_chunk;
if (ekp) {
@@ -3965,7 +3968,9 @@ struct Model::Impl {
return false;
}
if (!dalloc(d, d_mk_embed, te->bytes / 2, err, acct) || !upload(d, *te, d_mk_embed, err) ||
- !mk_head_q8(d, Z + "markov_head.head.weight", d_mk_head_q8, err, acct))
+ (strata::ds4::markov_head_q8_default(defaults_026())
+ ? !mk_head_q8(d, Z + "markov_head.head.weight", d_mk_head_q8, err, acct)
+ : !f16raw(d, Z + "markov_head.head.weight", d_mk_head, err, acct))) // (0.2.6: the head as F16)
return false;
}
}
@@ -4450,11 +4455,7 @@ struct Model::Impl {
// 0.2.7: DS4_COPY_HUGETLB unset = ON when the reserved pool already holds the whole copy (HugePages_Free), else the
// ordinary arena exactly as before; =0 is the off switch, =1 asks for it anyway (a smaller pool is used, the rest warns).
const uint64_t pool_free = os::huge_free_bytes();
- const bool huge_arena = [&] {
- const char* e = std::getenv("DS4_COPY_HUGETLB");
- if (e != nullptr) return std::atoi(e) != 0;
- return pool_free > 0 && (double) pool_free >= all;
- }();
+ const bool huge_arena = strata::ds4::copy_hugetlb_default(env_tri("DS4_COPY_HUGETLB"), (double) pool_free, all, defaults_026());
if (huge_arena && std::getenv("DS4_COPY_HUGETLB") == nullptr)
std::fprintf(stderr, "ds4: the reserved huge-page pool (%.1f GB free) holds the whole copy (%.1f GB): the arena on 2 MB pages "
"(DS4_COPY_HUGETLB=0 keeps the ordinary arena)\n", (double) pool_free / 1e9, all / 1e9);
@@ -4620,8 +4621,8 @@ struct Model::Impl {
// THP arena registers 4 KB pages and the DMA rate was erratic on the 12 GB cell: 11.9 s one prompt, 30.4 s the next), or (b) the
// cards hold at least half the routed experts on RDNA4 (4 x R9700: the pin was reliable in 4/4 runs there, see above). =0 is the off
// switch, =1 pins any arena.
- const char* cp = std::getenv("DS4_COPY_PIN");
- const bool pin_copies = cp != nullptr ? std::atoi(cp) != 0 : ((arena_all_huge || (rdna4() && gpu_expert_share() >= 0.5)) && !ram_chunks.empty());
+ const bool pin_copies = strata::ds4::copy_pin_default(env_tri("DS4_COPY_PIN"), arena_all_huge, rdna4(), gpu_expert_share(),
+ !ram_chunks.empty(), defaults_026());
if (pin_copies) {
const bool ro = std::getenv("DS4_COPY_PIN_RO") != nullptr && std::atoi(std::getenv("DS4_COPY_PIN_RO")) != 0;
const double tr = now_ms();
@@ -5013,7 +5014,7 @@ struct Model::Impl {
// up its coldest to the CPU lane, and a store without them reads each from the SSD while the CPU lane waits - 1.8 misses a
// token on the 251 GB R9700 box, 2.9 ms of a 49 ms token), then the lane's experts the profile never saw. Last in the list: they
// take only the slots the likely ones left. DS4_STORE_SPARE=0: off.
- if (!(std::getenv("DS4_STORE_SPARE") && std::atoi(std::getenv("DS4_STORE_SPARE")) == 0)) {
+ if (strata::ds4::store_feature_default(env_tri("DS4_STORE_SPARE"), defaults_026())) {
std::vector<std::pair<double, std::pair<int, int>>> vr, zero;
for (const Layer& l : L) {
if (l.il >= g.nl) continue;
@@ -5029,7 +5030,7 @@ struct Model::Impl {
}
const double t0 = now_ms();
// (with the spare experts in the list the reserve is theirs: last in the list, so the oldest ticks, so the first a demand read replaces)
- const bool spare_on = !(std::getenv("DS4_STORE_SPARE") && std::atoi(std::getenv("DS4_STORE_SPARE")) == 0);
+ const bool spare_on = strata::ds4::store_feature_default(env_tri("DS4_STORE_SPARE"), defaults_026());
const size_t leave = spare_on ? 0 : (size_t) (std::getenv("DS4_STORE_RESERVE") ? std::atoi(std::getenv("DS4_STORE_RESERVE")) : 192) + 64;
// The first 48 GB (what a store held before it could take every expert) are read before the first token; the rest of the
// hottest-first list is read after it, in pieces of 128 experts on a thread of its own, behind the model's own reads (a
@@ -6417,7 +6418,7 @@ struct Model::Impl {
}
if (got) blob_to_ram(l, sw_b, sw.ram);
else sw.ram = -1; // (back to the file's pages then)
- } else if (ok && store && l.nm == 1 && l.lay.fmt == gg::kFmtMXFP4 && !(std::getenv("DS4_STORE_PUT") && std::atoi(std::getenv("DS4_STORE_PUT")) == 0)) {
+ } else if (ok && store && l.nm == 1 && l.lay.fmt == gg::kFmtMXFP4 && strata::ds4::store_feature_default(env_tri("DS4_STORE_PUT"), defaults_026())) {
// `out` goes back to the CPU lane: its blob is in VRAM, so it is copied into a store slot now - the lane would otherwise read it from
// the SSD and wait for it (1-2 misses a token on the 251 GB R9700 box). DS4_STORE_PUT=0: off.
uint8_t* dst = store->put_begin(l.il, sw.out);
@@ -6481,7 +6482,7 @@ struct Model::Impl {
// The RAM store's preload after a chunked prompt is off by default: measured on Strix Halo (code fixture, prompt +
// 256 tokens, 3 runs a side) it costs the prompt 4.7 s and the decode that follows gains nothing (13.9/14.4 s with it
// against 14.2 s without). The swaps above are what the decode actually uses; DS4_SETTLE_STORE=1 restores it.
- if (store && env_f("DS4_SETTLE_STORE", 0.0f) != 0.0f) { // the RAM store too: a window prompt fills it through the CPU
+ if (store && env_f("DS4_SETTLE_STORE", strata::ds4::settle_store_default(defaults_026())) != 0.0f) { // the RAM store too: a window prompt fills it through the CPU
// lane's picks, a chunked one streams past it - the hottest CPU-lane experts of the prompt into its free slots
// (copy_mode: an expert already in the CPU lane's RAM copy gains nothing from a second copy of the same bytes -
// measured on the R9700 12 GB cell: 4152 such experts, 40 GB read at 6.4 GB/s, 6.2 s of an 8K prompt, 0.0 store
@@ -6490,7 +6491,7 @@ struct Model::Impl {
for (const Layer& l : L) {
if (l.mtp) continue;
for (int e = 0; e < l.n_exp; ++e)
- if (l.slot[(size_t) e] < 0 && !(copy_mode && !l.ram.empty() && l.ram[(size_t) e] >= 0) &&
+ if (l.slot[(size_t) e] < 0 && !(strata::ds4::settle_skips_copy_experts(defaults_026()) && copy_mode && !l.ram.empty() && l.ram[(size_t) e] >= 0) &&
l.heat[(size_t) e] >= 4.0f) hot.push_back({l.heat[(size_t) e], {l.il, e}});
}
std::sort(hot.begin(), hot.end(), [](const auto& a, const auto& b) { return a.first > b.first; });
@@ -7121,7 +7122,8 @@ struct Model::Impl {
sp.seed = dq_seed;
}
for (int i = 0; i < T; ++i) { // the markov bias of the token before, then that position's draft
- markov_add_q8(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head_q8, d_ints + i, V, R, hd.st);
+ if (d_mk_head_q8 != nullptr) markov_add_q8(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head_q8, d_ints + i, V, R, hd.st);
+ else markov_add(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head, d_ints + i, V, R, hd.st);
if (drafts_q) {
sp.counter = dq_counter + (uint64_t) i;
strata::dsv41k::sample_draft(hd.logits + (size_t) i * V, 1, V, sp, d_specq + i, d_ints + i + 1, hd.st);
@@ -8803,7 +8805,7 @@ struct Model::Impl {
// for a whole one, each pass reading the whole share; a GGUF's: 8, so that every window the engine can build (rows
// <= kWin = 8) walks the head once instead of twice - measured on the drafter's fixed T=5: 4.55 -> 2.83 ms, its
// round 14.49 -> 13.46; the verify window's head 3.48 -> 2.68 ms, the same logits. DS4_HEAD_PER overrides.)
- const int per = d.head.fmt != 0 ? (std::getenv("DS4_HEAD_PER") ? std::atoi(std::getenv("DS4_HEAD_PER")) : 8)
+ const int per = d.head.fmt != 0 ? (std::getenv("DS4_HEAD_PER") ? std::atoi(std::getenv("DS4_HEAD_PER")) : strata::ds4::head_per_default(defaults_026()))
: std::max(1, x3::mv_cols(d.head));
for (int c = 0; c < rows; c += per)
if (!mv(d, {job(d.head, xn + (size_t) c * D, out + (size_t) c * ld, std::min(per, rows - c), D, ld)}, err))
diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu
index ad1fcbd34..6f6f32321 100644
--- a/src/kernels/cuda/fused_gr.cu
+++ b/src/kernels/cuda/fused_gr.cu
@@ -2,6 +2,7 @@
#include "strata/core/emulate.hpp"
#include "strata/core/sm75_series.hpp"
#include "strata/core/sm120_series.hpp"
+#include "strata/core/defaults_026.hpp"
#include "strata/kernels/q8_1_finite.hpp" // #606: q8_1_ds
#include "strata/core/geometry.hpp"
#include "strata/kernels/fused_gr.hpp"
@@ -461,7 +462,7 @@ bool gr_up_wide_on() {
int major = 0, minor = 0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
- per_dev[dev] = strata::sm120_default(major, minor) ? 2 : 1;
+ per_dev[dev] = strata::gr_up_wide_default(false, major, minor, strata::qwen_defaults_026()) ? 2 : 1;
cudaGetLastError(); // drop what an attribute query on a CPU-only box leaves behind
}
return per_dev[dev] == 2;
@@ -2322,7 +2323,7 @@ static bool gr_v3_default_on(int dev) {
cudaDeviceProp p;
const bool ok = cudaGetDeviceProperties(&p, dev) == cudaSuccess;
if (!ok) cudaGetLastError();
- per_dev[dev] = ok && strata::gr_v3_default(false, p.major, p.minor, p.integrated != 0, (double) p.totalGlobalMem) ? 2 : 1;
+ per_dev[dev] = ok && strata::gr_v3_default(false, p.major, p.minor, p.integrated != 0, (double) p.totalGlobalMem, strata::qwen_defaults_026()) ? 2 : 1;
}
return per_dev[dev] == 2;
#endif
diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu
index f2b2d0a06..82b199b1e 100644
--- a/src/kernels/cuda/qsa_prompt_attn.cu
+++ b/src/kernels/cuda/qsa_prompt_attn.cu
@@ -1,6 +1,7 @@
// src/kernels/cuda/qsa_prompt_attn.cu - see include/strata/kernels/qsa_prompt_attn.hpp.
#include "strata/core/emulate.hpp"
#include "strata/core/sm120_series.hpp"
+#include "strata/core/defaults_026.hpp"
#include "strata/core/sm75_series.hpp"
#include "strata/core/geometry.hpp"
#include "strata/core/gfx12_platform_defaults.hpp"
@@ -2428,7 +2429,7 @@ bool qsa_prompt_attn_batch(const float* q, const QsaAttnPools& pools, const int3
const char* v = std::getenv("STRATA_PROMPT_ATTN_IMMA");
g_pa_imma = v == nullptr ? 2 : (v[0] == '1' ? 1 : 0); // 2: the default (on where the kernel can run)
}
- if (!turing && (g_pa_imma == 1 || (g_pa_imma == 2 && strata::prompt_attn_imma_default(false, 80)))) return launch_i8v3(q, pools, ids, steps, cap, s, attn, n_q, st);
+ if (!turing && (g_pa_imma == 1 || (g_pa_imma == 2 && strata::prompt_attn_imma_default(false, 80, strata::qwen_defaults_026())))) return launch_i8v3(q, pools, ids, steps, cap, s, attn, n_q, st);
return launch_i8(q, pools, ids, steps, cap, s, attn, n_q, st);
}
if (!pools.k_pool || !pools.v_pool) return false;
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index 43b9bcb5a..4e871b0d2 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -30,6 +30,7 @@
#include "strata/core/session_save_reclaim.hpp"
#include "strata/core/conversation_memory.hpp"
#include "strata/core/ple_residency.hpp"
+#include "strata/core/defaults_026.hpp"
#include "strata/core/coupled_draft.hpp"
#include "strata/core/expert_source.hpp"
#include "strata/core/foresight_swap.hpp"
@@ -3585,8 +3586,7 @@ int main(int argc, char** argv) {
const bool pf_old = pfd != nullptr && std::strcmp(pfd, "old") == 0;
// 0.2.7: gfx12 native packs start at 0.15 (see pcie_share_gfx12_default above); other cards and
// STRATA_PCIE_FRAC_DEFAULT=old keep the x16 share measured for them.
- const double base = nvfp4_pack ? 0.25
- : native_pack ? (pcie_share_gfx12_default() && !pf_old ? 0.15 : 0.55) : 0.2;
+ const double base = strata::pcie_start_frac(nvfp4_pack, native_pack, pcie_share_gfx12_default(), pf_old, strata::qwen_defaults_026());
std::string bursts;
#if !defined(STRATA_USE_HIP) && defined(_WIN32)
// Windows: opt-in (STRATA_PCIE_AUTO_CANON=1); an RTX 5070 decoded a short Q2_0 answer 3% slower with it, code 2.5% faster
@@ -4095,7 +4095,7 @@ int main(int argc, char** argv) {
if (pio.mode == strata::kernels::PleIo::Direct && !o.ple_io_explicit) {
const strata::kernels::PleIoOptions direct_pio = pio;
const char* auto_ram = std::getenv("STRATA_PLE_AUTO_RAM");
- const bool allowed = auto_ram == nullptr || std::atoi(auto_ram) != 0;
+ const bool allowed = strata::core::ple_auto_ram_allowed(auto_ram, strata::qwen_defaults_026());
const uint64_t need = ple_table.table_bytes();
const auto available = strata::core::available_host_bytes();
uint64_t experts_ram = 0; // every routed expert's blob, the arena the engine copies into RAM at start
diff --git a/tests/dsv41/experts_rule_test.cpp b/tests/dsv41/experts_rule_test.cpp
index 6fb5a1d81..895df7f02 100644
--- a/tests/dsv41/experts_rule_test.cpp
+++ b/tests/dsv41/experts_rule_test.cpp
@@ -215,6 +215,98 @@ int main() {
// a 192 GB Windows PC with a 4 GB page file: 150 GB free RAM but only 100 GB of commit room: no
CHECK_EQ(copy_all_fits(108 * GB, (uint64_t) (150 * GB), margin, 100 * GB), 0);
}
+ // ---- DS4_DEFAULTS=026: every rule gives v0.2.6's answer (the last argument v026 = true); an explicit variable / flag still wins; the six old
+ // DS4_*=0 switches keep working with v026 = false
+ {
+ using namespace strata::ds4;
+ const double GB = 1e9;
+ CHECK_EQ(is_026_token("026"), 1);
+ CHECK_EQ(is_026_token("0.2.6"), 1);
+ CHECK_EQ(is_026_token("v0.2.6"), 1);
+ CHECK_EQ(is_026_token("0"), 0);
+ CHECK_EQ(is_026_token(""), 0);
+ CHECK_EQ(is_026_token("027"), 0);
+ CHECK_EQ(is_026_token(nullptr), 0);
+ // the 5-experts default: 4 x R9700 goes back to 6; a small card and an integrated GPU were Faster in 0.2.6 already; --experts wins
+ CHECK_EQ(experts_per_word(-1, 4 * 32 * GiB, 6, false, true, true), 6);
+ CHECK_EQ(experts_per_word(-1, 4 * 32 * GiB, 6, false, true, false), 5);
+ CHECK_EQ(experts_per_word(-1, 12 * GiB, 6, false, false, true), 5);
+ CHECK_EQ(experts_per_word(-1, 91 * GiB, 6, true, false, true), 5);
+ CHECK_EQ(experts_per_word(5, 4 * 32 * GiB, 6, false, true, true), 5);
+ // the chunk rule: the multi-card tp run loses the 1024; a --tp 1 run keeps it (0.2.6 had it); an explicit --prefill-chunk is not this rule
+ CHECK_EQ(prefill_chunk_default(false, 0.86, false, true, true, 32 * GiB, 8192, true, true), 8192);
+ CHECK_EQ(prefill_chunk_default(false, 0.86, false, true, true, 32 * GiB, 8192, true, false), 1024);
+ CHECK_EQ(prefill_chunk_default(true, 0.86, false, true, true, 32 * GiB, 8192, true, true), 1024);
+ CHECK_EQ(prefill_chunk_default(false, 0.30, false, false, false, 24 * GiB, 8192, true, true), 2048);
+ // the slab: the base 8 MB everywhere, no growth, no whole-chunk slab; DS4_ATTN_SLAB=N (env N) and =0 still do what they say
+ CHECK_EQ(attn_slab_base_mb(true, 0, true), 8);
+ CHECK_EQ(attn_slab_base_mb(true, 0, false), 32);
+ CHECK_EQ(attn_slab_base_mb(false, 0, false), 8);
+ CHECK_EQ(attn_slab_base_mb(false, 0, true), 8);
+ CHECK_EQ(attn_slab_base_mb(true, 16, true), 16); // STRATA_DS4_A_MB wins
+ CHECK_EQ(attn_slab_rows(-1, 8192, 256, 1e18, 377000.0, 1.0, true), 256); // spare room: the 0.2.6 slab
+ CHECK_EQ(attn_slab_rows(-1, 1024, 256, -5.0e9, 377000.0, 0.77, true), 256); // the 4 x R9700 whole-chunk slab: off
+ CHECK_EQ(attn_slab_rows(1024, 1024, 256, -5.0e9, 377000.0, 0.77, true), 1024); // DS4_ATTN_SLAB=1024 wins
+ CHECK_EQ(attn_slab_rows(0, 8192, 256, 1e18, 377000.0, 1.0, true), 256);
+ CHECK_EQ(attn_slab_rows(0, 8192, 256, 1e18, 377000.0, 1.0, false), 256); // the old DS4_ATTN_SLAB=0 switch
+ // the staging ring: 16 MB where the cards hold the experts (>= 1/1.3), a fixed 400 MB below, whatever the platform
+ CHECK_EQ(staging_ring_mb(0.86, 4 * 30 * GB, 4, false, true, true), 16);
+ CHECK_EQ(staging_ring_mb(0.77, 4 * 31 * GB, 4, false, true, true), 16);
+ CHECK_EQ(staging_ring_mb(0.72, 4 * 31 * GB, 4, false, true, true), 400);
+ CHECK_EQ(staging_ring_mb(0.06, 10 * GB, 1, false, false, true), 400);
+ CHECK_EQ(staging_ring_mb(0.30, 18.75 * GB, 1, true, false, true), 400); // Strix Halo: not 1200
+ CHECK_EQ(staging_ring_mb(0.0, 0.0, 0, false, false, true), 400);
+ // the pinned copy and the huge-page arena: opt-in again; =1 / =0 win
+ CHECK_EQ(copy_pin_default(-1, true, true, 0.8, true, true), 0);
+ CHECK_EQ(copy_pin_default(-1, true, true, 0.8, true, false), 1);
+ CHECK_EQ(copy_pin_default(1, false, false, 0.0, false, true), 1);
+ CHECK_EQ(copy_pin_default(0, true, true, 0.8, true, false), 0); // the old DS4_COPY_PIN=0
+ CHECK_EQ(copy_pin_default(-1, false, true, 0.5, true, false), 1);
+ CHECK_EQ(copy_pin_default(-1, false, true, 0.49, true, false), 0);
+ CHECK_EQ(copy_pin_default(-1, false, false, 0.9, true, false), 0);
+ CHECK_EQ(copy_pin_default(-1, true, false, 0.0, false, false), 0); // nothing to pin
+ CHECK_EQ(copy_hugetlb_default(-1, 120 * GB, 100 * GB, true), 0);
+ CHECK_EQ(copy_hugetlb_default(-1, 120 * GB, 100 * GB, false), 1);
+ 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 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);
+ CHECK_EQ((int) (dspark_cum_value(false, 0.0f, false, false) * 100), 0);
+ CHECK_EQ((int) (dspark_cum_value(true, 0.7f, true, true) * 100), 70);
+ CHECK_EQ((int) (dspark_cum_value(true, 0.0f, true, false) * 100), 0);
+ // the store: spare slots and put off, the post-prompt settle back on (and without the copy-mode skip); the old =0 switches keep working
+ CHECK_EQ(store_feature_default(-1, true), 0);
+ CHECK_EQ(store_feature_default(-1, false), 1);
+ CHECK_EQ(store_feature_default(1, true), 1);
+ CHECK_EQ(store_feature_default(0, false), 0); // the old DS4_STORE_SPARE=0 / DS4_STORE_PUT=0
+ CHECK_EQ((int) settle_store_default(true), 1);
+ CHECK_EQ((int) settle_store_default(false), 0);
+ CHECK_EQ(settle_skips_copy_experts(true), 0);
+ CHECK_EQ(settle_skips_copy_experts(false), 1);
+ // the dense dequantizer, the head, the drafter's markov head, the F16 operand, the RDNA3 GEMM
+ CHECK_EQ(dq_old_default(-1, false, true), 1);
+ CHECK_EQ(dq_old_default(-1, false, false), 0);
+ CHECK_EQ(dq_old_default(-1, true, false), 1);
+ CHECK_EQ(dq_old_default(0, true, true), 0); // DS4_DQ_OLD=0 wins
+ CHECK_EQ(head_per_default(true), 4);
+ CHECK_EQ(head_per_default(false), 8);
+ CHECK_EQ(markov_head_q8_default(true), 0);
+ CHECK_EQ(markov_head_q8_default(false), 1);
+ CHECK_EQ(gate_up_x16_default(true), 0);
+ CHECK_EQ(gate_up_x16_default(false), 1);
+ CHECK_EQ(dense_pfgemm_default(-1, true), 0);
+ CHECK_EQ(dense_pfgemm_default(-1, false), 1);
+ CHECK_EQ(dense_pfgemm_default(1, true), 1);
+ CHECK_EQ(dense_pfgemm_default(0, false), 0);
+ }
if (fails == 0) std::printf("experts rule: all checks passed\n");
return fails == 0 ? 0 : 1;
}