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::encode_model;pub use encoder::encode_model_proto;pub use encoder::write_model;pub use encoder::Model;pub use encoder::ModelMetadata;pub use encoder::DEFAULT_IR_VERSION;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 epcontext::EmbedMode;pub use epcontext::EpContextBlob;pub use epcontext::EpContextNode;pub use weights::WeightStore;pub use writer::dump_ep_context;pub use writer::EpContextDumpConfig;pub use writer::EpContextPartition;
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).- graph_
builder - Build an
onnx_runtime_ir::Graphfrom a decodedModelProto(§19.1). - 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.