Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6f8ab1fa
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2323
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
6f8ab1fa
编写于
3月 30, 2023
作者:
Z
Zhang Ting
提交者:
GitHub
3月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[AMP] use promote dtype when amp_level=O2 (#51063)
上级
5cdd9f2c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
32 deletion
+25
-32
paddle/fluid/eager/amp_utils.h
paddle/fluid/eager/amp_utils.h
+10
-18
python/paddle/amp/__init__.py
python/paddle/amp/__init__.py
+2
-2
python/paddle/amp/auto_cast.py
python/paddle/amp/auto_cast.py
+11
-10
python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py
...e/fleet/test_imperative_auto_mixed_precision_for_eager.py
+2
-2
未找到文件。
paddle/fluid/eager/amp_utils.h
浏览文件 @
6f8ab1fa
...
...
@@ -122,24 +122,16 @@ inline phi::DataType GetAmpDestDtype(
auto
amp_setting_dtype
=
egr
::
Controller
::
Instance
().
GetCurrentTracer
()
->
GetAmpPhiDtype
();
auto
dst_type
=
amp_setting_dtype
;
if
(
amp_level
==
paddle
::
imperative
::
AmpLevel
::
O1
)
{
if
(
paddle
::
imperative
::
AmpOperators
::
Instance
()
.
GetMutableAllowOps
()
->
count
(
op_name
))
{
dst_type
=
amp_setting_dtype
;
}
else
if
(
paddle
::
imperative
::
AmpOperators
::
Instance
()
.
GetMutableBlockOps
()
->
count
(
op_name
))
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
}
else
{
dst_type
=
GetPromoteType
(
op_name
,
amp_tensors_vector
,
amp_setting_dtype
);
}
}
else
if
(
amp_level
==
paddle
::
imperative
::
AmpLevel
::
O2
)
{
if
(
paddle
::
imperative
::
AmpOperators
::
Instance
()
.
GetMutableBlockOps
()
->
count
(
op_name
))
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
}
if
(
paddle
::
imperative
::
AmpOperators
::
Instance
().
GetMutableAllowOps
()
->
count
(
op_name
))
{
dst_type
=
amp_setting_dtype
;
}
else
if
(
paddle
::
imperative
::
AmpOperators
::
Instance
()
.
GetMutableBlockOps
()
->
count
(
op_name
))
{
dst_type
=
phi
::
DataType
::
FLOAT32
;
}
else
{
dst_type
=
GetPromoteType
(
op_name
,
amp_tensors_vector
,
amp_setting_dtype
);
}
if
(
dst_type
==
amp_setting_dtype
&&
...
...
python/paddle/amp/__init__.py
浏览文件 @
6f8ab1fa
...
...
@@ -17,8 +17,8 @@ from .auto_cast import decorate # noqa: F401
from
.auto_cast
import
amp_guard
# noqa: F401
from
.auto_cast
import
amp_decorate
# noqa: F401
from
.auto_cast
import
low_precision_op_list
# noqa: F401
from
.auto_cast
import
WHITE_LIST
# noqa: F401
from
.auto_cast
import
BLACK_LIST
# noqa: F401
from
.auto_cast
import
FP16_
WHITE_LIST
# noqa: F401
from
.auto_cast
import
FP16_
BLACK_LIST
# noqa: F401
from
.auto_cast
import
PURE_FP16_WHITE_LIST
# noqa: F401
from
.auto_cast
import
PURE_FP16_BLACK_LIST
# noqa: F401
...
...
python/paddle/amp/auto_cast.py
浏览文件 @
6f8ab1fa
...
...
@@ -25,7 +25,7 @@ AMP_LEVEL = core.AmpLevel
# The set of ops that support fp16 calculation and are considered numerically-
# safe and performance-critical. These ops are always converted to fp16.
WHITE_LIST
=
{
FP16_
WHITE_LIST
=
{
'conv2d'
,
'matmul'
,
'matmul_v2'
,
...
...
@@ -37,7 +37,7 @@ WHITE_LIST = {
# The set of ops that support fp16 calculation and are considered numerically-
# dangerous and whose effects may also be observed in downstream ops.
BLACK_LIST
=
{
FP16_
BLACK_LIST
=
{
'exp'
,
'square'
,
'log'
,
...
...
@@ -73,7 +73,8 @@ AMP_RELATED_FLAGS_SETTING = {
'FLAGS_cudnn_batchnorm_spatial_persistent'
:
1
,
}
PURE_FP16_WHITE_LIST
=
set
()
PURE_FP16_WHITE_LIST
=
copy
.
copy
(
FP16_WHITE_LIST
)
PURE_FP16_BLACK_LIST
=
{
'lookup_table'
,
'lookup_table_v2'
,
...
...
@@ -90,7 +91,7 @@ PURE_FP16_BLACK_LIST = {
BF16_WHITE_LIST
=
{
'conv2d'
,
'matmul_v2'
}
BF16_BLACK_LIST
=
set
()
PURE_BF16_WHITE_LIST
=
set
(
)
PURE_BF16_WHITE_LIST
=
copy
.
copy
(
BF16_WHITE_LIST
)
PURE_BF16_BLACK_LIST
=
set
()
_g_amp_state_
=
None
...
...
@@ -139,8 +140,8 @@ def _update_list(
"""
if
dtype
==
'float16'
:
if
level
==
'O1'
:
_white_list
=
copy
.
copy
(
WHITE_LIST
)
_black_list
=
copy
.
copy
(
BLACK_LIST
)
_white_list
=
copy
.
copy
(
FP16_
WHITE_LIST
)
_black_list
=
copy
.
copy
(
FP16_
BLACK_LIST
)
else
:
_white_list
=
copy
.
copy
(
PURE_FP16_WHITE_LIST
)
_black_list
=
copy
.
copy
(
PURE_FP16_BLACK_LIST
)
...
...
@@ -424,8 +425,8 @@ def amp_guard(
if
level
==
'O1'
:
amp_level
=
AMP_LEVEL
.
O1
if
dtype
==
'float16'
:
_white_list
=
WHITE_LIST
_black_list
=
BLACK_LIST
_white_list
=
FP16_
WHITE_LIST
_black_list
=
FP16_
BLACK_LIST
elif
dtype
==
'bfloat16'
:
_white_list
=
BF16_WHITE_LIST
_black_list
=
BF16_BLACK_LIST
...
...
@@ -441,8 +442,8 @@ def amp_guard(
elif
level
==
'O0'
:
amp_level
=
AMP_LEVEL
.
O0
if
dtype
==
'float16'
:
_white_list
=
WHITE_LIST
_black_list
=
BLACK_LIST
_white_list
=
FP16_
WHITE_LIST
_black_list
=
FP16_
BLACK_LIST
elif
dtype
==
'bfloat16'
:
_white_list
=
BF16_WHITE_LIST
_black_list
=
BF16_BLACK_LIST
...
...
python/paddle/fluid/tests/unittests/collective/fleet/test_imperative_auto_mixed_precision_for_eager.py
浏览文件 @
6f8ab1fa
...
...
@@ -88,8 +88,8 @@ class TestAutoCast(unittest.TestCase):
def
custom_op_list
(
self
):
with
fluid
.
dygraph
.
guard
():
tracer
=
fluid
.
framework
.
_dygraph_tracer
()
base_white_list
=
paddle
.
amp
.
WHITE_LIST
base_black_list
=
paddle
.
amp
.
BLACK_LIST
base_white_list
=
paddle
.
amp
.
FP16_
WHITE_LIST
base_black_list
=
paddle
.
amp
.
FP16_
BLACK_LIST
with
paddle
.
amp
.
amp_guard
(
custom_white_list
=
[
"log"
],
custom_black_list
=
[
"conv2d"
]
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录