Skip to content

Commit c6d9464

Browse files
ggerganovNexesenex
authored andcommitted
llama : handle KV shift for recurrent models (ggml-org#10402)
ggml-ci
1 parent 2263eb5 commit c6d9464

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/llama.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18425,13 +18425,13 @@ static void llama_kv_cache_defrag_internal(struct llama_context & lctx) {
1842518425
static void llama_kv_cache_update_internal(struct llama_context & lctx) {
1842618426
bool need_reserve = false;
1842718427

18428-
// apply K-shift if needed
18429-
if (lctx.model.hparams.rope_type != LLAMA_ROPE_TYPE_NONE && lctx.kv_self.has_shift) {
18428+
if (lctx.kv_self.has_shift) {
1843018429
if (!llama_kv_cache_can_shift(&lctx)) {
18431-
GGML_ABORT("Deepseek2 does not support K-shift");
18430+
GGML_ABORT("The current context does not support K-shift");
1843218431
}
1843318432

18434-
{
18433+
// apply K-shift if needed
18434+
if (lctx.model.hparams.rope_type != LLAMA_ROPE_TYPE_NONE) {
1843518435
ggml_backend_sched_reset(lctx.sched.get());
1843618436

1843718437
ggml_cgraph * gf = llama_build_graph_k_shift(lctx);
@@ -20682,7 +20682,7 @@ void llama_kv_cache_update(struct llama_context * ctx) {
2068220682
}
2068320683

2068420684
bool llama_kv_cache_can_shift(struct llama_context * ctx) {
20685-
return ctx->model.arch != LLM_ARCH_DEEPSEEK2; // not supported due to MLA
20685+
return !ctx->kv_self.recurrent && ctx->model.arch != LLM_ARCH_DEEPSEEK2; // not supported due to MLA
2068620686
}
2068720687

2068820688
// deprecated

0 commit comments

Comments
 (0)