From 9ad6522be6406a6057bf9796ffac619ab8a54827 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 28 Nov 2025 08:57:48 +0100 Subject: [PATCH] squash! sampling : support intermixed backend/cpu samplers Add check that logits is not null which is can happen for embeddings. --- src/llama-context.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/llama-context.cpp b/src/llama-context.cpp index d8fb5d782b..f74248127c 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -1662,16 +1662,18 @@ uint32_t llama_context::output_reserve(int32_t n_outputs, const llama_batch & ba bool batch_has_backend_sampling = false; bool batch_needs_cpu_logits = false; - for (int32_t i = 0; i < batch.n_tokens; i++) { - if (!batch.logits[i]) { - continue; - } - for (int32_t j = 0; j < batch.n_seq_id[i]; j++) { - llama_seq_id seq_id = batch.seq_id[i][j]; - if (sampling.samplers.find(seq_id) != sampling.samplers.end()) { - batch_has_backend_sampling = true; - } else { - batch_needs_cpu_logits = true; + if (batch.logits) { + for (int32_t i = 0; i < batch.n_tokens; i++) { + if (!batch.logits[i]) { + continue; + } + for (int32_t j = 0; j < batch.n_seq_id[i]; j++) { + llama_seq_id seq_id = batch.seq_id[i][j]; + if (sampling.samplers.find(seq_id) != sampling.samplers.end()) { + batch_has_backend_sampling = true; + } else { + batch_needs_cpu_logits = true; + } } } }