Skip to content
heliaAOT
HELIA HUB

model

Machine-readable model

  • AirModelclassIn-memory graph IR for AOT codegen.
class

AirModel

Python

In-memory graph IR for AOT codegen.

helia_aot/air/model.py:8

AirModel()

In-memory graph IR for AOT codegen.

attribute

tensors

Python

helia_aot/air/model.py:25

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.

attribute

operators

Python

helia_aot/air/model.py:28

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.

attribute

input_ids

Python

helia_aot/air/model.py:31

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.

attribute

helia_aot/air/model.py:32

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.

attribute

inputs

Python

List of AirTensor objects corresponding to model inputs.

helia_aot/air/model.py:151

inputs: list[AirTensor]

List of AirTensor objects corresponding to model inputs.

attribute

outputs

Python

List of AirTensor objects corresponding to model outputs.

helia_aot/air/model.py:156

outputs: list[AirTensor]

List of AirTensor objects corresponding to model outputs.

method

Register a new tensor in the model.

helia_aot/air/model.py:34

add_tensor(tensor: AirTensor) -> None

Register a new tensor in the model.

Errors raised by add_tensor
TypeDescription
ValueErrorIf a tensor with the same ID already exists.
method

Remove a tensor from the model by its ID.

helia_aot/air/model.py:44

remove_tensor(tid: TensorId) -> None

Remove a tensor from the model by its ID.

Errors raised by remove_tensor
TypeDescription
KeyErrorIf the tensor ID is not found.
method

Append a new operator to the execution list.

helia_aot/air/model.py:55

add_operator(op: AirOperator) -> None

Append a new operator to the execution list.

Errors raised by add_operator
TypeDescription
ValueErrorIf an operator with the same ID already exists.
method

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

helia_aot/air/model.py:65

has_tensor(tid: TensorId) -> bool

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

method

Lookup a tensor by its ID.

helia_aot/air/model.py:69

get_tensor(tid: TensorId) -> AirTensor

Lookup a tensor by its ID.

Errors raised by get_tensor
TypeDescription
KeyErrorIf the tensor ID is not found.
method

Whether anything other than reader uses tensor tid.

helia_aot/air/model.py:90

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 of tensor_is_shared
NameTypeDefaultDescription
tidTensorIdRequiredThe tensor to check.
readerAirOperator | NoneNoneThe operator asking; its own references do not count.
Returns of tensor_is_shared
ValueTypeDescription
boolbool``True`` when some other use exists.
method

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

helia_aot/air/model.py:110

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 of rewrite_constant
NameTypeDefaultDescription
readerAirOperatorRequiredThe operator that owns the rewrite.
namestr | intRequiredIts local name for the tensor, or the tensor's position in its inputs.
dataRequiredThe rewritten data.
Returns of rewrite_constant
ValueTypeDescription
AirTensorAirTensorThe tensor ``reader`` now reads.
method

topo_sort

Python

Return operators in execution order.

helia_aot/air/model.py:160

topo_sort() -> list[AirOperator]

Return operators in execution order.

Assumes operators was populated in valid topological order.

method

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

helia_aot/air/model.py:167

prune_unused_tensors() -> list[TensorId]

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