Expand description
§RunNX: A Minimal ONNX Runtime in Rust
This crate provides a minimal, verifiable implementation of an ONNX runtime focused on educational purposes and simplicity while maintaining performance.
§Key Features
- Dual Format Support: Both JSON and binary ONNX protobuf formats
- Auto-detection: Automatic format detection based on file extension
- Simple Architecture: Easy to understand and extend
- Type Safety: Leverages Rust’s type system for memory safety
- Performance: Efficient tensor operations using ndarray
- Verifiable: Comprehensive tests and clear documentation
§Quick Start
use runnx::{Model, Tensor};
use ndarray::Array2;
// Load a model (supports both JSON and ONNX binary formats)
// let model = Model::from_file("model.onnx")?; // Auto-detects format
// let model = Model::from_file("model.json")?; // Auto-detects format
// Create a simple tensor
let input = Tensor::from_array(Array2::from_elem((2, 3), 1.0));
let weights = Tensor::from_array(Array2::from_elem((3, 4), 0.5));
// Perform matrix multiplication
let result = input.matmul(&weights)?;
println!("Result shape: {:?}", result.shape());
§Format Support
RunNX supports both formats with automatic detection:
- JSON Format (
.json
): Human-readable, easy to debug - ONNX Binary (
.onnx
): Compact, standard ONNX protobuf format
use runnx::Model;
// Auto-detection based on extension
let json_model = Model::from_file("model.json")?;
let onnx_model = Model::from_file("model.onnx")?;
// Explicit format specification
let json_model = Model::from_json_file("model.json")?;
let onnx_model = Model::from_onnx_file("model.onnx")?;
// Save in different formats
json_model.to_onnx_file("converted.onnx")?;
onnx_model.to_json_file("converted.json")?;
§Architecture Overview
The runtime consists of several core components:
Model
- ONNX model representationGraph
- Computational graph with nodes and edgesTensor
- N-dimensional array with type safetyoperators
- ONNX operation implementationsruntime
- Execution engine
§Error Handling
All operations return Result
types with descriptive error messages.
The main error type is OnnxError
which covers various failure modes.
Re-exports§
pub use error::OnnxError;
pub use error::Result;
pub use graph::Graph;
pub use graph::Node;
pub use model::Model;
pub use runtime::Runtime;
pub use tensor::Tensor;
pub use ndarray;
Modules§
- converter
- Conversion utilities between internal representations and ONNX protobuf format
- error
- Error handling for the ONNX runtime
- formal
- Formal specifications and contracts for RunNX
- graph
- Computational graph representation
- model
- ONNX model representation and loading
- operators
- ONNX operator implementations
- proto
- Generated protobuf definitions for ONNX
- runtime
- Runtime execution engine
- tensor
- Tensor implementation for ONNX runtime
Constants§
- VERSION
- Version of the RunNX crate