@@ -61,10 +61,7 @@ extern "C" {
61
61
struct llama_model ;
62
62
struct llama_context ;
63
63
struct llama_sampler ;
64
-
65
- typedef struct llama_memory_i * llama_memory_t ;
66
-
67
- struct llama_kv_cache ; // DEPRECATED (use llama_memory instead)
64
+ struct llama_kv_cache ;
68
65
69
66
typedef int32_t llama_pos;
70
67
typedef int32_t llama_token;
@@ -496,11 +493,9 @@ extern "C" {
496
493
DEPRECATED (LLAMA_API int32_t llama_n_vocab (const struct llama_vocab * vocab), "use llama_vocab_n_tokens instead");
497
494
498
495
LLAMA_API const struct llama_model * llama_get_model (const struct llama_context * ctx);
499
- LLAMA_API llama_memory_t llama_get_memory ( const struct llama_context * ctx);
496
+ LLAMA_API struct llama_kv_cache * llama_get_kv_self ( struct llama_context * ctx);
500
497
LLAMA_API enum llama_pooling_type llama_pooling_type (const struct llama_context * ctx); // TODO: rename to llama_get_pooling_type
501
498
502
- DEPRECATED (LLAMA_API struct llama_kv_cache * llama_get_kv_self (struct llama_context * ctx), "use llama_get_memory instead");
503
-
504
499
LLAMA_API const struct llama_vocab * llama_model_get_vocab (const struct llama_model * model);
505
500
LLAMA_API enum llama_rope_type llama_model_rope_type (const struct llama_model * model);
506
501
@@ -614,78 +609,7 @@ extern "C" {
614
609
int32_t il_end);
615
610
616
611
//
617
- // Memory
618
- //
619
-
620
- // Clear the memory contents
621
- LLAMA_API void llama_memory_clear (llama_memory_t mem);
622
-
623
- // Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
624
- // Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails
625
- // seq_id < 0 : match any sequence
626
- // p0 < 0 : [0, p1]
627
- // p1 < 0 : [p0, inf)
628
- LLAMA_API bool llama_memory_seq_rm (
629
- llama_memory_t mem,
630
- llama_seq_id seq_id,
631
- llama_pos p0,
632
- llama_pos p1);
633
-
634
- // Copy all tokens that belong to the specified sequence to another sequence
635
- // p0 < 0 : [0, p1]
636
- // p1 < 0 : [p0, inf)
637
- LLAMA_API void llama_memory_seq_cp (
638
- llama_memory_t mem,
639
- llama_seq_id seq_id_src,
640
- llama_seq_id seq_id_dst,
641
- llama_pos p0,
642
- llama_pos p1);
643
-
644
- // Removes all tokens that do not belong to the specified sequence
645
- LLAMA_API void llama_memory_seq_keep (
646
- llama_memory_t mem,
647
- llama_seq_id seq_id);
648
-
649
- // Adds relative position "delta" to all tokens that belong to the specified sequence and have positions in [p0, p1)
650
- // p0 < 0 : [0, p1]
651
- // p1 < 0 : [p0, inf)
652
- LLAMA_API void llama_memory_seq_add (
653
- llama_memory_t mem,
654
- llama_seq_id seq_id,
655
- llama_pos p0,
656
- llama_pos p1,
657
- llama_pos delta);
658
-
659
- // Integer division of the positions by factor of `d > 1`
660
- // p0 < 0 : [0, p1]
661
- // p1 < 0 : [p0, inf)
662
- LLAMA_API void llama_memory_seq_div (
663
- llama_memory_t mem,
664
- llama_seq_id seq_id,
665
- llama_pos p0,
666
- llama_pos p1,
667
- int d);
668
-
669
- // Returns the smallest position present in the memory for the specified sequence
670
- // This is typically non-zero only for SWA caches
671
- // Note that all positions in the range [pos_min, pos_max] are guaranteed to be present in the memory
672
- // Return -1 if the sequence is empty
673
- LLAMA_API llama_pos llama_memory_seq_pos_min (
674
- llama_memory_t mem,
675
- llama_seq_id seq_id);
676
-
677
- // Returns the largest position present in the memory for the specified sequence
678
- // Note that all positions in the range [pos_min, pos_max] are guaranteed to be present in the memory
679
- // Return -1 if the sequence is empty
680
- LLAMA_API llama_pos llama_memory_seq_pos_max (
681
- llama_memory_t mem,
682
- llama_seq_id seq_id);
683
-
684
- // Check if the memory supports shifting
685
- LLAMA_API bool llama_memory_can_shift (llama_memory_t mem);
686
-
687
- //
688
- // KV cache for self-attention (TODO: deprecate in favor of llama_memory)
612
+ // KV cache
689
613
//
690
614
691
615
// Returns the number of tokens in the KV cache (slow, use only for debug)
@@ -699,7 +623,7 @@ extern "C" {
699
623
700
624
// Clear the KV cache - both cell info is erased and KV data is zeroed
701
625
LLAMA_API void llama_kv_self_clear (
702
- struct llama_context * ctx);
626
+ struct llama_context * ctx);
703
627
704
628
// Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
705
629
// Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails
@@ -770,22 +694,22 @@ extern "C" {
770
694
// Defragment the KV cache
771
695
// This will be applied:
772
696
// - lazily on next llama_decode()
773
- DEPRECATED ( LLAMA_API void llama_kv_self_defrag (struct llama_context * ctx),
697
+ LLAMA_API DEPRECATED ( void llama_kv_self_defrag (struct llama_context * ctx),
774
698
"simply remove this call, the context will automatically decide when to do a defragmentation based on 'defrag_thold'");
775
699
776
700
// Check if the context supports KV cache shifting
777
701
LLAMA_API bool llama_kv_self_can_shift (const struct llama_context * ctx);
778
702
779
703
// Apply the KV cache updates (such as K-shifts, defragmentation, etc.)
780
- DEPRECATED ( LLAMA_API void llama_kv_self_update (struct llama_context * ctx),
704
+ LLAMA_API DEPRECATED ( void llama_kv_self_update (struct llama_context * ctx),
781
705
"simply remove this call, updates are applied lazily on the next llama_decode()");
782
706
783
707
//
784
708
// State / sessions
785
709
//
786
710
787
711
// Returns the *actual* size in bytes of the state
788
- // (logits, embedding and memory )
712
+ // (logits, embedding and kv_cache )
789
713
// Only use when saving the state, not when restoring it, otherwise the size may be too small.
790
714
LLAMA_API size_t llama_state_get_size (struct llama_context * ctx);
791
715
LLAMA_API DEPRECATED (size_t llama_get_state_size (struct llama_context * ctx),
@@ -841,12 +765,12 @@ extern "C" {
841
765
size_t n_token_count),
842
766
"use llama_state_save_file instead");
843
767
844
- // Get the exact size needed to copy the state of a single sequence
768
+ // Get the exact size needed to copy the KV cache of a single sequence
845
769
LLAMA_API size_t llama_state_seq_get_size (
846
770
struct llama_context * ctx,
847
771
llama_seq_id seq_id);
848
772
849
- // Copy the state of a single sequence into the specified buffer
773
+ // Copy the KV cache of a single sequence into the specified buffer
850
774
LLAMA_API size_t llama_state_seq_get_data (
851
775
struct llama_context * ctx,
852
776
uint8_t * dst,
@@ -912,16 +836,16 @@ extern "C" {
912
836
// For encode-decoder contexts, processes the batch using the encoder.
913
837
// Can store the encoder output internally for later use by the decoder's cross-attention layers.
914
838
// 0 - success
915
- // < 0 - error. the memory state is restored to the state before this call
839
+ // < 0 - error. the KV cache state is restored to the state before this call
916
840
LLAMA_API int32_t llama_encode (
917
841
struct llama_context * ctx,
918
842
struct llama_batch batch);
919
843
920
844
// Process a batch of tokens.
921
- // Requires the context to have a memory .
845
+ // Requires KV cache .
922
846
// For encode-decoder contexts, processes the batch using the decoder.
923
847
// Positive return values does not mean a fatal error, but rather a warning.
924
- // Upon non-zero return values, the memory state is restored to the state before this call
848
+ // Upon non-zero return values, the KV cache state is restored to the state before this call
925
849
// 0 - success
926
850
// 1 - could not find a KV slot for the batch (try reducing the size of the batch or increase the context)
927
851
// 2 - aborted
0 commit comments