torch.quantize_per_channel
- torch.quantize_per_channel(input, scales, zero_points, axis, dtype) → Tensor
-
将浮点张量转换为具有给定缩放因子和零点的 per-通道量化张量。
- 参数
-
-
输入 (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
-
- 返回值
-
一个新的量化后的张量
- 返回类型
示例:
>>> 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)