Skip to content

Commit c9bf03a

Browse files
committed
Fix some logic
- Raise error if save_logits but model will not produce - `logits_all` False - Get rid of extraneous comma that was causing bytes set to fail equality check
1 parent e5cccf4 commit c9bf03a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

llama_cpp/llama_cache.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ def build_cache(
253253
"""
254254
cache = LlamaStaticDiskCache(cache_dir, capacity_bytes)
255255

256+
if save_logits and not model.context_params.logits_all:
257+
raise ValueError(
258+
"Cannot save logits in cache when model is not configured to return logits."
259+
)
260+
256261
for p in prompts:
257262
if seed:
258263
model.set_seed(seed)
@@ -273,6 +278,9 @@ def build_cache(
273278
if (
274279
model.context_params.logits_all
275280
or model.draft_model is not None
281+
# This may be overly cautious, `embed` method does not use
282+
# numpy scores, instead uses logit values on llama.cpp
283+
# context.
276284
or model.context_params.embeddings
277285
):
278286
# Erroring instead of falling back to just saving with scores
@@ -365,7 +373,7 @@ def reload_from_cache_state(
365373
if (
366374
bytes_set := llama_cpp.llama_state_set_data(
367375
model._ctx.ctx, llama_state, ctypes.sizeof(llama_state)
368-
),
376+
)
369377
) != state_size:
370378
raise RuntimeError(
371379
"Failed to set llama state data - mismatch between bytes set "

0 commit comments

Comments
 (0)