From f348aacad88d5c43ed167a2723debc698bbca4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Szymczyk?= Date: Sat, 18 Jul 2026 20:44:27 +0200 Subject: [PATCH 1/2] llama : enforce the same K and V cache types for DeepSeek V4; enable FA if V cache is quantized --- src/llama-context.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/llama-context.cpp b/src/llama-context.cpp index eed041eef4e7..49da4a55e8c5 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -3538,6 +3538,22 @@ llama_context * llama_init_from_model( } } + if (model->arch == LLM_ARCH_DEEPSEEK4 && params.type_k != params.type_v) { + LLAMA_LOG_ERROR("%s: DeepSeek V4 does not support different K (%s) and V (%s) cache types\n", __func__, ggml_type_name(params.type_k), ggml_type_name(params.type_v)); + return nullptr; + } + + if (ggml_is_quantized(params.type_v) && params.flash_attn_type != LLAMA_FLASH_ATTN_TYPE_ENABLED) { + if (params.flash_attn_type == LLAMA_FLASH_ATTN_TYPE_AUTO) { + LLAMA_LOG_INFO("%s: enabling flash_attn since it is required for quantized V cache\n", __func__); + params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED; + } + if (params.flash_attn_type == LLAMA_FLASH_ATTN_TYPE_DISABLED) { + LLAMA_LOG_ERROR("%s: quantized V cache requires flash_attn to be enabled\n", __func__); + return nullptr; + } + } + if (params.flash_attn_type != LLAMA_FLASH_ATTN_TYPE_DISABLED && ggml_is_quantized(params.type_k)) { const uint32_t blck_size = ggml_blck_size(params.type_k); for (uint32_t il = 0; il < model->hparams.n_layer(); ++il) { @@ -3560,11 +3576,6 @@ llama_context * llama_init_from_model( } } - if (ggml_is_quantized(params.type_v) && params.flash_attn_type == LLAMA_FLASH_ATTN_TYPE_DISABLED) { - LLAMA_LOG_ERROR("%s: V cache quantization requires flash_attn\n", __func__); - return nullptr; - } - if (params.pooling_type != LLAMA_POOLING_TYPE_UNSPECIFIED && params.pooling_type != model->hparams.pooling_type) { //user-specified pooling-type is different from the model default From 8e0a652d04dd0eaf94bafa330a880ec50b90de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Szymczyk?= Date: Tue, 28 Jul 2026 10:14:23 +0200 Subject: [PATCH 2/2] llama : enforce the same K and V cache types for MLA models --- src/llama-context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llama-context.cpp b/src/llama-context.cpp index 49da4a55e8c5..836c2ad98dd4 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -3538,8 +3538,8 @@ llama_context * llama_init_from_model( } } - if (model->arch == LLM_ARCH_DEEPSEEK4 && params.type_k != params.type_v) { - LLAMA_LOG_ERROR("%s: DeepSeek V4 does not support different K (%s) and V (%s) cache types\n", __func__, ggml_type_name(params.type_k), ggml_type_name(params.type_v)); + if ((model->hparams.is_mla() || model->arch == LLM_ARCH_DEEPSEEK4) && params.type_k != params.type_v) { + LLAMA_LOG_ERROR("%s: model does not support different K (%s) and V (%s) cache types\n", __func__, ggml_type_name(params.type_k), ggml_type_name(params.type_v)); return nullptr; }