self.checkScript(foo, (torch.rand(2, 3), torch.rand(3)))
def test_bool_dispatch(self):
- def kwarg_false(x):
- # type: (Tensor) -> Tensor
- return F.max_pool1d(x, 1, 1, return_indices=False)
- self.checkScript(kwarg_false, (torch.randn(3, 3, 3),))
+ with self.disableModuleHook(): # TODO: Python print broadcasting list
+ def kwarg_false(x):
+ # type: (Tensor) -> Tensor
+ return F.max_pool1d(x, 1, 1, return_indices=False)
+ self.checkScript(kwarg_false, (torch.randn(3, 3, 3),))
- def kwarg_true(x):
- # type: (Tensor) -> Tuple[Tensor, Tensor]
- return F.max_pool1d(x, 1, 1, return_indices=True)
- self.checkScript(kwarg_true, (torch.randn(3, 3, 3),))
+ def kwarg_true(x):
+ # type: (Tensor) -> Tuple[Tensor, Tensor]
+ return F.max_pool1d(x, 1, 1, return_indices=True)
+ self.checkScript(kwarg_true, (torch.randn(3, 3, 3),))
- def full_kwarg_false(x):
- # type: (Tensor) -> Tensor
- return F.max_pool1d(x, 1, 1, ceil_mode=False, return_indices=False)
- self.checkScript(full_kwarg_false, (torch.randn(3, 3, 3),))
+ def full_kwarg_false(x):
+ # type: (Tensor) -> Tensor
+ return F.max_pool1d(x, 1, 1, ceil_mode=False, return_indices=False)
+ self.checkScript(full_kwarg_false, (torch.randn(3, 3, 3),))
- def full_kwarg_true(x):
- # type: (Tensor) -> Tuple[Tensor, Tensor]
- return F.max_pool1d(x, 1, 1, ceil_mode=False, return_indices=True)
- self.checkScript(full_kwarg_true, (torch.randn(3, 3, 3),))
+ def full_kwarg_true(x):
+ # type: (Tensor) -> Tuple[Tensor, Tensor]
+ return F.max_pool1d(x, 1, 1, ceil_mode=False, return_indices=True)
+ self.checkScript(full_kwarg_true, (torch.randn(3, 3, 3),))
- def use_default(x):
- # type: (Tensor) -> Tensor
- return F.max_pool1d(x, 1, 1)
- self.checkScript(use_default, (torch.randn(3, 3, 3),))
+ def use_default(x):
+ # type: (Tensor) -> Tensor
+ return F.max_pool1d(x, 1, 1)
+ self.checkScript(use_default, (torch.randn(3, 3, 3),))
- def arg_false(x):
- # type: (Tensor) -> Tensor
- return F.max_pool1d(x, 1, 1, 0, 1, False, False)
- self.checkScript(arg_false, (torch.randn(3, 3, 3),))
+ def arg_false(x):
+ # type: (Tensor) -> Tensor
+ return F.max_pool1d(x, 1, 1, 0, 1, False, False)
+ self.checkScript(arg_false, (torch.randn(3, 3, 3),))
- def arg_true(x):
- # type: (Tensor) -> Tuple[Tensor, Tensor]
- return F.max_pool1d(x, 1, 1, 0, 1, False, True)
- self.checkScript(arg_true, (torch.randn(3, 3, 3),))
+ def arg_true(x):
+ # type: (Tensor) -> Tuple[Tensor, Tensor]
+ return F.max_pool1d(x, 1, 1, 0, 1, False, True)
+ self.checkScript(arg_true, (torch.randn(3, 3, 3),))
def test_infer_size(self):
from torch._C import _infer_size
}
EXCLUDE_PYTHON_PRINT = {
+ # no support for BroadcastingList in python printer
'test_nn_max_unpool1d',
'test_nn_max_unpool2d',
'test_nn_max_unpool3d',
+ 'test_nn_max_pool3d',
+ 'test_nn_max_pool2d',
+ 'test_nn_max_pool3d'
}
EXCLUDE_SCRIPT_MODULES = {
'test_nn_BatchNorm1d_not_tracking_stats',
'test_nn_BatchNorm2d_not_tracking_stats',
'test_nn_BatchNorm3d_not_tracking_stats',
+ 'test_nn_AdaptiveAvgPool2d_tuple_none',
+ 'test_nn_AdaptiveAvgPool3d_tuple_none',
+ 'test_nn_AdaptiveMaxPool2d_tuple_none',
+ 'test_nn_AdaptiveMaxPool3d_tuple_none',
}
DISABLE_AUTODIFF_SUBGRAPH_INLINING = {
# module cannot be exported /imported currently
EXCLUDE_MODULE_EXPORT_IMPORT = {
'EmbeddingBag',
+ 'MaxPool1d',
+ 'MaxPool2d',
+ 'MaxPool3d',
+ 'AdaptiveAvgPool2d',
+ 'AdaptiveAvgPool3d',
}
# NB: JIT script tests for all nn functional interfaces, script mode does
@torch._jit_internal.weak_script
def max_pool1d_with_indices(input, kernel_size, stride=None, padding=0,
dilation=1, ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList1[int], Optional[BroadcastingList1[int]], int, int, bool, bool) -> Tuple[Tensor, Tensor] # noqa
+ # type: (Tensor, BroadcastingList1[int], Optional[BroadcastingList1[int]], BroadcastingList1[int], BroadcastingList1[int], bool, bool) -> Tuple[Tensor, Tensor] # noqa
r"""Applies a 1D max pooling over an input signal composed of several input
planes.
@torch._jit_internal.weak_script
def _max_pool1d(input, kernel_size, stride=None, padding=0, dilation=1,
ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList1[int], Optional[BroadcastingList1[int]], int, int, bool, bool) -> Tensor
+ # type: (Tensor, BroadcastingList1[int], Optional[BroadcastingList1[int]], BroadcastingList1[int], BroadcastingList1[int], bool, bool) -> Tensor # noqa
return max_pool1d_with_indices(
input, kernel_size, stride, padding, dilation, ceil_mode)[0]
@torch._jit_internal.weak_script
def max_pool2d_with_indices(input, kernel_size, stride=None, padding=0, dilation=1,
ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList2[int], Optional[BroadcastingList2[int]], int, int, bool, bool) -> Tuple[Tensor, Tensor] # noqa
+ # type: (Tensor, BroadcastingList2[int], Optional[BroadcastingList2[int]], BroadcastingList2[int], BroadcastingList2[int], bool, bool) -> Tuple[Tensor, Tensor] # noqa
r"""Applies a 2D max pooling over an input signal composed of several input
planes.
@torch._jit_internal.weak_script
def _max_pool2d(input, kernel_size, stride=None, padding=0, dilation=1,
ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList2[int], Optional[BroadcastingList2[int]], int, int, bool, bool) -> Tensor
+ # type: (Tensor, BroadcastingList2[int], Optional[BroadcastingList2[int]], BroadcastingList2[int], BroadcastingList2[int], bool, bool) -> Tensor # noqa
return max_pool2d_with_indices(
input, kernel_size, stride, padding, dilation, ceil_mode)[0]
@torch._jit_internal.weak_script
def max_pool3d_with_indices(input, kernel_size, stride=None, padding=0,
dilation=1, ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList3[int], Optional[BroadcastingList3[int]], int, int, bool, bool) -> Tuple[Tensor, Tensor] # noqa
+ # type: (Tensor, BroadcastingList3[int], Optional[BroadcastingList3[int]], BroadcastingList3[int], BroadcastingList3[int], bool, bool) -> Tuple[Tensor, Tensor] # noqa
r"""Applies a 3D max pooling over an input signal composed of several input
planes.
@torch._jit_internal.weak_script
def _max_pool3d(input, kernel_size, stride=None, padding=0, dilation=1,
ceil_mode=False, return_indices=False):
- # type: (Tensor, BroadcastingList3[int], Optional[BroadcastingList3[int]], int, int, bool, bool) -> Tensor
+ # type: (Tensor, BroadcastingList3[int], Optional[BroadcastingList3[int]], BroadcastingList3[int], BroadcastingList3[int], bool, bool) -> Tensor # noqa
return max_pool3d_with_indices(
input, kernel_size, stride, padding, dilation, ceil_mode)[0]
from ..._jit_internal import weak_module, weak_script_method
+@weak_module
class _MaxPoolNd(Module):
+ __constants__ = ['kernel_size', 'stride', 'padding', 'dilation',
+ 'return_indices', 'ceil_mode']
def __init__(self, kernel_size, stride=None, padding=0, dilation=1,
return_indices=False, ceil_mode=False):
', dilation={dilation}, ceil_mode={ceil_mode}'.format(**self.__dict__)
+@weak_module
class MaxPool1d(_MaxPoolNd):
r"""Applies a 1D max pooling over an input signal composed of several input
planes.
https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md
"""
+ @weak_script_method
def forward(self, input):
return F.max_pool1d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
', dilation={dilation}, ceil_mode={ceil_mode}'.format(**self.__dict__)
+@weak_module
class MaxPool2d(_MaxPoolNd):
r"""Applies a 2D max pooling over an input signal composed of several input
planes.
https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md
"""
+ @weak_script_method
def forward(self, input):
return F.max_pool2d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
self.return_indices)
+@weak_module
class MaxPool3d(_MaxPoolNd):
r"""Applies a 3D max pooling over an input signal composed of several input
planes. This is not a test
https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md
""" # noqa: E501
+ @weak_script_method
def forward(self, input):
return F.max_pool3d(input, self.kernel_size, self.stride,
self.padding, self.dilation, self.ceil_mode,
self.return_indices)
+@weak_module
class _MaxUnpoolNd(Module):
def extra_repr(self):
)
+@weak_module
class MaxUnpool1d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool1d`.
self.padding, output_size)
+@weak_module
class MaxUnpool2d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool2d`.
self.padding, output_size)
+@weak_module
class MaxUnpool3d(_MaxUnpoolNd):
r"""Computes a partial inverse of :class:`MaxPool3d`.
self.padding, output_size)
+@weak_module
class _AvgPoolNd(Module):
def extra_repr(self):
)
+@weak_module
class AvgPool1d(_AvgPoolNd):
r"""Applies a 1D average pooling over an input signal composed of several
input planes.
>>> m(torch.tensor([[[1.,2,3,4,5,6,7]]]))
tensor([[[ 2., 4., 6.]]])
"""
+ __constants__ = ['kernel_size', 'stride', 'padding', 'ceil_mode',
+ 'count_include_pad']
def __init__(self, kernel_size, stride=None, padding=0, ceil_mode=False,
count_include_pad=True):
self.ceil_mode = ceil_mode
self.count_include_pad = count_include_pad
+ @weak_script_method
def forward(self, input):
return F.avg_pool1d(
input, self.kernel_size, self.stride, self.padding, self.ceil_mode,
self.count_include_pad)
+@weak_module
class AvgPool2d(_AvgPoolNd):
r"""Applies a 2D average pooling over an input signal composed of several input
planes.
>>> input = torch.randn(20, 16, 50, 32)
>>> output = m(input)
"""
+ __constants__ = ['kernel_size', 'stride', 'padding', 'ceil_mode',
+ 'count_include_pad']
def __init__(self, kernel_size, stride=None, padding=0, ceil_mode=False,
count_include_pad=True):
self.ceil_mode = ceil_mode
self.count_include_pad = count_include_pad
+ @weak_script_method
def forward(self, input):
return F.avg_pool2d(input, self.kernel_size, self.stride,
self.padding, self.ceil_mode, self.count_include_pad)
+@weak_module
class AvgPool3d(_AvgPoolNd):
r"""Applies a 3D average pooling over an input signal composed of several input
planes.
>>> input = torch.randn(20, 16, 50,44, 31)
>>> output = m(input)
"""
+ __constants__ = ['kernel_size', 'stride', 'padding', 'ceil_mode',
+ 'count_include_pad']
def __init__(self, kernel_size, stride=None, padding=0, ceil_mode=False,
count_include_pad=True):
self.ceil_mode = ceil_mode
self.count_include_pad = count_include_pad
+ @weak_script_method
def forward(self, input):
return F.avg_pool3d(input, self.kernel_size, self.stride,
self.padding, self.ceil_mode, self.count_include_pad)
"""
@weak_script_method
+ @weak_script_method
def forward(self, input):
return F.lp_pool1d(input, float(self.norm_type), self.kernel_size,
self.stride, self.ceil_mode)
self.stride, self.ceil_mode)
+@weak_module
class _AdaptiveMaxPoolNd(Module):
+ __constants__ = ['output_size', 'return_indices']
def __init__(self, output_size, return_indices=False):
super(_AdaptiveMaxPoolNd, self).__init__()
# output shapes are, and how the operation computes output.
+@weak_module
class AdaptiveMaxPool1d(_AdaptiveMaxPoolNd):
r"""Applies a 1D adaptive max pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_max_pool1d(input, self.output_size, self.return_indices)
+@weak_module
class AdaptiveMaxPool2d(_AdaptiveMaxPoolNd):
r"""Applies a 2D adaptive max pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_max_pool2d(input, self.output_size, self.return_indices)
+@weak_module
class AdaptiveMaxPool3d(_AdaptiveMaxPoolNd):
r"""Applies a 3D adaptive max pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_max_pool3d(input, self.output_size, self.return_indices)
+@weak_module
class _AdaptiveAvgPoolNd(Module):
+ __constants__ = ['output_size']
def __init__(self, output_size):
super(_AdaptiveAvgPoolNd, self).__init__()
return 'output_size={}'.format(self.output_size)
+@weak_module
class AdaptiveAvgPool1d(_AdaptiveAvgPoolNd):
r"""Applies a 1D adaptive average pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_avg_pool1d(input, self.output_size)
+@weak_module
class AdaptiveAvgPool2d(_AdaptiveAvgPoolNd):
r"""Applies a 2D adaptive average pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_avg_pool2d(input, self.output_size)
+@weak_module
class AdaptiveAvgPool3d(_AdaptiveAvgPoolNd):
r"""Applies a 3D adaptive average pooling over an input signal composed of several input planes.
"""
+ @weak_script_method
def forward(self, input):
return F.adaptive_avg_pool3d(input, self.output_size)