Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
b3889938
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看板
提交
b3889938
编写于
9月 06, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge/examples): add trace & dump example of cifar10 quantization
GitOrigin-RevId: cfc5e3483a66915e92458d1f502f1dde64ffe564
上级
67859f04
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
15 addition
and
7 deletion
+15
-7
imperative/python/megengine/jit/tracing.py
imperative/python/megengine/jit/tracing.py
+11
-3
imperative/python/megengine/quantization/observer.py
imperative/python/megengine/quantization/observer.py
+4
-4
未找到文件。
imperative/python/megengine/jit/tracing.py
浏览文件 @
b3889938
...
@@ -332,6 +332,7 @@ class trace:
...
@@ -332,6 +332,7 @@ class trace:
need_reset_nodes
=
self
.
_need_reset_nodes
=
[]
need_reset_nodes
=
self
.
_need_reset_nodes
=
[]
# links enforce ordering of I/O nodes
# links enforce ordering of I/O nodes
links
=
()
links
=
()
readers
=
[]
if
self
.
_capture_as_const
:
if
self
.
_capture_as_const
:
for
h
in
itertools
.
chain
(
self
.
_arg_bindings
,
self
.
_kwarg_bindings
.
values
()):
for
h
in
itertools
.
chain
(
self
.
_arg_bindings
,
self
.
_kwarg_bindings
.
values
()):
...
@@ -345,7 +346,6 @@ class trace:
...
@@ -345,7 +346,6 @@ class trace:
for
op
,
ihandles
,
ohandles
in
self
.
_seq
:
for
op
,
ihandles
,
ohandles
in
self
.
_seq
:
ivars
=
[]
ivars
=
[]
readers
=
[]
for
h
in
ihandles
:
for
h
in
ihandles
:
info
=
self
.
_tinfo
[
h
]
info
=
self
.
_tinfo
[
h
]
if
not
hasattr
(
info
,
"varnode"
):
if
not
hasattr
(
info
,
"varnode"
):
...
@@ -431,11 +431,19 @@ class trace:
...
@@ -431,11 +431,19 @@ class trace:
if
output_names
and
not
isinstance
(
output_names
,
collections
.
Sequence
):
if
output_names
and
not
isinstance
(
output_names
,
collections
.
Sequence
):
output_names
=
(
output_names
,)
output_names
=
(
output_names
,)
if
output_names
and
len
(
output_names
)
!=
len
(
self
.
_output_bindings
):
if
output_names
and
len
(
output_names
)
!=
len
(
self
.
_output_bindings
):
raise
ValueError
(
"wrong number of output_names"
)
raise
ValueError
(
"wrong number of output_names, should be {} values"
.
format
(
len
(
self
.
_output_bindings
)
)
)
if
arg_names
and
not
isinstance
(
arg_names
,
collections
.
Sequence
):
if
arg_names
and
not
isinstance
(
arg_names
,
collections
.
Sequence
):
arg_names
=
(
arg_names
,)
arg_names
=
(
arg_names
,)
if
arg_names
and
len
(
arg_names
)
!=
len
(
self
.
_arg_bindings
):
if
arg_names
and
len
(
arg_names
)
!=
len
(
self
.
_arg_bindings
):
raise
ValueError
(
"wrong number of arg_names"
)
raise
ValueError
(
"wrong number of arg_names, should be {} values"
.
format
(
len
(
self
.
_arg_bindings
)
)
)
output_names
=
output_names
or
self
.
_output_names
output_names
=
output_names
or
self
.
_output_names
h2v
=
{}
h2v
=
{}
...
...
imperative/python/megengine/quantization/observer.py
浏览文件 @
b3889938
...
@@ -118,8 +118,8 @@ class MinMaxObserver(Observer):
...
@@ -118,8 +118,8 @@ class MinMaxObserver(Observer):
# stop gradient
# stop gradient
x
=
x_orig
.
detach
()
x
=
x_orig
.
detach
()
# find max and min
# find max and min
self
.
min_val
=
F
.
minimum
(
self
.
min_val
,
x
.
min
(
))
self
.
min_val
.
set_value
(
F
.
minimum
(
self
.
min_val
,
x
.
min
()
))
self
.
max_val
=
F
.
maximum
(
self
.
max_val
,
x
.
max
(
))
self
.
max_val
.
set_value
(
F
.
maximum
(
self
.
max_val
,
x
.
max
()
))
return
x_orig
return
x_orig
...
@@ -144,11 +144,11 @@ class ExponentialMovingAverageObserver(MinMaxObserver):
...
@@ -144,11 +144,11 @@ class ExponentialMovingAverageObserver(MinMaxObserver):
# stop gradient
# stop gradient
x
=
x_orig
.
detach
()
x
=
x_orig
.
detach
()
# Exponential Moving Average
# Exponential Moving Average
self
.
min_val
=
(
self
.
min_val
.
set_value
(
self
.
min_val
*
self
.
runtime_momentum
self
.
min_val
*
self
.
runtime_momentum
+
(
1
-
self
.
runtime_momentum
)
*
x
.
min
()
+
(
1
-
self
.
runtime_momentum
)
*
x
.
min
()
)
)
self
.
max_val
=
(
self
.
max_val
.
set_value
(
self
.
max_val
*
self
.
runtime_momentum
self
.
max_val
*
self
.
runtime_momentum
+
(
1
-
self
.
runtime_momentum
)
*
x
.
max
()
+
(
1
-
self
.
runtime_momentum
)
*
x
.
max
()
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录