-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
e1b6e36
to
10186cb
Compare
f50c66c
to
a11b2f7
Compare
"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.
Please await for others opinion .. |
good to me for # 1 - Enhance x86 conv2d schedule loading to allow more flexible schedule loading pattern. |
reviewers, please try to make inline comments, or approve the change https://docs.tvm.ai/contribute/code_review.html#approve-and-request-changes-explicitly |
nnvm/include/nnvm/top/tensor.h
Outdated
@@ -259,6 +259,17 @@ struct ClipParam : public dmlc::Parameter<ClipParam> { | |||
} | |||
}; | |||
|
|||
struct CropLikeParam : public dmlc::Parameter<CropLikeParam> { | |||
Tuple<int> offsets; | |||
bool center_crop; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/src/top/tensor/transform.cc
Outdated
|
||
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
topi/include/topi/transform.h
Outdated
* \param name The name of the operation. | ||
* \param tag The tag to mark the operation. | ||
* | ||
* \return Cropped tensor |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
@kevinthesun can you act or make updated rely on the review comments? |
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? |
Yes. Slice is more general. I'll remove crop from topi. |
@srkreddy1238 please review again on the updated changes |
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]; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
nnvm/src/top/tensor/transform.cc
Outdated
.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") |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
@srkreddy1238 comment addressed. |
There was a problem hiding this 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.
@yzhliu