tpt-infer

Rust

Pure-Rust, hardware-agnostic edge AI inference runtime — compile-time tensor shape checking, AOT code generation, zero-allocation execution, and ONNX support. No CUDA, no Python, no C++ toolchains.

0 stars0 forks0 watchersApache License 2.0

Languages

Rust100.0%Python0.0%
README

tpt-infer

Edge AI & Local Inference Runtime · TPT Solutions · MIT / Apache-2.0

CI docs.rs crates.io license

A zero-legacy, hardware-agnostic inference runtime that compiles and executes ML models without CUDA, Python, C++ toolchains, or large C-FFI bindings.

Not yet published to crates.io — the crates.io/docs.rs badges above will go live once the first release is tagged (see todo.md). Until then, depend on this repo directly via a path/git dependency.

┌─────────────────────────────────────────────────────────────┐
│                        tpt-infer                            │
│                     (facade + prelude)                      │
├──────────┬──────────┬──────────┬──────────┬────────────────┤
│   onnx   │ quantize │ compile  │ runtime  │     vision     │
│ (parser) │ (INT8/4) │ (AOT RS) │ (no_std) │ (preprocess)   │
├──────────┴────┬─────┴────┬─────┴──────────┴────────────────┤
│     ops       │   graph  │  core (Tensor, BumpArena, DType) │
│ (HAL + SIMD)  │ (const-  │        #![no_std]                │
│               │  generic)│                                  │
└───────────────┴──────────┴──────────────────────────────────┘

Crates

CrateRole
tpt-infer-coreConst-generic Tensor<T, N>, DType, BumpArena (no_std)
tpt-infer-opsBackend HAL: naive, AVX2, AVX-512, NEON, WASM SIMD, WebGPU
tpt-infer-graphType-state GraphBuilder — shape mismatches are compile errors
tpt-infer-onnxPure-Rust ONNX (opset-17) parser, no C-FFI
tpt-infer-quantizeINT8/INT4 PTQ, per-tensor & per-channel, nibble packing
tpt-infer-compileAOT compiler: graph → optimized static Rust fn
tpt-infer-runtimeZero-allocation execution over BumpArena (no_std)
tpt-infer-visionResize, normalize, letterbox, CHW↔HWC
tpt-infer-clitpt-infer binary: inspect/run/compile a model with no Rust required
tpt-infer-wasmwasm-bindgen JS bindings: load and run ONNX models in the browser/Node.js

Try it without writing Rust

cargo install --path crates/tpt-infer-cli   # from a checkout, until published
tpt-infer inspect your-model.onnx           # node/operator summary + AOT-compile preflight
tpt-infer run your-model.onnx               # execute with a random input, print the output

See crates/tpt-infer-cli/README.md for the full command reference.

Quick start (library)

use tpt_infer::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Load an ONNX model into a computation graph.
    let graph = load("model.onnx")?;

    // 2. Execute it with the interpreted runtime, zero heap allocation
    //    during inference (everything comes from the arena).
    let input = vec![0.0f32; /* ... your model's flattened input ... */ 4];
    let mut mem = vec![0u8; required_arena_bytes(&graph) + 4096];
    let mut arena = BumpArena::new(&mut mem);
    let backend = select_backend();
    let output = execute(&graph, &input, &mut arena, &backend)?;
    println!("top-1 class: {}", argmax(output.as_slice()));

    // ...or ahead-of-time compile it to standalone Rust source instead of
    // interpreting it (when every operator in the graph has codegen support):
    let compiled = aot_compile(&graph)?;
    std::fs::write("generated.rs", compiled.source())?;

    Ok(())
}

This mirrors the tested example in crates/tpt-infer/src/lib.rs (run via cargo test --doc -p tpt-infer), which builds its input graph programmatically with GraphBuilder instead of loading a file, since no real .onnx model ships with this repository.

Feature matrix

FeatureDefaultEnables
ops-cpu✓CPU SIMD backends
ops-webgpuWebGPU via wgpu
onnx✓ONNX model loading
compile✓AOT codegen
runtime✓Execution engine
visionImage preprocessing
quantizeINT8/INT4 PTQ

Building

cargo build --workspace
cargo test --workspace
cargo build -p tpt-infer-core --target thumbv7m-none-eabi   # no_std check
cargo deny check                                            # supply-chain policy (deny.toml)

Security

tpt-infer-onnx and tpt-infer-vision parse untrusted input by design (arbitrary .onnx model files and image bytes). See SECURITY.md for the trust boundary and how to report a vulnerability.

Contributing

See CONTRIBUTING.md.

License

Licensed under either of

at your option.