You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

elemwise.py 706 B

123456789101112131415161718192021
  1. from .. import elemwise as Float
  2. from .module import QATModule
  3. class Elemwise(Float.Elemwise, QATModule):
  4. r"""A :class:`~.QATModule` to do :mod:`~.functional.elemwise` operator with QAT support.
  5. Could be applied with :class:`~.Observer` and :class:`~.quantization.fake_quant.FakeQuantize`.
  6. """
  7. with_weight = False
  8. def forward(self, *inps):
  9. return self.apply_quant_activation(super().forward(*inps))
  10. @classmethod
  11. def from_float_module(cls, float_module: Float.Elemwise):
  12. r"""
  13. Return a :class:`~.QATModule` instance converted from
  14. a float :class:`~.Module` instance.
  15. """
  16. return cls(float_module.method, name=float_module.name)