@@ -102,8 +102,8 @@ def _load_shared_library(lib_base_name: str):
102
102
103
103
# define LLAMA_SESSION_MAGIC LLAMA_FILE_MAGIC_GGSN
104
104
LLAMA_SESSION_MAGIC = LLAMA_FILE_MAGIC_GGSN
105
- # define LLAMA_SESSION_VERSION 1
106
- LLAMA_SESSION_VERSION = 1
105
+ # define LLAMA_SESSION_VERSION 2
106
+ LLAMA_SESSION_VERSION = 2
107
107
108
108
109
109
# struct llama_model;
@@ -624,6 +624,16 @@ def llama_n_embd(model: llama_model_p) -> int:
624
624
_lib .llama_n_embd .restype = c_int
625
625
626
626
627
+ # // Get the model's RoPE frequency scaling factor
628
+ # LLAMA_API float llama_rope_freq_scale_train(const struct llama_model * model);
629
+ def llama_rope_freq_scale_train (model : llama_model_p ) -> float :
630
+ return _lib .llama_rope_freq_scale_train (model )
631
+
632
+
633
+ _lib .llama_rope_freq_scale_train .argtypes = [llama_model_p ]
634
+ _lib .llama_rope_freq_scale_train .restype = c_float
635
+
636
+
627
637
# // Get a string describing the model type
628
638
# LLAMA_API int llama_model_desc(const struct llama_model * model, char * buf, size_t buf_size);
629
639
def llama_model_desc (
@@ -768,6 +778,8 @@ def llama_get_kv_cache_token_count(ctx: llama_context_p) -> int:
768
778
769
779
770
780
# // Remove all tokens data of cells in [c0, c1)
781
+ # // c0 < 0 : [0, c1]
782
+ # // c1 < 0 : [c0, inf)
771
783
# LLAMA_API void llama_kv_cache_tokens_rm(
772
784
# struct llama_context * ctx,
773
785
# int32_t c0,
@@ -783,6 +795,8 @@ def llama_kv_cache_tokens_rm(
783
795
784
796
785
797
# // Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
798
+ # // p0 < 0 : [0, p1]
799
+ # // p1 < 0 : [p0, inf)
786
800
# LLAMA_API void llama_kv_cache_seq_rm(
787
801
# struct llama_context * ctx,
788
802
# llama_seq_id seq_id,
@@ -808,6 +822,8 @@ def llama_kv_cache_seq_rm(
808
822
809
823
# // Copy all tokens that belong to the specified sequence to another sequence
810
824
# // Note that this does not allocate extra KV cache memory - it simply assigns the tokens to the new sequence
825
+ # // p0 < 0 : [0, p1]
826
+ # // p1 < 0 : [p0, inf)
811
827
# LLAMA_API void llama_kv_cache_seq_cp(
812
828
# struct llama_context * ctx,
813
829
# llama_seq_id seq_id_src,
@@ -851,6 +867,8 @@ def llama_kv_cache_seq_keep(
851
867
852
868
# // Adds relative position "delta" to all tokens that belong to the specified sequence and have positions in [p0, p1)
853
869
# // If the KV cache is RoPEd, the KV data is updated accordingly
870
+ # // p0 < 0 : [0, p1]
871
+ # // p1 < 0 : [p0, inf)
854
872
# LLAMA_API void llama_kv_cache_seq_shift(
855
873
# struct llama_context * ctx,
856
874
# llama_seq_id seq_id,
@@ -1215,6 +1233,43 @@ def llama_token_nl(ctx: llama_context_p) -> int:
1215
1233
_lib .llama_token_nl .restype = llama_token
1216
1234
1217
1235
1236
+ # // codellama infill tokens
1237
+ # LLAMA_API llama_token llama_token_prefix(const struct llama_context * ctx); // Beginning of infill prefix
1238
+ def llama_token_prefix (ctx : llama_context_p ) -> int :
1239
+ return _lib .llama_token_prefix (ctx )
1240
+
1241
+
1242
+ _lib .llama_token_prefix .argtypes = [llama_context_p ]
1243
+ _lib .llama_token_prefix .restype = llama_token
1244
+
1245
+
1246
+ # LLAMA_API llama_token llama_token_middle(const struct llama_context * ctx); // Beginning of infill middle
1247
+ def llama_token_middle (ctx : llama_context_p ) -> int :
1248
+ return _lib .llama_token_middle (ctx )
1249
+
1250
+
1251
+ _lib .llama_token_middle .argtypes = [llama_context_p ]
1252
+ _lib .llama_token_middle .restype = llama_token
1253
+
1254
+
1255
+ # LLAMA_API llama_token llama_token_suffix(const struct llama_context * ctx); // Beginning of infill suffix
1256
+ def llama_token_suffix (ctx : llama_context_p ) -> int :
1257
+ return _lib .llama_token_suffix (ctx )
1258
+
1259
+
1260
+ _lib .llama_token_suffix .argtypes = [llama_context_p ]
1261
+ _lib .llama_token_suffix .restype = llama_token
1262
+
1263
+
1264
+ # LLAMA_API llama_token llama_token_eot (const struct llama_context * ctx); // End of infill middle
1265
+ def llama_token_eot (ctx : llama_context_p ) -> int :
1266
+ return _lib .llama_token_eot (ctx )
1267
+
1268
+
1269
+ _lib .llama_token_eot .argtypes = [llama_context_p ]
1270
+ _lib .llama_token_eot .restype = llama_token
1271
+
1272
+
1218
1273
# //
1219
1274
# // Tokenization
1220
1275
# //
@@ -1728,6 +1783,7 @@ def llama_grammar_accept_token(
1728
1783
# struct llama_beam_view {
1729
1784
# const llama_token * tokens;
1730
1785
1786
+
1731
1787
# size_t n_tokens;
1732
1788
# float p; // Cumulative beam probability (renormalized relative to all beams)
1733
1789
# bool eob; // Callback should set this to true when a beam is at end-of-beam.
@@ -1794,6 +1850,7 @@ def llama_beam_search(
1794
1850
ctx , callback , callback_data , n_beams , n_past , n_predict
1795
1851
)
1796
1852
1853
+
1797
1854
_lib .llama_beam_search .argtypes = [
1798
1855
llama_context_p ,
1799
1856
llama_beam_search_callback_fn_t ,
0 commit comments