| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1276,7 +1276,8 @@ def llama_flash_attn_type_name(flash_attn_type: int, /) -> Optional[bytes]: | |||
| 1276 | 1276 | # LLAMA_API const char * llama_ftype_name(enum llama_ftype ftype); | |
| 1277 | 1277 | @ctypes_function("llama_ftype_name", [ctypes.c_int], ctypes.c_char_p) | |
| 1278 | 1278 | def llama_ftype_name(ftype: int, /) -> Optional[bytes]: | |
| 1279 | - """Get the model file type (quantization) as a string, e.g. "Q8_0" or "Q4_K - Medium".""" | ||
| 1279 | + """Get the model file type (quantization) as a string, e.g. "Q8_0" or "Q4_K - Medium" | ||
| 1280 | + """ | ||
| 1280 | 1281 | ... | |
| 1281 | 1282 | ||
| 1282 | 1283 | ||
@@ -1785,7 +1786,8 @@ def llama_model_rope_freq_scale_train(model: llama_model_p, /) -> float: ... | |||
| 1785 | 1786 | # LLAMA_API uint32_t llama_model_n_cls_out(const struct llama_model * model); | |
| 1786 | 1787 | @ctypes_function("llama_model_n_cls_out", [llama_model_p_ctypes], ctypes.c_uint32) | |
| 1787 | 1788 | def llama_model_n_cls_out(model: llama_model_p, /) -> int: | |
| 1788 | - """Returns the number of classifier outputs (only valid for classifier models)""" | ||
| 1789 | + """Returns the number of classifier outputs (only valid for classifier models) | ||
| 1790 | + Undefined behavior for non-classifier models""" | ||
| 1789 | 1791 | ... | |
| 1790 | 1792 | ||
| 1791 | 1793 | ||
@@ -1851,7 +1853,7 @@ def llama_model_meta_count(model: llama_model_p, /) -> int: | |||
| 1851 | 1853 | # LLAMA_API const char * llama_model_meta_key_str(enum llama_model_meta_key key); | |
| 1852 | 1854 | @ctypes_function("llama_model_meta_key_str", [ctypes.c_int], ctypes.c_char_p) | |
| 1853 | 1855 | def llama_model_meta_key_str(key: int, /) -> Optional[bytes]: | |
| 1854 | - """Get sampling metadata key name. Returns None if the key is invalid.""" | ||
| 1856 | + """Get sampling metadata key name. Returns None if the key is invalid""" | ||
| 1855 | 1857 | ... | |
| 1856 | 1858 | ||
| 1857 | 1859 | ||
@@ -1922,7 +1924,7 @@ def llama_model_desc( | |||
| 1922 | 1924 | # LLAMA_API enum llama_ftype llama_model_ftype(const struct llama_model * model); | |
| 1923 | 1925 | @ctypes_function("llama_model_ftype", [llama_model_p_ctypes], ctypes.c_int) | |
| 1924 | 1926 | def llama_model_ftype(model: llama_model_p, /) -> int: | |
| 1925 | - """Get the model file type (quantization), e.g. LLAMA_FTYPE_MOSTLY_Q8_0.""" | ||
| 1927 | + """Get the model file type (quantization), e.g. LLAMA_FTYPE_MOSTLY_Q8_0""" | ||
| 1926 | 1928 | ... | |
| 1927 | 1929 | ||
| 1928 | 1930 | ||
@@ -2501,7 +2503,9 @@ def llama_memory_can_shift(mem: llama_memory_t, /) -> bool: | |||
| 2501 | 2503 | # LLAMA_API size_t llama_state_get_size(struct llama_context * ctx); | |
| 2502 | 2504 | @ctypes_function("llama_state_get_size", [llama_context_p_ctypes], ctypes.c_size_t) | |
| 2503 | 2505 | def llama_state_get_size(ctx: llama_context_p, /) -> int: | |
| 2504 | - """Returns the *actual* size in bytes of the state (logits, embedding and memory)""" | ||
| 2506 | + """Returns the *actual* size in bytes of the state | ||
| 2507 | + (logits, embedding and memory) | ||
| 2508 | + Only use when saving the state, not when restoring it, otherwise the size may be too small.""" | ||
| 2505 | 2509 | ... | |
| 2506 | 2510 | ||
| 2507 | 2511 | ||
@@ -3062,9 +3066,12 @@ def llama_batch_free(batch: llama_batch, /): | |||
| 3062 | 3066 | # struct llama_batch batch); | |
| 3063 | 3067 | @ctypes_function("llama_encode", [llama_context_p_ctypes, llama_batch], ctypes.c_int32) | |
| 3064 | 3068 | def llama_encode(ctx: llama_context_p, batch: llama_batch, /) -> int: | |
| 3065 | - """Process a batch of tokens using the encoder. | ||
| 3069 | + """Process a batch of tokens. | ||
| 3070 | + In contrast to llama_decode() - this call does not use KV cache. | ||
| 3071 | + For encode-decoder contexts, processes the batch using the encoder. | ||
| 3072 | + Can store the encoder output internally for later use by the decoder's cross-attention layers. | ||
| 3066 | 3073 | 0 - success | |
| 3067 | - < 0 - error""" | ||
| 3074 | + < 0 - error. the memory state is restored to the state before this call""" | ||
| 3068 | 3075 | ... | |
| 3069 | 3076 | ||
| 3070 | 3077 | ||
@@ -3086,9 +3093,15 @@ def llama_encode(ctx: llama_context_p, batch: llama_batch, /) -> int: | |||
| 3086 | 3093 | @ctypes_function("llama_decode", [llama_context_p_ctypes, llama_batch], ctypes.c_int32) | |
| 3087 | 3094 | def llama_decode(ctx: llama_context_p, batch: llama_batch, /) -> int: | |
| 3088 | 3095 | """Process a batch of tokens. | |
| 3096 | + Requires the context to have a memory. | ||
| 3097 | + For encode-decoder contexts, processes the batch using the decoder. | ||
| 3098 | + Positive return values does not mean a fatal error, but rather a warning. | ||
| 3099 | + Upon fatal-error or abort, the ubatches that managed to be been processed will remain in the memory state of the context | ||
| 3100 | + To handle this correctly, query the memory state using llama_memory_seq_pos_min() and llama_memory_seq_pos_max() | ||
| 3101 | + Upon other return values, the memory state is restored to the state before this call | ||
| 3089 | 3102 | 0 - success | |
| 3090 | 3103 | 1 - could not find a KV slot for the batch (try reducing the size of the batch or increase the context) | |
| 3091 | - 2 - aborted (processed ubatches will remain in the context's memory) | ||
| 3104 | + 2 - aborted (processed ubatches will remain in the context's memory) | ||
| 3092 | 3105 | -1 - invalid input batch | |
| 3093 | 3106 | < -1 - fatal error (processed ubatches will remain in the context's memory)""" | |
| 3094 | 3107 | ... | |
@@ -3124,15 +3137,15 @@ def llama_set_n_threads( | |||
| 3124 | 3137 | # LLAMA_API int32_t llama_n_threads(struct llama_context * ctx); | |
| 3125 | 3138 | @ctypes_function("llama_n_threads", [llama_context_p_ctypes], ctypes.c_int32) | |
| 3126 | 3139 | def llama_n_threads(ctx: llama_context_p, /) -> int: | |
| 3127 | - """Get the number of threads used for generation of a single token""" | ||
| 3140 | + """Get the number of threads used for generation of a single token.""" | ||
| 3128 | 3141 | ... | |
| 3129 | 3142 | ||
| 3130 | 3143 | ||
| 3131 | 3144 | # // Get the number of threads used for prompt and batch processing (multiple token). | |
| 3132 | 3145 | # LLAMA_API int32_t llama_n_threads_batch(struct llama_context * ctx); | |
| 3133 | 3146 | @ctypes_function("llama_n_threads_batch", [llama_context_p_ctypes], ctypes.c_int32) | |
| 3134 | 3147 | def llama_n_threads_batch(ctx: llama_context_p, /) -> int: | |
| 3135 | - """Get the number of threads used for prompt and batch processing (multiple token)""" | ||
| 3148 | + """Get the number of threads used for prompt and batch processing (multiple token).""" | ||
| 3136 | 3149 | ... | |
| 3137 | 3150 | ||
| 3138 | 3151 | ||
@@ -3141,7 +3154,8 @@ def llama_n_threads_batch(ctx: llama_context_p, /) -> int: | |||
| 3141 | 3154 | # LLAMA_API void llama_set_embeddings(struct llama_context * ctx, bool embeddings); | |
| 3142 | 3155 | @ctypes_function("llama_set_embeddings", [llama_context_p_ctypes, ctypes.c_bool], None) | |
| 3143 | 3156 | def llama_set_embeddings(ctx: llama_context_p, embeddings: bool, /): | |
| 3144 | - """Set whether the context outputs embeddings or not""" | ||
| 3157 | + """Set whether the context outputs embeddings or not | ||
| 3158 | + TODO: rename to avoid confusion with llama_get_embeddings()""" | ||
| 3145 | 3159 | ... | |
| 3146 | 3160 | ||
| 3147 | 3161 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments