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

[TF frontend] add support for StridedSlice to input a single constant #6949

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,9 @@ def _impl(inputs, attr, params, mod):
data_shape = get_const_tuple(in_type.checked_type.shape)
data_dim = len(data_shape)
stride_dim = len(stride)
if data_dim == 0 and isinstance(inputs[0], _expr.Constant):
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this is data_dim==1, right? Otherwise, the data would just be empty. Also, could you add a test case to check this situation? In general, every new feature should come with an appropriate test (see the guidelines : https://tvm.apache.org/docs/contribute/pull_request.html)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I didn't describe it clearly, the input here is a single number. So data_dim here is 0. This situation is the same as np.array(1). len(np.array(1).shape) == 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I didn't know that! I would still add a test to show when this situation arises (just to make sure that branch is covered). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌add test for that.

new_data = inputs[0].data.asnumpy().reshape(1)
return _expr.const(new_data, inputs[0].data.dtype)

# This is a special routine to handle strided_slice after shape_of.
# We need this since in some cases we want to do strided_slice on
Expand Down