@@ -164,6 +164,8 @@ int main(int argc, char ** argv) {
164164 return 1 ;
165165 }
166166
167+ llama_kv_cache * kv = llama_get_kv_cache (ctx);
168+
167169 const llama_vocab * vocab = llama_model_get_vocab (model);
168170
169171 LOG_INF (" %s: llama threadpool init, n_threads = %d\n " , __func__, (int ) params.cpuparams .n_threads );
@@ -326,7 +328,7 @@ int main(int argc, char ** argv) {
326328 }
327329
328330 // remove any "future" tokens that we might have inherited from the previous session
329- llama_kv_cache_seq_rm (ctx , -1 , n_matching_session_tokens, -1 );
331+ llama_kv_cache_seq_rm (kv , -1 , n_matching_session_tokens, -1 );
330332 }
331333
332334 LOG_DBG (" recalculate the cached logits (check): embd_inp.size() %zu, n_matching_session_tokens %zu, embd_inp.size() %zu, session_tokens.size() %zu\n " ,
@@ -567,8 +569,8 @@ int main(int argc, char ** argv) {
567569 LOG_DBG (" context full, swapping: n_past = %d, n_left = %d, n_ctx = %d, n_keep = %d, n_discard = %d\n " ,
568570 n_past, n_left, n_ctx, params.n_keep , n_discard);
569571
570- llama_kv_cache_seq_rm (ctx , 0 , params.n_keep , params.n_keep + n_discard);
571- llama_kv_cache_seq_add (ctx , 0 , params.n_keep + n_discard, n_past, -n_discard);
572+ llama_kv_cache_seq_rm (kv , 0 , params.n_keep , params.n_keep + n_discard);
573+ llama_kv_cache_seq_add (kv , 0 , params.n_keep + n_discard, n_past, -n_discard);
572574
573575 n_past -= n_discard;
574576
@@ -591,9 +593,9 @@ int main(int argc, char ** argv) {
591593 LOG_DBG (" div: [%6d, %6d] / %6d -> [%6d, %6d]\n " , ga_i + ib*bd, ga_i + ib*bd + ga_w, ga_n, (ga_i + ib*bd)/ga_n, (ga_i + ib*bd + ga_w)/ga_n);
592594 LOG_DBG (" shift: [%6d, %6d] + %6d -> [%6d, %6d]\n " , ga_i + ib*bd + ga_w, n_past + ib*bd, dd, ga_i + ib*bd + ga_w + dd, n_past + ib*bd + dd);
593595
594- llama_kv_cache_seq_add (ctx , 0 , ga_i, n_past, ib*bd);
595- llama_kv_cache_seq_div (ctx , 0 , ga_i + ib*bd, ga_i + ib*bd + ga_w, ga_n);
596- llama_kv_cache_seq_add (ctx , 0 , ga_i + ib*bd + ga_w, n_past + ib*bd, dd);
596+ llama_kv_cache_seq_add (kv , 0 , ga_i, n_past, ib*bd);
597+ llama_kv_cache_seq_div (kv , 0 , ga_i + ib*bd, ga_i + ib*bd + ga_w, ga_n);
598+ llama_kv_cache_seq_add (kv , 0 , ga_i + ib*bd + ga_w, n_past + ib*bd, dd);
597599
598600 n_past -= bd;
599601
0 commit comments