Skip to content

Commit d7ac811

Browse files
skywallrobert-kalmar
authored andcommitted
NXP Backend: Add integration test with CifarNet model
CifarNet requires input quantization for full INT8 model quantization. This test verifies that input node is quantized.
1 parent b6ee7e0 commit d7ac811

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

backends/nxp/run_unittests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ EXECUTORCH_DIR=$(dirname $(dirname $SCRIPT_DIR))
1111
cd $EXECUTORCH_DIR
1212

1313
# '-c /dev/null' is used to ignore root level pytest.ini.
14-
PYTHONPATH=`cd ..; pwd` pytest -c /dev/null backends/nxp/tests/
14+
pytest -c /dev/null backends/nxp/tests/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2024 NXP
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 executorch.extension.pybindings.portable_lib
7+
import executorch.kernels.quantized # noqa F401
8+
9+
from executorch.backends.nxp.tests.executorch_pipeline import (
10+
to_quantized_executorch_program,
11+
)
12+
from executorch.backends.nxp.tests.models import ConvFCSoftmaxModule
13+
from executorch.devtools.backend_debug import get_delegation_info
14+
from executorch.examples.nxp.experimental.cifar_net.cifar_net import CifarNet
15+
16+
17+
def test_conv_fc_softmax__to_executorch_program():
18+
model = ConvFCSoftmaxModule()
19+
input_shape = (1, 4, 5, 5)
20+
21+
exec_prog = to_quantized_executorch_program(model, input_shape)
22+
23+
program = exec_prog.exported_program()
24+
assert (
25+
program.graph_module.lowered_module_0
26+
), "There is no lowered module with Neutron microcode."
27+
28+
delegation_info = get_delegation_info(program.graph_module)
29+
assert delegation_info.num_delegated_subgraphs == 1
30+
assert delegation_info.num_non_delegated_nodes == 11
31+
assert delegation_info.num_delegated_nodes == 13
32+
33+
for node in program.graph.nodes:
34+
# Make sure Convolution and AddMM are delegated
35+
assert "convolution" not in node.name
36+
assert "addmm" not in node.name
37+
38+
39+
def test_cifarnet():
40+
model = CifarNet().get_eager_model().eval()
41+
input_shape = (1, 3, 32, 32)
42+
exec_prog = to_quantized_executorch_program(model, input_shape)
43+
44+
delegation_info = get_delegation_info(exec_prog.exported_program().graph_module)
45+
assert delegation_info.num_delegated_subgraphs == 1
46+
assert delegation_info.num_non_delegated_nodes == 17
47+
assert delegation_info.num_delegated_nodes == 42
48+
49+
nodes = list(exec_prog.exported_program().graph.nodes)
50+
assert nodes[2].name == "quantized_decomposed_quantize_per_tensor_default"

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ flatc = "executorch.data.bin:flatc"
111111
"*.fbs",
112112
# Some kernel libraries need their .yaml files.
113113
"*.yaml",
114+
# Add trained models from backends/nxp/experimental
115+
"backends/nxp/experimental/*.pth",
114116
]
115117

116118
[tool.setuptools.exclude-package-data]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../examples/nxp/experimental/

0 commit comments

Comments
 (0)