Skip to content

Commit c5d66a5

Browse files
rascaniRJ Ascani
andauthored
Cortex-M: Fix activation tests for conv2d (pytorch#16379)
### Summary Update three activation test configurations to avoid being classified as depthwise convolutions. Changed Conv2d(1,1,1) to Conv2d(2,1,1) with weight=0.5 in: - CortexMConv2DHardswish - CortexMConv2DHardsigmoid - CortexMConv2DClampInplace ### Test Plan ``` pytest --config-file=backends/arm/test/pytest.ini \ backends/cortex_m/test/ops/test_activation.py ``` Co-authored-by: RJ Ascani <rja@fb.com>
1 parent 44d436b commit c5d66a5

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎backends/cortex_m/test/ops/test_activation.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ class CortexMConv2DHardswish(torch.nn.Module):
268268
"executorch_exir_dialects_edge__ops_cortex_m_dequantize_per_tensor_default": 1,
269269
}
270270

271-
def __init__(self, in_channels=1, out_channels=1):
271+
def __init__(self):
272272
super().__init__()
273-
self.conv = torch.nn.Conv2d(1, 1, 1, padding=0, bias=False)
273+
self.conv = torch.nn.Conv2d(2, 1, 1, padding=0, bias=False)
274274
self.act = torch.nn.Hardswish()
275-
self.conv.weight.data.fill_(1)
275+
self.conv.weight.data.fill_(0.5)
276276

277277
def forward(self, x):
278278
return self.act(self.conv(x))
@@ -344,9 +344,9 @@ class CortexMConv2DHardsigmoid(torch.nn.Module):
344344

345345
def __init__(self):
346346
super().__init__()
347-
self.conv = torch.nn.Conv2d(1, 1, 1, bias=False)
347+
self.conv = torch.nn.Conv2d(2, 1, 1, bias=False)
348348
self.act = torch.nn.Hardsigmoid(inplace=True)
349-
self.conv.weight.data.fill_(1)
349+
self.conv.weight.data.fill_(0.5)
350350

351351
def forward(self, x):
352352
return self.act(self.conv(x))
@@ -369,8 +369,8 @@ class CortexMConv2DClampInplace(torch.nn.Module):
369369

370370
def __init__(self):
371371
super().__init__()
372-
self.conv = torch.nn.Conv2d(1, 1, 1, bias=False)
373-
self.conv.weight.data.fill_(1)
372+
self.conv = torch.nn.Conv2d(2, 1, 1, bias=False)
373+
self.conv.weight.data.fill_(0.5)
374374

375375
def forward(self, x):
376376
return torch.clamp_(self.conv(x), min=0.0, max=None)
@@ -490,19 +490,19 @@ def forward(self, x):
490490
"conv2d_hardsigmoid_inplace": McuTestCase(
491491
model=CortexMConv2DHardsigmoid(),
492492
example_inputs=(
493-
ramp_tensor(-4, 4, (1, 1, 6, 6)).to(memory_format=torch.channels_last),
493+
ramp_tensor(-4, 4, (1, 2, 6, 6)).to(memory_format=torch.channels_last),
494494
),
495495
),
496496
"conv2d_hardswish": McuTestCase(
497-
model=CortexMConv2DHardswish(in_channels=1, out_channels=1),
497+
model=CortexMConv2DHardswish(),
498498
example_inputs=(
499-
ramp_tensor(-3, 0, (1, 1, 1, 100)).to(memory_format=torch.channels_last),
499+
ramp_tensor(-3, 0, (1, 2, 1, 100)).to(memory_format=torch.channels_last),
500500
),
501501
),
502502
"conv2d_clamp_inplace": McuTestCase(
503503
model=CortexMConv2DClampInplace(),
504504
example_inputs=(
505-
ramp_tensor(-4, 4, (1, 1, 1, 10)).to(memory_format=torch.channels_last),
505+
ramp_tensor(-4, 4, (1, 2, 1, 10)).to(memory_format=torch.channels_last),
506506
),
507507
),
508508
"linear_clamp": McuTestCase(

0 commit comments

Comments
 (0)