Library / SDK
sonos/tract avatar
sonos/tract

tract writes its serialisation version into the model and then declines to check it

Tiny, no-nonsense, self-contained, Tensorflow and ONNX inference

3,137 stars308 forksRustLicense varies

At a glance

What is it?
A neural network inference engine written in Rust, shipped by its own maker inside shipped speakers for wake-word and streaming speech work. It imports two model formats but can only write one, its runtime selector cannot tell a browser from a CPU, and its compatibility rule is narrower than the enforcement it ships with.
Who is it for?
tract suits a team shipping a fixed model to a known fleet of devices, where converting once at build time and shipping a two-crate runtime beats carrying a training framework into production. Before adopting it, check five things.
Can I use it commercially?
Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • sonos/tract3,137 ★ · +63
Star history
Repository2026-09-242026-11-25
sonos/tract3.1k3.1k

63 Stars in the last 62 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The runtime selector cannot tell a browser from a CPU

The runtimes table has four rows and three distinct names, and the duplicate is the interesting one.

The CPU row is named default and covers several instruction sets, including a vector extension for ARM. The browser row is also named default, and its implementation column says it goes through the standard WebAssembly targets rather than naming a crate.

So the string you pass to select a runtime does not distinguish running in a browser from running on a processor. The same name covers both, and what actually differs is the compilation target and the set of kernels linked in. That is a defensible design: the graph being executed is identical, and only the arithmetic beneath it changes. But it means the sample code's selector cannot tell you where the code ended up, and a deployment that assumed the name was diagnostic would be wrong.

The CPU row also names its crate and describes its kernels as hand-rolled rather than delegating to an external linear algebra library. That is the concrete form of the self-contained claim in the project's one-line description, and it is the reason the same binary can target a speaker, a workstation and a browser without dragging in a vendor library.

There is a fourth accelerator directory in the repository that the table does not name as a runtime. So the tree is one backend ahead of the documentation, which is a small sign that the runtime list lags the implementation.

What ties the rows together is stated once and matters more than the individual entries: every runtime shares one typed intermediate representation and the same model loaders, which is what lets a model optimised on one platform be moved to another.

Two formats load and only one of them can be written back

The format table has four rows and two columns, and the asymmetry between the columns is the design.

One format loads and cannot be saved. That is the primary interchange format for imported models, and the runtime explicitly avoids carrying its serialisation machinery.

A second format loads and saves, and it is the one the project produces. It is a neural network exchange format, extended with the operators needed to express a full model in this engine's own intermediate representation.

Two legacy formats are listed as load-and-save in one case and load-only in the other. A frozen graph from the first generation of the training framework is import-only, and the readme explains why it still exists: it is the operator set that drove the project's original design, the classical vision and wake-word models of a few years ago.

The runtime's claim to smallness follows directly from that table. If the deployment artefact is written in the one writable format, the runtime needs neither a serialisation library for the import format nor a loader for any training framework. The readme says exactly that, naming the two things it avoids.

There is also a converter maintained alongside the project that goes directly from a PyTorch export to the writable format, described as useful when you want to skip the detour through the import format entirely. So the import format is an entry point, not a destination.

The compatibility rule is narrower than the enforcement

This is the sharpest thing in the readme, and it is a stability section that ends by declining to enforce itself.

The parts of the serialisation format that belong to the exchange standard are described as tied to that specification and very stable. The project's own extensions to it are described as more unsettled, and then a rule is offered. It is written as an observation rather than a guarantee: a model serialised by one version should work with a later version in the same minor line, provided the later one is at least as new.

The rule is therefore patch-level within a minor. A model written by one minor version and read by the next minor version falls outside it.

Then the implementation detail, stated in the same paragraph. Models embed a property identifying which version of the engine serialised them. And the engine does not check it.

So the version is written, and reading it is left to the application. That is a deliberate choice, and it has a clear consequence: a model generated by an older minor loads into a newer one silently, with no error and no warning, even though the rule the project states would not cover that case. A deployment that upgrades the engine and keeps old artefacts will not find out until something is wrong at run time.

The readme points at the change log for the running list of notable changes to the serialisation format, which is the right place to look, and the whole question is why the check was left to the caller rather than made a load-time error.

Pulsification moves the work to translation time

The feature that connects this engine to its stated production use is called pulsification, and it is a translation step rather than a runtime mode.

A network that operates on whole sequences, which is how it comes out of training, is translated into one that processes a fixed-size pulse along its streaming axis at each step. The same trained weights then serve batch evaluation and low-latency streaming from one artefact.

The readme is explicit about where the work happens. The translation logic lives in one crate, and the runtime ships only a much smaller companion crate. So the pass that rewrites the graph is a build-time concern, and what reaches the device is small.

That is the whole translate-once argument in one paragraph, and it is why the streaming use cases named are wake-word detection and streaming speech recognition: both are fixed-utterance or fixed-window problems where a pulse along one axis is a natural fit, and both have to run on hardware where the full sequence graph would be wasteful.

The readme also points at a design document for the engineering view and at a working example for the streaming speech case, which is the right pairing: the concept is unusual enough that it needs both an explanation and something you can run.

What is not stated is how the pulse length is chosen, or what happens to models whose streaming behaviour depends on seeing the full sequence, and those are the two questions a reader adopting this would need answered.

One crate is the public surface and the rest are declared unstable

The stability policy is stated in two sentences and is unusually clear about where the boundary sits.

One crate is named as the authoritative public API, and the readme gives its path in the source tree so you can find the module rather than guess at it. Every internal crate is named as not a stable surface and something that should not be depended on directly. The list given covers the core, the exchange-format crate and the import crate, which is to say the three you would most plausibly want to reach for.

