Skip to content

Commit b520763

Browse files
Pranshu-Srkazants
andauthored
[TF FE] Enable parallel execution of TensorFlow Layer 2 python tests (openvinotoolkit#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>
1 parent 113975f commit b520763

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

.github/workflows/job_python_unit_tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ jobs:
280280
run: |
281281
# requires 'unit_tests' from 'mo'
282282
export PYTHONPATH=${INSTALL_TEST_DIR}/mo
283-
python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml
283+
python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/tensorflow2_keras_tests/ -n logical -m precommit_tf_fe --junitxml=${INSTALL_TEST_DIR}/TEST-tf2_fe.xml
284284
env:
285285
TEST_DEVICE: CPU
286286
TEST_PRECISION: FP16

tests/layer_tests/tensorflow2_keras_tests/test_tf2_keras_conv_lstm_2d.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def _prepare_input(self, inputs_info):
2222
def create_keras_conv_lstm_2d_net(self, params, input_shapes):
2323
# create TensorFlow 2 model with Keras ConvLSTM2D operation
2424
tf.keras.backend.clear_session()
25+
26+
activation = params.get('activation', None)
27+
recurrent_activation = params.get('recurrent_activation', None)
28+
29+
if activation is not None:
30+
params['activation'] = tf.keras.activations.get(activation)
31+
if recurrent_activation is not None:
32+
params['recurrent_activation'] = tf.keras.activations.get(recurrent_activation)
33+
2534

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

3241
test_data_basic = [
3342
dict(params=dict(filters=4, kernel_size=(3, 3), padding='same', return_sequences=False,
34-
activation=tf.nn.swish),
43+
activation="swish"),
3544
input_shapes=[[2, 5, 20, 30, 2]]),
3645
dict(params=dict(filters=6, kernel_size=(2, 3), padding='valid', dilation_rate=3,
37-
recurrent_activation=tf.nn.elu, return_sequences=True, use_bias=True,
46+
recurrent_activation="elu", return_sequences=True, use_bias=True,
3847
data_format="channels_first"),
3948
input_shapes=[[2, 5, 1, 40, 30]]),
4049
dict(params=dict(filters=3, kernel_size=(3, 3), padding='valid', return_sequences=False),
4150
input_shapes=[[2, 5, 20, 30, 1]]),
42-
dict(params=dict(filters=2, kernel_size=(2, 2), padding='same', return_sequences=False, activation=tf.nn.swish),
51+
dict(params=dict(filters=2, kernel_size=(2, 2), padding='same', return_sequences=False, activation="swish"),
4352
input_shapes=[[2, 5, 25, 15, 3]]),
4453
dict(params=dict(filters=3, kernel_size=(3, 3), padding='valid', strides=(2, 2),
4554
return_sequences=True),
4655
input_shapes=[[2, 5, 10, 15, 2]]),
4756
dict(params=dict(filters=5, kernel_size=(2, 2), padding='valid', dilation_rate=3,
48-
activation=tf.nn.relu, return_sequences=False, use_bias=True,
57+
activation="relu", return_sequences=False, use_bias=True,
4958
data_format="channels_last"),
5059
input_shapes=[[2, 5, 18, 17, 1]])
5160
]

tests/layer_tests/tensorflow2_keras_tests/test_tf2_map_fn.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,36 @@
66

77
from common.tf2_layer_test_class import CommonTF2LayerTest
88

9+
def fn_1(x):
10+
return (x[0] * x[1] + x[2])
11+
12+
def fn_2(x):
13+
return (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2])
14+
15+
def fn_3(x):
16+
return (x[0] * x[1])
17+
18+
def fn_4(x):
19+
return (x[0] * x[1] + 2 * x[2])
20+
21+
def fn_5(x):
22+
return (x[0] * x[1], x[0] + x[1])
23+
24+
def fn_6(x):
25+
return (x[0] * x[1] + x[2], x[0] + x[2] * x[1], 2 * x[2])
26+
27+
def fn_7(x):
28+
return (x[0] * x[1] + x[2])
29+
30+
def fn_8(x):
31+
return (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2])
32+
33+
list_fns = [fn_1, fn_2, fn_3, fn_4, fn_5, fn_6, fn_7, fn_8]
934

