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]Slice_like support #2014

Merged
merged 7 commits into from
Nov 20, 2018
Merged

Conversation

siju-samuel
Copy link
Member

#1799

Thanks for contributing to TVM! Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers.

@siju-samuel
Copy link
Member Author

@srkreddy1238 @nishi-t @slyubomirsky @yuruofeifei @MarisaKirisame Could you please help in reviewing this PR. TIA

shape_like : tuple of int
The new shape.

axes : tuple of int, optional
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional[Tuple[int]]

data : relay.Expr
The source array.

shape_like : tuple of int
Copy link
Contributor

Choose a reason for hiding this comment

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

Tuple[int]


Parameters
----------
data : relay.Expr
Copy link
Contributor

Choose a reason for hiding this comment

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

tvm.relay.Expr

TVM_ATTR_FIELD(axes).set_default(Array<Integer>())
.describe("List of axes on which input data will be sliced according to the "
"corresponding size of the second input. By default will slice "
"on all axes. Negative axes are supported.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Negative axes are supported -> Negative axes mean counting in reverse.
Only slightly longer, and convey the exact meaning

CHECK(data != nullptr);

const auto* target = types[1].as<TensorTypeNode>();
CHECK(target != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

return false on null, as it might be resolved later.

const TypeReporter& reporter) {
CHECK_EQ(types.size(), 3);
const auto* data = types[0].as<TensorTypeNode>();
CHECK(data != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

return false on null, as it might be resolved later.

}
CHECK(reporter->Assert(i < make_const(Int(64), target_shape.size())))
<< "Axis " << i << " exceeds dimension "
<< target_shape.size()<< " of target_shape.";
Copy link
Contributor

Choose a reason for hiding this comment

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

space between ()<<

@siju-samuel siju-samuel force-pushed the relay_slice_like branch 2 times, most recently from 43de247 to c0a8739 Compare October 28, 2018 16:45
@tqchen
Copy link
Member

tqchen commented Oct 28, 2018

Since slice_like is not a conventional numpy op, let us put its support level as 10 for now, to mark it as experimental

const Array<IndexExpr> target_shape = target->shape;
std::vector<IndexExpr>&& oshape = AsVector(dshape);

if (!param->axes.defined() || param->axes.size() == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

do not support cases of axes.size() == 0, just us None to indicate everything

Copy link
Member Author

@siju-samuel siju-samuel Oct 30, 2018

Choose a reason for hiding this comment

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

@tqchen if we dont support 'axes.size() == 0,' the behaviour will be different for axes=None and axes=[]. I think both should behave the same way. What is your opinion?

Copy link
Member

Choose a reason for hiding this comment

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

In the numpy semantics, axes=None have special meaning, while axes=() really means the axes set is empty, and user might need an error message when this occurs

@siju-samuel
Copy link
Member Author

@tqchen review comments are resolved.

@icemelon
Copy link
Member

icemelon commented Nov 9, 2018

@MarisaKirisame @vinx13 Please review this PR.

@tqchen
Copy link
Member

tqchen commented Nov 9, 2018

Given #2051 and after #2082 , please also add compute part of the op and add testcases

@yzhliu yzhliu added the status: need update need update based on feedbacks label Nov 13, 2018
@siju-samuel siju-samuel force-pushed the relay_slice_like branch 2 times, most recently from 4fcef04 to b1c690f Compare November 13, 2018 06:53
}

const auto param = attrs.as<SliceLikeAttrs>();
if (param == nullptr) {
Copy link
Member

Choose a reason for hiding this comment

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

CHECK(param != nullptr);
as we always expect param to exist

} else {
CHECK(param->axes.size() != 0) << "Axes cannot be empty.";
for (Integer i : param->axes) {
if (reporter->Assert(i < make_const(Int(64), 0))) {
Copy link
Member

Choose a reason for hiding this comment

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

We cannot use Assert for checking symbolic conditions. since it is already Integer, use instead

for (Integer val : param->axes) {
    int axis = val->value;
    if (axis < 0) {
       .... 
    }
} 

if (reporter->Assert(i < make_const(Int(64), 0))) {
i += make_const(Int(64), dshape.size());
}
CHECK(reporter->Assert(i < make_const(Int(64), target_shape.size())))
Copy link
Member

Choose a reason for hiding this comment

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

just use int axis here

@tqchen
Copy link
Member

tqchen commented Nov 13, 2018

Some followup comment, I have noticed some common problems in the code: Assert get misused quite often to get facts out of symbolic relations, we should not do that.

Remember that Assert can optionally trigger an error if the problem occurs, and should not be sued to elicit fact from the solver. If we expect something is concrete integer, simply get things out in comparison

@tqchen tqchen merged commit 2849930 into apache:master Nov 20, 2018
@tqchen
Copy link
Member

tqchen commented Nov 20, 2018

Thanks, @siju-samuel @MarisaKirisame this is merged

@siju-samuel siju-samuel deleted the relay_slice_like branch November 27, 2018 06:42
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: need review status: need update need update based on feedbacks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants