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

[TF FE] Stabilize tests for RandomUniform and RandomUniformInt on all platforms #26921

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
82 changes: 28 additions & 54 deletions tests/layer_tests/tensorflow_tests/test_tf_RandomUniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,48 @@

import platform

import numpy as np
rkazants marked this conversation as resolved.
Show resolved Hide resolved
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, 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):
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('156027: Incorrect specification of RandomUniform for float16 and float64 output type')
rkazants marked this conversation as resolved.
Show resolved Hide resolved
if platform.machine() in ["aarch64", "arm64", "ARM64"]:
pytest.skip("156055: accuracy error on ARM")
rkazants marked this conversation as resolved.
Show resolved Hide resolved
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)
51 changes: 51 additions & 0 deletions tests/layer_tests/tensorflow_tests/test_tf_RandomUniformInt.py
Original file line number Diff line number Diff line change
@@ -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)
Loading