PyTorch torch.fake_quantize_per_tensor_affine 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.fake_quantize_per_tensor_affinePyTorch において、テンソルに対してテンソルレベルのフェイク量子化(Fake Quantization)を行うための関数です。

関数定義

torch.fake_quantize_per_tensor_affine(input, scale, zero_point, quant_min, quant_max)

使用例

例

import torch

# 入力テンソルを作成
x = torch.randn(2, 3, 4, 5)

# スケールファクターとゼロポイントを定義
scale = torch.tensor(1.5)
zero_point = torch.tensor(0)

# テンソルレベルのフェイク量子化を実行
y = torch.fake_quantize_per_tensor_affine(x, scale, zero_point, quant_min=0, quant_max=255)
print("量子化後の形状:", y.shape)

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張機能