Skip to content

Commit

Permalink
Enable parallel execution of TensorFlow Layer 2 python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu-S committed Mar 8, 2024
1 parent e77238b commit 4e41510
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 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
32 changes: 25 additions & 7 deletions tests/layer_tests/tensorflow2_keras_tests/test_tf2_map_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ def call(self, x):
fn_output_signature=self.fn_output_signature,
back_prop=self.back_prop)

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], x[0] + x[1])

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

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

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


class TestMapFN(CommonTF2LayerTest):
def create_map_fn_net(self, fn, input_type, fn_output_signature, back_prop,
Expand All @@ -39,10 +57,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=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=fn_2,
input_type=tf.float32,
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
input_names=["x1", "x2", "x3"],
Expand Down Expand Up @@ -77,11 +95,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=fn_3, 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=fn_4,
input_type=tf.float32,
fn_output_signature=(tf.float32, tf.float32, tf.float32), back_prop=True,
input_names=["x1", "x2", "x3"],
Expand All @@ -97,17 +115,17 @@ 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=fn_5,
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=fn_6,
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]]),
marks=[pytest.mark.xfail(reason="61587"), pytest.mark.precommit_tf_fe])
marks=[pytest.mark.xfail(reason="61587")])
]

@pytest.mark.parametrize("params", test_multiple_inputs_outputs_int32)
Expand Down

0 comments on commit 4e41510

Please sign in to comment.