Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
d6f043b0
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看板
提交
d6f043b0
编写于
5月 18, 2020
作者:
Y
yujianfeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix batch norm bert fission for control depend case
上级
4009a8e5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
7 deletion
+28
-7
mindspore/ccsrc/pre_activate/ascend/ir_fission/batch_norm_bert_fission.cc
...pre_activate/ascend/ir_fission/batch_norm_bert_fission.cc
+14
-3
mindspore/ccsrc/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion.cc
.../pre_activate/ascend/ir_fusion/fused_batch_norm_fusion.cc
+13
-3
mindspore/ccsrc/pre_activate/pass/convert_tuple_output_to_maketuple.cc
...rc/pre_activate/pass/convert_tuple_output_to_maketuple.cc
+1
-1
未找到文件。
mindspore/ccsrc/pre_activate/ascend/ir_fission/batch_norm_bert_fission.cc
浏览文件 @
d6f043b0
...
...
@@ -25,6 +25,7 @@ namespace opt {
namespace
{
const
std
::
vector
<
int
>
kOutputIndex
{
0
,
3
,
4
,
5
};
constexpr
size_t
kBatchNormRealOutputNum
=
3
;
constexpr
size_t
kBatchNormRealInputNum
=
3
;
bool
CompareTupleGetitem
(
const
AnfNodePtr
&
n1
,
const
AnfNodePtr
&
n2
)
{
MS_EXCEPTION_IF_NULL
(
n1
);
...
...
@@ -56,6 +57,9 @@ bool GetBatchNormOutputs(const FuncGraphPtr &func_graph, const AnfNodePtr &bn, s
for
(
const
auto
&
node_index
:
manager
->
node_users
()[
bn
])
{
AnfNodePtr
output
=
node_index
.
first
;
MS_EXCEPTION_IF_NULL
(
output
);
if
(
!
IsPrimitiveCNode
(
output
,
prim
::
kPrimTupleGetItem
))
{
continue
;
}
auto
tuple_getiterm_cnode
=
output
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
tuple_getiterm_cnode
);
auto
index_node
=
tuple_getiterm_cnode
->
input
(
kInputNodeOutputIndexInTupleGetItem
);
...
...
@@ -77,7 +81,10 @@ AnfNodePtr CreateBNTrainingReduce(const FuncGraphPtr &func_graph, const AnfNodeP
MS_EXCEPTION_IF_NULL
(
bn
);
auto
bn_cnode
=
bn
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
bn_cnode
);
CheckCNodeInputSize
(
bn_cnode
,
kBatchNormInputNum
+
1
);
if
(
bn_cnode
->
inputs
().
size
()
<
kBatchNormRealInputNum
+
1
)
{
MS_LOG
(
EXCEPTION
)
<<
"The input size of node "
+
bn_cnode
->
DebugString
()
+
" is less than "
<<
kBatchNormRealInputNum
+
1
;
}
std
::
vector
<
AnfNodePtr
>
bn_training_reduce_inputs
=
{
NewValueNode
(
std
::
make_shared
<
Primitive
>
(
kBNTrainingReduceOpName
)),
bn_cnode
->
input
(
1
)};
auto
bn_training_reduce
=
func_graph
->
NewCNode
(
bn_training_reduce_inputs
);
...
...
@@ -100,7 +107,10 @@ AnfNodePtr CreateBNTrainingUpdateV2(const FuncGraphPtr &func_graph, const AnfNod
MS_EXCEPTION_IF_NULL
(
bn
);
auto
bn_cnode
=
bn
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
bn_cnode
);
CheckCNodeInputSize
(
bn_cnode
,
kBatchNormInputNum
+
1
);
if
(
bn_cnode
->
inputs
().
size
()
<
kBatchNormRealInputNum
+
1
)
{
MS_LOG
(
EXCEPTION
)
<<
"The input size of node "
+
bn_cnode
->
DebugString
()
+
" is less than "
<<
kBatchNormRealInputNum
+
1
;
}
if
(
bn_training_reduce_outputs
.
size
()
!=
kBNTrainingReduceOutputNum
)
{
MS_LOG
(
EXCEPTION
)
<<
"The output size of node bn_training_reduce must be "
<<
kBNTrainingReduceOutputNum
<<
", but it is "
<<
bn_training_reduce_outputs
.
size
();
...
...
@@ -164,7 +174,8 @@ const AnfNodePtr BatchNormBertFission::Process(const FuncGraphPtr &func_graph, c
(
void
)
manager
->
Replace
(
output
,
bn_training_update_v2_outputs
[
output_index
]);
output_index
++
;
}
return
nullptr
;
// Return the new node for control depends.
return
bn_training_update_v2
;
}
}
// namespace opt
}
// namespace mindspore
mindspore/ccsrc/pre_activate/ascend/ir_fusion/fused_batch_norm_fusion.cc
浏览文件 @
d6f043b0
...
...
@@ -90,9 +90,19 @@ ValuePtr FusedBatchNormFusion::GetFactor(const EquivPtr &equiv) const {
}
auto
tensor_ptr
=
value
->
cast
<
tensor
::
TensorPtr
>
();
MS_EXCEPTION_IF_NULL
(
tensor_ptr
);
auto
*
tensor_data
=
static_cast
<
float
*>
(
tensor_ptr
->
data_c
());
MS_EXCEPTION_IF_NULL
(
tensor_data
);
return
MakeValue
(
tensor_data
[
0
]);
if
(
tensor_ptr
->
data_type
()
==
kNumberTypeFloat16
)
{
auto
*
half_data
=
static_cast
<
const
Eigen
::
half
*>
(
tensor_ptr
->
data_c
());
MS_EXCEPTION_IF_NULL
(
half_data
);
float
float_data
=
Eigen
::
half_impl
::
half_to_float
(
half_data
[
0
]);
return
MakeValue
(
float_data
);
}
else
if
(
tensor_ptr
->
data_type
()
==
kNumberTypeFloat32
)
{
auto
*
tensor_data
=
static_cast
<
const
float
*>
(
tensor_ptr
->
data_c
());
MS_EXCEPTION_IF_NULL
(
tensor_data
);
return
MakeValue
(
tensor_data
[
0
]);
}
else
{
MS_LOG
(
WARNING
)
<<
"The factor data type of value node "
<<
value_node
->
DebugString
()
<<
" is not fp16 or fp32"
;
return
nullptr
;
}
}
AnfNodePtr
FusedBatchNormFusion
::
CreateBNTrainingReduce
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
...
...
mindspore/ccsrc/pre_activate/pass/convert_tuple_output_to_maketuple.cc
浏览文件 @
d6f043b0
...
...
@@ -65,7 +65,7 @@ const AnfNodePtr ConvertTupleOutputToMaketuple::Process(const FuncGraphPtr &func
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
AnfAlgo
::
GetCNodeName
(
cnode
)
==
prim
::
kPrimTupleGetItem
->
name
(
))
{
if
(
IsPrimitiveCNode
(
cnode
,
prim
::
kPrimTupleGetItem
)
||
IsPrimitiveCNode
(
cnode
,
prim
::
kPrimControlDepend
))
{
return
nullptr
;
}
if
(
std
::
any_of
(
cnode
->
inputs
().
begin
()
+
1
,
cnode
->
inputs
().
end
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录