Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix fp32 flatten issue #15351

Merged
merged 7 commits into from
Jul 8, 2019
Merged

Conversation

wuxun-zhang
Copy link
Contributor

Description

This PR should fix issue #15267. The previous FP32 flatten op seems not work properly in some situations. So, we reimplement it by using mkldnn reshape op.
@pengzhao-intel @ciyongch @TaoLv please help review. Thanks

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@pengzhao-intel
Copy link
Contributor

@TaoLv @ciyongch please help to take a review.

// is larger than 2, we should use the default layout.
if (outputs[0].IsMKLDNNData() && inputs[0].shape().ndim() > 2)
const_cast<NDArray &>(outputs[0]).Reorder2Default();
if (SupportMKLDNNArray(inputs[0].dtype(), inputs[0].shape())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

SupportMKLDNNArray doesn't support 3D tensor, flatten should have same coverage as reshape, 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.

Yes, you're right.

Copy link
Member

Choose a reason for hiding this comment

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

Use the same conditions in SupportMKLDNNReshape.

@@ -98,62 +75,63 @@ class MKLDNNReshapeForward {
} else {
LOG(FATAL) << "not supported req type: " << req;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

indent from Line38 to 77?

@@ -119,12 +119,11 @@ void MKLDNNTransposeForward(const nnvm::NodeAttrs& attrs,
const OpReqType &req,
const NDArray &output);

void MKLDNNReshapeForward(const nnvm::NodeAttrs &attrs,
void MKLDNNFlattenForward(const nnvm::NodeAttrs &attrs,
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to keep both flatten and reshape function declaration here.

: MKLDNNReshapeFwd(req, input, output) {}
};

static MKLDNNFlattenFwd &GetFlattenForward(const OpReqType &req,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to combine GetFlattenForward and GetRehshapeForward into one, and call them via passing different template parameter? So that we can still reuse most of the function when implementing other ops like expand_dims?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems cannot combine these two functions into one. Because reshape op have a parameter ReshapeParam while flatten op don't, so when we try to create key, for reshape we use MKLDNNReshapeSignature key(ReshapeParam), but for flatten we use OpSignature key. So, this function should be designed differently.
Also, expand_dims op also have a parameter, and can reuse this function with reshape op.

@anirudhacharya
Copy link
Member

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jun 28, 2019
@wuxun-zhang
Copy link
Contributor Author

@ciyongch @TaoLv Please help review again if these changes are appropriate. Thanks.

@TaoLv
Copy link
Member

TaoLv commented Jul 1, 2019

@arcadiaphy, it would be highly appreciated if you can help to verify this fix with the java demo case. Hope this PR can fix the issue in #15267.

@arcadiaphy
Copy link
Member

@TaoLv I've tested the java demo, problem solved. Thanks!

@wuxun-zhang
Copy link
Contributor Author

@pengzhao-intel @TaoLv @ciyongch CI has passed. Please take a review again. Thanks.

Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

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

Thanks for the improvements.

@pengzhao-intel
Copy link
Contributor

https://mxnet.incubator.apache.org/versions/master/tutorials/mkldnn/operator_list.html

Please also add the OP in the MKLDNN supported list.

@wuxun-zhang wuxun-zhang requested a review from szha as a code owner July 5, 2019 07:46
@wuxun-zhang
Copy link
Contributor Author

@pengzhao-intel @TaoLv Thanks for your advice. Updated.

@pengzhao-intel
Copy link
Contributor

Thanks for your contribution. Merging now.

@pengzhao-intel pengzhao-intel merged commit 091fece into apache:master Jul 8, 2019
@wuxun-zhang wuxun-zhang deleted the fix_fp32_flatten branch July 12, 2019 01:04
juliusshufan pushed a commit to juliusshufan/incubator-mxnet that referenced this pull request Aug 8, 2019
* Fix flatten issue before slice op

* fix cpplint

* address comments

* retrigger CI

* trigger CI

* retrigger CI

* use SupportMKLDNNReshape and update operator list
juliusshufan pushed a commit to juliusshufan/incubator-mxnet that referenced this pull request Aug 8, 2019
* Fix flatten issue before slice op

* fix cpplint

* address comments

* retrigger CI

* trigger CI

* retrigger CI

* use SupportMKLDNNReshape and update operator list
juliusshufan pushed a commit to juliusshufan/incubator-mxnet that referenced this pull request Aug 11, 2019
* Fix flatten issue before slice op

* fix cpplint

* address comments

* retrigger CI

* trigger CI

* retrigger CI

* use SupportMKLDNNReshape and update operator list
juliusshufan pushed a commit to juliusshufan/incubator-mxnet that referenced this pull request Aug 11, 2019
* Fix flatten issue before slice op

* fix cpplint

* address comments

* retrigger CI

* trigger CI

* retrigger CI

* use SupportMKLDNNReshape and update operator list
TaoLv pushed a commit that referenced this pull request Aug 12, 2019
* Fix flatten issue before slice op

* fix cpplint

* address comments

* retrigger CI

* trigger CI

* retrigger CI

* use SupportMKLDNNReshape and update operator list
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants