@@ -60,6 +60,7 @@ extern "C" {
6060 struct llama_model ;
6161 struct llama_context ;
6262 struct llama_sampler ;
63+ struct llama_kv_cache ;
6364
6465 typedef int32_t llama_pos;
6566 typedef int32_t llama_token;
@@ -106,6 +107,7 @@ extern "C" {
106107 LLAMA_VOCAB_PRE_TYPE_MINERVA = 27 ,
107108 LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28 ,
108109 LLAMA_VOCAB_PRE_TYPE_GPT4O = 29 ,
110+ LLAMA_VOCAB_PRE_TYPE_SUPERBPE = 30 ,
109111 };
110112
111113 enum llama_rope_type {
@@ -469,7 +471,8 @@ extern "C" {
469471 DEPRECATED (LLAMA_API int32_t llama_n_vocab (const struct llama_vocab * vocab), "use llama_vocab_n_tokens instead");
470472
471473 LLAMA_API const struct llama_model * llama_get_model (const struct llama_context * ctx);
472- LLAMA_API enum llama_pooling_type llama_pooling_type (const struct llama_context * ctx);
474+ LLAMA_API struct llama_kv_cache * llama_get_kv_self ( struct llama_context * ctx);
475+ LLAMA_API enum llama_pooling_type llama_pooling_type (const struct llama_context * ctx); // TODO: rename to llama_get_pooling_type
473476
474477 LLAMA_API const struct llama_vocab * llama_model_get_vocab (const struct llama_model * model);
475478 LLAMA_API enum llama_rope_type llama_model_rope_type (const struct llama_model * model);
@@ -586,7 +589,7 @@ extern "C" {
586589 // KV cache
587590 //
588591
589- // TODO: remove llama_kv_cache_view_* API
592+ // TODO: start using struct llama_kv_cache
590593
591594 // Information associated with an individual cell in the KV cache view.
592595 struct llama_kv_cache_view_cell {
@@ -641,21 +644,27 @@ extern "C" {
641644
642645 // Returns the number of tokens in the KV cache (slow, use only for debug)
643646 // If a KV cell has multiple sequences assigned to it, it will be counted multiple times
644- LLAMA_API int32_t llama_get_kv_cache_token_count (const struct llama_context * ctx);
647+ LLAMA_API int32_t llama_kv_self_n_tokens (const struct llama_context * ctx);
648+
649+ DEPRECATED (LLAMA_API int32_t llama_get_kv_cache_token_count (const struct llama_context * ctx),
650+ "use llama_kv_self_n_tokens instead");
645651
646652 // Returns the number of used KV cells (i.e. have at least one sequence assigned to them)
647- LLAMA_API int32_t llama_get_kv_cache_used_cells (const struct llama_context * ctx);
653+ LLAMA_API int32_t llama_kv_self_used_cells (const struct llama_context * ctx);
654+
655+ DEPRECATED (LLAMA_API int32_t llama_get_kv_cache_used_cells (const struct llama_context * ctx),
656+ "use llama_kv_self_used_cells instead");
648657
649658 // Clear the KV cache - both cell info is erased and KV data is zeroed
650- LLAMA_API void llama_kv_cache_clear (
659+ LLAMA_API void llama_kv_self_clear (
651660 struct llama_context * ctx);
652661
653662 // Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
654663 // Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails
655664 // seq_id < 0 : match any sequence
656665 // p0 < 0 : [0, p1]
657666 // p1 < 0 : [p0, inf)
658- LLAMA_API bool llama_kv_cache_seq_rm (
667+ LLAMA_API bool llama_kv_self_seq_rm (
659668 struct llama_context * ctx,
660669 llama_seq_id seq_id,
661670 llama_pos p0,
@@ -665,25 +674,25 @@ extern "C" {
665674 // Note that this does not allocate extra KV cache memory - it simply assigns the tokens to the new sequence
666675 // p0 < 0 : [0, p1]
667676 // p1 < 0 : [p0, inf)
668- LLAMA_API void llama_kv_cache_seq_cp (
677+ LLAMA_API void llama_kv_self_seq_cp (
669678 struct llama_context * ctx,
670679 llama_seq_id seq_id_src,
671680 llama_seq_id seq_id_dst,
672681 llama_pos p0,
673682 llama_pos p1);
674683
675684 // Removes all tokens that do not belong to the specified sequence
676- LLAMA_API void llama_kv_cache_seq_keep (
685+ LLAMA_API void llama_kv_self_seq_keep (
677686 struct llama_context * ctx,
678687 llama_seq_id seq_id);
679688
680689 // Adds relative position "delta" to all tokens that belong to the specified sequence and have positions in [p0, p1)
681690 // If the KV cache is RoPEd, the KV data is updated accordingly:
682691 // - lazily on next llama_decode()
683- // - explicitly with llama_kv_cache_update ()
692+ // - explicitly with llama_kv_self_update ()
684693 // p0 < 0 : [0, p1]
685694 // p1 < 0 : [p0, inf)
686- LLAMA_API void llama_kv_cache_seq_add (
695+ LLAMA_API void llama_kv_self_seq_add (
687696 struct llama_context * ctx,
688697 llama_seq_id seq_id,
689698 llama_pos p0,
@@ -693,35 +702,87 @@ extern "C" {
693702 // Integer division of the positions by factor of `d > 1`
694703 // If the KV cache is RoPEd, the KV data is updated accordingly:
695704 // - lazily on next llama_decode()
696- // - explicitly with llama_kv_cache_update ()
705+ // - explicitly with llama_kv_self_update ()
697706 // p0 < 0 : [0, p1]
698707 // p1 < 0 : [p0, inf)
699- LLAMA_API void llama_kv_cache_seq_div (
708+ LLAMA_API void llama_kv_self_seq_div (
700709 struct llama_context * ctx,
701710 llama_seq_id seq_id,
702711 llama_pos p0,
703712 llama_pos p1,
704713 int d);
705714
706715 // Returns the largest position present in the KV cache for the specified sequence
707- LLAMA_API llama_pos llama_kv_cache_seq_pos_max (
716+ LLAMA_API llama_pos llama_kv_self_seq_pos_max (
708717 struct llama_context * ctx,
709- llama_seq_id seq_id);
710-
711- // TODO: the llama_kv_cache_defrag and llama_kv_cache_update API tightly couples llama_context with llama_kv_cache
712- // how to avoid this?
718+ llama_seq_id seq_id);
713719
714720 // Defragment the KV cache
715721 // This will be applied:
716722 // - lazily on next llama_decode()
717- // - explicitly with llama_kv_cache_update()
718- LLAMA_API void llama_kv_cache_defrag (struct llama_context * ctx);
723+ // - explicitly with llama_kv_self_update()
724+ LLAMA_API void llama_kv_self_defrag (struct llama_context * ctx);
725+
726+ // Check if the context supports KV cache shifting
727+ LLAMA_API bool llama_kv_self_can_shift (const struct llama_context * ctx);
719728
720729 // Apply the KV cache updates (such as K-shifts, defragmentation, etc.)
721- LLAMA_API void llama_kv_cache_update (struct llama_context * ctx);
730+ LLAMA_API void llama_kv_self_update (struct llama_context * ctx);
731+
732+ DEPRECATED (LLAMA_API void llama_kv_cache_clear (
733+ struct llama_context * ctx),
734+ "use llama_kv_self_clear instead");
735+
736+ DEPRECATED (LLAMA_API bool llama_kv_cache_seq_rm (
737+ struct llama_context * ctx,
738+ llama_seq_id seq_id,
739+ llama_pos p0,
740+ llama_pos p1),
741+ "use llama_kv_self_seq_rm instead");
742+
743+ DEPRECATED (LLAMA_API void llama_kv_cache_seq_cp (
744+ struct llama_context * ctx,
745+ llama_seq_id seq_id_src,
746+ llama_seq_id seq_id_dst,
747+ llama_pos p0,
748+ llama_pos p1),
749+ "use llama_kv_self_seq_cp instead");
750+
751+ DEPRECATED (LLAMA_API void llama_kv_cache_seq_keep (
752+ struct llama_context * ctx,
753+ llama_seq_id seq_id),
754+ "use llama_kv_self_seq_keep instead");
755+
756+ DEPRECATED (LLAMA_API void llama_kv_cache_seq_add (
757+ struct llama_context * ctx,
758+ llama_seq_id seq_id,
759+ llama_pos p0,
760+ llama_pos p1,
761+ llama_pos delta),
762+ "use llama_kv_self_seq_add instead");
763+
764+ DEPRECATED (LLAMA_API void llama_kv_cache_seq_div (
765+ struct llama_context * ctx,
766+ llama_seq_id seq_id,
767+ llama_pos p0,
768+ llama_pos p1,
769+ int d),
770+ "use llama_kv_self_seq_div instead");
771+
772+ DEPRECATED (LLAMA_API llama_pos llama_kv_cache_seq_pos_max (
773+ struct llama_context * ctx,
774+ llama_seq_id seq_id),
775+ "use llama_kv_self_seq_pos_max instead");
776+
777+ DEPRECATED (LLAMA_API void llama_kv_cache_defrag (struct llama_context * ctx),
778+ "use llama_kv_self_defrag instead");
779+
780+ DEPRECATED (LLAMA_API bool llama_kv_cache_can_shift (const struct llama_context * ctx),
781+ "use llama_kv_self_can_shift instead");
782+
783+ DEPRECATED (LLAMA_API void llama_kv_cache_update (struct llama_context * ctx),
784+ "use llama_kv_self_update instead");
722785
723- // Check if the context supports KV cache shifting
724- LLAMA_API bool llama_kv_cache_can_shift (struct llama_context * ctx);
725786
726787 //
727788 // State / sessions
@@ -885,6 +946,10 @@ extern "C" {
885946 // If set to true, the model will only attend to the past tokens
886947 LLAMA_API void llama_set_causal_attn (struct llama_context * ctx, bool causal_attn);
887948
949+ // Set whether the model is in warmup mode or not
950+ // If true, all model tensors are activated during llama_decode() to load and cache their weights.
951+ LLAMA_API void llama_set_warmup (struct llama_context * ctx, bool warmup);
952+
888953 // Set abort callback
889954 LLAMA_API void llama_set_abort_callback (struct llama_context * ctx, ggml_abort_callback abort_callback, void * abort_callback_data);
890955
0 commit comments