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

[Relay/TOPI][OP] Add clip and wrap mode support in take #2858

Merged
merged 6 commits into from
Apr 1, 2019

Conversation

icemelon
Copy link
Member

Previously take can return arbitrary values when indices are negative or too larger. It's very dangerous. Now it is fixed in this PR by eanbling take to handle out-of-bound indices in two modes: clip (default) and wrap.
Also fix bugs in HalideIR Simplify and CanonicalSimplify for non-Euclidean mod when operand is negative.

@icemelon
Copy link
Member Author

cc @tqchen

@icemelon
Copy link
Member Author

@Laurawly @yzhliu @merrymercy Could you help review this pr?

TVM_ATTR_FIELD(mode).set_default("CLIP")
.describe("Specify how out-of-bound indices will behave."
"CLIP - clip to the range (default)"
"WRAP - wrap around the indices");
Copy link
Member

Choose a reason for hiding this comment

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

suggest to use lower-case, to be the same as that in numpy. also add mode="raise" to the description

Copy link
Member Author

@icemelon icemelon Mar 30, 2019

Choose a reason for hiding this comment

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

Sure. I can change to lower case.
It's a bit tricky to add "raise" mode because current tvm::compute (see https://github.com/dmlc/tvm/blob/master/include/tvm/operation.h#L547) doesn't allow us to add AssertStmt in the body. I think we should add this in a follow-up pr.

cc @tqchen What do you suggest about AssertStmt?

Copy link
Member

Choose a reason for hiding this comment

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

how about we skip raise for now?

assert len(inputs) == 2
mode = attrs.get_str("mode", "clip")
if mode == "raise":
raise RuntimeError("take doesn't support raise mode")
Copy link
Member

Choose a reason for hiding this comment

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

enable the support?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@yzhliu yzhliu left a comment

Choose a reason for hiding this comment

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

good to me. please make the CI happy.

@yzhliu
Copy link
Member

yzhliu commented Apr 1, 2019

Thanks everyone.

@icemelon icemelon deleted the take branch April 1, 2019 22:40
ajtulloch pushed a commit to ajtulloch/tvm that referenced this pull request Apr 5, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 7, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 7, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 8, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
wweic pushed a commit to wweic/tvm that referenced this pull request Apr 10, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
wweic pushed a commit to neo-ai/tvm that referenced this pull request Apr 11, 2019
* Update take

* Add special case for canonical simplify and fix test cases

* Use lower case for wrap and clip

* remove unnecssary lower

* Fix mxnet converter for take

* fix
@apivovarov
Copy link
Contributor

I prepared MXNet Hybrid block which uses F.take(x, [1,2], axis=1).
MXNet and TVM outputs are different.
Script and output are below:
https://gist.github.com/apivovarov/7e951a86e9bda9d1b450b066839adea8

@apivovarov
Copy link
Contributor

@icemelon9 What you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants