Skip to main content
LiteRT, formerly known as TensorFlow Lite, is Google’s high-performance runtime for on-device AI. You can run existing quantized LiteRT models (in Python or C++) on the NPU on Dragonwing devices with a single line of code using the LiteRT delegates that are part of AI Engine Direct.
Where do .tflite files come from?

Quantizing models

The NPU only supports uint8/int8 quantized models. Unsupported models, or unsupported layers will be automatically moved back to the CPU. You can use quantization-aware training or post-training quantization to quantize your LiteRT models. Make sure you follow the steps for “Full integer quantization”.
Don’t want to quantize yourself? You can download a range of pre-quantized models from Qualcomm AI Hub, or use Edge Impulse to quantize new or existing models.

Running a model on the NPU (Python)

To offload a model to the NPU, you just need to load the LiteRT delegate; and pass it into the interpreter. For example:

Running a model on the NPU (C++)

To offload a model to the NPU, you’ll first need to add the following compile flags:
Then, you instantiate the LiteRT delegate and pass it to the LiteRT interpreter:

Python examples

Prerequisites
  • Ubuntu OS should be flashed
  • Terminal access with appropriate permissions
  • If you haven’t previously installed the PPA packages, please run the following steps to install them: https://qualcomm-3.mintlify.io/devices/iq9075-evk/update-software/upgrade-ubuntu#4-upgrade-pre-built-packages
  • Open the terminal on your development board, or an SSH session to your development board, create a new venv, and install the LiteRT runtime and Pillow:
  • To prepare the development environment, install the following packages. These packages provide essential components such as GTK bindings, Python development utilities, and build tools required for compiling and running the application effectively.

Vision Transformers

Here’s how you can run a Vision Transformer model (downloaded from AI Hub) on both the CPU and the NPU using the LiteRT delegates.
1

Create inference script

Create inference_vit.py and add the following code:
2

Run on CPU

3

Run on NPU

This model runs significantly faster on NPU — but there’s a slight drop in the accuracy output of the model. You can also see that for this model not all layers can run on NPU (“1382 nodes delegated out of 1633 nodes with 27 partitions”).