PyTorch torch.dequantize() Method

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

Using the torch.dequantize() method

That’s it!

Leave a Comment