Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
cc9c004b
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cc9c004b
编写于
5月 30, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 30, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1696 Enable ConfusionMulGrad fusion pass
Merge pull request !1696 from huanghui/TMP
上级
bbc64b88
71acaa53
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
15 deletion
+26
-15
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
.../ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
+1
-0
mindspore/ccsrc/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion.cc
...re_activate/ascend/ir_fusion/confusion_mul_grad_fusion.cc
+13
-7
mindspore/ccsrc/pre_activate/ascend/ir_fusion/mul_add_fusion.cc
...ore/ccsrc/pre_activate/ascend/ir_fusion/mul_add_fusion.cc
+3
-2
tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc
...tivate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc
+1
-2
tests/ut/cpp/python_input/gtest_input/pre_activate/confusion_mul_grad_fusion.py
...put/gtest_input/pre_activate/confusion_mul_grad_fusion.py
+8
-4
未找到文件。
mindspore/ccsrc/pre_activate/ascend/ascend_backend_optimization.cc
浏览文件 @
cc9c004b
...
...
@@ -100,6 +100,7 @@ void AddAscendBackendOptionalIRFusion(PassManager *ir_fusion_pm) {
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
ClipByNormNoDivSquareSumFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LambUpdateWithLRRuleFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
SoftmaxGradExtFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConfusionMulGradFusion
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
ConfusionSoftmaxGradRule
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LambNextMVWithDecayRuleCond1
>
());
ir_fusion_pm
->
AddPass
(
std
::
make_shared
<
LambNextMVWithDecayRuleCond2
>
());
...
...
mindspore/ccsrc/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion.cc
浏览文件 @
cc9c004b
...
...
@@ -74,10 +74,21 @@ AnfNodePtr GetMul0(const FuncGraphPtr &graph, const AnfNodePtr &input2, const An
}
bool
QuitFusion
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
mul0_anf
,
const
AnfNodePtr
&
mul1_anf
,
const
AnfNodePtr
&
reduce_sum
)
{
const
AnfNodePtr
&
reduce_sum
,
const
AnfNodePtr
&
input2
)
{
MS_EXCEPTION_IF_NULL
(
mul0_anf
);
MS_EXCEPTION_IF_NULL
(
mul1_anf
);
MS_EXCEPTION_IF_NULL
(
reduce_sum
);
MS_EXCEPTION_IF_NULL
(
input2
);
auto
addn
=
input2
->
cast
<
CNodePtr
>
();
if
(
addn
==
nullptr
||
AnfAlgo
::
GetCNodeName
(
addn
)
!=
prim
::
kPrimAddN
->
name
())
{
MS_LOG
(
INFO
)
<<
"mul's second input is not addn"
;
return
true
;
}
std
::
vector
<
size_t
>
shape
=
AnfAlgo
::
GetOutputInferShape
(
addn
,
0
);
if
(
shape
.
size
()
!=
2
||
!
(
shape
[
1
]
==
1024
||
shape
[
1
]
==
768
))
{
MS_LOG
(
INFO
)
<<
"Addn's infer shape is not equal [x,1024] or [x,768]"
;
return
true
;
}
if
(
!
mul0_anf
->
isa
<
CNode
>
()
||
!
mul1_anf
->
isa
<
CNode
>
())
{
return
true
;
}
...
...
@@ -86,11 +97,6 @@ bool QuitFusion(const FuncGraphPtr &graph, const AnfNodePtr &mul0_anf, const Anf
auto
mul0
=
mul0_anf
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
mul0
);
// when network is _VirtualDatasetCell, quit fusion
if
(
mul0
->
fullname_with_scope
().
find
(
"network-_VirtualDatasetCell"
)
!=
std
::
string
::
npos
)
{
return
true
;
}
if
(
IsDepend
(
graph
,
mul0
->
input
(
1
),
reduce_sum
))
{
MS_LOG
(
INFO
)
<<
"mul0->input(1) depends on reduce_sum, quit fusion"
;
return
true
;
...
...
@@ -128,7 +134,7 @@ const AnfNodePtr ConfusionMulGradFusion::Process(const FuncGraphPtr &graph, cons
MS_LOG
(
INFO
)
<<
"Mul0 do not exist, quit fusion"
;
return
nullptr
;
}
if
(
QuitFusion
(
graph
,
mul0
,
mul1
,
node
))
{
if
(
QuitFusion
(
graph
,
mul0
,
mul1
,
node
,
input2
))
{
return
nullptr
;
}
...
...
mindspore/ccsrc/pre_activate/ascend/ir_fusion/mul_add_fusion.cc
浏览文件 @
cc9c004b
...
...
@@ -84,8 +84,9 @@ const AnfNodePtr MulAddFusion::Process(const FuncGraphPtr &graph, const AnfNodeP
inputs
.
push_back
(
mul
->
input
(
index
));
}
auto
another_input_node
=
add
->
input
(
add
->
size
()
-
mul_index
);
if
(
IsUsedByOthers
(
graph
,
another_input_node
))
{
MS_LOG
(
INFO
)
<<
"Add's another input node is used by others, do not fuse"
;
if
(
another_input_node
->
isa
<
CNode
>
()
&&
AnfAlgo
::
GetCNodeName
(
another_input_node
)
==
prim
::
kPrimTupleGetItem
->
name
())
{
MS_LOG
(
INFO
)
<<
"Add's another input node has multiple outputs, do not fuse"
;
return
nullptr
;
}
inputs
.
push_back
(
another_input_node
);
...
...
tests/ut/cpp/pre_activate/ascend/ir_fusion/confusion_mul_grad_fusion_test.cc
浏览文件 @
cc9c004b
...
...
@@ -32,7 +32,7 @@ class TestHWOptimizeConfusionMulGradFusion : public BackendCommon {
TEST_F
(
TestHWOptimizeConfusionMulGradFusion
,
test_fusion
)
{
FuncGraphPtr
g
=
get_py_fun_
.
CallAndParseRet
(
"test_confusion_mul_grad_fusion"
,
"before"
);
EXPECT_NE
(
g
,
nullptr
);
std
::
vector
<
int
>
shp
{
1
,
1
,
1
,
1
};
std
::
vector
<
int
>
shp
{
1
0
,
1024
};
auto
x_abstract
=
std
::
make_shared
<
abstract
::
AbstractTensor
>
(
kFloat32
,
shp
);
AbstractBasePtrList
args_spec_list
;
for
(
size_t
i
=
0
;
i
<
3
;
++
i
)
{
...
...
@@ -49,6 +49,5 @@ TEST_F(TestHWOptimizeConfusionMulGradFusion, test_fusion) {
FuncGraphPtr
g_after
=
get_py_fun_
.
CallAndParseRet
(
"test_confusion_mul_grad_fusion"
,
"after"
);
EXPECT_TRUE
(
CheckEqualGraph
(
g_after
,
new_graph
));
}
}
// namespace opt
}
// namespace mindspore
tests/ut/cpp/python_input/gtest_input/pre_activate/confusion_mul_grad_fusion.py
浏览文件 @
cc9c004b
...
...
@@ -15,12 +15,13 @@
from
mindspore.ops
import
Primitive
from
mindspore.ops
import
operations
as
P
addn
=
P
.
AddN
()
mul
=
P
.
Mul
()
reduce_sum
=
P
.
ReduceSum
()
confusion_mul_grad
=
Primitive
(
'ConfusionMulGrad'
)
make_tuple
=
Primitive
(
'make_tuple'
)
tuple_getitem
=
Primitive
(
'tuple_getitem'
)
axis
=
2
axis
=
1
class
FnDict
:
...
...
@@ -39,8 +40,10 @@ def test_confusion_mul_grad_fusion(tag):
@
fns
def
before
(
input1
,
input2
,
input3
):
output1
=
mul
(
input1
,
input2
)
mul1
=
mul
(
input3
,
input2
)
addn0
=
addn
((
input2
,
input2
))
output1
=
mul
(
input1
,
addn0
)
mul1
=
mul
(
input3
,
addn0
)
# input axis will be convert to attr in step ConstructKernelGraph
output2
=
reduce_sum
(
mul1
,
axis
)
res
=
make_tuple
(
output1
,
output2
)
...
...
@@ -48,7 +51,8 @@ def test_confusion_mul_grad_fusion(tag):
@
fns
def
after
(
input1
,
input2
,
input3
):
res
=
confusion_mul_grad
(
input1
,
input2
,
input3
)
addn0
=
addn
(
input2
,
input2
)
res
=
confusion_mul_grad
(
input1
,
addn0
,
input3
)
item0
=
tuple_getitem
(
res
,
0
)
item1
=
tuple_getitem
(
res
,
1
)
res
=
make_tuple
(
item0
,
item1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录