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

Fix tests of mixed precision now that experimental is deprecated #17300

Merged
merged 2 commits into from
May 17, 2022
Merged
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
6 changes: 2 additions & 4 deletions src/transformers/training_args_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ def _setup_strategy(self) -> Tuple["tf.distribute.Strategy", int]:

# Set to float16 at first
if self.fp16:
policy = tf.keras.mixed_precision.experimental.Policy("mixed_float16")
tf.keras.mixed_precision.experimental.set_policy(policy)
tf.keras.mixed_precision.set_global_policy("mixed_float16")

if self.no_cuda:
strategy = tf.distribute.OneDeviceStrategy(device="/cpu:0")
Expand All @@ -217,8 +216,7 @@ def _setup_strategy(self) -> Tuple["tf.distribute.Strategy", int]:
if tpu:
# Set to bfloat16 in case of TPU
if self.fp16:
policy = tf.keras.mixed_precision.experimental.Policy("mixed_bfloat16")
tf.keras.mixed_precision.experimental.set_policy(policy)
tf.keras.mixed_precision.set_global_policy("mixed_bfloat16")

tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/test_modeling_tf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_saved_model_creation_extended(self):

@slow
def test_mixed_precision(self):
tf.keras.mixed_precision.experimental.set_policy("mixed_float16")
tf.keras.mixed_precision.set_global_policy("mixed_float16")

config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()

Expand All @@ -216,7 +216,7 @@ def test_mixed_precision(self):

self.assertIsNotNone(outputs)

tf.keras.mixed_precision.experimental.set_policy("float32")
tf.keras.mixed_precision.set_global_policy("float32")

@slow
def test_train_pipeline_custom_model(self):
Expand Down