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, is_dynamic=False, **kwargs)[源代码]

用于基于最小值和最大值的移动平均值计算量化参数的观察者模块。

此观察者基于传入张量的最小值和最大值的移动平均值来计算量化参数。该模块记录传入张量的平均最小值和最大值,并使用此统计信息来计算量化参数。

Parameters
  • averaging_constant – 用于最小/最大值的平均常数。

  • dtype – 实现参考模型规范所需的quantize节点的dtype参数。

  • qscheme – 要使用的量化方案

  • reduce_range – 将量化数据类型的范围减少1位

  • quant_min – 最小量化值。如果未指定,它将遵循8位设置。

  • quant_max – 最大量化值。如果未指定,它将遵循8位设置。

  • eps (张量) – 用于float32的Epsilon值,默认为torch.finfo(torch.float32).eps

移动平均的最小/最大值计算如下

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}

其中 xmin/maxx_\text{min/max} 是运行平均最小/最大值,XX 是输入的张量,ccaveraging_constant

比例和零点随后按照 MinMaxObserver中的方式计算。

注意

仅适用于 torch.per_tensor_affine 量化方案。

注意

如果运行最小值等于运行最大值,则比例和零点分别设置为1.0和0。

优云智算