From fdcaad09bdd67d869b86b03e5fe1a1c20957f083 Mon Sep 17 00:00:00 2001 From: lxcxjxhx Date: Thu, 9 Jul 2026 12:18:22 +0800 Subject: [PATCH 1/4] fix: handle deprecated 'embedding' kwarg with warning (#2210) --- llama_cpp/llama.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index b5bffd46b..3441ccf1b 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -199,8 +199,29 @@ def __init__( A Llama instance. """ self.verbose = verbose + + # Handle deprecated 'embedding' kwarg (singular) as alias for 'embeddings' (plural) + if 'embedding' in kwargs: + warnings.warn( + "The 'embedding' parameter is deprecated. Use 'embeddings' instead. " + "Support for 'embedding' will be removed in a future version.", + DeprecationWarning, + stacklevel=2 + ) + embedding = kwargs.pop('embedding') + self._stack = contextlib.ExitStack() + # Handle deprecated 'embedding' kwarg (singular) as alias for 'embeddings' (plural) + if 'embedding' in kwargs: + warnings.warn( + "The 'embedding' parameter is deprecated. Use 'embeddings' instead. " + "Support for 'embedding' will be removed in a future version.", + DeprecationWarning, + stacklevel=2 + ) + embedding = kwargs.pop('embedding') + set_verbose(verbose) if not Llama.__backend_initialized: From ad036a83bf5c0b167ffc6fe5b6370052ee103450 Mon Sep 17 00:00:00 2001 From: lxcxjxhx Date: Thu, 9 Jul 2026 12:18:50 +0800 Subject: [PATCH 2/4] fix: handle deprecated 'embedding' kwarg with warning (#2210) --- llama_cpp/llama.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 3441ccf1b..f62197c24 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -211,17 +211,6 @@ def __init__( embedding = kwargs.pop('embedding') self._stack = contextlib.ExitStack() - - # Handle deprecated 'embedding' kwarg (singular) as alias for 'embeddings' (plural) - if 'embedding' in kwargs: - warnings.warn( - "The 'embedding' parameter is deprecated. Use 'embeddings' instead. " - "Support for 'embedding' will be removed in a future version.", - DeprecationWarning, - stacklevel=2 - ) - embedding = kwargs.pop('embedding') - set_verbose(verbose) if not Llama.__backend_initialized: From 9aa447f6d65ad815d08fdfa2fd4433242379dc40 Mon Sep 17 00:00:00 2001 From: lxcxjxhx Date: Thu, 9 Jul 2026 12:22:05 +0800 Subject: [PATCH 3/4] fix: rename 'embedding' parameter to 'embeddings' with deprecation warning (#2210) --- llama_cpp/llama.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index f62197c24..49c196fef 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -90,7 +90,7 @@ def __init__( yarn_beta_slow: float = 1.0, yarn_orig_ctx: int = 0, logits_all: bool = False, - embedding: bool = False, + embeddings: bool = False, offload_kqv: bool = True, flash_attn: bool = False, op_offload: Optional[bool] = None, @@ -208,7 +208,7 @@ def __init__( DeprecationWarning, stacklevel=2 ) - embedding = kwargs.pop('embedding') + embeddings = kwargs.pop('embedding') self._stack = contextlib.ExitStack() set_verbose(verbose) @@ -352,7 +352,7 @@ def __init__( ) self.context_params.yarn_orig_ctx = yarn_orig_ctx if yarn_orig_ctx != 0 else 0 self._logits_all = logits_all if draft_model is None else True - self.context_params.embeddings = embedding # TODO: Rename to embeddings + self.context_params.embeddings = embeddings self.context_params.offload_kqv = offload_kqv self.context_params.flash_attn_type = ( llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED @@ -407,7 +407,7 @@ def __init__( self.context_params.n_batch = self.n_batch self.context_params.n_ubatch = min(self.n_batch, n_ubatch) - if embedding: + if embeddings: self.context_params.n_seq_max = min( self.n_batch, llama_cpp.llama_max_parallel_sequences(), From 4b67660362d80edc8b83d43e8ea91827f3355dca Mon Sep 17 00:00:00 2001 From: lxcxjxhx Date: Thu, 9 Jul 2026 18:03:20 +0800 Subject: [PATCH 4/4] fix: rename 'embedding' parameter to 'embeddings' for consistency - Update __init__ parameter from 'embedding' to 'embeddings' - Fix error message to reference 'embeddings=True' - Update __getstate__ to use 'embeddings' key - Add backward compatibility handling in __setstate__ The parameter naming was inconsistent between Python API and C++ bindings, causing confusion and potential serialization/deserialization issues. --- llama_cpp/llama.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 49c196fef..a571a4ff3 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -1098,7 +1098,7 @@ def embed( if self.context_params.embeddings is False: raise RuntimeError( - "Llama model must be created with embedding=True to call this method" + "Llama model must be created with embeddings=True to call this method" ) if self.verbose: @@ -2173,7 +2173,7 @@ def __getstate__(self): yarn_beta_slow=self.context_params.yarn_beta_slow, yarn_orig_ctx=self.context_params.yarn_orig_ctx, logits_all=self._logits_all, - embedding=self.context_params.embeddings, + embeddings=self.context_params.embeddings, offload_kqv=self.context_params.offload_kqv, flash_attn=( self.context_params.flash_attn_type