-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 3】add paddle sum op #12696
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (C) 2018-2022 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# | ||
# stack paddle model generator | ||
# | ||
import numpy as np | ||
from save_model import saveModel | ||
import sys | ||
|
||
|
||
def sum(name:str, input1, input2, input3): | ||
import paddle | ||
paddle.enable_static() | ||
|
||
with paddle.static.program_guard(paddle.static.Program(), paddle.static.Program()): | ||
data1 = paddle.static.data( | ||
'data1', shape=input1.shape, dtype=input1.dtype) | ||
data2 = paddle.static.data( | ||
'data2', shape=input2.shape, dtype=input2.dtype) | ||
data3 = paddle.static.data( | ||
'data3', shape=input3.shape, dtype=input3.dtype) | ||
|
||
out = paddle.fluid.layers.sum([data1, data2, data3]) | ||
cpu = paddle.static.cpu_places(1) | ||
exe = paddle.static.Executor(cpu[0]) | ||
exe.run(paddle.static.default_startup_program()) | ||
|
||
outs = exe.run( | ||
feed={"data1": input1, | ||
"data2": input2, | ||
"data3": input3}, | ||
fetch_list=[out]) | ||
saveModel(name, exe, feedkeys=['data1', 'data2', 'data3'], fetchlist=[out], inputs=[ | ||
input1, input2, input3], outputs=[outs[0]], target_dir=sys.argv[1]) | ||
|
||
return outs[0] | ||
|
||
|
||
def main(): | ||
|
||
in_type = np.float32 | ||
in_shape = [1, 5] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_1", input1, input2, input3) | ||
|
||
in_type = np.float32 | ||
in_shape = [5, 5] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_2", input1, input2, input3) | ||
|
||
in_type = np.float32 | ||
in_shape = [5, 10] | ||
input1 = np.random.random(in_shape).astype(in_type) | ||
input2 = np.random.random(in_shape).astype(in_type) | ||
input3 = np.random.random(in_shape).astype(in_type) | ||
sum("sum_float_3", input1, input2, input3) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2018-2022 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 sum(const NodeContext& node) { | ||
auto datas = node.get_ng_inputs("X"); | ||
auto data_type = datas[0].get_element_type(); | ||
auto data_shape = datas[0].get_shape(); | ||
std::shared_ptr<Node> out_node = datas[0].get_node_shared_ptr(); | ||
for (int i = 1; i < datas.size(); ++i) { | ||
PADDLE_OP_CHECK(node, | ||
data_type == datas[i].get_element_type(), | ||
"sum input tensor must have the same data types!"); | ||
PADDLE_OP_CHECK(node, | ||
data_shape == datas[i].get_shape(), | ||
"sum input tensor must have the same shape!"); | ||
out_node = std::make_shared<default_opset::Add>(datas[i], out_node); | ||
} | ||
return node.default_single_output_mapping({out_node}, {"Out"}); | ||
} | ||
} // namespace op | ||
} // namespace paddle | ||
} // namespace frontend | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove redundant line