pub fn validate_model(graph: &Graph) -> Result<(), LoaderError>Expand description
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).
This is the single cohesive entry point wired into both load paths — the
disk/bytes loader ([build_from_bytes_with_weights]) and the session’s
programmatic entry ([onnx_runtime_session]’s from_parts/from_graph) —
so the checks cannot drift between the two. It runs, in order:
Protobuf-only invariants (ir_version, raw SSA names, ref_attr_name,
subgraph shadows, and output names) run earlier in
validate_model_proto, before graph construction coalesces names or drops
protobuf-only fields. This IR-level phase then runs:
validate_opset_imports— every node’s domain must declare an opset.validate_no_control_flow— allow the implemented subgraph-bearing ops (If/Loop/Scan) and reject any other op carrying aGraphProtoattribute the executor cannot run.validate_no_dangling_refs— every consumed tensor must be sourced (graph input, initializer, or an upstream node output).validate_no_initializer_producer— an initializer must be a constant source; reject any initializer value that is also a node output (shares aValueIdwith a producer), which the IR structural check does not cover.
Each rejection names the offending node/op/tensor and explains what is expected. No sentinel defaults, no silent skips.
Structural invariants that the IR builder already enforces via
onnx_runtime_ir::Graph::validate at build time — duplicate output
names, dangling value ids, producer/consumer link consistency, and data
dependency cycles — are intentionally not re-checked here to avoid drift;
this function adds the checks that path does not cover.