[TFL FE] GELU implementation (#23669)
Add Gelu and corresponding layer test support. --------- Signed-off-by: Keyon Jie <yang.jie@linux.intel.com> Co-authored-by: Georgy Krivoruchko <georgy.krivoruchko@intel.com> Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com> Co-authored-by: Evgenya Nugmanova <evgeniia.nugmanova@intel.com>
This commit is contained in:
parent
52004d9f47
commit
6f599c05dd
|
|
@ -84,6 +84,7 @@ OP_CONVERTER(translate_gather_op);
|
|||
OP_CONVERTER(translate_gather_v2_op);
|
||||
OP_CONVERTER(translate_gather_nd_op);
|
||||
OP_CONVERTER(translate_gather_tree_op);
|
||||
OP_CONVERTER(translate_gelu_op);
|
||||
OP_CONVERTER(translate_identity_op);
|
||||
OP_CONVERTER(translate_identity_n_op);
|
||||
OP_CONVERTER(translate_ifft_op);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2024 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/gelu.hpp"
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ov;
|
||||
using namespace ov::op;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
namespace tensorflow {
|
||||
namespace op {
|
||||
|
||||
OutputVector translate_gelu_op(const NodeContext& node) {
|
||||
default_op_checks(node, 1, {"GELU"});
|
||||
auto input = node.get_input(0);
|
||||
auto approximate = node.get_attribute<bool>("approximate");
|
||||
const auto mode = (approximate == true) ? ov::op::GeluApproximationMode::TANH : ov::op::GeluApproximationMode::ERF;
|
||||
auto res = make_shared<ov::op::v7::Gelu>(input, mode);
|
||||
set_node_name(node.get_name(), res);
|
||||
return res->outputs();
|
||||
};
|
||||
|
||||
} // namespace op
|
||||
} // namespace tensorflow
|
||||
} // namespace frontend
|
||||
} // namespace ov
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2024 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "common_op_table.hpp"
|
||||
#include "op_translation_utils.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
namespace tensorflow_lite {
|
||||
namespace op {
|
||||
|
||||
OutputVector gelu(const ov::frontend::tensorflow_lite::NodeContext& node) {
|
||||
const auto& decoder = get_decoder(node);
|
||||
std::map<std::string, ov::Any> attrs{
|
||||
{"approximate", decoder->get_attribute(&tflite::GeluOptions::approximate)},
|
||||
};
|
||||
return attribute_helper(node, attrs, ov::frontend::tensorflow::op::translate_gelu_op);
|
||||
}
|
||||
|
||||
} // namespace op
|
||||
} // namespace tensorflow_lite
|
||||
} // namespace frontend
|
||||
} // namespace ov
|
||||
|
|
@ -86,7 +86,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
|
|||
{"FULLY_CONNECTED", DEQUANTIZE_INPUTS(fully_connected)},
|
||||
{"GATHER", DEQUANTIZE_INPUTS(gather)},
|
||||
{"GATHER_ND", DEQUANTIZE_INPUTS(translate_gather_nd_op)},
|
||||
// GELU
|
||||
{"GELU", DEQUANTIZE_INPUTS(gelu)},
|
||||
{"GREATER", translate_binary<opset8::Greater>},
|
||||
{"GREATER_EQUAL", translate_binary<opset8::GreaterEqual>},
|
||||
{"HARD_SWISH", translate_unary<opset8::HSwish>},
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ TFL_OP_CONVERTER(depthwise_conv2d);
|
|||
TFL_OP_CONVERTER(dequantize);
|
||||
TFL_OP_CONVERTER(fully_connected);
|
||||
TFL_OP_CONVERTER(gather);
|
||||
TFL_OP_CONVERTER(gelu);
|
||||
TFL_OP_CONVERTER(l2_normalization);
|
||||
TFL_OP_CONVERTER(leaky_relu);
|
||||
TFL_OP_CONVERTER(max_pool_2d);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class TestKerasActivation(CommonTF2LayerTest):
|
|||
# pytest-xdist can't execute the tests in parallel because workers can't compare tests scopes before run
|
||||
# tf.nn.<activation> operation have no "==" operation to be compared
|
||||
"elu": tf.nn.elu,
|
||||
"gelu": tf.nn.gelu,
|
||||
"relu": tf.nn.relu,
|
||||
"sigmoid": tf.nn.sigmoid,
|
||||
"softmax": tf.nn.softmax,
|
||||
|
|
@ -40,6 +41,8 @@ class TestKerasActivation(CommonTF2LayerTest):
|
|||
test_data_float32 = [
|
||||
dict(activation_func="elu", input_names=["x1"], input_shapes=[[5, 4]],
|
||||
input_type=tf.float32),
|
||||
dict(activation_func="gelu", input_names=["x1"], input_shapes=[[5, 4]],
|
||||
input_type=tf.float32),
|
||||
dict(activation_func="relu", input_names=["x1"], input_shapes=[[5, 4, 8]],
|
||||
input_type=tf.float32),
|
||||
dict(activation_func="sigmoid", input_names=["x1"], input_shapes=[[5, 4, 8, 3]],
|
||||
|
|
|
|||
Loading…
Reference in New Issue