Skip to content

Commit 98fe86b

Browse files
3l1facebook-github-bot
authored andcommitted
Add conv+residual tests for add/sub ifm scaling tests (#18754)
Summary: Add AddConvResidual and SubConvResidual test models (conv(x) + x, conv(x) - x) that exercise non-unit ifm scales Differential Revision: D99927633
1 parent ac68932 commit 98fe86b

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

backends/arm/test/ops/test_add.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,47 @@ def test_add_tensor_vgf_quant(test_data: input_t1):
278278
pipeline.run()
279279

280280

281+
class AddConvResidual(torch.nn.Module):
282+
"""conv(x) + x — residual block. Creates non-unit IFM scales"""
283+
284+
def __init__(self):
285+
super().__init__()
286+
self.conv = torch.nn.Conv2d(3, 3, 1, bias=False)
287+
288+
def forward(self, x):
289+
return self.conv(x) + x
290+
291+
test_data = {
292+
"4d_randn": lambda: (torch.randn(1, 3, 4, 4),),
293+
}
294+
295+
296+
@common.parametrize("test_data", AddConvResidual.test_data)
297+
def test_add_conv_residual_tosa_INT(test_data: input_t1):
298+
pipeline = TosaPipelineINT[input_t1](
299+
AddConvResidual(), test_data(), aten_op, exir_op
300+
)
301+
pipeline.run()
302+
303+
304+
@common.parametrize("test_data", AddConvResidual.test_data)
305+
@common.XfailIfNoCorstone300
306+
def test_add_conv_residual_u55_INT(test_data: input_t1):
307+
pipeline = EthosU55PipelineINT[input_t1](
308+
AddConvResidual(), test_data(), aten_op, exir_op
309+
)
310+
pipeline.run()
311+
312+
313+
@common.parametrize("test_data", AddConvResidual.test_data)
314+
@common.XfailIfNoCorstone320
315+
def test_add_conv_residual_u85_INT(test_data: input_t1):
316+
pipeline = EthosU85PipelineINT[input_t1](
317+
AddConvResidual(), test_data(), aten_op, exir_op
318+
)
319+
pipeline.run()
320+
321+
281322
@common.parametrize("test_data", Add.test_data)
282323
def test_add_tensor_tosa_INT_16a8w(test_data: input_t1):
283324
"""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)