From 1054c5e5567ecdc886d88f37764c5d511973910e Mon Sep 17 00:00:00 2001 From: Oscar Andersson Date: Thu, 23 May 2024 13:12:40 +0200 Subject: [PATCH] Tester: rename inputs to example_inputs Rename inputs to example_inputs to differentiate between what's used as test data and what's used as example/calibration data. Signed-off-by: Oscar Andersson Change-Id: Ibe6e65fd3f6ec14a8f27fe2270595a3835b1e038 --- backends/arm/test/misc/test_debug_feats.py | 6 ++--- .../arm/test/models/test_mobilenet_v2_arm.py | 6 ++--- backends/arm/test/ops/test_add.py | 6 ++--- backends/arm/test/ops/test_avg_pool.py | 6 ++--- backends/arm/test/ops/test_batch_norm.py | 8 +++---- backends/arm/test/ops/test_clone.py | 12 +++++++--- backends/arm/test/ops/test_conv.py | 6 ++--- backends/arm/test/ops/test_conv_combos.py | 6 ++--- backends/arm/test/ops/test_depthwise_conv.py | 6 ++--- backends/arm/test/ops/test_div.py | 6 ++--- backends/arm/test/ops/test_linear.py | 6 ++--- backends/arm/test/ops/test_mean_dim.py | 6 ++--- backends/arm/test/ops/test_softmax.py | 8 ++++--- backends/arm/test/ops/test_view.py | 12 +++++++--- backends/arm/test/tester/arm_tester.py | 6 ++--- backends/xnnpack/test/tester/tester.py | 24 +++++++++++-------- 16 files changed, 74 insertions(+), 56 deletions(-) diff --git a/backends/arm/test/misc/test_debug_feats.py b/backends/arm/test/misc/test_debug_feats.py index cc3a556363f..4158f085516 100644 --- a/backends/arm/test/misc/test_debug_feats.py +++ b/backends/arm/test/misc/test_debug_feats.py @@ -45,7 +45,7 @@ def _tosa_MI_pipeline(self, module: torch.nn.Module, dump_file=None): ( ArmTester( module, - inputs=module.get_inputs(), + example_inputs=module.get_inputs(), compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -59,7 +59,7 @@ def _tosa_BI_pipeline(self, module: torch.nn.Module, dump_file=None): ( ArmTester( module, - inputs=module.get_inputs(), + example_inputs=module.get_inputs(), compile_spec=common.get_tosa_compile_spec(), ) .quantize() @@ -101,7 +101,7 @@ def test_numerical_diff_prints(self): tester = ( ArmTester( model, - inputs=model.get_inputs(), + example_inputs=model.get_inputs(), compile_spec=common.get_tosa_compile_spec(), ) .quantize() diff --git a/backends/arm/test/models/test_mobilenet_v2_arm.py b/backends/arm/test/models/test_mobilenet_v2_arm.py index 71b056c26e5..d4921822e43 100644 --- a/backends/arm/test/models/test_mobilenet_v2_arm.py +++ b/backends/arm/test/models/test_mobilenet_v2_arm.py @@ -52,7 +52,7 @@ def test_mv2_tosa_MI(self): tester = ( ArmTester( self.mv2, - inputs=self.model_inputs, + example_inputs=self.model_inputs, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -72,7 +72,7 @@ def test_mv2_tosa_BI(self): tester = ( ArmTester( self.mv2, - inputs=self.model_inputs, + example_inputs=self.model_inputs, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -102,7 +102,7 @@ def test_mv2_u55_BI(self): ( ArmTester( self.mv2, - inputs=self.model_inputs, + example_inputs=self.model_inputs, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_add.py b/backends/arm/test/ops/test_add.py index 53e4c2ef655..48ecb48d1f1 100644 --- a/backends/arm/test/ops/test_add.py +++ b/backends/arm/test/ops/test_add.py @@ -61,7 +61,7 @@ def _test_add_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -85,7 +85,7 @@ def _test_add_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .quantize() @@ -111,7 +111,7 @@ def _test_add_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(), ) .quantize() diff --git a/backends/arm/test/ops/test_avg_pool.py b/backends/arm/test/ops/test_avg_pool.py index 259e8e11809..115e26a47f8 100644 --- a/backends/arm/test/ops/test_avg_pool.py +++ b/backends/arm/test/ops/test_avg_pool.py @@ -49,7 +49,7 @@ def _test_avgpool2d_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -74,7 +74,7 @@ def _test_avgpool2d_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -100,7 +100,7 @@ def _test_avgpool2d_tosa_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_batch_norm.py b/backends/arm/test/ops/test_batch_norm.py index dceb2c576d4..278ea037754 100644 --- a/backends/arm/test/ops/test_batch_norm.py +++ b/backends/arm/test/ops/test_batch_norm.py @@ -530,7 +530,7 @@ def _test_batchnorm2d_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -566,7 +566,7 @@ def _test_batchnorm2d_no_stats_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -600,7 +600,7 @@ def _test_batchnorm2d_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .quantize() @@ -638,7 +638,7 @@ def _test_batchnorm2d_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(), ) .quantize() diff --git a/backends/arm/test/ops/test_clone.py b/backends/arm/test/ops/test_clone.py index 2eb94a82322..7cd63edaa72 100644 --- a/backends/arm/test/ops/test_clone.py +++ b/backends/arm/test/ops/test_clone.py @@ -37,7 +37,9 @@ def _test_clone_tosa_MI_pipeline( ): tester = ( ArmTester( - module, inputs=test_data, compile_spec=common.get_tosa_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_tosa_compile_spec(), ) .export() .check_count({"torch.ops.aten.clone.default": 1}) @@ -59,7 +61,9 @@ def _test_clone_tosa_BI_pipeline( ): tester = ( ArmTester( - module, inputs=test_data, compile_spec=common.get_tosa_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_tosa_compile_spec(), ) .quantize() .export() @@ -82,7 +86,9 @@ def _test_clone_tosa_u55_pipeline( ): ( ArmTester( - module, inputs=test_data, compile_spec=common.get_u55_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_u55_compile_spec(), ) .quantize() .export() diff --git a/backends/arm/test/ops/test_conv.py b/backends/arm/test/ops/test_conv.py index 1f0ef7bc293..d95476afaef 100644 --- a/backends/arm/test/ops/test_conv.py +++ b/backends/arm/test/ops/test_conv.py @@ -247,7 +247,7 @@ def _test_conv2d_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -272,7 +272,7 @@ def _test_conv2d_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -296,7 +296,7 @@ def _test_conv2d_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_conv_combos.py b/backends/arm/test/ops/test_conv_combos.py index 2bde0688489..84d90c09059 100644 --- a/backends/arm/test/ops/test_conv_combos.py +++ b/backends/arm/test/ops/test_conv_combos.py @@ -160,7 +160,7 @@ def _test_conv_combo_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -187,7 +187,7 @@ def _test_conv_combo_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -211,7 +211,7 @@ def _test_conv_combo_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_depthwise_conv.py b/backends/arm/test/ops/test_depthwise_conv.py index 0901a49293b..84130654ebd 100644 --- a/backends/arm/test/ops/test_depthwise_conv.py +++ b/backends/arm/test/ops/test_depthwise_conv.py @@ -133,7 +133,7 @@ def _test_dw_conv2d_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -156,7 +156,7 @@ def _test_dw_conv2d_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -180,7 +180,7 @@ def _test_dw_conv2d_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_div.py b/backends/arm/test/ops/test_div.py index 5152a71c2ad..4ff0c8a8352 100644 --- a/backends/arm/test/ops/test_div.py +++ b/backends/arm/test/ops/test_div.py @@ -107,7 +107,7 @@ def _test_div_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -131,7 +131,7 @@ def _test_div_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .quantize() @@ -156,7 +156,7 @@ def _test_div_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(), ) .quantize() diff --git a/backends/arm/test/ops/test_linear.py b/backends/arm/test/ops/test_linear.py index bafadb6df52..e3b505e2997 100644 --- a/backends/arm/test/ops/test_linear.py +++ b/backends/arm/test/ops/test_linear.py @@ -119,7 +119,7 @@ def _test_linear_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -143,7 +143,7 @@ def _test_linear_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .quantize() @@ -168,7 +168,7 @@ def _test_linear_tosa_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(), ) .quantize() diff --git a/backends/arm/test/ops/test_mean_dim.py b/backends/arm/test/ops/test_mean_dim.py index 79ba3de7dad..870202d4329 100644 --- a/backends/arm/test/ops/test_mean_dim.py +++ b/backends/arm/test/ops/test_mean_dim.py @@ -54,7 +54,7 @@ def _test_meandim_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .export() @@ -79,7 +79,7 @@ def _test_meandim_tosa_BI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(permute_memory_to_nhwc=True), ) .quantize() @@ -105,7 +105,7 @@ def _test_meandim_tosa_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(permute_memory_to_nhwc=True), ) .quantize() diff --git a/backends/arm/test/ops/test_softmax.py b/backends/arm/test/ops/test_softmax.py index 32bd2253464..f96c4811324 100644 --- a/backends/arm/test/ops/test_softmax.py +++ b/backends/arm/test/ops/test_softmax.py @@ -42,7 +42,7 @@ def _test_softmax_tosa_MI_pipeline( tester = ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_tosa_compile_spec(), ) .export() @@ -66,7 +66,9 @@ def _test_softmax_tosa_BI_pipeline( ): tester = ( ArmTester( - module, inputs=test_data, compile_spec=common.get_tosa_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_tosa_compile_spec(), ) .quantize() .export() @@ -91,7 +93,7 @@ def _test_softmax_tosa_u55_BI_pipeline( ( ArmTester( module, - inputs=test_data, + example_inputs=test_data, compile_spec=common.get_u55_compile_spec(), ) .quantize() diff --git a/backends/arm/test/ops/test_view.py b/backends/arm/test/ops/test_view.py index fddd21ed2fb..0a1d1e06166 100644 --- a/backends/arm/test/ops/test_view.py +++ b/backends/arm/test/ops/test_view.py @@ -34,7 +34,9 @@ def _test_view_tosa_MI_pipeline( ): tester = ( ArmTester( - module, inputs=test_data, compile_spec=common.get_tosa_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_tosa_compile_spec(), ) .export() .check_count({"torch.ops.aten.view.default": 1}) @@ -56,7 +58,9 @@ def _test_view_tosa_BI_pipeline( ): tester = ( ArmTester( - module, inputs=test_data, compile_spec=common.get_tosa_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_tosa_compile_spec(), ) .quantize() .export() @@ -79,7 +83,9 @@ def _test_view_u55_BI_pipeline( ): ( ArmTester( - module, inputs=test_data, compile_spec=common.get_u55_compile_spec() + module, + example_inputs=test_data, + compile_spec=common.get_u55_compile_spec(), ) .quantize() .export() diff --git a/backends/arm/test/tester/arm_tester.py b/backends/arm/test/tester/arm_tester.py index 69a47f0fdd3..7a00a460e94 100644 --- a/backends/arm/test/tester/arm_tester.py +++ b/backends/arm/test/tester/arm_tester.py @@ -155,13 +155,13 @@ class ArmTester(Tester): def __init__( self, model: torch.nn.Module, - inputs: Tuple[torch.Tensor], + example_inputs: Tuple[torch.Tensor], compile_spec: List[CompileSpec] = None, ): """ Args: model (torch.nn.Module): The model to test - inputs (Tuple[torch.Tensor]): The inputs to the model + example_inputs (Tuple[torch.Tensor]): Example inputs to the model compile_spec (List[CompileSpec]): The compile spec to use """ @@ -173,7 +173,7 @@ def __init__( self.compile_spec = compile_spec - super().__init__(model, inputs) + super().__init__(model, example_inputs) def quantize(self, quantize_stage: Optional[Quantize] = None): if quantize_stage is None: diff --git a/backends/xnnpack/test/tester/tester.py b/backends/xnnpack/test/tester/tester.py index 28f6fe553de..058057955d8 100644 --- a/backends/xnnpack/test/tester/tester.py +++ b/backends/xnnpack/test/tester/tester.py @@ -1,4 +1,5 @@ # Copyright (c) Meta Platforms, Inc. and affiliates. +# Copyright 2024 Arm Limited and/or its affiliates. # All rights reserved. # # This source code is licensed under the BSD-style license found in the @@ -341,13 +342,13 @@ class Tester: def __init__( self, module: torch.nn.Module, - inputs: Tuple[torch.Tensor], + example_inputs: Tuple[torch.Tensor], dynamic_shapes: Optional[Tuple[Any]] = None, ): module.eval() self.original_module = module - self.inputs = inputs + self.example_inputs = example_inputs self.dynamic_shapes = dynamic_shapes self.stages: Dict[str, Stage] = OrderedDict.fromkeys(list(_stages_.keys())) self.pipeline = { @@ -385,15 +386,15 @@ def generate_random_inputs(self): # Get shapes of inputs input_shapes = [] if self.dynamic_shapes is None: - for tensor_arg in self.inputs: + for tensor_arg in self.example_inputs: assert isinstance(tensor_arg, torch.Tensor) input_shapes.append(tensor_arg.shape) else: # Random shapes depending on dynamic shape constraint dim_name_to_size = {} - for arg_idx in range(len(self.inputs)): - assert isinstance(self.inputs[arg_idx], torch.Tensor) - ex_shape = list(self.inputs[arg_idx].shape) + for arg_idx in range(len(self.example_inputs)): + assert isinstance(self.example_inputs[arg_idx], torch.Tensor) + ex_shape = list(self.example_inputs[arg_idx].shape) dynamic_dim_spec = self.dynamic_shapes[arg_idx] for dim_idx, dim_spec in dynamic_dim_spec.items(): assert dim_idx < len(ex_shape) @@ -427,9 +428,11 @@ def fn(x): input_shapes.append(torch.Size(ex_shape)) # create random tensor inputs with the shapes given above: random_inputs = [] - for arg_idx in range(len(self.inputs)): + for arg_idx in range(len(self.example_inputs)): random_inputs.append( - torch.randn(input_shapes[arg_idx]).to(dtype=self.inputs[arg_idx].dtype) + torch.randn(input_shapes[arg_idx]).to( + dtype=self.example_inputs[arg_idx].dtype + ) ) yield tuple(random_inputs) @@ -466,11 +469,12 @@ def _run_stage(self, stage_instance, inputs=None): # Stages def quantize(self, quantize_stage: Optional[Quantize] = None): - return self._run_stage(quantize_stage or Quantize(), self.inputs) + return self._run_stage(quantize_stage or Quantize(), self.example_inputs) def export(self, export_stage: Optional[Export] = None): return self._run_stage( - export_stage or Export(dynamic_shapes=self.dynamic_shapes), self.inputs + export_stage or Export(dynamic_shapes=self.dynamic_shapes), + self.example_inputs, ) def to_edge(self, to_edge_stage: Optional[ToEdge] = None):