class, dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None, eps=1.1920928955078125e-07, is_dynamic=False, **kwargs)[source]

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.

  • 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

xmin={min(X)if xmin=None(1c)xmin+cmin(X)otherwisexmax={max(X)if xmax=None(1c)xmax+cmax(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}

where xmin/maxx_\text{min/max} is the running average min/max, XX is is the incoming tensor, and cc is the averaging_constant.

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


Only works with torch.per_tensor_affine quantization scheme.


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


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources