Skip to content
heliaAOT
HELIA HUB

utils

Machine-readable model

function

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

helia_aot/air/utils.py:8

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

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

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

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.

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.

helia_aot/air/utils.py:111

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

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

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).
Returns of compute_padding_with_offset
ValueTypeDescription
inttuple[int, int]The computed top or left padding value.
function

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

helia_aot/air/utils.py:140

compute_padding(
in_size: int,
filter_size: int,
stride: int,
dilation_rate: int = 1,
padding_type: int = AirPaddingType.SAME,
) -> int

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

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).
Returns of compute_padding
ValueTypeDescription
intintThe computed top or left padding value.
function

Reduce a multiplier value for int16 quantization.

helia_aot/air/utils.py:185

reduce_multiplier_q31_to_q15(multiplier: int) -> int

Reduce a multiplier value for int16 quantization.

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.