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 silu for paddle #16007

Closed
wants to merge 2 commits into from
Closed
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");
const auto beta_node = default_opset::Constant::create(element::f32, Shape{}, {1.0f});
return node.default_single_output_mapping({std::make_shared<default_opset::Swish>(x, beta_node)}, {"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 @@ -90,6 +90,7 @@ OP_CONVERTER(roi_align);
OP_CONVERTER(scale);
OP_CONVERTER(select_input);
OP_CONVERTER(shape);
OP_CONVERTER(silu);
OP_CONVERTER(slice);
OP_CONVERTER(softmax);
OP_CONVERTER(softplus);
Expand Down Expand Up @@ -206,6 +207,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
{"scale", op::scale},
{"select_input", op::select_input},
{"shape", op::shape},
{"silu", op::silu},
{"slice", op::slice},
{"softmax", op::softmax},
{"softplus", op::softplus},
Expand Down
1 change: 1 addition & 0 deletions src/frontends/paddle/tests/op_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ static const std::vector<std::string> models{
std::string("scale_tensor_bias_before"),
std::string("shape"),
std::string("sigmoid"),
std::string("silu"),
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,39 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

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

def silu(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='float32')
silu_f = paddle.nn.Silu()
out = silu_f(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.random([2, 3, 4]).astype('float32')
silu("silu", data)


if __name__ == "__main__":
main()