Create the local quality baseline
Modules 1 and 2 introduced PyTorch export, ExecuTorch lowering, and XNNPACK delegation. This section applies the same process to LR-ASPP and writes an FP32 model you can use as a quality baseline prior to quantization.
Before lowering the model, consider your answers to these questions:
- Do you expect LR-ASPP MobileNetV3 to be delegated as one XNNPACK partition or split across several partitions?
- What sort of operators might remain outside XNNPACK?
- What evidence would show that the main segmentation work was delegated?
Run the lowering and delegation script:
module-3-executorch-on-android-semantic-segmentation/scripts/aot/lower_lraspp_xnnpack.py \
--spec module-3-executorch-on-android-semantic-segmentation/artifacts/lraspp_mobilenetv3/model_spec.json \
--backend xnnpack
TorchVision segmentation models return a dictionary. The wrapper returns only
the out logits tensor, giving the exported program a single output tensor
with a fixed [1, 21, 520, 520] shape that the Android code can read directly:
def forward(self, image):
return self.inner(image)["out"]
The remaining export and XNNPACK lowering sequence is the same as in Module 2:
example_inputs = (torch.randn(*spec["input"]["shape"]),)
with torch.inference_mode():
exported = export(model, example_inputs)
program, delegation = lower_xnnpack(exported)
write_pte(program, out)
lower_xnnpack() applies XnnpackPartitioner, whereas to_executorch() creates
the .pte program. Look inside the scripts to see the underlying ExecuTorch API, covered in the earlier modules.
Check the artifact size and delegation summary:
PTE size: 12.90 MB
Delegation
==========
XNNPACK delegate call sites: 1
Fallback call_function ops: 33
<built-in function getitem> (1)
<function alloc> (16)
dim_order_ops._to_dim_order_copy.out (16)
The 12.90 MB file is the FP32 baseline for the later INT8 comparison. One delegate call suggests that XNNPACK captured the main LR-ASPP workload in one region. The fallback operations handle output selection, allocation, and layout conversion around that region.
Course complete
Nice work
You completed Optimize and deploy AI inference with ExecuTorch on Arm.