mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
### Summary: This PR updates the design of APoT Observer, Quantizer, and Tensor to be more consistent with their uniform counterparts in the PyTorch framework. APoT Observer now calculates alpha as the max between the absolute values of the max and min values in the input tensor. APoT Quantizer is modified so its instance methods quantize_APoT and dequantize_APoT are called by their global method counterparts. APoT Tensor is modified to account for the new method definition of the `quantize_APoT` from APoT Quantizer. ### Test Plan: Run APoT Observer class unit tests with: `python pytorch/test/quantization/core/experimental/test_nonuniform_observer.py` Run APoT Quantize class unit tests with: `python pytorch/test/quantization/core/experimental/test_quantizer.py` Run APoT Tensor class unit tests with: `python pytorch/test/quantization/core/experimental/test_quantized_tensor.py` Pull Request resolved: https://github.com/pytorch/pytorch/pull/80075 Approved by: https://github.com/jerryzh168
15 lines
387 B
Python
15 lines
387 B
Python
import torch
|
|
from torch.ao.quantization.experimental.quantizer import APoTQuantizer
|
|
|
|
# class to store APoT quantized tensor
|
|
class TensorAPoT():
|
|
quantizer: APoTQuantizer
|
|
data: torch.Tensor
|
|
|
|
def __init__(self, quantizer: APoTQuantizer, apot_data: torch.Tensor):
|
|
self.quantizer = quantizer
|
|
self.data = apot_data
|
|
|
|
def int_repr(self):
|
|
return self.data
|