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 3】Add Paddle sum operator #12545

Merged
merged 12 commits into from
Sep 15, 2022
Merged

【PaddlePaddle Hackathon 3】Add Paddle sum operator #12545

merged 12 commits into from
Sep 15, 2022

Conversation

Patrick-Star125
Copy link
Contributor

@Patrick-Star125 Patrick-Star125 commented Aug 13, 2022

@Patrick-Star125 Patrick-Star125 requested a review from a team as a code owner August 13, 2022 05:34
@Patrick-Star125
Copy link
Contributor Author

Patrick-Star125 commented Aug 13, 2022

I faced this compilation problem and I don't know how to fix it.
image
It says my implementation includes the illegal conversion from list to <ov::Node>
image
But the sum in my code should always be type of Output<Node> logically,and I'm not sure whether my usage of function Add caused this error.

@openvino-dev-samples
Copy link
Contributor

I faced this compilation problem and I don't know how to fix it. image It says my implementation includes the illegal conversion from list to <ov::Node> image But the sum in my code should always be type of Output<Node> logically,and I'm not sure whether my usage of function Add caused this error.

Hi Did you check the type of data[0] ? maybe it is a list ?

Copy link
Contributor

@openvino-dev-samples openvino-dev-samples left a 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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@Patrick-Star125
Copy link
Contributor Author

@OpenVINO-dev-contest Hi, I ran into another problem. Exception shows as blow
image

  1. I don't know where I implement this 'paddle.fluid.core_avx.BlockDesc' object. Can you help check my unit test code?
  2. Maybe API fill_contant() is the error source
  3. I need input a Python list consist of Paddle Tensor into sum Op, Is that can be implemented directly?


def sum(name: str, x, dtype=None):
out = fluid.layers.sum(x)
exe = paddle.fluid.Executor(paddle.fluid.core.CPUPlace())
Copy link
Contributor

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.

@Patrick-Star125
Copy link
Contributor Author

Patrick-Star125 commented Aug 18, 2022

Thanks, problem fixed. Now can you pls review my code? @OpenVINO-dev-contest

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"});
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.
But if I reuse the sum, it will cause a error in the compile phase.
image

Copy link
Contributor

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.

Copy link
Contributor Author

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.
image
But it will cause another error in the compile phase.
image

Copy link
Contributor

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. image But it will cause another error in the compile phase. image

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.

Copy link
Contributor Author

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.

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();
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@yuxu42 yuxu42 requested review from liubo-intel and removed request for openvino-dev-samples August 25, 2022 02:51
@ilyachur ilyachur added this to the 2022.3 milestone Sep 1, 2022
@ilyachur ilyachur added the category: PDPD FE OpenVINO PaddlePaddle FrontEnd label Sep 1, 2022
Copy link
Contributor

@ilyachur ilyachur left a 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

@openvino-dev-samples
Copy link
Contributor

openvino-dev-samples commented Sep 1, 2022

@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

@ceciliapeng2011 ceciliapeng2011 added the PaddlePaddle Hackathon a Intel and Baidu joint Hackathon event label Sep 1, 2022
Copy link
Contributor

@liubo-intel liubo-intel left a 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)

@Patrick-Star125 Patrick-Star125 requested a review from a team as a code owner September 1, 2022 08:09
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();
Copy link
Contributor

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

Copy link
Contributor Author

@Patrick-Star125 Patrick-Star125 Sep 13, 2022

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.

@ilyachur ilyachur enabled auto-merge (squash) September 14, 2022 03:26
@ilyachur ilyachur merged commit 8cfb285 into openvinotoolkit:master Sep 15, 2022
@ilya-lavrenov ilya-lavrenov added the ExternalPR External contributor label Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: PDPD FE OpenVINO PaddlePaddle FrontEnd ExternalPR External contributor PaddlePaddle Hackathon a Intel and Baidu joint Hackathon event
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants