Skip to content

Commit

Permalink
separate paddle.logsumexp (#3897)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxcd authored Nov 19, 2024
1 parent 89bfd44 commit d32ced7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions paddlespeech/s2t/models/whisper/whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,14 @@ def apply(self, logits: paddle.Tensor, tokens: paddle.Tensor):
# if sum of probability over timestamps is above any other token, sample timestamp
logprobs = F.log_softmax(logits, axis=-1, dtype=paddle.float32)
for k in range(tokens.shape[0]):
timestamp_logprob = paddle.logsumexp(
logprobs[k, self.tokenizer.timestamp_begin:], axis=-1)
# When using paddle.logsumexp on a 32GB Tesla-V100 GPU, we encountered CUDA error 700.
# To bypass this issue in CI, we have decomposed the operation into separate steps.
# It will raise 2e-6 difference in precision.
# TODO: revert this after logsumexp been fixed.
timestamp_logprob = paddle.exp(
logprobs[k, self.tokenizer.timestamp_begin:])
timestamp_logprob = paddle.sum(timestamp_logprob, axis=-1)
timestamp_logprob = paddle.log(timestamp_logprob)
max_text_token_logprob = paddle.max(
logprobs[k, :self.tokenizer.timestamp_begin])
if timestamp_logprob > max_text_token_logprob:
Expand Down

0 comments on commit d32ced7

Please sign in to comment.