Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
ad9331ea
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ad9331ea
编写于
5月 21, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(dtr): import dtr as submodule
GitOrigin-RevId: abecd0f176e6bb292cd19f129b11b43be41f891c
上级
4c5141d6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
42 deletion
+30
-42
imperative/python/megengine/__init__.py
imperative/python/megengine/__init__.py
+1
-1
imperative/python/megengine/dtr.py
imperative/python/megengine/dtr.py
+29
-41
未找到文件。
imperative/python/megengine/__init__.py
浏览文件 @
ad9331ea
...
...
@@ -76,7 +76,6 @@ from .core._imperative_rt.core2 import full_sync as _full_sync
from
.core._imperative_rt.core2
import
sync
as
_sync
from
.core._imperative_rt.utils
import
_set_fork_exec_path_for_timed_func
from
.device
import
*
from
.dtr
import
*
from
.logger
import
enable_debug_log
,
get_logger
,
set_log_file
,
set_log_level
from
.serialization
import
load
,
save
from
.tensor
import
Parameter
,
Tensor
,
tensor
...
...
@@ -100,6 +99,7 @@ del _set_fork_exec_path_for_timed_func
import
megengine.autodiff
import
megengine.data
import
megengine.distributed
import
megengine.dtr
import
megengine.functional
import
megengine.hub
import
megengine.jit
...
...
imperative/python/megengine/dtr.py
浏览文件 @
ad9331ea
...
...
@@ -11,14 +11,14 @@ from typing import Union
from
mprop
import
mproperty
from
.core._imperative_rt.core2
import
set_option
from
.core._imperative_rt.core2
import
set_option
as
_set_option
from
.core._imperative_rt.utils
import
_set_defrag
_eviction_threshold
=
0
_evictee_minimum_size
=
1024
**
2
def
str2bytes
(
text
:
str
)
->
int
:
def
_
str2bytes
(
text
:
str
)
->
int
:
regex
=
re
.
compile
(
r
"(\d+(?:\.\d+)?)\s*([kmg]?b)"
,
re
.
IGNORECASE
)
order
=
[
"b"
,
"kb"
,
"mb"
,
"gb"
]
result
=
regex
.
findall
(
text
)
...
...
@@ -32,7 +32,9 @@ def str2bytes(text: str) -> int:
@
mproperty
def
eviction_threshold
(
mod
):
r
"""
Returns the eviction threshold in bytes.
Get or set the eviction threshold in bytes. It can also be set to a string,
whose formatting supports byte(B), kilobyte(KB), megabyte(MB) and
gigabyte(GB) units.
.. note::
...
...
@@ -40,40 +42,34 @@ def eviction_threshold(mod):
and evict resident tensors until the amount of used memory falls below
this threshold.
"""
return
mod
.
_eviction_threshold
@
eviction_threshold
.
setter
def
eviction_threshold
(
mod
,
value
:
Union
[
int
,
str
]):
r
"""
Change the eviction threshold. If `value` is an int, it represents the
number of bytes. If `value` is a string, its formatting supports bytes(B),
kilobyte(KB), megabyte(MB) and gigabyte(GB) units.
Examples:
.. code-block::
import megengine as mge
mge.dtr.eviction_threshold = 2 * 1024 ** 3
mge.dtr.eviction_threshold = "2GB"
mge.dtr.eviction_threshold = "2048MB"
"""
return
mod
.
_eviction_threshold
@
eviction_threshold
.
setter
def
eviction_threshold
(
mod
,
value
:
Union
[
int
,
str
]):
if
isinstance
(
value
,
str
):
mod
.
_eviction_threshold
=
mod
.
str2bytes
(
value
)
mod
.
_eviction_threshold
=
mod
.
_
str2bytes
(
value
)
elif
isinstance
(
value
,
int
):
mod
.
_eviction_threshold
=
value
else
:
raise
TypeError
(
"`value` should be a str or an int"
)
set_option
(
"dtr_eviction_threshold"
,
mod
.
_eviction_threshold
)
_
set_option
(
"dtr_eviction_threshold"
,
mod
.
_eviction_threshold
)
@
mproperty
def
evictee_minimum_size
(
mod
):
r
"""
Returns the memory threshold of tensors in bytes.
Get or set the memory threshold of tensors in bytes. It can also be set to a
string, whose formatting supports byte(B), kilobyte(KB), megabyte(MB) and
gigabyte(GB) units.
.. note::
...
...
@@ -81,34 +77,26 @@ def evictee_minimum_size(mod):
candidate set. A tensor that is not added to the candidate set will
never be evicted during its lifetime.
"""
return
mod
.
_evictee_minimum_size
@
evictee_minimum_size
.
setter
def
evictee_minimum_size
(
mod
,
value
:
Union
[
int
,
str
]):
r
"""
Change the memory threshold of tensors. If `value` is an int, it represents
the number of bytes. If `value` is a string, its formatting supports bytes(B),
kilobyte(KB), megabyte(MB) and gigabyte(GB) units.
Examples:
.. code-block::
import megengine as mge
mge.dtr.evictee_minimum_size = 2 * 1024 ** 2
mge.dtr.evictee_minimum_size = "2MB"
mge.dtr.evictee_minimum_size = "2048KB"
"""
return
mod
.
_evictee_minimum_size
@
evictee_minimum_size
.
setter
def
evictee_minimum_size
(
mod
,
value
:
Union
[
int
,
str
]):
if
isinstance
(
value
,
str
):
mod
.
_evictee_minimum_size
=
mod
.
str2bytes
(
value
)
mod
.
_evictee_minimum_size
=
mod
.
_
str2bytes
(
value
)
elif
isinstance
(
value
,
int
):
mod
.
_evictee_minimum_size
=
value
else
:
raise
TypeError
(
"`value` should be a str or an int"
)
set_option
(
"dtr_evictee_minimum_size"
,
mod
.
_evictee_minimum_size
)
_
set_option
(
"dtr_evictee_minimum_size"
,
mod
.
_evictee_minimum_size
)
def
enable
():
...
...
@@ -116,16 +104,16 @@ def enable():
Enable to record computing path of tensors and to perform DTR policy.
"""
_set_defrag
(
True
)
set_option
(
"enable_dtr_auto_drop"
,
1
)
set_option
(
"enable_drop"
,
1
)
set_option
(
"buffer_length"
,
0
)
set_option
(
"record_computing_path"
,
1
)
_
set_option
(
"enable_dtr_auto_drop"
,
1
)
_
set_option
(
"enable_drop"
,
1
)
_
set_option
(
"buffer_length"
,
0
)
_
set_option
(
"record_computing_path"
,
1
)
def
disable
():
r
"""
Stop recording computing path of tensors and performing DTR policy.
"""
set_option
(
"enable_dtr_auto_drop"
,
0
)
set_option
(
"enable_drop"
,
0
)
set_option
(
"record_computing_path"
,
0
)
_
set_option
(
"enable_dtr_auto_drop"
,
0
)
_
set_option
(
"enable_drop"
,
0
)
_
set_option
(
"record_computing_path"
,
0
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录