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

fallback to dense version for grad(reshape), grad(expand_dims) #13599

Merged
merged 5 commits into from
Dec 20, 2018

Conversation

yzhliu
Copy link
Member

@yzhliu yzhliu commented Dec 10, 2018

Description

Current reshape uses _backward_copy to do gradient calculation.

But _backward_copy sparse calculation requires same shapes of input and output - which is fair since sparsity is bind to # of rows and cols.

And though reshape itself does not have sparse version, we can easily construct a network, in which its backward input and output are sparse - see test case.

Thus we need to provide a fallback version for reshape backward computation, so as expand_dims.

@eric-haibin-lin @zheng-da

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 https://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

.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& n) {
return std::vector<ResourceRequest>{ResourceRequest::kTempSpace};
})
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

does mkldnn support reshape?

if you want to optimize for mkldnn, you should add FComputeEx

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, #12980 is enabled the FW of MKL-DNN supported reshape but BW is still WIP @huangzhiyuan

Copy link
Member Author

Choose a reason for hiding this comment

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

Then I guess we need to remove this for now.

@zheng-da
Copy link
Contributor

Otherwise, it looks good to me.

BTW, I don't think it has anything to do with sparse.

[](const NodeAttrs& attrs){
return std::vector<std::pair<int, int> >{{0, 0}};
})
.set_attr<FInferStorageType>("FInferStorageType", ElemwiseStorageType<1, 1, false, false, false>)
Copy link
Member

Choose a reason for hiding this comment

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

If an op only supports dense tensors and FCompute, FInferStorageType is not needed

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, thanks!

@eric-haibin-lin eric-haibin-lin merged commit 59f4395 into apache:master Dec 20, 2018
rondogency pushed a commit to rondogency/incubator-mxnet that referenced this pull request Jan 9, 2019
…e#13599)

* fallback to dense version for grad(reshape), grad(expand_dims)

* add _backward_reshape gpu version

* reshape test case comments

* fix gpu test

* remove mkldnn support for _backward_reshape
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
…e#13599)

* fallback to dense version for grad(reshape), grad(expand_dims)

* add _backward_reshape gpu version

* reshape test case comments

* fix gpu test

* remove mkldnn support for _backward_reshape
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants