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

prefill: an MMQ product without a tile on some GPU takes the non-MMQ path instead of aborting (#420, qni-live)

Niko1221d5871c1af178
diff --git a/include/strata/prefill/moe_mmq.hpp b/include/strata/prefill/moe_mmq.hpp
index a8c6714ec..d9f0eba6f 100644
--- a/include/strata/prefill/moe_mmq.hpp
+++ b/include/strata/prefill/moe_mmq.hpp
@@ -15,6 +15,10 @@ bool built();
/// MMQ covers this ggml type (the i-quants and Q2_0 the packs use, Q8_0, and in a CUDA build with STRATA_MMQ_KQUANTS
/// the Q4_K / Q5_K / Q5_1 of Unsloth's UD-Q4_K_XL; IQ1_M is not covered).
bool supported(int ggml_type);
+/// #420: `supported`, and on every visible GPU llama.cpp's MMQ has a tile for this type and a weight matrix of
+/// `w_rows` rows that fits the card's shared memory - the same test its tile choice makes, which aborts the process
+/// ("J_best=0") when nothing fits. false (said once per type) keeps that product on the non-MMQ path.
+bool fits(int ggml_type, int64_t w_rows);
/// Bytes of one expert's gate+up ([2*n_ff, n_embd]) or down ([n_embd, n_ff]) weights in `ggml_type`.
size_t matrix_bytes(int ggml_type, int64_t rows, int64_t cols);
/// Bytes of `rows` activation rows of `cols` values quantized for MMQ (the row padded to 512 values).
diff --git a/src/prefill/moe_mmq.cu b/src/prefill/moe_mmq.cu
index f1e398748..1f0221c71 100644
--- a/src/prefill/moe_mmq.cu
+++ b/src/prefill/moe_mmq.cu
@@ -107,6 +107,34 @@ bool supported(int t) {
}
}
+bool fits(int t, int64_t w_rows) {
+ if (!supported(t)) return false;
+ // mul_mat_q_case's choice: the "fallback" configs when the rows are not a multiple of 128; then
+ // mul_mat_q_switch_J's loop - a tile size whose config exists for this card and fits its shared memory
+ const bool fallback = w_rows % 128 != 0;
+ const ggml_cuda_device_info& info = ggml_cuda_info();
+ for (int id = 0; id < info.device_count; ++id) {
+ const int cc = info.devices[id].cc;
+ const size_t smpbo = info.devices[id].smpbo;
+ bool any = false;
+ for (int J = 8; J <= 128 && !any; J += 8) {
+ const ggml_cuda_mmq_config c = ggml_cuda_mmq_get_config((ggml_type) t, J, fallback, cc);
+ any = c.type != GGML_TYPE_COUNT && mmq_get_nbytes_shared(c, cc) <= smpbo;
+ }
+ if (!any) {
+ static bool said[GGML_TYPE_COUNT] = {};
+ if (t >= 0 && t < GGML_TYPE_COUNT && !said[t]) {
+ said[t] = true;
+ std::fprintf(stderr, "strata: prompt kernels: llama.cpp's MMQ has no tile for %s (%lld rows) on GPU %d "
+ "(cc %d, %zu bytes of shared memory per block): that product takes the non-MMQ path "
+ "(#420)\n", ggml_type_name((ggml_type) t), (long long) w_rows, id, cc, smpbo);
+ }
+ return false;
+ }
+ }
+ return true;
+}
+
size_t matrix_bytes(int t, int64_t rows, int64_t cols) {
return (size_t) rows * (size_t) (cols / ggml_blck_size((ggml_type) t)) * ggml_type_size((ggml_type) t);
}
diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp
index 290b53d2a..ed47b9758 100644
--- a/src/prefill/prefill.cpp
+++ b/src/prefill/prefill.cpp
@@ -46,6 +46,7 @@
namespace strata::prefill::mmq {
bool built() { return false; }
bool supported(int) { return false; }
+bool fits(int, int64_t) { return false; }
size_t matrix_bytes(int, int64_t, int64_t) { return 0; }
size_t q8_bytes(int64_t, int64_t) { return 0; }
void quantize(const float*, const int32_t*, void*, int, int64_t, int64_t, int64_t, void*) {}
@@ -479,7 +480,8 @@ const MmqPlan& mmq_plan() {
p.fallback = !on || layers <= 0;
for (int64_t l = 0; on && l < layers; ++l) {
const int gt = lay.native ? lay.fmt[(size_t) l].gu_type : 42, dt = lay.native ? lay.fmt[(size_t) l].d_type : 42;
- if (!mmq::supported(gt) || !mmq::supported(dt)) { p.fallback = true; continue; }
+ // #420: a tile on every GPU for these shapes (gate+up: 1280 rows, down: N rows), else the FP16 path
+ if (!mmq::fits(gt, 1280) || !mmq::fits(dt, N)) { p.fallback = true; continue; }
p.layer[(size_t) l] = 1;
p.any = true;
p.gu_max = std::max(p.gu_max, mmq::matrix_bytes(gt, 1280, N));
@@ -768,7 +770,7 @@ bool Prefill::draft_kv(core::MtpDrafter& mtp, const float* R_rows, const int32_t
// E-9: the drafter's Q8_0 matrices through Q8_1 x Q8_0 MMQ - its own pass's integer dot products (mmvq), so
// its K/V stay close to what the drafter computes itself; STRATA_MTP_BATCH_F16=1: FP16 GEMMs (the A/B)
static const bool f16_only = [] { const char* v = std::getenv("STRATA_MTP_BATCH_F16"); return v && v[0] == '1'; }();
- const bool q8 = !f16_only && mmq::built() && mmq::supported(kQ8_0);
+ const bool q8 = !f16_only && mmq::built() && mmq::fits(kQ8_0, Nn) && mmq::fits(kQ8_0, KV); // #420
const uint64_t per_row = 4 * (2 * Nn + 4 * HCN + LR + HC + Nn + 2 * KV + 1) + 2 * (Nn + 2 * HCN + LR + Nn) + 64 +
(q8 ? (uint64_t) mmq::q8_bytes(g.hc, Nn) + 4 * g.hc : 0);
const int64_t B = std::min<int64_t>(n - r0, (int64_t) (m.region_bytes / per_row) & ~(int64_t) 63);