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] Support Erfc operation (#29419)
Roman Kazantsev560b02df0dfa
diff --git a/src/frontends/common_translators/include/common_translators.hpp b/src/frontends/common_translators/include/common_translators.hppindex 636c73c7f2e..7f791974938 100644--- a/src/frontends/common_translators/include/common_translators.hpp+++ b/src/frontends/common_translators/include/common_translators.hpp@@ -18,8 +18,10 @@ COMMON_OP_CONVERTER(translate_imag);COMMON_OP_CONVERTER(translate_atan2);COMMON_OP_CONVERTER(translate_angle);+COMMON_OP_CONVERTER(translate_erfc);OutputVector translate_atan2_util(const NodeContext& context, const Output<Node>& lhs, const Output<Node>& rhs);+OutputVector translate_erfc_util(const NodeContext& context, const Output<Node>& data);} // namespace common_translators} // namespace frontenddiff --git a/src/frontends/common_translators/src/op/erfc.cpp b/src/frontends/common_translators/src/op/erfc.cppnew file mode 100644index 00000000000..8ab2b641cba--- /dev/null+++ b/src/frontends/common_translators/src/op/erfc.cpp@@ -0,0 +1,33 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_translators.hpp"+#include "openvino/op/erf.hpp"+#include "openvino/op/subtract.hpp"+#include "utils.hpp"++namespace ov {+namespace frontend {+namespace common_translators {++using namespace ov::op;+using namespace std;++OutputVector translate_erfc_util(const NodeContext& context, const Output<Node>& data) {+ auto one_const = create_same_type_const_scalar<int32_t>(data, 1);+ auto erf = context.mark_node(make_shared<v0::Erf>(data));+ auto erfc = context.mark_node(make_shared<v1::Subtract>(one_const, erf));+ return {erfc};+}++OutputVector translate_erfc(const NodeContext& context) {+ num_inputs_check(context, 1, 1);+ auto data = context.get_input(0);++ return translate_erfc_util(context, data);+}++} // namespace common_translators+} // namespace frontend+} // namespace ovdiff --git a/src/frontends/pytorch/src/op/erfc.cpp b/src/frontends/pytorch/src/op/erfc.cppindex ea89a2c6651..64e0fff2483 100644--- a/src/frontends/pytorch/src/op/erfc.cpp+++ b/src/frontends/pytorch/src/op/erfc.cpp@@ -2,10 +2,8 @@// SPDX-License-Identifier: Apache-2.0//+#include "common_translators.hpp"#include "openvino/frontend/pytorch/node_context.hpp"-#include "openvino/op/convert.hpp"-#include "openvino/op/erf.hpp"-#include "openvino/op/subtract.hpp"#include "utils.hpp"using namespace std;@@ -22,15 +20,7 @@ OutputVector translate_erfc(const NodeContext& context) {num_inputs_check(context, 1, 2);auto x = get_input_with_floating_type(context, 0);- // create 'ones' to use to calculate complementary of Erf output- auto ones = context.mark_node(make_shared<v0::Constant>(element::f32, Shape{}, 1.0f))->output(0);-- ones = context.mark_node(std::make_shared<v1::ConvertLike>(ones, x));-- // apply Erf to the input tensor 'x'- auto y = context.mark_node(make_shared<v0::Erf>(x));-- y = context.mark_node(make_shared<v1::Subtract>(ones, y));+ auto y = common_translators::translate_erfc_util(context, x)[0];if (!context.input_is_none(1)) {context.mutate_input(1, y);diff --git a/src/frontends/tensorflow/docs/supported_ops.md b/src/frontends/tensorflow/docs/supported_ops.mdindex bd6e03cfdab..c9534c8aee0 100644--- a/src/frontends/tensorflow/docs/supported_ops.md+++ b/src/frontends/tensorflow/docs/supported_ops.md@@ -375,7 +375,7 @@ A "supported operation" is one that TensorFlow Frontend can convert to the OpenV| Enter | YES | || Equal | YES | || Erf | YES | |-| Erfc | NO | |+| Erfc | YES | || Erfinv | NO | || EuclideanNorm | YES | || Exit | YES | |diff --git a/src/frontends/tensorflow/src/op_table.cpp b/src/frontends/tensorflow/src/op_table.cppindex bcdfbb37927..56e0a7d7612 100644--- a/src/frontends/tensorflow/src/op_table.cpp+++ b/src/frontends/tensorflow/src/op_table.cpp@@ -144,6 +144,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops() {{"Cos", CreatorFunction(translate_unary_op<v0::Cos>)},{"Cosh", CreatorFunction(translate_unary_op<v0::Cosh>)},{"Erf", CreatorFunction(translate_unary_op<v0::Erf>)},+ {"Erfc", CreatorFunction(translate_erfc_op)},{"Exp", CreatorFunction(translate_unary_op<v0::Exp>)},{"Floor", CreatorFunction(translate_unary_op<v0::Floor>)},{"Invert", CreatorFunction(translate_unary_op<v13::BitwiseNot>)},diff --git a/src/frontends/tensorflow_common/include/common_op_table.hpp b/src/frontends/tensorflow_common/include/common_op_table.hppindex c4a36e30119..6fc06835318 100644--- a/src/frontends/tensorflow_common/include/common_op_table.hpp+++ b/src/frontends/tensorflow_common/include/common_op_table.hpp@@ -74,6 +74,7 @@ OP_CONVERTER(translate_mul_op);OP_CONVERTER(translate_dynamic_partition_op);OP_CONVERTER(translate_einsum_op);OP_CONVERTER(translate_elu_op);+OP_CONVERTER(translate_erfc_op);OP_CONVERTER(translate_expm1_op);OP_CONVERTER(translate_expand_dims_op);OP_CONVERTER(translate_extract_image_patches_op);diff --git a/src/frontends/tensorflow_common/src/op/erfc.cpp b/src/frontends/tensorflow_common/src/op/erfc.cppnew file mode 100644index 00000000000..8f5b124bc63--- /dev/null+++ b/src/frontends/tensorflow_common/src/op/erfc.cpp@@ -0,0 +1,27 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_op_table.hpp"+#include "common_translators.hpp"++using namespace std;+using namespace ov;+using namespace ov::op;++namespace ov {+namespace frontend {+namespace tensorflow {+namespace op {++OutputVector translate_erfc_op(const NodeContext& node) {+ default_op_checks(node, 1, {"Erfc"});+ auto res = common_translators::translate_erfc(node);++ set_node_name(node.get_name(), res[0].get_node_shared_ptr());+ return res;+}+} // namespace op+} // namespace tensorflow+} // namespace frontend+} // namespace ovdiff --git a/tests/layer_tests/tensorflow_tests/test_tf_Erfc.py b/tests/layer_tests/tensorflow_tests/test_tf_Erfc.pynew file mode 100644index 00000000000..9b9ce48e013--- /dev/null+++ b/tests/layer_tests/tensorflow_tests/test_tf_Erfc.py@@ -0,0 +1,42 @@+# Copyright (C) 2018-2025 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import numpy as np+import pytest+import tensorflow as tf+from common.tf_layer_test_class import CommonTFLayerTest++rng = np.random.default_rng(3453466)+++class TestAddTypes(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(-3.0, 3.0, x_shape).astype(self.input_type)+ return inputs_data++ def create_erfc_net(self, input_shape, input_type):+ self.input_type = input_type+ tf.compat.v1.reset_default_graph()+ # Create the graph and model+ with tf.compat.v1.Session() as sess:+ x = tf.compat.v1.placeholder(input_type, input_shape, 'x')+ tf.raw_ops.Erfc(x=x)+ tf.compat.v1.global_variables_initializer()++ tf_net = sess.graph_def++ return tf_net, None++ @pytest.mark.parametrize("input_shape", [[], [2], [3, 4], [3, 2, 1, 4]])+ @pytest.mark.parametrize("input_type", [np.float16, np.float32, np.float64])+ @pytest.mark.precommit+ @pytest.mark.nightly+ def test_erfc(self, input_shape, input_type,+ ie_device, precision, ir_version, temp_dir,+ use_legacy_frontend):+ self._test(*self.create_erfc_net(input_shape, input_type),+ ie_device, precision, ir_version, temp_dir=temp_dir,+ use_legacy_frontend=use_legacy_frontend)