Skip to content

Commit fc181e9

Browse files
authored
Update decoding.py
Following the suggestions of @Jeronymous in openai#914 and openai#924, it solves the problem of endless loop.
1 parent 6dea21f commit fc181e9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

whisper/decoding.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ def apply(self, logits: Tensor, tokens: Tensor):
470470
if timestamps.numel() > 0:
471471
# timestamps shouldn't decrease; forbid timestamp tokens smaller than the last
472472
logits[k, self.tokenizer.timestamp_begin : timestamps[-1]] = -np.inf
473+
474+
# to force that timestamps are strictly increasing
475+
if last_was_timestamp and not penultimate_was_timestamp:
476+
timestamp_last = timestamps[-1]
477+
else:
478+
timestamp_last = timestamps[-1] + 1
479+
logits[k, self.tokenizer.timestamp_begin: timestamp_last] = -np.inf
473480

474481
if tokens.shape[1] == self.sample_begin:
475482
# suppress generating non-timestamp tokens at the beginning

0 commit comments

Comments
 (0)