From 1e240db2a02e090b01eb3cee7fd3633049d59a88 Mon Sep 17 00:00:00 2001 From: Kawrakow Date: Mon, 19 Jan 2026 14:38:53 +0000 Subject: [PATCH] Couldn't look at it without fixing it. --- src/llama-sampling.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/llama-sampling.cpp b/src/llama-sampling.cpp index 6a90c964..b6e929c9 100644 --- a/src/llama-sampling.cpp +++ b/src/llama-sampling.cpp @@ -311,10 +311,9 @@ void llama_sample_typical_impl(struct llama_sampling * smpl, llama_token_data_ar } // Compute the absolute difference between negative log probability and entropy for each candidate - std::vector shifted_scores; + std::vector shifted_scores(candidates->size); for (size_t i = 0; i < candidates->size; ++i) { - float shifted_score = fabsf(-logf(candidates->data[i].p) - entropy); - shifted_scores.push_back(shifted_score); + shifted_scores[i] = fabsf(-logf(candidates->data[i].p) - entropy); } // Sort tokens based on the shifted_scores and their corresponding indices @@ -341,10 +340,10 @@ void llama_sample_typical_impl(struct llama_sampling * smpl, llama_token_data_ar } // Resize the output vector to keep only the locally typical tokens - std::vector new_candidates; + std::vector new_candidates(last_idx); for (size_t i = 0; i < last_idx; ++i) { size_t idx = indices[i]; - new_candidates.push_back(candidates->data[idx]); + new_candidates[i] = candidates->data[idx]; } // Replace the data in candidates with the new_candidates data