]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server : fix cache reuse logic (#12161)
authorClauszy <redacted>
Wed, 5 Mar 2025 07:25:45 +0000 (15:25 +0800)
committerGitHub <redacted>
Wed, 5 Mar 2025 07:25:45 +0000 (09:25 +0200)
The first kv shift offsets the positions of all tokens after head_c.
When using llama_kv_cache_seq_rm next, using head_c will remove the valid tokens because their positions have already been offset.

examples/server/server.cpp

index 2306dc26fe43121627fbd7c7880bd1f81f01d8be..e4f7e43fdcd46931c79f08a213d3691c63dd4bb1 100644 (file)
@@ -3003,7 +3003,7 @@ struct server_context {
                                             const int64_t kv_shift = (int64_t) head_p - (int64_t) head_c;
 
                                             llama_kv_cache_seq_rm (ctx, slot.id, head_p, head_c);
-                                            llama_kv_cache_seq_add(ctx, slot.id, head_c, -1,     kv_shift);
+                                            llama_kv_cache_seq_add(ctx, slot.id, head_c, head_c + n_match, kv_shift);
 
                                             for (size_t i = 0; i < n_match; i++) {
                                                 slot.cache_tokens[head_p + i] = slot.cache_tokens[head_c + i];