• 文件 >
  • torch >
  • torch.fake_quantize_per_tensor_affine
快捷方式

torch.fake_quantize_per_tensor_affine

torch.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max) Tensor

返回一個新張量,其資料使用 scalezero_pointquant_minquant_maxinput 進行偽量化。

output=(min(quant_max,max(quant_min,std::nearby_int(input/scale)+zero_point))zero_point)×scale\text{output} = ( min( \text{quant\_max}, max( \text{quant\_min}, \text{std::nearby\_int}(\text{input} / \text{scale}) + \text{zero\_point} ) ) - \text{zero\_point} ) \times \text{scale}
引數
  • input (Tensor) – 輸入值,torch.float32 張量

  • scale (double scalar or float32 Tensor) – 量化比例 (quantization scale)

  • zero_point (int64 scalar or int32 Tensor) – 量化零點 (quantization zero_point)

  • quant_min (int64) – 量化域下界

  • quant_max (int64) – 量化域上界

返回

一個新偽量化的 torch.float32 張量

返回型別

Tensor

示例

>>> x = torch.randn(4)
>>> x
tensor([ 0.0552,  0.9730,  0.3973, -1.0780])
>>> torch.fake_quantize_per_tensor_affine(x, 0.1, 0, 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])
>>> torch.fake_quantize_per_tensor_affine(x, torch.tensor(0.1), torch.tensor(0), 0, 255)
tensor([0.1000, 1.0000, 0.4000, 0.0000])

文件

訪問 PyTorch 全面的開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得解答

檢視資源