Skip to content

Commit 3716d0a

Browse files
committed
Update llama.cpp API 20251230
1 parent a6d0ebd commit 3716d0a

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

llama_cpp/llama_cpp.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class llama_model_tensor_buft_override(ctypes.Structure):
681681
# // NULL-terminated list of buffer types to use for tensors that match a pattern
682682
# const struct llama_model_tensor_buft_override * tensor_buft_overrides;
683683
#
684-
# int32_t n_gpu_layers; // number of layers to store in VRAM
684+
# int32_t n_gpu_layers; // number of layers to store in VRAM, a negative value means all layers
685685
# enum llama_split_mode split_mode; // how to split the model across multiple GPUs
686686

687687
# // main_gpu interpretation depends on split_mode:
@@ -720,7 +720,7 @@ class llama_model_params(ctypes.Structure):
720720
Attributes:
721721
devices (ctypes.Array[ggml_backend_dev_t]): NULL-terminated list of devices to use for offloading (if NULL, all available devices are used)
722722
tensor_buft_overrides(llama_model_tensor_buft_override): NULL-terminated list of buffer types to use for tensors that match a pattern
723-
n_gpu_layers (int): number of layers to store in VRAM
723+
n_gpu_layers (int): number of layers to store in VRAM, a negative value means all layers
724724
split_mode (int): how to split the model across multiple GPUs
725725
main_gpu (int): the GPU that is used for the entire model. main_gpu interpretation depends on split_mode: LLAMA_SPLIT_NONE: the GPU that is used for the entire model LLAMA_SPLIT_ROW: the GPU that is used for small tensors and intermediate results LLAMA_SPLIT_LAYER: ignored
726726
tensor_split (ctypes.Array[ctypes.ctypes.c_float]): proportion of the model (layers or rows) to offload to each GPU, size: llama_max_devices()
@@ -1312,10 +1312,22 @@ def llama_free(ctx: llama_context_p, /):
13121312
...
13131313

13141314

1315+
# enum llama_params_fit_status {
1316+
# LLAMA_PARAMS_FIT_STATUS_SUCCESS = 0, // found allocations that are projected to fit
1317+
# LLAMA_PARAMS_FIT_STATUS_FAILURE = 1, // could not find allocations that are projected to fit
1318+
# LLAMA_PARAMS_FIT_STATUS_ERROR = 2, // a hard error occured, e.g. because no model could be found at the specified path
1319+
# };
1320+
class llama_params_fit_status(enum.IntEnum):
1321+
LLAMA_PARAMS_FIT_STATUS_SUCCESS = 0
1322+
LLAMA_PARAMS_FIT_STATUS_FAILURE = 1
1323+
LLAMA_PARAMS_FIT_STATUS_ERROR = 2
1324+
1325+
13151326
# // fits mparams and cparams to free device memory (assumes system memory is unlimited)
1316-
# // returns true if the parameters could be successfully modified to fit device memory
1317-
# // this function is NOT thread safe because it modifies the global llama logger state
1318-
# LLAMA_API bool llama_params_fit(
1327+
# // - returns true if the parameters could be successfully modified to fit device memory
1328+
# // - this function is NOT thread safe because it modifies the global llama logger state
1329+
# // - only parameters that have the same value as in llama_default_model_params are modified
1330+
# LLAMA_API enum llama_params_fit_status llama_params_fit(
13191331
# const char * path_model,
13201332
# struct llama_model_params * mparams,
13211333
# struct llama_context_params * cparams,
@@ -1336,7 +1348,7 @@ def llama_free(ctx: llama_context_p, /):
13361348
ctypes.c_uint32,
13371349
ctypes.c_int,
13381350
],
1339-
ctypes.c_bool,
1351+
ctypes.c_int,
13401352
)
13411353
def llama_params_fit(
13421354
path_model: ctypes.c_char_p,
@@ -1348,7 +1360,7 @@ def llama_params_fit(
13481360
n_ctx_min: ctypes.c_uint32,
13491361
log_level: int,
13501362
/,
1351-
) -> bool:
1363+
) -> int:
13521364
"""
13531365
fits mparams and cparams to free device memory (assumes system memory is unlimited)
13541366
returns true if the parameters could be successfully modified to fit device memory

0 commit comments

Comments
 (0)