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++
native experts without AVX2: Q2_0 layers on ggml-cpu, every AVX2 kernel gated (#595)
4EverBuilder3f32e4b66a9f
diff --git a/include/strata/kernels/cpu/expert_layout.hpp b/include/strata/kernels/cpu/expert_layout.hppindex 9a8b99183..540ccabdb 100644--- a/include/strata/kernels/cpu/expert_layout.hpp+++ b/include/strata/kernels/cpu/expert_layout.hpp@@ -47,6 +47,10 @@ bool cpu_avx512_ok();/// Whether this CPU (and its OS) runs the AVX2 kernels (AVX, AVX2, FMA, F16C): the floor of every expert kernel/// (q2_avx2.cpp, iq_avx2.cpp, and ggml-cpu in the portable build). STRATA_FORCE_AVX2 does not change it.bool cpu_avx2_ok();+/// Whether a native pack's layer of this ggml type runs on Strata's own Q2_0 kernels (AVX2 / AVX-512). On a+/// CPU without AVX2 (a native, non-portable build: ggml-cpu compiled for this CPU's SSE) a Q2_0 layer takes+/// ggml-cpu's own Q2_0 vec_dot like every other native type: slower, but it runs.+inline bool q2_native_kernels(int type) { return type == 42 && cpu_avx2_ok(); }/// The CPU's brand string (CPUID 0x80000002..4), for messages; "unknown" when it has none.std::string cpu_name();/// Q2_0 GGUF rows / activation quantizer on the kernels this CPU has.diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex e2154941a..3cbb71dd1 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -2100,7 +2100,7 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32}}const auto c1 = std::chrono::steady_clock::now();- if (native && lay.fmt[(size_t) d.layers].gu_type == 42) // a native Q2_0 pack: the Q2_0 kernels' activations+ if (native && strata::kernels::cpu::q2_native_kernels(lay.fmt[(size_t) d.layers].gu_type)) // a native Q2_0 pack: the Q2_0 kernels' activationsfor (int64_t t = 0; t < n_tok; ++t) act_quant_any(x_f + (size_t) t * H, H, d.act_multi[(size_t) t]);else if (native)for (int64_t t = 0; t < n_tok; ++t)diff --git a/src/kernels/cpu/native_expert.cpp b/src/kernels/cpu/native_expert.cppindex d90d60958..0dc5d3aa8 100644--- a/src/kernels/cpu/native_expert.cpp+++ b/src/kernels/cpu/native_expert.cpp@@ -100,7 +100,7 @@ void native_gu_rows(const NativeFmt& f, const uint8_t* blob, const void* const*// Unsloth UD-Q4_K_XL's Q4_K gate/up: the multi-token kernel is bit-exact against ggml's per-token dot (any group// size, no #152 rule). Opt-in, STRATA_KQ256=1: measured no faster in the engine (a window's expert groups hold// ~1.4 tokens and the weights stay in L1 across ggml's per-token calls; 1.01-1.13x in native_expert_parity).- static const bool kq = [] { const char* v = std::getenv("STRATA_KQ256"); return v != nullptr && std::atoi(v) != 0; }();+ static const bool kq = [] { const char* v = std::getenv("STRATA_KQ256"); return cpu_avx2_ok() && v != nullptr && std::atoi(v) != 0; }();if (kq && f.gu_type == 12 && nt >= 2) { // one token: ggml's own dot below (the same bits, less overhead)kq256_gu_rows(f.gu_type, blob, f.gu_row, f.up_off, (int) f.n_embd, act, nt, ff, r0, r1);return;diff --git a/src/kernels/cpu/pool.cpp b/src/kernels/cpu/pool.cppindex 1919d2e9c..28a1f612e 100644--- a/src/kernels/cpu/pool.cpp+++ b/src/kernels/cpu/pool.cpp@@ -549,7 +549,7 @@ void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) {const int e = (int) (r / per), r0 = (int) (r % per);const int r1 = (int) std::min<int64_t>(per, r0 + (g1 - r));SplitBufMulti& sb = split_multi_[(size_t) e];- if (mode_ == 5 && nfmt_->gu_type == 42) {+ if (mode_ == 5 && q2_native_kernels(nfmt_->gu_type)) {// a native Q2_0 pack: gate and up rows on the Q2_0 kernels, then SwiGLUthread_local float gbuf[MAXT][FF], ubuf[MAXT][FF];float* gp[MAXT];@@ -565,7 +565,7 @@ void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) {float* ff[MAXT];for (int t = 0; t < mjobs_[e].nt; ++t) ff[t] = sb.ff[t];native_gu_rows(*nfmt_, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1);- } else if (nfmt_->d_type == 42) {+ } else if (q2_native_kernels(nfmt_->d_type)) {// Q2_0 down (most IQ layers): the AVX-512 kernel, ggml-cpu has only a scalar one on x86const ActQ* a2[MAXT];for (int t = 0; t < mjobs_[e].nt; ++t) a2[t] = &sb.a2[t];@@ -685,7 +685,7 @@ void ExpertPool::run_split_multi_native(const NativeFmt& f, ExpertJobMulti* jobsconst auto b = std::chrono::steady_clock::now();for (int e = 0; e < nb; ++e)for (int t = 0; t < mjobs_[e].nt; ++t)- if (f.d_type == 42) act_quant_any(split_multi_[(size_t) e].ff[t], FF, split_multi_[(size_t) e].a2[t]);+ if (q2_native_kernels(f.d_type)) act_quant_any(split_multi_[(size_t) e].ff[t], FF, split_multi_[(size_t) e].a2[t]);else native_quant_h(f, split_multi_[(size_t) e].ff[t], split_multi_[(size_t) e].hq[t]);const auto c = std::chrono::steady_clock::now();mrows_ = (int64_t) nb * H;diff --git a/src/kernels/native_expert_parity.cpp b/src/kernels/native_expert_parity.cppindex 0183f01b4..01133fad5 100644--- a/src/kernels/native_expert_parity.cpp+++ b/src/kernels/native_expert_parity.cpp@@ -147,7 +147,7 @@ int check_blob(const cpu::NativeFmt& f, const std::vector<uint8_t>& blob, int se};// guarded: the binary runs on AVX-2 CPUs too, and IQ4_XS has no AVX-512 kernel (an empty switch)if (cpu::cpu_avx512_ok() && cpu::iq512_supported(f.gu_type)) check("avx512", true);- if (cpu::iq256_supported(f.gu_type)) check("avx2", false);+ if (cpu::cpu_avx2_ok() && cpu::iq256_supported(f.gu_type)) check("avx2", false); // no AVX2: ggml-cpu only}for (int k = 0; k < NT; ++k) {cpu::native_quant_h(f, ff[k].data(), hq[k].data());@@ -180,7 +180,7 @@ int check_blob(const cpu::NativeFmt& f, const std::vector<uint8_t>& blob, int se// BIT FOR BIT, for 1..8 tokens; then the time of 4 tokens (a verify window) both waysfor (int role = 0; role < 2; ++role) {const int type = role == 0 ? f.gu_type : f.d_type;- if (!cpu::kq256_supported(type) || (role == 0 && type != 12)) continue;+ if (!cpu::cpu_avx2_ok() || !cpu::kq256_supported(type) || (role == 0 && type != 12)) continue;const int n = role == 0 ? (int) H : (int) FF, rows = role == 0 ? (int) FF : (int) H;const size_t rb = role == 0 ? f.gu_row : f.d_row;const uint8_t* w = blob.data() + (role == 0 ? 0 : f.down_off);@@ -223,7 +223,7 @@ int check_blob(const cpu::NativeFmt& f, const std::vector<uint8_t>& blob, int serole == 0 ? "gate" : "down", differ, us_k, us_g, us_g / us_k);if (differ) ++failures;}- if (f.d_type == 42) {+ if (cpu::q2_native_kernels(f.d_type)) {// (b2) the GGUF-layout Q2_0 kernel the pool uses for Q2_0 down projections - the AVX-512 one// where the CPU has it, the AVX-2 one (q2_avx2.cpp) where it does not. Calling the AVX-512// kernel unconditionally faults on a Zen 2/3 CPU.@@ -240,7 +240,7 @@ int check_blob(const cpu::NativeFmt& f, const std::vector<uint8_t>& blob, int sestd::printf(" q2_0 %s down vs ggml down: rel %.2e\n",cpu::cpu_avx512_ok() ? "AVX-512" : "AVX-2", rel(alt, got_c));}- if (f.d_type == 20) {+ if (f.d_type == 20 && cpu::cpu_avx2_ok()) {// (b3) the IQ4_NL multi-token AVX-2 kernel the pool now uses for IQ4_NL down projections,// against ggml-cpu's single-token vec_dot on the SAME Q8_0 activations (h), plus timing.std::vector<float> alt((size_t) NT * H), refd((size_t) NT * H);