---
title: "ClikaRT::runtime::Model"
sidebar_label: "Model"
description: "The serving-model contract: subclass this to run under Executor / Pipeline."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/runtime/model.h`  
**Inherited by:** [`ClikaRT::runtime::FunctionModel`](./FunctionModel.md)

The serving-model contract: subclass this to run under [`Executor`](./Executor.md) / [`Pipeline`](./Pipeline.md).

A model declares its I/O ([`schema`](./Model.md#schema)), its phase list ([`phases`](./Model.md#phases)), and implements the phase bodies ([`Phase_RunOnce`](./Model.md#Phase_RunOnce) for one-shot phases, [`Phase_Iterate`](./Model.md#Phase_Iterate) for continuous-batched stepping); stateful models allocate per-session state in [`make_state`](./Model.md#make_state) and reclaim it in [`evict`](./Model.md#evict). A model that reports its capacity ([`capacity_units`](./Model.md#capacity_units), [`project_units`](./Model.md#project_units)) lets the scheduler admit against it ([`SchedulerConfig::capacity_policy`](./SchedulerConfig.md#capacity_policy)). Overrides MAY raise [`ClikaRT::Error`](../Error.md); the runtime catches caller-side and fails only that session.

## Member functions

### \~Model() {#Model}

<div class="api-signature">

`virtual` **`~Model`**()

</div>

Virtual base destructor.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 49

</div>

### schema() {#schema}

<div class="api-signature">

`virtual` `const` [`ModelSchema`](./ModelSchema.md)`&` **`schema`**() `const =0`

</div>

The model's I/O contract. Return a reference to model-owned storage.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 52

</div>

### phases() {#phases}

<div class="api-signature">

`virtual` [`ClikaRT::Span`](../Span.md)`<const` [`PhaseSpec`](./PhaseSpec.md)`>` **`phases`**() `const =0`

</div>

The model's phases, in order. Borrowed (model-owned storage).

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 54

</div>

### make\_state() {#make_state}

<div class="api-signature">

`virtual` [`ModelState`](./ModelState.md)`*` **`make_state`**([`Stream`](../Stream.md) `stream`) `const`

</div>

Allocate per-session state (stateful models only). Return a heap-allocated [`ModelState`](./ModelState.md) subclass (the runtime takes ownership and frees it after [`evict`](./Model.md#evict)); the default returns `nullptr` (stateless). MAY raise on failure.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 59

</div>

### Phase\_RunOnce() {#Phase_RunOnce}

<div class="api-signature">

`virtual` `void` **`Phase_RunOnce`**(`const` [`PhaseSpec`](./PhaseSpec.md)`&` `phase`, [`PhaseContext`](./PhaseContext.md)`&` `ctx`) `=0`

</div>

Run a `RunOnce` phase: read `ctx.inputs`, write `ctx.outputs`. MAY raise.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 62

</div>

### Phase\_Iterate() {#Phase_Iterate}

<div class="api-signature">

`virtual` [`StepBatchOut`](./StepBatchOut.md) **`Phase_Iterate`**(`const` [`PhaseSpec`](./PhaseSpec.md)`&`, [`StepContext`](./StepContext.md)`&`)

</div>

Step an `Iterate` phase over the batch in `ctx.slots`; return one [`SessionStepResult`](./SessionStepResult.md) per slot (in order). The default raises `Unsupported` (a RunOnce-only model need not override it). MAY raise.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 67

</div>

### evict() {#evict}

<div class="api-signature">

`virtual` `void` **`evict`**([`ModelState`](./ModelState.md)`&` `state`) `noexcept`

</div>

Reclaim a session's state before the runtime destroys it (free slots, caches). Default: no-op. Must not throw.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 77

</div>

### capacity\_units() {#capacity_units}

<div class="api-signature">

`virtual` `std::int64_t` **`capacity_units`**() `const noexcept`

</div>

The capacity this model has free right now, in its own units. The default, -1, reports no capacity: every capacity policy then admits under [`SchedulerConfig::max_active_sessions`](./SchedulerConfig.md#max_active_sessions) alone, which is also all that [`CapacityPolicy::SlotCap`](./index.md#CapacityPolicy) ever does. Read once per admission round. Must not throw.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 89

</div>

### project\_units() {#project_units}

<div class="api-signature">

`virtual` [`UnitProjection`](./UnitProjection.md) **`project_units`**(`const` [`NamedTensors`](../NamedTensors.md)`&` `inputs`) `const noexcept`

</div>

A request's need in the same units, read from its inputs before it is admitted (and again before a session set aside with [`Disposition::Preempted`](./index.md#Disposition) is re-admitted, its resume payload merged in): `total` through the output cap, `first_step` for what the admitting step commits (the prompt, or its first chunk). The default reports both unknown (-1), and the request is admitted under the session cap alone. Must not throw.

<div class="api-declared">

Declared in `ClikaRT/runtime/model.h`, line 98

</div>
