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 848 B

123456789101112131415161718192021222324252627282930313233
  1. from ..core._imperative_rt import TensorSanityCheckImpl
  2. from ..core._imperative_rt.imperative 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. .. testcode::
  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. print(c.numpy())
  14. .. testoutput::
  15. [4 6]
  16. """
  17. def __init__(self):
  18. self.impl = TensorSanityCheckImpl()
  19. def __enter__(self):
  20. sync()
  21. self.impl.enable()
  22. return self
  23. def __exit__(self, val, type, trace):
  24. sync()
  25. self.impl.disable()

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台