tract

sonos活跃维护

用 Rust 写的轻量级推理引擎,能直接跑 TensorFlow 和 ONNX 模型,无需额外依赖,适合在边缘设备或嵌入式场景部署神经网络。

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

v0.23.10发布于 2026-11-05 10:55 UTC3,116star +4 / 7 天300fork同步于 2026-11-10 11:42 UTC

怎么上手

由 README 提炼,执行前请确认
pip install tract
硬件要求按 README 说明

CPU 运行时覆盖 x86、ARMv6/7/8 与 ARM SVE,可在嵌入式 ARM 板、RISC-V、x86 桌面及浏览器 WebAssembly 上运行;GPU 支持 Apple Metal 与 NVIDIA CUDA。README 未给出具体显存要求。

支持 Apple Silicon需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Sonos 出品的自包含神经网络推理引擎,加载 ONNX/NNEF 模型并优化后跑在嵌入式到 GPU 各种平台

用 Rust 写的轻量级推理引擎,能直接跑 TensorFlow 和 ONNX 模型,无需额外依赖,适合在边缘设备或嵌入式场景部署神经网络。

核心能力

  • 加载 ONNX、NNEF、TFLite 与 TF1 frozen graph 模型
  • prepare() 阶段优化并编译模型到目标运行时
  • 提供 CPU、Metal、CUDA、WebAssembly 多种运行时
  • 支持 pulsification 把整段模型转为定长脉冲流式推理
  • 可用 CLI 把模型转成 NNEF 以精简运行时体积

容易踩的坑

Rust 侧要求 rustc >= 1.91.0;内部 crate(tract-core、tract-onnx 等)不是稳定 API,应只依赖 tract 主 crate;TensorFlow 2 模型不被直接支持,需先转成 ONNX。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.23.10
  1. v0.23.10tract 0.23.10最新正式版2026-11-05 · 2026-11-05 10:55 UTC

    这个版本没有写更新说明。

  2. 0.21.192026-10-15 · 2026-10-15 13:33 UTC

    这个版本没有写更新说明。

  3. 0.22.52026-10-15 · 2026-10-15 13:22 UTC

    这个版本没有写更新说明。

  4. v0.23.9tract 0.23.92026-10-15 · 2026-10-15 12:37 UTC

    这个版本没有写更新说明。

  5. v0.23.8tract 0.23.82026-09-21 · 2026-09-21 09:36 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    tract-logo

    Rust rustc >= 1.91.0 MIT/Apache 2 Native Linux test status Embedded targets status Doc Python Ask DeepWiki

    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).

    Quick start

    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

    examples/ has runnable demos covering the workloads tract targets today:

    ExampleWhat
    onnx-mobilenet-v2Minimal CV starter
    tflite-mobilenet-v3TFLite import path
    causal_llmTransformer text generation
    nemo-parakeet-asr / nemo-nemotron-streaming-asrSpeech recognition, including streaming via pulsification
    stable-diffusion / stable-diffusion-3 / stable-diffusion-xlText-to-image
    face_detection_yolov8onnx_example / face_similarity_arcface_onnxModern object detection / face recognition
    wasm-model-benchRunning tract in the browser

    Resources

    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.

    Python

    tract is also available as the tract package on PyPI, built on top of the same Rust core:

    pip install tract
    

    The API mirrors the Rust pipeline: load a model, set input facts, optimise, then run. Documentation: sonos.github.io/tract. Source lives in api/py/.

    Runtimes

    RuntimeNameCrateNotes
    CPU (x86, ARMv6/7/8, ARM SVE)"default"tract-linalgDefault. Hand-rolled SIMD micro-kernels.
    Apple Metal"metal"tract-metalApple GPUs.
    NVIDIA CUDA"cuda"tract-cudaNVIDIA GPUs.
    WebAssembly"default"via standard wasm32 targetsBrowser / WASI deployment.

    All runtimes share the TypedModel IR and the same loaders, so a model optimised on one platform can be moved to another.

    Benchmarks

    Every night, main is benchmarked on a fleet of devices — Cortex-A7 to Cortex-A55 boards, RISC-V boards, x86 and Apple desktops, NVIDIA and Apple GPUs, and WebAssembly — over wake-word, speech recognition, speech enhancement, vision and LLM models. The bench page tracks every model on every device. A few of the trends:

    ModelTargetSpeedTrend
    GTCRN speech enhancementCortex-A5512.1× since Aug 2026GTCRN speech enhancement on Cortex-A55
    MobileNet v2, multi-threadCortex-A533.2× since Aug 2026MobileNet v2, multi-thread on Cortex-A53
    Parakeet TDT 0.6B preprocessorIntel i9-11900KB14.7× since Jun 2026Parakeet TDT 0.6B preprocessor on Intel i9-11900KB
    Llama 3.2 3B text generationApple M1 Max, Metal1.8× since Apr 2025Llama 3.2 3B text generation on Apple M1 Max, Metal

    Speed is relative to the first week of each series, dashed line at 1×. doc/bench/sparklines.py regenerates the charts.

    Streaming and pulsification

    tract has first-class support for pulsified inference: a network that operates on full sequences during training is translated into one that processes a fixed-size pulse along its streaming axis at each step. This lets the same model serve both batch evaluation and low-latency real-time inference (wake-word, streaming ASR, ...).

    The translate-time logic lives in tract-pulse; runtime ships only the small tract-pulse-opl crate. See doc/overview.md § Streaming and pulsification for the engineering view, and examples/nemo-nemotron-streaming-asr for a working demo.

    Formats and tract-OPL

    FormatLoadSave
    ONNX✓—
    NNEF (+ tract-OPL extensions)✓✓
    TensorFlow Lite (legacy)✓✓
    TensorFlow 1 frozen graph (legacy)✓—

    PyTorch models can be exported directly to NNEF using torch-to-nnef (source), an open-source PyTorch-to-NNEF converter maintained alongside tract — useful when you want to skip the detour through ONNX.

    tract-OPL is an NNEF-compatible intermediate representation that extends NNEF with the operators needed to express a full tract-core model. The recommended deployment workflow is:

    1. Once, at build time: convert from ONNX / TF / TFLite to NNEF using the tract CLI:
      tract model.onnx dump --nnef model.nnef.tgz
      
    2. At runtime: ship only tract-core + tract-nnef, plus tract-onnx-opl if the model uses ONNX-only operators, and tract-pulse-opl if it is pulsified.

    This keeps the runtime footprint small (no protobuf, no training-framework loaders). See doc/intro.md for the full design rationale.

    tract-OPL stability

    NNEF parts are tied to the NNEF specification and very stable. tract-OPL extensions are a bit more in flux, but we observe the rule:

    A model serialised with tract 0.x.y should work with tract 0.x.z where z >= y.

    Models embed a tract_nnef_ser_version property identifying the generating tract version; tract itself does not enforce a version check, so it is up to the application to do so if needed. See CHANGELOG.md for the running list of notable serialisation-format changes.

    TensorFlow 1 (legacy)

    tract still loads TF1 frozen graphs and supports the operator set needed for the classical CV and wake-word models that originally drove its design (Inception v3, Snips wake words, ...). TensorFlow 2 is not directly supported — convert to ONNX first.

    License

    Files in tensorflow/protos are copied from the TensorFlow project and files in onnx/protos from the ONNX project; neither is covered by the licence statement below.

    Apache 2.0 / MIT

    All original work is licensed under either of

    at your option.

    Contribution

    Unless you explicitly state otherwise, any Contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.