Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cf825da3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
cf825da3
编写于
12月 12, 2022
作者:
W
Wilber
提交者:
GitHub
12月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test_convert_to_mixed_precision.py use tempfile for temporary models/params (#48819)
上级
9aef0e3e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
43 addition
and
54 deletion
+43
-54
python/paddle/fluid/tests/unittests/ir/test_convert_to_mixed_precision.py
...uid/tests/unittests/ir/test_convert_to_mixed_precision.py
+43
-54
未找到文件。
python/paddle/fluid/tests/unittests/ir/test_convert_to_mixed_precision.py
浏览文件 @
cf825da3
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
os
import
tempfile
import
unittest
import
unittest
import
paddle
import
paddle
...
@@ -30,69 +32,56 @@ from paddle.vision.models import resnet50
...
@@ -30,69 +32,56 @@ from paddle.vision.models import resnet50
'should compile with cuda.'
,
'should compile with cuda.'
,
)
)
class
TestConvertToMixedPrecision
(
unittest
.
TestCase
):
class
TestConvertToMixedPrecision
(
unittest
.
TestCase
):
def
test_convert_to_fp16
(
self
):
def
setUp
(
self
):
self
.
temp_dir
=
tempfile
.
TemporaryDirectory
()
model
=
resnet50
(
True
)
model
=
resnet50
(
True
)
net
=
to_static
(
net
=
to_static
(
model
,
input_spec
=
[
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
name
=
'x'
)]
model
,
input_spec
=
[
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
name
=
'x'
)]
)
)
paddle
.
jit
.
save
(
net
,
'resnet50/inference'
)
paddle
.
jit
.
save
(
convert_to_mixed_precision
(
net
,
os
.
path
.
join
(
self
.
temp_dir
.
name
,
'resnet50/inference'
)
'resnet50/inference.pdmodel'
,
'resnet50/inference.pdiparams'
,
'mixed/inference.pdmodel'
,
'mixed/inference.pdiparams'
,
PrecisionType
.
Half
,
PlaceType
.
GPU
,
True
,
)
)
def
test_convert_to_fp16_with_fp16_input
(
self
):
def
tearDown
(
self
):
model
=
resnet50
(
True
)
self
.
temp_dir
.
cleanup
()
net
=
to_static
(
model
,
input_spec
=
[
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
name
=
'x'
)]
)
paddle
.
jit
.
save
(
net
,
'resnet50/inference'
)
convert_to_mixed_precision
(
'resnet50/inference.pdmodel'
,
'resnet50/inference.pdiparams'
,
'mixed1/inference.pdmodel'
,
'mixed1/inference.pdiparams'
,
PrecisionType
.
Half
,
PlaceType
.
GPU
,
False
,
)
def
test_convert_to_fp16_with_blacklist
(
self
):
def
test_convert_to_mixed_precision
(
self
):
model
=
resnet50
(
True
)
mixed_precision_options
=
[
net
=
to_static
(
model
,
input_spec
=
[
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
name
=
'x'
)]
)
paddle
.
jit
.
save
(
net
,
'resnet50/inference'
)
convert_to_mixed_precision
(
'resnet50/inference.pdmodel'
,
'resnet50/inference.pdiparams'
,
'mixed2/inference.pdmodel'
,
'mixed2/inference.pdiparams'
,
PrecisionType
.
Half
,
PrecisionType
.
Half
,
PlaceType
.
GPU
,
PrecisionType
.
Half
,
False
,
PrecisionType
.
Half
,
set
(
'conv2d'
),
PrecisionType
.
Bfloat16
,
)
]
keep_io_types_options
=
[
True
,
False
,
False
,
True
]
black_list_options
=
[
set
(),
set
(),
set
([
'conv2d'
]),
set
()]
def
test_convert_to_bf16
(
self
):
test_configs
=
zip
(
model
=
resnet50
(
True
)
mixed_precision_options
,
keep_io_types_options
,
black_list_options
net
=
to_static
(
model
,
input_spec
=
[
InputSpec
(
shape
=
[
None
,
3
,
224
,
224
],
name
=
'x'
)]
)
)
paddle
.
jit
.
save
(
net
,
'resnet50/inference'
)
for
mixed_precision
,
keep_io_types
,
black_list
in
test_configs
:
config
=
f
'mixed_precision=
{
mixed_precision
}
-keep_io_types=
{
keep_io_types
}
-black_list=
{
black_list
}
'
with
self
.
subTest
(
mixed_precision
=
mixed_precision
,
keep_io_types
=
keep_io_types
,
black_list
=
black_list
,
):
convert_to_mixed_precision
(
convert_to_mixed_precision
(
'resnet50/inference.pdmodel'
,
os
.
path
.
join
(
'resnet50/inference.pdiparams'
,
self
.
temp_dir
.
name
,
'resnet50/inference.pdmodel'
'mixed3/inference.pdmodel'
,
),
'mixed3/inference.pdiparams'
,
os
.
path
.
join
(
PrecisionType
.
Bfloat16
,
self
.
temp_dir
.
name
,
'resnet50/inference.pdiparams'
PlaceType
.
GPU
,
),
True
,
os
.
path
.
join
(
self
.
temp_dir
.
name
,
f
'
{
config
}
/inference.pdmodel'
),
os
.
path
.
join
(
self
.
temp_dir
.
name
,
f
'
{
config
}
/inference.pdiparams'
),
backend
=
PlaceType
.
GPU
,
mixed_precision
=
mixed_precision
,
keep_io_types
=
keep_io_types
,
black_list
=
black_list
,
)
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录