Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
1a82ff0a
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看板
提交
1a82ff0a
编写于
4月 03, 2020
作者:
W
wanghua
提交者:
高东海
4月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bert precison bug
上级
26e61382
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
24 addition
and
16 deletion
+24
-16
mindspore/ccsrc/device/ascend/kernel_select_ascend.cc
mindspore/ccsrc/device/ascend/kernel_select_ascend.cc
+13
-7
mindspore/ccsrc/utils/utils.h
mindspore/ccsrc/utils/utils.h
+3
-0
mindspore/ops/_op_impl/tbe/gelu.py
mindspore/ops/_op_impl/tbe/gelu.py
+4
-4
tests/st/networks/models/bert/bert_tdt_no_lossscale.py
tests/st/networks/models/bert/bert_tdt_no_lossscale.py
+4
-5
未找到文件。
mindspore/ccsrc/device/ascend/kernel_select_ascend.cc
浏览文件 @
1a82ff0a
...
...
@@ -35,6 +35,7 @@ enum MatchCountPriority : int {
MATCH_COUNT_PRIORITY_BEGIN
=
0
,
MATCH_DTYPE_COUNT
=
MATCH_COUNT_PRIORITY_BEGIN
,
MATCH_FORMAT_COUNT
,
MATCH_SPECIAL_FORMAT_COUNT
,
MATCH_5D_FORMAT_COUNT
,
MATCH_OUTPUT_DTYPE_COUNT
,
MATCH_COUNT_PRIORITY_END
...
...
@@ -81,6 +82,12 @@ bool IsValidKernelInfo(const std::shared_ptr<CNode> &kernel_node, const kernel::
}
return
true
;
};
if
(
AnfAlgo
::
GetCNodeName
(
kernel_node
)
==
"LayerNormBetaGammaBackprop"
||
AnfAlgo
::
GetCNodeName
(
kernel_node
)
==
"LayerNormXBackprop"
)
{
if
(
AnfAlgo
::
GetPrevNodeOutputFormat
(
kernel_node
,
0
)
!=
kernel_build_info
.
GetInputFormat
(
0
))
{
return
true
;
}
}
if
(
AnfAlgo
::
GetCNodeName
(
kernel_node
)
==
prim
::
kPrimCast
->
name
())
{
return
AnfAlgo
::
GetOutputInferDataType
(
kernel_node
,
0
)
==
kernel_build_info
.
GetOutputDeviceType
(
0
)
&&
AnfAlgo
::
GetPrevNodeOutputInferDataType
(
kernel_node
,
0
)
==
kernel_build_info
.
GetInputDeviceType
(
0
);
...
...
@@ -154,7 +161,7 @@ bool PriorityChooseItem(const std::vector<int> &cur_item, std::vector<int> *best
return
false
;
}
}
return
fals
e
;
return
tru
e
;
}
void
UpdateCurMatchCounts
(
const
kernel
::
KernelBuildInfo
&
kernel_build_info
,
const
std
::
shared_ptr
<
CNode
>
&
kernel_node
,
...
...
@@ -174,12 +181,11 @@ void UpdateCurMatchCounts(const kernel::KernelBuildInfo &kernel_build_info, cons
continue
;
}
}
if
(
input_anf_node
->
isa
<
ValueNode
>
())
{
if
(
AnfAlgo
::
GetOutputDeviceDataType
(
input_anf_node
,
0
)
==
kTypeUnknown
)
{
continue
;
}
}
if
(
kernel_build_info
.
GetInputFormat
(
input_index
)
==
AnfAlgo
::
GetPrevNodeOutputFormat
(
kernel_node
,
input_index
))
{
if
(
AnfAlgo
::
IsFeatureMapInput
(
kernel_node
,
input_index
)
&&
kSpecialFormatSet
.
find
(
kernel_build_info
.
GetInputFormat
(
input_index
))
!=
kSpecialFormatSet
.
end
())
{
(
*
cur_kernelinfo_match_counts
)[
MATCH_SPECIAL_FORMAT_COUNT
]
++
;
}
(
*
cur_kernelinfo_match_counts
)[
MATCH_FORMAT_COUNT
]
++
;
}
if
(
kernel_build_info
.
GetInputDeviceType
(
input_index
)
==
...
...
@@ -203,7 +209,7 @@ void UpdateCurMatchCounts(const kernel::KernelBuildInfo &kernel_build_info, cons
(
*
cur_kernelinfo_match_counts
)[
MATCH_OUTPUT_DTYPE_COUNT
]
++
;
}
}
}
}
// namespace
void
SetTensorDeviceInfo
(
const
kernel
::
KernelBuildInfo
&
selected_kernel_info
,
const
CNodePtr
&
kernel_node
)
{
MS_EXCEPTION_IF_NULL
(
kernel_node
);
...
...
mindspore/ccsrc/utils/utils.h
浏览文件 @
1a82ff0a
...
...
@@ -195,6 +195,9 @@ const std::set<std::string> kOptOperatorSet = {
kApplyRMSPropOpName
,
};
const
std
::
set
<
std
::
string
>
kSpecialFormatSet
=
{
kOpFormat_FRAC_Z
,
kOpFormat_NC1KHKWHWC0
,
kOpFormat_NC1HWC0
,
kOpFormat_FRAC_NZ
,
kOpFormat_C1HWNCoC0
};
static
inline
void
ChangeFileMode
(
const
std
::
string
&
file_name
,
mode_t
mode
)
{
if
(
access
(
file_name
.
c_str
(),
F_OK
)
!=
0
)
{
MS_LOG
(
DEBUG
)
<<
"File `"
<<
file_name
<<
"` does not exist."
;
...
...
mindspore/ops/_op_impl/tbe/gelu.py
浏览文件 @
1a82ff0a
...
...
@@ -32,10 +32,10 @@ from mindspore.ops.op_info_register import op_info_register
{
"index": 0,
"dtype": [
"float16","float","float16","float16","float16","float16","float","float","float","float"
"float16","float",
"float16","float","float16","float16","float16","float16","float","float","float","float"
],
"format": [
"FracZ","FracZ","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat"
"F
RACTAL_NZ","FRACTAL_NZ","F
racZ","FracZ","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat"
],
"name": "x",
"need_compile": false,
...
...
@@ -47,10 +47,10 @@ from mindspore.ops.op_info_register import op_info_register
{
"index": 0,
"dtype": [
"float16","float","float16","float16","float16","float16","float","float","float","float"
"float16","float",
"float16","float","float16","float16","float16","float16","float","float","float","float"
],
"format": [
"FracZ","FracZ","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat"
"F
RACTAL_NZ","FRACTAL_NZ","F
racZ","FracZ","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat","DefaultFormat","NC1HWC0","DefaultFormat","DefaultFormat"
],
"name": "y",
"need_compile": true,
...
...
tests/st/networks/models/bert/bert_tdt_no_lossscale.py
浏览文件 @
1a82ff0a
...
...
@@ -153,8 +153,7 @@ def test_bert_tdt():
batch_size
=
int
(
os
.
getenv
(
'BATCH_SIZE'
,
'16'
))
config
=
get_config
(
version
=
version
,
batch_size
=
batch_size
)
netwithloss
=
BertNetworkWithLoss
(
config
,
True
)
optimizer
=
Lamb
(
netwithloss
.
trainable_params
(),
decay_steps
=
10000
,
start_learning_rate
=
1e-4
,
end_learning_rate
=
0.0
,
power
=
10.0
,
warmup_steps
=
0
,
decay_filter
=
lambda
x
:
False
)
optimizer
=
Momentum
(
netwithloss
.
trainable_params
(),
learning_rate
=
2e-5
,
momentum
=
0.9
)
netwithgrads
=
BertTrainOneStepCell
(
netwithloss
,
optimizer
=
optimizer
)
netwithgrads
.
set_train
(
True
)
model
=
Model
(
netwithgrads
)
...
...
@@ -178,10 +177,10 @@ def test_bert_tdt():
param
.
default_input
=
weight_variable
(
value
.
asnumpy
().
shape
)
model
.
train
(
ds
.
get_repeat_count
(),
ds
,
callbacks
=
parallel_callback
,
dataset_sink_mode
=
False
)
loss_value
=
np
.
array
(
parallel_callback
.
loss_list
)
expect_out
=
[
12.19179
0
,
11.739655
,
11.523477
,
11.320723
,
11.113152
,
11.203759
,
10.841681
,
10.826849
,
1
0.616718
,
10.486609
]
expect_out
=
[
12.19179
,
11.965041
,
11.969687
,
11.97815
,
11.969171
,
12.603289
,
12.165594
,
1
2.824818
,
12.38842
,
12.604046
]
logger
.
info
(
"expected loss value output: {}"
.
format
(
expect_out
))
assert
allclose
(
loss_value
,
expect_out
,
0.00
1
,
0.
001
)
assert
allclose
(
loss_value
,
expect_out
,
0.00
001
,
0.00
001
)
if
__name__
==
'__main__'
:
test_bert_tdt
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录