AirModel
PythonIn-memory graph IR for AOT codegen.
AirModel()In-memory graph IR for AOT codegen.
name
Pythonname: str = Field(default='Model', description='Name of the model')Name of the model.
version
Pythonversion: str = Field(default='1.0.0', description='Version of the model')Version of the model.
description
Pythondescription: str = Field(default='', description='Description of the model')Description of the model.
tensors
Pythontensors: dict[str, AirTensor] = Field(default_factory=dict, description='Mapping from tensor ID to its AirTensor metadata')Mapping from tensor ID to its AirTensor metadata.
operators
Pythonoperators: 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.
input_ids
Pythoninput_ids: list[str] = Field(default_factory=list, description='IDs of tensors that serve as model inputs')IDs of tensors that serve as model inputs.
output_ids
Pythonoutput_ids: list[str] = Field(default_factory=list, description='IDs of tensors that serve as model outputs')IDs of tensors that serve as model outputs.
inputs
PythonList of AirTensor objects corresponding to model inputs.
inputs: list[AirTensor]List of AirTensor objects corresponding to model inputs.
outputs
PythonList of AirTensor objects corresponding to model outputs.
outputs: list[AirTensor]List of AirTensor objects corresponding to model outputs.
add_tensor
PythonRegister a new tensor in the model.
add_tensor(tensor: AirTensor) -> NoneRegister a new tensor in the model.
Raises
| Type | Description |
|---|---|
ValueError | If a tensor with the same ID already exists. |
remove_tensor
PythonRemove a tensor from the model by its ID.
remove_tensor(tid: TensorId) -> NoneRemove a tensor from the model by its ID.
Raises
| Type | Description |
|---|---|
KeyError | If the tensor ID is not found. |
add_operator
PythonAppend a new operator to the execution list.
add_operator(op: AirOperator) -> NoneAppend a new operator to the execution list.
Raises
| Type | Description |
|---|---|
ValueError | If an operator with the same ID already exists. |
has_tensor
PythonCheck if a tensor exists in the model by its ID.
has_tensor(tid: TensorId) -> boolCheck if a tensor exists in the model by its ID.
get_tensor
PythonLookup a tensor by its ID.
get_tensor(tid: TensorId) -> AirTensorLookup a tensor by its ID.
Raises
| Type | Description |
|---|---|
KeyError | If the tensor ID is not found. |
tensor_is_shared
PythonWhether anything other than reader uses tensor tid.
tensor_is_shared(tid: TensorId, reader: AirOperator | None = None) -> boolWhether 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
| Value | Type | Description |
|---|---|---|
bool | bool | ``True`` when some other use exists. |
rewrite_constant
PythonBind reader's tensor name to data, rewriting it only where that is safe.
rewrite_constant(reader: AirOperator, name: str | int, data) -> AirTensorBind 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
| Value | Type | Description |
|---|---|---|
AirTensor | AirTensor | The tensor ``reader`` now reads. |
topo_sort
PythonReturn operators in execution order.
topo_sort() -> list[AirOperator]Return operators in execution order.
Assumes operators was populated in valid topological order.
prune_unused_tensors
PythonRemove dangling tensors that are not referenced by any operator or model input/output.
prune_unused_tensors() -> list[TensorId]Remove dangling tensors that are not referenced by any operator or model input/output.