-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68904e3
[RELAY][OP] conv2d, ShapeExpr->IndexExpr
tqchen 110d355
Fix attrs api
tqchen e95402e
fix topi axis problem
tqchen 6dc5a71
Fix review comments, fix AlphaEq for shape
tqchen 9a6802a
Bug fix error caught by recovering alpha eq, more testcase on layout
tqchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /*! | ||
| * Copyright (c) 2018 by Contributors | ||
| * \file tvm/relay/attrs/nn.h | ||
| * \brief Auxiliary attributes for nn operators. | ||
| */ | ||
| #ifndef TVM_RELAY_ATTRS_NN_H_ | ||
| #define TVM_RELAY_ATTRS_NN_H_ | ||
|
|
||
| #include <tvm/attrs.h> | ||
| #include <string> | ||
|
|
||
| namespace tvm { | ||
| namespace relay { | ||
|
|
||
| /*! \brief Attributes used in convolution operators */ | ||
| struct ConvAttrs : public tvm::AttrsNode<ConvAttrs> { | ||
| Array<IndexExpr> strides; | ||
| Array<IndexExpr> padding; | ||
| Array<IndexExpr> dilation; | ||
| int groups; | ||
| IndexExpr channels; | ||
| Array<IndexExpr> kernel_size; | ||
| std::string data_layout; | ||
| std::string weight_layout; | ||
| std::string out_layout; | ||
| DataType out_dtype; | ||
|
|
||
| TVM_DECLARE_ATTRS(ConvAttrs, "relay.attrs.ConvAttrs") { | ||
| TVM_ATTR_FIELD(strides).set_default(Array<IndexExpr>({1, 1})) | ||
| .describe("Specifies the strides of the convolution."); | ||
| TVM_ATTR_FIELD(padding).set_default(Array<IndexExpr>({0, 0})) | ||
| .describe("If padding is non-zero, then the input is implicitly zero-padded" | ||
| "on both sides for padding number of points"); | ||
| TVM_ATTR_FIELD(dilation).set_default(Array<IndexExpr>({1, 1})) | ||
| .describe("Specifies the dilation rate to use for dilated convolution."); | ||
| TVM_ATTR_FIELD(groups).set_default(1) | ||
| .describe("Controls the connections between inputs and outputs." | ||
| "At groups=1, all inputs are convolved to all outputs." | ||
| "At groups=2, the operation becomes equivalent to having two convolution" | ||
| "layers side by side, each seeing half the input channels, and producing" | ||
| "half the output channels, and both subsequently concatenated."); | ||
| TVM_ATTR_FIELD(channels) | ||
| .describe("The number of output channels in the convolution." | ||
| " If it is not set, inferred by shape of the weight.") | ||
| .set_default(NullValue<IndexExpr>()); | ||
| TVM_ATTR_FIELD(kernel_size) | ||
| .describe("Specifies the dimensions of the convolution window.") | ||
| .set_default(NullValue<Array<IndexExpr> >()); | ||
| TVM_ATTR_FIELD(data_layout).set_default("NCHW") | ||
| .describe("Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc." | ||
| "'N', 'C', 'H', 'W' stands for batch, channel, height, and width" | ||
| "dimensions respectively. Convolution is applied on the 'H' and" | ||
| "'W' dimensions."); | ||
| TVM_ATTR_FIELD(weight_layout).set_default("OIHW") | ||
| .describe("Dimension ordering of weight. Can be 'OIHW', 'OIHW16o16i', etc." | ||
| "'O', 'I', 'H', 'W' stands for num_filter, input_channel, height, and width" | ||
| "dimensions respectively."); | ||
| TVM_ATTR_FIELD(out_layout).set_default("__undef__") | ||
| .describe("Dimension ordering of output. Can be 'NCHW', 'NHWC', etc." | ||
| "'N', 'C', 'H', 'W' stands for batch, channel, height, and width" | ||
| "dimensions respectively. Default to be same as input layout."); | ||
|
|
||
| // use 0 bits to indicate none. | ||
| TVM_ATTR_FIELD(out_dtype) | ||
| .set_default(Int(0)) | ||
| .describe("Output data type, set to explicit type under mixed precision setting"); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace relay | ||
| } // namespace tvm | ||
| #endif // TVM_RELAY_ATTRS_NN_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| # Operators | ||
| from .op import Op | ||
| from .op.tensor import * | ||
| from .op import nn | ||
|
|
||
| # Span | ||
| Span = base.Span | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
|
|
||
| # Operators | ||
| from .tensor import * | ||
| from . import nn | ||
|
|
||
|
|
||
| # operator registry | ||
| from . import _tensor | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Neural network operations.""" | ||
| from __future__ import absolute_import as _abs | ||
| from . import _make | ||
|
|
||
|
|
||
| def conv2d(data, | ||
| weight, | ||
| strides=(1, 1), | ||
| padding=(0, 0), | ||
| dilation=(1, 1), | ||
| groups=1, | ||
| channels=None, | ||
| kernel_size=None, | ||
| data_layout="NCHW", | ||
| weight_layout="OIHW", | ||
| out_layout="", | ||
| out_dtype=""): | ||
| """Two dimensional convolution operator. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| data : relay.Expr | ||
| The input data to the operator. | ||
|
|
||
| weight : relay.Expr | ||
| The weight expressions. | ||
|
|
||
| strides : tuple of int, optional | ||
| The strides of convoltution. | ||
|
|
||
| padding : tuple of int, optional | ||
| The padding of convolution on both sides of inputs. | ||
|
|
||
| dilation : tuple of int, optional | ||
| Specifies the dilation rate to be used for dilated convolution. | ||
|
|
||
| groups : int, optional | ||
| Number of groups for grouped convolution. | ||
|
|
||
| data_layout : str, optional | ||
| Layout of the input. | ||
|
|
||
| weight_layout : str, optional | ||
| Layout of the weight. | ||
|
|
||
| out_layout : str, optional | ||
| Layout of the output. | ||
|
|
||
| out_dtype : str, optional | ||
| Specifies the output data type for mixed precision conv2d. | ||
| """ | ||
| return _make.conv2d(data, weight, strides, padding, dilation, | ||
| groups, channels, kernel_size, data_layout, | ||
| weight_layout, out_layout, out_dtype) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_layoutetc?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.
@junrushao1994
It can be a sample then complete list if required.
The possible options list is very long and is explained in layout header.
Uh oh!
There was an error while loading. Please reload this page.
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::ConvAttrsdefined ininclude/tvm/relay/attrs/nn.h.