From c257a8871cc444df660e2dfa49d2b20c9fe77124 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Mon, 9 Jun 2025 20:45:56 +0300 Subject: [PATCH] cont : fix defrag erasing cells that didn't move ggml-ci --- src/llama-kv-cache-unified.cpp | 2 +- src/llama-kv-cells.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/llama-kv-cache-unified.cpp b/src/llama-kv-cache-unified.cpp index d8f4e7ffc4..3566d5fd4d 100644 --- a/src/llama-kv-cache-unified.cpp +++ b/src/llama-kv-cache-unified.cpp @@ -462,7 +462,7 @@ bool llama_kv_cache_unified::update(llama_context * lctx, bool do_shift, const d for (uint32_t i = 0; i < n_kv; ++i) { assert(dinfo.ids[i] <= n_kv); - if (dinfo.ids[i] == n_kv) { + if (dinfo.ids[i] == n_kv || dinfo.ids[i] == i) { continue; } diff --git a/src/llama-kv-cells.h b/src/llama-kv-cells.h index d71853592f..acf30aebec 100644 --- a/src/llama-kv-cells.h +++ b/src/llama-kv-cells.h @@ -80,6 +80,9 @@ public: assert(isrc < pos.size()); assert(idst < pos.size()); + assert(pos[idst] == -1); + assert(pos[isrc] != -1); + pos [idst] = pos [isrc]; shift[idst] = shift[isrc]; seq [idst] = seq [isrc];