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

PyTorch torch.fake_quantize_per_channel_affine function

PyTorch torch.fake_quantize_per_channel_affine function


PyTorch torch reference manual PyTorch torch reference manual

torch.fake_quantize_per_channel_affine is a PyTorch function for per-channel fake quantization of a tensor, commonly used in quantization-aware training.

Function definition

torch.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max)


Usage examples

Example

import

torch

Create an input tensor

x

=

torch.

randn

(

2

,

3

,

4

,

5

)

Define scale factors and zero points

scale

=

torch.

tensor

(

[

1.0

,

1.2

,

1.5

]

)

zero_point

=

torch.

tensor

(

[

0

,

0

,

0

]

,

dtype

=

torch.

long

)

Perform per-channel fake quantization

y

=

torch.

fake_quantize_per_channel_affine

(

x

,

scale

,

zero_point

,

axis

=

1

,

quant_min

=

0

,

quant_max

=

255

)

print

(

"Quantized shape:"

,

y.

shape

)


PyTorch torch reference manual PyTorch torch reference manual