|
| 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" |
0 commit comments