Skip to content

Commit

Permalink
Move labels to the same device as logits for Whisper (#22779)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-garzon committed Apr 14, 2023
1 parent 20e54e4 commit fb3aa06
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/transformers/models/whisper/modeling_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ def forward(
loss = None
if labels is not None:
loss_fct = CrossEntropyLoss()
# move labels to correct device to enable PP
labels = labels.to(lm_logits.device)
loss = loss_fct(lm_logits.view(-1, self.config.vocab_size), labels.reshape(-1))

if not return_dict:
Expand Down Expand Up @@ -1760,6 +1762,8 @@ def forward(

if labels is not None:
loss_fct = CrossEntropyLoss()
# move labels to correct device to enable PP
labels = labels.to(logits.device)
loss = loss_fct(logits.view(-1, self.config.num_labels), labels.view(-1))

if not return_dict:
Expand Down

0 comments on commit fb3aa06

Please sign in to comment.