Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
0ac59119
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看板
提交
0ac59119
编写于
6月 11, 2020
作者:
W
WilliamLian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove the useless transdata and cast connected with control depend
上级
eaaacfea
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
96 addition
and
44 deletion
+96
-44
mindspore/ccsrc/pipeline/validator.cc
mindspore/ccsrc/pipeline/validator.cc
+2
-2
mindspore/ccsrc/pre_activate/ascend/format_type/merge_cast_to_op.cc
...ccsrc/pre_activate/ascend/format_type/merge_cast_to_op.cc
+14
-10
mindspore/ccsrc/pre_activate/common/helper.cc
mindspore/ccsrc/pre_activate/common/helper.cc
+27
-3
mindspore/ccsrc/pre_activate/common/helper.h
mindspore/ccsrc/pre_activate/common/helper.h
+4
-0
mindspore/ccsrc/pre_activate/pass/optimize_dependence.cc
mindspore/ccsrc/pre_activate/pass/optimize_dependence.cc
+45
-25
tests/st/networks/models/bert/bert_tdt_lossscale.py
tests/st/networks/models/bert/bert_tdt_lossscale.py
+4
-4
未找到文件。
mindspore/ccsrc/pipeline/validator.cc
浏览文件 @
0ac59119
...
...
@@ -62,12 +62,12 @@ void ValidateOperation(const AnfNodePtr &node) {
void
ValidateAbstract
(
const
AnfNodePtr
&
node
)
{
if
(
node
==
nullptr
)
{
MS_LOG
(
WARNIN
G
)
<<
"Node to validate is invalid"
;
MS_LOG
(
DEBU
G
)
<<
"Node to validate is invalid"
;
return
;
}
AbstractBasePtr
ptrBase
=
node
->
abstract
();
if
(
ptrBase
==
nullptr
)
{
MS_LOG
(
WARNIN
G
)
<<
"Abstract is null in node: "
<<
node
->
DebugString
();
MS_LOG
(
DEBU
G
)
<<
"Abstract is null in node: "
<<
node
->
DebugString
();
return
;
}
if
(
ptrBase
->
isa
<
AbstractClass
>
()
||
ptrBase
->
isa
<
AbstractJTagged
>
())
{
...
...
mindspore/ccsrc/pre_activate/ascend/format_type/merge_cast_to_op.cc
浏览文件 @
0ac59119
...
...
@@ -61,16 +61,14 @@ bool AlternativeKernelInfoForInput(const CNodePtr &node, const TypeId dst_type,
bool
GetNextNodeAndCastIndex
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
,
AnfNodePtr
*
next_node
,
size_t
*
cast_index
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
node
);
// Check whether the cast node is used for input by only one another node.
auto
manager
=
graph
->
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
if
(
manager
->
node_users
().
find
(
node
)
==
manager
->
node_users
().
end
()
||
manager
->
node_users
()[
node
].
size
()
!=
1
)
{
auto
output_node_list
=
GetRealNodeUsedList
(
graph
,
node
);
MS_EXCEPTION_IF_NULL
(
output_node_list
);
if
(
output_node_list
->
size
()
!=
1
)
{
return
false
;
}
*
next_node
=
manager
->
node_users
()[
node
].
begin
()
->
first
;
*
cast_index
=
IntToSize
(
manager
->
node_users
()[
node
].
begin
()
->
second
-
1
);
auto
node_pair
=
output_node_list
->
at
(
0
);
*
next_node
=
node_pair
.
first
;
*
cast_index
=
node_pair
.
second
-
1
;
return
true
;
}
...
...
@@ -148,7 +146,10 @@ AnfNodePtr MergeCastToNextOp(const FuncGraphPtr &graph, const CNodePtr &node, co
if
(
alternative_kernel_info
==
kernel_info_list
.
end
())
{
return
nullptr
;
}
MS_LOG
(
INFO
)
<<
"Found alternative kernel info for current anf kernel "
<<
next_op_name
;
auto
ori_kernel_info
=
AnfAlgo
::
GetSelectKernelBuildInfo
(
next_node
);
MS_LOG
(
INFO
)
<<
"Found alternative kernel info for current anf kernel "
<<
next_cnode
->
DebugString
()
<<
"ori kernel info"
<<
ori_kernel_info
->
ToString
()
<<
"alternative kernel info"
<<
(
*
alternative_kernel_info
)
->
ToString
();
AnfAlgo
::
SetSelectKernelBuildInfo
(
*
alternative_kernel_info
,
next_cnode
.
get
());
if
(
node
->
inputs
().
size
()
<
kCastInputNum
)
{
auto
op_name
=
AnfAlgo
::
GetCNodeName
(
node
);
...
...
@@ -217,8 +218,11 @@ AnfNodePtr MergeCastToPriorOp(const FuncGraphPtr &graph, const CNodePtr &cur_nod
if
(
kernel_info_it
==
kernel_info_list
.
end
())
{
return
nullptr
;
}
auto
ori_kernel_info
=
AnfAlgo
::
GetSelectKernelBuildInfo
(
prior_op
);
MS_LOG
(
INFO
)
<<
"Found alternative kernel info for current anf kernel "
<<
prior_op
->
DebugString
()
<<
"ori kernel info"
<<
ori_kernel_info
->
ToString
()
<<
"alternative kernel info"
<<
(
*
kernel_info_it
)
->
ToString
();
AnfAlgo
::
SetSelectKernelBuildInfo
(
*
kernel_info_it
,
prior_op
.
get
());
auto
prior_name
=
AnfAlgo
::
GetCNodeName
(
prior_op
);
if
(
prior_name
==
kFive2FourOpName
)
{
AnfAlgo
::
CopyNodeAttr
(
"dst_type"
,
"dstType"
,
cur_node
,
prior_op
);
...
...
mindspore/ccsrc/pre_activate/common/helper.cc
浏览文件 @
0ac59119
...
...
@@ -20,6 +20,7 @@
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <deque>
#include "utils/utils.h"
#include "utils/base_ref.h"
...
...
@@ -472,15 +473,38 @@ void RemoveNopNode(session::KernelGraph *const graph) {
}
}
bool
IsUsedByOthers
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
)
{
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
AnfNodePtr
,
int
>>>
GetRealNodeUsedList
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
)
{
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
AnfNodePtr
,
int
>>>
output_node_list
=
std
::
make_shared
<
std
::
vector
<
std
::
pair
<
AnfNodePtr
,
int
>>>
();
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
node
);
auto
manager
=
graph
->
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
if
(
manager
->
node_users
().
find
(
node
)
==
manager
->
node_users
().
end
())
{
auto
iter
=
manager
->
node_users
().
find
(
node
);
if
(
iter
==
manager
->
node_users
().
end
())
{
MS_LOG
(
EXCEPTION
)
<<
"node has no output in manager"
;
}
return
manager
->
node_users
()[
node
].
size
()
>
1
;
auto
output_info_list
=
iter
->
second
;
for
(
const
auto
&
output_info
:
output_info_list
)
{
if
(
AnfAlgo
::
GetCNodeName
(
output_info
.
first
)
==
prim
::
kPrimControlDepend
->
name
())
{
continue
;
}
if
(
AnfAlgo
::
GetCNodeName
(
output_info
.
first
)
==
prim
::
kPrimDepend
->
name
()
&&
output_info
.
second
==
kDependAttachNodeIndex
)
{
continue
;
}
output_node_list
->
push_back
(
output_info
);
}
return
output_node_list
;
}
bool
IsUsedByOthers
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
node
);
auto
output_node_list
=
GetRealNodeUsedList
(
graph
,
node
);
MS_EXCEPTION_IF_NULL
(
output_node_list
);
return
output_node_list
->
size
()
>
1
;
}
AnfNodePtr
CreatTupleGetItemNode
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
size_t
output_idx
)
{
...
...
mindspore/ccsrc/pre_activate/common/helper.h
浏览文件 @
0ac59119
...
...
@@ -19,6 +19,7 @@
#include <vector>
#include <memory>
#include <string>
#include <utility>
#include <unordered_set>
#include "ir/func_graph.h"
#include "session/kernel_graph.h"
...
...
@@ -160,6 +161,9 @@ void RemoveNopNode(session::KernelGraph *const graph);
AnfNodePtr
CreatTupleGetItemNode
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
size_t
output_idx
);
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
AnfNodePtr
,
int
>>>
GetRealNodeUsedList
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
);
bool
IsUsedByOthers
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
);
void
ConstInputToAttr
(
const
CNodePtr
&
cnode
,
const
std
::
unordered_set
<
size_t
>
&
input_attrs
);
...
...
mindspore/ccsrc/pre_activate/pass/optimize_dependence.cc
浏览文件 @
0ac59119
...
...
@@ -44,11 +44,11 @@ AnfNodePtr GetReplaceNode(const AnfNodePtr &node) {
return
cnode
->
input
(
kSingleInputIndex
);
}
bool
ReplaceMakeTuple
(
const
FuncGraphPtr
&
func_graph
,
const
CNodePtr
&
cnode
)
{
AnfNodePtr
ReplaceMakeTuple
(
const
FuncGraphPtr
&
func_graph
,
const
CNodePtr
&
cnode
)
{
MS_EXCEPTION_IF_NULL
(
func_graph
);
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
AnfAlgo
::
GetCNodeName
(
cnode
)
!=
prim
::
kPrimMakeTuple
->
name
())
{
return
false
;
return
nullptr
;
}
std
::
vector
<
AnfNodePtr
>
new_make_tuple_inputs
;
bool
need_update
=
false
;
...
...
@@ -75,17 +75,16 @@ bool ReplaceMakeTuple(const FuncGraphPtr &func_graph, const CNodePtr &cnode) {
auto
manager
=
func_graph
->
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
manager
->
Replace
(
cnode
,
new_make_tuple
);
return
new_make_tuple
;
}
return
true
;
return
nullptr
;
}
}
// namespace
const
BaseRef
OptimizeDependence
::
DefinePattern
()
const
{
VarPtr
X
=
std
::
make_shared
<
Var
>
(
"X"
);
MS_EXCEPTION_IF_NULL
(
X
);
VarPtr
Y
=
std
::
make_shared
<
Var
>
(
"Y"
);
MS_EXCEPTION_IF_NULL
(
Y
);
return
VectorRef
({
prim
::
kPrimDepend
,
X
,
Y
});
VarPtr
X
=
std
::
make_shared
<
Var
>
();
VarPtr
Xs
=
std
::
make_shared
<
SeqVar
>
();
return
VectorRef
({
X
,
Xs
});
}
const
AnfNodePtr
OptimizeDependence
::
Process
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
...
...
@@ -95,29 +94,50 @@ const AnfNodePtr OptimizeDependence::Process(const FuncGraphPtr &func_graph, con
if
(
!
node
->
isa
<
CNode
>
())
{
return
nullptr
;
}
if
(
AnfAlgo
::
GetCNodeName
(
node
)
!=
prim
::
kPrimControlDepend
->
name
()
&&
AnfAlgo
::
GetCNodeName
(
node
)
!=
prim
::
kPrimDepend
->
name
())
{
return
nullptr
;
}
size_t
index
=
0
;
auto
depend_cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
depend_cnode
);
CheckCNodeInputSize
(
depend_cnode
,
kDependInputNum
);
auto
replacing_node
=
depend_cnode
->
input
(
kDependInputNum
-
1
);
MS_EXCEPTION_IF_NULL
(
replacing_node
);
if
(
!
replacing_node
->
isa
<
CNode
>
())
{
return
nullptr
;
std
::
vector
<
AnfNodePtr
>
new_depend_inputs
=
{
depend_cnode
->
input
(
kAnfPrimitiveIndex
)};
if
(
AnfAlgo
::
GetCNodeName
(
node
)
==
prim
::
kPrimDepend
->
name
())
{
index
=
1
;
new_depend_inputs
.
push_back
(
depend_cnode
->
input
(
kRealInputIndexInDepend
));
}
auto
replacing_cnode
=
replacing_node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
replacing_cnode
);
// Deal with the make_tuple with TransData or Cast inputs.
if
(
ReplaceMakeTuple
(
func_graph
,
replacing_cnode
))
{
return
nullptr
;
if
(
AnfAlgo
::
GetInputTensorNum
(
depend_cnode
)
<
2
)
{
MS_LOG
(
EXCEPTION
)
<<
"The depend node input size is at less size 2,but got "
<<
AnfAlgo
::
GetInputTensorNum
(
depend_cnode
)
<<
depend_cnode
->
DebugString
();
}
AnfNodePtr
replace_node
=
GetReplaceNode
(
replacing_cnode
);
if
(
replace_node
==
nullptr
)
{
MS_LOG
(
DEBUG
)
<<
"Can not find the TransData or Cast with single output node. Depend node: "
<<
node
->
DebugString
();
return
nullptr
;
while
(
index
<
AnfAlgo
::
GetInputTensorNum
(
depend_cnode
))
{
auto
replacing_node
=
AnfAlgo
::
GetInputNode
(
depend_cnode
,
index
);
++
index
;
MS_EXCEPTION_IF_NULL
(
replacing_node
);
if
(
!
replacing_node
->
isa
<
CNode
>
())
{
new_depend_inputs
.
push_back
(
replacing_node
);
continue
;
}
auto
replacing_cnode
=
replacing_node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
replacing_cnode
);
// Deal with the make_tuple with TransData or Cast inputs.
auto
make_tuple_replace_node
=
ReplaceMakeTuple
(
func_graph
,
replacing_cnode
);
if
(
make_tuple_replace_node
!=
nullptr
)
{
new_depend_inputs
.
push_back
(
make_tuple_replace_node
);
continue
;
}
AnfNodePtr
replace_node
=
GetReplaceNode
(
replacing_cnode
);
if
(
replace_node
==
nullptr
)
{
new_depend_inputs
.
push_back
(
replacing_node
);
MS_LOG
(
DEBUG
)
<<
"Can not find the TransData or Cast with single output node. Depend node: "
<<
node
->
DebugString
();
continue
;
}
new_depend_inputs
.
push_back
(
replace_node
);
}
std
::
vector
<
AnfNodePtr
>
new_depend_inputs
=
{
depend_cnode
->
input
(
kAnfPrimitiveIndex
),
depend_cnode
->
input
(
kRealInputIndexInDepend
),
replace_node
};
auto
kernel_graph
=
func_graph
->
cast
<
std
::
shared_ptr
<
session
::
KernelGraph
>>
();
CNodePtr
new_depend
;
CNodePtr
new_depend
=
nullptr
;
if
(
kernel_graph
==
nullptr
)
{
new_depend
=
func_graph
->
NewCNode
(
new_depend_inputs
);
MS_EXCEPTION_IF_NULL
(
new_depend
);
...
...
tests/st/networks/models/bert/bert_tdt_lossscale.py
浏览文件 @
0ac59119
...
...
@@ -171,18 +171,18 @@ def test_bert_tdt():
# assertion occurs while the loss value, overflow state or loss_scale value is wrong
loss_value
=
np
.
array
(
callback
.
loss_list
)
expect_loss_value
=
[
12.207198
,
11.
980881
,
11.984844
,
11.879381
,
11.832978
,
12.411333
,
12.009284
,
12.621
277
,
12.223178
,
12.427385
]
expect_loss_value
=
[
12.207198
,
11.
865665
,
11.828972
,
11.827378
,
11.821808
,
12.408042
,
12.00606
,
12.621
794
,
12.223485
,
12.427612
]
print
(
"loss value: {}"
.
format
(
loss_value
))
assert
np
.
allclose
(
loss_value
,
expect_loss_value
,
0
,
0.0005
)
overflow
=
np
.
array
(
callback
.
overflow_list
)
expect_overflow
=
[
True
,
True
,
False
,
False
,
False
,
True
,
False
,
False
,
False
,
Tru
e
]
expect_overflow
=
[
False
,
False
,
False
,
True
,
False
,
False
,
False
,
True
,
False
,
Fals
e
]
print
(
"overflow: {}"
.
format
(
overflow
))
assert
(
overflow
==
expect_overflow
).
all
()
loss_scale
=
np
.
array
(
callback
.
lossscale_list
)
expect_loss_scale
=
[
32768.0
,
16384.0
,
16384.0
,
16384.0
,
32768.0
,
16384.0
,
16384.0
,
16384.0
,
32768.0
,
16384
.0
]
expect_loss_scale
=
[
65536.0
,
65536.0
,
131072.0
,
65536.0
,
65536.0
,
65536.0
,
131072.0
,
65536.0
,
65536.0
,
65536
.0
]
print
(
"loss scale: {}"
.
format
(
loss_scale
))
assert
np
.
allclose
(
loss_scale
,
expect_loss_scale
,
0
,
0
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录