diff --git a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/kashin_test.py b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/kashin_test.py index cc20aeb57..563d0398a 100644 --- a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/kashin_test.py +++ b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/kashin_test.py @@ -204,7 +204,7 @@ def test_unknown_shape_raises(self): x = test_utils.get_tensor_with_random_shape() stage = self.default_encoding_stage() params, _ = stage.get_params() - with self.assertRaisesRegexp(ValueError, 'fully known'): + with self.assertRaisesRegex(ValueError, 'fully known'): stage.encode(x, params) @parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)]) @@ -212,41 +212,41 @@ def test_more_than_two_ndims_raises(self, dims): x = tf.random.normal(dims) stage = self.default_encoding_stage() params, _ = stage.get_params() - with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'): + with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'): stage.encode(x, params) @parameterized.parameters([0.0, 1.0, -1.0, 2.5]) def test_eta_out_of_bounds_raises(self, eta): - with self.assertRaisesRegexp(ValueError, 'between 0 and 1'): + with self.assertRaisesRegex(ValueError, 'between 0 and 1'): kashin.KashinHadamardEncodingStage(eta=eta) @parameterized.parameters([0.0, -1.0]) def test_delta_small_raises(self, delta): - with self.assertRaisesRegexp(ValueError, 'greater than 0'): + with self.assertRaisesRegex(ValueError, 'greater than 0'): kashin.KashinHadamardEncodingStage(delta=delta) @parameterized.parameters([0, -1, -10]) def test_num_iters_small_raises(self, num_iters): - with self.assertRaisesRegexp(ValueError, 'positive'): + with self.assertRaisesRegex(ValueError, 'positive'): kashin.KashinHadamardEncodingStage(num_iters=num_iters) def test_num_iters_tensor_raises(self): - with self.assertRaisesRegexp(ValueError, 'num_iters'): + with self.assertRaisesRegex(ValueError, 'num_iters'): kashin.KashinHadamardEncodingStage( num_iters=tf.constant(2, dtype=tf.int32)) def test_last_iter_clip_tensor_raises(self): - with self.assertRaisesRegexp(ValueError, 'last_iter_clip'): + with self.assertRaisesRegex(ValueError, 'last_iter_clip'): kashin.KashinHadamardEncodingStage( last_iter_clip=tf.constant(True, dtype=tf.bool)) @parameterized.parameters([0, 1, 0.0, 1.0]) def test_last_iter_clip_not_bool_raises(self, last_iter_clip): - with self.assertRaisesRegexp(ValueError, 'last_iter_clip must be a bool'): + with self.assertRaisesRegex(ValueError, 'last_iter_clip must be a bool'): kashin.KashinHadamardEncodingStage(last_iter_clip=last_iter_clip) def test_pad_extra_level_threshold_tensor_raises(self): - with self.assertRaisesRegexp(ValueError, 'pad_extra_level_threshold'): + with self.assertRaisesRegex(ValueError, 'pad_extra_level_threshold'): kashin.KashinHadamardEncodingStage( pad_extra_level_threshold=tf.constant(0.8, dtype=tf.float32)) diff --git a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/misc_test.py b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/misc_test.py index 2d2ff063b..ad49e9847 100644 --- a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/misc_test.py +++ b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/misc_test.py @@ -176,7 +176,7 @@ def test_empty_input_dynamic(self): @parameterized.parameters([tf.bool, tf.float32]) def test_encode_unsupported_type_raises(self, dtype): stage = self.default_encoding_stage() - with self.assertRaisesRegexp(TypeError, 'Unsupported input type'): + with self.assertRaisesRegex(TypeError, 'Unsupported input type'): self.run_one_to_many_encode_decode( stage, lambda: tf.cast(self.default_input(), dtype)) @@ -184,7 +184,7 @@ def test_encode_unsupported_input_shape_raises(self): x = tf.random.uniform((3, 4), maxval=10, dtype=tf.int32) stage = self.default_encoding_stage() params, _ = stage.get_params() - with self.assertRaisesRegexp(ValueError, 'Number of dimensions must be 1'): + with self.assertRaisesRegex(ValueError, 'Number of dimensions must be 1'): stage.encode(x, params) diff --git a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/quantization_test.py b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/quantization_test.py index bee155e56..43a148588 100644 --- a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/quantization_test.py +++ b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/quantization_test.py @@ -112,7 +112,7 @@ def test_all_zero_input_works(self): @parameterized.parameters([0, 17, -1, 1.5]) def test_bits_out_of_range_raises(self, bits): - with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'): quantization.PRNGUniformQuantizationEncodingStage(bits=bits) def test_dynamic_input_shape(self): @@ -226,11 +226,11 @@ def test_all_zero_input_works(self): @parameterized.parameters([0, 17, -1, 1.5]) def test_bits_out_of_range_raises(self, bits): - with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'): quantization.PerChannelUniformQuantizationEncodingStage(bits=bits) def test_stochastic_tensor_raises(self): - with self.assertRaisesRegexp(TypeError, 'stochastic'): + with self.assertRaisesRegex(TypeError, 'stochastic'): quantization.PerChannelUniformQuantizationEncodingStage( stochastic=tf.constant(True, dtype=tf.bool)) @@ -343,7 +343,7 @@ def test_all_zero_input_works(self): @parameterized.parameters([0, 17, -1, 1.5]) def test_bits_out_of_range_raises(self, bits): - with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'): quantization.PerChannelPRNGUniformQuantizationEncodingStage(bits=bits) def test_dynamic_input_shape(self): diff --git a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/stages_impl_test.py b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/stages_impl_test.py index 72dbef081..c2c074ebb 100644 --- a/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/stages_impl_test.py +++ b/tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/stages_impl_test.py @@ -192,7 +192,7 @@ def test_unknown_shape_raises(self): x = test_utils.get_tensor_with_random_shape() stage = self.default_encoding_stage() params, _ = stage.get_params() - with self.assertRaisesRegexp(ValueError, 'fully known'): + with self.assertRaisesRegex(ValueError, 'fully known'): stage.encode(x, params) @parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)]) @@ -200,7 +200,7 @@ def test_more_than_two_ndims_raises(self, dims): x = tf.random.normal(dims) stage = self.default_encoding_stage() params, _ = stage.get_params() - with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'): + with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'): stage.encode(x, params) @@ -336,27 +336,27 @@ def test_commutes_with_sum_given_min_max(self): @parameterized.parameters([0, 17, -1, 1.5]) def test_bits_out_of_range_raises(self, bits): - with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'): stages_impl.UniformQuantizationEncodingStage(bits=bits) @parameterized.parameters([1.0, ([1.0, 2.0, 3.0],)]) def test_bad_min_max_tensor_raises(self, bad_min_max): - with self.assertRaisesRegexp(ValueError, r'shape \(2\)'): + with self.assertRaisesRegex(ValueError, r'shape \(2\)'): stages_impl.UniformQuantizationEncodingStage( min_max=tf.constant(bad_min_max)) @parameterized.parameters([([1.0],), ([1.0, 2.0, 3.0],)]) def test_bad_min_max_python_shape_raises(self, bad_min_max): - with self.assertRaisesRegexp(ValueError, 'list with two elements'): + with self.assertRaisesRegex(ValueError, 'list with two elements'): stages_impl.UniformQuantizationEncodingStage(min_max=bad_min_max) @parameterized.parameters([([1.0, 1.0],), ([2.0, 1.0],)]) def test_bad_min_max_python_values_raises(self, bad_min_max): - with self.assertRaisesRegexp(ValueError, 'smaller than the second'): + with self.assertRaisesRegex(ValueError, 'smaller than the second'): stages_impl.UniformQuantizationEncodingStage(min_max=bad_min_max) def test_stochastic_tensor_raises(self): - with self.assertRaisesRegexp(TypeError, 'stochastic'): + with self.assertRaisesRegex(TypeError, 'stochastic'): stages_impl.UniformQuantizationEncodingStage( stochastic=tf.constant(True, dtype=tf.bool)) @@ -441,16 +441,16 @@ def test_bad_input_executes(self): @parameterized.parameters([tf.bool, tf.int32]) def test_encode_unsupported_type_raises(self, dtype): stage = self.default_encoding_stage() - with self.assertRaisesRegexp(TypeError, 'Unsupported packing type'): + with self.assertRaisesRegex(TypeError, 'Unsupported packing type'): self.run_one_to_many_encode_decode( stage, lambda: tf.cast(self.default_input(), dtype)) def test_bad_input_bits_raises(self): - with self.assertRaisesRegexp(TypeError, 'cannot be a TensorFlow value'): + with self.assertRaisesRegex(TypeError, 'cannot be a TensorFlow value'): stages_impl.BitpackingEncodingStage(tf.constant(1, dtype=tf.int32)) - with self.assertRaisesRegexp(ValueError, 'between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'between 1 and 16'): stages_impl.BitpackingEncodingStage(0) - with self.assertRaisesRegexp(ValueError, 'between 1 and 16'): + with self.assertRaisesRegex(ValueError, 'between 1 and 16'): stages_impl.BitpackingEncodingStage(17) diff --git a/tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/tf_utils_test.py b/tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/tf_utils_test.py index 6675ed2f7..d2003d31d 100644 --- a/tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/tf_utils_test.py +++ b/tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/tf_utils_test.py @@ -57,16 +57,18 @@ def test_apply_twice_equals_identity(self, first_dim): def test_illegal_inputs_shape(self, *dims): """Tests incorrect rank of the input.""" x = tf.random.normal(dims) - with self.assertRaisesRegexp(ValueError, - 'Number of dimensions of x must be 2.'): + with self.assertRaisesRegex( + ValueError, 'Number of dimensions of x must be 2.' + ): tf_utils.fast_walsh_hadamard_transform(x) @parameterized.parameters([[1, 3], [1, 7], [1, 9], [4, 3]]) def test_illegal_inputs_static_power_of_two(self, *dims): """Tests incorrect static shape of the rank 2 input.""" x = tf.random.normal(dims) - with self.assertRaisesRegexp(ValueError, - 'The dimension of x must be a power of two.'): + with self.assertRaisesRegex( + ValueError, 'The dimension of x must be a power of two.' + ): tf_utils.fast_walsh_hadamard_transform(x) def test_illegal_inputs_dynamic_power_of_two(self): @@ -170,20 +172,20 @@ def test_approximately_uniform_distribution(self): self.assertAllLessEqual(bucket_counts, 10250) def test_tensor_num_elements_raises(self): - with self.assertRaisesRegexp(TypeError, 'must be a Python integer'): + with self.assertRaisesRegex(TypeError, 'must be a Python integer'): tf_utils._cmwc_random_sequence( tf.constant(10), tf.constant(123, tf.int64)) def test_negative_num_elements_raises(self): - with self.assertRaisesRegexp(ValueError, 'must be positive'): + with self.assertRaisesRegex(ValueError, 'must be positive'): tf_utils._cmwc_random_sequence(-10, tf.constant(123, tf.int64)) def test_python_seed_raises(self): - with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'): + with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'): tf_utils._cmwc_random_sequence(10, 123) def test_tf_int32_seed_raises(self): - with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'): + with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'): tf_utils._cmwc_random_sequence(10, tf.constant(123, tf.int32)) @@ -232,9 +234,9 @@ def test_expected_dtype(self, dtype): @parameterized.parameters([tf.int32, tf.int64]) def test_type_error_raises(self, dtype): - with self.assertRaisesRegexp( - TypeError, 'Supported types are tf.float32 and ' - 'tf.float64 values'): + with self.assertRaisesRegex( + TypeError, 'Supported types are tf.float32 and tf.float64 values' + ): tf_utils.random_floats_cmwc(10, tf.constant(456, tf.int64), dtype) def test_differs_given_different_seed(self): @@ -291,9 +293,9 @@ def test_expected_dtype(self, dtype): @parameterized.parameters([tf.int32, tf.int64]) def test_type_error_raises(self, dtype): - with self.assertRaisesRegexp(TypeError, - 'Supported types are tf.float32 and ' - 'tf.float64 values'): + with self.assertRaisesRegex( + TypeError, 'Supported types are tf.float32 and tf.float64 values' + ): tf_utils.random_floats(10, tf.constant([456, 123], tf.int64), dtype) def test_differs_given_different_seed(self):