Skip to main content

Crate onnx_std

Crate onnx_std 

Source
Expand description

§onnx-std

A pure-Rust ONNX standard library — model I/O, textual format, and an extensible validator — built on the shared runtime IR. This is the first wave of the design captured in docs/ONNX_RS.md.

§Relationship to the rest of the workspace

onnx-std does not define its own IR. Per ONNX_RS §4.1 (“Shared Crate”), the Graph / Node / Value / Tensor / WeightRef types are reused verbatim from onnx_runtime_ir, and the protobuf parse/encode stack is reused from onnx_runtime_loader. onnx-std is the standard-library layer on top: ergonomic model I/O, a human-readable text format, and a checker — the concerns the design assigns to the ONNX library rather than the inference runtime.

onnx-std  ──(standard lib: load/save/print/check)
   │
   └─ depends on ─▶ onnx-runtime-ir      (shared Graph/Node/Value IR)
   └─ depends on ─▶ onnx-runtime-loader  (protobuf serde + weight mmap)

§What this wave covers

ONNX_RS §FeatureStatus
§3.4 / §4load_model / save_model round-trip
§5Model::to_text / Model::from_text
§7schema op schemas and opset-aware registry
§8check::OnnxChecker extensible validator✅ (schema-aware)
§9shape::infer_shapes symbolic shape inference
§10version::VersionConverter opset conversion
§6.2textproto protobuf TextFormat I/O

JSON and protobuf TextFormat are descriptor-driven from the exact vendored ONNX proto, so every bound message, field, oneof, and enum is covered. The readable text DSL appends a protobuf-TextFormat extension containing only fields outside the graph syntax. The parsed DSL is authoritative for every field it represents, while the explicit extension preserves the remainder.

Deferred to later waves (see // FOLLOW-UP markers): the complete operator catalog, remaining function/IR-gate checker rules, custom-op registration (§11), and Python bindings (§12). Training semantics are out of scope.

§Example

let model = onnx_std::load_model("model.onnx")?;
println!("{}", model.to_text());
let report = model.validate();
assert!(report.is_valid());
onnx_std::save_model(&model, "roundtrip.onnx")?;

Re-exports§

pub use check::OnnxChecker;
pub use check::Severity;
pub use check::ValidationResult;
pub use check::ValidationRule;
pub use check::Violation;
pub use schema::AttributeDefault;
pub use schema::AttributeSpec;
pub use schema::AttributeType;
pub use schema::InputSpec;
pub use schema::OpSchema;
pub use schema::OutputSpec;
pub use schema::SchemaError;
pub use schema::SchemaRegistry;
pub use schema::TypeConstraint;
pub use shape::ShapeInferenceResult;
pub use shape::infer_shapes;
pub use text::PrintOptions;
pub use text::from_text;
pub use text::to_text;
pub use text::to_text_with;
pub use version::AdaptResult;
pub use version::ConvertError;
pub use version::ConvertReport;
pub use version::IncompatibleOp;
pub use version::OpAdapter;
pub use version::VersionConverter;
pub use onnx_runtime_ir as ir;

Modules§

check
Extensible model checker / validator (ONNX_RS §8).
json
Canonical descriptor-driven ONNX protobuf JSON interchange.
schema
Declarative operator schemas and an opset-aware registry (ONNX_RS §7).
shape
Symbolic shape inference over the shared runtime IR (ONNX_RS §9).
simple_sharded_dim_proto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
text
Textual representation of ONNX models (ONNX_RS §5).
textproto
Descriptor-driven ONNX protobuf TextFormat (.onnxtxt / .pbtxt).
version
Opset version conversion with composable per-operator adapters (ONNX_RS §10).

Structs§

DeviceConfigurationProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
IntIntListEntryProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
Json
Canonical protobuf JSON mapping (ONNX_RS §6).
Model
An owned ONNX model: the shared-IR Graph plus the model-level metadata and (optionally) the live weight store backing external initializers.
ModelMetadata
Model-level metadata that the IR Graph does not itself carry.
NodeDeviceConfigurationProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
ShardedDimProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
ShardingSpecProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
SimpleShardedDimProto
Generated ONNX IR v13 multi-device/sharding protobuf model types.
Text
The human-readable ONNX text DSL (ONNX_RS §5).
TextProto
Protobuf TextFormat (.onnxtxt / .pbtxt) (ONNX_RS §6).
WeightStore
A resolved set of initializer weights, keyed by the value they populate, plus the live memory maps backing any external data files.

Enums§

Error
An error produced by an onnx-std operation.
ShapeError
An error produced while inferring shapes.

Traits§

TextCodec
A textual serialization format for Model.

Functions§

load_model
Load an ONNX model from a .onnx protobuf file (ONNX_RS §3.4).
save_model
Save a Model to a .onnx protobuf file (ONNX_RS §3.4).

Type Aliases§

OpaqueProto
ONNX-ML opaque type payload (TypeProto.opaque_type, field 7).
Result
The result type used throughout the onnx-std public API.