diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index b5bffd46b..a571a4ff3 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, @@ -199,8 +199,18 @@ def __init__( A Llama instance. """ self.verbose = verbose - 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 + ) + embeddings = kwargs.pop('embedding') + + self._stack = contextlib.ExitStack() set_verbose(verbose) if not Llama.__backend_initialized: @@ -342,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 @@ -397,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(), @@ -1088,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: @@ -2163,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