• 文档 >
  • 量化 >
  • 量化 API 参考 >
  • 移动平均最小最大观察者
快捷键

移动平均最小最大观察者 ¶

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)[source][source]

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

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

参数:
  • 平均常数 - 最小/最大值的平均常数。

  • dtype - 量化节点需要的 dtype 参数,以实现参考模型规范。

  • qscheme – 要使用的量化方案

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

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

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

  • eps (Tensor) – 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。


© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源