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++
qsa: mask cells whose page did not resolve; refuse a clock sweep over fewer slots than the resolve block
Guillaume PUTIERa8d79afab722
diff --git a/src/kernels/cuda/kv_stream.cu b/src/kernels/cuda/kv_stream.cuindex 5787001f2..ec01ff229 100644--- a/src/kernels/cuda/kv_stream.cu+++ b/src/kernels/cuda/kv_stream.cu@@ -209,6 +209,14 @@ void kv_stream_resolve(const KvStreamMap& m, const QsaAttnPools& slots, const Kvstd::fprintf(stderr, "kv_stream: a block's scale run must be a multiple of 16 bytes\n");std::exit(1);}+ // one sweep step looks at RT consecutive slots `(hand + thread) % n_slots`; with fewer slots than RT two+ // threads see the same slot and may both take it for two different misses. The engine never streams with fewer+ // than qsa_kv_resident_min() / page_size = 5,120 slots, so this is a guard, not a limit.+ if (m.n_slots < RT) {+ std::fprintf(stderr, "kv_stream: %lld slots is fewer than the resolve block (%d): the clock sweep would take a "+ "slot twice\n", (long long) m.n_slots, RT);+ std::exit(1);+ }resolve_kernel<<<1, RT, 0, (cudaStream_t) stream>>>(m, ids, steps, (int) n_q, (int) cap, (int) s.page_size);check("resolve");copy_kernel<<<96, 128, 0, (cudaStream_t) stream>>>(m, runs_of(slots, host, fmt, s));diff --git a/src/kernels/cuda/qsa_decode_attn.cu b/src/kernels/cuda/qsa_decode_attn.cuindex 9f7fb8842..4035999a9 100644--- a/src/kernels/cuda/qsa_decode_attn.cu+++ b/src/kernels/cuda/qsa_decode_attn.cu@@ -113,14 +113,16 @@ __global__ void __launch_bounds__(THREADS) attn_chunk_kernel(const float* __restif (t < n_here) {const int cell = ids[c0 + t];const long long page = (long long) p.page_table[cell / page_size];- r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);+ // a block the KV streaming could not make resident keeps page -1 (ctl[3]); its cells are masked+ // (score -FLT_MAX, weight 0) instead of being read from before the pool.+ if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size);}srow[t] = r;}__syncthreads();// scores: each warp takes cells warp, warp+8, ...; each lane holds 8 of the 256 dimensions.for (int c = warp; c < CHUNK; c += WARPS) {- if (c >= n_here) {+ if (c >= n_here || srow[c] < 0) {if (lane < G) sp[lane][c] = -FLT_MAX;continue;}@@ -141,8 +143,8 @@ __global__ void __launch_bounds__(THREADS) attn_chunk_kernel(const float* __restfor (int h = warp; h < G; h += WARPS) {const float a = sp[h][lane], b = sp[h][lane + 32];const float m = warp_max(fmaxf(a, b));- const float ea = (lane < n_here) ? __expf(a - m) : 0.0f;- const float eb = (lane + 32 < n_here) ? __expf(b - m) : 0.0f;+ const float ea = (lane < n_here && srow[lane] >= 0) ? __expf(a - m) : 0.0f;+ const float eb = (lane + 32 < n_here && srow[lane + 32] >= 0) ? __expf(b - m) : 0.0f;sp[h][lane] = ea;sp[h][lane + 32] = eb;const float l = warp_sum(ea + eb);@@ -154,6 +156,7 @@ __global__ void __launch_bounds__(THREADS) attn_chunk_kernel(const float* __rest#pragma unrollfor (int h = 0; h < G; ++h) acc[h] = 0.0f;for (int c = 0; c < n_here; ++c) {+ if (srow[c] < 0) continue; // masked above, weight 0float v;if constexpr (KV_MODE == 0) {v = __half2float(__ushort_as_half(p.v_pool[srow[c] * HD + t]));