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
- Export. Export the trained model to ONNX (opsets 11–20). Language and vision-language models are converted directly from their original checkpoint instead.
- Check. A dry run of
slab-load convertlists the model's inputs and every operation Slab cannot run, before anything is written. The support matrix shows which operations each backend runs. - Convert.
slab-load convertwrites the.slabfile. 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. - Describe. Add or change metadata at any time with
slab-load meta(set, get, delete), without converting again. - Verify.
slab-load runruns 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 benchmeasures speed. - Choose precision. See below.
- Optional: shrink and protect.
slab-load quantizestores the large weights as int8 (2.4–3.7× smaller).slab-load protectencrypts 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:
- Sweep.
slab-load sweepruns every precision a backend offers on your input. For each it reports the speed and the similarity of the output to full precision. - Calibrate. For
int8:staticand int8 on the NPU, giveslab-load precisiona few representative inputs to measure activation ranges. - Set.
slab-load precisionwrites 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.