|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +import torch |
| 8 | +from executorch.backends.arm.test.common import parametrize |
| 9 | +from executorch.backends.cortex_m.test.tester import CortexMTester, McuTestCase |
| 10 | +from executorch.examples.models.mlperf_tiny.ds_cnn import DSCNNKWS |
| 11 | + |
| 12 | +ops_before_transforms: dict[str, int] = { |
| 13 | + "executorch_exir_dialects_edge__ops_aten_avg_pool2d_default": 1, |
| 14 | + "executorch_exir_dialects_edge__ops_aten_convolution_default": 9, |
| 15 | + "executorch_exir_dialects_edge__ops_aten_linear_default": 1, |
| 16 | + "executorch_exir_dialects_edge__ops_aten_relu_default": 9, |
| 17 | + "executorch_exir_dialects_edge__ops_aten_view_copy_default": 1, |
| 18 | + "executorch_exir_dialects_edge__ops_dim_order_ops__clone_dim_order_default": 2, |
| 19 | + "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_channel_default": 18, |
| 20 | + "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default": 17, |
| 21 | + "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default": 15, |
| 22 | +} |
| 23 | + |
| 24 | +ops_after_transforms: dict[str, int] = { |
| 25 | + "executorch_exir_dialects_edge__ops_aten_view_copy_default": 1, |
| 26 | + "executorch_exir_dialects_edge__ops_cortex_m_dequantize_per_tensor_default": 1, |
| 27 | + "executorch_exir_dialects_edge__ops_cortex_m_pad_default": 1, |
| 28 | + "executorch_exir_dialects_edge__ops_cortex_m_quantize_per_tensor_default": 1, |
| 29 | + "executorch_exir_dialects_edge__ops_cortex_m_quantized_avg_pool2d_default": 1, |
| 30 | + "executorch_exir_dialects_edge__ops_cortex_m_quantized_conv2d_default": 4, |
| 31 | + "executorch_exir_dialects_edge__ops_cortex_m_quantized_depthwise_conv2d_default": 5, |
| 32 | + "executorch_exir_dialects_edge__ops_cortex_m_quantized_linear_default": 1, |
| 33 | + "executorch_exir_dialects_edge__ops_dim_order_ops__clone_dim_order_default": 2, |
| 34 | +} |
| 35 | + |
| 36 | +test_cases = { |
| 37 | + "ds_cnn": McuTestCase( |
| 38 | + model=DSCNNKWS().eval(), |
| 39 | + example_inputs=lambda: ( |
| 40 | + (torch.rand(1, 1, 49, 10) * 2 - 1).to(memory_format=torch.channels_last), |
| 41 | + ), |
| 42 | + ), |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +@parametrize("test_case", test_cases) |
| 47 | +def test_dialect_ds_cnn(test_case): |
| 48 | + inputs = test_case.get_example_inputs() |
| 49 | + tester = CortexMTester(test_case.model, inputs) |
| 50 | + tester.test_dialect(ops_before_transforms, ops_after_transforms, qtol=1) |
| 51 | + |
| 52 | + |
| 53 | +@parametrize("test_case", test_cases) |
| 54 | +def test_implementation_ds_cnn(test_case): |
| 55 | + inputs = test_case.get_example_inputs() |
| 56 | + tester = CortexMTester(test_case.model, inputs) |
| 57 | + tester.test_implementation(qtol=1) |
0 commit comments