Skip to content
heliaAOT
API Reference
HELIA HUB

utils

Machine-readable model

function

Convert a floating point multiplier into a fixed-point multiplier and shift.

helia_aot/air/utils.py:10

quantize_multiplier(real_multiplier: float) -> tuple[int, int]

Convert a floating point multiplier into a fixed-point multiplier and shift.

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

Given a real multiplier, this function computes a pair (quantized_multiplier, shift) such that the fixed-point multiplication approximates the real multiplier:

real_multiplier ~ quantized_multiplier / (2^(31 - shift))

This is typically used in quantized inference to convert floating-point scaling factors to fixed-point representation.

The CMSIS-NN arm_nn_divide_by_power_of_two function only supports exponent values in [0, 31], so the resulting shift is clamped to [-31, 30]. When the real multiplier is so small that the shift would fall below -31 the contribution is negligible and the multiplier is flushed to zero.

Parameters of quantize_multiplier
NameTypeDefaultDescription
real_multiplierfloatRequiredThe floating-point multiplier.
Returns of quantize_multiplier
ValueTypeDescription
tupletuple[int, int](quantized_multiplier, shift)
function

Compute the activation min and max values based on the fused activation function.

helia_aot/air/utils.py:70

compute_fused_activation_range(
activation_function: AirActivationType,
output_zero_point: int = 0,
output_scale: float = 1.0,
qmin: int = -128,
qmax: int = 127,
) -> tuple[int, int]

Compute the activation min and max values based on the fused activation function.

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

Parameters of compute_fused_activation_range
NameTypeDefaultDescription
activation_functionlitert.ActivationFunctionTypeRequiredThe activation function type.
output_zero_pointint0The zero point for the output tensor. Defaults to 0.
output_scalefloat1.0The scale for the output tensor. Defaults to 1.0.
qminint-128Minimum quantized value. Defaults to -128.
qmaxint127Maximum quantized value. Defaults to 127.
Returns of compute_fused_activation_range
TypeDescription
tuple[int, int]tuple[int, int]: The activation min and max values.
function

Computes a single padding value (top/left) for one dimension with offset, as LiteRT does.

helia_aot/air/utils.py:159

compute_padding_with_offset(
in_size: int,
filter_size: int,
stride: int,
dilation_rate: int = 1,
padding_type: int = AirPaddingType.SAME,
operator: str = 'A window operator',
) -> tuple[int, int]

Computes a single padding value (top/left) for one dimension with offset, as LiteRT does.

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

This is LiteRT’s ComputePaddingWithOffset over :func:compute_out_size. VALID padding is therefore 0 except when the filter is wider than in_size plus a stride, as a transposed convolution’s output can be.

Parameters of compute_padding_with_offset
NameTypeDefaultDescription
in_sizeintRequiredInput dimension (height or width).
filter_sizeintRequiredKernel dimension (height or width).
strideintRequiredStride for that dimension.
dilation_rateint1Dilation rate for that dimension (default is 1).
padding_typeintAirPaddingType.SAME0 for SAME padding, 1 for VALID padding (default is SAME).
operatorstr'A window operator'The operator, as an error names it.
Returns of compute_padding_with_offset
TypeDescription
tuple[int, int]tuple[int, int]: The top or left padding, and the extra bottom or right padding (0 or 1).
Errors raised by compute_padding_with_offset
TypeDescription
UnsupportedModelErrorIf the stride or dilation is below 1, or the padding type is neither SAME nor VALID.
function

Computes a single padding value (top/left) for one dimension.

helia_aot/air/utils.py:191

compute_padding(
in_size: int,
filter_size: int,
stride: int,
dilation_rate: int = 1,
padding_type: int = AirPaddingType.SAME,
operator: str = 'A window operator',
) -> int

Computes a single padding value (top/left) for one dimension.

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

Parameters of compute_padding
NameTypeDefaultDescription
in_sizeintRequiredInput dimension (height or width).
filter_sizeintRequiredKernel dimension (height or width).
strideintRequiredStride for that dimension.
dilation_rateint1Dilation rate for that dimension (default is 1).
padding_typeintAirPaddingType.SAME0 for SAME padding, 1 for VALID padding (default is SAME).
operatorstr'A window operator'The operator, as an error names it.
Returns of compute_padding
ValueTypeDescription
intintThe computed top or left padding value.
Errors raised by compute_padding
TypeDescription
UnsupportedModelErrorIf the stride or dilation is below 1, or the padding type is neither SAME nor VALID.
function

Reduce a multiplier value for int16 quantization.

helia_aot/air/utils.py:243

reduce_multiplier_q31_to_q15(multiplier: int) -> int

Reduce a multiplier value for int16 quantization.

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

Certain CMSIS functions for int16 quantized models require the multiplier to be reduced from Q31 format to Q15 format. This function performs that reduction.

Parameters of reduce_multiplier_q31_to_q15
NameTypeDefaultDescription
multiplierintRequiredThe original multiplier value.
Returns of reduce_multiplier_q31_to_q15
ValueTypeDescription
intintThe reduced multiplier value.