Expand description
§onnx-runtime-loader
Loads ONNX models from disk into the onnx_runtime_ir::Graph IR
(see docs/ORT2.md §19).
Pipeline (load_model / load_model_with_weights):
proto— decode the ONNX protobuf (prosttypes generated from the vendoredonnx.proto3) into aModelProto.- [
graph_builder] — build anonnx_runtime_ir::Graph(nodes, values, symbolic dim interning, opset imports), upholding the §3.5 invariants. weights— resolve inline and external initializer data (external files are memory-mapped into aWeightStore).- Static/symbolic shape inference via
onnx-runtime-shape-inference: the loader owns the “loader = shape-inference” seam, so after theGraphis built (with initializers applied) it runs the extensible per-op registry to populate every value’s shape and dtype. Values that cannot be resolved statically (genuinely data-dependent extents) are left symbolic for the session to resolve just-in-time.
§Obtaining weight bytes at session time
Use load_model_with_weights (or load_model_bytes_with_weights) to
receive both the Graph and an Arc<WeightStore>. Then, given any
onnx_runtime_ir::WeightRef stored in graph.initializers, call
WeightStore::bytes to get the raw little-endian byte slice:
ⓘ
let (graph, store) = load_model_with_weights("model.onnx")?;
for (vid, weight_ref) in &graph.initializers {
let bytes: &[u8] = store.bytes(weight_ref).expect("weight bytes live");
// ... hand bytes to a kernel
}The Arc keeps all memory maps alive as long as any clone of it exists, so
kernel dispatch can store Arc<WeightStore> alongside the Graph without
lifetime coupling.
Re-exports§
pub use encoder::DEFAULT_IR_VERSION;pub use encoder::Model;pub use encoder::ModelMetadata;pub use encoder::encode_model;pub use encoder::encode_model_proto;pub use encoder::write_model;pub use epcontext::EmbedMode;pub use epcontext::EpContextBlob;pub use epcontext::EpContextNode;pub use epcontext::ep_context_node_ids;pub use epcontext::ep_context_nodes;pub use epcontext::is_ep_context_op;pub use epcontext::resolve_ep_context;pub use weights::WeightStore;pub use writer::EpContextDumpConfig;pub use writer::EpContextPartition;pub use writer::dump_ep_context;
Modules§
- encoder
- ONNX protobuf encoding — the inverse of
graph_builderandweights(§19.1, §55.4 dump path). - epcontext
com.microsoft::EPContextnode support — the load path (§55.3).- function_
inline - Model-local function inlining (ONNX function expansion) at load time.
- proto
- ONNX protobuf decoding (§19.1).
- weights
- Initializer weight resolution: inline data and external
mmap(§19.2, §12). - writer
com.microsoft::EPContextdump / writer path (§55.4) — the inverse of the load path incrate::epcontext.
Enums§
- Loader
Error - Errors produced while loading an ONNX model.
Functions§
- load_
model - Load a model from a filesystem path, producing a fully-built
Graph. - load_
model_ bytes - Load a model from an in-memory protobuf buffer, producing a
Graph. - load_
model_ bytes_ with_ weights - Load a model from an in-memory protobuf buffer, returning both the
Graphand the liveWeightStorethat backs all initializer data. - load_
model_ with_ weights - Load a model from a filesystem path, returning both the
Graphand the liveWeightStorethat backs all initializer data. - validate_
model - Fail-fast, load-time validation of everything statically knowable to be illegal or unsupported (RULES #1: fail at load, never via a silent sentinel at run time).
- validate_
model_ proto - Validate ONNX model metadata and protobuf-level graph invariants that are
intentionally not preserved by the runtime IR (notably
ir_versionandAttributeProto::ref_attr_name). - validate_
no_ control_ flow - Reject subgraph-bearing (control-flow) ops the runtime cannot execute.
- validate_
no_ dangling_ refs - Reject graphs with a node input that has no source.
- validate_
no_ initializer_ producer - Reject graphs where an initializer value is also produced by a node.
- validate_
opset_ imports - ONNX treats
""and"ai.onnx"as equivalent spellings of the default domain. Model-level imports also govern nodes nested in subgraphs.