Expand description
oxionnx — Pure Rust ONNX inference engine.
Zero C/C++ dependencies. Supports a wide subset of ONNX operators sufficient to run transformer-based models (BERT, T5, GPT-2 family).
§Quick start
use std::collections::HashMap;
use oxionnx::{Session, Tensor};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let session = Session::from_file("model.onnx".as_ref())?;
let mut inputs = HashMap::new();
inputs.insert("input_ids", Tensor::new(vec![1.0, 2.0, 3.0], vec![1, 3]));
let outputs = session.run(&inputs)?;
Ok(())
}Re-exports§
pub use benchmark_select::benchmark_elementwise;pub use benchmark_select::benchmark_matmul;pub use benchmark_select::benchmark_suite;pub use benchmark_select::format_results;pub use benchmark_select::BenchmarkResult;pub use benchmark_select::ExecutionPath;pub use compat::GraphOptimizationLevel;pub use compat::SessionOutputs;pub use execution_providers::CPUExecutionProvider;pub use execution_providers::CUDAExecutionProvider;pub use execution_providers::CoreMLExecutionProvider;pub use execution_providers::DirectMLExecutionProvider;pub use execution_providers::ExecutionProviderDispatch;pub use execution_providers::OpenVINOExecutionProvider;pub use execution_providers::TensorRTExecutionProvider;pub use io_binding::IoBinding;pub use memory::BufferPool;pub use memory::MemoryPlan;pub use memory::PoolStats;pub use memory::SizeClassPool;pub use memory_tracker::MemoryTracker;pub use session::ModelInfo;pub use session::ModelMetadata;pub use session::NodeProfile;pub use session::OptLevel;pub use session::Session;pub use session::SessionBuilder;pub use tolerance::compare_tensors;pub use tolerance::tensors_close;pub use tolerance::ToleranceReport;pub use typed_session::Shape;pub use typed_session::TypedSession;
Modules§
- benchmark_
select - Benchmark-based execution path selection.
- compat
- Compatibility layer for easy migration from the
ortcrate. - execution_
providers - Execution Provider compatibility layer for migration from
ort. - graph
- io_
binding - Pre-allocated I/O buffer management for zero-copy inference.
- macros
- Convenience macros for building inference input maps.
- memory
- Auto-generated module structure
- memory_
tracker - Peak memory usage tracking for inference runs.
- model
- ops
- opset_
coverage - Opset version coverage report generator.
- optimizer
- Graph optimization passes for ONNX inference. Applied after model loading but before topological sort and execution.
- proto
- session
- tensor
- tolerance
- Numerical tolerance validation for inference results.
- typed_
session - Typed inference API with compile-time shape checking.
Macros§
- define_
shape - Macro to define a shape type.
- inputs
- Build a
Result<HashMap<&str, Tensor>, OnnxError>input map. - inputs_
typed - Build a typed input map for use with
crate::Session::run_typed.
Structs§
- Attributes
- Parsed attributes for a node.
- Graph
- Compute graph produced by parsing an ONNX model.
- Node
- A single computation node in the ONNX graph.
- OpContext
- Runtime context passed to every operator during execution.
- Operator
Registry - Maps ONNX op_type strings to operator implementations.
- Tensor
- N-dimensional tensor with f32 data and a shape vector. Layout: row-major (C order), last dimension varies fastest.
- Tensor
Info - Metadata for a model input or output tensor (parsed from ValueInfoProto).
- Typed
Tensor - A multi-dtype tensor with shape and typed storage.
This complements the existing
Tensor(which is f32-only) for advanced use cases.
Enums§
- DType
- ONNX data types.
- Dim
- A tensor dimension: either a concrete size, a symbolic name, or unknown.
- Error
- Typed error returned by all public
Sessionmethods. - Onnx
Error - Typed error returned by all public
Sessionmethods. - OpKind
- All ONNX operators currently supported by oxionnx.
- Tensor
Storage - Type-erased tensor storage.
Traits§
- Operator
- Trait for ONNX operator implementations. Operators are stateless – all runtime state comes through OpContext.
Functions§
- default_
registry - Build the default operator registry containing all supported ONNX operators.