delldu commented on a change in pull request #8443:
URL: https://github.com/apache/tvm/pull/8443#discussion_r670192155
##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -2329,6 +2331,30 @@ def flip(self, inputs, input_types):
axis = inputs[1]
return _op.transform.reverse(data, axis=axis[0])
+ def grid_sampler(self, inputs, input_types):
+ data = inputs[0]
+ grid = inputs[1]
+
+ # Torch grid shape is like [batch, out_height, out_width, 2], but
+ # TVM grid is [batch, 2, out_height, out_width], so here grid need to
be converted
+ grid = _op.transform.transpose(grid, axes=[0, 3, 1, 2])
+ return _op.image.grid_sample(data, grid, method="bilinear",
layout="NCHW")
+
+ def im2col(self, inputs, input_types):
+ r"""
+ Torch F.unfold set kerenl_size, dilation, padding, stride as pairs
before calling im2col
+ but it brokern TVM "if condition expression", so please USE
torch._C._nn.im2col instead
+ of F.unfold and make sure giving paired parameters. Please reference
test_forward_im2col
+ in file tests/python/frontend/pytorch/test_forward.py.
Review comment:
From
[https://pytorch.org/docs/stable/_modules/torch/nn/functional.html#unfold]:
```
def unfold(
input: Tensor, kernel_size: BroadcastingList2[int],
dilation: BroadcastingList2[int] = 1,
padding: BroadcastingList2[int] = 0,
stride: BroadcastingList2[int] = 1
) -> Tensor:
if input.dim() == 4:
msg = "{} must be int or 2-tuple for 4D input"
assert_int_or_pair(kernel_size, "kernel_size", msg)
assert_int_or_pair(dilation, "dilation", msg)
assert_int_or_pair(padding, "padding", msg)
assert_int_or_pair(stride, "stride", msg)
return torch._C._nn.im2col(input, _pair(kernel_size),
_pair(dilation), _pair(padding), _pair(stride))
else:
raise NotImplementedError("Input Error: Only 4D input Tensors are
supported (got {}D)".format(input.dim()))
```
You can find:
1) _pair(kernel_size), _pair(dilation), _pair(padding), _pair(stride)
2) if input.dim() == 4: ... else raise ...
First thing, we hope user call im2col with pairs parameters. Second, we hope
user do not use F.unfold directly for it breaks "if return tensor1 else return
tensor2" condition, otherwise, type check will failure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]