Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
205a39b0
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
411
Star
4707
Fork
583
代码
文件
提交
分支
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看板
提交
205a39b0
编写于
10月 09, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mge): remove add_update
GitOrigin-RevId: 3068593eebb6f83884602651b21c94d623e78079
上级
67d33303
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
7 addition
and
92 deletion
+7
-92
imperative/python/megengine/core/tensor/tensor_wrapper.py
imperative/python/megengine/core/tensor/tensor_wrapper.py
+1
-1
imperative/python/megengine/functional/__init__.py
imperative/python/megengine/functional/__init__.py
+0
-1
imperative/python/megengine/functional/graph.py
imperative/python/megengine/functional/graph.py
+0
-41
imperative/python/megengine/module/qat/conv_bn.py
imperative/python/megengine/module/qat/conv_bn.py
+5
-13
imperative/python/megengine/quantization/fake_quant.py
imperative/python/megengine/quantization/fake_quant.py
+1
-1
imperative/python/test/unit/functional/test_functional.py
imperative/python/test/unit/functional/test_functional.py
+0
-35
未找到文件。
imperative/python/megengine/core/tensor/tensor_wrapper.py
浏览文件 @
205a39b0
imperative/python/megengine/functional/__init__.py
浏览文件 @
205a39b0
...
...
@@ -8,7 +8,6 @@
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# pylint: disable=redefined-builtin
from
.elemwise
import
*
from
.graph
import
add_update
from
.loss
import
*
from
.math
import
*
from
.nn
import
*
...
...
imperative/python/megengine/functional/graph.py
已删除
100644 → 0
浏览文件 @
67d33303
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
collections
from
typing
import
Iterable
,
Optional
,
Union
from
..tensor
import
Tensor
def
add_update
(
dest
:
Tensor
,
delta
:
Tensor
,
*
,
alpha
:
Union
[
Tensor
,
float
,
int
]
=
1.0
,
beta
:
Union
[
Tensor
,
float
,
int
]
=
1.0
,
bias
:
Union
[
Tensor
,
float
,
int
]
=
0.0
):
r
"""Modify ``dest`` inplace as follows:
.. math::
dest = alpha * dest + beta * delta + bias
:param dest: input data that will be inplace modified.
:param delta: update value that will be added to ``dest``.
:param alpha: weight ratio of ``dest``. Default: 1.0
:param beta: weight ratio of ``delta``. Default: 1.0
:param bias: bias value appended to the result. Default: 0.0
"""
if
beta
is
not
None
and
beta
!=
1.0
:
delta
=
delta
*
beta
if
bias
is
not
None
and
bias
!=
0.0
:
delta
=
delta
+
bias
if
alpha
is
not
None
and
alpha
!=
1.0
:
dest
*=
alpha
dest
+=
delta
return
dest
imperative/python/megengine/module/qat/conv_bn.py
浏览文件 @
205a39b0
...
...
@@ -5,7 +5,7 @@
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
from
...functional
import
add_update
,
ones
,
relu
,
sqrt
,
sum
,
zeros
from
...functional
import
ones
,
relu
,
sqrt
,
sum
,
zeros
from
...quantization.utils
import
fake_quant_bias
from
..
import
conv_bn
as
Float
from
.module
import
QATModule
...
...
@@ -76,18 +76,10 @@ class _ConvBnActivation2d(Float._ConvBnActivation2d, QATModule):
bn_var
.
detach
()
*
num_elements_per_channel
/
(
num_elements_per_channel
-
1
)
)
exponential_average_factor
=
1
-
self
.
bn
.
momentum
add_update
(
self
.
bn
.
running_mean
,
delta
=
bn_mean
,
alpha
=
1
-
exponential_average_factor
,
beta
=
exponential_average_factor
,
)
add_update
(
self
.
bn
.
running_var
,
delta
=
bn_var
,
alpha
=
1
-
exponential_average_factor
,
beta
=
exponential_average_factor
,
)
self
.
bn
.
running_mean
*=
self
.
bn
.
momentum
self
.
bn
.
running_mean
+=
exponential_average_factor
*
bn_mean
self
.
bn
.
running_var
*=
self
.
bn
.
momentum
self
.
bn
.
running_var
+=
exponential_average_factor
*
bn_var
def
calc_conv_bn_qat
(
self
,
inp
,
approx
=
True
):
if
self
.
training
and
not
approx
:
...
...
imperative/python/megengine/quantization/fake_quant.py
浏览文件 @
205a39b0
...
...
@@ -127,7 +127,7 @@ class TQT(_FakeQuantize):
# when disable, TQT will do normal forward, initialize scale weight
tmp_scale
=
F
.
maximum
(
F
.
abs
(
q_dict
[
"min_val"
]),
F
.
abs
(
q_dict
[
"max_val"
]))
tmp_scale
=
F
.
log
(
tmp_scale
/
127
)
/
math
.
log
(
2
)
F
.
add_update
(
self
.
scale
,
tmp_scale
,
alpha
=
0.0
,
beta
=
1.0
,
bias
=
0.0
)
self
.
scale
[...]
=
tmp_scale
return
inp
def
get_qparams
(
self
):
...
...
imperative/python/test/unit/functional/test_functional.py
浏览文件 @
205a39b0
...
...
@@ -290,41 +290,6 @@ def test_one_hot():
onehot_high_dimension
()
def
test_add_update
():
shape
=
(
2
,
3
)
v
=
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
b
=
Tensor
(
v
)
u
=
F
.
add_update
(
b
,
1
)
np
.
testing
.
assert_allclose
(
u
.
numpy
(),
v
+
1
,
atol
=
1e-6
)
u
=
F
.
add_update
(
b
,
1
)
np
.
testing
.
assert_allclose
(
u
.
numpy
(),
v
+
2
,
atol
=
1e-6
)
x
=
np
.
ones
((
2
,
2
),
dtype
=
np
.
float32
)
y
=
x
*
0.5
dest
=
tensor
(
x
)
delta
=
tensor
(
y
)
r
=
F
.
add_update
(
dest
,
delta
,
alpha
=
0.9
,
beta
=
0.1
,
bias
=
0.1
)
np
.
testing
.
assert_allclose
(
r
.
numpy
(),
x
*
0.9
+
y
*
0.1
+
0.1
,
atol
=
1e-6
)
def
test_add_update_params
():
b
=
np
.
random
.
random
((
2
,
3
)).
astype
(
np
.
float32
)
y
=
Tensor
(
b
)
# @jit.trace
def
f
(
x
):
return
F
.
add_update
(
y
,
x
)
f
(
np
.
zeros
((
2
,
3
)).
astype
(
np
.
float32
))
z
=
Tensor
(
np
.
zeros
((
2
,
3
)).
astype
(
np
.
float32
))
F
.
add_update
(
y
,
z
,
beta
=
0.1
)
res
=
f
(
np
.
ones
((
2
,
3
)).
astype
(
np
.
float32
))
np
.
testing
.
assert_allclose
(
res
.
numpy
(),
b
+
1
)
def
test_binary_cross_entropy
():
data1_shape
=
(
2
,
2
)
label1_shape
=
(
2
,
2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录