Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding GPU automatic mixed precision training #200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def get_train_op(FLAGS, total_loss, grads_and_vars=None):
if FLAGS.use_tpu:
optimizer = tf.contrib.tpu.CrossShardOptimizer(optimizer)

if 'gpu_auto_mixed_precision' in FLAGS and FLAGS.gpu_auto_mixed_precision:
if FLAGS.use_tpu:
raise(RuntimeError("GPU auto mixed precision cannot be used with TPU"))
else:
print("=============Enabling GPU Automatic Mixed Precision=============")
optimizer = tf.train.experimental.enable_mixed_precision_graph_rewrite(optimizer)

if grads_and_vars is None:
grads_and_vars = optimizer.compute_gradients(total_loss)
gradients, variables = zip(*grads_and_vars)
Expand Down
2 changes: 2 additions & 0 deletions run_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
help="Classifier layer scope.")
flags.DEFINE_bool("is_regression", default=False,
help="Whether it's a regression task.")
flags.DEFINE_bool("gpu_auto_mixed_precision", default=False,
help="Enabling GPU automatic mixed precision training.")

FLAGS = flags.FLAGS

Expand Down