From a613b2609442885a74abef36d79fd44374cac79a Mon Sep 17 00:00:00 2001 From: "Kazantsev, Roman" Date: Sat, 5 Oct 2024 21:32:59 +0400 Subject: [PATCH 1/5] [TF FE] Stabilize tests for RandomUniform and RandomUniformInt on all platforms Signed-off-by: Kazantsev, Roman --- .../tensorflow_tests/test_tf_RandomUniform.py | 82 ++++++------------- .../test_tf_RandomUniformInt.py | 51 ++++++++++++ 2 files changed, 77 insertions(+), 56 deletions(-) create mode 100644 tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index 5ef188435d23d5..1e1f990f9a6c15 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -1,76 +1,46 @@ # Copyright (C) 2018-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import platform - +import numpy as np import pytest import tensorflow as tf from common.tf_layer_test_class import CommonTFLayerTest class TestRandomUniform(CommonTFLayerTest): - def create_tf_random_uniform_net(self, global_seed, op_seed, x_shape, min_val, max_val, - input_type, precision, - ir_version, use_legacy_frontend): + def _prepare_input(self, inputs_info): + assert 'shape:0' in inputs_info, "Test error: inputs_info must contain `shape`" + inputs_data = {} + inputs_data['shape:0'] = np.array(self.shape_value).astype(self.shape_type) + return inputs_data + + def create_tf_random_uniform_net(self, shape_value, shape_type, dtype, seed, seed2): + self.shape_value = shape_value + self.shape_type = shape_type tf.compat.v1.reset_default_graph() # Create the graph and model with tf.compat.v1.Session() as sess: - x = tf.compat.v1.placeholder(input_type, x_shape, 'Input') - if global_seed is not None: - tf.compat.v1.random.set_random_seed(global_seed) - tf.random.uniform(x_shape, seed=op_seed, dtype=input_type, - minval=min_val, - maxval=max_val) + x + shape = tf.compat.v1.placeholder(shape_type, [len(shape_value)], 'shape') + tf.raw_ops.RandomUniform(shape=shape, dtype=dtype, seed=seed, seed2=seed2) tf.compat.v1.global_variables_initializer() tf_net = sess.graph_def - ref_net = None - - return tf_net, ref_net + return tf_net, None - test_data_basic = [ - dict(global_seed=32465, op_seed=48971, min_val=0.0, max_val=1.0, x_shape=[3, 7], - input_type=tf.float32), - dict(global_seed=78132, op_seed=None, min_val=-200, max_val=-50, x_shape=[5, 8], - input_type=tf.int32) - ] - - @pytest.mark.parametrize("params", test_data_basic) + @pytest.mark.parametrize('shape_value', [[2], [3, 4], [8, 5, 3]]) + @pytest.mark.parametrize('shape_type', [np.int32, np.int64]) + @pytest.mark.parametrize('dtype', [np.float16, np.float32, np.float64]) + @pytest.mark.parametrize('seed', [312, 50]) + @pytest.mark.parametrize('seed2', [1, 22]) @pytest.mark.nightly @pytest.mark.precommit - @pytest.mark.precommit - @pytest.mark.xfail(platform.machine() in ["aarch64", "arm64", "ARM64"], - reason='Ticket - 122716') - def test_random_uniform_basic(self, params, ie_device, precision, ir_version, temp_dir, - use_legacy_frontend): - if ie_device == 'GPU': - pytest.skip("RandomUniform is not supported on GPU") - self._test( - *self.create_tf_random_uniform_net(**params, precision=precision, ir_version=ir_version, - use_legacy_frontend=use_legacy_frontend), ie_device, - precision, temp_dir=temp_dir, ir_version=ir_version, use_legacy_frontend=use_legacy_frontend, - **params) - - test_data_other = [ - dict(global_seed=None, op_seed=56197, min_val=-100, max_val=100, x_shape=[6], - input_type=tf.float32), - dict(global_seed=None, op_seed=56197, min_val=-100, max_val=100, x_shape=[1, 2, 1, 1], - input_type=tf.float32), - dict(global_seed=4571, op_seed=48971, min_val=1.5, max_val=2.3, x_shape=[7], - input_type=tf.float32), - dict(global_seed=32465, op_seed=12335, min_val=-150, max_val=-100, x_shape=[18], - input_type=tf.int32)] - - @pytest.mark.parametrize("params", test_data_other) - @pytest.mark.nightly - def test_random_uniform_other(self, params, ie_device, precision, ir_version, temp_dir, - use_legacy_frontend): - if ie_device == 'GPU': - pytest.skip("RandomUniform is not supported on GPU") - self._test( - *self.create_tf_random_uniform_net(**params, precision=precision, ir_version=ir_version, - use_legacy_frontend=use_legacy_frontend), ie_device, - precision, temp_dir=temp_dir, ir_version=ir_version, use_legacy_frontend=use_legacy_frontend, - **params) + def test_random_uniform(self, shape_value, shape_type, dtype, seed, seed2, + ie_device, precision, ir_version, temp_dir, + use_legacy_frontend): + if dtype == np.float16 or dtype == np.float64: + pytest.skip('Incorrect specification of RandomUniform for float16 and float64 output type') + self._test(*self.create_tf_random_uniform_net(shape_value, shape_type, dtype, seed, seed2), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_legacy_frontend=use_legacy_frontend) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py new file mode 100644 index 00000000000000..e3b224d3603746 --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py @@ -0,0 +1,51 @@ +# Copyright (C) 2018-2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest + + +class TestRandomUniformInt(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'shape:0' in inputs_info, "Test error: inputs_info must contain `shape`" + inputs_data = {} + inputs_data['shape:0'] = np.array(self.shape_value).astype(self.shape_type) + return inputs_data + + def create_tf_random_uniform_int_net(self, shape_value, shape_type, minval_type, + minval_value, maxval_value, seed, seed2): + self.shape_value = shape_value + self.shape_type = shape_type + tf.compat.v1.reset_default_graph() + + # Create the graph and model + with tf.compat.v1.Session() as sess: + shape = tf.compat.v1.placeholder(shape_type, [len(shape_value)], 'shape') + minval = tf.constant(minval_value, dtype=minval_type) + maxval = tf.constant(maxval_value, dtype=minval_type) + tf.raw_ops.RandomUniformInt(shape=shape, minval=minval, maxval=maxval, + seed=seed, seed2=seed2) + + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + @pytest.mark.parametrize('shape_value', [[2], [3, 4], [8, 5, 3]]) + @pytest.mark.parametrize('shape_type', [np.int32, np.int64]) + @pytest.mark.parametrize('minval_type', [np.int32, np.int64]) + @pytest.mark.parametrize('minval_value,maxval_value', [(0, 10), (-5, 4), (-10, -1)]) + @pytest.mark.parametrize('seed', [312, 50]) + @pytest.mark.parametrize('seed2', [1, 22]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_random_uniform_int(self, shape_value, shape_type, minval_type, minval_value, maxval_value, seed, seed2, + ie_device, precision, ir_version, temp_dir, use_legacy_frontend): + if minval_type == np.int64: + pytest.skip('Incorrect specification of RandomUniform for np.int64 output type') + self._test(*self.create_tf_random_uniform_int_net(shape_value, shape_type, minval_type, + minval_value, maxval_value, seed, seed2), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_legacy_frontend=use_legacy_frontend) From 598881d6f7e3e81583a6448fb7ec8cbf0875cbf4 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Fri, 25 Oct 2024 11:56:43 +0400 Subject: [PATCH 2/5] Apply suggestions from code review --- tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py | 2 +- tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index 1e1f990f9a6c15..fcad5b19399837 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -40,7 +40,7 @@ def test_random_uniform(self, shape_value, shape_type, dtype, seed, seed2, ie_device, precision, ir_version, temp_dir, use_legacy_frontend): if dtype == np.float16 or dtype == np.float64: - pytest.skip('Incorrect specification of RandomUniform for float16 and float64 output type') + pytest.skip('156027: Incorrect specification of RandomUniform for float16 and float64 output type') self._test(*self.create_tf_random_uniform_net(shape_value, shape_type, dtype, seed, seed2), ie_device, precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py index e3b224d3603746..6bbaf00c5c8b35 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py @@ -44,7 +44,7 @@ def create_tf_random_uniform_int_net(self, shape_value, shape_type, minval_type, def test_random_uniform_int(self, shape_value, shape_type, minval_type, minval_value, maxval_value, seed, seed2, ie_device, precision, ir_version, temp_dir, use_legacy_frontend): if minval_type == np.int64: - pytest.skip('Incorrect specification of RandomUniform for np.int64 output type') + pytest.skip('156027: Incorrect specification of RandomUniform for np.int64 output type') self._test(*self.create_tf_random_uniform_int_net(shape_value, shape_type, minval_type, minval_value, maxval_value, seed, seed2), ie_device, precision, ir_version, temp_dir=temp_dir, From 453721ab8f97f497d8b46183e5a24e46ef6d5d14 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Fri, 25 Oct 2024 14:39:59 +0400 Subject: [PATCH 3/5] Apply suggestions from code review --- tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index fcad5b19399837..69f4f2d5ca2d51 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 +import platform + import numpy as np import pytest import tensorflow as tf @@ -41,6 +43,9 @@ def test_random_uniform(self, shape_value, shape_type, dtype, seed, seed2, use_legacy_frontend): if dtype == np.float16 or dtype == np.float64: pytest.skip('156027: Incorrect specification of RandomUniform for float16 and float64 output type') + if platform.machine() in ["aarch64", "arm64", "ARM64"]: + pytest.skip("156055: accuracy error on ARM") + self._test(*self.create_tf_random_uniform_net(shape_value, shape_type, dtype, seed, seed2), ie_device, precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend) From 7960564402b9ee7020966b97a4db9ecac379f4c5 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Fri, 25 Oct 2024 14:40:17 +0400 Subject: [PATCH 4/5] Update tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py --- tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index 69f4f2d5ca2d51..963a65090a072b 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -45,7 +45,6 @@ def test_random_uniform(self, shape_value, shape_type, dtype, seed, seed2, pytest.skip('156027: Incorrect specification of RandomUniform for float16 and float64 output type') if platform.machine() in ["aarch64", "arm64", "ARM64"]: pytest.skip("156055: accuracy error on ARM") - self._test(*self.create_tf_random_uniform_net(shape_value, shape_type, dtype, seed, seed2), ie_device, precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend) From 4a5262f2cfbddfa2fb9e86410738ecfbc1f48fbf Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Fri, 25 Oct 2024 14:43:41 +0400 Subject: [PATCH 5/5] Update tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py --- tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py index 963a65090a072b..8a6ecf8d343a3c 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py @@ -45,6 +45,8 @@ def test_random_uniform(self, shape_value, shape_type, dtype, seed, seed2, pytest.skip('156027: Incorrect specification of RandomUniform for float16 and float64 output type') if platform.machine() in ["aarch64", "arm64", "ARM64"]: pytest.skip("156055: accuracy error on ARM") + if ie_device == 'GPU': + pytest.skip('156056: Accuracy error on GPU') self._test(*self.create_tf_random_uniform_net(shape_value, shape_type, dtype, seed, seed2), ie_device, precision, ir_version, temp_dir=temp_dir, use_legacy_frontend=use_legacy_frontend)