快速鍵

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

用於計算量化參數的觀察者模組,基於最小值和最大值的移動平均值。

此觀察者基於輸入張量的最小值和最大值的移動平均值來計算量化參數。此模組記錄輸入張量的平均最小值和最大值,並使用此統計數據來計算量化參數。

參數
  • averaging_constant – 最小值/最大值的平均常數。

  • dtype – 實作參考模型規格所需的 quantize 節點的 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

然後,scale 和 zero point 的計算方式與 MinMaxObserver 中相同。

注意

僅適用於 torch.per_tensor_affine 量化方案。

注意

如果執行最小值等於執行最大值,則 scale 和 zero_point 會設定為 1.0 和 0。

文件

存取 PyTorch 的完整開發者文件

查看文件

教學

取得為初學者和進階開發者提供的深入教學

查看教學

資源

尋找開發資源並獲得解答

查看資源