Skip to content

Commit 0587cde

Browse files
authored
Switch to non-experimental mixed precision API. (#2657)
1 parent 53d70f2 commit 0587cde

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

Diff for: tensorflow_addons/callbacks/tests/avg_model_checkpoint_test.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ def test_invalid_save_freq(tmp_path):
200200
def test_loss_scale_optimizer(tmp_path):
201201
test_model_filepath = str(tmp_path / "test_model.{epoch:02d}.h5")
202202
moving_avg = MovingAverage(tf.keras.optimizers.SGD(lr=2.0), average_decay=0.5)
203-
optimizer = tf.keras.mixed_precision.experimental.LossScaleOptimizer(
204-
moving_avg, "dynamic"
205-
)
203+
optimizer = tf.keras.mixed_precision.LossScaleOptimizer(moving_avg)
206204
x, y, model = get_data_and_model(optimizer)
207205
save_freq = "epoch"
208206
avg_model_ckpt = AverageModelCheckpoint(

Diff for: tensorflow_addons/layers/tests/noisy_dense_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import tensorflow as tf
2222
from tensorflow import keras
23-
from tensorflow.keras.mixed_precision.experimental import Policy
2423

2524
from tensorflow_addons.utils import test_utils
2625
from tensorflow_addons.layers.noisy_dense import NoisyDense
@@ -47,7 +46,7 @@ def test_noisy_dense_dtype(dtype):
4746
@pytest.mark.usefixtures("maybe_run_functions_eagerly")
4847
def test_noisy_dense_with_policy():
4948
inputs = tf.convert_to_tensor(np.random.randint(low=0, high=7, size=(2, 2)))
50-
layer = NoisyDense(5, dtype=Policy("mixed_float16"), name="noisy_dense_policy")
49+
layer = NoisyDense(5, dtype="mixed_float16", name="noisy_dense_policy")
5150
outputs = layer(inputs)
5251
output_signature = layer.compute_output_signature(
5352
tf.TensorSpec(dtype="float16", shape=(2, 2))

Diff for: tensorflow_addons/layers/tests/stochastic_depth_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def stochastic_depth_test(seed, training):
4141

4242
@pytest.mark.usefixtures("run_with_mixed_precision_policy")
4343
def test_with_mixed_precision_policy():
44-
policy = tf.keras.mixed_precision.experimental.global_policy()
44+
policy = tf.keras.mixed_precision.global_policy()
4545

4646
shortcut = np.asarray([[0.2, 0.1, 0.4]])
4747
residual = np.asarray([[0.2, 0.4, 0.5]])

Diff for: tensorflow_addons/seq2seq/tests/attention_wrapper_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _test_with_attention(
398398
seed=1337
399399
)
400400

401-
policy = tf.keras.mixed_precision.experimental.global_policy()
401+
policy = tf.keras.mixed_precision.global_policy()
402402
sampler = sampler_py.TrainingSampler()
403403
my_decoder = basic_decoder.BasicDecoder(cell=cell, sampler=sampler)
404404
initial_state = cell.get_initial_state(
@@ -541,7 +541,7 @@ def set_random_state_for_tf_and_np():
541541
@pytest.mark.usefixtures("run_with_mixed_precision_policy")
542542
def test_bahdanau_not_normalized():
543543
set_random_state_for_tf_and_np()
544-
policy = tf.keras.mixed_precision.experimental.global_policy()
544+
policy = tf.keras.mixed_precision.global_policy()
545545
create_attention_mechanism = wrapper.BahdanauAttention
546546
create_attention_kwargs = {"kernel_initializer": "ones"}
547547
expected_final_output = basic_decoder.BasicDecoderOutput(
@@ -617,7 +617,7 @@ def test_bahdanau_normalized():
617617
@pytest.mark.usefixtures("run_with_mixed_precision_policy")
618618
def test_luong_not_normalized():
619619
set_random_state_for_tf_and_np()
620-
policy = tf.keras.mixed_precision.experimental.global_policy()
620+
policy = tf.keras.mixed_precision.global_policy()
621621
create_attention_mechanism = wrapper.LuongAttention
622622

623623
expected_final_output = basic_decoder.BasicDecoderOutput(

Diff for: tensorflow_addons/seq2seq/tests/decoder_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_dynamic_decode_rnn_with_training_helper_matches_dynamic_rnn(
181181

182182
@pytest.mark.usefixtures("run_with_mixed_precision_policy")
183183
def test_dynamic_decode_rnn_with_scheduled_embedding_training_sampler():
184-
policy = tf.keras.mixed_precision.experimental.global_policy()
184+
policy = tf.keras.mixed_precision.global_policy()
185185
sequence_length = [3, 4, 3, 1]
186186
batch_size = 4
187187
input_depth = 7

Diff for: tensorflow_addons/utils/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def _restore_py_ops_value():
114114

115115
@pytest.fixture(scope="function", params=["float32", "mixed_float16"])
116116
def run_with_mixed_precision_policy(request):
117-
tf.keras.mixed_precision.experimental.set_policy(request.param)
117+
tf.keras.mixed_precision.set_global_policy(request.param)
118118
yield
119-
tf.keras.mixed_precision.experimental.set_policy("float32")
119+
tf.keras.mixed_precision.set_global_policy("float32")
120120

121121

122122
@pytest.fixture(scope="function", params=["channels_first", "channels_last"])

0 commit comments

Comments
 (0)