aboutsummaryrefslogtreecommitdiff
path: root/llama.cpp
diff options
context:
space:
mode:
authorIvan Stepanov <ivanstepanovftw@gmail.com>2023-04-03 03:19:04 +0300
committerGitHub <noreply@github.com>2023-04-03 02:19:04 +0200
commitcd7fa956904cb8e321b72b3499f4a3a82e43c266 (patch)
tree3dc983a8d344debee8c6d9e73c6882c0b91f844f /llama.cpp
parenta0c05164168297c04737936ad0cad849a512547a (diff)
Define non-positive temperature behavior (#720)
Diffstat (limited to 'llama.cpp')
-rw-r--r--llama.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llama.cpp b/llama.cpp
index 8789071..854bb89 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -1194,6 +1194,20 @@ static llama_vocab::id llama_sample_top_p_top_k(
const auto & logits = lctx.logits;
const auto * plogits = logits.data() + logits.size() - n_logits;
+ if (temp <= 0) {
+ // select the token with the highest logit directly
+ float max_logit = plogits[0];
+ llama_vocab::id max_id = 0;
+
+ for (int i = 1; i < n_logits; ++i) {
+ if (plogits[i] > max_logit) {
+ max_logit = plogits[i];
+ max_id = i;
+ }
+ }
+ return max_id;
+ }
+
std::vector<std::pair<float, llama_vocab::id>> logits_id;
logits_id.reserve(n_logits);