评价此页

MovingAveragePerChannelMinMaxObserver#

class torch.ao.quantization.observer.MovingAveragePerChannelMinMaxObserver(averaging_constant=0.01, ch_axis=0, dtype=torch.quint8, qscheme=torch.per_channel_affine, reduce_range=False, quant_min=None, quant_max=None, eps=1.1920928955078125e-07, is_dynamic=False, **kwargs)[源代码]#

用于基于运行时的逐通道最小/最大值计算量化参数的观察者模块。

此观察器使用张量的 min/max 统计信息来计算每个通道的量化参数。该模块记录传入张量的运行最小值和最大值,并使用此统计信息来计算量化参数。

参数
  • averaging_constant – min/max 的平均常数。

  • ch_axis – 通道轴

  • dtype – 量化数据类型

  • 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.

量化参数的计算方式与 MovingAverageMinMaxObserver 中的相同,不同之处在于运行的 min/max 值是按通道存储的。因此,比例因子(scales)和零点(zero points)也是按通道计算的。

注意

如果运行的最小值等于运行的最大值,则比例因子和零点将设置为 1.0 和 0。