From 2852e1af55b1a2c180e608e62c0a0f0ab18bba10 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 9 Mar 2024 08:50:03 -0800 Subject: [PATCH] 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. --- 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;