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.

dtr.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. # MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  3. #
  4. # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  5. #
  6. # Unless required by applicable law or agreed to in writing,
  7. # software distributed under the License is distributed on an
  8. # "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. from ..core._imperative_rt.core2 import set_option
  10. from ..core._imperative_rt.utils import _set_defrag
  11. class DTR:
  12. r"""
  13. DTR implements `Dynamic Tensor Rematerialization <https://arxiv.org/abs/2006.09616>`_ in MegEngine.
  14. It is basically an online algorithm for checkpointing driven by certain eviction policies.
  15. .. code-block::
  16. from megengine.utils.dtr import DTR
  17. ds = DTR(memory_budget=5*1024**3)
  18. # your training code
  19. """
  20. def __init__(self, memory_budget=0, tensor_lowerbound=1048576):
  21. r"""
  22. :param memory_budget: int. The threshold of memory usage. When memory
  23. usage exceeds this value, auto evict will be triggered.
  24. :param tensor_lowerbound: int. The minimum memory limit of the tensor
  25. that can be evicted. Default: 1MB.
  26. """
  27. if memory_budget > 0:
  28. set_option("enable_auto_drop", 1)
  29. set_option("enable_drop", 1)
  30. set_option("buffer_length", 0)
  31. set_option("memory_budget", memory_budget)
  32. set_option("tensor_lowerbound", tensor_lowerbound)
  33. set_option("record_computing_path", 1)
  34. _set_defrag(True)

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