Skip to content

Commit b6bf564

Browse files
committed
Update llama_context_params and fix the embeddings typo
1 parent 9a5f323 commit b6bf564

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ The standard `Llama` class still supports basic embedding generation, but it lac
858858

859859
```python
860860
# Old method - Not recommended for large batches or reranking
861-
llm = llama_cpp.Llama(model_path="...", embedding=True)
861+
llm = llama_cpp.Llama(model_path="...", embeddings=True)
862862
emb = llm.create_embedding("text")
863863
```
864864

llama_cpp/llama.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(
7979
n_ctx: int = 512,
8080
n_batch: int = 512,
8181
n_ubatch: int = 512,
82+
n_seq_max: int = 1,
8283
n_threads: Optional[int] = None,
8384
n_threads_batch: Optional[int] = None,
8485
rope_scaling_type: Optional[
@@ -95,13 +96,13 @@ def __init__(
9596
yarn_beta_slow: float = 1.0,
9697
yarn_orig_ctx: int = 0,
9798
logits_all: bool = False,
98-
embedding: bool = False,
99+
embeddings: bool = False,
99100
offload_kqv: bool = True,
101+
no_perf: bool = False,
100102
op_offload: Optional[bool] = None,
101103
swa_full: Optional[bool] = None,
102104
kv_unified: Optional[bool] = None,
103105
# Sampling Params
104-
no_perf: bool = False,
105106
last_n_tokens_size: int = 64,
106107
# LoRA Params
107108
lora_base: Optional[str] = None,
@@ -168,6 +169,7 @@ def __init__(
168169
n_ctx: Text context, 0 = from model
169170
n_batch: Prompt processing maximum batch size
170171
n_ubatch: Physical batch size
172+
n_seq_max: max number of sequences (i.e. distinct states for recurrent models)
171173
n_threads: Number of threads to use for generation
172174
n_threads_batch: Number of threads to use for batch processing
173175
rope_scaling_type: RoPE scaling type, from `enum llama_rope_scaling_type`. ref: https://github.com/ggml-org/llama.cpp/pull/2054
@@ -182,12 +184,12 @@ def __init__(
182184
yarn_beta_slow: YaRN high correction dim
183185
yarn_orig_ctx: YaRN original context size
184186
logits_all: Return logits for all tokens, not just the last token. Must be True for completion to return logprobs.
185-
embedding: Embedding mode only.
187+
embeddings: Embedding mode only. if true, extract embeddings (together with logits)
186188
offload_kqv: Offload K, Q, V to GPU.
189+
no_perf: Measure performance timings.
187190
op_offload: whether to offload host tensor operations to device
188191
swa_full: whether to use full-size SWA cache
189192
kv_unified: use single unified KV buffer for the KV cache of all sequences
190-
no_perf: Measure performance timings.
191193
last_n_tokens_size: Maximum number of tokens to keep in the last_n_tokens deque.
192194
lora_base: Optional path to base model, useful if using a quantized base model and you want to apply LoRA to an f16 model.
193195
lora_path: Path to a LoRA file to apply to the model.
@@ -314,6 +316,7 @@ def __init__(
314316
self.model_params.kv_overrides = self._kv_overrides_array
315317

316318
self.n_batch = min(n_ctx, n_batch) # ???
319+
self.n_seq_max = n_seq_max
317320
self.n_threads = n_threads or max(multiprocessing.cpu_count() // 2, 1)
318321
self.n_threads_batch = n_threads_batch or multiprocessing.cpu_count()
319322

@@ -325,6 +328,7 @@ def __init__(
325328
self.context_params.n_ctx = n_ctx
326329
self.context_params.n_batch = self.n_batch
327330
self.context_params.n_ubatch = min(self.n_batch, n_ubatch)
331+
self.context_params.n_seq_max = self.n_seq_max
328332
self.context_params.n_threads = self.n_threads
329333
self.context_params.n_threads_batch = self.n_threads_batch
330334
self.context_params.rope_scaling_type = (
@@ -366,10 +370,15 @@ def __init__(
366370
yarn_beta_slow if yarn_beta_slow != 0.0 else 0
367371
)
368372
self.context_params.yarn_orig_ctx = yarn_orig_ctx if yarn_orig_ctx != 0 else 0
373+
369374
self._logits_all = logits_all if draft_model is None else True
370-
self.context_params.embeddings = embedding # TODO: Rename to embeddings
375+
376+
self.context_params.embeddings = embeddings
371377
self.context_params.offload_kqv = offload_kqv
372378

379+
if no_perf is not None:
380+
self.context_params.no_perf = no_perf
381+
373382
if op_offload is not None:
374383
self.context_params.op_offload = op_offload
375384

llama_cpp/llama_embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(
6262
- Set to -1 for all layers (recommended for best performance).
6363
**kwargs: Additional arguments passed to the Llama base class (e.g., n_batch, n_ctx, verbose).
6464
"""
65-
kwargs["embedding"] = True
65+
kwargs["embeddings"] = True
6666
kwargs["n_gpu_layers"] = n_gpu_layers
6767
kwargs["n_ctx"] = n_ctx
6868
kwargs["n_batch"] = n_batch

llama_cpp/server/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama:
278278
n_ctx=settings.n_ctx,
279279
n_batch=settings.n_batch,
280280
n_ubatch=settings.n_ubatch,
281+
n_seq_max=settings.n_seq_max,
281282
n_threads=settings.n_threads,
282283
n_threads_batch=settings.n_threads_batch,
283284
rope_scaling_type=settings.rope_scaling_type,
@@ -293,8 +294,9 @@ def load_llama_from_model_settings(settings: ModelSettings) -> llama_cpp.Llama:
293294
yarn_orig_ctx=settings.yarn_orig_ctx,
294295
mul_mat_q=settings.mul_mat_q,
295296
logits_all=settings.logits_all,
296-
embedding=settings.embedding,
297+
embeddings=settings.embeddings,
297298
offload_kqv=settings.offload_kqv,
299+
no_perf=settings.no_perf,
298300
op_offload=settings.op_offload,
299301
swa_full=settings.swa_full,
300302
kv_unified=settings.kv_unified,

llama_cpp/server/settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class ModelSettings(BaseSettings):
7373
n_ubatch: int = Field(
7474
default=512, ge=1, description="The physical batch size used by llama.cpp"
7575
)
76+
n_seq_max: int = Field(
77+
default=1, ge=1, description="max number of sequences (i.e. distinct states for recurrent models)"
78+
)
7679
n_threads: int = Field(
7780
default=max(multiprocessing.cpu_count() // 2, 1),
7881
ge=1,
@@ -112,10 +115,13 @@ class ModelSettings(BaseSettings):
112115
default=True, description="if true, use experimental mul_mat_q kernels"
113116
)
114117
logits_all: bool = Field(default=True, description="Whether to return logits.")
115-
embedding: bool = Field(default=False, description="Whether to use embeddings.")
118+
embeddings: bool = Field(default=False, description="Whether to use embeddings.")
116119
offload_kqv: bool = Field(
117120
default=True, description="Whether to offload kqv to the GPU."
118121
)
122+
no_perf: bool = Field(
123+
default=False, description="measure performance timings"
124+
)
119125
op_offload: bool = Field(
120126
default=True, description="Whether to offload host tensor operations to device"
121127
)

0 commit comments

Comments
 (0)