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.

quant_dequant.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from .. import quant_dequant as Float
  2. from .module import QATModule
  3. class QuantStub(Float.QuantStub, QATModule):
  4. r"""A helper :class:`~.QATModule` simply return input, but will quantize
  5. input after converted to :class:`~.QuantizedModule`.
  6. """
  7. with_weight = False
  8. def forward(self, inp):
  9. return self.apply_quant_activation(inp)
  10. @classmethod
  11. def from_float_module(cls, float_module: Float.QuantStub):
  12. r"""
  13. Return a :class:`~.QATModule` instance converted from
  14. a float :class:`~.Module` instance.
  15. """
  16. return cls(name=float_module.name)
  17. class DequantStub(Float.DequantStub, QATModule):
  18. r"""A helper :class:`~.QATModule` simply return input, but will de-quantize
  19. input after converted to :class:`~.QuantizedModule`.
  20. """
  21. with_weight = False
  22. with_act = False
  23. def forward(self, inp):
  24. return inp
  25. @classmethod
  26. def from_float_module(cls, float_module: Float.DequantStub):
  27. r"""
  28. Return a :class:`~.QATModule` instance converted from
  29. a float :class:`~.Module` instance.
  30. """
  31. return cls(name=float_module.name)