Sonos' neural-network inference engine.
tract loads ONNX and NNEF models, optimises them, and runs them anywhere — from embedded ARM CPUs to NVIDIA / Apple GPUs, in the browser via WebAssembly, or on a Linux / macOS / Windows workstation. It is used in production at Sonos for wake-word and streaming speech-recognition workloads, and also runs LLM, text-to-image, and classical CV models with a particular focus on the translate-once / ship-tiny-runtime story enabled by its NNEF-based intermediate format (tract-OPL).
From examples/onnx-mobilenet-v2:
use tract::prelude::*;
tract::impl_ndarray_interop!();
let model = tract::onnx()?
.load("mobilenetv2-7.onnx")?
.into_model()?;
// prepare() optimises and compiles the model for the chosen runtime
let runtime = tract::runtime_for_name("default")?;
let runnable = runtime.prepare(model)?;
let result = runnable.run([input.tract()?])?;The tract crate (api/rs/src/lib.rs) is the authoritative public API. The
internal crates (tract-core, tract-nnef, tract-onnx, ...) are not
stable surface and shouldn't be depended on directly.
For Python, see the tract package on PyPI.
examples/ has runnable demos covering the workloads tract
targets today:
| Example | What |
|---|---|
onnx-mobilenet-v2 |
Minimal CV starter |
tflite-mobilenet-v3 |
TFLite import path |
causal_llm |
Transformer text generation |
nemo-parakeet-asr / nemo-nemotron-streaming-asr |
Speech recognition, including streaming via pulsification |
stable-diffusion / stable-diffusion-3 / stable-diffusion-xl |
Text-to-image |
face_detection_yolov8onnx_example / face_similarity_arcface_onnx |
Modern object detection / face recognition |
wasm-model-bench |
Running tract in the browser |
Technical documentation lives under doc/ (start at doc/intro.md);
the doc/cli-recipe.md page collects practical CLI recipes.
The Sonos engineering blog
has a long-form post on tract internals.
tract is also available as the tract package on PyPI,
built on top of the same Rust core:
