From 7c040b440c45ae86a335ac5f6302d8cdb809ec9c Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 8 Mar 2024 12:57:18 -0800 Subject: [PATCH] whisper : make beam candidate sort more stable All else being otherwise equal, this encourages the beam candidate selection to re-use the same decoder, which slightly reduces the cache size. I wouldn't expect it to make much of a performance difference, but it helps when debug printing the cache and beam. Added as part of understanding #1941. --- whisper.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/whisper.cpp b/whisper.cpp index 3459dd6efcb..84d292d304c 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -5357,7 +5357,10 @@ int whisper_full_with_state( beam_candidates.begin(), beam_candidates.end(), [](const beam_candidate & a, const beam_candidate & b) { - return a.sequence.sum_logprobs_all > b.sequence.sum_logprobs_all; + if (a.sequence.sum_logprobs_all != b.sequence.sum_logprobs_all) { + return a.sequence.sum_logprobs_all > b.sequence.sum_logprobs_all; + } + return a.decoder_idx < b.decoder_idx; }); uint32_t cur_c = 0;