From 285e90aee284c09ac41b8fa3bb5e26f9d65a464e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 15 Oct 2026 06:42:44 +0200 Subject: [PATCH] qsa_prompt_attn: Q4_0 KV prompt attention on Turing, opt-in STRATA_PROMPT_ATTN_Q4_TC=1 (#1581, the Q4 attention part only) Ported from c3c's #1581 (the native-IQ and VRAM-loan parts are not in this commit). Default unchanged: Turing keeps returning false for q4_0. Co-authored-by: c3c --- src/kernels/cuda/qsa_prompt_attn.cu | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu index 10a061da..54f40e9a 100644 --- a/src/kernels/cuda/qsa_prompt_attn.cu +++ b/src/kernels/cuda/qsa_prompt_attn.cu @@ -1623,8 +1623,13 @@ bool qsa_prompt_attn_batch(const float* q, const QsaAttnPools& pools, const int3 const char* v = std::getenv("STRATA_PROMPT_ATTN_Q4"); return v != nullptr && v[0] == '0'; }(); - // sm_80+ only: on Turing mode 4 would run as pairs of m16n8k8 MMAs, which no parity run has checked yet - if (q4_off || turing || pools.v_q4 == nullptr) return false; + // Turing runs mode 4 as pairs of m16n8k8 MMAs (another summation order than the FP32 kernel it replaces): manual + // opt-in STRATA_PROMPT_ATTN_Q4_TC=1 (#1581, c3c: qsa_prompt_attn_parity at 4096/512 and 1500/512 on an RTX 2080 Super). + static const bool q4_tc = [] { + const char* v = std::getenv("STRATA_PROMPT_ATTN_Q4_TC"); + return v != nullptr && v[0] == '1'; + }(); + if (q4_off || volta || (turing && !q4_tc) || pools.v_q4 == nullptr) return false; return launch<4>(q, pools, ids, steps, cap, s, attn, n_q, st); } if (pools.k_q != nullptr && pools.v_q4 != nullptr) { // hybrid K8V4: int8 K + dequantized-q4 V