1035
class MapFNLayer(tf.keras.layers.Layer):
1136
def __init__(self, fn, input_type, fn_output_signature, back_prop):
1237
super(MapFNLayer, self).__init__()
13-
self.fn = fn
38+
self.fn = list_fns[fn-1]
1439
self.input_type = input_type
1540
self.fn_output_signature = fn_output_signature
1641
self.back_prop = back_prop
@@ -20,7 +45,6 @@ def call(self, x):
2045
fn_output_signature=self.fn_output_signature,
2146
back_prop=self.back_prop)
2247

23-
2448
class TestMapFN(CommonTF2LayerTest):
2549
def create_map_fn_net(self, fn, input_type, fn_output_signature, back_prop,
2650
input_names, input_shapes, ir_version):
@@ -39,10 +63,10 @@ def create_map_fn_net(self, fn, input_type, fn_output_signature, back_prop,
3963
return tf2_net, ref_net
4064

4165
test_basic = [
42-
dict(fn=lambda x: x[0] * x[1] + x[2], input_type=tf.float32,
66+
dict(fn=1, input_type=tf.float32,
4367
fn_output_signature=tf.float32, back_prop=False,
4468
input_names=["x1", "x2", "x3"], input_shapes=[[2, 3, 4], [2, 3, 4], [2, 3, 4]]),
45-
pytest.param(dict(fn=lambda x: (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2]),
69+
pytest.param(dict(fn=2,
4670
input_type=tf.float32,
4771
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
4872
input_names=["x1", "x2", "x3"],
@@ -59,10 +83,10 @@ def test_basic(self, params, ie_device, precision, ir_version, temp_dir, use_leg
5983
**params)
6084

6185
test_multiple_inputs = [
62-
dict(fn=lambda x: x[0] * x[1], input_type=tf.float32,
86+
dict(fn=3, input_type=tf.float32,
6387
fn_output_signature=tf.float32, back_prop=True,
6488
input_names=["x1", "x2"], input_shapes=[[2, 4], [2, 4]]),
65-
dict(fn=lambda x: x[0] * x[1] + 2 * x[2], input_type=tf.float32,
89+
dict(fn=4, input_type=tf.float32,
6690
fn_output_signature=tf.float32, back_prop=False,
6791
input_names=["x1", "x2", "x3"], input_shapes=[[2, 1, 3, 4],
6892
[2, 1, 3, 4],
@@ -77,11 +101,11 @@ def test_multiple_inputs(self, params, ie_device, precision, ir_version, temp_di
77101
**params)
78102

79103
test_multiple_outputs = [
80-
pytest.param(dict(fn=lambda x: (x[0] * x[1], x[0] + x[1]), input_type=tf.float32,
104+
pytest.param(dict(fn=5, input_type=tf.float32,
81105
fn_output_signature=(tf.float32, tf.float32), back_prop=True,
82106
input_names=["x1", "x2"], input_shapes=[[2, 4], [2, 4]]),
83107
marks=pytest.mark.xfail(reason="61587")),
84-
pytest.param(dict(fn=lambda x: (x[0] * x[1] + x[2], x[0] + x[2] * x[1], 2 * x[2]),
108+
pytest.param(dict(fn=6,
85109
input_type=tf.float32,
86110
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
87111
input_names=["x1", "x2", "x3"],
@@ -97,12 +121,12 @@ def test_multiple_outputs(self, params, ie_device, precision, ir_version, temp_d
97121
**params)
98122

99123
test_multiple_inputs_outputs_int32 = [
100-
dict(fn=lambda x: x[0] * x[1] + x[2],
124+
dict(fn=7,
101125
input_type=tf.int32,
102126
fn_output_signature=tf.int32, back_prop=True,
103127
input_names=["x1", "x2", "x3"],
104128
input_shapes=[[2, 1, 3], [2, 1, 3], [2, 1, 3]]),
105-
pytest.param(dict(fn=lambda x: (x[0] + x[1] + x[2], x[0] - x[2] + x[1], 2 + x[2]),
129+
pytest.param(dict(fn=8,
106130
input_type=tf.int32,
107131
fn_output_signature=(tf.int32, tf.int32, tf.int32), back_prop=True,
108132
input_names=["x1", "x2", "x3"],

0 commit comments

Comments
 (0)