Shortcuts

torch.quantize_per_channel

torch.quantize_per_channel(input, scales, zero_points, axis, dtype) 张量

将浮点张量转换为具有给定比例和零点的逐通道量化张量。

Parameters
  • 输入 (张量) – 要量化的浮点张量

  • scales (Tensor) – 要使用的浮点数一维张量,大小应与 input.size(axis) 匹配

  • zero_points (int) – 整数1D张量,用于偏移量,大小应与input.size(axis)匹配

  • (int) – 在哪个维度上应用逐通道量化

  • dtype (torch.dtype) – 返回张量所需的数据类型。 必须是以下量化数据类型之一:torch.quint8, torch.qint8, torch.qint32

Returns

一个新的量化张量

Return type

张量

示例:

>>> 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)
优云智算