Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
56947361
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看板
未验证
提交
56947361
编写于
5月 22, 2023
作者:
N
niuliling123
提交者:
GitHub
5月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix ctest error in test_amp_api (#53885)
上级
f7083f47
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
23 deletion
+39
-23
python/paddle/static/amp/decorator.py
python/paddle/static/amp/decorator.py
+0
-2
python/paddle/static/amp/fp16_utils.py
python/paddle/static/amp/fp16_utils.py
+0
-2
test/amp/test_amp_api.py
test/amp/test_amp_api.py
+39
-19
未找到文件。
python/paddle/static/amp/decorator.py
浏览文件 @
56947361
...
...
@@ -916,8 +916,6 @@ def decorate(
warnings
.
warn
(
"If the Amp level is set to OD, the amp list will not be used."
)
amp_lists
.
white_list
=
{
"conv2d"
,
"matmul_v2"
}
amp_lists
.
black_list
=
amp_lists
.
all_list
-
amp_lists
.
white_list
if
use_dynamic_loss_scaling
is
None
:
...
...
python/paddle/static/amp/fp16_utils.py
浏览文件 @
56947361
...
...
@@ -622,8 +622,6 @@ def cast_model_to_fp16(
if
amp_lists
is
not
None
:
dtype
=
get_low_precision_dtypestr
(
dest_type
)
amp_lists
=
AutoMixedPrecisionLists
(
dtype
)
amp_lists
.
white_list
=
{
"conv2d"
,
"matmul_v2"
}
amp_lists
.
black_list
=
amp_lists
.
all_list
-
amp_lists
.
white_list
global_block
=
program
.
global_block
()
...
...
test/amp/test_amp_api.py
浏览文件 @
56947361
...
...
@@ -15,9 +15,10 @@
import
unittest
import
numpy
as
np
from
amp_base_models
import
AmpTestBase
,
build_conv_model
from
amp_base_models
import
AmpTestBase
import
paddle
from
paddle
import
nn
from
paddle.static
import
amp
...
...
@@ -39,25 +40,47 @@ class TestAutoCast(AmpTestBase):
self
.
assertEqual
(
out3
.
dtype
,
paddle
.
float32
)
class
SimpleConvNet
(
nn
.
Layer
):
def
__init__
(
self
):
super
().
__init__
()
self
.
_conv
=
paddle
.
nn
.
Conv2D
(
in_channels
=
1
,
out_channels
=
6
,
kernel_size
=
3
,
bias_attr
=
False
)
self
.
_linear
=
paddle
.
nn
.
Linear
(
in_features
=
4
,
out_features
=
4
)
def
forward
(
self
,
x
):
out1
=
self
.
_conv
(
paddle
.
rand
(
shape
=
[
1
,
1
,
6
,
6
],
dtype
=
'float32'
))
out2
=
out1
+
paddle
.
rand
(
shape
=
out1
.
shape
,
dtype
=
'float16'
)
out3
=
self
.
_linear
(
out2
)
return
out3
class
TestStaticDecorate
(
AmpTestBase
):
def
check_results
(
self
,
use_amp
,
dtype
,
level
,
use_promote
,
expected_op_calls
):
(
main_program
,
startup_program
,
optimizer
,
feed_vars
,
fetch_vars
,
)
=
build_conv_model
(
use_amp
,
dtype
,
level
,
use_promote
)
main_program
=
paddle
.
static
.
Program
()
startup_program
=
paddle
.
static
.
Program
()
with
paddle
.
utils
.
unique_name
.
guard
():
with
paddle
.
static
.
program_guard
(
main_program
,
startup_program
):
model
=
SimpleConvNet
()
x
=
paddle
.
static
.
data
(
name
=
'input'
,
shape
=
[
None
,
1
,
6
,
6
],
dtype
=
'float32'
)
out
=
model
(
x
)
loss
=
paddle
.
mean
(
out
)
optimizer
=
paddle
.
fluid
.
optimizer
.
Adadelta
(
learning_rate
=
0.001
)
optimizer
=
paddle
.
static
.
amp
.
decorate
(
optimizer
,
init_loss_scaling
=
128.0
,
use_dynamic_loss_scaling
=
True
,
level
=
level
,
)
optimizer
.
minimize
(
loss
)
feed_vars
=
[
x
]
fetch_vars
=
[
loss
]
self
.
assertEqual
(
main_program
.
num_blocks
,
1
)
optimizer
=
paddle
.
fluid
.
optimizer
.
Adadelta
(
learning_rate
=
0.001
)
optimizer
=
paddle
.
static
.
amp
.
decorate
(
optimizer
,
init_loss_scaling
=
128.0
,
use_dynamic_loss_scaling
=
True
,
level
=
level
,
)
amp
.
debugging
.
collect_operator_stats
(
main_program
)
op_stats_list
=
amp
.
debugging
.
_get_op_stats_list
(
main_program
)
...
...
@@ -85,16 +108,13 @@ class TestStaticDecorate(AmpTestBase):
level
,
)
def
test_static_amp_
o1
(
self
):
def
test_static_amp_
OD
(
self
):
paddle
.
enable_static
()
expected_fp16_calls
=
{
"conv2d"
:
1
,
"elementwise_add"
:
0
,
"relu"
:
0
,
"matmul_v2"
:
1
,
"softmax"
:
0
,
"reduce_mean"
:
0
,
"adamw"
:
0
,
}
self
.
check_results
(
True
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录