Shortcuts

直方图观察器

class torch.ao.quantization.observer.HistogramObserver(bins=2048, upsample_rate=128, dtype=torch.quint8, qscheme=torch.per_tensor_affine, reduce_range=False, quant_min=None, quant_max=None, factory_kwargs=None, eps=1.1920928955078125e-07, is_dynamic=False, **kwargs)[源代码]

该模块记录张量值的运行直方图以及最小/最大值。calculate_qparams 将计算比例和零点。

Parameters
  • bins (int) – 用于直方图的箱数

  • upsample_rate (int) – 直方图上采样的因子,用于在不同观测值之间插值具有不同范围的直方图

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

  • qscheme – 要使用的量化方案

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

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

比例和零点计算如下:

  1. Create the histogram of the incoming inputs.

    直方图是连续计算的,每个区间的范围会随着观察到的每个新张量的变化而变化。

  2. Search the distribution in the histogram for optimal min/max values.

    搜索最小/最大值确保了相对于浮点模型的量化误差的最小化。

  3. Compute the scale and zero point the same way as in the

    MinMaxObserver

优云智算