Skip to content
heliaAOT
API Reference
HELIA HUB

model

Machine-readable model

  • AirFoldedVariableclassA resource variable a transform replaced with the constant it provably always holds.
  • AirModelclassIn-memory graph IR for AOT codegen.
class

A resource variable a transform replaced with the constant it provably always holds.

helia_aot/air/model.py:12

AirFoldedVariable()

A resource variable a transform replaced with the constant it provably always holds.

Provisional: importable, but outside the compatibility promise; a minor release can change or remove it.

attribute

helia_aot/air/model.py:29

assignment: str

none when the main graph never assigned it, clip when every assignment stored a MAXIMUM/MINIMUM chain of its own read that leaves the initial value unchanged.

class

AirModel

Python

In-memory graph IR for AOT codegen.

helia_aot/air/model.py:34

AirModel()

In-memory graph IR for AOT codegen.

attribute

tensors

Python

helia_aot/air/model.py:52

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:55

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:58

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:59

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

helia_aot/air/model.py:60

folded_variables: list[AirFoldedVariable] = Field(default_factory=list, description='Resource variables folded into constants, in folding order')

Resource variables folded into constants.

attribute

inputs

Python

List of AirTensor objects corresponding to model inputs.

helia_aot/air/model.py:358

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:363

outputs: list[AirTensor]

List of AirTensor objects corresponding to model outputs.

method

Register a new tensor in the model.

helia_aot/air/model.py:64

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:74

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:85

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:95

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:99

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

The tensor whose storage tid reads: the end of its alias chain, or tid itself.

helia_aot/air/model.py:110

alias_root(tid: TensorId) -> TensorId

The tensor whose storage tid reads: the end of its alias chain, or tid itself.

method

Why tensor tid's bytes may not be moved or shared, or None when they may.

helia_aot/air/model.py:135

tensor_owns_storage(tid: TensorId, *, model_inputs: bool = True) -> str | None

Why tensor tid’s bytes may not be moved or shared, or None when they may.

A tensor owns its storage when it is persistent (state a kernel may write through an input or a named tensor, which no producer count sees), pinned to an arena offset by an external compiler, named by an ETHOS_U operator (whose command stream addresses the arena rather than the pointer table), or a model input (the caller’s buffer). This is the one list of owners; structure_violations, substitution_blockers and identity pruning all consult it.

Parameters of tensor_owns_storage
NameTypeDefaultDescription
tidTensorIdRequiredThe tensor to check.
model_inputsboolTrueWhether being a model input counts. A model input's bytes may be viewed through an alias but not replaced, so a caller asking about the root of a view passes ``False``.
Returns of tensor_owns_storage
TypeDescription
str | Nonestr | None: The reason, or ``None`` when nothing owns the storage.
method

The reason of every tensor that owns its storage, by the rules of :meth:tensorownsstorage.

helia_aot/air/model.py:160

storage_owners(*, model_inputs: bool = True) -> dict[TensorId, str]

The reason of every tensor that owns its storage, by the rules of :meth:tensor_owns_storage.

One pass over the operators indexes the ETHOS_U-addressed tensors, so asking about every tensor costs the model’s size, not its square.

Parameters of storage_owners
NameTypeDefaultDescription
model_inputsboolTrueWhether being a model input counts.
Returns of storage_owners
TypeDescription
dict[TensorId, str]dict[TensorId, str]: The reason per owning tensor; a tensor that owns nothing is absent.
method

Why the consumers of tid cannot be given another tensor, nor its storage another role.

helia_aot/air/model.py:191

substitution_blockers(tid: TensorId) -> list[str]

Why the consumers of tid cannot be given another tensor, nor its storage another role.

A transform that replaces reads of a run-time tensor, or turns one into a constant in place, may do so only when this is empty. rewrite_constant owns the matching rule for constants.

Parameters of substitution_blockers
NameTypeDefaultDescription
tidTensorIdRequiredThe tensor whose consumers would be rebound.
Returns of substitution_blockers
TypeDescription
list[str]list[str]: One reason per blocker, empty when the substitution is safe.
method

Describe every way the model's tensors and aliases are ill-formed.

helia_aot/air/model.py:225

structure_violations() -> list[str]

Describe every way the model’s tensors and aliases are ill-formed.

Every tensor an operator or the model names exists; no tensor has two producers and no operator produces a constant (read-only storage has no writer); alias chains end at an existing root without a cycle; a tensor that owns its storage (tensor_owns_storage) has no alias; a constant alias has a constant root; nothing aliases into persistent, pinned or NPU-addressed storage; a model output’s alias root is scratch. The transform pipeline runs this on the loaded model and after each transform.

Returns of structure_violations
TypeDescription
list[str]list[str]: One description per violation; empty when the model is well-formed.
method

Whether anything other than reader uses tensor tid.

helia_aot/air/model.py:295

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:315

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 and reader itself references it once. Otherwise reader’s name 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, and every other reference keeps the original.

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:367

topo_sort() -> list[AirOperator]

Return operators in execution order.

Assumes operators was populated in valid topological order.

method

Describe every read of a tensor that a later operator produces.

helia_aot/air/model.py:374

order_violations() -> list[str]

Describe every read of a tensor that a later operator produces.

operators is the execution order the planner and the emitted schedule follow, so an operator may not reference, through its inputs or named tensors, a tensor that only a later operator writes. Constant and persistent tensors and model inputs hold a value before any operator runs and are exempt. A read through an alias is checked against every tensor on its alias chain down to the root, because an operator that writes an alias writes the root’s storage.

Returns of order_violations
TypeDescription
list[str]list[str]: One description per violation; empty when the order is valid.
method

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

helia_aot/air/model.py:415

prune_unused_tensors() -> list[TensorId]

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