# helia_aot.air.model

## helia_aot.air.model.AirModel

`class` · `python`

```python
AirModel()
```

In-memory graph IR for AOT codegen.

Source: `helia_aot/air/model.py:8`

### helia_aot.air.model.AirModel.name

`attribute` · `python`

```python
name: str = Field(default='Model', description='Name of the model')
```

Name of the model.

Source: `helia_aot/air/model.py:22`

### helia_aot.air.model.AirModel.version

`attribute` · `python`

```python
version: str = Field(default='1.0.0', description='Version of the model')
```

Version of the model.

Source: `helia_aot/air/model.py:23`

### helia_aot.air.model.AirModel.description

`attribute` · `python`

```python
description: str = Field(default='', description='Description of the model')
```

Description of the model.

Source: `helia_aot/air/model.py:24`

### helia_aot.air.model.AirModel.tensors

`attribute` · `python`

```python
tensors: dict[str, AirTensor] = Field(default_factory=dict, description='Mapping from tensor ID to its AirTensor metadata')
```

Mapping from tensor ID to its AirTensor metadata.

Source: `helia_aot/air/model.py:25`

### helia_aot.air.model.AirModel.operators

`attribute` · `python`

```python
operators: list[AirOperator] = Field(default_factory=list, description='Topologically ordered list of operators (nodes) in the graph')
```

Topologically ordered list of operators (nodes) in the graph.

Source: `helia_aot/air/model.py:28`

### helia_aot.air.model.AirModel.input_ids

`attribute` · `python`

```python
input_ids: list[str] = Field(default_factory=list, description='IDs of tensors that serve as model inputs')
```

IDs of tensors that serve as model inputs.

Source: `helia_aot/air/model.py:31`

### helia_aot.air.model.AirModel.output_ids

`attribute` · `python`

```python
output_ids: list[str] = Field(default_factory=list, description='IDs of tensors that serve as model outputs')
```

IDs of tensors that serve as model outputs.

Source: `helia_aot/air/model.py:32`

### helia_aot.air.model.AirModel.inputs

`attribute` · `python`

```python
inputs: list[AirTensor]
```

List of AirTensor objects corresponding to model inputs.

Source: `helia_aot/air/model.py:151`

### helia_aot.air.model.AirModel.outputs

`attribute` · `python`

```python
outputs: list[AirTensor]
```

List of AirTensor objects corresponding to model outputs.

Source: `helia_aot/air/model.py:156`

### helia_aot.air.model.AirModel.add_tensor

`method` · `python`

```python
add_tensor(tensor: AirTensor) -> None
```

Register a new tensor in the model.

**Raises**

| Name | Description |
| --- | --- |
| ValueError | If a tensor with the same ID already exists. |

Source: `helia_aot/air/model.py:34`

### helia_aot.air.model.AirModel.remove_tensor

`method` · `python`

```python
remove_tensor(tid: TensorId) -> None
```

Remove a tensor from the model by its ID.

**Raises**

| Name | Description |
| --- | --- |
| KeyError | If the tensor ID is not found. |

Source: `helia_aot/air/model.py:44`

### helia_aot.air.model.AirModel.add_operator

`method` · `python`

```python
add_operator(op: AirOperator) -> None
```

Append a new operator to the execution list.

**Raises**

| Name | Description |
| --- | --- |
| ValueError | If an operator with the same ID already exists. |

Source: `helia_aot/air/model.py:55`

### helia_aot.air.model.AirModel.has_tensor

`method` · `python`

```python
has_tensor(tid: TensorId) -> bool
```

Check if a tensor exists in the model by its ID.

Source: `helia_aot/air/model.py:65`

### helia_aot.air.model.AirModel.get_tensor

`method` · `python`

```python
get_tensor(tid: TensorId) -> AirTensor
```

Lookup a tensor by its ID.

**Raises**

| Name | Description |
| --- | --- |
| KeyError | If the tensor ID is not found. |

Source: `helia_aot/air/model.py:69`

### helia_aot.air.model.AirModel.tensor_is_shared

`method` · `python`

```python
tensor_is_shared(tid: TensorId, reader: AirOperator | None = None) -> bool
```

Whether anything other than ``reader`` uses tensor ``tid``.

Uses are other operators, aliases in either direction (following alias
chains transitively), and the model's inputs and outputs. Rewriting a
tensor in place is safe only when this is ``False``.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| tid | TensorId | Required | The tensor to check. |
| reader | AirOperator \| None | None | The operator asking; its own references do not count. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| bool | bool | ``True`` when some other use exists. |

Source: `helia_aot/air/model.py:90`

### helia_aot.air.model.AirModel.rewrite_constant

`method` · `python`

```python
rewrite_constant(reader: AirOperator, name: str | int, data) -> AirTensor
```

Bind ``reader``'s tensor ``name`` to ``data``, rewriting it only where that is safe.

The tensor is rewritten in place when nothing else uses it. Otherwise
``reader`` is rebound to a copy under ``<id>_rewritten`` (or the first
free ``<id>_rewritten_N``) whose ``packed_from`` names the source, so
``memory.tensors`` rules on the source id still place it.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| reader | AirOperator | Required | The operator that owns the rewrite. |
| name | str \| int | Required | Its local name for the tensor, or the tensor's position in its inputs. |
| data |  | Required | The rewritten data. |

**Returns**

| Name | Type | Description |
| --- | --- | --- |
| AirTensor | AirTensor | The tensor ``reader`` now reads. |

Source: `helia_aot/air/model.py:110`

### helia_aot.air.model.AirModel.topo_sort

`method` · `python`

```python
topo_sort() -> list[AirOperator]
```

Return operators in execution order.

Assumes `operators` was populated in valid topological order.

Source: `helia_aot/air/model.py:160`

### helia_aot.air.model.AirModel.prune_unused_tensors

`method` · `python`

```python
prune_unused_tensors() -> list[TensorId]
```

Remove dangling tensors that are not referenced by any operator or model input/output.

Source: `helia_aot/air/model.py:167`
