快捷方式

torch.quantize_per_channel

torch.quantize_per_channel(input, scales, zero_points, axis, dtype) Tensor

使用給定的比例因子 (scales) 和零點 (zero points) 將浮點張量轉換為逐通道量化張量。

引數
  • input (Tensor) – 要量化的浮點張量

  • scales (Tensor) – 要使用的浮點 1D 比例因子張量,大小應與 input.size(axis) 匹配

  • zero_points (int) – 要使用的整數 1D 偏移量張量,大小應與 input.size(axis) 匹配

  • axis (int) – 應用逐通道量化的維度

  • dtype (torch.dtype) – 返回張量所需的資料型別。必須是量化資料型別之一:torch.quint8, torch.qint8, torch.qint32

返回

一個新的量化張量

返回型別

Tensor

示例

>>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
tensor([[-1.,  0.],
        [ 1.,  2.]], size=(2, 2), dtype=torch.quint8,
       quantization_scheme=torch.per_channel_affine,
       scale=tensor([0.1000, 0.0100], dtype=torch.float64),
       zero_point=tensor([10,  0]), axis=0)
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
tensor([[  0,  10],
        [100, 200]], dtype=torch.uint8)

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

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

檢視教程

資源

查詢開發資源並獲取問題解答

檢視資源