coreai_opt.quantization.spec.MovingAverageQParamsCalculator

class coreai_opt.quantization.spec.MovingAverageQParamsCalculator(dtype, qscheme, granularity, target_dtype, quant_min, quant_max, range_calculator, float_range, averaging_constant=0.01, **kwargs)[source]

Bases: RunningRangeMixin, QParamsCalculatorBase

Computes the scale and zero point using a moving average of the range.

Maintains running_min and running_max buffers that are updated each forward pass using exponential moving average (EMA):

a_{i} = c * x_{i} + (1 - c) * a_{i-1}

where c is the averaging_constant.

Parameters:
__init__(dtype, qscheme, granularity, target_dtype, quant_min, quant_max, range_calculator, float_range, averaging_constant=0.01, **kwargs)[source]
Parameters:

Methods

compute_qparams(tensor, min_val, max_val)

Update running range, persist to buffers, then compute qparams.

extra_repr()

Return the extra representation of the module.

forward(tensor)

Compute scale, zero point, and minval from the input tensor.

get_class(key)

get_qparams()

Return the computed scale, zero point and minval.

list_registry_keys()

list_registry_values()

register(key)

Register a virtual subclass of an ABC.

set_export_mode([enabled])

update_running_range(min_val, max_val)

Return (updated_min, updated_max) using subclass-specific rule.

update_running_range(min_val, max_val)[source]

Return (updated_min, updated_max) using subclass-specific rule.

Parameters:
  • min_val (Tensor)

  • max_val (Tensor)

Return type:

tuple[Tensor, Tensor]