-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 operator #12545
Conversation
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.
Hi Thanks for your contribution
|
||
|
||
def sum(name: str, x, dtype=None): | ||
out = paddle.add_n(x) |
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.
Hi
According to your reference document: https://www.paddlepaddle.org.cn/documentation/docs/zh/1.8/api_cn/layers_cn/sum_cn.html#sum
seems we should use paddle.fluid.layers.sum(x) to simulate paddle's output right?
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.
updated
|
||
def sum(name: str, x, dtype=None): | ||
out = fluid.layers.sum(x) | ||
exe = paddle.fluid.Executor(paddle.fluid.core.CPUPlace()) |
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.
hi I think you have to convert x to a paddle.static.data object before feed into sum(), pls refer to other generation script.
Thanks, problem fixed. Now can you pls review my code? @OpenVINO-dev-contest |
src/frontends/paddle/src/op/sum.cpp
Outdated
sum = std::make_shared<default_opset::Add>(sum, data[i]); | ||
} | ||
const auto temp = default_opset::Constant::create(input_type, {shape}, {0}); | ||
return node.default_single_output_mapping({std::make_shared<default_opset::Add>(sum, temp)}, {"Out"}); |
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.
Hi @Patrick-Star125 can we reuse the 'sum' here, not create a constant to build a new node again ?
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.
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.
Maybe we can create a 'Constant Node' to initialize the sum node ? but not initialize it by data[0] ? I guess.
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.
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.
I thought so at first, so I tried to implement it as below.
But it will cause another error in the compile phase.
Got it. Thanks. How about leaving the {std::make_shared<default_opset::Add>(sum, temp)} before the loop, to transfer the first input element into a Add node. And let's see other reviewer's comments.
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.
Thanks, the problem was solved by initializing the sum
with a copied pointer of the data
object.
src/frontends/paddle/src/op/sum.cpp
Outdated
NamedOutputs sum(const NodeContext& node) { | ||
auto data = node.get_ng_inputs("X"); | ||
const auto input_type = data[0].get_element_type(); | ||
const auto shape = data[0].get_shape(); |
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.
Shall we check the shape of each element in list to make sure they are same ?
You can leverage 'PADDLE_OP_CHECK' to log a message if the shapes are not aligned.
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.
updated
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
Outdated
Show resolved
Hide resolved
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.
@ceciliapeng2011 Looks like we have the same op in the PR: #12696
hi @ilyachur, since this PR is submitted before another one, could you help to review it with higher priority if it is almost qualified ? thanks |
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
Outdated
Show resolved
Hide resolved
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
Outdated
Show resolved
Hide resolved
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.
Hi, @Patrick-Star125 : thanks for contribution of this Paddle OP conversion. have left some comments mainly related with that I think we would better keep align with PaddlePaddle2.1 'sum' Operator, as 'PaddlePaddle2.1' is openvino currently officially supported version .
And also modified the 'Reference' link of this PR's description(changed spec version from 1.8 to 2.1, and the language version from Chinese to English, convenient for global viewers)
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
Outdated
Show resolved
Hide resolved
src/core/tests/frontend/paddle/test_models/gen_scripts/generate_sum.py
Outdated
Show resolved
Hide resolved
src/frontends/paddle/src/op/sum.cpp
Outdated
NamedOutputs sum(const NodeContext& node) { | ||
auto data = node.get_ng_inputs("X"); | ||
const auto input_type = data[0].get_element_type(); | ||
const auto shape = data[0].get_shape(); |
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.
I don't see that you use shape
and input_type
here. I think we should remove these variables
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.
Done, removed these redundant codes already.
Details:
add sum operation in Paddle front end
Reference:
Unit-test passed