def quantize_APoT(self, tensor2quantize: Tensor): result = torch.tensor([]) # map float_to_apot over tensor2quantize elements result = tensor2quantize.apply_(lambda x: float_to_apot( x, self.quantization_levels, self.level_indices)) return result
def quant_levels_visualization(self, obs_result, filename): xs = [float(x) / 1000.0 for x in range(1000)] ys = [apot_to_float(float_to_apot(x, obs_result[1], obs_result[2]), obs_result[1], obs_result[2]).item() for x in xs] f = plt.figure(figsize=(15, 10)) plt.plot(xs, ys) plt.title("APoT Quantization Plot") plt.xlabel("Full Precision") plt.ylabel("Quantized") plt.show()
def quantize(self, tensor2quantize: Tensor): result = torch.tensor([]) # map float_to_apot over tensor2quantize elements tensor2quantize = tensor2quantize.apply_(lambda x: float_to_apot( x, self.quantization_levels, self.level_indices, self.alpha)) from torch.ao.quantization.experimental.APoT_tensor import TensorAPoT result = TensorAPoT(self, tensor2quantize) return result
def quant_levels_visualization(self, signed=False): alpha, gamma, quantization_levels, level_indices = self.calculate_qparams(signed) xs = [float(x) / 1000.0 for x in range(1000)] ys = [apot_to_float(float_to_apot(x, quantization_levels, level_indices, alpha), quantization_levels, level_indices).item() for x in xs] f = plt.figure(figsize=(15, 10)) plt.plot(xs, ys) plt.title("APoT Quantization Plot") plt.xlabel("Full Precision") plt.ylabel("Quantized") plt.show()