Fonction torch.fake_quantize_per_channel_affine de PyTorch
Manuel de référence Pytorch torch
torch.fake_quantize_per_channel_affineIl s'agit d'une fonction de PyTorch utilisée pour la quantification factice par canal des tenseurs, couramment utilisée dans l'entraînement conscient de la quantification.
Définition de fonction
torch.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max)
Exemple d'utilisation
Exemple
import torch
# Créer un tenseur d'entrée
x = torch.randn(2, 3, 4, 5)
# Définir l'échelle et le point zéro
scale = torch.tensor([1.0, 1.2, 1.5])
zero_point = torch.tensor([0, 0, 0], dtype=torch.long)
# Effectuer une quantification factice par canal
y = torch.fake_quantize_per_channel_affine(x, scale, zero_point, axis=1, quant_min=0, quant_max=255)
print("Forme quantifiée :", y.shape)
# Créer un tenseur d'entrée
x = torch.randn(2, 3, 4, 5)
# Définir l'échelle et le point zéro
scale = torch.tensor([1.0, 1.2, 1.5])
zero_point = torch.tensor([0, 0, 0], dtype=torch.long)
# Effectuer une quantification factice par canal
y = torch.fake_quantize_per_channel_affine(x, scale, zero_point, axis=1, quant_min=0, quant_max=255)
print("Forme quantifiée :", y.shape)
Autres extensions