Skip to content

Commit 29c1495

Browse files
committed
sort before apply softmax
1 parent cc90cdb commit 29c1495

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/server/utils.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,11 @@ static std::vector<llama_token_data> get_token_probabilities(llama_context * ctx
705705
cur[token_id] = llama_token_data{token_id, logits[token_id], 0.0f};
706706
}
707707

708+
// sort tokens by logits
709+
std::sort(cur.begin(), cur.end(), [](const llama_token_data & a, const llama_token_data & b) {
710+
return a.logit > b.logit;
711+
});
712+
708713
// apply softmax
709714
float max_l = cur[0].logit;
710715
float cum_sum = 0.0f;
@@ -717,10 +722,5 @@ static std::vector<llama_token_data> get_token_probabilities(llama_context * ctx
717722
cur[i].p /= cum_sum;
718723
}
719724

720-
// sort tokens by probability
721-
std::sort(cur.begin(), cur.end(), [](const llama_token_data & a, const llama_token_data & b) {
722-
return a.p > b.p;
723-
});
724-
725725
return cur;
726726
}

0 commit comments

Comments
 (0)