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

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

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

# ModelGraph

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

A compiled model: its I/O contract, its placement, and its runs. A graph runs once it is finalized ([finalizeGraph](finalizeGraph.md): placed on its device, the weights packed, the execution order planned); a run before that fails with `FAILED_PRECONDITION`. [to](to.md) moves it to a device or a stream, before finalizing (recording where finalizing places it) or after (moving the finalized graph). `AutoCloseable`: [close](close.md) releases the graph.

## Properties

| Name | Summary |
|---|---|
| [device](device.md) | [common]<br>val [device](device.md): [Device](../Device/index.md)<br>The device the graph serves on. |
| [inputNames](inputNames.md) | [common]<br>val [inputNames](inputNames.md): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)&gt;<br>The runtime input names in declaration order, the order the positional [run](run.md) binds. |
| [isEmpty](isEmpty.md) | [common]<br>val [isEmpty](isEmpty.md): [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)<br>True for a graph that holds none (moved from, or consumed). |
| [isFinalized](isFinalized.md) | [common]<br>val [isFinalized](isFinalized.md): [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)<br>True once [finalizeGraph](finalizeGraph.md) ran. |
| [outputNames](outputNames.md) | [common]<br>val [outputNames](outputNames.md): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)&gt;<br>The output names in declaration order, the order every [run](run.md) answers. |

## Functions

| Name | Summary |
|---|---|
| [close](close.md) | [common]<br>open fun [close](close.md)() |
| [finalizeGraph](finalizeGraph.md) | [common]<br>fun [finalizeGraph](finalizeGraph.md)()<br>Finalize the graph for serving: place it on its device, pack the weights into their kernel layouts, absorb the constants and plan the execution order. A second call changes nothing. (The name carries the word `Graph` because `finalize` alone is the JVM's own method.) |
| [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 input slots as specs, in [inputNames](inputNames.md) order (a dim the graph left dynamic reads as [TensorSpec.DYNAMIC_DIM](../TensorSpec/Companion/DYNAMIC_DIM.md)). |
| [optimize](optimize.md) | [common]<br>fun [optimize](optimize.md)(options: [OptimizeOptions](../OptimizeOptions/index.md) = OptimizeOptions()): [OptimizeReport](../OptimizeReport/index.md)<br>Run the graph optimizer with the graph's own transform list, iterated until an iteration changes nothing or the cap stops it; a transform that fails is undone and skipped, and the run goes on. Refuses `FAILED_PRECONDITION` on a finalized graph. |
| [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 output slots as specs, in [outputNames](outputNames.md) order. |
| [run](run.md) | [common]<br>fun [run](run.md)(inputs: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;<br>Run with positional inputs (one per [inputNames](inputNames.md) entry, that order); the outputs in [outputNames](outputNames.md) order, fresh tensors the caller owns.<br>[common]<br>fun [run](run.md)(inputs: [Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), [Tensor](../Tensor/index.md)&gt;): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;<br>Run with named inputs (every runtime input present, every name an input); the outputs in [outputNames](outputNames.md) order.<br>[common]<br>fun [run](run.md)(inputs: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;, boundOutputs: [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;<br>Run with positional inputs, landing the results in [boundOutputs](run.md), one caller-preallocated buffer per [outputNames](outputNames.md) entry shaped and typed to accept its result; the answered tensors alias the bound buffers.<br>[common]<br>fun [run](run.md)(inputs: [Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), [Tensor](../Tensor/index.md)&gt;, boundOutputs: [Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)&lt;[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html), [Tensor](../Tensor/index.md)&gt;): [List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)&lt;[Tensor](../Tensor/index.md)&gt;<br>Run with named inputs and named output bindings (every binding name an output; an unbound output comes back fresh). |
| [to](to.md) | [common]<br>fun [to](to.md)(where: [Placement](../Placement/index.md))<br>Move the graph to a device or a stream (`to(stream)` once, then every run computes on it). |