@@ -93,7 +93,7 @@ llama_context::llama_context(
93
93
// the batch has to be at least GGML_KQ_MASK_PAD because we will be padding the KQ_mask
94
94
// this is required by GPU kernels in order to avoid out-of-bounds accesses (e.g. ggml_flash_attn_ext)
95
95
// 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
97
97
if (cparams.n_batch < GGML_KQ_MASK_PAD) {
98
98
LLAMA_LOG_WARN (" %s: n_batch is less than GGML_KQ_MASK_PAD - increasing to %d\n " , __func__, GGML_KQ_MASK_PAD);
99
99
cparams.n_batch = GGML_KQ_MASK_PAD;
@@ -439,26 +439,12 @@ llama_memory_t llama_context::get_memory() const {
439
439
return memory.get ();
440
440
}
441
441
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) {
453
443
if (!memory) {
454
444
return false ;
455
445
}
456
446
457
447
{
458
- // TODO: remove in the future
459
- optimize |= memory_force_optimize;
460
- memory_force_optimize = false ;
461
-
462
448
const auto mctx = memory->init_update (this , optimize);
463
449
switch (mctx->get_status ()) {
464
450
case LLAMA_MEMORY_STATUS_SUCCESS:
@@ -993,7 +979,7 @@ int llama_context::decode(const llama_batch & batch_inp) {
993
979
bool did_optimize = false ;
994
980
995
981
// handle any pending defrags/shifts
996
- kv_self_update (false );
982
+ memory_update (false );
997
983
998
984
llama_memory_context_ptr mctx;
999
985
@@ -1018,7 +1004,7 @@ int llama_context::decode(const llama_batch & batch_inp) {
1018
1004
if (!did_optimize) {
1019
1005
did_optimize = true ;
1020
1006
1021
- if (kv_self_update (true )) {
1007
+ if (memory_update (true )) {
1022
1008
LLAMA_LOG_DEBUG (" %s: retrying batch size %d after cache optimization\n " , __func__, balloc->get_n_tokens ());
1023
1009
1024
1010
continue ;
@@ -2338,11 +2324,6 @@ const llama_model * llama_get_model(const llama_context * ctx) {
2338
2324
return &ctx->get_model ();
2339
2325
}
2340
2326
2341
- // deprecated
2342
- void llama_kv_self_update (llama_context * ctx) {
2343
- ctx->kv_self_update (false );
2344
- }
2345
-
2346
2327
enum llama_pooling_type llama_pooling_type (const llama_context * ctx) {
2347
2328
return ctx->pooling_type ();
2348
2329
}
@@ -2560,168 +2541,6 @@ bool llama_memory_can_shift(llama_memory_t mem) {
2560
2541
return mem->get_can_shift ();
2561
2542
}
2562
2543
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
-
2725
2544
// llama state API
2726
2545
2727
2546
// deprecated
0 commit comments