Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.quantize_per_tensor function

PyTorch torch.quantize_per_tensor function


PyTorch torch reference manual 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

)

print

(

"Quantized tensor:"

)

print

(

x

)

print

(

"Dequantized original values:"

)

print

(

x.

dequantize

(

)

)


PyTorch torch reference manual PyTorch torch reference manual