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.

module.py 751 B

1234567891011121314151617181920212223242526
  1. from abc import abstractmethod
  2. from ..module import Module
  3. from ..qat import QATModule
  4. class QuantizedModule(Module):
  5. r"""Base class of quantized :class:`~.Module`,
  6. which should be converted from :class:`~.QATModule` and not support traning.
  7. """
  8. def __call__(self, *inputs, **kwargs):
  9. if self.training:
  10. raise ValueError("quantized module only support inference.")
  11. return super().__call__(*inputs, **kwargs)
  12. def __repr__(self):
  13. return "Quantized." + super().__repr__()
  14. @classmethod
  15. @abstractmethod
  16. def from_qat_module(cls, qat_module: QATModule):
  17. r"""
  18. Return a :class:`~.QATModule` instance converted from
  19. a float :class:`~.Module` instance.
  20. """