Skip to content

Commit

Permalink
[TF FE] Enable parallel execution of TensorFlow Layer 2 python tests (o…
Browse files Browse the repository at this point in the history
…penvinotoolkit#23344)

Addresses issue: openvinotoolkit#20919 

### Details:
- Enables parallel execution of TensorFlow Layer 2 python tests
- Fixes test_tf2_keras_conv_lstm_2d.py and test_tf2_map_fn.py to not
fail during parallel execution
- Appends args in github workflow to enable parallel execution

Errors fixed:
- Due to varying Kera activation function addresses causing the workers
to get different parameter inputs and thus failing. See [known
issue](https://pytest-xdist.readthedocs.io/en/stable/known-limitations.html#order-and-amount-of-test-must-be-consistent)
```
-tensorflow2_keras_tests/test_tf2_keras_conv_lstm_2d.py::TestKerasConvLSTM2D::test_keras_conv_lstm_2d_basic[ ie_device:CPU - precision:FP32 - params:{'params': {'filters': 4, 'kernel_size': (3, 3), 'padding': 'same', 'return_sequences': False, 'activation': <function swish at 0x7f1fadf364d0>}, 'input_shapes': [[2, 5, 20, 30, 2]]} ]
-tensorflow2_keras_tests/test_tf2_keras_conv_lstm_2d.py::TestKerasConvLSTM2D::test_keras_conv_lstm_2d_basic[ ie_device:CPU - precision:FP32 - params:{'params': {'filters': 6, 'kernel_size': (2, 3), 'padding': 'valid', 'dilation_rate': 3, 'recurrent_activation': <function elu at 0x7f1fe6a1a830>, 'return_sequences': True, 'use_bias': True, 'data_format': 'channels_first'}, 'input_shapes': [[2, 5, 1, 40, 30]]} ]
+tensorflow2_keras_tests/test_tf2_keras_conv_lstm_2d.py::TestKerasConvLSTM2D::test_keras_conv_lstm_2d_basic[ ie_device:CPU - precision:FP32 - params:{'params': {'filters': 4, 'kernel_size': (3, 3), 'padding': 'same', 'return_sequences': False, 'activation': <function swish at 0x7f635e4d24d0>}, 'input_shapes': [[2, 5, 20, 30, 2]]} ]
+tensorflow2_keras_tests/test_tf2_keras_conv_lstm_2d.py::TestKerasConvLSTM2D::test_keras_conv_lstm_2d_basic[ ie_device:CPU - precision:FP32 - params:{'params': {'filters': 6, 'kernel_size': (2, 3), 'padding': 'valid', 'dilation_rate': 3, 'recurrent_activation': <function elu at 0x7f6396fa2830>, 'return_sequences': True, 'use_bias': True, 'data_format': 'channels_first'}, 'input_shapes': [[2, 5, 1, 40, 30]]} ]
```

- Due to lambda function definitions giving varying addresses as inputs
```
-tensorflow2_keras_tests/test_tf2_map_fn.py::TestMapFN::test_multiple_inputs_outputs_int32[ ie_device:CPU - precision:FP32 - params:{'fn': <function TestMapFN.<lambda> at 0x7f66c2c63c70>, 'input_type': tf.int32, 'fn_output_signature': (tf.int32, tf.int32, tf.int32), 'back_prop': True, 'input_names': ['x1', 'x2', 'x3'], 'input_shapes': [[2, 1, 3, 4], [2, 1, 3, 4], [2, 1, 3, 4]]} ]
-tensorflow2_keras_tests/test_tf2_map_fn.py::TestMapFN::test_multiple_inputs_outputs_int32[ ie_device:CPU - precision:FP16 - params:{'fn': <function TestMapFN.<lambda> at 0x7f66c2c63c70>, 'input_type': tf.int32, 'fn_output_signature': (tf.int32, tf.int32, tf.int32), 'back_prop': True, 'input_names': ['x1', 'x2', 'x3'], 'input_shapes': [[2, 1, 3, 4], [2, 1, 3, 4], [2, 1, 3, 4]]} ]
+tensorflow2_keras_tests/test_tf2_map_fn.py::TestMapFN::test_multiple_inputs_outputs_int32[ ie_device:CPU - precision:FP32 - params:{'fn': <function TestMapFN.<lambda> at 0x7f211b56fd00>, 'input_type': tf.int32, 'fn_output_signature': (tf.int32, tf.int32, tf.int32), 'back_prop': True, 'input_names': ['x1', 'x2', 'x3'], 'input_shapes': [[2, 1, 3, 4], [2, 1, 3, 4], [2, 1, 3, 4]]} ]
+tensorflow2_keras_tests/test_tf2_map_fn.py::TestMapFN::test_multiple_inputs_outputs_int32[ ie_device:CPU - precision:FP16 - params:{'fn': <function TestMapFN.<lambda> at 0x7f211b56fd00>, 'input_type': tf.int32, 'fn_output_signature': (tf.int32, tf.int32, tf.int32), 'back_prop': True, 'input_names': ['x1', 'x2', 'x3'], 'input_shapes': [[2, 1, 3, 4], [2, 1, 3, 4], [2, 1, 3, 4]]} ]
```

---------

Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
  • Loading branch information
2 people authored and alvoron committed Apr 29, 2024
1 parent a383e96 commit 74bbaaa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/job_python_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ jobs:
run: |
# requires 'unit_tests' from 'mo'
export PYTHONPATH=${INSTALL_TEST_DIR}/mo
python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml
python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ -n logical -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml
env:
TEST_DEVICE: CPU
TEST_PRECISION: FP16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def _prepare_input(self, inputs_info):
def create_keras_conv_lstm_2d_net(self, params, input_shapes):
# create TensorFlow 2 model with Keras ConvLSTM2D operation
tf.keras.backend.clear_session()

activation = params.get('activation', None)
recurrent_activation = params.get('recurrent_activation', None)

if activation is not None:
params['activation'] = tf.keras.activations.get(activation)
if recurrent_activation is not None:
params['recurrent_activation'] = tf.keras.activations.get(recurrent_activation)


x = tf.keras.Input(shape=input_shapes[0][1:], name="x")
y = tf.keras.layers.ConvLSTM2D(**params)(x)
Expand All @@ -31,21 +40,21 @@ def create_keras_conv_lstm_2d_net(self, params, input_shapes):

test_data_basic = [
dict(params=dict(filters=4, kernel_size=(3, 3), padding='same', return_sequences=False,
activation=tf.nn.swish),
activation="swish"),
input_shapes=[[2, 5, 20, 30, 2]]),
dict(params=dict(filters=6, kernel_size=(2, 3), padding='valid', dilation_rate=3,
recurrent_activation=tf.nn.elu, return_sequences=True, use_bias=True,
recurrent_activation="elu", return_sequences=True, use_bias=True,
data_format="channels_first"),
input_shapes=[[2, 5, 1, 40, 30]]),
dict(params=dict(filters=3, kernel_size=(3, 3), padding='valid', return_sequences=False),
input_shapes=[[2, 5, 20, 30, 1]]),
dict(params=dict(filters=2, kernel_size=(2, 2), padding='same', return_sequences=False, activation=tf.nn.swish),
dict(params=dict(filters=2, kernel_size=(2, 2), padding='same', return_sequences=False, activation="swish"),
input_shapes=[[2, 5, 25, 15, 3]]),
dict(params=dict(filters=3, kernel_size=(3, 3), padding='valid', strides=(2, 2),
return_sequences=True),
input_shapes=[[2, 5, 10, 15, 2]]),
dict(params=dict(filters=5, kernel_size=(2, 2), padding='valid', dilation_rate=3,
activation=tf.nn.relu, return_sequences=False, use_bias=True,
activation="relu", return_sequences=False, use_bias=True,
data_format="channels_last"),
input_shapes=[[2, 5, 18, 17, 1]])
]
Expand Down
44 changes: 34 additions & 10 deletions tests/layer_tests/tensorflow2_keras_tests/test_tf2_map_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@

from common.tf2_layer_test_class import CommonTF2LayerTest

def fn_1(x):
return (x[0] * x[1] + x[2])

def fn_2(x):
return (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2])

def fn_3(x):
return (x[0] * x[1])

def fn_4(x):
return (x[0] * x[1] + 2 * x[2])

def fn_5(x):
return (x[0] * x[1], x[0] + x[1])

def fn_6(x):
return (x[0] * x[1] + x[2], x[0] + x[2] * x[1], 2 * x[2])

def fn_7(x):
return (x[0] * x[1] + x[2])

def fn_8(x):
return (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2])

