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

PyTorch torch.quantized_batch_norm function

PyTorch torch.quantized_batch_norm function


PyTorch torch reference manual PyTorch torch reference manual

torch.quantized_batch_norm is a function in PyTorch used to perform batch normalization on quantized tensors. This function is very useful during inference with quantized models, allowing batch normalization while preserving the benefits of quantization.

Function definition

torch.quantized_batch_norm(input, weight, bias, mean, var, eps, output_scale, output_zero_point)

Parameter Description


Usage examples

Example

import

torch

Create a quantized input tensor

input

=

torch.

quantize_per_tensor

(

torch.

randn

(

1

,

3

,

4

,

4

)

,

scale

=

0.1

,

zero_point

=

0

,

dtype

=

torch.

quint8

)

Batch normalization parameters

weight

=

torch.

ones

(

3

)

bias

=

torch.

zeros

(

3

)

mean

=

torch.

ones

(

3

)

0.5

var

=

torch.

ones

(

3

)

0.2

Perform quantized batch normalization

output

=

torch.

quantized_batch_norm

(

   

input

,

weight

,

bias

,

mean

,

var

,

    eps

=

1e-5

,

output_scale

=

0.1

,

output_zero_point

=

0

)

print

(

"Output shape:"

,

output.

shape

)

print

(

"Output type:"

,

output.

dtype

)

The output is:

输出形状: torch.Size([1, 3, 4, 4])

输出类型: torch.quint8


PyTorch torch reference manual PyTorch torch reference manual