Skip to content

Commit

Permalink
enable sin/cos && fix top_k_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
xczhai committed Aug 28, 2023
1 parent e7b815a commit b9be789
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/frontends/paddle/src/op/cos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 cos(const NodeContext& node) {
return node.default_single_output_mapping({std::make_shared<default_opset::Cos>(node.get_input("X"))}, {"Out"});
}

} // namespace op
} // namespace paddle
} // namespace frontend
} // namespace ov
19 changes: 19 additions & 0 deletions src/frontends/paddle/src/op/sin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 sin(const NodeContext& node) {
return node.default_single_output_mapping({std::make_shared<default_opset::Sin>(node.get_input("X"))}, {"Out"});
}

} // namespace op
} // namespace paddle
} // namespace frontend
} // namespace ov
2 changes: 1 addition & 1 deletion src/frontends/paddle/src/op/top_k_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NamedOutputs top_k_v2(const NodeContext& node) {
std::string sort_type = sorted ? "value" : "none";
std::string mode = largest ? "max" : "min";

auto node_topk = std::make_shared<default_opset::TopK>(x, k_expected_node, axis, mode, sort_type);
auto node_topk = std::make_shared<default_opset::TopK>(x, k_expected_node, axis, mode, sort_type, element::i64);

NamedOutputs named_outputs;
named_outputs["Out"] = OutputVector{node_topk->output(0)};
Expand Down
4 changes: 4 additions & 0 deletions src/frontends/paddle/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OP_CONVERTER(concat);
OP_CONVERTER(conditional_block);
OP_CONVERTER(conv2d);
OP_CONVERTER(conv2d_transpose);
OP_CONVERTER(cos);
OP_CONVERTER(cumsum);
OP_CONVERTER(deformable_conv);
OP_CONVERTER(dequantize_linear);
Expand Down Expand Up @@ -100,6 +101,7 @@ OP_CONVERTER(shape);
OP_CONVERTER(share_data);
OP_CONVERTER(sigmoid);
OP_CONVERTER(silu);
OP_CONVERTER(sin);
OP_CONVERTER(slice);
OP_CONVERTER(softmax);
OP_CONVERTER(softplus);
Expand Down Expand Up @@ -142,6 +144,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
{"conditional_block", op::conditional_block},
{"conv2d", op::conv2d},
{"conv2d_transpose", op::conv2d_transpose},
{"cos", op::cos},
{"cumsum", op::cumsum},
{"deformable_conv", op::deformable_conv},
{"deformable_conv_v1", op::deformable_conv},
Expand Down Expand Up @@ -226,6 +229,7 @@ std::map<std::string, CreatorFunction> get_supported_ops() {
{"share_data", op::share_data},
{"sigmoid", op::sigmoid},
{"silu", op::silu},
{"sin", op::sin},
{"slice", op::slice},
{"softmax", op::softmax},
{"softplus", op::softplus},
Expand Down
3 changes: 2 additions & 1 deletion src/frontends/paddle/tests/convert_unsupported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "common_test_utils/ngraph_test_utils.hpp"
#include "paddle_utils.hpp"
#include "utils.hpp"
#include "openvino/opsets/opset6.hpp"

using namespace ngraph;
using namespace ov::frontend;
Expand All @@ -32,7 +33,7 @@ TEST(FrontEndConvertModelTest, test_unsupported_op) {

for (auto& node : function->get_ordered_ops()) {
if (node->get_friendly_name() == "rxyz_0.tmp_0") {
function->replace_node(node, std::make_shared<opset6::Relu>(node->input(0).get_source_output()));
function->replace_node(node, std::make_shared<ov::opset6::Relu>(node->input(0).get_source_output()));
}
}
ASSERT_NO_THROW(frontEnd->convert(function));
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 @@ -111,6 +111,7 @@ static const std::vector<std::string> models{
std::string("conv2d_transpose_strides_padding/conv2d_transpose_strides_padding.pdmodel"),
std::string("conv2d_transpose_VALID_padding/conv2d_transpose_VALID_padding.pdmodel"),
std::string("conv2d_VALID_padding/conv2d_VALID_padding.pdmodel"),
std::string("cos"),
std::string("cumsum"),
std::string("cumsum_i32"),
std::string("cumsum_i64"),
Expand Down Expand Up @@ -493,6 +494,7 @@ static const std::vector<std::string> models{
std::string("silu_dynamic_test2"),
std::string("silu_dynamic_test3"),
std::string("silu_dynamic_test4"),
std::string("sin"),
std::string("slice"),
std::string("slice_1d"),
std::string("slice_decrease_axis/slice_decrease_axis.pdmodel"),
Expand Down
40 changes: 40 additions & 0 deletions src/frontends/paddle/tests/test_models/gen_scripts/generate_cos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

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

data_type = 'float32'

def cos(name:str, x):
paddle.enable_static()

with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()):
data = paddle.static.data(name='x', shape=x.shape, dtype = data_type)
out = paddle.sin(data)

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():
x = np.random.uniform(-1000,1000, (8, 24, 32)).astype(data_type)

cos("cos", x)

if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions src/frontends/paddle/tests/test_models/gen_scripts/generate_sin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

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

data_type = 'float32'

def sin(name:str, x):
paddle.enable_static()

with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()):
data = paddle.static.data(name='x', shape=x.shape, dtype = data_type)
out = paddle.sin(data)

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():
x = np.random.uniform(-1000,1000, (8, 24, 32)).astype(data_type)

sin("sin", x)

if __name__ == "__main__":
main()

0 comments on commit b9be789

Please sign in to comment.