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++
IQ3_S support: the GSQ-RCO IQ3_S model (engine 0.1.4)
Niko122159b069620812
diff --git a/README.md b/README.mdindex 3c67d6538..c5867ae9a 100644--- a/README.md+++ b/README.md@@ -39,7 +39,7 @@ model - is set up for you.2. Double-click **`START-HERE.bat`**.3. Answer 4 questions - or just press Enter each time for the recommended choice:- **Which model?** The original, or Swift 1.5 (a version that thinks shorter and answers sooner)- - **Which size?** Q2_0, IQ2_XS or IQ3_XXS - see [which model](#which-model-should-i-pick)+ - **Which size?** Q2_0, IQ2_XS, IQ3_XXS or IQ3_S - see [which model](#which-model-should-i-pick)- **How much context?** How much text it can keep in mind at once (it suggests one for your card)- **Images?** Whether it should also read pictures@@ -60,6 +60,7 @@ Measured on an RTX 5070 (12 GB), a Ryzen 5 7600 and 64 GB of RAM:| **Q2_0** | 95 tokens/s | 65 tokens/s | 539 tokens/s || **IQ2_XS** | 78 tokens/s | 52 tokens/s | 463 tokens/s || **IQ3_XXS** | 66 tokens/s | 45 tokens/s | 410 tokens/s |+| **IQ3_S** | 54 tokens/s | 42 tokens/s | 374 tokens/s |- **Writes answers** = how fast the reply appears (tokens per second).- **Reads your prompt** = how fast it takes in what you send (long documents, code, chat history).@@ -76,7 +77,8 @@ A card with more VRAM is faster, because more of the model fits on the GPU: an R| --- | ---: | --- | --- | --- || **Q2_0** | 66 GB | fastest | good | you want speed || **IQ2_XS** | 68 GB | fast | better | you want a good all-rounder (**recommended**) |-| **IQ3_XXS** | 76 GB | slower | best | you want the best answers (uses 43 GB of your 64 GB RAM) |+| **IQ3_XXS** | 76 GB | slower | great | you want better answers (uses 43 GB of your 64 GB RAM) |+| **IQ3_S** | 84 GB | slowest | best: matches the full model on the published tests | you want the very best answers (original model only; uses 50 GB of your 64 GB RAM, so close other big programs) |**The version:**diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex e608905c5..6d8c1c999 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -21,6 +21,7 @@ tokens, MTP speculative decoding on. "262K" is the model's full context window (| **Q2_0** | 389 | 539 | 571 | 561 | 543 | 496 || **IQ2_XS** | 332 | 463 | 495 | 486 | 472 | 437 || **IQ3_XXS** | 285 | 410 | 435 | 427 | 414 | - |+| **IQ3_S** | 260 | 374 | 397 | - | 378 | - |### Output (tokens/s)@@ -29,9 +30,11 @@ tokens, MTP speculative decoding on. "262K" is the model's full context window (| **Q2_0** | 88.7 | 94.6 | 87.5 | 76.4 | 65.1 | 56.3 || **IQ2_XS** | 82.0 | 78.0 | 65.3 | 63.7 | 52.0 | 48.0 || **IQ3_XXS** | 64.6 | 65.6 | 57.3 | 54.4 | 44.8 | - |+| **IQ3_S** | 51.2 | 54.4 | 51.1 | - | 42.2 | - |-IQ3_XXS at 262K is not measured: with its 43 GB of experts, a 260K-token context brings a 64 GB PC to its memory-limit. Use up to 128K with IQ3_XXS on 64 GB.+IQ3_XXS and IQ3_S at 262K are not measured: with their 43 / 50 GB of experts, a 260K-token context brings a 64 GB PC+to its memory limit. Use up to 128K with them on 64 GB (setup caps it). IQ3_S (engine 0.1.4 or newer) is only published+for the original model, not for Swift 1.5.Time to first token is prompt length / prompt speed: about 7 s at 4K, 55 s at 32K, 4 minutes at 128K and 9 minutes at262K. The raw numbers: [`bench/results/`](../bench/results/). The [paper](paper/Strata-Paper.pdf) explains every number.diff --git a/setup.py b/setup.pyindex 1591b2915..6a3189a55 100644--- a/setup.py+++ b/setup.py@@ -19,7 +19,7 @@ What the first run does (each step is skipped when it is already done):6. prepares the model for Strata and fetches the MTP draft layer (~5 GB, from the original Qwen checkpoint)7. writes run-<model>.bat / run-<model>.sh and starts the model-Options: --family qwen|swift, --model Q2_0|IQ2_XS|IQ3_XXS, --context 32768, --vision yes|no|gpu|cpu, --port 8080, --yes (recommended+Options: --family qwen|swift, --model Q2_0|IQ2_XS|IQ3_XXS|IQ3_S, --context 32768, --vision yes|no|gpu|cpu, --port 8080, --yes (recommendedanswers, no questions), --setup (install another model / change settings instead of starting), --no-start,--models-dir DIR, --gguf-dir DIR (use GGUF files you already have), --build (compile instead of the ready-madeengine), --check (only check this PC).@@ -61,8 +61,12 @@ MODELS = {"Q2_0": {"about": "2-bit, the fastest", "download_gb": 66.4, "ram_gb": 48, "arena_gb": 34.0},"IQ2_XS": {"about": "2-bit i-quant, a little better quality, close in speed", "download_gb": 68.0, "ram_gb": 48,"arena_gb": 35.5},- "IQ3_XXS": {"about": "3-bit i-quant, the best quality, slower (more CPU work per token)", "download_gb": 75.8,+ "IQ3_XXS": {"about": "3-bit i-quant, better quality, slower (more CPU work per token)", "download_gb": 75.8,"ram_gb": 60, "arena_gb": 42.9},+ # the original model only (Swift 1.5 has no IQ3_S): matches the full BF16 model on the published benchmarks+ "IQ3_S": {"about": "3.5-bit i-quant, the best quality (matches the full model), the slowest; needs a 64 GB PC "+ "with little else running", "download_gb": 83.6, "ram_gb": 62, "arena_gb": 50.3,+ "families": ("qwen",)},}CONTEXTS = [8192, 32768, 65536, 131072, 262144]# The model families: the same architecture, weights in the same three GSQ-RCO sizes, different files.@@ -719,13 +723,15 @@ def main() -> int:if fam.get("license"):say(f" Its license: {fam['license']}")say()- names = list(MODELS)+ names = [m for m in MODELS if family in MODELS[m].get("families", FAMILIES)]+ if a.model and a.model not in names:+ fail(f"{fam['title']} has no {a.model} model file", "choose one of: " + ", ".join(names))for i, m in enumerate(names, 1):d = MODELS[m]fit = "" if ram >= d["ram_gb"] else f" <- needs {d['ram_gb']} GB RAM, you have {ram:.0f}"say(f" {i}) {m:8s} {d['about']}; download {d['download_gb']:.0f} GB, uses ~{d['arena_gb']:.0f} GB of RAM{fit}")- rec = "3" if ram >= 60 else "1"- model = a.model or names[int(ask("Which size?", ["1", "2", "3"], rec, a.yes)) - 1]+ rec = str(names.index("IQ3_XXS") + 1) if ram >= 60 else "1"+ model = a.model or names[int(ask("Which size?", [str(i) for i in range(1, len(names) + 1)], rec, a.yes)) - 1]if ram < MODELS[model]["ram_gb"] - 4:fail(f"{model} needs about {MODELS[model]['ram_gb']} GB of RAM; this PC has {ram:.0f} GB","choose Q2_0 or IQ2_XS, or add RAM")@@ -741,8 +747,9 @@ def main() -> int:for i, c in enumerate(CONTEXTS, 1):say(f" {i}) {c // 1024}K tokens" + (" (recommended for your GPU)" if c == rec_ctx else ""))ctx = CONTEXTS[int(ask("Context?", [str(i) for i in range(1, 6)], str(CONTEXTS.index(rec_ctx) + 1), a.yes)) - 1]- if model == "IQ3_XXS" and ram < 90 and ctx > 131072:- warn("IQ3_XXS with a 262K context needs more than 64 GB of RAM (43 GB of experts + the context): using 128K")+ if model in ("IQ3_XXS", "IQ3_S") and ram < 90 and ctx > 131072:+ warn(f"{model} with a 262K context needs more than 64 GB of RAM ({MODELS[model]['arena_gb']:.0f} GB of experts "+ "+ the context): using 128K")ctx = 131072ok(f"context: {ctx} tokens")if a.vision:diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cuindex 3525b91ad..ea05d9d23 100644--- a/src/kernels/cuda/iq_kernels.cu+++ b/src/kernels/cuda/iq_kernels.cu@@ -268,6 +268,28 @@ __device__ __forceinline__ float vec_dot_iq4_nl_q8_1(const void* __restrict__ vbreturn d * sumi;}+// IQ4_XS: 256 values as 8 sub-blocks of 32 (6-bit scale each); one call covers one sub-block (iqs = 4 * sub-block),+// and `bq8_1` is the super-block's first q8_1 block, so the call's activation is bq8_1[iqs / 4]. The GSQ-RCO IQ3_S+// file keeps one layer's routed gate/up experts in this format.+__device__ __forceinline__ float vec_dot_iq4_xs_q8_1(const void* __restrict__ vbq, const block_q8_1* __restrict__ bq8_1,+ const int& kbx, const int& iqs) {+ const block_iq4_xs* bq4 = (const block_iq4_xs*) vbq + kbx;+ int sumi = 0;+#pragma unroll+ for (int j = 0; j < 4; ++j) {+ const int aux_q4 = get_int_b4(bq4->qs, iqs + j);+ const int2 v = get_int_from_table_16(aux_q4, kvalues_iq4nl);+ const int u0 = get_int_b4(bq8_1[iqs / 4].qs, j + 0);+ const int u1 = get_int_b4(bq8_1[iqs / 4].qs, j + 4);+ sumi = ggml_cuda_dp4a(v.x, u0, sumi);+ sumi = ggml_cuda_dp4a(v.y, u1, sumi);+ }+ const int ls = ((bq4->scales_l[iqs / 8] >> (iqs & 0x04)) & 0x0F) | (((bq4->scales_h >> (iqs / 2)) & 0x03) << 4);+ sumi *= ls - 32;+ const float d = __half2float(bq4->d) * __low2float(bq8_1[iqs / 4].ds);+ return d * sumi;+}+// ---------------------------------------------------------------- the formats// qk = values per block, ipb = dot calls per block (qi / vdr), step = the iqs stride between calls.template<int TY> struct Fmt;@@ -281,6 +303,8 @@ template<> struct Fmt<20> { static constexpr int qk = 32, ipb = 2, step = 2;__device__ static float dot(const void* v, const block_q8_1* y, int kbx, int iqs) { return vec_dot_iq4_nl_q8_1(v, y, kbx, iqs); } };template<> struct Fmt<21> { static constexpr int qk = 256, ipb = 8, step = 2;__device__ static float dot(const void* v, const block_q8_1* y, int kbx, int iqs) { return vec_dot_iq3_s_q8_1(v, y, kbx, iqs); } };+template<> struct Fmt<23> { static constexpr int qk = 256, ipb = 8, step = 4;+ __device__ static float dot(const void* v, const block_q8_1* y, int kbx, int iqs) { return vec_dot_iq4_xs_q8_1(v, y, kbx, iqs); } };template<> struct Fmt<22> { static constexpr int qk = 256, ipb = 8, step = 2;__device__ static float dot(const void* v, const block_q8_1* y, int kbx, int iqs) { return vec_dot_iq2_s_q8_1(v, y, kbx, iqs); } };template<> struct Fmt<29> { static constexpr int qk = 256, ipb = 8, step = 1;@@ -618,6 +642,7 @@ void iq_mmvq(int t, const void* w, const void* x_q8_1, float* y, int n_in, int ncase 20: mmvq_kernel<20><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;case 21: mmvq_kernel<21><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;case 22: mmvq_kernel<22><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;+ case 23: mmvq_kernel<23><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;case 29: mmvq_kernel<29><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;case 42: mmvq_kernel<42><<<grid, block, 0, s>>>(W, rb, X, y, n_in, n_out, ncols); break;default: std::fprintf(stderr, "iq_mmvq: type %d is not supported\n", t); std::exit(1);@@ -700,6 +725,7 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long longcase 18: native_gu_kernel<18><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;case 21: native_gu_kernel<21><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;case 22: native_gu_kernel<22><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;+ case 23: native_gu_kernel<23><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;case 29: native_gu_kernel<29><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;case 42: native_gu_kernel<42><<<ggu, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;default: std::fprintf(stderr, "native_expert_grouped: gate/up type %d\n", L.gu_type); std::exit(1);@@ -711,6 +737,7 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long longconst dim3 gd((unsigned) ((L.n_embd + 7) / 8), (unsigned) cap_groups);switch (L.d_type) {case 20: native_down_kernel<20><<<gd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;+ case 23: native_down_kernel<23><<<gd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;case 42: native_down_kernel<42><<<gd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;default: std::fprintf(stderr, "native_expert_grouped: down type %d\n", L.d_type); std::exit(1);}diff --git a/src/kernels/cuda/verify_kernels.cu b/src/kernels/cuda/verify_kernels.cuindex f9abe84dc..6dde0cbf2 100644--- a/src/kernels/cuda/verify_kernels.cu+++ b/src/kernels/cuda/verify_kernels.cu@@ -244,12 +244,14 @@ __global__ void ident_hits_kernel(const int32_t* __restrict__ ids, int n, int32_if (i == 0) *count = n;}-__global__ void gather_rows_kernel(const uint4* __restrict__ src, long long row16, const int32_t* __restrict__ ids,- long long n, uint4* __restrict__ dst) {- const long long total = n * row16;+// E = the widest element the row size divides into (16, 4 or 1 bytes): a Q6_K head row of 2560 values is 2100 bytes+template<typename E>+__global__ void gather_rows_kernel(const E* __restrict__ src, long long row_e, const int32_t* __restrict__ ids,+ long long n, E* __restrict__ dst) {+ const long long total = n * row_e;for (long long i = (long long) blockIdx.x * blockDim.x + threadIdx.x; i < total; i += (long long) gridDim.x * blockDim.x) {- const long long r = i / row16, o = i - r * row16;- dst[i] = src[(long long) ids[r] * row16 + o];+ const long long r = i / row_e, o = i - r * row_e;+ dst[i] = src[(long long) ids[r] * row_e + o];}}@@ -334,8 +336,13 @@ void mtp_select(const float* R_src, int64_t R_stride, const int32_t* ids, const}void gather_rows(const uint8_t* src, int64_t row_bytes, const int32_t* ids, int64_t n, uint8_t* dst, void* stream) {- if (row_bytes % 16 != 0) { std::fprintf(stderr, "gather_rows: row size must be a multiple of 16\n"); std::exit(1); }- gather_rows_kernel<<<48 * 8, 256, 0, (cudaStream_t) stream>>>((const uint4*) src, row_bytes / 16, ids, n, (uint4*) dst);+ cudaStream_t s = (cudaStream_t) stream;+ if (row_bytes % 16 == 0)+ gather_rows_kernel<<<48 * 8, 256, 0, s>>>((const uint4*) src, row_bytes / 16, ids, n, (uint4*) dst);+ else if (row_bytes % 4 == 0)+ gather_rows_kernel<<<48 * 8, 256, 0, s>>>((const uint32_t*) src, row_bytes / 4, ids, n, (uint32_t*) dst);+ else+ gather_rows_kernel<<<48 * 8, 256, 0, s>>>(src, row_bytes, ids, n, dst);check("gather_rows");}