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

Improve schedule load, add slice_like #1299

Merged
merged 9 commits into from
Jun 27, 2018

Conversation

kevinthesun
Copy link
Contributor

  1. Enhance x86 conv2d schedule loading to allow more flexible schedule loading patten.
  2. Add crop_like operator.

@yzhliu

@srkreddy1238
Copy link
Contributor

@kevinthesun

"Croping only 2nd and 3rd dimensions" and "Always crop based on other tensor shape" look like a special case consideration to me.

I suggest below changes for crop/crop_like for consideration to keep it more generalized.

  • TVM/TOPI interface could be (Input Tensor, Array of Offsets, Array Of Lengths) to keep it more independent.
  • At NNVM/TOP you could add logic to derive Lengths and Offsets based on inputs and attributes.
  • Along with crop_like you could add crop to nnvm which doesn't do anything but call tvm/topi.

Please await for others opinion ..

@yzhliu
Copy link
Member

yzhliu commented Jun 20, 2018

good to me for # 1 - Enhance x86 conv2d schedule loading to allow more flexible schedule loading pattern.

@tqchen
Copy link
Member

tqchen commented Jun 21, 2018

reviewers, please try to make inline comments, or approve the change https://docs.tvm.ai/contribute/code_review.html#approve-and-request-changes-explicitly

@@ -259,6 +259,17 @@ struct ClipParam : public dmlc::Parameter<ClipParam> {
}
};

struct CropLikeParam : public dmlc::Parameter<CropLikeParam> {
Tuple<int> offsets;
bool center_crop;
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle the layout as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I didn't add layout as parameter is this operator's behavior is unrelated to layout. It just crops on the second and third axis.


NNVM_REGISTER_OP(crop_like)
.describe(R"code(Crop the 2nd and 3rd dim of input data,
with width and height of the second input symbol.
Copy link
Contributor

Choose a reason for hiding this comment

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

A new operator to call tvm/crop directly

Copy link
Contributor Author

@kevinthesun kevinthesun Jun 22, 2018

Choose a reason for hiding this comment

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

Issue for a single crop operator in nnvm is that number of inputs can be either 1 or 2. It requires an extra parameter to hint whether it is a "crop_like" operator to set number of inputs. I can add another crop operator in nnvm which just takes 1 input tensor.

* \param name The name of the operation.
* \param tag The tag to mark the operation.
*
* \return Cropped tensor
Copy link
Contributor

Choose a reason for hiding this comment

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

TVM/TOPI interface could be (Input Tensor, Array of Offsets, Array Of Lengths) to keep it more independent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this related to the doc string?

@tqchen tqchen added status: review in progress status: need update need update based on feedbacks labels Jun 21, 2018
@tqchen
Copy link
Member

tqchen commented Jun 22, 2018

@kevinthesun can you act or make updated rely on the review comments?

@tqchen
Copy link
Member

tqchen commented Jun 22, 2018

I am less sure about introducing crop operator, as crop seems to be a special case of slice operator( #1183), if shape inference can be done on the fly during conversion, it is likely we won't need the crop operator at all.

@kevinthesun maybe you can remove the crop related stuffs first and merge the rest part it?

@kevinthesun
Copy link
Contributor Author

kevinthesun commented Jun 23, 2018

Yes. Slice is more general. I'll remove crop from topi.

@tqchen
Copy link
Member

tqchen commented Jun 26, 2018

@srkreddy1238 please review again on the updated changes

@tqchen tqchen changed the title Improve schedule load Improve schedule load, add slice_like Jun 26, 2018
if (param.axis.ndim() == 0) {
for (size_t i = 0; i < src_shape.ndim(); ++i) {
if (i < target_shape.ndim()) {
end_idx[i] = target_shape[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a check to make sure the end_idx doesn't go beyond input length.

CHECK_LT(i, target_shape.ndim())
<< "Axis " << i << " exceeds dimension "
<< target_shape.ndim()<< " of target_shape.";
end_idx[i] = target_shape[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

Same check as above here as well.

.describe(R"code(Slice the first input respect to the second input.
)code" NNVM_ADD_FILELINE)
.add_argument("data", "Tensor", "Input data to be sliced.")
.add_argument("shape_like", "Tensor", "Shape like tensor")
Copy link
Contributor

Choose a reason for hiding this comment

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

shape_like or slice_like ?

Array<Expr> src_shape = inputs[0]->shape;
Array<Expr> target_shape = inputs[1]->shape;
Array<Expr> begin_idx, end_idx, strides;
for (size_t i = 0; i < src_shape.size(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Merge these two loops.

if (axis < 0) {
axis = static_cast<int>(src_shape.size()) + axis;
}
end_idx.Set(static_cast<size_t>(axis), target_shape[axis]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same check as above here as well.

if (param.axis.ndim() == 0) {
for (size_t i = 0; i < src_shape.size(); ++i) {
if (i < target_shape.size()) {
end_idx.Set(i, target_shape[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same check as above here as well.

topi::strided_slice(inputs[0], begin_idx, end_idx, strides)
};
})
.set_attr<FListInputNames>("FListInputNames", [](const NodeAttrs& attrs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shape_like or slice_like ?

slice_idx = []
for b, e in zip(begin_idx, end_idx):
slice_idx.append(slice(b, e))
np_result = np_data[slice_idx]
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this numpy slicing as a function.

@kevinthesun
Copy link
Contributor Author

@srkreddy1238 comment addressed.

Copy link
Contributor

@srkreddy1238 srkreddy1238 left a comment

Choose a reason for hiding this comment

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

@kevinthesun great thanks.

np_slice_like could be a sub function inside verify_slice_like as no other calls it.

Good to go now.

@tqchen tqchen merged commit c72cd71 into apache:master Jun 27, 2018
tqchen pushed a commit to tqchen/tvm that referenced this pull request Jul 6, 2018
mnuyens pushed a commit to mnuyens/tvm that referenced this pull request Jul 10, 2018
@kevinthesun kevinthesun deleted the ImproveScheduleLoad branch July 18, 2018 22:29
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
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.

4 participants