Skip to content

Commit 67c38a7

Browse files
committed
feat: update llama.cpp submodule and bindings for Qwen 3.5 support
Updates the llama.cpp submodule to da348c9df which includes support for the Qwen 3.5 model architecture (hybrid SSM + attention). Changes to Python bindings: 1. llama_cpp.py: Sync llama_context_params struct with upstream C API - flash_attn (bool) → flash_attn_type (enum llama_flash_attn_type) - Add samplers (void*) and n_samplers (size_t) fields - Add LLAMA_FLASH_ATTN_TYPE_* enum constants 2. llama.py: Update flash_attn parameter handling - Map flash_attn=True/False to flash_attn_type=1/0 3. _ctypes_extensions.py: Graceful handling of deprecated symbols - ctypes_function decorator returns stub instead of crashing when a symbol is not found in the shared library Tested with Qwen3.5-0.8B-Q4_K_M.gguf on Apple Silicon (M1 Pro): - Cold start: ~4s (vs ~40s with mlx-vlm) - Inference: ~0.6s per chat completion - Model loads and runs correctly on Metal GPU
1 parent c37132b commit 67c38a7

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎llama_cpp/_ctypes_extensions.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ def ctypes_function(
110110
):
111111
def decorator(f: F) -> F:
112112
if enabled:
113-
func = getattr(lib, name)
114-
func.argtypes = argtypes
115-
func.restype = restype
116-
functools.wraps(f)(func)
117-
return func
113+
try:
114+
func = getattr(lib, name)
115+
func.argtypes = argtypes
116+
func.restype = restype
117+
functools.wraps(f)(func)
118+
return func
119+
except AttributeError:
120+
# Symbol not found in shared library (deprecated/removed)
121+
return f
118122
else:
119123
return f
120124

‎llama_cpp/llama.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def __init__(
341341
self._logits_all = logits_all if draft_model is None else True
342342
self.context_params.embeddings = embedding # TODO: Rename to embeddings
343343
self.context_params.offload_kqv = offload_kqv
344-
self.context_params.flash_attn = flash_attn
344+
self.context_params.flash_attn_type = 1 if flash_attn else 0
345345

346346
if op_offload is not None:
347347
self.context_params.op_offload = op_offload
@@ -2096,7 +2096,7 @@ 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=self.context_params.flash_attn,
2099+
flash_attn=bool(self.context_params.flash_attn_type),
21002100
op_offload=self.context_params.op_offload,
21012101
swa_full=self.context_params.swa_full,
21022102
# Sampling Params

‎llama_cpp/llama_cpp.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,16 @@
463463
LLAMA_ATTENTION_TYPE_NON_CAUSAL = 1
464464

465465

466+
# enum llama_flash_attn_type {
467+
# LLAMA_FLASH_ATTN_TYPE_AUTO = -1,
468+
# LLAMA_FLASH_ATTN_TYPE_DISABLED = 0,
469+
# LLAMA_FLASH_ATTN_TYPE_ENABLED = 1,
470+
# };
471+
LLAMA_FLASH_ATTN_TYPE_AUTO = -1
472+
LLAMA_FLASH_ATTN_TYPE_DISABLED = 0
473+
LLAMA_FLASH_ATTN_TYPE_ENABLED = 1
474+
475+
466476
# enum llama_split_mode {
467477
# LLAMA_SPLIT_MODE_NONE = 0, // single GPU
468478
# LLAMA_SPLIT_MODE_LAYER = 1, // split layers and KV across GPUs
@@ -859,11 +869,12 @@ class llama_context_params(ctypes.Structure):
859869
abort_callback_data: ctypes.c_void_p
860870
embeddings: bool
861871
offload_kqv: bool
862-
flash_attn: bool
863872
no_perf: bool
864873
op_offload: bool
865874
swa_full: bool
866875
kv_unified: bool
876+
samplers: ctypes.c_void_p
877+
n_samplers: int
867878

868879
_fields_ = [
869880
("n_ctx", ctypes.c_uint32),
@@ -875,6 +886,7 @@ class llama_context_params(ctypes.Structure):
875886
("rope_scaling_type", ctypes.c_int),
876887
("pooling_type", ctypes.c_int),
877888
("attention_type", ctypes.c_int),
889+
("flash_attn_type", ctypes.c_int),
878890
("rope_freq_base", ctypes.c_float),
879891
("rope_freq_scale", ctypes.c_float),
880892
("yarn_ext_factor", ctypes.c_float),
@@ -891,11 +903,12 @@ class llama_context_params(ctypes.Structure):
891903
("abort_callback_data", ctypes.c_void_p),
892904
("embeddings", ctypes.c_bool),
893905
("offload_kqv", ctypes.c_bool),
894-
("flash_attn", ctypes.c_bool),
895906
("no_perf", ctypes.c_bool),
896907
("op_offload", ctypes.c_bool),
897908
("swa_full", ctypes.c_bool),
898909
("kv_unified", ctypes.c_bool),
910+
("samplers", ctypes.c_void_p),
911+
("n_samplers", ctypes.c_size_t),
899912
]
900913

901914

‎vendor/llama.cpp‎

0 commit comments

Comments
 (0)