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++
STRATA_HC_Q8=1: inject rows as the exact BF16, the final mixer from Q8_0 too
Niko122158729711d952
diff --git a/src/core/native_dense.cpp b/src/core/native_dense.cppindex aae66aec4..62a42db78 100644--- a/src/core/native_dense.cpp+++ b/src/core/native_dense.cpp@@ -24,6 +24,7 @@ bool hc_q8_requested() {return on;}bool hc_q8_name(const std::string& name) {+ if (name == "output_hc_down.weight" || name == "output_hc_up.weight") return true; // S25: the final mixer tooif (name.rfind("blk.", 0) != 0) return false;static const char* suffixes[] = {".hc_attn_down.weight", ".hc_attn_up.weight", ".hc_attn_inject.weight",".hc_ffn_down.weight", ".hc_ffn_up.weight", ".hc_ffn_inject.weight"};@@ -225,7 +226,10 @@ bool NativeDense::load(const std::vector<std::string>& shards, WeightTable& tabl}if (hc_q8_requested())for (const auto& tensor : gguf.tensors()) {- const bool f32_inject = tensor.type == 0 && tensor.name.ends_with("_inject.weight");+ // S25: the F32 inject rows hold BF16-exact values: the read takes the pack's BF16 rows unless+ // STRATA_HC_Q8_INJECT=1 asks for a Q8_0 copy+ static const bool q8_inject = [] { const char* v = std::getenv("STRATA_HC_Q8_INJECT"); return v && v[0] == '1'; }();+ const bool f32_inject = q8_inject && tensor.type == 0 && tensor.name.ends_with("_inject.weight");if ((tensor.type != 8 && !f32_inject) || !hc_q8_name(tensor.name) || tensor.shape.size() != 2) continue;auto found = table.table_.find(tensor.name);if (found == table.table_.end() || found->second.hc_q8 != nullptr) continue;diff --git a/src/core/verify.cpp b/src/core/verify.cppindex e631ee742..57a0a2da4 100644--- a/src/core/verify.cpp+++ b/src/core/verify.cpp@@ -829,7 +829,23 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {const WeightRef *hn = wt.find("output_hc_norm.weight"), *hd = wt.find("output_hc_down.weight"),*hu = wt.find("output_hc_up.weight");if (!hn || !hd || !hu) { err = "verify: an output_hc_* weight is missing"; return false; }- for (int t = 0; t < T; ++t) {+ // S25 (STRATA_HC_Q8=1): the final mixer from the GGUF's Q8_0 projections too, through the same multi read+ // (no pending write, no inject)+ const bool mix_q8 = hd->hc_q8 != nullptr && hu->hc_q8 != nullptr && head_ != nullptr && head_->loaded();+ if (mix_q8) {+ FusedGrArgs fa[kFusedGrMaxT];+ for (int t = 0; t < T; ++t) {+ FusedGrArgs& a = fa[t];+ a.R = Rt(t); a.R_out = Rt(t); a.apply = false;+ a.w_norm = (const float*) hn->data; a.w_down = (const uint16_t*) hd->data;+ a.w_up = (const uint16_t*) hu->data; a.w_inject = nullptr;+ a.q8_down = (const uint8_t*) hd->hc_q8; a.q8_up = (const uint8_t*) hu->hc_q8;+ a.eps = EPS; a.lo = lo_ + t * g.hc_lr; a.rs = rs_ + t * HC;+ a.mixed = head_mixed_ + t * N;+ }+ fused_gr_read_multi(fa, T, xn_, cs);+ }+ for (int t = 0; t < T && !mix_q8; ++t) {BlockBuffers bb = ss.block;bb.R = Rt(t);bb.mixed = head_mixed_ + t * N;diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cuindex d6515ac37..ec7ddb566 100644--- a/src/kernels/cuda/fused_gr.cu+++ b/src/kernels/cuda/fused_gr.cu@@ -827,7 +827,10 @@ __global__ void __launch_bounds__(THREADS) gr_down_q8_kernel(GrMulti m, float* _const int t = threadIdx.x, lane = t & 31, warp = t >> 5;const int rg = blockIdx.x, kc = blockIdx.y, c = kc / Q8_CPS;const bool inj = rg == Q8_RG;- const int nrows = inj ? ((m.a[0].q8_inject != nullptr && warp < HC) ? 1 : 0) : Q8_RPW;+ // S25: the inject rows are F32 in the GGUF with BF16-exact values, so by default they are read as the pack's BF16+ // (exact); a Q8_0 copy (STRATA_HC_Q8_INJECT=1) is the other option+ const bool inj_bf16 = inj && m.a[0].q8_inject == nullptr;+ const int nrows = inj ? (((m.a[0].q8_inject != nullptr || m.a[0].w_inject != nullptr) && warp < HC) ? 1 : 0) : Q8_RPW;const int row0 = inj ? warp : (rg * WARPS + warp) * Q8_RPW;const uint8_t* wb = inj ? m.a[0].q8_inject : m.a[0].q8_down;const int sub = lane & 7, bl = lane >> 3; // lanes 8b..8b+7: one Q8_0 block, 4 values each@@ -835,7 +838,7 @@ __global__ void __launch_bounds__(THREADS) gr_down_q8_kernel(GrMulti m, float* _float dq[Q8_RPW][Q8_SPB];#pragma unrollfor (int r = 0; r < Q8_RPW; ++r) {- if (r >= nrows) break;+ if (r >= nrows || inj_bf16) break;const uint8_t* row = wb + (size_t) (row0 + r) * (D / 32) * Q8B + (size_t) kc * (Q8_KC / 32) * Q8B;#pragma unrollfor (int s = 0; s < Q8_SPB; ++s) {@@ -883,8 +886,15 @@ __global__ void __launch_bounds__(THREADS) gr_down_q8_kernel(GrMulti m, float* _for (int k = 0; k < T; ++k) acc[k] = 0.0f;#pragma unrollfor (int s = 0; s < Q8_SPB; ++s) {- const float4 w = q8_four(q[r][s], dq[r][s]);const int v = 32 * (4 * s + bl) + 4 * sub;+ float4 w;+ if (inj_bf16) {+ const uint2 b = *reinterpret_cast<const uint2*>(m.a[0].w_inject + (size_t) row0 * D + (size_t) kc * Q8_KC + v);+ w = make_float4(__uint_as_float(b.x << 16), __uint_as_float(b.x & 0xffff0000u),+ __uint_as_float(b.y << 16), __uint_as_float(b.y & 0xffff0000u));+ } else {+ w = q8_four(q[r][s], dq[r][s]);+ }#pragma unrollfor (int k = 0; k < T; ++k) {const float4 x = *reinterpret_cast<const float4*>(&xs[k][v]);@@ -1044,7 +1054,7 @@ void fused_gr_read_multi(const FusedGrArgs* a, int n_tok, float* xn_scratch, voim.xn = xn_scratch;m.T = n_tok;cudaStream_t st = (cudaStream_t) stream;- if (a[0].q8_down != nullptr && a[0].q8_up != nullptr && (a[0].w_inject == nullptr || a[0].q8_inject != nullptr)) {+ if (a[0].q8_down != nullptr && a[0].q8_up != nullptr) { // inject: Q8_0 copy, or the BF16 rowslaunch_q8(m, xn_scratch, st, stamp_buf, stamp_i0); // S23 experiment: STRATA_HC_Q8=1const cudaError_t eq = cudaGetLastError();if (eq != cudaSuccess) {