Skip to main content
You can run PyTorch models accelerated on the NPU of your Dragonwing device, for fast and efficient machine learning inference.

Quantizing and converting a model

PyTorch models use 32-bit floating point numbers for their weights and activations. The NPU on your development board only supports 8-bit integers, so PyTorch models must be quantized - converted from floating point to fixed point values. This makes the model smaller and faster to run (and able to run on the NPU), but it has an effect on accuracy. Open the terminal on your development board, or connect via SSH to your board, and follow these steps:
  1. Create a new venv, and install ONNX Runtime and the Python packages used by the example:
  1. Here’s an end-to-end example running SqueezeNet-1.1 from torchvision. Save this file as inference_pytorch_onnx.py:
  1. Run the model on the CPU:
  1. Run the model on the NPU:

Tips and Tricks

Disable CPU fallback

To debug, you might want to choose to disable fallback to the CPU via:

Building new versions of the the onnxruntime package

See: edgeimpulse/onnxruntime-qnn-linux-aarch64.