onnx-runtime-ir
The Graph intermediate representation (IR) for the ORT 2.0 runtime.
This crate is the stable contract that every downstream runtime crate
(onnx-runtime-loader, onnx-runtime-ep-api, onnx-runtime-session, …)
builds against. It is intentionally pure, safe Rust with no FFI and no
device dependencies so it compiles standalone on any target.
It is a Rust port of the design captured in docs/architecture/ORT2.md §3 (Graph IR),
§5 (Striding & Layout) and §11 (Dynamic Shape), itself inspired by the
Python onnx-ir package.
What lives here
| Concept | Type |
|---|---|
| Element type | [DataType] |
| Symbolic / static shapes | [Shape], [Dim], [SymbolConstraints] |
| Physical strided layout | [TensorLayout], [MemoryFormat] |
| Canonical Einsum planning | [EinsumPlan], [EinsumShapePlan], [EinsumPlanningClassification] |
| Device placement | [DeviceType], [DeviceId] |
| Graph values (SSA edges) | [Value], [ValueId] |
| Graph operations | [Node], [NodeId], [Attribute] |
| Constant / weight storage | [TensorData], [SparseTensorData], [WeightRef] |
| The graph itself | [Graph] |
| Errors | [IrError], [GraphError] |
Design guarantees
- SSA-like: every [
Value] has at most one producer [Node]; node outputs are unique. - First-class layout & device: every value carries a [
TensorLayout] and an optional [DeviceId], unlike upstream ONNX /onnx-ir. - Mutable during optimization: the [
Graph] mutation API keeps producer/consumer edges consistent so optimization passes can rewrite it, then it is shared immutably viaArconce frozen.
Per-op graph shape inference remains in onnx-runtime-shape-inference.
Shared semantic contracts needed by both inference and execution providers,
such as [EinsumPlan] and [EinsumShapePlan], live here so every consumer
validates and classifies an operator exactly once. The Graph operations that are cheap and
foundational (topological ordering, validation, edge rewiring, broadcasting,
stride arithmetic) are likewise fully implemented and unit-tested.