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
4faeb38b
"...git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "1396186815aab1f2380c3627efd26cb12d760500"
Commit
4faeb38b
authored
Nov 03, 2018
by
Ubuntu
Browse files
Fix loss loss logging for multi-gpu compatibility
parent
25f73add
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
run_classifier_pytorch.py
run_classifier_pytorch.py
+3
-3
No files found.
run_classifier_pytorch.py
View file @
4faeb38b
...
@@ -529,10 +529,10 @@ def main():
...
@@ -529,10 +529,10 @@ def main():
label_ids
=
label_ids
.
to
(
device
)
label_ids
=
label_ids
.
to
(
device
)
loss
,
_
=
model
(
input_ids
,
segment_ids
,
input_mask
,
label_ids
)
loss
,
_
=
model
(
input_ids
,
segment_ids
,
input_mask
,
label_ids
)
total_tr_loss
+=
loss
.
item
()
total_tr_loss
+=
loss
.
sum
().
item
()
# sum() is to account for multi-gpu support.
nb_tr_examples
+=
input_ids
.
size
(
0
)
nb_tr_examples
+=
input_ids
.
size
(
0
)
model
.
zero_grad
()
model
.
zero_grad
()
loss
.
backward
()
loss
.
sum
().
backward
()
# sum() is to account for multi-gpu support.
optimizer
.
step
()
optimizer
.
step
()
global_step
+=
1
global_step
+=
1
...
@@ -573,7 +573,7 @@ def main():
...
@@ -573,7 +573,7 @@ def main():
label_ids
=
label_ids
.
to
(
'cpu'
).
numpy
()
label_ids
=
label_ids
.
to
(
'cpu'
).
numpy
()
tmp_eval_accuracy
=
accuracy
(
logits
,
label_ids
)
tmp_eval_accuracy
=
accuracy
(
logits
,
label_ids
)
eval_loss
+=
tmp_eval_loss
.
item
()
eval_loss
+=
tmp_eval_loss
.
sum
().
item
()
eval_accuracy
+=
tmp_eval_accuracy
eval_accuracy
+=
tmp_eval_accuracy
nb_eval_examples
+=
input_ids
.
size
(
0
)
nb_eval_examples
+=
input_ids
.
size
(
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