OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TF FE] Stabilize tests for RandomUniform and RandomUniformInt on all platforms (#26921)
Roman Kazantsev3af0e9ebda36
diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.pyindex 5ef188435d2..8a6ecf8d343 100644--- a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py+++ b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py@@ -3,74 +3,50 @@import platform+import numpy as npimport pytestimport tensorflow as tffrom common.tf_layer_test_class import CommonTFLayerTestclass 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_typetf.compat.v1.reset_default_graph()# Create the graph and modelwith 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, None- return tf_net, ref_net-- 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):+ 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('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("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)+ 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)diff --git a/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py b/tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.pynew file mode 100644index 00000000000..6bbaf00c5c8--- /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('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,+ use_legacy_frontend=use_legacy_frontend)