From 711ef84442117b07c345b57fa16ceb5667b0dd03 Mon Sep 17 00:00:00 2001 From: Arianna Method Date: Wed, 23 Sep 2026 10:45:06 +0300 Subject: [PATCH] common : fix for two functions when top_k exceeds the vocabulary size. (ggml/1633) --- examples/common.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/common.cpp b/examples/common.cpp index 8eb633e58..1ff8b43ab 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -406,6 +406,7 @@ gpt_vocab::id gpt_sample_top_k_top_p( double temp, std::mt19937 & rng) { int n_logits = vocab.id_to_token.size(); + top_k = std::min(top_k, n_logits); std::vector> logits_id; logits_id.reserve(n_logits); @@ -491,6 +492,7 @@ gpt_vocab::id gpt_sample_top_k_top_p_repeat( std::mt19937 & rng) { int n_logits = vocab.id_to_token.size(); + top_k = std::min(top_k, n_logits); const auto * plogits = logits;