Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
5d390e9e
Unverified
Commit
5d390e9e
authored
Oct 06, 2021
by
Anton Lozhkov
Committed by
GitHub
Oct 06, 2021
Browse files
Fix nan-loss condition (#13911)
parent
8f2c07d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
src/transformers/trainer.py
src/transformers/trainer.py
+7
-4
No files found.
src/transformers/trainer.py
View file @
5d390e9e
...
@@ -1315,8 +1315,11 @@ class Trainer:
...
@@ -1315,8 +1315,11 @@ class Trainer:
else
:
else
:
tr_loss_step
=
self
.
training_step
(
model
,
inputs
)
tr_loss_step
=
self
.
training_step
(
model
,
inputs
)
if
args
.
logging_nan_inf_filter
and
not
is_torch_tpu_available
():
if
(
if
torch
.
isnan
(
tr_loss_step
)
or
torch
.
isinf
(
tr_loss_step
):
args
.
logging_nan_inf_filter
and
not
is_torch_tpu_available
()
and
(
torch
.
isnan
(
tr_loss_step
)
or
torch
.
isinf
(
tr_loss_step
))
):
# if loss is nan or inf simply add the average of previous logged losses
# if loss is nan or inf simply add the average of previous logged losses
tr_loss
+=
tr_loss
/
(
1
+
self
.
state
.
global_step
-
self
.
_globalstep_last_logged
)
tr_loss
+=
tr_loss
/
(
1
+
self
.
state
.
global_step
-
self
.
_globalstep_last_logged
)
else
:
else
:
...
...
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