Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
de8ffe0c
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
de8ffe0c
编写于
1月 14, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(imperative): unify interpreter option setting
GitOrigin-RevId: 53510445cc38866a4bae1059aec56e4c91e9ca4d
上级
8b60bdfa
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
32 addition
and
43 deletion
+32
-43
imperative/python/megengine/__init__.py
imperative/python/megengine/__init__.py
+1
-0
imperative/python/megengine/core/_config.py
imperative/python/megengine/core/_config.py
+7
-7
imperative/python/megengine/dtr/dtr.py
imperative/python/megengine/dtr/dtr.py
+1
-1
imperative/python/src/tensor.cpp
imperative/python/src/tensor.cpp
+2
-10
imperative/python/test/integration/test_converge_with_drop.py
...rative/python/test/integration/test_converge_with_drop.py
+3
-3
imperative/python/test/unit/core/test_interpreter.py
imperative/python/test/unit/core/test_interpreter.py
+18
-22
未找到文件。
imperative/python/megengine/__init__.py
浏览文件 @
de8ffe0c
...
...
@@ -79,6 +79,7 @@ from .core._imperative_rt.core2 import close as _close
from
.core._imperative_rt.core2
import
full_sync
as
sync
from
.core._imperative_rt.core2
import
sync
as
_sync
from
.core._imperative_rt.utils
import
_set_fork_exec_path_for_timed_func
from
.config
import
*
from
.device
import
*
from
.logger
import
enable_debug_log
,
get_logger
,
set_log_file
,
set_log_level
from
.serialization
import
load
,
save
...
...
imperative/python/megengine/core/_config.py
浏览文件 @
de8ffe0c
...
...
@@ -9,12 +9,12 @@
import
os
from
contextlib
import
contextmanager
from
._imperative_rt.core2
import
get_option
,
set_option
__compute_mode
=
"default"
__conv_format
=
"default"
_benchmark_kernel
=
False
_deterministic_kernel
=
False
_async_level
=
os
.
getenv
(
"MEGENGINE_INTERP_ASYNC_LEVEL"
,
2
)
__all__
=
[
"benchmark_kernel"
,
...
...
@@ -77,13 +77,13 @@ def async_level(mod) -> int:
import megengine as mge
mge.config.async_level = 2
"""
return
_async_level
return
get_option
(
"async_level"
)
@
async_level
.
setter
def
async_level
(
mod
,
level
:
int
):
global
_async_level
_async_level
=
level
assert
level
>=
0
and
level
<=
2
,
"async_level should be 0, 1 or 2"
set_option
(
"async_level"
,
level
)
@
property
...
...
@@ -148,7 +148,7 @@ def _reset_execution_config(
orig_flags
=
(
_benchmark_kernel
,
_deterministic_kernel
,
_async_level
,
get_option
(
"async_level"
)
,
__compute_mode
,
__conv_format
,
)
...
...
@@ -157,7 +157,7 @@ def _reset_execution_config(
if
deterministic_kernel
is
not
None
:
_deterministic_kernel
=
deterministic_kernel
if
async_level
is
not
None
:
_async_level
=
async_level
set_option
(
"async_level"
,
async_level
)
if
compute_mode
is
not
None
:
__compute_mode
=
compute_mode
if
conv_format
is
not
None
:
...
...
imperative/python/megengine/dtr/dtr.py
浏览文件 @
de8ffe0c
...
...
@@ -9,8 +9,8 @@
import
re
from
typing
import
Union
from
..core
import
set_option
as
_set_option
from
..core._imperative_rt.core2
import
clear_candidates
as
_clear_candidates
from
..core._imperative_rt.core2
import
set_option
as
_set_option
_eviction_threshold
=
0
_evictee_minimum_size
=
1024
**
2
...
...
imperative/python/src/tensor.cpp
浏览文件 @
de8ffe0c
...
...
@@ -599,7 +599,7 @@ void init_tensor(py::module m) {
auto
val2
=
py_async_error
.
py
::
object
::
operator
()(
"An async error is reported. See above for the actual cause."
" Hint: This is where it is reported, not where it happened."
" You may call `megengine.co
re.set_option('async_level', 0)`
"
" You may call `megengine.co
nfig.async_level = 0
"
"to get better error reporting."
);
PyException_SetCause
(
val2
.
ptr
(),
val
);
// PyException_SetCause steals reference
...
...
@@ -698,20 +698,12 @@ void init_tensor(py::module m) {
py_task_q
.
wait_all_task_finish
();
};
m
.
def
(
"clear_candidates"
,
[
channel
]()
{
channel
->
clear_candidates
();
});
m
.
def
(
"set_option"
,
[
channel
](
std
::
string
name
,
size_t
value
)
{
channel
->
set_option
(
name
,
value
);
});
m
.
def
(
"clear_candidates"
,
[
channel
]()
{
channel
->
clear_candidates
();
});
m
.
def
(
"get_option"
,
[
channel
](
std
::
string
name
)
{
return
channel
->
get_option
(
name
);
});
m
.
def
(
"_set_drop_flag"
,
[
channel
](
bool
flag
)
{
channel
->
set_option
(
"enable_drop"
,
flag
);
});
m
.
def
(
"config_async_level"
,
[
channel
](
int
level
)
{
mgb_assert
(
level
>=
0
and
level
<=
2
,
"async_level should be 0, 1 or 2"
);
channel
->
set_option
(
"async_level"
,
level
);
});
m
.
def
(
"get_async_level"
,
[
channel
]()
{
return
channel
->
get_option
(
"async_level"
);
});
m
.
def
(
"set_buffer_length"
,
[
channel
](
int
length
)
{
mgb_assert
(
length
>=
0
and
length
<
100
,
"buffer_length should be in [0, 100)"
);
channel
->
set_option
(
"buffer_length"
,
length
);
...
...
imperative/python/test/integration/test_converge_with_drop.py
浏览文件 @
de8ffe0c
...
...
@@ -14,7 +14,7 @@ import megengine as mge
import
megengine.autodiff
as
ad
import
megengine.functional
as
F
from
megengine
import
Tensor
from
megengine.core
._imperative_rt.core2
import
_set_drop_flag
,
get_option
,
set_option
from
megengine.core
import
get_option
,
set_option
from
megengine.module
import
Linear
,
Module
from
megengine.optimizer
import
SGD
...
...
@@ -75,7 +75,7 @@ class XORNet(Module):
def
test_training_converge_with_drop
():
_set_drop_flag
(
True
)
set_option
(
"enable_drop"
,
1
)
old_buffer_length
=
get_option
(
"buffer_length"
)
set_option
(
"buffer_length"
,
0
)
net
=
XORNet
()
...
...
@@ -118,5 +118,5 @@ def test_training_converge_with_drop():
precision
)
_set_drop_flag
(
False
)
set_option
(
"enable_drop"
,
0
)
set_option
(
"buffer_length"
,
old_buffer_length
)
imperative/python/test/unit/core/test_interpreter.py
浏览文件 @
de8ffe0c
...
...
@@ -6,23 +6,19 @@ import pytest
import
megengine
as
mge
import
megengine.functional
as
F
from
megengine.core._imperative_rt.core2
import
(
AsyncError
,
_set_drop_flag
,
config_async_level
,
get_async_level
,
)
from
megengine.core
import
set_option
from
megengine.core._imperative_rt.core2
import
AsyncError
def
test_basic
():
config_async_level
(
2
)
assert
get_async_level
()
==
2
with
pytest
.
raises
(
Runtime
Error
):
config_async_level
(
3
)
mge
.
config
.
async_level
=
2
assert
mge
.
config
.
async_level
==
2
with
pytest
.
raises
(
Assertion
Error
):
mge
.
config
.
async_level
=
3
def
test_level1_infer_value
():
config_async_level
(
1
)
mge
.
config
.
async_level
=
1
a
=
mge
.
tensor
([[
1
,
2
],
[
2
,
3
],
[
3
,
4
]],
dtype
=
"float32"
)
b
=
mge
.
tensor
([
1
,
1
],
dtype
=
"float32"
)
identity
=
mge
.
tensor
(
np
.
array
([[
1
,
0
],
[
0
,
1
]]),
dtype
=
"float32"
)
...
...
@@ -30,11 +26,11 @@ def test_level1_infer_value():
c
=
F
.
matmul
(
b
,
identity
)
with
pytest
.
raises
(
RuntimeError
):
d
=
F
.
reshape
(
a
,
c
)
config_async_level
(
2
)
mge
.
config
.
async_level
=
2
def
test_level1_infer_shape_with_unknown
():
config_async_level
(
2
)
mge
.
config
.
async_level
=
2
a
=
mge
.
tensor
([[
1
,
2
,
2
,
3
]],
dtype
=
"float32"
)
b
=
mge
.
tensor
([
1
,
1
],
dtype
=
"float32"
)
multi2
=
mge
.
tensor
(
np
.
array
([[
2
,
0
],
[
0
,
2
]]),
dtype
=
"float32"
)
...
...
@@ -42,13 +38,13 @@ def test_level1_infer_shape_with_unknown():
# make DepType::SHAPE unknown
d
=
F
.
reshape
(
a
,
c
)
e
=
mge
.
tensor
([[
1
,
2
]],
dtype
=
"float32"
)
config_async_level
(
1
)
mge
.
config
.
async_level
=
1
# test src no shape, throw in level1
with
pytest
.
raises
(
RuntimeError
):
f
=
F
.
reshape
(
d
,
b
)
with
pytest
.
raises
(
RuntimeError
):
g
=
F
.
matmul
(
d
,
e
)
config_async_level
(
2
)
mge
.
config
.
async_level
=
2
def
test_host_compute_elemwise
():
...
...
@@ -61,7 +57,7 @@ def test_host_compute_elemwise():
def
test_drop_basic
():
_set_drop_flag
(
True
)
set_option
(
"enable_drop"
,
True
)
# test xpu compute
x
=
mge
.
tensor
(
np
.
ones
((
3
,
3
)),
dtype
=
np
.
float32
)
y
=
mge
.
tensor
(
np
.
ones
((
3
,
3
)),
dtype
=
np
.
float32
)
...
...
@@ -74,7 +70,7 @@ def test_drop_basic():
z
=
x
+
y
z
.
_drop
()
z
.
numpy
()
_set_drop_flag
(
False
)
set_option
(
"enable_drop"
,
False
)
def
test_finalize
():
...
...
@@ -107,21 +103,21 @@ def test_async_error_check():
# NOTE: DO NOT REMOVE THIS TEST
# This is also a compatibility test for
# mge.co
re.set_option('async_level', 0)
.
# mge.co
nfig.async_level = 0
.
# If you change the canonical API to set async level,
# update the error message of AsyncError as well.
def
test_async_error
():
orig_lvl
=
mge
.
co
re
.
get_option
(
"async_level"
)
orig_lvl
=
mge
.
co
nfig
.
async_level
try
:
mge
.
co
re
.
set_option
(
"async_level"
,
1
)
mge
.
co
nfig
.
async_level
=
1
x
=
F
.
utils
.
_simulate_error
()
try
:
x
.
numpy
()
except
AsyncError
as
e
:
assert
isinstance
(
e
.
__cause__
,
RuntimeError
)
mge
.
co
re
.
set_option
(
"async_level"
,
0
)
mge
.
co
nfig
.
async_level
=
0
with
pytest
.
raises
(
RuntimeError
):
F
.
utils
.
_simulate_error
()
finally
:
mge
.
co
re
.
set_option
(
"async_level"
,
orig_lvl
)
mge
.
co
nfig
.
async_level
=
orig_lvl
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录