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

PyTorch torch.quantize_per_channel function

PyTorch torch.quantize_per_channel function


PyTorch torch reference manual PyTorch torch reference manual

torch.quantize_per_channel is a function in PyTorch used to create a quantized tensor with per-channel quantization.

Function definition

torch.quantize_per_channel(input, scales, zero_points, axis, dtype)


Usage examples

Example

import

torch

Create an input tensor (2D)

input

=

torch.

tensor

(

[

[

1.0

,

0.0

]

,

[

1.0

,

2.0

]

]

)

Quantize per channel

scales: Scaling factor for each channel

zero_points: Zero point for each channel

axis: Specifies which dimension to quantize along

scales

=

torch.

tensor

(

[

0.1

,

0.2

]

)

zero_points

=

torch.

tensor

(

[

10

,

10

]

)

axis

=

0

x

=

torch.

quantize_per_channel

(

input

,

scales

,

zero_points

,

axis

,

dtype

=

torch.

quint8

)

print

(

"Quantized tensor:"

)

print

(

x

)

print

(

"Dequantized original values:"

)

print

(

x.

dequantize

(

)

)


PyTorch torch reference manual PyTorch torch reference manual