PyTorch torch.quantize_per_channel 関数
torch.quantize_per_channelは PyTorch において、チャネルごと(per-channel)に量子化された量子化テンソルを作成するための関数です。
関数定義
torch.quantize_per_channel(input, scales, zero_points, axis, dtype)
使用例
実例
import torch
# 入力テンソルを作成 (2D)
input = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
# チャネルごとに量子化
# scales: 各チャネルのスケール係数
# zero_points: 各チャネルのゼロ点
# axis: どの次元に沿って量子化するかを指定
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("量子化テンソル:")
print(x)
print("元の値を逆量子化:")
print(x.dequantize())
# 入力テンソルを作成 (2D)
input = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
# チャネルごとに量子化
# scales: 各チャネルのスケール係数
# zero_points: 各チャネルのゼロ点
# axis: どの次元に沿って量子化するかを指定
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("量子化テンソル:")
print(x)
print("元の値を逆量子化:")
print(x.dequantize())
その他の拡張
Pytorch torch リファレンスマニュアル