From 4fc8cf90c43c77a1fb2939d517946e673befe250 Mon Sep 17 00:00:00 2001 From: Tai An Date: Fri, 4 Sep 2026 18:21:04 -0700 Subject: [PATCH] fix: stop silently swallowing unknown Llama kwargs (#2210) `Llama.__init__` ends in a bare `**kwargs` that is never read, so any keyword it does not know is discarded without a word. The server hits this itself: `llama_cpp/server/model.py` still passes `rpc_servers=` and `mul_mat_q=`, neither of which is a parameter of `Llama.__init__` any more, so `--rpc_servers` has been a silent no-op. - warn on unexpected keyword arguments instead of dropping them - accept `embeddings=` as an alias for `embedding=` - stop passing the two dead settings from the server, and warn when a user actually set them Signed-off-by: Tai An --- llama_cpp/llama.py | 15 +++++++++++++++ llama_cpp/server/model.py | 21 +++++++++++++++++++-- llama_cpp/server/settings.py | 5 +++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/llama_cpp/llama.py b/llama_cpp/llama.py index 14e2f8500f..64b5d1eec7 100644 --- a/llama_cpp/llama.py +++ b/llama_cpp/llama.py @@ -198,6 +198,21 @@ def __init__( Returns: A Llama instance. """ + if "embeddings" in kwargs: + # `embeddings` (plural) is the spelling used by llama.cpp's context + # params and by `Llama.__getstate__`, so it is a natural thing to + # pass here. Accept it as an alias instead of dropping it. + embedding = bool(kwargs.pop("embeddings")) + + if kwargs: + warnings.warn( + "Llama.__init__ got unexpected keyword argument(s): " + f"{', '.join(sorted(kwargs))}. They are ignored. Pass only " + "arguments that appear in the Llama.__init__ signature.", + UserWarning, + stacklevel=2, + ) + self.verbose = verbose self._stack = contextlib.ExitStack() diff --git a/llama_cpp/server/model.py b/llama_cpp/server/model.py index 8aa929202c..7e13a8bd13 100644 --- a/llama_cpp/server/model.py +++ b/llama_cpp/server/model.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import warnings from typing import Dict, Optional, Union, List @@ -252,6 +253,24 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama: import functools + # `rpc_servers` and `mul_mat_q` are not parameters of Llama.__init__: + # llama_model_params no longer carries rpc_servers and mul_mat_q is long + # gone upstream. Passing them here only fed Llama's **kwargs sink, so a + # user who set them got a silent no-op. Say so instead. + if settings.rpc_servers: + warnings.warn( + "The `rpc_servers` server setting is no longer supported by " + "llama.cpp's model params and has no effect.", + UserWarning, + stacklevel=2, + ) + if not settings.mul_mat_q: + warnings.warn( + "The `mul_mat_q` server setting is obsolete and has no effect.", + UserWarning, + stacklevel=2, + ) + kwargs = {} if settings.hf_model_repo_id is not None: @@ -275,7 +294,6 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama: use_mmap=settings.use_mmap, use_mlock=settings.use_mlock, kv_overrides=kv_overrides, - rpc_servers=settings.rpc_servers, # Context Params seed=settings.seed, n_ctx=settings.n_ctx, @@ -291,7 +309,6 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama: yarn_beta_fast=settings.yarn_beta_fast, yarn_beta_slow=settings.yarn_beta_slow, yarn_orig_ctx=settings.yarn_orig_ctx, - mul_mat_q=settings.mul_mat_q, logits_all=settings.logits_all, embedding=settings.embedding, offload_kqv=settings.offload_kqv, diff --git a/llama_cpp/server/settings.py b/llama_cpp/server/settings.py index 78dd7cdeb8..5282967171 100644 --- a/llama_cpp/server/settings.py +++ b/llama_cpp/server/settings.py @@ -60,7 +60,7 @@ class ModelSettings(BaseSettings): ) rpc_servers: Optional[str] = Field( default=None, - description="comma separated list of rpc servers for offloading", + description="Deprecated and ignored: llama.cpp's model params no longer accept a list of rpc servers.", ) # Context Params seed: int = Field( @@ -96,7 +96,8 @@ class ModelSettings(BaseSettings): yarn_beta_slow: float = Field(default=1.0) yarn_orig_ctx: int = Field(default=0) mul_mat_q: bool = Field( - default=True, description="if true, use experimental mul_mat_q kernels" + default=True, + description="Deprecated and ignored: the experimental mul_mat_q kernels were removed upstream.", ) logits_all: bool = Field(default=True, description="Whether to return logits.") embedding: bool = Field(default=False, description="Whether to use embeddings.")