From: Josh Bleecher Snyder Date: Sat, 9 Mar 2024 16:50:03 +0000 (-0800) Subject: whisper : make beam candidate sort more stable (#1943) X-Git-Tag: upstream/1.7.4~908 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=2852e1af55b1a2c180e608e62c0a0f0ab18bba10;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp whisper : make beam candidate sort more stable (#1943) 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. --- diff --git a/whisper.cpp b/whisper.cpp index 3459dd6e..84d292d3 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;