PyTorch torch.quantized_batch_norm 関数
torch.quantized_batch_normPyTorchにおいて、量子化テンソルに対してバッチ正規化を実行するための関数です。この関数は量子化モデルの推論時に非常に有用で、量子化の利点を維持しながらバッチ正規化操作を実行できます。
関数定義
torch.quantized_batch_norm(input, weight, bias, mean, var, eps, output_scale, output_zero_point)
パラメータ説明
input: 入力の量子化テンソルweight: バッチ正規化のスケールパラメータbias: バッチ正規化のバイアスパラメータmean: バッチ正規化の平均var: バッチ正規化の分散eps: ゼロ除算を防ぐための小さな定数output_scale: 出力テンソルの量子化スケールoutput_zero_point: 出力テンソルの量子化ゼロポイント
使用例
実例
import torch
# 量子化入力テンソルを作成
input = torch.quantize_per_tensor(torch.randn(1, 3, 4, 4), scale=0.1, zero_point=0, dtype=torch.quint8)
# バッチ正規化パラメータ
weight = torch.ones(3)
bias = torch.zeros(3)
mean = torch.ones(3) * 0.5
var = torch.ones(3) * 0.2
# 量子化バッチ正規化を実行
output = torch.quantized_batch_norm(
input, weight, bias, mean, var,
eps=1e-5, output_scale=0.1, output_zero_point=0
)
print("出力形状:", output.shape)
print("出力型:", output.dtype)
# 量子化入力テンソルを作成
input = torch.quantize_per_tensor(torch.randn(1, 3, 4, 4), scale=0.1, zero_point=0, dtype=torch.quint8)
# バッチ正規化パラメータ
weight = torch.ones(3)
bias = torch.zeros(3)
mean = torch.ones(3) * 0.5
var = torch.ones(3) * 0.2
# 量子化バッチ正規化を実行
output = torch.quantized_batch_norm(
input, weight, bias, mean, var,
eps=1e-5, output_scale=0.1, output_zero_point=0
)
print("出力形状:", output.shape)
print("出力型:", output.dtype)
出力結果は次のとおりです:
输出形状: torch.Size([1, 3, 4, 4]) 输出类型: torch.quint8
その他の拡張
Pytorch torch リファレンスマニュアル