torch.quantize_per_channel¶
- torch.quantize_per_channel(input, scales, zero_points, axis, dtype) Tensor ¶
将浮点张量转换为具有给定缩放比例和零点的按通道量化的张量。
- 参数:
输入(张量)- 要量化的浮点张量
尺度(张量)- 使用尺度的浮点 1D 张量,大小应与
input.size(axis)
匹配零点(整数)- 使用偏移的整数 1D 张量,大小应与
input.size(axis)
匹配轴(整数)- 应用通道量化维度的维度
dtype (
torch.dtype
) – 返回张量的期望数据类型。必须是以下量化数据类型之一:torch.quint8
,torch.qint8
,torch.qint32
- 返回值:
一个新量化的张量
- 返回类型:
示例:
>>> 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)