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
e21f89f6
Unverified
Commit
e21f89f6
authored
Mar 22, 2021
by
Stas Bekman
Committed by
GitHub
Mar 22, 2021
Browse files
fix nan in full-fp16 label_smoothing eval (#10815)
parent
b5b957a6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
1 deletion
+2
-1
src/transformers/trainer_pt_utils.py
src/transformers/trainer_pt_utils.py
+2
-1
No files found.
src/transformers/trainer_pt_utils.py
View file @
e21f89f6
...
...
@@ -433,7 +433,8 @@ class LabelSmoother:
# will ignore them in any case.
labels
.
clamp_min_
(
0
)
nll_loss
=
log_probs
.
gather
(
dim
=-
1
,
index
=
labels
)
smoothed_loss
=
log_probs
.
sum
(
dim
=-
1
,
keepdim
=
True
)
# works for fp16 input tensor too, by internally upcasting it to fp32
smoothed_loss
=
log_probs
.
sum
(
dim
=-
1
,
keepdim
=
True
,
dtype
=
torch
.
float32
)
nll_loss
.
masked_fill_
(
padding_mask
,
0.0
)
smoothed_loss
.
masked_fill_
(
padding_mask
,
0.0
)
...
...
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