Skip to content

Commit 19a54bc

Browse files
NXP backend: Fix group convolution merge conflict (#13894)
Updated version with lint fixes: #13867 --------- Co-authored-by: Martin Pavella <[email protected]>
1 parent 43bd889 commit 19a54bc

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

backends/nxp/tests/test_split_group_convolution.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,43 @@
1515
from executorch.backends.nxp.aten_passes.split_group_convolution import (
1616
SplitGroupConvolution,
1717
)
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+
)
1925
from executorch.backends.nxp.tests.executors import graph_contains_any_of_ops
2026
from executorch.backends.nxp.tests.models import (
2127
Conv1dModule,
2228
Conv2dModule,
2329
Conv3dModule,
2430
)
31+
from executorch.exir import EdgeCompileConfig, EdgeProgramManager
2532
from executorch.exir.dialects._ops import ops as exir_ops
33+
from executorch.extension.export_util import export_to_edge
2634
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)
2755

2856

2957
class TestSplitGroupConvolution(unittest.TestCase):
@@ -81,7 +109,7 @@ def test_split_group_convolution__2d(self, _, input_shape: list[int], group: int
81109
assert np.allclose(out1, out2, atol=2.0e-7)
82110

83111
# Make sure the graph can be correctly quantized and lowered to edge.
84-
ep = to_quantized_edge_program(
112+
ep = _quantize_and_lower_module(
85113
modified_module, tuple(input_shape)
86114
).exported_program()
87115
nodes = list(ep.graph.nodes)
@@ -138,7 +166,7 @@ def test_split_group_convolution__1d(self, _, input_shape: list[int], group: int
138166
assert np.allclose(out1, out2, atol=2.0e-7)
139167

140168
# Make sure the graph can be correctly quantized and lowered to edge.
141-
ep = to_quantized_edge_program(
169+
ep = _quantize_and_lower_module(
142170
modified_module, tuple(input_shape)
143171
).exported_program()
144172
nodes = list(ep.graph.nodes)
@@ -226,7 +254,7 @@ def test_split_group_convolution__applied_by_default(self):
226254
assert np.allclose(out1, out2, atol=5.0e-7)
227255

228256
# Make sure the graph can be correctly quantized and lowered to edge.
229-
ep = to_quantized_edge_program(
257+
ep = _quantize_and_lower_module(
230258
modified_module, tuple(input_shape)
231259
).exported_program()
232260
nodes = list(ep.graph.nodes)

0 commit comments

Comments
 (0)