r"""To standardize FakeQuant, Observer and Tensor's qparams format. If custom qparams is needed, inherit this class and add custom ``__slots__``.
| 67 | |
| 68 | |
| 69 | class QParams: |
| 70 | r"""To standardize FakeQuant, Observer and Tensor's qparams format. If custom |
| 71 | qparams is needed, inherit this class and add custom ``__slots__``. |
| 72 | """ |
| 73 | |
| 74 | __slots__ = "mode", "dtype_meta", "scale", "zero_point" |
| 75 | |
| 76 | def __init__( |
| 77 | self, |
| 78 | mode: QuantMode, |
| 79 | dtype_meta: QuantDtypeMeta, |
| 80 | scale: Tensor, |
| 81 | zero_point: Tensor, |
| 82 | ): |
| 83 | self.mode = mode |
| 84 | self.dtype_meta = dtype_meta |
| 85 | self.scale = scale |
| 86 | self.zero_point = zero_point |
| 87 | |
| 88 | def update(self, qparams: "QParams"): |
| 89 | for key in self.__slots__: |
| 90 | setattr(self, key, getattr(qparams, key)) |
| 91 | |
| 92 | def __eq__(self, other): |
| 93 | if len(self.__slots__) != len(other.__slots__): |
| 94 | return False |
| 95 | for key in self.__slots__: |
| 96 | if not hasattr(other, key) or getattr(self, key) != getattr(other, key): |
| 97 | return False |
| 98 | return True |
| 99 | |
| 100 | def __repr__(self): |
| 101 | content = ", ".join( |
| 102 | ["{}={}".format(key, getattr(self, key)) for key in self.__slots__] |
| 103 | ) |
| 104 | return "QParams({})".format(content) |
| 105 | |
| 106 | |
| 107 | class LSQParams(QParams): |
no outgoing calls
no test coverage detected