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

KVA: keep gdn_recurrence_variant's public signature - the SYCL tree defines that symbol, so a new parameter would break its link; the state-only form goes through a private impl

Niko12215b469ee9a312
diff --git a/docs/KVA.md b/docs/KVA.md
index eeb3dee51..3e84dca30 100644
--- a/docs/KVA.md
+++ b/docs/KVA.md
@@ -58,6 +58,8 @@ Requirements and limits for this first version:
- Layer type matters more than the count: approximating only the 6 late QSA layers cost a 0.153 residual error
at 1.08×; approximating 18 GDN layers cost 0.339 at 1.18×. A gated recurrence integrates its input over the
whole prefix, so a wrong input keeps biasing the state, while a wrong QSA K/V only misplaces attention keys.
+- On IQ2_XS the same 14.6K-token three-needle test gives 208.0 → 328.7 prompt tok/s (1.58×) with all three
+ codes retrieved, against 201.6 → 320.7 (1.59×) on IQ3_XXS: the feature is not tied to one quantization.
- The control is not bit-reproducible on this box (identical runs differ in the last chunks by ~0.85 %), so the
residual figures are quoted against that measured floor, never as bit equality.
diff --git a/include/strata/prefill/kernels.hpp b/include/strata/prefill/kernels.hpp
index 9bbf6732b..5f1bf3554 100644
--- a/include/strata/prefill/kernels.hpp
+++ b/include/strata/prefill/kernels.hpp
@@ -74,10 +74,11 @@ void gdn_recurrence(float* state, const float* h, const float* gate, const float
/// bits as 0 on an Arc A770; gdn_recurrence takes it by default on Alchemist (STRATA_GDN_XE=0 off, =1 any Intel GPU).
void gdn_recurrence_variant(int variant, float* state, const float* h, const float* gate, const float* beta,
const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T,
- void* stream, int64_t ld16 = 0, bool with_out = true);
-/// KVA: the same recurrence kernels as gdn_recurrence, bit for bit, without the output normalization: state, h,
-/// gate, beta and the scratch `y` only. The output projection and the gated residual write have no consumer when
-/// only the state advances, and their input (z, the gate projection) is not needed either.
+ void* stream, int64_t ld16 = 0);
+/// KVA (CUDA/HIP only): the same recurrence kernels as gdn_recurrence, bit for bit, without the output
+/// normalization: state, h, gate, beta and the scratch `y` only. The output projection and the gated residual
+/// write have no consumer when only the state advances, and their input (z, the gate projection) is not needed
+/// either. Declared here for the CUDA build; the SYCL tree keeps its own recurrence and does not reference it.
void gdn_recurrence_state_only(float* state, const float* h, const float* gate, const float* beta, float* y,
int64_t T, void* stream);
diff --git a/src/prefill/kernels.cu b/src/prefill/kernels.cu
index 5d1701306..e99f5ba6e 100644
--- a/src/prefill/kernels.cu
+++ b/src/prefill/kernels.cu
@@ -2606,9 +2606,11 @@ void gdn_conv(float* history, const float* qkv, const float* conv_w, float* h, i
gdn_l2_kernel<<<dim3(2 * HK, (unsigned) T), S, 0, (cudaStream_t) stream>>>(h, eps);
check("gdn_conv");
}
-void gdn_recurrence_variant(int variant, float* state, const float* h, const float* gate, const float* beta,
- const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T,
- void* stream, int64_t ld16, bool with_out) {
+// The recurrence dispatch, shared by the two entry points below so the state-only form cannot drift from the full
+// one. `with_out` false runs exactly the same kernels minus the output normalization (the CUDA-only KVA path).
+static void gdn_recurrence_impl(int variant, float* state, const float* h, const float* gate, const float* beta,
+ const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T,
+ void* stream, int64_t ld16, bool with_out) {
if (ld16 <= 0) ld16 = (int64_t) HV * S;
static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr; // the one-block-per-head kernel (A/B)
#if defined(__HIPCC__)
@@ -2727,6 +2729,11 @@ void gdn_recurrence_variant(int variant, float* state, const float* h, const flo
}
check("gdn_recurrence");
}
+void gdn_recurrence_variant(int variant, float* state, const float* h, const float* gate, const float* beta,
+ const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T,
+ void* stream, int64_t ld16) {
+ gdn_recurrence_impl(variant, state, h, gate, beta, z, gamma, eps, y, y16, T, stream, ld16, /*with_out=*/true);
+}
void gdn_recurrence(float* state, const float* h, const float* gate, const float* beta, const float* z,
const float* gamma, float eps, float* y, uint16_t* y16, int64_t T, void* stream, int64_t ld16) {
// Aurora (S23): four lanes per column + the grid-stride norm, the same bits (tests/hip/gdn_rec_head.cpp);
@@ -2734,7 +2741,7 @@ void gdn_recurrence(float* state, const float* h, const float* gate, const float
// (AMD builds only; the arch defaults set STRATA_GDN_HEAD=1 on gfx1151 and leave other cards on the earlier kernels)
static const bool head = [] { const char* v = std::getenv("STRATA_GDN_HEAD"); return v != nullptr && std::atoi(v) != 0; }();
static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr;
- gdn_recurrence_variant(head && !serial ? 1 : 0, state, h, gate, beta, z, gamma, eps, y, y16, T, stream, ld16);
+ gdn_recurrence_impl(head && !serial ? 1 : 0, state, h, gate, beta, z, gamma, eps, y, y16, T, stream, ld16, true);
}
/// KVA: the same recurrence, bit for bit, without the output normalisation (its readers - the output projection
/// and the gated residual write - have no consumer when only the state advances). `y` is still the scratch the
@@ -2743,8 +2750,8 @@ void gdn_recurrence_state_only(float* state, const float* h, const float* gate,
int64_t T, void* stream) {
static const bool head = [] { const char* v = std::getenv("STRATA_GDN_HEAD"); return v != nullptr && std::atoi(v) != 0; }();
static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr;
- gdn_recurrence_variant(head && !serial ? 1 : 0, state, h, gate, beta, nullptr, nullptr, 0.0f, y, nullptr, T,
- stream, 0, /*with_out=*/false);
+ gdn_recurrence_impl(head && !serial ? 1 : 0, state, h, gate, beta, nullptr, nullptr, 0.0f, y, nullptr, T,
+ stream, 0, /*with_out=*/false);
}
void route(const float* logits, int32_t* ids, float* weights, int64_t T, int64_t n_expert, void* stream) {
if (n_expert == 512)