---
title: "OnnxModel"
sidebar_label: "OnnxModel"
description: "Kotlin binding reference: OnnxModel."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

//[clika-runtime](../../../index.md)/[io.clika.runtime](../index.md)/[OnnxModel](index.md)

# OnnxModel

[common]\
class [OnnxModel](index.md)

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](compile.md) is where operator support is decided. `AutoCloseable`: [close](close.md) releases the parsed model (a graph it compiled lives on).

```kotlin
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

| Name | Summary |
|---|---|
| [Companion](Companion/index.md) | [common]<br>object [Companion](Companion/index.md) |

## Properties

| Name | Summary |
|---|---|
| [irVersion](irVersion.md) | [common]<br>val [irVersion](irVersion.md): [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)<br>The file's ONNX IR version. |
| [numInitializers](numInitializers.md) | [common]<br>val [numInitializers](numInitializers.md): [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)<br>The initializer (weight) count. |
| [numNodes](numNodes.md) | [common]<br>val [numNodes](numNodes.md): [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)<br>The graph's node count. |
| [opset](opset.md) | [common]<br>val [opset](opset.md): [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)<br>The default (`ai.onnx`) opset version. |

## Functions

| Name | Summary |
|---|---|
| [close](close.md) | [common]<br>open fun [close](close.md)() |
| [compile](compile.md) | [common]<br>fun [compile](compile.md)(options: [CompileOptions](../CompileOptions/index.md) = CompileOptions()): [ModelGraph](../ModelGraph/index.md)<br>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](compile.md). The graph comes back as built: optimize it when wanted, then [ModelGraph.finalizeGraph](../ModelGraph/finalizeGraph.md) it to run. The model is unchanged and reusable. |
| [inputs](inputs.md) | [common]<br>fun [inputs](inputs.md)(): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[TensorSpec](../TensorSpec/index.md)&gt;<br>The graph inputs as specs, declaration order (a dynamic dim reads as [TensorSpec.DYNAMIC_DIM](../TensorSpec/Companion/DYNAMIC_DIM.md)). |
| [optimize](optimize.md) | [common]<br>fun [optimize](optimize.md)(): [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)<br>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](outputs.md) | [common]<br>fun [outputs](outputs.md)(): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[TensorSpec](../TensorSpec/index.md)&gt;<br>The graph outputs as specs, declaration order. |
| [save](save.md) | [common]<br>fun [save](save.md)(path: [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html))<br>Assemble the model and write it to [path](save.md) (the payloads inline or in a sidecar per [OnnxModelOptions.saveAsExternalData](../OnnxModelOptions/saveAsExternalData.md)). |