Skip to content
heliaEDGE
Reference
HELIA

runner

Run exported LiteRT model bytes with ai-edge-litert.

Machine-readable model

  • LiteRTRunnerclassRun a single-input, single-output .tflite model one sample at a time.
  • LiteRTStreamRunnerclassRun a streaming .tflite model one step at a time, carrying its state as raw tensors.
class

Run a single-input, single-output .tflite model one sample at a time.

helia_edge/export/runner.py:23

LiteRTRunner(content: bytes, *, reference_kernels: bool = False, num_threads: int = 1) -> None

Run a single-input, single-output .tflite model one sample at a time.

The input tensor is resized to each sample’s shape along the model’s dynamic dimensions only; fixed dimensions must match. Native float16 graphs run when the runtime has float16 kernels for every operator; otherwise the runtime’s error is raised unchanged.

Parameters of LiteRTRunner
NameTypeDefaultDescription
contentbytesRequiredModel flatbuffer bytes.
reference_kernelsboolFalseUse LiteRT's reference kernels instead of its optimized kernels.
num_threadsint1Interpreter threads.
method

run

Python

Invoke on samples along axis 0 already in the model's input dtype; return raw outputs.

helia_edge/export/runner.py:48

run(x: npt.NDArray) -> npt.NDArray

Invoke on samples along axis 0 already in the model’s input dtype; return raw outputs.

method

encode

Python

Convert real-valued samples to the input dtype, rounding and saturating integer inputs.

helia_edge/export/runner.py:62

encode(x: npt.NDArray) -> npt.NDArray

Convert real-valued samples to the input dtype, rounding and saturating integer inputs.

method

predict

Python

Encode real-valued samples, run them and decode the outputs.

helia_edge/export/runner.py:78

predict(x: npt.NDArray) -> npt.NDArray

Encode real-valued samples, run them and decode the outputs.

class

Run a streaming .tflite model one step at a time, carrying its state as raw tensors.

helia_edge/export/runner.py:99

LiteRTStreamRunner(content: bytes, *, reference_kernels: bool = False, num_threads: int = 1) -> None

Run a streaming .tflite model one step at a time, carrying its state as raw tensors.

Inputs and outputs are addressed by signature name. State inputs state_in_k start at zero, and at each later step take the raw state_out_k of the previous step unchanged, so an integer state keeps its value only if the pair has one scale and zero point (export_model ties them).

Parameters of LiteRTStreamRunner
NameTypeDefaultDescription
contentbytesRequiredModel flatbuffer bytes with one signature.
reference_kernelsboolFalseUse LiteRT's reference kernels instead of its optimized kernels.
num_threadsint1Interpreter threads.
Errors raised by LiteRTStreamRunner
TypeDescription
ValueErrorIf the model does not have exactly one signature, or its state inputs and outputs do not pair up.
method

Each state input at zero: the zero point for an integer state.

helia_edge/export/runner.py:136

initial_state() -> dict[str, npt.NDArray]

Each state input at zero: the zero point for an integer state.

method

step

Python

Invoke once on raw tensors for every input name; return every output by name.

helia_edge/export/runner.py:143

step(inputs: Mapping[str, npt.NDArray]) -> dict[str, npt.NDArray]

Invoke once on raw tensors for every input name; return every output by name.

method

run

Python

Stream raw signal inputs, carrying the state.

helia_edge/export/runner.py:158

run(
signals: Mapping[str, npt.NDArray],
resets: Collection[int] = (),
) -> tuple[dict[str, npt.NDArray], dict[str, npt.NDArray]]

Stream raw signal inputs, carrying the state.

Parameters of run
NameTypeDefaultDescription
signalsMapping[str, npt.NDArray]RequiredEvery input that is not a state, by name, as raw tensors stacked along a leading step axis (``[steps, *input shape]``).
resetsCollection[int]()Steps at which the state inputs return to ``initial_state``.
Returns of run
ValueTypeDescription
tupletuple[dict[str, npt.NDArray], dict[str, npt.NDArray]]Every input as fed and every output as produced, by name, stacked along the step axis.
method

encode

Python

Convert real values to input name's dtype, rounding and saturating integer inputs.

helia_edge/export/runner.py:193

encode(name: str, x: npt.NDArray) -> npt.NDArray

Convert real values to input name’s dtype, rounding and saturating integer inputs.

method

decode

Python

Convert raw values of output name to float32.

helia_edge/export/runner.py:197

decode(name: str, y: npt.NDArray) -> npt.NDArray

Convert raw values of output name to float32.