FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: align llama.cpp binding docstrings (#2328) · abetlen/llama-cpp-python@d115822 · GitHub

Commit d115822

Browse files
authored
fix: align llama.cpp binding docstrings (#2328)
* fix: align llama.cpp binding docstrings * fix: use None in Python binding docstrings
1 parent 9290f80 commit d115822

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

‎llama_cpp/llama_cpp.py‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,8 @@ def llama_flash_attn_type_name(flash_attn_type: int, /) -> Optional[bytes]:
12761276
# LLAMA_API const char * llama_ftype_name(enum llama_ftype ftype);
12771277
@ctypes_function("llama_ftype_name", [ctypes.c_int], ctypes.c_char_p)
12781278
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+
"""
12801281
...
12811282

12821283

@@ -1785,7 +1786,8 @@ def llama_model_rope_freq_scale_train(model: llama_model_p, /) -> float: ...
17851786
# LLAMA_API uint32_t llama_model_n_cls_out(const struct llama_model * model);
17861787
@ctypes_function("llama_model_n_cls_out", [llama_model_p_ctypes], ctypes.c_uint32)
17871788
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"""
17891791
...
17901792

17911793

@@ -1851,7 +1853,7 @@ def llama_model_meta_count(model: llama_model_p, /) -> int:
18511853
# LLAMA_API const char * llama_model_meta_key_str(enum llama_model_meta_key key);
18521854
@ctypes_function("llama_model_meta_key_str", [ctypes.c_int], ctypes.c_char_p)
18531855
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"""
18551857
...
18561858

18571859

@@ -1922,7 +1924,7 @@ def llama_model_desc(
19221924
# LLAMA_API enum llama_ftype llama_model_ftype(const struct llama_model * model);
19231925
@ctypes_function("llama_model_ftype", [llama_model_p_ctypes], ctypes.c_int)
19241926
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"""
19261928
...
19271929

19281930

@@ -2501,7 +2503,9 @@ def llama_memory_can_shift(mem: llama_memory_t, /) -> bool:
25012503
# LLAMA_API size_t llama_state_get_size(struct llama_context * ctx);
25022504
@ctypes_function("llama_state_get_size", [llama_context_p_ctypes], ctypes.c_size_t)
25032505
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."""
25052509
...
25062510

25072511

@@ -3062,9 +3066,12 @@ def llama_batch_free(batch: llama_batch, /):
30623066
# struct llama_batch batch);
30633067
@ctypes_function("llama_encode", [llama_context_p_ctypes, llama_batch], ctypes.c_int32)
30643068
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.
30663073
0 - success
3067-
< 0 - error"""
3074+
< 0 - error. the memory state is restored to the state before this call"""
30683075
...
30693076

30703077

@@ -3086,9 +3093,15 @@ def llama_encode(ctx: llama_context_p, batch: llama_batch, /) -> int:
30863093
@ctypes_function("llama_decode", [llama_context_p_ctypes, llama_batch], ctypes.c_int32)
30873094
def llama_decode(ctx: llama_context_p, batch: llama_batch, /) -> int:
30883095
"""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
30893102
0 - success
30903103
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)
30923105
-1 - invalid input batch
30933106
< -1 - fatal error (processed ubatches will remain in the context's memory)"""
30943107
...
@@ -3124,15 +3137,15 @@ def llama_set_n_threads(
31243137
# LLAMA_API int32_t llama_n_threads(struct llama_context * ctx);
31253138
@ctypes_function("llama_n_threads", [llama_context_p_ctypes], ctypes.c_int32)
31263139
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."""
31283141
...
31293142

31303143

31313144
# // Get the number of threads used for prompt and batch processing (multiple token).
31323145
# LLAMA_API int32_t llama_n_threads_batch(struct llama_context * ctx);
31333146
@ctypes_function("llama_n_threads_batch", [llama_context_p_ctypes], ctypes.c_int32)
31343147
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)."""
31363149
...
31373150

31383151

@@ -3141,7 +3154,8 @@ def llama_n_threads_batch(ctx: llama_context_p, /) -> int:
31413154
# LLAMA_API void llama_set_embeddings(struct llama_context * ctx, bool embeddings);
31423155
@ctypes_function("llama_set_embeddings", [llama_context_p_ctypes, ctypes.c_bool], None)
31433156
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()"""
31453159
...
31463160

31473161

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL