Skip to content

Commit cd7fa95

Browse files
Define non-positive temperature behavior (#720)
1 parent a0c0516 commit cd7fa95

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llama.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,20 @@ static llama_vocab::id llama_sample_top_p_top_k(
11941194
const auto & logits = lctx.logits;
11951195
const auto * plogits = logits.data() + logits.size() - n_logits;
11961196

1197+
if (temp <= 0) {
1198+
// select the token with the highest logit directly
1199+
float max_logit = plogits[0];
1200+
llama_vocab::id max_id = 0;
1201+
1202+
for (int i = 1; i < n_logits; ++i) {
1203+
if (plogits[i] > max_logit) {
1204+
max_logit = plogits[i];
1205+
max_id = i;
1206+
}
1207+
}
1208+
return max_id;
1209+
}
1210+
11971211
std::vector<std::pair<float, llama_vocab::id>> logits_id;
11981212
logits_id.reserve(n_logits);
11991213

0 commit comments

Comments
 (0)