PyTorch torch.dequantize() method returns an fp32 Tensor by dequantizing a quantized Tensor.
Syntax
tensor.dequantize()
Example: Using the torch.dequantize() method
import torch
# Create a float tensor
x = torch.randn(2, 3)
# Quantize the tensor using 8-bit linear quantization
xq = torch.quantize_per_tensor(x, 0.1, 0, torch.quint8)
# Print the quantized tensor
print(xq)
# Dequantize the tensor using torch.dequantize()
xd = torch.dequantize(xq)
# Print the dequantized tensor
print(xd)
Output
That’s it!

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Machine Learning frameworks like PyTorch and Tensorflow is a testament to his versatility and commitment to the craft.