|
| 1 | +# Copyright 2026 Arm Limited and/or its affiliates. |
| 2 | +# |
| 3 | +# This source code is licensed under the BSD-style license found in the |
| 4 | +# LICENSE file in the root directory of this source tree. |
| 5 | + |
| 6 | +import torch |
| 7 | +from executorch.backends.arm.test.common import parametrize |
| 8 | +from executorch.backends.cortex_m.test.tester import CortexMTester, McuTestCase |
| 9 | +from executorch.examples.models.silero_vad.export_silero_vad import ( |
| 10 | + CONTEXT_SIZE, |
| 11 | + HIDDEN_DIM, |
| 12 | + SileroVAD16k, |
| 13 | + WINDOW_SIZE, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +ops_before_transforms: dict[str, int] = { |
| 18 | + "executorch_exir_dialects_edge__ops_aten_abs_default": 2, |
| 19 | + "executorch_exir_dialects_edge__ops_aten_add_Tensor": 3, |
| 20 | + "executorch_exir_dialects_edge__ops_aten_arange_start_step": 1, |
| 21 | + "executorch_exir_dialects_edge__ops_aten_cat_default": 1, |
| 22 | + "executorch_exir_dialects_edge__ops_aten_convolution_default": 6, |
| 23 | + "executorch_exir_dialects_edge__ops_aten_index_Tensor": 1, |
| 24 | + "executorch_exir_dialects_edge__ops_aten_linear_default": 2, |
| 25 | + "executorch_exir_dialects_edge__ops_aten_mean_dim": 1, |
| 26 | + "executorch_exir_dialects_edge__ops_aten_mul_Tensor": 3, |
| 27 | + "executorch_exir_dialects_edge__ops_aten_pow_Tensor_Scalar": 2, |
| 28 | + "executorch_exir_dialects_edge__ops_aten_relu_default": 5, |
| 29 | + "executorch_exir_dialects_edge__ops_aten_select_copy_int": 2, |
| 30 | + "executorch_exir_dialects_edge__ops_aten_sigmoid_default": 4, |
| 31 | + "executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor": 2, |
| 32 | + "executorch_exir_dialects_edge__ops_aten_split_with_sizes_copy_default": 1, |
| 33 | + "executorch_exir_dialects_edge__ops_aten_sqrt_default": 1, |
| 34 | + "executorch_exir_dialects_edge__ops_aten_squeeze_copy_dims": 2, |
| 35 | + "executorch_exir_dialects_edge__ops_aten_sub_Tensor": 2, |
| 36 | + "executorch_exir_dialects_edge__ops_aten_tanh_default": 2, |
| 37 | + "executorch_exir_dialects_edge__ops_aten_unsqueeze_copy_default": 2, |
| 38 | + "executorch_exir_dialects_edge__ops_aten_view_copy_default": 1, |
| 39 | + "executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor_default": 12, |
| 40 | + "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default": 11, |
| 41 | +} |
| 42 | +ops_after_transforms: dict[str, int] = { |
| 43 | + "executorch_exir_dialects_edge__ops_aten_abs_default": 2, |
| 44 | + "executorch_exir_dialects_edge__ops_aten_add_Tensor": 2, |
| 45 | + "executorch_exir_dialects_edge__ops_aten_arange_start_step": 1, |
| 46 | + "executorch_exir_dialects_edge__ops_aten_cat_default": 1, |
| 47 | + "executorch_exir_dialects_edge__ops_aten_convolution_default": 6, |
| 48 | + "executorch_exir_dialects_edge__ops_aten_index_Tensor": 1, |
| 49 | + "executorch_exir_dialects_edge__ops_aten_linear_default": 2, |
| 50 | + "executorch_exir_dialects_edge__ops_aten_mean_dim": 1, |
| 51 | + "executorch_exir_dialects_edge__ops_aten_mul_Tensor": 3, |
| 52 | + "executorch_exir_dialects_edge__ops_aten_pow_Tensor_Scalar": 2, |
| 53 | + "executorch_exir_dialects_edge__ops_aten_relu_default": 5, |
| 54 | + "executorch_exir_dialects_edge__ops_aten_select_copy_int": 2, |
| 55 | + "executorch_exir_dialects_edge__ops_aten_sigmoid_default": 4, |
| 56 | + "executorch_exir_dialects_edge__ops_aten_slice_copy_Tensor": 2, |
| 57 | + "executorch_exir_dialects_edge__ops_aten_split_with_sizes_copy_default": 1, |
| 58 | + "executorch_exir_dialects_edge__ops_aten_sqrt_default": 1, |
| 59 | + "executorch_exir_dialects_edge__ops_aten_squeeze_copy_dims": 2, |
| 60 | + "executorch_exir_dialects_edge__ops_aten_sub_Tensor": 2, |
| 61 | + "executorch_exir_dialects_edge__ops_aten_tanh_default": 2, |
| 62 | + "executorch_exir_dialects_edge__ops_aten_unsqueeze_copy_default": 2, |
| 63 | + "executorch_exir_dialects_edge__ops_aten_view_copy_default": 1, |
| 64 | + "executorch_exir_dialects_edge__ops_cortex_m_dequantize_per_tensor_default": 6, |
| 65 | + "executorch_exir_dialects_edge__ops_cortex_m_quantize_per_tensor_default": 6, |
| 66 | + "executorch_exir_dialects_edge__ops_cortex_m_quantized_add_default": 1, |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +pt_model = SileroVAD16k().eval() |
| 71 | + |
| 72 | +x = torch.randn( |
| 73 | + 1, CONTEXT_SIZE + WINDOW_SIZE |
| 74 | +) # (1, 576) — 64 context + 512 audio samples |
| 75 | +state = torch.zeros(2, 1, HIDDEN_DIM) # (2, 1, 128) — [h, c] LSTM state |
| 76 | + |
| 77 | +test_cases = { |
| 78 | + "silero_vad_16k": McuTestCase( |
| 79 | + model=pt_model, |
| 80 | + example_inputs=lambda: (x, state), |
| 81 | + ), |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +@parametrize("test_case", test_cases) |
| 86 | +def test_dialect_silero_vad_16k(test_case): |
| 87 | + """This model currently does largely not lower to accelerated kernels due to missing LSTM and conv1d support, this test is to track development progress.""" |
| 88 | + inputs = test_case.get_example_inputs() |
| 89 | + tester = CortexMTester(test_case.model, inputs) |
| 90 | + tester.test_dialect( |
| 91 | + ops_before_transforms, |
| 92 | + ops_after_transforms, |
| 93 | + qtol=10, |
| 94 | + ) |
0 commit comments