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] Support dynamic slicing on first few axes, keeping the rest static #8068

Merged
merged 6 commits into from
May 20, 2021

Conversation

masahi
Copy link
Member

@masahi masahi commented May 18, 2021

This PR relaxes the constraint that begin, end and strides params of dynamic strided slice to have the same length as input rank, and enable slicing on only first few axes (in particular, slicing along batch dim only).

For example, the output shape of ONNX NMS is (num_detection, 3). However, when translated to relay, it becomes (?, ?), since current dynamic stride slice always slices on all axes, even if some axes are conceptually static. This posed a problem when GatherND is applied to the output of ONNX NMS, since it requires the second dimension to be static:

ICHECK(mdim) << "GatherND needs a static shape for the first axis of indices, got "
<< indices->shape;

ready for review @mbrookhart @jwfromm @kevinthesun @yongwww

@@ -25,16 +25,19 @@

@tvm.testing.uses_gpu
def test_dynamic_strided_slice():
def verify(dshape, begin, end, strides, output, slice_mode="end", test_ref=True, dtype="int32"):
Copy link
Member Author

Choose a reason for hiding this comment

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

output is not used in the test, so I removed it.

@masahi masahi changed the title [Relay, TOPI] Supporting dynamic slice on first few axes, keeping the rest static [Relay, TOPI] Support dynamic slicing on first few axes, keeping the rest static May 18, 2021
@mbrookhart
Copy link
Contributor

This looks good to me. Do we need to do anything to support this behavior in the standard strided slice op?

@masahi
Copy link
Member Author

masahi commented May 19, 2021

No, I believe it is already supported, although the static version doesn't have a constraint that len(begin) == len(end) == len(strides).
https://github.com/apache/tvm/blob/main/include/tvm/topi/transform.h#L651-L653
https://github.com/apache/tvm/blob/main/include/tvm/topi/transform.h#L672-L674

(No idea why CI is running another job, it already passed).

Copy link
Contributor

@mbrookhart mbrookhart left a comment

Choose a reason for hiding this comment

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

LGTM

@masahi masahi merged commit 0d96f95 into apache:main May 20, 2021
@masahi
Copy link
Member Author

masahi commented May 20, 2021

thanks @mbrookhart

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 17, 2021
…rest static (apache#8068)

* Supporting dynamic slice on first few axes

* fix index normalization

* update dynamic slice tests

* pylint fix

* fix loop index dtype

* fix more dtype issue
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jun 17, 2021
…rest static (apache#8068)

* Supporting dynamic slice on first few axes

* fix index normalization

* update dynamic slice tests

* pylint fix

* fix loop index dtype

* fix more dtype issue
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