Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
62fd1927
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
62fd1927
编写于
12月 18, 2020
作者:
W
WangXi
提交者:
GitHub
12月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimizer fleet distributed strategy (#500)
上级
7b15ef1a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
44 deletion
+60
-44
tools/static/program.py
tools/static/program.py
+60
-44
未找到文件。
tools/static/program.py
浏览文件 @
62fd1927
...
...
@@ -288,6 +288,60 @@ def create_optimizer(config):
opt
=
OptimizerBuilder
(
config
,
**
opt_config
)
return
opt
(
lr
),
lr
def
create_strategy
(
config
):
"""
Create build strategy and exec strategy.
Args:
config(dict): config
Returns:
build_strategy: build strategy
exec_strategy: exec strategy
"""
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
exec_strategy
.
num_threads
=
1
exec_strategy
.
num_iteration_per_drop_scope
=
10000
if
config
.
get
(
'use_pure_fp16'
,
False
)
else
10
fuse_op
=
config
.
get
(
'use_amp'
,
False
)
or
config
.
get
(
'use_pure_fp16'
,
False
)
fuse_bn_act_ops
=
config
.
get
(
'fuse_bn_act_ops'
,
fuse_op
)
fuse_elewise_add_act_ops
=
config
.
get
(
'fuse_elewise_add_act_ops'
,
fuse_op
)
fuse_bn_add_act_ops
=
config
.
get
(
'fuse_bn_add_act_ops'
,
fuse_op
)
enable_addto
=
config
.
get
(
'enable_addto'
,
fuse_op
)
try
:
build_strategy
.
fuse_bn_act_ops
=
fuse_bn_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse batch_norm and activation_op."
)
try
:
build_strategy
.
fuse_elewise_add_act_ops
=
fuse_elewise_add_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse elewise_add_act and activation_op."
)
try
:
build_strategy
.
fuse_bn_add_act_ops
=
fuse_bn_add_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle 2.0-rc or higher is "
"required when you want to enable fuse_bn_add_act_ops strategy."
)
try
:
build_strategy
.
enable_addto
=
enable_addto
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle 2.0-rc or higher is "
"required when you want to enable addto strategy."
)
return
build_strategy
,
exec_strategy
def
dist_optimizer
(
config
,
optimizer
):
"""
...
...
@@ -300,14 +354,15 @@ def dist_optimizer(config, optimizer):
Returns:
optimizer: a distributed optimizer
"""
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
exec_strategy
.
num_threads
=
3
exec_strategy
.
num_iteration_per_drop_scope
=
10
build_strategy
,
exec_strategy
=
create_strategy
(
config
)
dist_strategy
=
DistributedStrategy
()
dist_strategy
.
execution_strategy
=
exec_strategy
dist_strategy
.
build_strategy
=
build_strategy
dist_strategy
.
nccl_comm_num
=
1
dist_strategy
.
fuse_all_reduce_ops
=
True
dist_strategy
.
execution_strategy
=
exec_strategy
dist_strategy
.
fuse_grad_size_in_MB
=
16
optimizer
=
fleet
.
distributed_optimizer
(
optimizer
,
strategy
=
dist_strategy
)
return
optimizer
...
...
@@ -399,46 +454,7 @@ def compile(config, program, loss_name=None, share_prog=None):
Returns:
compiled_program(): a compiled program
"""
build_strategy
=
paddle
.
static
.
BuildStrategy
()
exec_strategy
=
paddle
.
static
.
ExecutionStrategy
()
exec_strategy
.
num_threads
=
1
exec_strategy
.
num_iteration_per_drop_scope
=
10000
if
config
.
get
(
'use_pure_fp16'
,
False
)
else
10
fuse_op
=
config
.
get
(
'use_amp'
,
False
)
or
config
.
get
(
'use_pure_fp16'
,
False
)
fuse_bn_act_ops
=
config
.
get
(
'fuse_bn_act_ops'
,
fuse_op
)
fuse_elewise_add_act_ops
=
config
.
get
(
'fuse_elewise_add_act_ops'
,
fuse_op
)
fuse_bn_add_act_ops
=
config
.
get
(
'fuse_bn_add_act_ops'
,
fuse_op
)
enable_addto
=
config
.
get
(
'enable_addto'
,
fuse_op
)
try
:
build_strategy
.
fuse_bn_act_ops
=
fuse_bn_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse batch_norm and activation_op."
)
try
:
build_strategy
.
fuse_elewise_add_act_ops
=
fuse_elewise_add_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle version 1.7.0 or higher is "
"required when you want to fuse elewise_add_act and activation_op."
)
try
:
build_strategy
.
fuse_bn_add_act_ops
=
fuse_bn_add_act_ops
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle 2.0-rc or higher is "
"required when you want to enable fuse_bn_add_act_ops strategy."
)
try
:
build_strategy
.
enable_addto
=
enable_addto
except
Exception
as
e
:
logger
.
info
(
"PaddlePaddle 2.0-rc or higher is "
"required when you want to enable addto strategy."
)
build_strategy
,
exec_strategy
=
create_strategy
(
config
)
compiled_program
=
paddle
.
static
.
CompiledProgram
(
program
).
with_data_parallel
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录