PyTorch torch.fake_quantize_per_tensor_affine Function
PyTorch torch Reference Manual
torch.fake_quantize_per_tensor_affineis a function in PyTorch used to perform tensor-level fake quantization on tensors.
Function Definition
torch.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max)
Usage Example
Example
import torch
# Create input tensor
x = torch.randn(2, 3, 4, 5)
# Define scale factor and zero point
scale = torch.tensor(1.5)
zero_point = torch.tensor(0)
# Perform tensor-level fake quantization
y = torch.fake_quantize_per_tensor_affine(x, scale, zero_point, quant_min=0, quant_max=255)
print("Quantized shape:", y.shape)
# Create input tensor
x = torch.randn(2, 3, 4, 5)
# Define scale factor and zero point
scale = torch.tensor(1.5)
zero_point = torch.tensor(0)
# Perform tensor-level fake quantization
y = torch.fake_quantize_per_tensor_affine(x, scale, zero_point, quant_min=0, quant_max=255)
print("Quantized shape:", y.shape)
Other Extensions