评价此页

PerChannelMinMaxObserver#

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

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

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

参数
  • ch_axis – 通道轴

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

量化参数的计算方式与 MinMaxObserver 中的相同,不同之处在于运行的 min/max 值是按通道存储的。因此,缩放因子和零点也按通道计算。

注意

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

reset_min_max_vals()[源代码]#

重置 min/max 值。