]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : remember and restore kv cache data pointers (#1104)
authorxaedes <redacted>
Fri, 21 Apr 2023 15:25:21 +0000 (17:25 +0200)
committerGitHub <redacted>
Fri, 21 Apr 2023 15:25:21 +0000 (18:25 +0300)
because their value is stored in buf and overwritten by memcpy

llama.cpp

index 33ee4fbb5947461a0f2685a6fb7ce73354c22bf1..0345b61c6b3b6c33a155f89a09ac387e5091ed9b 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -2092,7 +2092,11 @@ void llama_set_kv_cache(
                          int   n_token_count) {
     // Make sure we have the same kv cache setup
     LLAMA_ASSERT(ctx->model.kv_self.buf.size == n_size);
+    void * k_data = ctx->model.kv_self.k->data; // remember data pointers
+    void * v_data = ctx->model.kv_self.v->data; // because their value is stored in buf and overwritten by memcpy
     memcpy(ctx->model.kv_self.buf.addr, kv_cache, n_size);
+    ctx->model.kv_self.k->data = k_data; // restore correct data pointers
+    ctx->model.kv_self.v->data = v_data;
     ctx->model.kv_self.n = n_token_count;
 }