Skip to content

Commit 8687c1f

Browse files
authored
llama : remember and restore kv cache data pointers (#1104)
because their value is stored in buf and overwritten by memcpy
1 parent 1bfc153 commit 8687c1f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llama.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,11 @@ void llama_set_kv_cache(
20922092
int n_token_count) {
20932093
// Make sure we have the same kv cache setup
20942094
LLAMA_ASSERT(ctx->model.kv_self.buf.size == n_size);
2095+
void * k_data = ctx->model.kv_self.k->data; // remember data pointers
2096+
void * v_data = ctx->model.kv_self.v->data; // because their value is stored in buf and overwritten by memcpy
20952097
memcpy(ctx->model.kv_self.buf.addr, kv_cache, n_size);
2098+
ctx->model.kv_self.k->data = k_data; // restore correct data pointers
2099+
ctx->model.kv_self.v->data = v_data;
20962100
ctx->model.kv_self.n = n_token_count;
20972101
}
20982102

0 commit comments

Comments
 (0)