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.

tensor_sanity_check.py 811 B

123456789101112131415161718192021222324252627282930
  1. from ..core._imperative_rt import TensorSanityCheckImpl
  2. from ..core._imperative_rt.core2 import sync
  3. class TensorSanityCheck:
  4. r"""An object that checks whether the input tensors of each operator have changed before and after the operation.
  5. Examples:
  6. .. code-block:: python
  7. from megengine import tensor
  8. from megengine.utils.tensor_sanity_check import TensorSanityCheck
  9. with TensorSanityCheck() as checker:
  10. a = tensor([1, 2])
  11. b = tensor([3, 4])
  12. c = a + b
  13. """
  14. def __init__(self):
  15. self.impl = TensorSanityCheckImpl()
  16. def __enter__(self):
  17. sync()
  18. self.impl.enable()
  19. return self
  20. def __exit__(self, val, type, trace):
  21. sync()
  22. self.impl.disable()