From 51fee298222be59730499e0c5dbad2922b60b8fb Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 19 Nov 2025 07:14:11 +0100 Subject: [PATCH] sampling : always populate logits for sampled probs This commit updates common/sampler.cpp set_logits and src/llama-sampling.cpp llama_sampler_sample to always populate the logits field when backend sampled probabilities are available. The motivation for this is that this ensure that CPU sampler always have access to the logits values even when probabilites have been produced by backend samplers. --- common/sampling.cpp | 2 +- src/llama-sampling.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/sampling.cpp b/common/sampling.cpp index 9c707a5bb9..9813762eca 100644 --- a/common/sampling.cpp +++ b/common/sampling.cpp @@ -129,7 +129,7 @@ struct common_sampler { const uint32_t sampled_probs_count = llama_get_backend_sampled_probs_count_ith(ctx, idx); cur.reserve(sampled_probs_count); for (uint32_t i = 0; i < sampled_probs_count; ++i) { - cur.emplace_back(llama_token_data{sampled_ids[i], 0.0f, sampled_probs[i]}); + cur.emplace_back(llama_token_data{sampled_ids[i], sampled_logits[i], sampled_probs[i]}); } } else if (sampled_logits) { const uint32_t sampled_logits_count = llama_get_backend_sampled_logits_count_ith(ctx, idx); diff --git a/src/llama-sampling.cpp b/src/llama-sampling.cpp index 456e050201..2cffa524cd 100644 --- a/src/llama-sampling.cpp +++ b/src/llama-sampling.cpp @@ -461,7 +461,7 @@ llama_token llama_sampler_sample(struct llama_sampler * smpl, struct llama_conte const uint32_t sampled_probs_count = llama_get_backend_sampled_probs_count_ith(ctx, idx); cur.reserve(sampled_probs_count); for (uint32_t i = 0; i < sampled_probs_count; ++i) { - cur.emplace_back(llama_token_data{sampled_ids[i], 0.0f, sampled_probs[i]}); + cur.emplace_back(llama_token_data{sampled_ids[i], sampled_logits[i], sampled_probs[i]}); } } else if (sampled_logits) { const uint32_t sampled_logits_count = llama_get_backend_sampled_logits_count_ith(ctx, idx);