list_fns = [fn_1, fn_2, fn_3, fn_4, fn_5, fn_6, fn_7, fn_8]

class MapFNLayer(tf.keras.layers.Layer):
def __init__(self, fn, input_type, fn_output_signature, back_prop):
super(MapFNLayer, self).__init__()
self.fn = fn
self.fn = list_fns[fn-1]
self.input_type = input_type
self.fn_output_signature = fn_output_signature
self.back_prop = back_prop
Expand All @@ -20,7 +45,6 @@ def call(self, x):
fn_output_signature=self.fn_output_signature,
back_prop=self.back_prop)


class TestMapFN(CommonTF2LayerTest):
def create_map_fn_net(self, fn, input_type, fn_output_signature, back_prop,
input_names, input_shapes, ir_version):
Expand All @@ -39,10 +63,10 @@ def create_map_fn_net(self, fn, input_type, fn_output_signature, back_prop,
return tf2_net, ref_net

test_basic = [
dict(fn=lambda x: x[0] * x[1] + x[2], input_type=tf.float32,
dict(fn=1, input_type=tf.float32,
fn_output_signature=tf.float32, back_prop=False,
input_names=["x1", "x2", "x3"], input_shapes=[[2, 3, 4], [2, 3, 4], [2, 3, 4]]),
pytest.param(dict(fn=lambda x: (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2]),
pytest.param(dict(fn=2,
input_type=tf.float32,
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
input_names=["x1", "x2", "x3"],
Expand All @@ -59,10 +83,10 @@ def test_basic(self, params, ie_device, precision, ir_version, temp_dir, use_leg
**params)

test_multiple_inputs = [
dict(fn=lambda x: x[0] * x[1], input_type=tf.float32,
dict(fn=3, input_type=tf.float32,
fn_output_signature=tf.float32, back_prop=True,
input_names=["x1", "x2"], input_shapes=[[2, 4], [2, 4]]),
dict(fn=lambda x: x[0] * x[1] + 2 * x[2], input_type=tf.float32,
dict(fn=4, input_type=tf.float32,
fn_output_signature=tf.float32, back_prop=False,
input_names=["x1", "x2", "x3"], input_shapes=[[2, 1, 3, 4],
[2, 1, 3, 4],
Expand All @@ -77,11 +101,11 @@ def test_multiple_inputs(self, params, ie_device, precision, ir_version, temp_di
**params)

test_multiple_outputs = [
pytest.param(dict(fn=lambda x: (x[0] * x[1], x[0] + x[1]), input_type=tf.float32,
pytest.param(dict(fn=5, input_type=tf.float32,
fn_output_signature=(tf.float32, tf.float32), back_prop=True,
input_names=["x1", "x2"], input_shapes=[[2, 4], [2, 4]]),
marks=pytest.mark.xfail(reason="61587")),
pytest.param(dict(fn=lambda x: (x[0] * x[1] + x[2], x[0] + x[2] * x[1], 2 * x[2]),
pytest.param(dict(fn=6,
input_type=tf.float32,
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
input_names=["x1", "x2", "x3"],
Expand All @@ -97,12 +121,12 @@ def test_multiple_outputs(self, params, ie_device, precision, ir_version, temp_d
**params)

test_multiple_inputs_outputs_int32 = [
dict(fn=lambda x: x[0] * x[1] + x[2],
dict(fn=7,
input_type=tf.int32,
fn_output_signature=tf.int32, back_prop=True,
input_names=["x1", "x2", "x3"],
input_shapes=[[2, 1, 3], [2, 1, 3], [2, 1, 3]]),
pytest.param(dict(fn=lambda x: (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2]),
pytest.param(dict(fn=8,
input_type=tf.int32,
fn_output_signature=(tf.int32, tf.int32, tf.int32), back_prop=True,
input_names=["x1", "x2", "x3"],
Expand Down

0 comments on commit 74bbaaa

Please sign in to comment.