OnnxModelContract

dicechess.engine.model.OnnxModelContract

Checks that a loaded ONNX graph is the graph its manifest promises, before a single row is scored.

The engine feeds a session by name (session.run takes a name → tensor map) and reads the first output by position, so a graph whose input is called something else fails inside the runtime with a message about a missing input, and a graph whose output is a different tensor than expected is scored anyway — the observed cause of the Python/JVM disagreement this contract exists to end (the repository's own older fixtures name their output variable, which the JVM reads by index and the contract now rejects by name).

A width mismatch is the other half: [batch, 27] fed 13 floats is an error, [batch, 13] fed a 13-column row from the wrong schema is not — which is why the schema id is checked in the manifest and the width here. Both must hold.

Attributes

Source
OnnxModelContract.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def validate(session: OrtSession, manifest: ModelManifest): Either[String, Unit]

Validates session against manifest's tensor names and feature width.

Validates session against manifest's tensor names and feature width.

Any runtime failure while reading the graph metadata is reported as a rejection rather than propagated: a caller wiring a model has exactly one decision to make — serve it or refuse it — and an exception from the middle of the check is the same answer with a worse message.

Attributes

Source
OnnxModelContract.scala
def validateTensors(inputs: Vector[OnnxTensorContract], outputs: Vector[OnnxTensorContract], manifest: ModelManifest): Either[String, Unit]

The shape and dtype rules, stated over metadata so they are testable without onnxruntime loading a file.

The shape and dtype rules, stated over metadata so they are testable without onnxruntime loading a file.

Attributes

Source
OnnxModelContract.scala