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_config.py 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. class DTRConfig:
  10. r"""Configuration for DTR memory optimization.
  11. Args:
  12. eviction_threshold: eviction threshold in bytes. When GPU memory usage
  13. exceeds this value, DTR will heuristically select and evict resident
  14. tensors until the amount of used memory falls below this threshold.
  15. evictee_minimum_size: memory threshold of tensors in bytes. Only tensors
  16. whose size exceeds this threshold will be added to the candidate set.
  17. A tensor that is not added to the candidate set will never be evicted
  18. during its lifetime. Default: 1048576.
  19. recomp_memory_factor: hyperparameter of the estimated memory of recomputing
  20. the tensor. The larger this value is, the less memory-consuming
  21. tensor will be evicted in heuristic strategies. This value is greater
  22. than or equal to 0. Default: 1.
  23. recomp_time_factor: hyperparameter of the estimated time of recomputing
  24. the tensor. The larger this value is, the less time-consuming
  25. tensor will be evicted in heuristic strategies. This value is greater
  26. than or equal to 0. Default: 1.
  27. """
  28. def __init__(
  29. self,
  30. eviction_threshold: int = 0,
  31. evictee_minimum_size: int = 1 << 20,
  32. recomp_memory_factor: float = 1,
  33. recomp_time_factor: float = 1,
  34. ):
  35. assert eviction_threshold > 0, "eviction_threshold must be greater to zero"
  36. self.eviction_threshold = eviction_threshold
  37. assert (
  38. evictee_minimum_size >= 0
  39. ), "evictee_minimum_size must be greater or equal to zero"
  40. self.evictee_minimum_size = evictee_minimum_size
  41. assert (
  42. recomp_memory_factor >= 0
  43. ), "recomp_memory_factor must be greater or equal to zero"
  44. self.recomp_memory_factor = recomp_memory_factor
  45. assert (
  46. recomp_time_factor >= 0
  47. ), "recomp_time_factor must be greater or equal to zero"
  48. self.recomp_time_factor = recomp_time_factor

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