Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4ee3815e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4ee3815e
编写于
6月 14, 2023
作者:
Z
Zhang Ting
提交者:
GitHub
6月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP] fix bf16 amp training error (#54571)
上级
4277f61f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
41 deletion
+34
-41
paddle/fluid/eager/amp_auto_cast.h
paddle/fluid/eager/amp_auto_cast.h
+7
-5
paddle/fluid/eager/amp_utils.h
paddle/fluid/eager/amp_utils.h
+21
-31
paddle/fluid/eager/eager_amp_auto_cast.h
paddle/fluid/eager/eager_amp_auto_cast.h
+6
-5
未找到文件。
paddle/fluid/eager/amp_auto_cast.h
浏览文件 @
4ee3815e
...
...
@@ -69,15 +69,16 @@ inline paddle::Tensor AmpAutoCast(const std::string& input_name,
VLOG
(
6
)
<<
"AMP AmpAutoCasts:"
<<
" input("
<<
input_name
<<
") dst_dtype("
<<
phi
::
DataTypeToString
(
dst_dtype
)
<<
")."
;
if
((
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
)
&&
input_name
!=
"X"
)
{
return
input
;
}
if
(
dst_dtype
==
phi
::
DataType
::
FLOAT16
)
{
if
(
op_name
==
"run_program"
)
{
return
input
;
}
if
((
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
)
&&
input_name
!=
"X"
)
{
return
input
;
}
if
((
op_name
==
"fused_attention"
||
op_name
==
"fused_feedforward"
))
{
if
(
input_name
==
"LnScale"
||
input_name
==
"LnBias"
||
input_name
==
"Ln2Scale"
||
input_name
==
"Ln2Bias"
||
...
...
@@ -86,6 +87,7 @@ inline paddle::Tensor AmpAutoCast(const std::string& input_name,
}
}
}
if
(
NeedCast
(
input
,
dst_dtype
))
{
paddle
::
framework
::
AttributeMap
cast_attrs
=
{
{
"in_dtype"
,
paddle
::
framework
::
TransToProtoVarType
(
input
.
dtype
())},
...
...
paddle/fluid/eager/amp_utils.h
浏览文件 @
4ee3815e
...
...
@@ -26,19 +26,24 @@ static inline phi::DataType GetPromoteType(
kSlotSmallVectorSize
>&
amp_tensors_vector
,
const
phi
::
DataType
&
amp_dtype
)
{
auto
dst_type
=
amp_dtype
;
// only consider the dtype of input(X).
if
(
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
||
op_name
==
"moving_average_abs_max_scale"
)
{
if
(
amp_tensors_vector
[
0
][
0
].
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
}
return
dst_type
;
}
if
(
egr
::
Controller
::
Instance
().
GetCurrentTracer
()
->
GetAmpDtype
()
==
"float16"
)
{
if
(
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
)
{
if
(
amp_tensors_vector
[
0
][
0
].
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
}
}
else
if
(
op_name
==
"fused_attention"
)
{
if
(
op_name
==
"fused_attention"
)
{
for
(
size_t
i
=
0
;
i
<
amp_tensors_vector
.
size
();
i
++
)
{
if
(
i
!=
3
||
i
!=
4
||
i
!=
9
||
i
!=
10
)
{
if
(
amp_tensors_vector
[
i
][
0
].
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
break
;
return
dst_type
;
}
}
}
...
...
@@ -47,37 +52,22 @@ static inline phi::DataType GetPromoteType(
if
(
i
!=
7
||
i
!=
8
||
i
!=
9
||
i
!=
10
)
{
if
(
amp_tensors_vector
[
i
][
0
].
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
break
;
}
}
}
}
else
{
for
(
const
auto
&
tensors
:
amp_tensors_vector
)
{
for
(
const
auto
&
tensor
:
tensors
)
{
if
(
tensor
.
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
tensor
.
dtype
();
break
;
return
dst_type
;
}
}
}
}
}
else
{
for
(
const
auto
&
tensors
:
amp_tensors_vector
)
{
for
(
const
auto
&
tensor
:
tensors
)
{
if
(
tensor
.
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
tensor
.
dtype
();
break
;
}
}
}
}
// NOTE(juncai): moving_average_abs_max_scale only consider the dtype of
// input(X)
if
(
op_name
==
"moving_average_abs_max_scale"
)
{
if
(
amp_tensors_vector
[
0
][
0
].
dtype
()
==
phi
::
DataType
::
FLOAT16
)
{
dst_type
=
phi
::
DataType
::
FLOAT16
;
for
(
const
auto
&
tensors
:
amp_tensors_vector
)
{
for
(
const
auto
&
tensor
:
tensors
)
{
if
(
tensor
.
dtype
()
==
phi
::
DataType
::
FLOAT32
)
{
dst_type
=
tensor
.
dtype
();
break
;
}
}
}
return
dst_type
;
}
...
...
paddle/fluid/eager/eager_amp_auto_cast.h
浏览文件 @
4ee3815e
...
...
@@ -89,15 +89,16 @@ inline paddle::Tensor EagerAmpAutoCast(const std::string& input_name,
VLOG
(
6
)
<<
"AMP AmpAutoCasts:"
<<
" input("
<<
egr
::
EagerUtils
::
TensorStr
(
input
)
<<
" to dst_dtype("
<<
phi
::
DataTypeToString
(
dst_dtype
)
<<
")."
;
if
((
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
)
&&
input_name
!=
"x"
)
{
return
input
;
}
if
(
dst_dtype
==
phi
::
DataType
::
FLOAT16
)
{
if
(
op_name
==
"run_program"
)
{
return
input
;
}
if
((
op_name
==
"batch_norm"
||
op_name
==
"layer_norm"
||
op_name
==
"sync_batch_norm"
)
&&
input_name
!=
"x"
)
{
return
input
;
}
if
((
op_name
==
"fused_attention"
||
op_name
==
"fused_feedforward"
))
{
if
(
input_name
==
"LnScale"
||
input_name
==
"LnBias"
||
input_name
==
"Ln2Scale"
||
input_name
==
"Ln2Bias"
||
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录