Skip to content

Commit 46ec26b

Browse files
copyrightlyfacebook-github-bot
authored andcommitted
check "transposed convolution" at beginning
Summary: Current `check_convolution_args` checks shapes of parameters before checking `transposed`. For a model using `ConvTranspose2d`, this may incur error like ``` executorch:tensor_util.h:655] Check failed (a.size(dim_a) == b.size(dim_b)): Tensors do not match: a.size(0) = 512 does not match b.size(0) = 1024 ``` instead of showing `"transposed convolution not supported yet."` (see "ET CPU" in the test plan of D57258810). The reason for getting the error above is due to the difference of shape of `weight` between `ConvTranspose2d` and `Conv2d`, specifically, - shape of `weight` in [`ConvTranspose2d` ](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html) is (note that the first item is `in_channels`) ``` (in_channels, out_channels/groups, kernel_size[0], kernel_size[1]) ``` - instead, shape of `weight` in [`Conv2d`](https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html) is (note that the first item is `out_channels`) ``` (out_channels, in_channels/groups​, kernel_size[0], kernel_size[1]) ``` so [`tensors_have_same_size_at_dims(bias.value(), 0, weight, 0));`](https://www.internalfb.com/code/fbsource/[d34494a8af88b8c9742d00d62046d7884da47d7e]/fbcode/executorch/kernels/portable/cpu/util/kernel_ops_util.cpp?lines=314) may fail for `ConvTranspose2d` (even when valid shapes were used) before checking `transposed`. The error message would be more informative if we check `transposed` at the beginning. Reviewed By: manuelcandales, jorgep31415 Differential Revision: D57424572 fbshipit-source-id: 592b4052bc067ca6108eec8af65a4111099a8697
1 parent 7f05874 commit 46ec26b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernels/portable/cpu/util/kernel_ops_util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ bool check_convolution_args(
294294
IntArrayRef output_padding,
295295
int64_t groups,
296296
Tensor& out) {
297+
ET_LOG_MSG_AND_RETURN_IF_FALSE(
298+
!transposed, "transposed convolution not supported yet.");
297299
ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, weight, out));
298300

299301
ET_LOG_AND_RETURN_IF_FALSE(tensor_is_default_or_channels_last_dim_order(in));
@@ -335,9 +337,6 @@ bool check_convolution_args(
335337
groups,
336338
in.size(1));
337339

338-
ET_LOG_MSG_AND_RETURN_IF_FALSE(
339-
!transposed, "transposed convolution not supported yet.");
340-
341340
return true;
342341
}
343342

0 commit comments

Comments
 (0)