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++
qwen35: the chunk rule counts what the chunk really costs (measured on the R9700)
Niko1221b0f675be7613
diff --git a/src/qwen35/q36_engine.cu b/src/qwen35/q36_engine.cuindex 9fcc0d0a6..de95aedb6 100644--- a/src/qwen35/q36_engine.cu+++ b/src/qwen35/q36_engine.cu@@ -3765,6 +3765,7 @@ int strata::qwen35::run(int argc, char** argv) {size_t fr = 0, tot = 0, experts = 0;CK(cudaMemGetInfo(&fr, &tot));for (const Layer& L : m.layers) experts += L.stride * (size_t) m.g.n_expert;+ const size_t fr_raw = fr; // before the packed Q8_0 copies count as given back// (the MTP block's experts can go to the CPU, the packed Q8_0 copies can be given back: see place_experts)size_t packed = 0;for (const auto& pk : m.packed) packed += std::get<2>(pk);@@ -3778,14 +3779,16 @@ int strata::qwen35::run(int argc, char** argv) {if (fits && expert_vram < 0) {// a bigger prompt chunk feeds the MMQ expert kernels more rows per expert (R9700, UD-Q4_K_XL, pp4096: 512 3390, 1024// 4495, 2048 5353, 4096 5750 tok/s): the largest that fits beside the experts. Its buffers grow by about 0.5 MiB per- // token (measured 0.47: 1.66 GiB more at 4096 than at 512), the sessions' K / V caches by 45 KB per cell and session.+ // token (measured 0.47: 1.66 GiB more at 4096 than at 512), the sessions' K / V caches by 50 KB per cell and session.// With several slots a long prompt would hold the other slots' windows for a whole chunk: 1024 at most there.- const double kv_cell = 45056.0;+ // (measured on a 32 GB R9700 at 8192 cells, 512 chunk: 1.77 GiB of buffers + K / V; the free room after init must still hold+ // every expert and the 0.77 GiB reserve, or place_experts gives the packed decode copies back - slower decode - or goes hybrid)const int ns = std::max(1, batch);- const double sess_extra = std::max(0.0, (double) ns * (double) ctx * kv_cell - 8192.0 * kv_cell);+ const double kv_one = 45056.0, kv_shared = 5120.0; // per cell: a session's K / V, and the fp16 copies the prompt attention keeps+ const double sess_extra = std::max(0.0, (double) ctx * (kv_one * ns + kv_shared) - 8192.0 * (kv_one + kv_shared));const int cap = ns > 1 ? 1024 : 4096;for (int c : {4096, 2048, 1024})- if (c <= cap && want + (double) (c - 512) * 0.5 * 1048576.0 + sess_extra <= (double) fr) {+ if (c <= cap && (double) experts + 2.75 * GiB + (double) (c - 512) * 0.5 * 1048576.0 + sess_extra <= (double) fr_raw) { // (no give-back of the packed decode copies for a bigger chunk)chunk = c;break;}@@ -3797,8 +3800,8 @@ int strata::qwen35::run(int argc, char** argv) {}if (const char* cv = std::getenv("STRATA_Q36_CHUNK")) chunk = std::max(256, std::min(4096, std::atoi(cv))); // force a chunk (512: the old default)if (std::getenv("STRATA_Q36_PLACE_DEBUG"))- std::fprintf(stderr, "strata-q36: chunk rule: free %.2f GiB (with %.2f packed), main experts %.2f GiB\n",- fr / 1073741824.0, packed / 1073741824.0, experts / 1073741824.0);+ std::fprintf(stderr, "strata-q36: chunk rule: free %.2f GiB (raw %.2f, with %.2f packed), main experts %.2f GiB, chunk %d\n",+ fr / 1073741824.0, fr_raw / 1073741824.0, packed / 1073741824.0, experts / 1073741824.0, chunk);}E.init(m, ctx, chunk, batch, vision);if (!place_experts(m, E, expert_vram, cpu_threads, hybrid_rows, expert_slots, err)) {