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

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

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