Skip to main content

uor_addr/onnx/
mod.rs

1//! **`uor_addr::onnx` — the ONNX realization of UOR-ADDR.**
2//!
3//! Typed content-addressing for ONNX `ModelProto` files under a
4//! protobuf-canonical structural form. The default σ-projection is
5//! [`prism::crypto::Sha256Hasher`]; [`address_blake3`], [`address_sha3_256`],
6//! [`address_keccak256`], and [`address_sha512`] select the other axes
7//! ([`crate::hash`]).
8//! As with GGUF, the skeleton's leaf commitments are SHA-256 by
9//! canonical-form definition and the selected κ-axis `H` is applied on top
10//! (κ = `H(skeleton)`); the sha256 κ-labels are byte-identical to prior
11//! releases. Admits any known IR revision
12//! (`ir_version` in `1..=`[`ONNX_IR_VERSION_MAX`]`
13//! = 13`, the latest in `onnx.proto`); the `ir_version` is bound into the
14//! canonical form, so distinct revisions of the same logical model
15//! address distinctly.
16//!
17//! ## Authoritative sources
18//!
19//! - ONNX protobuf schema — <https://github.com/onnx/onnx/blob/main/onnx/onnx.proto>
20//! - ONNX IR specification — <https://github.com/onnx/onnx/blob/main/docs/IR.md>
21//! - ONNX versioning — <https://github.com/onnx/onnx/blob/main/docs/Versioning.md>
22//! - Protobuf v3 wire format — <https://protobuf.dev/programming-guides/encoding/>
23//! - SHA-256 σ-projection — NIST FIPS 180-4.
24//!
25//! ## Canonical form
26//!
27//! The ONNX spec defines no canonical form (protobuf v3 admits many
28//! byte-encodings of the same logical message); this realization defines
29//! one (canonical form v3 — [`CANONICAL_FORM_VERSION`]). It is a **flat
30//! skeleton**: the `ModelProto` structure emitted inline (opset imports
31//! sorted by `(domain, version)`, nodes in Kahn-topological order with
32//! lexicographic `(name, op_type, domain, outputs..., canonical_node_digest)`
33//! tie-break, name-sorted
34//! initializers / IO, typed-data-to-`raw_data` reduction, depth-bounded
35//! subgraph recursion emitted inline), in which every variable-length
36//! leaf — tensor data, strings, opaque sub-message payloads — is
37//! represented by its 32-byte SHA-256 digest, so the skeleton's size
38//! grows with structure, not model size, while still binding every weight
39//! byte into the κ-label. See [`value`] for the full byte layout.
40//!
41//! Under ADR-060 the **full skeleton** flows through the pipeline as a
42//! [`TermValue::Borrowed`](prism::operation::TermValue) carrier and ψ₉
43//! folds it through `H = Sha256Hasher` — there is no two-level commitment
44//! and no count / width cap. Two ONNX models that decode to the same
45//! logical content canonicalize to byte-identical skeletons and therefore
46//! to the same κ-label.
47
48pub mod dtype;
49pub mod model;
50pub mod pipeline;
51pub mod protobuf;
52pub mod shapes;
53pub mod value;
54pub mod verbs;
55
56/// Canonical-form version (see module docs). Bumped to 3 to make node
57/// ordering total when `NodeProto.name` is empty by extending the
58/// topological tie-break with output tensor names and a canonical node
59/// digest fallback. This is a compatibility break: models with previously
60/// ambiguous `(name, op_type, domain)` ties can now receive different
61/// κ-labels than canonical-form v2.
62pub const CANONICAL_FORM_VERSION: u32 = 3;
63
64pub use dtype::OnnxDataType;
65pub use model::{
66    AddressModel, AddressModelBlake3, AddressModelKeccak256, AddressModelSha3_256,
67    AddressModelSha512, AddressRoute,
68};
69#[cfg(feature = "alloc")]
70pub use pipeline::{address, address_blake3, address_keccak256, address_sha3_256, address_sha512};
71pub use pipeline::{AddressFailure, AddressOutcome, AddressWitness, VerifyError};
72pub use shapes::bounds::{ONNX_IR_VERSION_MAX, ONNX_OPSET_VERSION_MIN, ONNX_SUBGRAPH_DEPTH_MAX};
73pub use value::OnnxCarrier;
74#[cfg(feature = "alloc")]
75pub use value::{canonicalize, OnnxValue};
76pub use verbs::{address_inference, VERB_TERMS_ADDRESS_INFERENCE};
77
78/// The shared, format-independent ψ-tower (re-exported for convenience;
79/// canonical path is [`crate::resolvers::AddressResolverTuple`]).
80pub use crate::resolvers::AddressResolverTuple;