CUDA : take the vec kv_rows path only for K/V pairs with a compiled vec kernel
Some checks failed
Check Pre-Tokenizer Hashes / pre-tokenizer-hashes (push) Has been cancelled
Python check requirements.txt / check-requirements (push) Has been cancelled
Python Type-Check / python type-check (push) Has been cancelled
Update Operations Documentation / update-ops-docs (push) Has been cancelled

Without a compiled vec kernel for the K/V pair (the default GGML_CUDA_FA_QUANTS has only same-type pairs), the vec kernel falls back to f16 and converts the whole cache, which is slower than the MMA kernel. Mixed pairs such as q8_0/q4_0 keep the MMA kernel as on master. The lookup also covers the head sizes of the vec kernel.
This commit is contained in:
Aman Gupta 2026-11-21 13:57:52 +08:00
parent 308bac3bc0
commit 078ffbedc7

View file

@ -695,9 +695,10 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
memcpy(&logit_softcap, (const float *) KQV->op_params + 2, sizeof(float));
// the vec kernel reads quantized/bf16/f8 K/V in place, the MMA kernel would convert the whole cache to f16
const bool vec_rows = Q->ne[0] <= 256 && Q->ne[0] % 64 == 0 && Q->ne[0] != 192 && n_kv % FATTN_KQ_STRIDE == 0 &&
// only for K/V pairs with a compiled vec kernel, the f16 fallback of the vec kernel also converts the whole cache
const bool vec_rows = n_kv % FATTN_KQ_STRIDE == 0 &&
(K->type != GGML_TYPE_F16 || V->type != GGML_TYPE_F16) && K->type != GGML_TYPE_F32 && V->type != GGML_TYPE_F32 &&
Q->ne[1] == 1 && logit_softcap == 0.0f;
Q->ne[1] == 1 && logit_softcap == 0.0f && ggml_cuda_get_fattn_vec_case(Q->ne[0], K->type, V->type) != nullptr;
if (vec_rows) {
return BEST_FATTN_KERNEL_VEC;
}