sort before apply softmax
This commit is contained in:
parent
cc90cdbc33
commit
29c1495afa
1 changed files with 5 additions and 5 deletions
|
@ -705,6 +705,11 @@ static std::vector<llama_token_data> get_token_probabilities(llama_context * ctx
|
||||||
cur[token_id] = llama_token_data{token_id, logits[token_id], 0.0f};
|
cur[token_id] = llama_token_data{token_id, logits[token_id], 0.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort tokens by logits
|
||||||
|
std::sort(cur.begin(), cur.end(), [](const llama_token_data & a, const llama_token_data & b) {
|
||||||
|
return a.logit > b.logit;
|
||||||
|
});
|
||||||
|
|
||||||
// apply softmax
|
// apply softmax
|
||||||
float max_l = cur[0].logit;
|
float max_l = cur[0].logit;
|
||||||
float cum_sum = 0.0f;
|
float cum_sum = 0.0f;
|
||||||
|
@ -717,10 +722,5 @@ static std::vector<llama_token_data> get_token_probabilities(llama_context * ctx
|
||||||
cur[i].p /= cum_sum;
|
cur[i].p /= cum_sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort tokens by probability
|
|
||||||
std::sort(cur.begin(), cur.end(), [](const llama_token_data & a, const llama_token_data & b) {
|
|
||||||
return a.p > b.p;
|
|
||||||
});
|
|
||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue