Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
fb3aa06c
"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "52c85f847aba62ef2018162472007a167dc25622"
Unverified
Commit
fb3aa06c
authored
Apr 14, 2023
by
oscar-garzon
Committed by
GitHub
Apr 14, 2023
Browse files
Move labels to the same device as logits for Whisper (#22779)
parent
20e54e49
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
src/transformers/models/whisper/modeling_whisper.py
src/transformers/models/whisper/modeling_whisper.py
+4
-0
No files found.
src/transformers/models/whisper/modeling_whisper.py
View file @
fb3aa06c
...
@@ -1432,6 +1432,8 @@ class WhisperForConditionalGeneration(WhisperPreTrainedModel):
...
@@ -1432,6 +1432,8 @@ class WhisperForConditionalGeneration(WhisperPreTrainedModel):
loss
=
None
loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
loss_fct
=
CrossEntropyLoss
()
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
))
loss
=
loss_fct
(
lm_logits
.
view
(
-
1
,
self
.
config
.
vocab_size
),
labels
.
reshape
(
-
1
))
if
not
return_dict
:
if
not
return_dict
:
...
@@ -1760,6 +1762,8 @@ class WhisperForAudioClassification(WhisperPreTrainedModel):
...
@@ -1760,6 +1762,8 @@ class WhisperForAudioClassification(WhisperPreTrainedModel):
if
labels
is
not
None
:
if
labels
is
not
None
:
loss_fct
=
CrossEntropyLoss
()
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
))
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
1
))
if
not
return_dict
:
if
not
return_dict
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment