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
ModelZoo
ResNet50_tensorflow
Commits
306e3e14
Commit
306e3e14
authored
Oct 16, 2019
by
A. Unique TensorFlower
Browse files
Do not scale loss manually for BERT classifier when compile/fit() API is used.
PiperOrigin-RevId: 275142626
parent
06412123
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
official/nlp/bert/run_classifier.py
official/nlp/bert/run_classifier.py
+11
-4
No files found.
official/nlp/bert/run_classifier.py
View file @
306e3e14
...
...
@@ -132,10 +132,17 @@ def run_bert_classifier(strategy,
classifier_model
.
optimizer
)
return
classifier_model
,
core_model
loss_fn
=
get_loss_fn
(
num_classes
,
loss_factor
=
1.0
/
strategy
.
num_replicas_in_sync
if
FLAGS
.
scale_loss
else
1.0
)
# During distributed training, loss used for gradient computation is
# summed over from all replicas. When Keras compile/fit() API is used,
# the fit() API internally normalizes the loss by dividing the loss by
# the number of replicas used for computation. However, when custom
# training loop is used this is not done automatically and should be
# done manually by the end user.
loss_multiplier
=
1.0
if
FLAGS
.
scale_loss
and
not
use_keras_compile_fit
:
loss_multiplier
=
1.0
/
strategy
.
num_replicas_in_sync
loss_fn
=
get_loss_fn
(
num_classes
,
loss_factor
=
loss_multiplier
)
# Defines evaluation metrics function, which will create metrics in the
# correct device and strategy scope.
...
...
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