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

CUDA sm_86: Q3_K on the interleaved 2-4 column path and one column on the same kernel, sm_86 table (STRATA_MMVQ_IL_Q3K=0 / STRATA_MMVQ_IL_T1=0 turn them off)

Niko1221195d37912544
diff --git a/src/core/verify.cpp b/src/core/verify.cpp
index 3e9ec069a..2b6eb4bdd 100644
--- a/src/core/verify.cpp
+++ b/src/core/verify.cpp
@@ -1010,7 +1010,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
bool il_ready = false; // xil_ holds xq_'s interleaved copy (reset whenever xq_ is rewritten)
auto mm = [&](const WeightRef* w, float* out, int n_in, int n_out) {
if (g_mmvq_il() && strata::kernels::native_mmvq_il_supported(w->native_type, n, n_out)) {
- if (!il_ready) {
+ if (!il_ready && n >= 2) { // one column reads the plain q8_1 blocks
strata::kernels::native_q8_1_interleave(xq_, xil_, n_in, n, cs);
il_ready = true;
}
@@ -1667,7 +1667,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
try {
native_quantize_q8_1(head_mixed_, xq_, (int) N, T, cs);
if (g_mmvq_il() && strata::kernels::native_mmvq_il_supported(head_->type(), (int) T, (int) n_vocab_)) {
- strata::kernels::native_q8_1_interleave(xq_, xil_, (int) N, (int) T, cs);
+ if (T >= 2) strata::kernels::native_q8_1_interleave(xq_, xil_, (int) N, (int) T, cs);
strata::kernels::native_mmvq_il(head_->type(), head_->weights(), xq_, xil_, head_logits_, (int) N,
(int) n_vocab_, (int) T, cs);
} else
diff --git a/src/kernels/cuda/native_mmvq.cu b/src/kernels/cuda/native_mmvq.cu
index 6a47e6fa7..5e642a236 100644
--- a/src/kernels/cuda/native_mmvq.cu
+++ b/src/kernels/cuda/native_mmvq.cu
@@ -1389,6 +1389,46 @@ struct IlQ5K {
}
}
};
+// Q3_K (143-dense): the Q2_0 pack's dense projections are mostly Q3_K, which only had the exact layout's kernel. The
+// dot is q3_q8_dot_impl, the multi-column kernel's own call, on the same four blocks' ints and scales.
+struct IlQ3K {
+ using F = Q3KTraits;
+ static constexpr bool PM = false;
+ template <int NC, class X>
+ __device__ static void apply(const F::W& r, const X& x, int kby, int iqs, float (&out)[NC]) {
+ int u[4][NC];
+ float d8[4][NC];
+#pragma unroll
+ for (int i = 0; i < 4; ++i) {
+ const int b = kby + r.bq8_offset + i;
+ x.u(b, iqs % 8, u[i]);
+ x.scales(b, d8[i]);
+ }
+ // q3_q8_dot_impl's arithmetic with the column-independent part done once: the four scales, and the four sets of
+ // signed values (vil - vih, vih = 4 where the high bit is set, is vil | 0xFC in that byte: vil is 0..3, so nothing
+ // saturates and it is __vsubss4's result)
+ int vi[4], sc[4];
+#pragma unroll
+ for (int i = 0; i < 4; ++i) {
+ const int isc = r.scale_offset + 2 * i;
+ const int isc_low = isc % 8;
+ const int sc_shift_low = 4 * (isc / 8);
+ const int sc_low = (r.scales[isc_low] >> sc_shift_low) & 0xf;
+ const int isc_high = isc % 4;
+ const int sc_shift_high = 2 * (isc / 4);
+ const int sc_high = ((r.scales[8 + isc_high] >> sc_shift_high) & 3) << 4;
+ sc[i] = (sc_low | sc_high) - 32;
+ vi[i] = ((r.vl >> (2 * i)) & 0x03030303) | (((r.vh >> i) & 0x01010101) * 252);
+ }
+#pragma unroll
+ for (int c = 0; c < NC; ++c) {
+ float sumf = 0.0f;
+#pragma unroll
+ for (int i = 0; i < 4; ++i) sumf += d8[i][c] * (STRATA_DP4A(vi[i], u[i][c], 0) * sc[i]);
+ out[c] = r.d * sumf;
+ }
+ }
+};
struct IlQ6K {
using F = Q6KTraits;
static constexpr bool PM = false;
@@ -1467,6 +1507,10 @@ template <typename I, int R>
void launch_il(const void* weights, const void* x_il, float* y, int n_in, int n_out, int ncols, cudaStream_t s) {
const auto* w = static_cast<const typename I::F::Block*>(weights);
const unsigned blocks = unsigned(((n_out + R - 1) / R + 3) / 4);
+ if (ncols == 1) { // 143-dense: one column reads the plain q8_1 blocks (x_il is then the caller's x_q8_1)
+ native_mmvq_il_kernel<I, 1, R><<<blocks, 4 * WARP, 0, s>>>(w, static_cast<const int*>(x_il), nullptr, y, n_in, n_out);
+ return;
+ }
const Q81IlParts parts = q8_1_il_parts(x_il, n_in, ncols);
const int* xq = I::PM ? parts.pm : parts.bm;
const float* xd = parts.d;
@@ -1474,7 +1518,7 @@ void launch_il(const void* weights, const void* x_il, float* y, int n_in, int n_
#define STRATA_IL_CASE(N) case N: native_mmvq_il_kernel<I, N, R><<<blocks, 4 * WARP, 0, s>>>(w, xq, xd, y, n_in, n_out); break;
STRATA_IL_CASE(2) STRATA_IL_CASE(3) STRATA_IL_CASE(4)
#undef STRATA_IL_CASE
- default: throw std::invalid_argument("native_mmvq_il requires 2 <= ncols <= 4");
+ default: throw std::invalid_argument("native_mmvq_il requires 1 <= ncols <= 4");
}
}
@@ -2521,9 +2565,35 @@ constexpr IlRows kIlRows_70[] = {
{13, {{0, 2, 2, 2, 2}, {0, 2, 2, 2, 2}, {0, 1, 2, 2, 2}}}, // Q5_K
{14, {{0, 1, 1, 1, 1}, {0, 2, 2, 2, 2}, {0, 2, 2, 4, 2}}}, // Q6_K
};
+// RTX 30-series (sm_86), 143-dense: read off mmvq_il_parity --bench --emit-table on an RTX A4000 with the engine's real
+// shapes (the output projections have 6144 inputs, not 4096), per cell the rows count whose worst measured shape is under
+// 0.97 of native_mmvq's time. The four older rows are the shared table's; Q3_K (the Q2_0 pack's main dense type) is new.
+constexpr IlRows kIlRows_86[] = {
+ {23, {{0, 0, 0, 0, 0}, {0, 0, 2, 4, 4}, {0, 1, 1, 1, 1}}}, // IQ4_XS
+ {12, {{0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}, {0, 1, 1, 1, 1}}}, // Q4_K
+ {13, {{0, 0, 1, 1, 1}, {0, 4, 1, 1, 1}, {0, 1, 1, 1, 2}}}, // Q5_K
+ {14, {{0, 0, 1, 1, 0}, {0, 0, 1, 1, 2}, {0, 0, 1, 1, 1}}}, // Q6_K
+ {11, {{1, 2, 2, 2, 2}, {1, 1, 1, 2, 2}, {1, 1, 1, 1, 1}}}, // Q3_K (two runs; 2560x10240 at 4 columns 120 -> 70 us)
+};
+// One column: rows a warp by n_out class, 0 = native_mmvq's single-column kernels (STRATA_MMVQ_IL_T1=0 turns this off).
+struct Il1Rows { int type; uint8_t r[5]; };
+constexpr Il1Rows kIl1Rows_86[] = {
+ {11, {0, 1, 1, 1, 1}}, // Q3_K: 2560x10240 60 -> 43 us, 6144x2560 30 -> 26 us on the A4000
+};
+struct Il1Arch { int cc; const Il1Rows* t; size_t n; };
+constexpr Il1Arch kIl1Arch[] = {
+ {86, kIl1Rows_86, sizeof(kIl1Rows_86) / sizeof(Il1Rows)},
+};
+bool il_env_on(const char* name) {
+ const char* v = std::getenv(name);
+ return v == nullptr || v[0] != '0';
+}
+bool il_t1_on() { static const bool on = il_env_on("STRATA_MMVQ_IL_T1"); return on; }
+bool il_q3k_on() { static const bool on = il_env_on("STRATA_MMVQ_IL_Q3K"); return on; }
struct IlArch { int cc; const IlRows* t; size_t n; };
constexpr IlArch kIlArch[] = {
{70, kIlRows_70, sizeof(kIlRows_70) / sizeof(IlRows)}, // Volta: PR 1401, measured on a V100-SXM2
+ {86, kIlRows_86, sizeof(kIlRows_86) / sizeof(IlRows)}, // 143-dense: RTX A4000 with the real shapes (Q3_K added)
};
// STRATA_MMVQ_IL_ROWS="type:ncols:r0,r1,r2,r3,r4;..." overrides single rows of the table for every card (type = ggml
// type 23/12/13/14, ncols 2-4, r* = rows a warp 0/1/2/4 for the five n_out classes). Parsed once.
@@ -2540,7 +2610,7 @@ const std::vector<IlEnvRow>& il_env_rows() {
if (end == std::string::npos) end = str.size();
int t = 0, n = 0, r[5] = {0, 0, 0, 0, 0}, used = 0;
if (std::sscanf(str.substr(pos, end - pos).c_str(), "%d:%d:%d,%d,%d,%d,%d%n", &t, &n, &r[0], &r[1], &r[2], &r[3],
- &r[4], &used) >= 7 && n >= 2 && n <= 4) {
+ &r[4], &used) >= 7 && n >= 1 && n <= 4) {
IlEnvRow x{t, n, {}};
bool ok = true;
for (int i = 0; i < 5; ++i) { ok = ok && (r[i] == 0 || r[i] == 1 || r[i] == 2 || r[i] == 4); x.r[i] = (uint8_t) r[i]; }
@@ -2560,10 +2630,19 @@ const std::vector<IlEnvRow>& il_env_rows() {
// The rows a warp for a card of compute capability `cc` (major * 10 + minor); 0: native_mmvq's kernels. Pure, so a test
// can check every architecture's table without that card.
int native_mmvq_il_rows_for(int cc, int type, int ncols, int n_out) {
- if (ncols < 2 || ncols > 4) return 0;
+ if (ncols < 1 || ncols > 4) return 0;
const int cls = n_out < 2048 ? 0 : n_out < 4096 ? 1 : n_out < 8192 ? 2 : n_out < 12288 ? 3 : 4;
for (const IlEnvRow& e : il_env_rows())
if (e.type == type && e.ncols == ncols) return e.r[cls];
+ if (ncols == 1) { // 143-dense: one column (the plain q8_1 blocks, no interleaved copy); STRATA_MMVQ_IL_T1=0 turns it off
+ if (!il_t1_on()) return 0;
+ for (const Il1Arch& a : kIl1Arch)
+ if (a.cc == cc)
+ for (size_t i = 0; i < a.n; ++i)
+ if (a.t[i].type == type) return a.t[i].r[cls];
+ return 0;
+ }
+ if (type == 11 && !il_q3k_on()) return 0; // STRATA_MMVQ_IL_Q3K=0: Q3_K keeps native_mmvq's kernels
const IlRows* t = kIlRowsShared;
size_t n = sizeof(kIlRowsShared) / sizeof(IlRows);
for (const IlArch& a : kIlArch)
@@ -2611,9 +2690,9 @@ bool il_arch_ok() {
} // namespace
bool native_mmvq_il_supported(int ggml_type, int ncols, int n_out) {
- if (ncols < 2 || ncols > 4 || !g_multi_exact || !il_arch_ok()) return false;
+ if (ncols < 1 || ncols > 4 || !g_multi_exact || !il_arch_ok()) return false;
return (g_tune_rows ? g_tune_rows : il_rows(ggml_type, ncols, n_out)) != 0 &&
- (ggml_type == 23 || ggml_type == 12 || ggml_type == 13 || ggml_type == 14);
+ (ggml_type == 23 || ggml_type == 12 || ggml_type == 13 || ggml_type == 14 || ggml_type == 11);
}
void native_mmvq_il(int ggml_type, const void* weights, const void* x_q8_1, const void* x_il, float* y, int n_in,
@@ -2625,6 +2704,7 @@ void native_mmvq_il(int ggml_type, const void* weights, const void* x_q8_1, cons
const int r = g_tune_rows ? g_tune_rows : il_rows(ggml_type, ncols, n_out);
validate_shape(n_in, ncols, QK);
validate_pointer(weights);
+ if (ncols == 1) x_il = x_q8_1; // one column: the plain blocks, no interleaved copy
validate_pointer(x_il);
validate_pointer(y);
validate_stream(stream);
@@ -2634,6 +2714,7 @@ void native_mmvq_il(int ggml_type, const void* weights, const void* x_q8_1, cons
case 12: launch_il_rows<IlQ4K>(r, weights, x_il, y, n_in, n_out, ncols, s); break;
case 13: launch_il_rows<IlQ5K>(r, weights, x_il, y, n_in, n_out, ncols, s); break;
case 14: launch_il_rows<IlQ6K>(r, weights, x_il, y, n_in, n_out, ncols, s); break;
+ case 11: launch_il_rows<IlQ3K>(r, weights, x_il, y, n_in, n_out, ncols, s); break;
}
launch_check();
}