Skip to main content

//clika-runtime/io.clika.runtime/OnnxModel

OnnxModel

[common]
class OnnxModel

An ONNX model opened from a file: the graph loads into memory and the external initializer payloads stay on disk until something consumes them; nothing is validated beyond the wire format, and compile is where operator support is decided. AutoCloseable: close releases the parsed model (a graph it compiled lives on).

OnnxModel.open("model.onnx").use { model ->
model.compile(CompileOptions(sampleInputs = mapOf("x" to x))).use { graph ->
graph.finalizeGraph()
val y = graph.run(listOf(x)).single()
}
}

Types​

NameSummary
Companion[common]
object Companion

Properties​

NameSummary
irVersion[common]
val irVersion: Long
The file's ONNX IR version.
numInitializers[common]
val numInitializers: Long
The initializer (weight) count.
numNodes[common]
val numNodes: Long
The graph's node count.
opset[common]
val opset: Long
The default (ai.onnx) opset version.

Functions​

NameSummary
close[common]
open fun close()
compile[common]
fun compile(options: CompileOptions = CompileOptions()): ModelGraph
Build the executable form: every node parsed into its runtime operator (an unsupported one fails here, naming it), the weights bound, the shapes resolved per options. The graph comes back as built: optimize it when wanted, then ModelGraph.finalizeGraph it to run. The model is unchanged and reusable.
inputs[common]
fun inputs(): List<TensorSpec>
The graph inputs as specs, declaration order (a dynamic dim reads as TensorSpec.DYNAMIC_DIM).
optimize[common]
fun optimize(): Int
Run the ONNX rewrite passes to a fixed point (double casts collapsed, redundant quantize/dequantize pairs dropped, shape movement fused, constants folded, dead nodes removed); the number of passes run.
outputs[common]
fun outputs(): List<TensorSpec>
The graph outputs as specs, declaration order.
save[common]
fun save(path: String)
Assemble the model and write it to path (the payloads inline or in a sidecar per OnnxModelOptions.saveAsExternalData).