• 文件 >
  • 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

傳回一個新的 Tensor,其中的資料使用 scalezero_pointquant_minquant_max 進行偽量化後的 input

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 純量或 float32 Tensor) – 量化比例

  • zero_point (int64 純量或 int32 Tensor) – 量化零點

  • quant_min (int64) – 量化域的下限

  • quant_max (int64) – 量化域的上限

回傳值

一個新建立的 fake_quantized 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 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並獲得您的問題解答

檢視資源