Lunderberg commented on code in PR #13414:
URL: https://github.com/apache/tvm/pull/13414#discussion_r1034074531
##########
python/tvm/topi/nn/depthwise_conv2d.py:
##########
@@ -284,9 +295,13 @@ def depthwise_conv2d_nhwc(Input, Filter, stride, padding,
dilation, out_dtype=No
j * stride_w + dj * dilation_w,
idxdiv(c, channel_multiplier),
].astype(out_dtype)
- * Filter[
- di, dj, idxdiv(c, channel_multiplier), idxmod(c,
channel_multiplier)
- ].astype(out_dtype)
+ * Filter.__getitem__(
Review Comment:
The explicit `__getitem__` isn't required. `Filter[x,y,z]` is syntactic
sugar for `Filter[(x,y,z)]`. If you already have a tuple, then `Filter[tuple(
... )]` can be called.
##########
python/tvm/topi/nn/depthwise_conv2d.py:
##########
@@ -252,8 +253,18 @@ def depthwise_conv2d_nhwc(Input, Filter, stride, padding,
dilation, out_dtype=No
dilation_h, dilation_w = dilation
batch, in_height, in_width, in_channel = Input.shape
+
+ dim = len(Input.shape) - 2
+
# shape of dilated kernel
- filter_height, filter_width, filter_channel, channel_multiplier =
Filter.shape
+ if kernel_layout == "HWOI":
+ filter_height, filter_width, filter_channel, channel_multiplier =
Filter.shape
+ kernel_permutation_to = [0, 1] + list(range(2, dim + 2))
+ elif kernel_layout == "HWIO":
+ filter_height, filter_width, channel_multiplier, filter_channel =
Filter.shape
+ kernel_permutation_to = [dim + 1, dim] + list(range(dim))
+
+ kernel_permutation_from = np.argsort(kernel_permutation_to)
Review Comment:
Is there a benefit to defining in terms of `kernel_permutation_to` instead
of directly defining `kernel_permutation_from`?
##########
python/tvm/topi/nn/depthwise_conv2d.py:
##########
@@ -252,8 +253,18 @@ def depthwise_conv2d_nhwc(Input, Filter, stride, padding,
dilation, out_dtype=No
dilation_h, dilation_w = dilation
batch, in_height, in_width, in_channel = Input.shape
+
+ dim = len(Input.shape) - 2
+
# shape of dilated kernel
- filter_height, filter_width, filter_channel, channel_multiplier =
Filter.shape
+ if kernel_layout == "HWOI":
+ filter_height, filter_width, filter_channel, channel_multiplier =
Filter.shape
+ kernel_permutation_to = [0, 1] + list(range(2, dim + 2))
+ elif kernel_layout == "HWIO":
+ filter_height, filter_width, channel_multiplier, filter_channel =
Filter.shape
+ kernel_permutation_to = [dim + 1, dim] + list(range(dim))
Review Comment:
I'm not seeing how this permutation generates `HWIO`. This defines
`kernel_permutation_to` as `[3, 2, 0, 1]`, so `kernel_permutation_from` is `[2,
3, 1, 0]`. With the usage below, that would permute from `[di, dj,
c//channel_multiplier, c%channel_multiplier]` to `[c//channel_multiplier,
c%channel_multiplier, dj, di]`, which would be `OIWH`.
Should this be `list(range(dim)) + [dim + 1, dim]` instead?
--
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]