Skip to content

Commit

Permalink
[TF FE] Test RaggedTensorToTensor for rowids format and Equal for str…
Browse files Browse the repository at this point in the history
…ing tensors (openvinotoolkit#23410)

**Details:** Test RaggedTensorToTensor for rowids format and Equal for
string tensors. Needs to be merged after
openvinotoolkit/openvino_tokenizers#70

**Tickets:** TBD

---------

Signed-off-by: Kazantsev, Roman <[email protected]>
  • Loading branch information
rkazants committed Mar 12, 2024
1 parent dec89c0 commit 5d9c595
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/layer_tests/tensorflow_tests/test_tf_Equal.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (C) 2022 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


# Testing operation Equal
# Documentation: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/math/equal
rng = np.random.default_rng()


class TestTFEqual(CommonTFLayerTest):
output_type = np.float32
Expand Down Expand Up @@ -210,3 +213,45 @@ def test_tf_equal_float64(self, params, ie_device, precision, ir_version, temp_d
ie_device, precision,
temp_dir=temp_dir, ir_version=ir_version, use_legacy_frontend=use_legacy_frontend,
**params)


class TestEqualStr(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'x:0' in inputs_info
assert 'y:0' in inputs_info
x_shape = inputs_info['x:0']
y_shape = inputs_info['y:0']
inputs_data = {}
strings_dictionary = ['UPPER<>CASE SENTENCE', 'lower case\n\s sentence', ' UppEr LoweR CAse SENtence \t\n',
' some sentence', 'another sentence HERE ']
inputs_data['x:0'] = rng.choice(strings_dictionary, x_shape)
inputs_data['y:0'] = rng.choice(strings_dictionary, y_shape)
return inputs_data

def create_equal_net(self, x_shape, y_shape):
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(tf.string, x_shape, 'x')
y = tf.compat.v1.placeholder(tf.string, x_shape, 'y')
tf.raw_ops.Equal(x=x, y=y)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def

ref_net = None

return tf_net, ref_net

@pytest.mark.parametrize('x_shape', [[1], [5]])
@pytest.mark.parametrize('y_shape', [[1], [5]])
@pytest.mark.precommit_tf_fe
@pytest.mark.nightly
@pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ['arm', 'armv7l',
'aarch64',
'arm64', 'ARM64'],
reason='126314, 132699: Build tokenizers for ARM and MacOS')
def test_equal_str(self, x_shape, y_shape,
ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
self._test(*self.create_equal_net(x_shape=x_shape, y_shape=y_shape),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
56 changes: 56 additions & 0 deletions tests/layer_tests/tensorflow_tests/test_tf_RaggedTensorToTensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,59 @@ def test_ragged_tensor_to_tensor(self, shape_type, shape_value, values_shape, va
row_partition_types=row_partition_types),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)


class TestRaggedTensorToTensorRowIds(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'values:0' in inputs_info, "Test error: inputs_info must contain `values`"
values_shape = inputs_info['values:0']
inputs_data = {}
if np.issubdtype(self.values_type, np.floating):
inputs_data['values:0'] = rng.uniform(-5.0, 5.0, values_shape).astype(self.values_type)
elif np.issubdtype(self.values_type, np.signedinteger):
inputs_data['values:0'] = rng.integers(-8, 8, values_shape).astype(self.values_type)
else:
inputs_data['values:0'] = rng.integers(0, 8, values_shape).astype(self.values_type)
return inputs_data

def create_ragged_tensor_to_tensor_net(self, shape_type, shape_value, values_shape, values_type, default_value,
row_partition_tensors, row_partition_types):
self.values_type = values_type
tf.compat.v1.reset_default_graph()

# Create the graph and model
with tf.compat.v1.Session() as sess:
values = tf.compat.v1.placeholder(values_type, values_shape, 'values')
shape = tf.constant(shape_value, dtype=shape_type)
default_value = tf.constant(default_value, dtype=values_type)
tf.raw_ops.RaggedTensorToTensor(shape=shape, values=values, default_value=default_value,
row_partition_tensors=row_partition_tensors,
row_partition_types=row_partition_types)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def

return tf_net, None

@pytest.mark.parametrize('shape_type', [np.int32, np.int64])
@pytest.mark.parametrize('shape_value', [[4, 8], [-1, 64], [5, -1], [-1, -1]])
@pytest.mark.parametrize('values_shape', [[10]])
@pytest.mark.parametrize('values_type', [np.float32, np.int32, np.int64])
@pytest.mark.parametrize('default_value', [-1, 0])
@pytest.mark.parametrize('row_partition_tensors', [[20, [1, 2, 3, 3, 4, 8, 8, 9, 9, 9]]])
@pytest.mark.parametrize('row_partition_types', [["FIRST_DIM_SIZE", "VALUE_ROWIDS"]])
@pytest.mark.precommit_tf_fe
@pytest.mark.nightly
@pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ['arm', 'armv7l',
'aarch64',
'arm64', 'ARM64'],
reason='126314, 132699: Build tokenizers for ARM and MacOS')
def test_ragged_tensor_to_tensor(self, shape_type, shape_value, values_shape, values_type, default_value,
row_partition_tensors, row_partition_types,
ie_device, precision, ir_version, temp_dir, use_legacy_frontend):
self._test(*self.create_ragged_tensor_to_tensor_net(shape_type=shape_type, shape_value=shape_value,
values_shape=values_shape, values_type=values_type,
default_value=default_value,
row_partition_tensors=row_partition_tensors,
row_partition_types=row_partition_types),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)

0 comments on commit 5d9c595

Please sign in to comment.