Go to Map Courses Lab Glossary How it works Troubleshooting Start →
ITEN
← Course 06 · From model to app (Lesson 06.04 · 18 minutes · No sensor · For everyone)

Formats and engines.

LiteRT, Core ML, ONNX Runtime, ExecuTorch, MediaPipe, WebGPU. Here you'll sort out the names, understand what's inside a model file, and see which engines can reach the phone's NPU.

What you learn
  1. What a model file contains and what an inference engine does
  2. Which engines are used on Android, on iPhone and in the browser
  3. How to choose the right engine for a project
You need to know

If you don't remember one of these, the link takes you to the chapter that explains it.

How do you want to follow it
Preparing the scene…
  1. 01 The file and the engine

    A model is a file, and an engine runs it.

    After training, the model is saved to a file. Inside are the weights and the recipe, meaning the order of the operations. To use it on the phone you need a program that reads the file and does the math, and that's the inference01.03 engine. Each engine reads its own formats and decides which part of the chip does the work.

    In practice. Choose the engine before you train. Some operations exist in one format and not in another, and finding that out at the end costs you dearly.

01 / 07
(Go deeper)

A few more numbers.


(01)

What's inside a tflite file

A tflite file is a single block of bytes, laid out so it can be read without being copied, in a format called FlatBuffers. It holds the list of operations, like convolutions and additions, the list of tensors with their shapes, the weights, and for quantized models the scale and zero point of each tensor.

To look inside, there's Netron, a free viewer that also works in the browser. It shows the network as a block diagram, with the shapes of the inputs and outputs. It also reads ONNX and Core ML files, and many other formats.

(02)

Which engine reaches what, on the phone and beyond

The table sums up how each engine reaches the three parts of the chip. On the CPU almost all of them use XNNPACK, a highly optimized library from Google. For the NPU you need pieces written by the companies that make the chip, like Qualcomm, MediaTek or Apple. That's why an NPU can work with one engine and not with another, or only with 8-bit models.

The same models also run outside the phone. On a microcontroller that costs a few euros, with LiteRT for Microcontrollers, a model of a few tens of KB recognizes a gesture or a sound on a small battery. On a Raspberry Pi, a model like the lab's runs with a camera and no screen. On boards with a GPU, like NVIDIA's Jetson, models follow a video in real time.

EngineFileCPUGPUNPU
LiteRTtfliteXNNPACKGPU delegateChip makers' delegates
Core MLmlpackageYesYesNeural Engine
ONNX RuntimeonnxYesYesProviders like QNN and Core ML
ExecuTorchpteXNNPACKVulkan and MetalChip makers' backends
BrowservariousWebAssemblyWebGL and WebGPUNot yet, WebNN is on the way

The tutorials, one for each course →

(03)

Converting without surprises

Every conversion can change the answers a little or a lot. An operation translated in a different way, a color order flipped, a normalization step forgotten. The check is simple. You run the same hundred examples through the original model and the converted one, and compare the outputs.

For models with decimal numbers the differences should be tiny, in the third or fourth decimal place. For quantized ones you check that the chosen class is the same almost every time. If it doesn't match, the problem is almost always in how the input is prepared, not in the engine.

(Try it on your phone)

Inside a real model


Download the model that blurs the background in the segmentation lesson. It's 250 KB. Then open it in Netron, from your phone or your computer, and look for these things in the block diagram.

  1. (01) The input and its shape, an image of 256 by 256 pixels with 3 colors
  2. (02) The output, the mask with a confidence for each pixel
  3. (03) A convolution block, with the size of its filters
  4. (04) The weights of a filter, when you tap the block
  5. (05) The point where the network narrows and then widens again

You've seen the recipe the first chapter talks about. Each block is an operation that the engine has to know how to run on the CPU, the GPU or the NPU.

(Quiz)

4 questions to close the lesson.

When you have answered them all, the lesson counts as done and its stone on the map turns yellow. Answering is what counts, not the score.


  1. (01)

    What does a model file contain?

  2. (02)

    The NPU delegate doesn't support one of the operations. What happens?

  3. (03)

    You're making an app for iPhone only. Which engine is the most natural choice?

  4. (04)

    Why does the course lab use the GPU and not the NPU?

(Next lesson · 06.05) An app that works without a network