OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TF FE] Test Swish function in precommit (#30213)
Roman Kazantsev6b26a1120334
diff --git a/tests/layer_tests/tensorflow_tests/test_tf_Swish.py b/tests/layer_tests/tensorflow_tests/test_tf_Swish.pyindex 89766443f83..f0868220267 100644--- a/tests/layer_tests/tensorflow_tests/test_tf_Swish.py+++ b/tests/layer_tests/tensorflow_tests/test_tf_Swish.py@@ -1,21 +1,32 @@# Copyright (C) 2018-2025 Intel Corporation# SPDX-License-Identifier: Apache-2.0+import numpy as npimport pytest+import tensorflow as tffrom common.tf_layer_test_class import CommonTFLayerTest+rng = np.random.default_rng(325)-class TestSwish(CommonTFLayerTest):- def create_swish_net(self, shape, ir_version, use_legacy_frontend):- import tensorflow as tf+class TestSwish(CommonTFLayerTest):+ def _prepare_input(self, inputs_info):+ assert 'x:0' in inputs_info, "Test error: inputs_info must contain `x`"+ x_shape = inputs_info['x:0']+ inputs_data = {}+ inputs_data['x:0'] = rng.uniform(-5.0, 5.0, x_shape).astype(self.input_type)+ return inputs_data++ def create_swish_net(self, input_type, input_shape):+ self.input_type = input_type+ self.input_shape = input_shapetf.compat.v1.reset_default_graph()-# Create the graph and modelwith tf.compat.v1.Session() as sess:- input = tf.compat.v1.placeholder(tf.float32, shape, 'Input')-- tf.compat.v1.nn.swish(input)+ x = tf.compat.v1.placeholder(input_type, input_shape, 'x')+ # increment helps to avoid IdentityN fused to Parameter+ swish = tf.compat.v1.nn.swish(x + 1)+ tf.identity(swish, name='swish')tf.compat.v1.global_variables_initializer()tf_net = sess.graph_def@@ -23,31 +34,16 @@ class TestSwish(CommonTFLayerTest):ref_net = Nonereturn tf_net, ref_net- test_data_precommit = [- pytest.param(dict(shape=[1, 3, 50, 100, 224]),- marks=pytest.mark.skip(reason="Skipped until fixed"))- ]-- @pytest.mark.parametrize("params", test_data_precommit)+ @pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64])+ @pytest.mark.parametrize("input_shape", [[], [2], [2, 3], [2, 3, 4]])@pytest.mark.precommit@pytest.mark.nightly- def test_swish_precommit(self, params, ie_device, precision, ir_version, temp_dir,- use_legacy_frontend):- self._test(*self.create_swish_net(**params, ir_version=ir_version,- use_legacy_frontend=use_legacy_frontend),- ie_device, precision, ir_version, temp_dir=temp_dir,- use_legacy_frontend=use_legacy_frontend)-- test_data = [dict(shape=[1]),- dict(shape=[1, 224]),- dict(shape=[1, 3, 224]),- dict(shape=[1, 3, 100, 224]),- dict(shape=[1, 3, 50, 100, 224])]-- @pytest.mark.parametrize("params", test_data)- @pytest.mark.nightly- def test_swish(self, params, ie_device, precision, ir_version, temp_dir, use_legacy_frontend):- self._test(*self.create_swish_net(**params, ir_version=ir_version,- use_legacy_frontend=use_legacy_frontend),+ def test_swish(self, input_type, input_shape,+ ie_device, precision, ir_version, temp_dir,+ use_legacy_frontend):+ custom_eps = None+ if input_type == np.float16:+ custom_eps = 3 * 1e-3+ self._test(*self.create_swish_net(input_type, input_shape),ie_device, precision, ir_version, temp_dir=temp_dir,- use_legacy_frontend=use_legacy_frontend)+ use_legacy_frontend=use_legacy_frontend, custom_eps=custom_eps)