Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0c43ce22
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看板
未验证
提交
0c43ce22
编写于
2月 07, 2022
作者:
A
arlesniak
提交者:
GitHub
2月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update BF16 amp list (#39304)
* amp list updated * tests updated * gray list updated * amp list updated * test updated
上级
ebd14743
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
40 addition
and
17 deletion
+40
-17
python/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py
...on/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py
+9
-6
python/paddle/fluid/contrib/tests/test_bf16_utils.py
python/paddle/fluid/contrib/tests/test_bf16_utils.py
+8
-8
python/paddle/fluid/contrib/tests/test_model_cast_to_bf16.py
python/paddle/fluid/contrib/tests/test_model_cast_to_bf16.py
+23
-3
未找到文件。
python/paddle/fluid/contrib/mixed_precision/bf16/amp_lists.py
浏览文件 @
0c43ce22
...
...
@@ -83,15 +83,18 @@ class AutoMixedPrecisionListsBF16(object):
bf16_initializer_list
=
{
'fill_constant'
,
'uniform_random'
}
# always bf16
bf16_list
=
{
'elementwise_add'
,
'mul'
}
bf16_list
=
{
'conv2d'
,
'matmul'
,
'matmul_v2'
,
'mul'
,
}
# depends on the prev_op type
gray_list
=
{
'cast'
,
'fill_constant'
,
'reduce_mean'
,
'reshape2'
,
'scale'
,
'elementwise_add'
,
'elementwise_sub'
,
'elementwise_mul'
,
'elementwise_div'
,
'relu'
,
'layer_norm'
,
'slice'
,
'concat'
,
'uniform_random'
,
'reshape2'
,
'transpose2'
,
'pool2d'
,
'sigmoid'
,
'cast'
,
'scale'
,
'fill_constant'
,
'split'
}
_
,
_
,
_sys_unsupported_bf16_list
=
core
.
op_supported_infos
(
...
...
python/paddle/fluid/contrib/tests/test_bf16_utils.py
浏览文件 @
0c43ce22
...
...
@@ -57,20 +57,20 @@ class AMPTest(unittest.TestCase):
self
.
amp_lists_
=
amp
.
bf16
.
AutoMixedPrecisionListsBF16
({
'lstm'
})
def
test_amp_lists_4
(
self
):
# 4. w=None, b={'
elementwise_add
'}
self
.
bf16_list
.
remove
(
'
elementwise_add
'
)
self
.
fp32_list
.
add
(
'
elementwise_add
'
)
# 4. w=None, b={'
matmul_v2
'}
self
.
bf16_list
.
remove
(
'
matmul_v2
'
)
self
.
fp32_list
.
add
(
'
matmul_v2
'
)
self
.
amp_lists_
=
amp
.
bf16
.
AutoMixedPrecisionListsBF16
(
custom_fp32_list
=
{
'
elementwise_add
'
})
custom_fp32_list
=
{
'
matmul_v2
'
})
def
test_amp_lists_5
(
self
):
# 5. w=None, b={'
elementwise_add
'}
self
.
fp32_list
.
add
(
'
elementwise_add
'
)
self
.
bf16_list
.
remove
(
'
elementwise_add
'
)
# 5. w=None, b={'
matmul_v2
'}
self
.
fp32_list
.
add
(
'
matmul_v2
'
)
self
.
bf16_list
.
remove
(
'
matmul_v2
'
)
self
.
amp_lists_
=
amp
.
bf16
.
AutoMixedPrecisionListsBF16
(
custom_fp32_list
=
{
'
elementwise_add
'
})
custom_fp32_list
=
{
'
matmul_v2
'
})
def
test_amp_lists_6
(
self
):
# 6. w=None, b={'lstm'}
...
...
python/paddle/fluid/contrib/tests/test_model_cast_to_bf16.py
浏览文件 @
0c43ce22
...
...
@@ -19,6 +19,7 @@ import paddle.fluid as fluid
import
contextlib
import
unittest
import
numpy
as
np
import
struct
import
paddle.fluid.layers
as
layers
import
paddle.static.amp
as
amp
from
paddle.fluid
import
core
...
...
@@ -26,6 +27,20 @@ from paddle.fluid import core
paddle
.
enable_static
()
def
convert_uint16_to_float
(
in_list
):
if
in_list
.
dtype
==
np
.
uint16
:
in_list
=
np
.
asarray
(
in_list
)
out
=
np
.
vectorize
(
lambda
x
:
struct
.
unpack
(
'<f'
,
struct
.
pack
(
'<I'
,
x
<<
16
))[
0
],
otypes
=
[
np
.
float32
])(
in_list
.
flat
)
return
np
.
reshape
(
out
,
in_list
.
shape
)
else
:
return
in_list
cutf
=
convert_uint16_to_float
@
unittest
.
skipIf
(
not
core
.
supports_bfloat16
(),
"place does not support BF16 evaluation"
)
class
TestModelCastBF16
(
unittest
.
TestCase
):
...
...
@@ -111,10 +126,13 @@ class TestModelCastBF16(unittest.TestCase):
'tt_bf16'
:
nn_bf16
,
},
fetch_list
=
[
ret_bf16
,
ret
,
ret_fp32bf16
],
amp_fun
=
lambda
prog
:
amp
.
bf16
.
rewrite_program_bf16
(
prog
))
amp_fun
=
_amp_fun
,
startup_prog
=
startup_prog
)
self
.
assertTrue
(
np
.
allclose
(
static_ret_bf16
,
static_ret
,
1e-2
))
self
.
assertTrue
(
np
.
allclose
(
static_ret_bf16
,
ret_fp32bf16
,
1e-2
))
self
.
assertTrue
(
np
.
allclose
(
cutf
(
static_ret_bf16
),
cutf
(
static_ret
),
1e-2
))
self
.
assertTrue
(
np
.
allclose
(
cutf
(
static_ret_bf16
),
cutf
(
ret_fp32bf16
),
1e-2
))
with
self
.
static_graph
():
t
=
layers
.
data
(
name
=
't'
,
shape
=
[
size
,
size
],
dtype
=
'float32'
)
...
...
@@ -141,6 +159,7 @@ class TestModelCastBF16(unittest.TestCase):
self
.
_graph_common
(
lambda
prog
:
amp
.
bf16
.
rewrite_program_bf16
(
prog
,
amp
.
bf16
.
AutoMixedPrecisionListsBF16
(
custom_bf16_list
=
{
'elementwise_add'
},
custom_fp32_varnames
=
{
'elementwise_add_0.tmp_0'
})
))
...
...
@@ -149,6 +168,7 @@ class TestModelCastBF16(unittest.TestCase):
prog
,
startup_prog
,
amp
.
bf16
.
AutoMixedPrecisionListsBF16
(
custom_bf16_list
=
{
'elementwise_add'
},
custom_fp32_list
=
{
'elementwise_mul'
}),
use_bf16_guard
=
True
),
startup_prog
=
fluid
.
default_startup_program
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录