Skip to content

Commit 46b3fa7

Browse files
authored
[CMSIS-NN] Support for asymmetric padding in Convolutions (#9886)
1 parent 57af88f commit 46b3fa7

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

python/tvm/relay/op/contrib/cmsisnn.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ def check_qnn_conv2d(pattern):
135135

136136
return (
137137
conv2d.attrs.out_dtype == "int32"
138-
and int(conv2d.attrs.padding[0]) == int(conv2d.attrs.padding[2])
139-
and int(conv2d.attrs.padding[1]) == int(conv2d.attrs.padding[3])
140138
and conv2d_input.checked_type.dtype == "int8"
141139
and conv2d_weight.checked_type.dtype == "int8"
142140
and pattern.checked_type.dtype == "int8"

tests/python/contrib/test_cmsisnn/test_conv2d.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ def make_model(
6969
kernel_w = kernel_shape[w_index]
7070
invar = relay.var("input", shape=shape, dtype=dtype)
7171
p = (0, 0, 0, 0)
72-
if padding == "INVALID":
73-
p = [1, 2, 2, 1]
7472
if padding == "SAME":
7573
p = get_same_padding((shape[1], shape[2]), (kernel_h, kernel_w), dilation, strides)
7674
invar = relay.nn.pad(
@@ -126,10 +124,10 @@ def make_model(
126124

127125

128126
@tvm.testing.requires_cmsisnn
129-
@pytest.mark.parametrize("ifm_shape", [(1, 28, 28, 12), (1, 64, 100, 4)])
130-
@pytest.mark.parametrize("kernel_size", [(3, 3)])
127+
@pytest.mark.parametrize("ifm_shape", [(1, 25, 25, 12), (1, 64, 100, 4)])
128+
@pytest.mark.parametrize("kernel_size", [(5, 5)])
131129
@pytest.mark.parametrize("padding", ["SAME", "VALID"])
132-
@pytest.mark.parametrize("strides, dilation", [((1, 1), (1, 1))])
130+
@pytest.mark.parametrize("strides, dilation", [((2, 2), (1, 1))])
133131
@pytest.mark.parametrize("relu_type", ["RELU"])
134132
@pytest.mark.parametrize("enable_bias", [True, False])
135133
@pytest.mark.parametrize(
@@ -353,19 +351,15 @@ def parameterize_for_invalid_model(test):
353351
in_dtype = ["uint8", "int8"]
354352
kernel_dtype = ["uint8", "int8"]
355353
kernel_zero_point = [-33, 10, 0]
356-
padding = ["SAME", "INVALID"]
357-
all_combinations = itertools.product(in_dtype, kernel_dtype, kernel_zero_point, padding)
354+
all_combinations = itertools.product(in_dtype, kernel_dtype, kernel_zero_point)
358355
all_combinations = filter(
359356
lambda parameters: not (
360-
parameters[0] == "int8"
361-
and parameters[1] == "int8"
362-
and parameters[2] == 0
363-
and parameters[3] == "SAME"
357+
parameters[0] == "int8" and parameters[1] == "int8" and parameters[2] == 0
364358
),
365359
all_combinations,
366360
)
367361
return pytest.mark.parametrize(
368-
["in_dtype", "kernel_dtype", "kernel_zero_point", "padding"],
362+
["in_dtype", "kernel_dtype", "kernel_zero_point"],
369363
all_combinations,
370364
)(test)
371365

@@ -376,7 +370,6 @@ def test_invalid_parameters(
376370
in_dtype,
377371
kernel_dtype,
378372
kernel_zero_point,
379-
padding,
380373
):
381374
ifm_shape = (1, 28, 28, 12)
382375
out_channels = 2
@@ -407,7 +400,7 @@ def test_invalid_parameters(
407400
kernel_scale=kernel_scale,
408401
output_zero_point=output_zero_point,
409402
output_scale=output_scale,
410-
padding=padding,
403+
padding="SAME",
411404
strides=(1, 1),
412405
dilation=(1, 1),
413406
groups=1,

0 commit comments

Comments
 (0)