Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 5th No.97】add paddle tanh_shrink op #20067

Merged
merged 18 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/frontends/paddle/src/op/tanh_shrink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "default_opset.hpp"
#include "openvino/frontend/paddle/node_context.hpp"

namespace ov {
namespace frontend {
namespace paddle {
namespace op {
NamedOutputs tanh_shrink(const NodeContext& node) {
const auto x = node.get_input("X");
const auto tanh = std::make_shared<default_opset::Tanh>(x);
return node.default_single_output_mapping({std::make_shared<default_opset::Subtract>(x, tanh)}, {"Out"});
}

} // namespace op
} // namespace paddle
} // namespace frontend
} // namespace ov
2 changes: 2 additions & 0 deletions src/frontends/paddle/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ OP_CONVERTER(strided_slice);
OP_CONVERTER(sum);
OP_CONVERTER(swish);
OP_CONVERTER(tanh);
OP_CONVERTER(tanh_shrink);
OP_CONVERTER(tensor_array_to_tensor);
OP_CONVERTER(tile);
OP_CONVERTER(top_k_v2);
Expand Down Expand Up @@ -244,6 +245,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
{"swish", op::swish},
{"sync_batch_norm", op::batch_norm},
{"tanh", op::tanh},
{"tanh_shrink", op::tanh_shrink},
{"tensor_array_to_tensor", op::tensor_array_to_tensor},
{"tile", op::tile},
{"top_k_v2", op::top_k_v2},
Expand Down
2 changes: 2 additions & 0 deletions src/frontends/paddle/tests/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ static const std::vector<std::string> models{
std::string("swish_default_params"),
std::string("swish_beta"),
std::string("tanh"),
std::string("tanh_shrink_1"),
std::string("tanh_shrink_2"),
std::string("tile_repeat_times_tensor"),
std::string("tile_list_float32"),
std::string("tile_list_int32"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

#
# tanh_shrink paddle model generator
#
import numpy as np
import sys
from save_model import saveModel


def tanh_shrink(name: str, x):
import paddle

paddle.enable_static()

with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()):
node_x = paddle.static.data(name='x', shape=x.shape, dtype=x.dtype)
out = paddle.nn.functional.tanhshrink(node_x)

cpu = paddle.static.cpu_places(1)
exe = paddle.static.Executor(cpu[0])
# startup program will call initializer to initialize the parameters.
exe.run(paddle.static.default_startup_program())

outs = exe.run(feed={'x': x}, fetch_list=[out])

saveModel(
name,
exe,
feedkeys=['x'],
fetchlist=[out],
inputs=[x],
outputs=[outs[0]],
target_dir=sys.argv[1],
)

return outs[0]


def main():
data = np.random.uniform(10, 20, [2, 3, 4]).astype(np.float32)
tanh_shrink("tanh_shrink_1", data)

data = np.random.uniform(-10, 20, [4, 3, 2]).astype(np.float32)
tanh_shrink("tanh_shrink_2", data)

if __name__ == "__main__":
main()


Loading