Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down