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

[XShape] Xshape is alternative for flatten op #10088

Merged
merged 3 commits into from
Mar 21, 2023
Merged

[XShape] Xshape is alternative for flatten op #10088

merged 3 commits into from
Mar 21, 2023

Conversation

mjp9527
Copy link
Collaborator

@mjp9527 mjp9527 commented Mar 10, 2023

PR devices

Host

PR types

Bug fixes

PR changes

OP

Description

Xshape is alternative for flatten op;

@paddle-bot
Copy link

paddle-bot bot commented Mar 10, 2023

Thanks for your contribution!

@@ -80,21 +80,26 @@ bool FlattenOp::AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) {

bool Flatten2Op::CheckShape() const {
FlattenOp::CheckShape();
CHECK(param_.xshape);
if (has_xshape_) CHECK(param_.xshape);
Copy link
Collaborator

Choose a reason for hiding this comment

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

是不是可以直接删除了

return true;
}

bool Flatten2Op::InferShapeImpl() const {
FlattenOp::InferShapeImpl();
auto x_shape = param_.x->dims().Vectorize();
x_shape.insert(x_shape.begin(), 0);
param_.xshape->Resize(x_shape);
if (has_xshape_) param_.xshape->Resize(x_shape);
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以简化成这样?
if (param_.xshape)
param_.xshape->Resize(x_shape);

return true;
}

bool Flatten2Op::AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) {
FlattenOp::AttachImpl(opdesc, scope);
param_.xshape = scope->FindMutableTensor(opdesc.Output("XShape").front());
if (opdesc.HasOutput("XShape")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

是不是可以参考

if (opdesc.HasInput("Shape") && !opdesc.Input("Shape").empty()) {
改下?
这样是不是可以不用引入新的变量 has_xshape_ 了?

@mjp9527 mjp9527 changed the title [XShape] Xshape is alternative for flatten op; is_test is alte… [XShape] Xshape is alternative for flatten op Mar 14, 2023
Copy link
Collaborator

@hong19860320 hong19860320 left a comment

Choose a reason for hiding this comment

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

LGTM

@mjp9527 mjp9527 merged commit 32eb13d into PaddlePaddle:develop Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants