afe.ir.bias_correction ====================== .. py:module:: afe.ir.bias_correction .. autoapi-nested-parse:: Bias correction algorithms. These algorithms correct for unwanted bias in convolution or matrix multiply that is caused by quantization. Classes ------- .. autoapisummary:: afe.ir.bias_correction.BiasCorrector afe.ir.bias_correction.NullBiasCorrector afe.ir.bias_correction.MeanBiasCorrector Functions --------- .. autoapisummary:: afe.ir.bias_correction.prepare_input_mean Module Contents --------------- .. py:function:: prepare_input_mean(calibration_input: list[numpy.ndarray], quantization: afe.ir.defines.Quantization | None) -> numpy.ndarray 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. :param calibration_input: Set of quantized calibration samples :param quantization: Quantization of the input data. If None, the input data is not quantized. :returns: Dequantized mean value. It is a 1D array. .. py:class:: BiasCorrector Abstract base class of a bias correction algorithm. The constructor may take parameters that are used for bias correction, such as calibration data. .. py:method:: calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) -> numpy.ndarray | None :abstractmethod: Calculate bias correction. Returns a floating-point value that should be added to the convolution's bias before it is quantized. :param weights: Floating-point weight tensor. :param fake_quantized_weights: Fake quantized weight tensor. It is the result of quantizing and then dequantizing the weights. :return: Bias correction value .. py:class:: NullBiasCorrector No bias correction. .. py:method:: calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) -> numpy.ndarray | None Do no bias correction. .. py:class:: MeanBiasCorrector(input_mean: numpy.ndarray) 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 :param input_mean: Observed per-channel mean value of the convolution's input. A one-dimensional tensor. .. py:method:: calculate(weights: numpy.ndarray, fake_quantized_weights: numpy.ndarray) -> numpy.ndarray | None Calculate bias correction. Returns a floating-point value that should be added to the convolution's bias before it is quantized. :param weights: Floating-point weight tensor. :param fake_quantized_weights: Fake quantized weight tensor. It is the result of quantizing and then dequantizing the weights. :return: Bias correction value