Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
7bd848ce
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看板
提交
7bd848ce
编写于
12月 29, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(subgraph): fix hand-written backward for serval jit-elemwise ops
GitOrigin-RevId: ea3a40d96efb6dd083fa4278c041837aff3833d0
上级
7be7656c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
13 deletion
+37
-13
imperative/python/megengine/functional/nn.py
imperative/python/megengine/functional/nn.py
+15
-13
imperative/src/impl/ops/utility.cpp
imperative/src/impl/ops/utility.cpp
+22
-0
未找到文件。
imperative/python/megengine/functional/nn.py
浏览文件 @
7bd848ce
...
...
@@ -909,9 +909,9 @@ def _get_prelu_op(dtype=None, device=None):
min_0
=
f
(
"min"
,
inp
,
c
(
0
))
oup
=
f
(
"fma3"
,
min_0
,
weight
,
max_0
)
(
oup_grad
,)
=
yield
(
oup
,)
inp_grad_0
=
f
(
"cond_leq_mov"
,
inp
,
c
(
0
)
,
oup_grad
)
inp_grad_0
=
f
(
"cond_leq_mov"
,
c
(
0
),
inp
,
oup_grad
)
inp_grad_1
=
f
(
"*"
,
oup_grad
,
weight
)
inp_grad_1
=
f
(
"cond_leq_mov"
,
c
(
0
),
inp
,
inp_grad_1
)
inp_grad_1
=
f
(
"cond_leq_mov"
,
inp
,
c
(
0
)
,
inp_grad_1
)
inp_grad
=
f
(
"+"
,
inp_grad_0
,
inp_grad_1
)
weight_grad
=
f
(
"*"
,
oup_grad
,
min_0
)
yield
(
inp_grad
,
weight_grad
)
...
...
@@ -925,7 +925,7 @@ def prelu(inp: Tensor, weight: Tensor) -> Tensor:
Refer to :class:`~.PReLU` for more information.
"""
prelu
=
_get_prelu_op
(
dtype
=
inp
.
dtype
,
device
=
inp
.
device
)
(
oup
,)
=
prelu
(
inp
,
weight
)
(
oup
,)
=
prelu
(
inp
,
broadcast_to
(
weight
,
inp
.
shape
)
)
return
oup
...
...
@@ -947,7 +947,7 @@ def _get_leagk_relu_op(negative_slope, *, dtype=None, device=None):
(
oup_grad
,)
=
yield
(
oup
,)
inp_grad_0
=
f
(
"cond_leq_mov"
,
c
(
0
),
inp
,
oup_grad
)
inp_grad_1
=
f
(
"*"
,
oup_grad
,
c
(
negative_slope
))
inp_grad_1
=
f
(
"cond_leq_mov"
,
inp
,
c
(
negative_slope
),
inp_grad_1
)
inp_grad_1
=
f
(
"cond_leq_mov"
,
inp
,
c
(
0
),
inp_grad_1
)
inp_grad
=
f
(
"+"
,
inp_grad_0
,
inp_grad_1
)
yield
(
inp_grad
,)
...
...
@@ -994,13 +994,14 @@ def _get_softplus_op(dtype=None, device=None):
(
inp
,)
=
inputs
[
0
:
1
]
neg_abs
=
f
(
"-"
,
f
(
"abs"
,
inp
))
exp
=
f
(
"exp"
,
neg_abs
)
oup
=
f
(
"log1p"
,
exp
)
oup
=
f
(
"+"
,
oup
,
f
(
"relu"
,
inp
))
oup0
=
f
(
"log1p"
,
exp
)
oup1
=
f
(
"relu"
,
inp
)
oup
=
f
(
"+"
,
oup0
,
oup1
)
(
oup_grad
,)
=
yield
(
oup
,)
inp_grad_0
=
f
(
"switch_gt0"
,
inp
,
oup_grad
)
inp_grad_0
=
f
(
"switch_gt0"
,
oup1
,
oup_grad
)
inp_grad_1
=
oup_grad
inp_grad_1
=
f
(
"/"
,
oup_grad
,
f
(
"+"
,
exp
,
c
(
1
)))
inp_grad_1
=
f
(
"*"
,
oup_grad
,
exp
)
inp_grad_1
=
f
(
"*"
,
inp_grad_1
,
exp
)
inp_grad_1
=
f
(
"-"
,
inp_grad_1
)
inp_grad_1
=
f
(
"abs_grad"
,
inp
,
inp_grad_1
)
inp_grad
=
f
(
"+"
,
inp_grad_0
,
inp_grad_1
)
...
...
@@ -1098,16 +1099,17 @@ def _get_logsigmoid_op(dtype=None, device=None):
(
inp
,)
=
inputs
[
0
:
1
]
neg_abs
=
f
(
"-"
,
f
(
"abs"
,
inp
))
exp
=
f
(
"exp"
,
neg_abs
)
oup
=
f
(
"log1p"
,
exp
)
oup
=
f
(
"+"
,
oup
,
f
(
"relu"
,
f
(
"-"
,
inp
)))
oup0
=
f
(
"log1p"
,
exp
)
oup1
=
f
(
"relu"
,
f
(
"-"
,
inp
))
oup
=
f
(
"+"
,
oup0
,
oup1
)
oup
=
f
(
"-"
,
oup
)
(
oup_grad
,)
=
yield
(
oup
,)
oup_grad
=
f
(
"-"
,
oup_grad
)
inp_grad_0
=
f
(
"switch_gt0"
,
inp
,
oup_grad
)
inp_grad_0
=
f
(
"switch_gt0"
,
oup1
,
oup_grad
)
inp_grad_0
=
f
(
"-"
,
inp_grad_0
)
inp_grad_1
=
oup_grad
inp_grad_1
=
f
(
"/"
,
oup_grad
,
f
(
"+"
,
exp
,
c
(
1
)))
inp_grad_1
=
f
(
"*"
,
oup_grad
,
exp
)
inp_grad_1
=
f
(
"/"
,
inp_grad_1
,
f
(
"+"
,
exp
,
c
(
1
)))
inp_grad_1
=
f
(
"*"
,
inp_grad_1
,
exp
)
inp_grad_1
=
f
(
"-"
,
inp_grad_1
)
inp_grad_1
=
f
(
"abs_grad"
,
inp
,
inp_grad_1
)
inp_grad
=
f
(
"+"
,
inp_grad_0
,
inp_grad_1
)
...
...
imperative/src/impl/ops/utility.cpp
浏览文件 @
7bd848ce
...
...
@@ -726,6 +726,28 @@ auto apply_on_var_node(const OpDef& def, const VarNodeArray& inputs) {
auto
infer_output_attrs_fallible
(
const
OpDef
&
def
,
const
SmallVector
<
LogicalTensorDesc
>&
input_descs
)
{
TensorShape
shape
;
DType
dtype
=
input_descs
[
0
].
layout
.
dtype
;
CompNode
comp_node
=
input_descs
[
0
].
comp_node
;
for
(
auto
&&
desc
:
input_descs
)
{
if
(
desc
.
layout
.
ndim
)
{
shape
=
desc
.
layout
;
break
;
}
}
for
(
size_t
i
=
0
;
i
<
input_descs
.
size
();
++
i
)
{
if
(
input_descs
[
i
].
layout
.
ndim
)
{
mgb_assert
(
input_descs
[
i
].
layout
.
eq_shape
(
shape
),
"inputs of JITFusionOp should have same shapes"
);
}
mgb_assert
(
input_descs
[
i
].
layout
.
dtype
==
dtype
,
"inputs of JITFusionOp should have same dtypes"
);
mgb_assert
(
input_descs
[
i
].
comp_node
==
comp_node
,
"inputs of JITFusionOp should have same devices"
);
}
return
OpDef
::
infer_output_attrs_fallible
(
*
def
.
cast_final_safe
<
JITFusionOp
>
().
op
,
input_descs
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录