Skip to content
imaged

Prepare a model

Convert, describe, benchmark, and choose precision.

This page is for the person who turns a trained model into a .slab file that apps can ship. It covers what the file contains, how conversion works, and the decisions the model author makes.

What a .slab file is

One file holds everything an app needs to run the model:

  • The graph: the model's operations with fixed input shapes, already simplified (shape arithmetic is computed, reshapes become views).
  • The weights: aligned for fast loading, with integrity hashes. They can be stored as FP32, FP16 or int8.
  • Metadata: the author's settings. Apps read them automatically when they open the model.

Because the file describes itself, an app developer only opens it and passes an image or tensors. Getting preprocessing, labels, backend and precision right is the model author's job, and it is done once, in the file.

The workflow

  1. Export. Export the trained model to ONNX (opsets 11–20). Language and vision-language models are converted directly from their original checkpoint instead.
  2. Check. A dry run of slab-load convert lists the model's inputs and every operation Slab cannot run, before anything is written. The support matrix shows which operations each backend runs.
  3. Convert. slab-load convert writes the .slab file. You fix each input's shape here (an unset batch size is 1), and can add metadata and a default backend in the same step.
  4. Describe. Add or change metadata at any time with slab-load meta (set, get, delete), without converting again.
  5. Verify. slab-load run runs the model on a chosen backend with your own input tensors and writes the outputs, so you can compare them with your reference framework. slab-load bench measures speed.
  6. Choose precision. See below.
  7. Optional: shrink and protect. slab-load quantize stores the large weights as int8 (2.4–3.7× smaller). slab-load protect encrypts the file with your key.

Metadata you set

Setting What it does in the app
Task (classify, embed, detect, segment, upscale) Enables the matching ready-made results: top classes, decoded boxes, normalized embeddings, image output
Labels (one per line, from a text file) Class names in results
Resize (stretch, letterbox, center crop) and letterbox padding How an image is fitted to the input size
Color order (RGB or BGR) Channel order of the input tensor
Normalization (a preset, or scale, mean and std) How pixel values are turned into input values
Default backend, overall or per platform Which backend the app uses by default
Precision per backend Which precision each backend runs

App developers can override preprocessing in code, but the file's settings are the defaults everyone gets.

Backend preference

You know your model, so the file states its preferred backend. You can set a different one per platform, for example the GPU on Apple and the CPU on Android for a small model. On a device that cannot honor the preference, Slab takes the first backend, in the order NPU → GPU → CPU, that the device has and that runs the whole model. A model always runs entirely on one backend; its operations are never split between backends.

Precision

Precision is chosen per backend, and only by you. Slab never lowers it on its own.

Value Meaning
f32 Full precision. The default.
f16 16-bit storage, 32-bit math
f16:fast 16-bit storage and math
int8 int8 weights; activations quantized at run time
int8:static int8 weights; activations with calibrated scales
int8:f16 int8 weights, 16-bit activations

How to choose:

  1. Sweep. slab-load sweep runs every precision a backend offers on your input. For each it reports the speed and the similarity of the output to full precision.
  2. Calibrate. For int8:static and int8 on the NPU, give slab-load precision a few representative inputs to measure activation ranges.
  3. Set. slab-load precision writes your choice per backend into the file. Separate settings exist for the CPU, the GPU (with separate Vulkan and Metal overrides) and the NPU.

Accuracy loss depends on the model. Some models keep near-full accuracy at int8; others need int8:f16. Always measure on your own data. If a device cannot run the precision you chose, the session fails with a clear reason. Slab does not substitute another precision.

Protected models

slab-load protect encrypts the weights with a key you hold. Apps then supply the key, or a license token Slab verifies on the device. Protected models run on the CPU and GPU. You can also rekey a protected file, or remove protection with the key.