Table of Contents
Shortcuts

# MovingAverageMinMaxObserver

class torch.ao.quantization.observer.MovingAverageMinMaxObserver(averaging_constant=0.01, dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None, eps=1.1920928955078125e-07, **kwargs)

  Observer module for computing the quantization parameters based on the moving average of the min and max values.

  This observer computes the quantization parameters based on the moving averages of minimums and maximums of the incoming tensors. The module records the average minimum and maximum of incoming tensors, and uses this statistic to compute the quantization parameters.

  Parameters:

    - averaging_constant – Averaging constant for min/max.

    - dtype – dtype argument to the quantize node needed to implement the reference model spec.

    - qscheme – Quantization scheme to be used

    - reduce_range – Reduces the range of the quantized data type by 1 bit

    - quant_min – Minimum quantization value. If unspecified, it will follow the 8-bit setup.

    - quant_max – Maximum quantization value. If unspecified, it will follow the 8-bit setup.

    - eps (Tensor) – Epsilon value for float32, Defaults to torch.finfo(torch.float32).eps.

  The moving average min/max is computed as follows

  x min={min⁡(X)if x min=None(1−c)x min+c min⁡(X)otherwise x max={max⁡(X)if x max=None(1−c)x max+c max⁡(X)otherwise\begin{array}{ll} x_\text{min} = \begin{cases} \min(X) & \text{if~}x_\text{min} = \text{None} \\ (1 - c) x_\text{min} + c \min(X) & \text{otherwise} \end{cases}\\ x_\text{max} = \begin{cases} \max(X) & \text{if~}x_\text{max} = \text{None} \\ (1 - c) x_\text{max} + c \max(X) & \text{otherwise} \end{cases}\\ \end{array}x min​={min(X)(1−c)x min​+c min(X)​if x min​=None otherwise​x max​={max(X)(1−c)x max​+c max(X)​if x max​=None otherwise​​

  where x min/max x_\text{min/max}x min/max​ is the running average min/max, X X X is is the incoming tensor, and c c c is the `averaging_constant`.

  The scale and zero point are then computed as in `MinMaxObserver`.

  Note

  Only works with `torch.per_tensor_affine` quantization scheme.

  Note

  If the running minimum equals to the running maximum, the scale and zero_point are set to 1.0 and 0.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.