torch.quantize_per_tensor¶
- torch.quantize_per_tensor(input, scale, zero_point, dtype) Tensor ¶
将浮点张量转换为具有给定比例和零点的量化张量。
- 参数
- 返回值
一个新的量化张量或量化张量列表。
- 返回类型
示例
>>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8, quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10) >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, torch.quint8).int_repr() tensor([ 0, 10, 20, 30], dtype=torch.uint8) >>> torch.quantize_per_tensor([torch.tensor([-1.0, 0.0]), torch.tensor([-2.0, 2.0])], >>> torch.tensor([0.1, 0.2]), torch.tensor([10, 20]), torch.quint8) (tensor([-1., 0.], size=(2,), dtype=torch.quint8, quantization_scheme=torch.per_tensor_affine, scale=0.1, zero_point=10), tensor([-2., 2.], size=(2,), dtype=torch.quint8, quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=20)) >>> torch.quantize_per_tensor(torch.tensor([-1.0, 0.0, 1.0, 2.0]), torch.tensor(0.1), torch.tensor(10), torch.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=torch.quint8, quantization_scheme=torch.per_tensor_affine, scale=0.10, zero_point=10)