diff --git a/src/llama-kv-cache-unified.cpp b/src/llama-kv-cache-unified.cpp index d8f4e7ffc..3566d5fd4 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 d71853592..acf30aebe 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];