Skip to content

Commit a7e9380

Browse files
NXP backend: Extend NXP backend docs page, add partitioner and quantization (#14997)
### Summary This PR updates NXP backend docs Readme. ### Test plan cc @robert-kalmar @JakeStevens @digantdesai Co-authored-by: roman-janik-nxp <[email protected]>
1 parent db49614 commit a7e9380

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

docs/source/backends-nxp.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ For up-to-date status about running ExecuTorch on Neutron Backend please visit t
1010

1111
## Features
1212

13-
Executorch v1.0 supports running machine learning models on selected NXP chips (for now only i.MXRT700).
13+
ExecuTorch v1.0 supports running machine learning models on selected NXP chips (for now only i.MXRT700).
1414
Among currently supported machine learning models are:
1515
- Convolution-based neutral networks
16-
- Full support for MobileNetv2 and CifarNet
16+
- Full support for MobileNetV2 and CifarNet
1717

1818
## Prerequisites (Hardware and Software)
1919

20-
In order to succesfully build executorch project and convert models for NXP eIQ Neutron Backend you will need a computer running Windows or Linux.
20+
In order to successfully build ExecuTorch project and convert models for NXP eIQ Neutron Backend you will need a computer running Linux.
2121

2222
If you want to test the runtime, you'll also need:
2323
- Hardware with NXP's [i.MXRT700](https://www.nxp.com/products/i.MX-RT700) chip or a testing board like MIMXRT700-AVK
@@ -32,9 +32,48 @@ To test converting a neural network model for inference on NXP eIQ Neutron Backe
3232
./examples/nxp/aot_neutron_compile.sh [model (cifar10 or mobilenetv2)]
3333
```
3434

35-
For a quick overview how to convert a custom PyTorch model, take a look at our [exmple python script](https://github.com/pytorch/executorch/tree/release/1.0/examples/nxp/aot_neutron_compile.py).
35+
For a quick overview how to convert a custom PyTorch model, take a look at our [example python script](https://github.com/pytorch/executorch/tree/release/1.0/examples/nxp/aot_neutron_compile.py).
36+
37+
### Partitioner API
38+
39+
The partitioner is defined in `NeutronPartitioner` in `backends/nxp/neutron_partitioner.py`. It has the following
40+
arguments:
41+
* `compile_spec` - list of key-value pairs defining compilation. E.g. for specifying platform (i.MXRT700) and Neutron Converter flavor.
42+
* `custom_delegation_options` - custom options for specifying node delegation.
43+
44+
### Quantization
45+
46+
The quantization for Neutron Backend is defined in `NeutronQuantizer` in `backends/nxp/quantizer/neutron_quantizer.py`.
47+
The quantization follows PT2E workflow, INT8 quantization is supported. Operators are quantized statically, activations
48+
follow affine and weights symmetric per-tensor quantization scheme.
49+
50+
#### Supported operators
51+
52+
List of Aten operators supported by Neutron quantizer:
53+
54+
`abs`, `adaptive_avg_pool2d`, `addmm`, `add.Tensor`, `avg_pool2d`, `cat`, `conv1d`, `conv2d`, `dropout`,
55+
`flatten.using_ints`, `hardtanh`, `hardtanh_`, `linear`, `max_pool2d`, `mean.dim`, `pad`, `permute`, `relu`, `relu_`,
56+
`reshape`, `view`, `softmax.int`, `sigmoid`, `tanh`, `tanh_`
57+
58+
#### Example
59+
```python
60+
import torch
61+
from executorch.backends.nxp.quantizer.neutron_quantizer import NeutronQuantizer
62+
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e
63+
64+
# Prepare your model in Aten dialect
65+
aten_model = get_model_in_aten_dialect()
66+
# Prepare calibration inputs, each tuple is one example, example tuple has items for each model input
67+
calibration_inputs: list[tuple[torch.Tensor, ...]] = get_calibration_inputs()
68+
quantizer = NeutronQuantizer()
69+
70+
m = prepare_pt2e(aten_model, quantizer)
71+
for data in calibration_inputs:
72+
m(*data)
73+
m = convert_pt2e(m)
74+
```
3675

3776
## Runtime Integration
3877

39-
To learn how to run the converted model on the NXP hardware, use one of our example projects on using executorch runtime from MCUXpresso IDE example projects list.
78+
To learn how to run the converted model on the NXP hardware, use one of our example projects on using ExecuTorch runtime from MCUXpresso IDE example projects list.
4079
For more finegrained tutorial, visit [this manual page](https://mcuxpresso.nxp.com/mcuxsdk/latest/html/middleware/eiq/executorch/docs/nxp/topics/example_applications.html).

0 commit comments

Comments
 (0)