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.

concat.py 859 B

1234567891011121314151617181920212223242526
  1. from typing import Iterable
  2. from ... import functional as F
  3. from ...tensor import Tensor
  4. from ..qat import concat as QAT
  5. from .module import QuantizedModule
  6. class Concat(QuantizedModule):
  7. r"""A :class:`~.QuantizedModule` to do quantized :func:`~.concat`, used for inference only."""
  8. def __init__(self, dtype=None, **kwargs):
  9. super().__init__(**kwargs)
  10. self.output_dtype = dtype
  11. def forward(self, inps: Iterable[Tensor], axis: int = 0):
  12. new_inps = tuple(x.astype(self.output_dtype) for x in inps)
  13. return F.concat(new_inps, axis)
  14. @classmethod
  15. def from_qat_module(cls, qat_module: QAT.Concat):
  16. r"""
  17. Return a :class:`~.QuantizedModule` instance converted from a
  18. :class:`~.QATModule` instance.
  19. """
  20. return cls(qat_module.get_activation_dtype(), name=qat_module.name)