-
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
[Torch] Add support for max_pool1d #5142
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -987,6 +987,10 @@ Array<te::Tensor> Pool1DCompute(const Attrs& attrs, | |
<< " or 4-D input (e.g. NCWc on for vector instructions)" | ||
<< " or 5-D input (e.g. NCWnc for tensor accelerators)"; | ||
|
||
if (param->padding.size() == 1) { | ||
padding.push_back(padding[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? Does 1D pooling require two pad values (left & right)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, If we don't have this, the max_pool1d will fail in https://github.com/apache/incubator-tvm/blob/7c5ff50873e91e9ad27b5f08847c27d58e8b5c4c/topi/include/topi/nn/pooling.h#L679-L680 |
||
} | ||
|
||
if (mode == topi::nn::kAvgPool) { | ||
bool count_include_pad = reinterpret_cast<const AvgPool1DAttrs*>(param)->count_include_pad; | ||
return Array<te::Tensor>{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,7 +351,7 @@ def forward(self, *args): | |
verify_model(AdaptiveAvgPool2D1().float().eval(), input_data=input_data) | ||
verify_model(AdaptiveAvgPool2D2().float().eval(), input_data=input_data) | ||
|
||
def test_forward_maxpool(): | ||
def test_forward_maxpool2d(): | ||
torch.set_grad_enabled(False) | ||
input_shape = [1, 3, 10, 10] | ||
|
||
|
@@ -363,9 +363,35 @@ class MaxPool2D2(Module): | |
def forward(self, *args): | ||
return torch.nn.MaxPool2d(kernel_size=[10, 10])(args[0]) | ||
|
||
class MaxPool2D3(Module): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this wrapper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need a test for padding and stride in Maxpool? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am talking about the same point as https://github.com/apache/incubator-tvm/pull/5142/files#r397046667 Yes, you should have a test, but no need to write a wrapper class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks. I misunderstood your review suggestion :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
def forward(self, *args): | ||
return torch.nn.MaxPool2d(kernel_size=[4, 4], padding=2, stride=2)(args[0]) | ||
|
||
input_data = torch.rand(input_shape).float() | ||
verify_model(MaxPool2D1().float().eval(), input_data=input_data) | ||
verify_model(MaxPool2D2().float().eval(), input_data=input_data) | ||
verify_model(MaxPool2D3().float().eval(), input_data=input_data) | ||
|
||
def test_forward_maxpool1d(): | ||
torch.set_grad_enabled(False) | ||
input_shape = [1, 3, 10] | ||
|
||
class MaxPool1D1(Module): | ||
def forward(self, *args): | ||
return torch.nn.MaxPool1d(kernel_size=1)(args[0]) | ||
|
||
class MaxPool1D2(Module): | ||
def forward(self, *args): | ||
return torch.nn.MaxPool1d(kernel_size=10)(args[0]) | ||
|
||
class MaxPool1D3(Module): | ||
def forward(self, *args): | ||
return torch.nn.MaxPool1d(kernel_size=4, padding=2, stride=2)(args[0]) | ||
|
||
input_data = torch.rand(input_shape).float() | ||
verify_model(MaxPool1D1().float().eval(), input_data=input_data) | ||
verify_model(MaxPool1D2().float().eval(), input_data=input_data) | ||
verify_model(MaxPool1D3().float().eval(), input_data=input_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
||
def test_forward_avgpool(): | ||
torch.set_grad_enabled(False) | ||
|
@@ -1028,7 +1054,8 @@ def forward(self, xs): | |
test_forward_concatenate() | ||
test_forward_relu() | ||
test_forward_adaptiveavgpool() | ||
test_forward_maxpool() | ||
test_forward_maxpool2d() | ||
test_forward_maxpool1d() | ||
test_forward_hardtanh() | ||
test_forward_conv() | ||
test_forward_threshold() | ||
|
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.
does pooling have dilation argument?
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.
In https://pytorch.org/docs/stable/nn.html#maxpool1d, MaxPool1d and MaxPool2d have dilation argument.