That is a better answer than most multi-crate workspaces give, because it tells you the failure mode of ignoring it: you will get no stability commitment, and a patch release inside a minor can change those crates.

The pipeline the readme demonstrates is four calls, and the third of them is where the runtime is chosen:

rust
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()?])?;

Load, convert into the engine's model type, select a runtime by name, then prepare and run. The inline comment on the prepare step is the only place the readme explains what compilation actually happens.

The repository holds five API surfaces rather than one. Alongside the Rust crate there is a foreign function interface, a proxy with a system-specific subdirectory, and a Python package. So the same engine is reachable four ways, and only one of them is the supported entry point.

The Python package is described as built on the same Rust core, with an API that mirrors the Rust pipeline: load, set input facts, optimise, run. The mention of input facts is the one piece of vocabulary the readme uses without defining, and it is the concept the typed intermediate representation is built around.

A default build skips the graphics backends and the Lite format

The workspace manifest lists around fifty-five member crates, and then lists a different, smaller set as the default members.

The comment above the second list explains what was removed: the Metal backend, its test crate, the CUDA backend, its test crate, and the Lite format, because those are described as problematic on specific targets. The word problematic is misspelled in the comment, which is the kind of detail that tells you the file is edited by hand and has been for a long time.

The practical effect is that a plain build of the workspace does not compile the graphics backends or the Lite importer. If you are targeting a GPU you have to name those members, which means your build command differs from the obvious one, and nothing at the root says so.

The testing arrangement is the more impressive half. There are thirteen separate crates under a test directory, and they are organised by concern rather than by component: an infrastructure crate, three suites, and then one crate per thing that can fail differently, covering half precision, each of the three graphics backends, the unit core, the pulse core, the import core, a serialisation round-trip cycle, and the Lite format.

So the GPU paths and the Lite path have dedicated test crates that the default build does not run. That is a sensible way to keep a plain build fast on a laptop, and it means the backends are tested explicitly rather than incidentally, provided someone remembers to select them.

Deployment is two steps and the second one is two crates

The recommended workflow is numbered, and the numbering is the point: step one happens once, at build time, and step two happens on every device.

Step one converts a model from any of the import formats into the writable one, using the command line tool. The invocation takes the source file, a subcommand named dump, a flag naming the output format, and an output filename ending in a compressed archive extension rather than a plain model file.

Step two is what you ship. Two crates are named as the baseline, with two conditional additions: one if the model uses operators that only exist in the import format, and one if the model was pulsified.

That is the entire deployment surface, and it is short enough to read twice. The two conditional crates are the interesting part: they are exactly the two features that would otherwise force you to carry the import loader and the translation pass into production. A model that uses only shared operators and needs no streaming ships two crates and nothing else.

The command line tool has its own recipes page in the documentation, which suggests the conversion step has more than one form. The engineering blog carries a long-form post on the internals for anyone who needs to go further than the readme goes.

The example table in the readme, by contrast, lists seven rows of workload demos. The repository's examples directory holds more than twice that, including several PyTorch-based ones that the table does not mention at all, which is a reminder that the documentation is a selection rather than an index.

Editorial conclusion

tract suits a team shipping a fixed model to a known fleet of devices, where converting once at build time and shipping a two-crate runtime beats carrying a training framework into production. Before adopting it, check five things. Plan to check the serialisation version yourself, because the engine records which version wrote a model and then states that it does not verify it, so a model written by an older minor loads without complaint. Convert to the one writable format rather than shipping an import format. Do not expect the runtime name to tell you where you are, since the browser and the CPU share one name and differ only by compilation target. Pin the crate, not the internal ones, which the readme explicitly declares unstable. And note that a plain workspace build skips the graphics backends and the Lite format, so test those paths deliberately.

Frequently asked questions

What is Sonos' tract?

A neural network inference engine written in Rust that loads models in two interchange formats, optimises them, and runs them on processors, on graphics hardware, or compiled to WebAssembly. The readme says it runs in production inside Sonos products for wake-word detection and streaming speech recognition.

Which model formats can tract write back out?

Only the exchange format and its project-specific extensions. The primary interchange format loads but cannot be saved, and the first-generation frozen-graph format is also import-only. The readme notes that shipping the writable format avoids carrying a serialisation library or any training-framework loader at runtime.

Does tract check the version of a saved model when loading it?

No. Models embed a property naming the engine version that serialised them, and the readme states plainly that the engine does not enforce a version check, leaving it to the application. The rule it does state is that a model serialised by one version works with a later one in the same minor line.

How do I choose a runtime in tract?

By name, at run time. The processor runtime and the WebAssembly runtime share one name and differ by compilation target, so the name alone does not tell you where the code is running. All runtimes share one typed intermediate representation and the same loaders.

Which tract crates are safe to depend on?

The single crate the readme names as the authoritative public API, whose source path it gives. It explicitly says the internal crates, listing the core, the exchange-format crate and the import crate among them, are not a stable surface and should not be depended on directly.

What is pulsification in tract?

A translation that turns a network operating on whole sequences into one processing a fixed-size pulse along its streaming axis at each step, so one artefact serves both batch and low-latency streaming. The translation runs at build time; the runtime ships only a small companion crate.

Official sources

  1. Issues
  2. README
  3. Releases
  4. sonos/tract on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/sonos-tract.svg)](https://hysenlabs.com/projects/sonos-tract)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/sonos-tract.svg)](https://hysenlabs.com/projects/sonos-tract)

Was this useful?