PyTorch torch.quantize_per_tensor function
PyTorch torch reference manual
torch.quantize_per_tensor is a function in PyTorch used to create a quantized tensor with per-tensor quantization.
Function definition
torch.quantize_per_tensor(input, scale, zero_point, dtype)
Usage examples
Example
import
torch
Create an input tensor
input
=
torch.
tensor
(
[
[
1.0
,
0.0
]
,
[
1.0
,
2.0
]
]
)
Quantize per tensor
scale: Quantization scale factor
zero_point: Zero point
dtype: Quantization data type
x
=
torch.
quantize_per_tensor
(
input
,
scale
=
0.1
,
zero_point
=
10
,
dtype
=
torch.
quint8
)
(
"Quantized tensor:"
)
(
x
)
(
"Dequantized original values:"
)
(
x.
dequantize
(
)
)