Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
1b568517
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
395
Star
4704
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1b568517
编写于
10月 30, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/trace): fix graph option in trace
GitOrigin-RevId: 7bec84f56d61cea4ad50f66224ffa11255458d0b
上级
f2f5f9ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
20 deletion
+32
-20
imperative/python/megengine/jit/tracing.py
imperative/python/megengine/jit/tracing.py
+3
-1
imperative/python/test/unit/test_tracing.py
imperative/python/test/unit/test_tracing.py
+29
-19
未找到文件。
imperative/python/megengine/jit/tracing.py
浏览文件 @
1b568517
...
...
@@ -284,6 +284,7 @@ class trace:
apply
.
enable
(
apply_symbolic_mode
)
apply
.
enable
(
apply_const_symbolic_mode
)
self
.
_lazy_eval_graph
=
G
.
Graph
()
self
.
_apply_graph_options
(
self
.
_lazy_eval_graph
)
def
_take_escaped_tensors
(
self
):
escaped_tensors
=
tuple
(
self
.
_active_tensors
)
...
...
@@ -302,7 +303,6 @@ class trace:
readers
.
append
(
reader
)
active_lazy_eval_tensors
.
append
(
x
)
visited
.
add
(
x
)
self
.
_apply_graph_options
(
lazy_eval_graph
)
lazy_eval_graph
.
compile
(
*
readers
)
lazy_eval_graph
()
for
r
,
x
in
zip
(
readers
,
active_lazy_eval_tensors
):
...
...
@@ -599,6 +599,8 @@ class trace:
h2v
=
{}
graph
=
G
.
Graph
()
# only graph_opt_level takes effect in dump
self
.
_apply_graph_options
(
graph
)
for
i
,
h
in
enumerate
(
self
.
_arg_bindings
):
info
=
self
.
_tinfo
[
h
]
...
...
imperative/python/test/unit/test_tracing.py
浏览文件 @
1b568517
...
...
@@ -174,31 +174,24 @@ def test_trace_profiler():
assert
out
.
get
(
"profiler"
)
@
pytest
.
mark
.
skip
(
reason
=
"could not disable opt_level"
)
def
test_goptions_log_exp
():
def
test_goptions
():
@
trace
(
symbolic
=
True
,
opt_level
=
0
,
capture_as_const
=
True
)
def
f
(
x
):
return
log
(
exp
(
x
))
# directly return x / x will not trigger gopt
# since there's no way to tell the two x are the same
y
=
2.0
*
x
return
y
/
y
@
trace
(
symbolic
=
True
,
opt_level
=
1
,
capture_as_const
=
True
)
def
g
(
x
):
return
log
(
exp
(
x
))
f
(
tensor
(
1.0
))
_
,
out
=
mkstemp
()
f
.
dump
(
out
,
optimize_for_inference
=
False
)
*
_
,
outputs
=
G
.
load_graph
(
out
)
oprs_1
=
cgtools
.
get_oprs_seq
(
outputs
)
g
(
tensor
(
1.0
))
g
.
dump
(
out
,
optimize_for_inference
=
False
)
*
_
,
outputs
=
G
.
load_graph
(
out
)
oprs_2
=
cgtools
.
get_oprs_seq
(
outputs
)
y
=
2.0
*
x
return
y
/
y
assert
len
(
oprs_1
)
-
len
(
oprs_2
)
==
2
d
=
tensor
(
0.0
)
assert
not
np
.
isfinite
(
f
(
d
).
numpy
())
np
.
testing
.
assert_equal
(
g
(
d
).
numpy
().
item
(),
1.0
)
@
pytest
.
mark
.
skip
(
reason
=
"could not disable opt_level"
)
def
test_goptions_log_sum_exp
():
@
trace
(
symbolic
=
True
,
opt_level
=
0
,
capture_as_const
=
True
)
def
f
(
x
,
y
):
...
...
@@ -208,13 +201,30 @@ def test_goptions_log_sum_exp():
def
g
(
x
,
y
):
return
log
(
exp
(
x
)
+
exp
(
y
))
f
(
tensor
(
1.0
),
tensor
(
2.0
))
val
=
1.0e4
d
=
tensor
(
val
)
o
=
tensor
(
0.0
)
assert
not
np
.
isfinite
(
f
(
d
,
o
).
numpy
())
np
.
testing
.
assert_almost_equal
(
g
(
d
,
o
),
val
)
@
pytest
.
mark
.
skip
(
reason
=
"could not use opt_level=0 with dump"
)
def
test_goptions_log_exp
():
@
trace
(
symbolic
=
True
,
opt_level
=
0
,
capture_as_const
=
True
)
def
f
(
x
):
return
log
(
exp
(
x
))
@
trace
(
symbolic
=
True
,
opt_level
=
1
,
capture_as_const
=
True
)
def
g
(
x
):
return
log
(
exp
(
x
))
f
(
tensor
(
1.0
))
_
,
out
=
mkstemp
()
f
.
dump
(
out
,
optimize_for_inference
=
False
)
*
_
,
outputs
=
G
.
load_graph
(
out
)
oprs_1
=
cgtools
.
get_oprs_seq
(
outputs
)
g
(
tensor
(
1.0
)
,
tensor
(
2.0
)
)
g
(
tensor
(
1.0
))
g
.
dump
(
out
,
optimize_for_inference
=
False
)
*
_
,
outputs
=
G
.
load_graph
(
out
)
oprs_2
=
cgtools
.
get_oprs_seq
(
outputs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录