backend sampling: support returning post-sampling probs (#22622)
* server: Never return 0.0 post-sampling probabilities * backend sampling: support returning post-sampling probs
This commit is contained in:
@@ -1317,7 +1317,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool need_logits = task.params.sampling.n_probs > 0;
|
||||
const bool need_pre_sample_logits = task.params.sampling.n_probs > 0 && !task.params.post_sampling_probs;
|
||||
|
||||
bool backend_sampling = true;
|
||||
|
||||
@@ -1326,8 +1326,8 @@ private:
|
||||
// TODO: speculative decoding requires multiple samples per batch - not supported yet
|
||||
backend_sampling &= !(slot.can_speculate() && common_speculative_n_max(slot.spec.get(), task.params.speculative) > 0);
|
||||
|
||||
// TODO: getting post/pre sampling logits is not yet supported with backend sampling
|
||||
backend_sampling &= !need_logits;
|
||||
// TODO: getting pre sampling logits is not yet supported with backend sampling
|
||||
backend_sampling &= !need_pre_sample_logits;
|
||||
|
||||
// TODO: tmp until backend sampling is fully implemented
|
||||
if (backend_sampling) {
|
||||
@@ -1504,6 +1504,12 @@ private:
|
||||
// set probability for top n_probs tokens
|
||||
result.probs.reserve(n_probs);
|
||||
for (size_t i = 0; i < n_probs; i++) {
|
||||
// Some samplers do return 0.0 probabilities, others don't.
|
||||
// Filter 0.0 probailities, to ensure the behavior is consistent.
|
||||
if (cur_p->data[i].p == 0.0) {
|
||||
break;
|
||||
}
|
||||
|
||||
result.probs.push_back({
|
||||
cur_p->data[i].id,
|
||||
common_token_to_piece(ctx, cur_p->data[i].id, special),
|
||||
|
||||
Reference in New Issue
Block a user