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

【PaddlePaddle Hackathon 4】Add paddle op mapper silu #15874

Merged
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
20 changes: 20 additions & 0 deletions src/frontends/paddle/src/op/silu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 silu(const NodeContext& node) {
const auto x = node.get_input("X");
return node.default_single_output_mapping({std::make_shared<default_opset::Swish>(x)}, {"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 @@ -95,6 +95,7 @@ OP_CONVERTER(softmax);
OP_CONVERTER(softplus);
OP_CONVERTER(softshrink);
OP_CONVERTER(sigmoid);
OP_CONVERTER(silu);
OP_CONVERTER(split);
OP_CONVERTER(sqrt);
OP_CONVERTER(squeeze);
Expand Down Expand Up @@ -212,6 +213,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
{"softplus", op::softplus},
{"softshrink", op::softshrink},
{"sigmoid", op::sigmoid},
{"silu", op::silu},
{"split", op::split},
{"sqrt", op::sqrt},
{"squeeze2", op::squeeze},
Expand Down
8 changes: 8 additions & 0 deletions src/frontends/paddle/tests/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ static const std::vector<std::string> models{
std::string("scale_tensor_bias_before"),
std::string("shape"),
std::string("sigmoid"),
std::string("silu_static_test1"),
std::string("silu_static_test2"),
std::string("silu_static_test3"),
std::string("silu_static_test4"),
std::string("silu_dynamic_test1"),
std::string("silu_dynamic_test2"),
std::string("silu_dynamic_test3"),
std::string("silu_dynamic_test4"),
std::string("slice"),
std::string("slice_1d"),
std::string("slice_decrease_axis/slice_decrease_axis.pdmodel"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# silu paddle model generator
#
import numpy as np
from save_model import saveModel
import paddle as pdpd
import sys


def silu(name: str, x, data_type, use_static=True):
pdpd.enable_static()

with pdpd.static.program_guard(pdpd.static.Program(), pdpd.static.Program()):
if use_static:
node_x = pdpd.static.data(
name='input_x', shape=x.shape, dtype=data_type)
else:
node_x = pdpd.static.data(
name='input_x', shape=[1, 1, -1, -1], dtype=data_type)
out = pdpd.nn.functional.silu(x=node_x, name='silu')

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

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

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

return outs[0]


def main():
xczhai marked this conversation as resolved.
Show resolved Hide resolved
x1 = np.random.randn(2,).astype('float32')
silu("silu_static_test1", x1, 'float32', True)

x2 = np.random.randn(2, 3).astype('float32')
silu("silu_static_test2", x2, 'float32', True)

x3 = np.random.randn(2, 3, 4).astype('float32')
silu("silu_static_test3", x3, 'float32', True)

x4 = np.random.randn(2, 3, 4, 5).astype('float32')
silu("silu_static_test4", x4, 'float32', True)

x5 = np.random.randn(1, 1, 32, 32).astype('float32')
silu("silu_dynamic_test1", x5, 'float32', False)

x6 = np.random.randn(1, 1, 64, 64).astype('float32')
silu("silu_dynamic_test2", x6, 'float32', False)

x7 = np.random.randn(1, 1, 128, 128).astype('float32')
silu("silu_dynamic_test3", x7, 'float32', False)

x8 = np.random.randn(1, 1, 256, 256).astype('float32')
silu("silu_dynamic_test4", x8, 'float32', False)


if __name__ == "__main__":
main()