用於根據執行時的最小值和最大值計算量化引數的觀察者模組。
此觀察者使用張量的最小值/最大值統計資料來計算量化引數。該模組記錄傳入張量的執行時的最小值和最大值,並使用此統計資料來計算量化引數。
- 引數
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.
給定執行時的最小值/最大值為 xmin 和 xmax,縮放因子 s 和零點 z 的計算方法如下:
執行時的最小值/最大值 xmin/max 的計算方法如下:
xminxmax={min(X)min(xmin,min(X))if xmin=Noneotherwise={max(X)max(xmax,max(X))if xmax=Noneotherwise 其中 X 是觀察到的張量。
縮放因子 s 和零點 z 的計算方法如下:
if Symmetric:Otherwise:s=2max(∣xmin∣,xmax)/(Qmax−Qmin)z={0128if dtype is qint8otherwises=(xmax−xmin)/(Qmax−Qmin)z=Qmin−round(xmin/s) 其中 Qmin 和 Qmax 是量化資料型別的最小值和最大值。
警告
dtype 只能取 torch.qint8 或 torch.quint8。
注意
如果執行時的最小值等於執行時的最大值,則縮放因子和零點分別設定為 1.0 和 0。
-
calculate_qparams()[source]
計算量化引數。
-
forward(x_orig)[source]
記錄 x 的執行時的最小值和最大值。
-
reset_min_max_vals()[source]
重置最小值/最大值。