@@ -93,7 +93,7 @@ llama_context::llama_context(
9393 // the batch has to be at least GGML_KQ_MASK_PAD because we will be padding the KQ_mask
9494 // this is required by GPU kernels in order to avoid out-of-bounds accesses (e.g. ggml_flash_attn_ext)
9595 // ref: https://github.com/ggerganov/llama.cpp/pull/5021
96- // TODO: this padding is not needed for the cache-less context so we should probably move it to llama_context_kv_self
96+ // TODO: this padding is not needed for the cache-less context so we should probably move it to llama_memory
9797 if (cparams.n_batch < GGML_KQ_MASK_PAD) {
9898 LLAMA_LOG_WARN (" %s: n_batch is less than GGML_KQ_MASK_PAD - increasing to %d\n " , __func__, GGML_KQ_MASK_PAD);
9999 cparams.n_batch = GGML_KQ_MASK_PAD;
@@ -439,26 +439,12 @@ llama_memory_t llama_context::get_memory() const {
439439 return memory.get ();
440440}
441441
442- // deprecated
443- void llama_context::kv_self_defrag_sched () {
444- if (!memory) {
445- return ;
446- }
447-
448- memory_force_optimize = true ;
449- }
450-
451- // deprecated
452- bool llama_context::kv_self_update (bool optimize) {
442+ bool llama_context::memory_update (bool optimize) {
453443 if (!memory) {
454444 return false ;
455445 }
456446
457447 {
458- // TODO: remove in the future
459- optimize |= memory_force_optimize;
460- memory_force_optimize = false ;
461-
462448 const auto mctx = memory->init_update (this , optimize);
463449 switch (mctx->get_status ()) {
464450 case LLAMA_MEMORY_STATUS_SUCCESS:
@@ -993,7 +979,7 @@ int llama_context::decode(const llama_batch & batch_inp) {
993979 bool did_optimize = false ;
994980
995981 // handle any pending defrags/shifts
996- kv_self_update (false );
982+ memory_update (false );
997983
998984 llama_memory_context_ptr mctx;
999985
@@ -1018,7 +1004,7 @@ int llama_context::decode(const llama_batch & batch_inp) {
10181004 if (!did_optimize) {
10191005 did_optimize = true ;
10201006
1021- if (kv_self_update (true )) {
1007+ if (memory_update (true )) {
10221008 LLAMA_LOG_DEBUG (" %s: retrying batch size %d after cache optimization\n " , __func__, balloc->get_n_tokens ());
10231009
10241010 continue ;
@@ -2338,11 +2324,6 @@ const llama_model * llama_get_model(const llama_context * ctx) {
23382324 return &ctx->get_model ();
23392325}
23402326
2341- // deprecated
2342- void llama_kv_self_update (llama_context * ctx) {
2343- ctx->kv_self_update (false );
2344- }
2345-
23462327enum llama_pooling_type llama_pooling_type (const llama_context * ctx) {
23472328 return ctx->pooling_type ();
23482329}
@@ -2560,168 +2541,6 @@ bool llama_memory_can_shift(llama_memory_t mem) {
25602541 return mem->get_can_shift ();
25612542}
25622543
2563- //
2564- // kv cache
2565- //
2566-
2567- // deprecated
2568- int32_t llama_kv_self_n_tokens (const llama_context * ctx) {
2569- const auto * kv = llama_get_memory (ctx);
2570- if (!kv) {
2571- return 0 ;
2572- }
2573-
2574- int32_t res = 0 ;
2575-
2576- for (uint32_t s = 0 ; s < ctx->get_cparams ().n_seq_max ; s++) {
2577- const llama_pos p0 = kv->seq_pos_min (s);
2578- const llama_pos p1 = kv->seq_pos_max (s);
2579-
2580- if (p0 >= 0 ) {
2581- res += (p1 - p0) + 1 ;
2582- }
2583- }
2584-
2585- return res;
2586- }
2587-
2588- // deprecated
2589- // note: this is the same as above - will be removed anyway, so it's ok
2590- int32_t llama_kv_self_used_cells (const llama_context * ctx) {
2591- const auto * kv = llama_get_memory (ctx);
2592- if (!kv) {
2593- return 0 ;
2594- }
2595-
2596- int32_t res = 0 ;
2597-
2598- for (uint32_t s = 0 ; s < ctx->get_cparams ().n_seq_max ; s++) {
2599- const llama_pos p0 = kv->seq_pos_min (s);
2600- const llama_pos p1 = kv->seq_pos_max (s);
2601-
2602- if (p0 >= 0 ) {
2603- res += (p1 - p0) + 1 ;
2604- }
2605- }
2606-
2607- return res;
2608- }
2609-
2610- // deprecated
2611- void llama_kv_self_clear (llama_context * ctx) {
2612- auto * kv = llama_get_memory (ctx);
2613- if (!kv) {
2614- return ;
2615- }
2616-
2617- llama_memory_clear (kv, true );
2618- }
2619-
2620- // deprecated
2621- bool llama_kv_self_seq_rm (
2622- llama_context * ctx,
2623- llama_seq_id seq_id,
2624- llama_pos p0,
2625- llama_pos p1) {
2626- auto * kv = llama_get_memory (ctx);
2627- if (!kv) {
2628- return true ;
2629- }
2630-
2631- return llama_memory_seq_rm (kv, seq_id, p0, p1);
2632- }
2633-
2634- // deprecated
2635- void llama_kv_self_seq_cp (
2636- llama_context * ctx,
2637- llama_seq_id seq_id_src,
2638- llama_seq_id seq_id_dst,
2639- llama_pos p0,
2640- llama_pos p1) {
2641- auto * kv = llama_get_memory (ctx);
2642- if (!kv) {
2643- return ;
2644- }
2645-
2646- llama_memory_seq_cp (kv, seq_id_src, seq_id_dst, p0, p1);
2647- }
2648-
2649- // deprecated
2650- void llama_kv_self_seq_keep (llama_context * ctx, llama_seq_id seq_id) {
2651- auto * kv = llama_get_memory (ctx);
2652- if (!kv) {
2653- return ;
2654- }
2655-
2656- llama_memory_seq_keep (kv, seq_id);
2657- }
2658-
2659- // deprecated
2660- void llama_kv_self_seq_add (
2661- llama_context * ctx,
2662- llama_seq_id seq_id,
2663- llama_pos p0,
2664- llama_pos p1,
2665- llama_pos delta) {
2666- auto * kv = llama_get_memory (ctx);
2667- if (!kv) {
2668- return ;
2669- }
2670-
2671- llama_memory_seq_add (kv, seq_id, p0, p1, delta);
2672- }
2673-
2674- // deprecated
2675- void llama_kv_self_seq_div (
2676- llama_context * ctx,
2677- llama_seq_id seq_id,
2678- llama_pos p0,
2679- llama_pos p1,
2680- int d) {
2681- auto * kv = llama_get_memory (ctx);
2682- if (!kv) {
2683- return ;
2684- }
2685-
2686- llama_memory_seq_div (kv, seq_id, p0, p1, d);
2687- }
2688-
2689- // deprecated
2690- llama_pos llama_kv_self_seq_pos_min (llama_context * ctx, llama_seq_id seq_id) {
2691- auto * kv = llama_get_memory (ctx);
2692- if (!kv) {
2693- return -1 ;
2694- }
2695-
2696- return llama_memory_seq_pos_min (kv, seq_id);
2697- }
2698-
2699- // deprecated
2700- llama_pos llama_kv_self_seq_pos_max (llama_context * ctx, llama_seq_id seq_id) {
2701- auto * kv = llama_get_memory (ctx);
2702- if (!kv) {
2703- return -1 ;
2704- }
2705-
2706- return llama_memory_seq_pos_max (kv, seq_id);
2707- }
2708-
2709- // deprecated
2710- void llama_kv_self_defrag (llama_context * ctx) {
2711- // force defrag
2712- ctx->kv_self_defrag_sched ();
2713- }
2714-
2715- // deprecated
2716- bool llama_kv_self_can_shift (const llama_context * ctx) {
2717- auto * kv = llama_get_memory (ctx);
2718- if (!kv) {
2719- return false ;
2720- }
2721-
2722- return llama_memory_can_shift (kv);
2723- }
2724-
27252544// llama state API
27262545
27272546// deprecated
0 commit comments