afe.ir.bias_correction

Bias correction algorithms. These algorithms correct for unwanted bias in convolution or matrix multiply that is caused by quantization.

Classes

BiasCorrector

Abstract base class of a bias correction algorithm.

NullBiasCorrector

No bias correction.

MeanBiasCorrector

Bias correction based on the observed mean value of the input activation tensor.

Functions

prepare_input_mean(→ numpy.ndarray)

Dequantize a set of calibration samples and calculate their per-channel mean value.

Module Contents

afe.ir.bias_correction.prepare_input_mean(calibration_input: list[numpy.ndarray], quantization: afe.ir.defines.Quantization | None) numpy.ndarray[source]

Dequantize a set of calibration samples and calculate their per-channel mean value. This function’s intended purpose is to calculate convolution’s mean input value for iterative bias correction.

Parameters:
  • calibration_input – Set of quantized calibration samples

  • quantization – Quantization of the input data. If None, the input data is not quantized.

Returns:

Dequantized mean value. It is a 1D array.

class afe.ir.bias_correction.BiasCorrector[source]

Abstract base class of a bias correction algorithm.

The constructor may take parameters that are used for bias correction, such as calibration data.

abstract calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) numpy.ndarray | None[source]

Calculate bias correction. Returns a floating-point value that should be added to the convolution’s bias before it is quantized.

Parameters:
  • weights – Floating-point weight tensor.

  • fake_quantized_weights – Fake quantized weight tensor. It is the result of quantizing and then dequantizing the weights.

Returns:

Bias correction value

class afe.ir.bias_correction.NullBiasCorrector[source]

No bias correction.

calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) numpy.ndarray | None[source]

Do no bias correction.

class afe.ir.bias_correction.MeanBiasCorrector(input_mean: numpy.ndarray)[source]

Bias correction based on the observed mean value of the input activation tensor. Statistics correction as described in https://arxiv.org/abs/1906.04721, Section 4.2

Parameters:

input_mean – Observed per-channel mean value of the convolution’s input. A one-dimensional tensor.

calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) numpy.ndarray | None[source]

Calculate bias correction. Returns a floating-point value that should be added to the convolution’s bias before it is quantized.

Parameters:
  • weights – Floating-point weight tensor.

  • fake_quantized_weights – Fake quantized weight tensor. It is the result of quantizing and then dequantizing the weights.

Returns:

Bias correction value