Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
ef8cdbd8
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef8cdbd8
编写于
6月 29, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2639 [ad] improve the performance of ad
Merge pull request !2639 from Kang/master
上级
3e995340
e6060685
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
32 deletion
+32
-32
mindspore/ccsrc/optimizer/ad/dfunctor.cc
mindspore/ccsrc/optimizer/ad/dfunctor.cc
+0
-1
mindspore/ccsrc/optimizer/ad/dfunctor.h
mindspore/ccsrc/optimizer/ad/dfunctor.h
+4
-4
mindspore/ccsrc/optimizer/ad/kprim.cc
mindspore/ccsrc/optimizer/ad/kprim.cc
+24
-26
tests/ut/cpp/operator/grad_implementations_test.cc
tests/ut/cpp/operator/grad_implementations_test.cc
+4
-1
未找到文件。
mindspore/ccsrc/optimizer/ad/dfunctor.cc
浏览文件 @
ef8cdbd8
...
...
@@ -424,7 +424,6 @@ AnfNodePtr DFunctor::MapToK(const AnfNodePtr &primal) {
}
auto
k_prim
=
g_k_prims
.
KPrimitive
(
value_node
,
resources_
);
if
(
k_prim
!=
nullptr
)
{
k_prim
=
BasicClone
(
k_prim
);
return
NewValueNode
(
k_prim
);
}
// When failed to find k_prim, try k_meta.
...
...
mindspore/ccsrc/optimizer/ad/dfunctor.h
浏览文件 @
ef8cdbd8
...
...
@@ -47,12 +47,12 @@ struct PrimitiveTotalEqual {
return
false
;
}
for
(
auto
&
attr
:
attrs1
)
{
if
(
!
t2
->
HasAttr
(
attr
.
first
))
{
for
(
auto
&
attr
1
:
attrs1
)
{
if
(
!
t2
->
HasAttr
(
attr
1
.
first
))
{
return
false
;
}
if
(
!
(
*
(
attr
.
second
)
==
*
(
t2
->
GetAttr
(
attr
.
first
))))
{
if
(
!
(
*
(
attr
1
.
second
)
==
*
(
t2
->
GetAttr
(
attr1
.
first
))))
{
return
false
;
}
}
...
...
@@ -61,7 +61,7 @@ struct PrimitiveTotalEqual {
}
};
using
Registry
=
std
::
unordered_map
<
PrimitivePtr
,
FuncGraphPtr
,
PrimitiveHasher
>
;
using
Registry
=
std
::
unordered_map
<
PrimitivePtr
,
FuncGraphPtr
,
PrimitiveHasher
,
PrimitiveTotalEqual
>
;
class
KPrim
;
extern
KPrim
g_k_prims
;
class
DFunctor
;
...
...
mindspore/ccsrc/optimizer/ad/kprim.cc
浏览文件 @
ef8cdbd8
...
...
@@ -96,34 +96,37 @@ FuncGraphPtr KPrim::KPrimitive(const ValueNodePtr &value_node, const pipeline::R
MS_LOG
(
EXCEPTION
)
<<
"Primitive node is not valid."
;
}
auto
prim
=
value_node
->
value
()
->
cast
<
PrimitivePtr
>
();
MS_EXCEPTION_IF_NULL
(
prim
);
auto
iter
=
bprop_registry_
.
find
(
prim
);
if
(
iter
!=
bprop_registry_
.
end
())
{
return
iter
->
second
;
}
if
(
prim
->
Hash
()
==
prim
::
kPrimSwitchLayer
->
Hash
()
&&
prim
->
name
()
==
"switch_layer"
)
{
auto
prim
=
GetValueNode
<
PrimitivePtr
>
(
value_node
);
if
(
prim
->
Hash
()
==
prim
::
kPrimSwitchLayer
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimSwitchLayer
->
name
())
{
auto
fprop
=
GetFprop
(
prim
);
fprop
->
transforms
().
emplace
(
"primal"
,
FuncGraphTransform
(
prim
::
kPrimSwitchLayer
));
bprop_registry_
[
prim
::
kPrimSwitchLayer
]
=
fprop
;
return
fprop
;
}
if
(
prim
->
Hash
()
==
prim
::
kPrimMakeTuple
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimMakeTuple
->
name
())
{
}
else
if
(
prim
->
Hash
()
==
prim
::
kPrimMakeTuple
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimMakeTuple
->
name
())
{
return
nullptr
;
}
bool
is_faked_bprop
=
false
;
FuncGraphPtr
bprop_fg
=
nullptr
;
if
(
prim
->
Hash
()
==
prim
::
kPrimHookBackward
->
Hash
()
&&
prim
->
name
()
==
"HookBackward"
)
{
bprop_fg
=
BpropCut
(
value_node
,
resources
);
}
else
{
bprop_fg
=
GetBprop
(
prim
);
if
(
bprop_fg
==
nullptr
)
{
bprop_fg
=
FakeBprop
(
value_node
,
resources
);
is_faked_bprop
=
true
;
auto
iter
=
bprop_registry_
.
find
(
prim
);
if
(
iter
!=
bprop_registry_
.
end
())
{
bprop_fg
=
iter
->
second
;
}
if
(
bprop_fg
==
nullptr
)
{
bool
is_faked_bprop
=
false
;
if
(
prim
->
Hash
()
==
prim
::
kPrimHookBackward
->
Hash
()
&&
prim
->
name
()
==
prim
::
kPrimHookBackward
->
name
())
{
bprop_fg
=
BpropCut
(
value_node
,
resources
);
}
else
{
bprop_fg
=
GetBprop
(
prim
);
if
(
bprop_fg
==
nullptr
)
{
bprop_fg
=
FakeBprop
(
value_node
,
resources
);
is_faked_bprop
=
true
;
}
}
// To support primitives with variable params, do not cache faked bprop
if
(
!
is_faked_bprop
)
{
// Set bprop_g graph cache
bprop_registry_
[
prim
]
=
bprop_fg
;
}
}
...
...
@@ -134,11 +137,6 @@ FuncGraphPtr KPrim::KPrimitive(const ValueNodePtr &value_node, const pipeline::R
<<
trace
::
GetDebugInfo
(
bprop_fg
->
debug_info
());
}
// To support primitives with variable params, do not cache faked bprop
if
(
!
is_faked_bprop
)
{
// Set bprop_g graph cache
bprop_registry_
[
prim
]
=
expanded_fg
;
}
return
expanded_fg
;
}
...
...
tests/ut/cpp/operator/grad_implementations_test.cc
浏览文件 @
ef8cdbd8
...
...
@@ -38,7 +38,10 @@ TEST_F(TestGradImplementations, TestGetAugmentedGraph) {
draw
::
Draw
(
"gradImpl_TestGetAugmentedFuncGraph.dot"
,
fg
);
auto
fg1
=
ad
::
g_k_prims
.
KPrimitive
(
NewValueNode
(
kPrimScalarMul
),
nullptr
);
ASSERT_TRUE
(
fg
==
fg1
);
FuncGraphPairMapEquiv
equiv_graph
;
NodeMapEquiv
equiv_node
;
ASSERT_TRUE
(
Isomorphic
(
fg
,
fg1
,
&
equiv_graph
,
&
equiv_node
));
}
}
// namespace prim
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录