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

bugfix for kAddTo in swap_axis #9495

Closed
wants to merge 1 commit into from

Conversation

asmushetzel
Copy link
Contributor

Description

the operator switch_axis was ignoring the "req" argument. That leads to wrong gradients being computed if an operator fans out to two or more other ones where one of them is swap_axis.
This error was detected on something that should become a production model.

Checklist

Essentials

  • [x ] Passed code style checking (make lint)
  • [x ] Changes are complete (i.e. I finished coding on this PR)
  • [ x] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

@asmushetzel
Copy link
Contributor Author

@tdomhan
Copy link
Contributor

tdomhan commented Jan 19, 2018

thanks! I can confirm that this fixes the swapaxes issue observed in Sockeye PR awslabs/sockeye#272

@sxjscience
Copy link
Member

We need to test the case “grad_req=addto”. There seems to be many untested OPs. Here is an example of testing the correctness of AddTo: https://github.com/apache/incubator-mxnet/blob/master/tests/python/unittest/test_operator.py#L777

@sxjscience sxjscience added the Bug label Jan 19, 2018
const std::vector<TShape> &in_shape) const override {
return {ResourceRequest::kTempSpace};
}

Operator* CreateOperator(Context ctx) const override {
LOG(FATAL) << "Not Implemented";
return NULL;
Copy link
Member

Choose a reason for hiding this comment

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

@piiswrong
Copy link
Contributor

Temp space is not necessay. Change line https://github.com/apache/incubator-mxnet/pull/9495/files#diff-f299af08ae07ceaecbd468970ef7ee9cR128 to += when AddTo is set

@@ -135,7 +135,7 @@ class SwapAxisOp : public Operator {
const std::vector<TBlob> &aux_args) {
using namespace mshadow;
Stream<xpu> *s = ctx.get_stream<xpu>();

CHECK_NE(req[swapaxisenum::kOut], kAddTo);
Copy link
Contributor

Choose a reason for hiding this comment

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

it would probably make sense to add a message here to not get very cryptic error messages. Would it not be possible to apply what has been done for the backward pass?

@tdomhan
Copy link
Contributor

tdomhan commented Jan 24, 2018

here's the version of the fix suggested by @piiswrong: #9541
Any chance we could still get this into the next release?

@asmushetzel
Copy link
Contributor Author

Will close this PR as #9541 is the suitable fix.

@asmushetzel asmushetzel deleted the swap_axis_fix branch May 31, 2018 10:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants