From fbb8787b7d336bf99e5485ca3809d51206c4e574 Mon Sep 17 00:00:00 2001 From: "Michael J. Culbertson" Date: Sat, 18 Jul 2026 13:40:30 -0500 Subject: [PATCH 1/2] fix null no_speech_prob calculation Logits for SOT were not set correctly for the no_speech_prob calculation, because wisper_decode_internal() copies computed logits only if batch.logits[i] is true, so set batch.logits[sot_index] = 1. The sot_index is the token after the prompt prefix. --- src/whisper.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/whisper.cpp b/src/whisper.cpp index 2a95bdb1e..5790f2892 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -7164,6 +7164,11 @@ int whisper_full_with_state( whisper_batch_prep_legacy(state->batch, prompt.data(), prompt.size(), 0, 0); + // Identify the SOT position: The first token after prompt + const int sot_index = (int) prompt.size() - (int) prompt_init.size(); + // Include SOT in the decode mask so whisper_decode_internal() will copy to state->logits + state->batch.logits[sot_index] = 1; + if (!whisper_decode_internal(*ctx, *state, state->batch, params.n_threads, false, params.abort_callback, params.abort_callback_user_data)) { WHISPER_LOG_ERROR("%s: failed to decode\n", __func__); return -8; @@ -7176,8 +7181,13 @@ int whisper_full_with_state( std::vector logprobs(n_logits); std::vector probs(n_logits); - whisper_compute_logprobs(state->logits, n_logits, logprobs); - whisper_compute_probs(state->logits, n_logits, logprobs, probs); + // Get the SOT logits, which aren't at position 0 if there was a prompt prefix + const std::vector sot_logits = state->logits;( + state->logits.begin() + (size_t) sot_index * n_logits, + state->logits.begin() + (size_t) (sot_index + 1) * n_logits); + + whisper_compute_logprobs(sot_logits, n_logits, logprobs); + whisper_compute_probs(sot_logits, n_logits, logprobs, probs); state->no_speech_prob = probs[whisper_token_nosp(ctx)]; } From 895c841441b10ec6832770bf53672d9cfed28241 Mon Sep 17 00:00:00 2001 From: "Michael J. Culbertson" Date: Tue, 28 Jul 2026 17:08:11 -0500 Subject: [PATCH 2/2] Fix typo --- src/whisper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/whisper.cpp b/src/whisper.cpp index 5790f2892..1359fcd2a 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -7182,7 +7182,7 @@ int whisper_full_with_state( std::vector probs(n_logits); // Get the SOT logits, which aren't at position 0 if there was a prompt prefix - const std::vector sot_logits = state->logits;( + const std::vector sot_logits( state->logits.begin() + (size_t) sot_index * n_logits, state->logits.begin() + (size_t) (sot_index + 1) * n_logits);