Skip to content

Commit 8aada9a

Browse files
committed
refactor: address PR review feedback
- Fix n_samplers type hint to ctypes.c_size_t - Map flash_attn=True exactly to LLAMA_FLASH_ATTN_TYPE_ENABLED instead of relying on bool() - Raise NotImplementedError instead of returning stub when C symbol is missing
1 parent 67c38a7 commit 8aada9a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

llama_cpp/_ctypes_extensions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ def decorator(f: F) -> F:
118118
return func
119119
except AttributeError:
120120
# Symbol not found in shared library (deprecated/removed)
121-
return f
121+
@functools.wraps(f)
122+
def stub(*args: Any, **kwargs: Any) -> Any:
123+
raise NotImplementedError(
124+
f"Symbol '{name}' not found in shared library. The C API might "
125+
"have been removed or deprecated."
126+
)
127+
128+
return stub # type: ignore
122129
else:
123130
return f
124131

llama_cpp/llama.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,10 @@ def __getstate__(self):
20962096
logits_all=self._logits_all,
20972097
embedding=self.context_params.embeddings,
20982098
offload_kqv=self.context_params.offload_kqv,
2099-
flash_attn=bool(self.context_params.flash_attn_type),
2099+
flash_attn=(
2100+
self.context_params.flash_attn_type
2101+
== llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
2102+
),
21002103
op_offload=self.context_params.op_offload,
21012104
swa_full=self.context_params.swa_full,
21022105
# Sampling Params

llama_cpp/llama_cpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ class llama_context_params(ctypes.Structure):
874874
swa_full: bool
875875
kv_unified: bool
876876
samplers: ctypes.c_void_p
877-
n_samplers: int
877+
n_samplers: ctypes.c_size_t
878878

879879
_fields_ = [
880880
("n_ctx", ctypes.c_uint32),

0 commit comments

Comments
 (0)