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 1.2 kB

123456789101112131415161718192021222324252627282930313233
  1. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  2. #
  3. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  4. #
  5. # Unless required by applicable law or agreed to in writing,
  6. # software distributed under the License is distributed on an
  7. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8. from typing import Iterable
  9. from ... import functional as F
  10. from ...tensor import Tensor
  11. from ..qat import concat as QAT
  12. from .module import QuantizedModule
  13. class Concat(QuantizedModule):
  14. r"""A :class:`~.QuantizedModule` to do quantized :func:`~.concat`, used for inference only."""
  15. def __init__(self, dtype=None, **kwargs):
  16. super().__init__(**kwargs)
  17. self.output_dtype = dtype
  18. def forward(self, inps: Iterable[Tensor], axis: int = 0):
  19. new_inps = tuple(x.astype(self.output_dtype) for x in inps)
  20. return F.concat(new_inps, axis)
  21. @classmethod
  22. def from_qat_module(cls, qat_module: QAT.Concat):
  23. r"""
  24. Return a :class:`~.QuantizedModule` instance converted from a
  25. :class:`~.QATModule` instance.
  26. """
  27. return cls(qat_module.get_activation_dtype(), name=qat_module.name)