Skip to content

Commit a92d13d

Browse files
3l1facebook-github-bot
authored andcommitted
Add conv+residual tests for add/sub ifm scaling (#18754)
Summary: Add AddConvResidual and SubConvResidual test models (conv(x) + x, conv(x) - x) that exercise ifm scaling. The existing standalone Add/Sub tests (x+x, x+y) always have unit ifm scales. Reviewed By: digantdesai Differential Revision: D99927633
1 parent 651f2f2 commit a92d13d

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

backends/arm/test/ops/test_add.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,51 @@ def test_add_tensor_vgf_quant_a16w8(test_data: input_t1):
294294
pipeline.run()
295295

296296

297+
class AddConvResidual(torch.nn.Module):
298+
"""Conv(x) + x — residual block.
299+
300+
Creates non-unit IFM scales
301+
302+
"""
303+
304+
def __init__(self):
305+
super().__init__()
306+
self.conv = torch.nn.Conv2d(3, 3, 1, bias=False)
307+
308+
def forward(self, x):
309+
return self.conv(x) + x
310+
311+
test_data = {
312+
"4d_randn": lambda: (torch.randn(1, 3, 4, 4),),
313+
}
314+
315+
316+
@common.parametrize("test_data", AddConvResidual.test_data)
317+
def test_add_conv_residual_tosa_INT(test_data: input_t1):
318+
pipeline = TosaPipelineINT[input_t1](
319+
AddConvResidual(), test_data(), aten_op, exir_op
320+
)
321+
pipeline.run()
322+
323+
324+
@common.parametrize("test_data", AddConvResidual.test_data)
325+
@common.XfailIfNoCorstone300
326+
def test_add_conv_residual_u55_INT(test_data: input_t1):
327+
pipeline = EthosU55PipelineINT[input_t1](
328+
AddConvResidual(), test_data(), aten_op, exir_op
329+
)
330+
pipeline.run()
331+
332+
333+
@common.parametrize("test_data", AddConvResidual.test_data)
334+
@common.XfailIfNoCorstone320
335+
def test_add_conv_residual_u85_INT(test_data: input_t1):
336+
pipeline = EthosU85PipelineINT[input_t1](
337+
AddConvResidual(), test_data(), aten_op, exir_op
338+
)
339+
pipeline.run()
340+
341+
297342
@common.parametrize("test_data", Add.test_data)
298343
def test_add_tensor_tosa_INT_16a8w(test_data: input_t1):
299344
"""Test add operation with 16A8W quantization (16-bit activations, 8-bit

backends/arm/test/ops/test_sub.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,47 @@ def test_sub_tensor_vgf_quant_2(test_data: Tuple[torch.Tensor, torch.Tensor]):
313313
pipeline.run()
314314

315315

316+
class SubConvResidual(torch.nn.Module):
317+
"""conv(x) - x — residual block. Creates non-unit IFM scales"""
318+
319+
def __init__(self):
320+
super().__init__()
321+
self.conv = torch.nn.Conv2d(3, 3, 1, bias=False)
322+
323+
def forward(self, x):
324+
return self.conv(x) - x
325+
326+
test_data = {
327+
"4d_randn": lambda: (torch.randn(1, 3, 4, 4),),
328+
}
329+
330+
331+
@common.parametrize("test_data", SubConvResidual.test_data)
332+
def test_sub_conv_residual_tosa_INT(test_data: input_t1):
333+
pipeline = TosaPipelineINT[input_t1](
334+
SubConvResidual(), test_data(), aten_op, exir_op
335+
)
336+
pipeline.run()
337+
338+
339+
@common.parametrize("test_data", SubConvResidual.test_data)
340+
@common.XfailIfNoCorstone300
341+
def test_sub_conv_residual_u55_INT(test_data: input_t1):
342+
pipeline = EthosU55PipelineINT[input_t1](
343+
SubConvResidual(), test_data(), aten_op, exir_op
344+
)
345+
pipeline.run()
346+
347+
348+
@common.parametrize("test_data", SubConvResidual.test_data)
349+
@common.XfailIfNoCorstone320
350+
def test_sub_conv_residual_u85_INT(test_data: input_t1):
351+
pipeline = EthosU85PipelineINT[input_t1](
352+
SubConvResidual(), test_data(), aten_op, exir_op
353+
)
354+
pipeline.run()
355+
356+
316357
@common.parametrize("test_data", sub_test_data)
317358
def test_sub_tensor_16a8w_tosa_INT(test_data: input_t1):
318359
"""Test sub operation with 16A8W quantization (16-bit activations, 8-bit

0 commit comments

Comments
 (0)