Correct Whisper's beam search scores computation #32336
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #32246
There have been many failing tests these past days with Whisper, so I'd probably wait for them to be fixed before merging this PR.
What does this PR do?
@cifkao made a great summary the current issue in #32246:
He also rightfully identified what was the origin of the issue:
The solution simply consists in taking the right
logits_scores
for each of the generated tokens.Instead of taking the
batch_idx
-thlogits_scores
out of thenum_beams * batch
, we're now taking thebeam_idx
-thlogits_scores
.Reproduction results
I've recomputed the code snippet from #32246.
How to read the results:
The first set of scores are the scores corresponding to each generated tokens, as well as their beam index.
The second set of scores are the scores of a handmade forward pass of the generated tokens, they indicates the "true scores" that we should have.
Notice how in #32246, the scores coming from the 1-th beam index are different from the recomputed scores. It indicates that we selected the wrong scores.
Here, they're about the same, which indicates we selected the right beam indices.
Scores out of the generation:
Scores out of the forward:
** Code:**
cc @LysandreJik, @kamilakesbi and @sanchit-gandhi