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.

batch_matmul_activation.py 900 B

123456789101112131415161718192021222324
  1. from .. import batch_matmul_activation as Float
  2. from .module import QATModule
  3. class BatchMatMulActivation(Float.BatchMatMulActivation, QATModule):
  4. r"""A :class:`~.QATModule` :class:`~.module.BatchMatMulActivation` with QAT support."""
  5. def forward(self, inp):
  6. w_qat = self.apply_quant_weight(self.weight)
  7. b_qat = self.apply_quant_bias(self.bias, inp, w_qat)
  8. return self.apply_quant_activation(self._calc_linear(inp, w_qat, b_qat))
  9. @classmethod
  10. def from_float_module(cls, float_module: Float.BatchMatMulActivation):
  11. qat_module = cls(
  12. float_module.batch,
  13. float_module.in_features,
  14. float_module.out_features,
  15. float_module.bias is not None,
  16. name=float_module.name,
  17. )
  18. qat_module.weight = float_module.weight
  19. qat_module.bias = float_module.bias
  20. return qat_module