快捷方式

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 的全面开发者文档

查看文档

教程

获取针对初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获取问题解答

查看资源