-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[RELAY][OP] conv2d, ShapeExpr->IndexExpr #1798
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
Conversation
|
Rushing for an exam. Will check it out tomorrow evening. |
src/relay/op/nn/layout.h
Outdated
| * indicates the split dimension. | ||
| * return undefined layout if "__undef__" is passed. | ||
| */ | ||
| inline Layout(const std::string& layout) { // NOLINT(*) |
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.
I think there is no need to have inline. Definitions inside a class will be treated as inlined automatically. Same to the methods that implemented in this class below.
| * \return shape in target layout | ||
| */ | ||
| inline std::vector<IndexExpr> ConvertLayout( | ||
| std::vector<IndexExpr> src, |
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.
const &?
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.
const is not used in here as it can be used for copy-elison when directly returning it
src/relay/op/nn/layout.h
Outdated
| } | ||
|
|
||
| inline std::vector<IndexExpr> ConvertLayout( | ||
| Array<IndexExpr> src, |
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.
const & ?
| void ShapeEqual(Array<ShapeExpr> s1, Array<ShapeExpr> s2) {} | ||
| void ShapeEqual(Array<IndexExpr> s1, Array<IndexExpr> s2) {} | ||
|
|
||
| void VisitType_(const TensorTypeNode *tt1, const Type& t2) final { |
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.
TensorTypeNode* tt1
src/relay/op/nn/layout.h
Outdated
| << ": invalid factor size " << factor | ||
| << " before dimension " << c; | ||
| CHECK_EQ(superdim_pos_[pos], -1) << "Invalid layout " << layout | ||
| << ": duplicate dimension " << c; |
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.
remove two space?
| int pos = c - 'a'; | ||
| CHECK_GT(factor, 0) << "Invalid layout " << layout << ": invalid factor size " | ||
| << factor << " for dimension " << c; | ||
| CHECK_EQ(subdim_pos_[pos], -1) << "Invalid layout " << layout |
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.
remove two space to align
| ib.ret(func) | ||
| func = relay.ir_pass.infer_type(ib.env, func.to_func()) | ||
| ftype = func.checked_type() | ||
| assert ftype.ret_type == relay.ty.TensorType( |
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.
@tqchen
I tried some hands on with this test case and observed this comparison hold good only for the dtype not for shape.
Am I missing some thing here?
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.
Can you elaborate? The testcase should works for shape 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.
assert ftype.ret_type == relay.ty.TensorType((n, 2, 224, 224), "float32")
To
assert ftype.ret_type == relay.ty.TensorType((n, 2, 100, 100), "float32")
doesn't fail.
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.
Great catch, this is actually due to a problem in alpha_eq comparator, I have fixed this in recent commit
|
@MarisaKirisame @zhiics Thanks for the comments, i have fixed them |
| Number of groups for grouped convolution. | ||
| data_layout : str, optional | ||
| Layout of the input. |
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.
Should we mention the possible options for data_layout, weight_layout etc?
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.
It can be a sample then complete list if required.
The possible options list is very long and is explained in layout header.
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.
@srkreddy1238 My comment here is too picky. Definitely It is not a big deal.
I am just a little bit worried whether Python frontend users will be willing to check C APIs described in tvm::relay::ConvAttrs defined in include/tvm/relay/attrs/nn.h.
|
@tqchen Seems some test cases failed. Please fix them. |
|
Thanks @srkreddy1238 's comment uncovering the problem of alpha eq, this leads to a few more problems to be uncovered. It is a good reminder for us to have good test coverage, in light of that. I have added more test cases for conv2d including the layout transformation. @zhiics @srkreddy1238 @MarisaKirisame please review again |
srkreddy1238
left a comment
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.
Layout conversion on oshape is also addressed now & LGTM.
| Number of groups for grouped convolution. | ||
| data_layout : str, optional | ||
| Layout of the input. |
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.
It can be a sample then complete list if required.
The possible options list is very long and is explained in layout header.
junrushao
left a comment
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 PR looks good to me.
| Number of groups for grouped convolution. | ||
| data_layout : str, optional | ||
| Layout of the input. |
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.
@srkreddy1238 My comment here is too picky. Definitely It is not a big deal.
I am just a little bit worried whether Python frontend users will be willing to check C APIs described in tvm::relay::ConvAttrs defined in include/tvm/relay/attrs/nn.h.
|
Thanks @junrushao1994 @srkreddy1238 @zhiics @MarisaKirisame this is now merged. I agree with @junrushao1994 that we might want to list common options here, maybe not all of them |
This PR represents what is generally need to be done to port an NNVM operator to relay, most of the logic remains the same
Examples
Although I am not completely happy with the current python DSL API(relay.ir_builder). The example test case does show some interesting improvement over what we can do previously, for example, we can already do limited symbolic inference with batch dimension as symbolic