|
15 | 15 | from executorch.backends.nxp.aten_passes.split_group_convolution import (
|
16 | 16 | SplitGroupConvolution,
|
17 | 17 | )
|
18 |
| -from executorch.backends.nxp.tests.executorch_pipeline import to_quantized_edge_program |
| 18 | +from executorch.backends.nxp.neutron_partitioner import NeutronPartitioner |
| 19 | +from executorch.backends.nxp.nxp_backend import generate_neutron_compile_spec |
| 20 | +from executorch.backends.nxp.tests.executorch_pipeline import ( |
| 21 | + _quantize_model, |
| 22 | + get_random_calibration_inputs, |
| 23 | + to_model_input_spec, |
| 24 | +) |
19 | 25 | from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
|
20 | 26 | from executorch.backends.nxp.tests.models import (
|
21 | 27 | Conv1dModule,
|
22 | 28 | Conv2dModule,
|
23 | 29 | Conv3dModule,
|
24 | 30 | )
|
| 31 | +from executorch.exir import EdgeCompileConfig, EdgeProgramManager |
25 | 32 | from executorch.exir.dialects._ops import ops as exir_ops
|
| 33 | +from executorch.extension.export_util import export_to_edge |
26 | 34 | from parameterized import parameterized
|
| 35 | +from torch.fx import GraphModule |
| 36 | + |
| 37 | + |
| 38 | +def _quantize_and_lower_module( |
| 39 | + module: GraphModule, input_shape: tuple[int, ...], target="imxrt700" |
| 40 | +) -> EdgeProgramManager: |
| 41 | + calibration_inputs = get_random_calibration_inputs(to_model_input_spec(input_shape)) |
| 42 | + |
| 43 | + exir_program_aten__module_quant = _quantize_model(module, calibration_inputs) |
| 44 | + |
| 45 | + edge_compile_config = EdgeCompileConfig(_check_ir_validity=False) |
| 46 | + edge_program_manager = export_to_edge( |
| 47 | + exir_program_aten__module_quant, |
| 48 | + calibration_inputs[0], |
| 49 | + edge_compile_config=edge_compile_config, |
| 50 | + ) |
| 51 | + |
| 52 | + compile_spec = generate_neutron_compile_spec(target, "SDK_25_03") |
| 53 | + partitioner = NeutronPartitioner(compile_spec) |
| 54 | + return edge_program_manager.to_backend(partitioner) |
27 | 55 |
|
28 | 56 |
|
29 | 57 | class TestSplitGroupConvolution(unittest.TestCase):
|
@@ -81,7 +109,7 @@ def test_split_group_convolution__2d(self, _, input_shape: list[int], group: int
|
81 | 109 | assert np.allclose(out1, out2, atol=2.0e-7)
|
82 | 110 |
|
83 | 111 | # Make sure the graph can be correctly quantized and lowered to edge.
|
84 |
| - ep = to_quantized_edge_program( |
| 112 | + ep = _quantize_and_lower_module( |
85 | 113 | modified_module, tuple(input_shape)
|
86 | 114 | ).exported_program()
|
87 | 115 | nodes = list(ep.graph.nodes)
|
@@ -138,7 +166,7 @@ def test_split_group_convolution__1d(self, _, input_shape: list[int], group: int
|
138 | 166 | assert np.allclose(out1, out2, atol=2.0e-7)
|
139 | 167 |
|
140 | 168 | # Make sure the graph can be correctly quantized and lowered to edge.
|
141 |
| - ep = to_quantized_edge_program( |
| 169 | + ep = _quantize_and_lower_module( |
142 | 170 | modified_module, tuple(input_shape)
|
143 | 171 | ).exported_program()
|
144 | 172 | nodes = list(ep.graph.nodes)
|
@@ -226,7 +254,7 @@ def test_split_group_convolution__applied_by_default(self):
|
226 | 254 | assert np.allclose(out1, out2, atol=5.0e-7)
|
227 | 255 |
|
228 | 256 | # Make sure the graph can be correctly quantized and lowered to edge.
|
229 |
| - ep = to_quantized_edge_program( |
| 257 | + ep = _quantize_and_lower_module( |
230 | 258 | modified_module, tuple(input_shape)
|
231 | 259 | ).exported_program()
|
232 | 260 | nodes = list(ep.graph.nodes)
|
|
0 commit comments