whisper : fix max_tokens skipping remaining audio (#3798)

* whisper: fix max_tokens skipping remaining audio

* add PR reference comment as suggested

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* fix(ci): enable artifact overwrite
This commit is contained in:
annaeina
2026-05-13 07:32:00 +02:00
committed by GitHub
co-authored by Georgi Gerganov
parent 338cce1e58
commit f08258abd7
3 changed files with 61 additions and 0 deletions
+12
View File
@@ -6216,6 +6216,13 @@ static void whisper_process_logits(
}
}
// ref: https://github.com/ggml-org/whisper.cpp/pull/3798
if (!params.no_timestamps && !params.single_segment && params.max_tokens > 0 && (int) tokens_cur.size() >= params.max_tokens) {
for (int i = 0; i < vocab.token_eot; ++i) {
logits[i] = -INFINITY;
}
}
// suppress sot and nosp tokens
logits[vocab.token_sot] = -INFINITY;
logits[vocab.token_nosp] = -INFINITY;
@@ -7725,7 +7732,12 @@ int whisper_full_with_state(
}
// ref: https://github.com/ggml-org/whisper.cpp/pull/2629
const bool max_tokens_timestamp_ending = params.max_tokens > 0 &&
!params.single_segment &&
tokens_cur.size() > (size_t) params.max_tokens;
const bool single_timestamp_ending = tokens_cur.size() > 1 &&
!max_tokens_timestamp_ending &&
tokens_cur[tokens_cur.size() - 2].id < whisper_token_beg(ctx) &&
tokens_cur[tokens_cur.size() - 1].id > whisper_token_beg(ctx);
if (single_timestamp_ending) {