PyTorch torch.fake_quantize_per_tensor_affine function
PyTorch torch reference manual
torch.fake_quantize_per_tensor_affine is a PyTorch function for per-tensor fake quantization of a tensor.
Function definition
torch.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max)
Usage examples
Example
import
torch
Create an input tensor
x
=
torch.
randn
(
2
,
3
,
4
,
5
)
Define scale factors and zero points
scale
=
torch.
tensor
(
1.5
)
zero_point
=
torch.
tensor
(
0
)
Perform per-tensor fake quantization
y
=
torch.
fake_quantize_per_tensor_affine
(
x
,
scale
,
zero_point
,
quant_min
=
0
,
quant_max
=
255
)
(
"Quantized shape:"
,
y.
shape
)