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++
Verify PLE block: the window's key and value projections at once (opt-in STRATA_PLE_BATCH=1, bit-identical)
Niko1221d92c9feb78ce
diff --git a/include/strata/core/verify.hpp b/include/strata/core/verify.hppindex 5717eb4fa..6e0bf4ecf 100644--- a/include/strata/core/verify.hpp+++ b/include/strata/core/verify.hpp@@ -198,6 +198,8 @@ private:VerifyHits hits_;const NativeHead* head_ = nullptr;int max_t_ = 0;+ float* ple_key_ = nullptr; ///< STRATA_PLE_BATCH: the window rows' PLE key / value projections+ float* ple_val_ = nullptr;int last_t_ = 0;int64_t last_pos0_ = 0;int32_t last_tokens_[8] = {};diff --git a/include/strata/kernels/ple.hpp b/include/strata/kernels/ple.hppindex fabad838a..30afb01d2 100644--- a/include/strata/kernels/ple.hpp+++ b/include/strata/kernels/ple.hpp@@ -33,6 +33,7 @@ namespace strata::kernels {/// Opt in to pinned CUDA BF16/F32 MMVF for the PLE value projection only (default false)./// Configure before session capture; captured graphs retain their selected projection kernels.void ple_set_native_bf16(bool enabled);+bool ple_native_bf16();/// Opt in to pinned CUDA postprojection norms, gate, convolution and residual/// arithmetic (default false). Set before capture; existing graphs keep their@@ -70,6 +71,11 @@ struct PleWeights {/// Plan v0.3 P6: the IQ model files keep `ple_key` in BF16 ([n_embd, hc_dim], `w[o*n_embd+i]`); when set it/// replaces both key paths above.const uint16_t* key_bf16 = nullptr;+ /// S25 (STRATA_PLE_BATCH=1): the key (hc_dim) and value (n_embd) projections of `emb`, already computed by the+ /// caller for a window's rows at once (the same kernels' multi-row forms); ple_block then copies them instead of+ /// running its own GEMVs+ const float* pre_key = nullptr;+ const float* pre_value = nullptr;};/// Everything the block produces, in the order `ple_layer_xcheck`'s oracle writes it. Any pointer may bediff --git a/src/core/verify.cpp b/src/core/verify.cppindex 57a0a2da4..812074d7f 100644--- a/src/core/verify.cpp+++ b/src/core/verify.cpp@@ -320,6 +320,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState&sh_up_ = b.take<float>(T * (uint64_t) g.n_ff); sh_g_ = b.take<float>(T + 4);head_logits_ = b.take<float>(T * (uint64_t) n_vocab_);hist_snap_ = b.take<float>(T * HS);+ ple_key_ = b.take<float>(T * (uint64_t) strata::kernels::NG_HC_DIM); ple_val_ = b.take<float>(T * N);};Bump count;carve(count);@@ -472,13 +473,37 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {bool pending = l > 0 && !cvec().covers(l - 1);if (l == 1 && ple_on) {float* normalized = (float*) ((uint8_t*) ss.ple.scratch + ple_block_scratch_bytes());+ // S25 (STRATA_PLE_BATCH=1): the key and value projections depend only on each row's n-gram embedding, so+ // the group's rows run through the multi-row forms of the same kernels (the weights read once); every+ // row's arithmetic is the single-row call's. The history-dependent rest stays row by row.+ static const bool ple_batch = [] { const char* e = std::getenv("STRATA_PLE_BATCH"); return e && e[0] == '1'; }();+ PleWeights pw = ss.ple.w;+ const bool nkey = pw.key_native_data != nullptr && pw.key_bf16 == nullptr;+ const bool batched = ple_batch && n > 1 && (pw.key_bf16 != nullptr || nkey) && ple_native_bf16();+ if (batched) {+ try {+ if (pw.key_bf16 != nullptr)+ bf16_gemv_fp32_mmvf_multi(ple_ + tb * N, N, pw.key_bf16, ple_key_ + (size_t) tb * NG_HC_DIM,+ NG_HC_DIM, N, NG_HC_DIM, n, cs);+ else {+ native_quantize_q8_1(ple_ + tb * N, xq_, (int) N, n, cs);+ native_mmvq(pw.key_native_type, pw.key_native_data, xq_, ple_key_ + (size_t) tb * NG_HC_DIM,+ (int) N, NG_HC_DIM, n, cs);+ }+ bf16_gemv_fp32_mmvf_multi(ple_ + tb * N, N, pw.value_bf16, ple_val_ + tb * N, N, N, N, n, cs);+ } catch (const std::exception& e) {+ err = std::string("verify PLE batch: ") + e.what();+ return false;+ }+ }for (int t = tb; t < te; ++t) {+ if (batched) { pw.pre_key = ple_key_ + (size_t) t * NG_HC_DIM; pw.pre_value = ple_val_ + t * N; }gr_write(Rt(t), bo_ + t * N, inj2_ + t * HC, gs, Rt(t), cs);PleOut po;po.normalized = normalized;po.result = Rt(t);try {- ple_block(ple_ + t * N, Rt(t), ss.ple.hist, ss.ple.w, po, ss.ple.scratch, cs);+ ple_block(ple_ + t * N, Rt(t), ss.ple.hist, pw, po, ss.ple.scratch, cs);ple_history_advance(ss.ple.hist, normalized, cs);} catch (const std::exception& e) {err = std::string("verify PLE: ") + e.what();diff --git a/src/kernels/cuda/ple.cu b/src/kernels/cuda/ple.cuindex 6585bbaab..3f37ab7a5 100644--- a/src/kernels/cuda/ple.cu+++ b/src/kernels/cuda/ple.cu@@ -197,6 +197,7 @@ void ck(cudaError_t e, const char* what) {} // namespacevoid ple_set_native_bf16(bool enabled) { native_bf16 = enabled; }+bool ple_native_bf16() { return native_bf16; }void ple_set_native_postops(bool enabled) { native_postops = enabled; }bool ple_native_postops_enabled() { return native_postops; }@@ -303,7 +304,9 @@ void ple_block(const float* emb, const float* hidden, const float* hist_rows, co// ---- key = grouped_norm(ple_key @ emb). The optional native projection// follows pinned CUDA Q8_1 MMVQ; the default retains its canonical Q8_0 path.- if (w.key_bf16 != nullptr) {+ if (w.pre_key != nullptr) {+ cudaMemcpyAsync(d_key, w.pre_key, (size_t) hc_dim * sizeof(float), cudaMemcpyDeviceToDevice, st);+ } else if (w.key_bf16 != nullptr) {bf16_gemv_fp32_mmvf(emb, w.key_bf16, d_key, n_embd, hc_dim, stream);} else if (native_key) {native_quantize_q8_1(emb, w.key_native_q8_1, n_embd, 1, stream);@@ -319,7 +322,9 @@ void ple_block(const float* emb, const float* hidden, const float* hist_rows, co}// The value projection's independent option leaves the nonlinear PLE operations unchanged.- if (native_bf16) {+ if (w.pre_value != nullptr) {+ cudaMemcpyAsync(d_value, w.pre_value, (size_t) n_embd * sizeof(float), cudaMemcpyDeviceToDevice, st);+ } else if (native_bf16) {bf16_gemv_fp32_mmvf(emb, w.value_bf16, d_value, n_embd, n_embd, stream);} else {to_bf16_kernel<<<(n_embd + THREADS - 1) / THREADS, THREADS, 0, st>>>(emb, d_emb16, n_embd);