]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper : make beam candidate sort more stable (#1943)
authorJosh Bleecher Snyder <redacted>
Sat, 9 Mar 2024 16:50:03 +0000 (08:50 -0800)
committerGitHub <redacted>
Sat, 9 Mar 2024 16:50:03 +0000 (18:50 +0200)
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

index 3459dd6efcb5781cd148623a1d972ab09ece23f5..84d292d304c3508a553580248df0e269c13a6f25 100644 (file)
@@ -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;