Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
9368aec8
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9368aec8
编写于
4月 09, 2020
作者:
T
tangwei12
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug, cluster training
上级
2ebef2b7
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
35 addition
and
29 deletion
+35
-29
examples/ctr-dnn_train_cluster.yaml
examples/ctr-dnn_train_cluster.yaml
+2
-1
examples/train.py
examples/train.py
+2
-6
trainer/cluster_trainer.py
trainer/cluster_trainer.py
+4
-2
trainer/factory.py
trainer/factory.py
+11
-7
trainer/local_engine.py
trainer/local_engine.py
+15
-12
utils/envs.py
utils/envs.py
+1
-1
未找到文件。
examples/ctr-dnn_train_cluster.yaml
浏览文件 @
9368aec8
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
train
:
train
:
threads
:
12
threads
:
12
epochs
:
10
epochs
:
10
trainer
:
"
LocalClusterTraining"
trainer
:
"
ClusterTraining"
container
:
"
local"
pserver_num
:
2
pserver_num
:
2
trainer_num
:
2
trainer_num
:
2
...
...
examples/train.py
浏览文件 @
9368aec8
...
@@ -26,15 +26,11 @@
...
@@ -26,15 +26,11 @@
import
os
import
os
import
yaml
from
eleps.trainer.factory
import
TrainerFactory
from
eleps.trainer.factory
import
TrainerFactory
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
abs_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
abs_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
yaml
=
os
.
path
.
join
(
abs_dir
,
'ctr-dnn_train_cluster.yaml'
)
with
open
(
os
.
path
.
join
(
abs_dir
,
'ctr-dnn_train_single.yaml'
),
'r'
)
as
rb
:
trainer
=
TrainerFactory
.
create
(
yaml
)
global_config
=
yaml
.
load
(
rb
.
read
(),
Loader
=
yaml
.
FullLoader
)
trainer
=
TrainerFactory
.
create
(
global_config
)
trainer
.
run
()
trainer
.
run
()
trainer/cluster_trainer.py
浏览文件 @
9368aec8
...
@@ -42,10 +42,9 @@ class ClusterTrainerWithDataloader(TranspileTrainer):
...
@@ -42,10 +42,9 @@ class ClusterTrainerWithDataloader(TranspileTrainer):
class
ClusterTrainerWithDataset
(
TranspileTrainer
):
class
ClusterTrainerWithDataset
(
TranspileTrainer
):
def
processor_register
(
self
):
def
processor_register
(
self
):
role
=
PaddleCloudRoleMaker
()
role
=
PaddleCloudRoleMaker
()
fleet
.
init
(
role
)
fleet
.
init
(
role
)
if
role
.
is_server
():
if
fleet
.
is_server
():
self
.
regist_context_processor
(
'uninit'
,
self
.
instance
)
self
.
regist_context_processor
(
'uninit'
,
self
.
instance
)
self
.
regist_context_processor
(
'init_pass'
,
self
.
init
)
self
.
regist_context_processor
(
'init_pass'
,
self
.
init
)
self
.
regist_context_processor
(
'server_pass'
,
self
.
server
)
self
.
regist_context_processor
(
'server_pass'
,
self
.
server
)
...
@@ -74,6 +73,9 @@ class ClusterTrainerWithDataset(TranspileTrainer):
...
@@ -74,6 +73,9 @@ class ClusterTrainerWithDataset(TranspileTrainer):
return
strategy
return
strategy
def
init
(
self
,
context
):
def
init
(
self
,
context
):
print
(
"init pass"
)
self
.
model
.
input
()
self
.
model
.
input
()
self
.
model
.
net
()
self
.
model
.
net
()
self
.
metrics
=
self
.
model
.
metrics
()
self
.
metrics
=
self
.
model
.
metrics
()
...
...
trainer/factory.py
浏览文件 @
9368aec8
...
@@ -35,7 +35,7 @@ from eleps.trainer.single_trainer import SingleTrainerWithDataset
...
@@ -35,7 +35,7 @@ from eleps.trainer.single_trainer import SingleTrainerWithDataset
from
eleps.trainer.cluster_trainer
import
ClusterTrainerWithDataloader
from
eleps.trainer.cluster_trainer
import
ClusterTrainerWithDataloader
from
eleps.trainer.cluster_trainer
import
ClusterTrainerWithDataset
from
eleps.trainer.cluster_trainer
import
ClusterTrainerWithDataset
from
eleps.trainer.local_engine
import
local_l
aunch
from
eleps.trainer.local_engine
import
L
aunch
from
eleps.trainer.ctr_trainer
import
CtrPaddleTrainer
from
eleps.trainer.ctr_trainer
import
CtrPaddleTrainer
from
eleps.utils
import
envs
from
eleps.utils
import
envs
...
@@ -91,24 +91,26 @@ class TrainerFactory(object):
...
@@ -91,24 +91,26 @@ class TrainerFactory(object):
cluster_envs
[
"start_port"
]
=
envs
.
get_global_env
(
"train.start_port"
)
cluster_envs
[
"start_port"
]
=
envs
.
get_global_env
(
"train.start_port"
)
cluster_envs
[
"log_dir"
]
=
envs
.
get_global_env
(
"train.log_dirname"
)
cluster_envs
[
"log_dir"
]
=
envs
.
get_global_env
(
"train.log_dirname"
)
envs
.
pretty_print_envs
(
cluster_envs
,
(
"Cluster Global Envs"
,
"Value"
))
print
(
envs
.
pretty_print_envs
(
cluster_envs
,
(
"Cluster Global Envs"
,
"Value"
)
))
local_launch
(
cluster_envs
,
yaml_config
)
launch
=
Launch
(
cluster_envs
,
yaml_config
)
return
launch
@
staticmethod
@
staticmethod
def
create
(
config
):
def
create
(
config
):
_config
=
None
_config
=
None
if
os
.
path
.
exists
(
config
)
and
os
.
path
.
isfile
(
config
):
if
os
.
path
.
exists
(
config
)
and
os
.
path
.
isfile
(
config
):
with
open
(
config
,
'r'
)
as
rb
:
with
open
(
config
,
'r'
)
as
rb
:
_config
=
yaml
.
load
(
rb
.
read
())
_config
=
yaml
.
load
(
rb
.
read
()
,
Loader
=
yaml
.
FullLoader
)
else
:
else
:
raise
ValueError
(
"eleps's config only support yaml"
)
raise
ValueError
(
"eleps's config only support yaml"
)
envs
.
set_global_envs
(
_config
)
envs
.
set_global_envs
(
_config
)
train_mode
=
envs
.
get_global_env
(
"train.trainer"
)
mode
=
envs
.
get_global_env
(
"train.trainer"
)
container
=
envs
.
get_global_env
(
"train.container"
)
instance
=
str2bool
(
os
.
getenv
(
"CLUSTER_INSTANCE"
,
"0"
))
instance
=
str2bool
(
os
.
getenv
(
"CLUSTER_INSTANCE"
,
"0"
))
if
train_mode
==
"LocalClusterTraining
"
and
not
instance
:
if
mode
==
"ClusterTraining"
and
container
==
"local
"
and
not
instance
:
trainer
=
TrainerFactory
.
_build_engine
(
config
)
trainer
=
TrainerFactory
.
_build_engine
(
config
)
else
:
else
:
trainer
=
TrainerFactory
.
_build_trainer
(
_config
)
trainer
=
TrainerFactory
.
_build_trainer
(
_config
)
...
@@ -120,4 +122,6 @@ class TrainerFactory(object):
...
@@ -120,4 +122,6 @@ class TrainerFactory(object):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
!=
2
:
if
len
(
sys
.
argv
)
!=
2
:
raise
ValueError
(
"need a yaml file path argv"
)
raise
ValueError
(
"need a yaml file path argv"
)
TrainerFactory
.
create
(
sys
.
argv
[
1
])
trainer
=
TrainerFactory
.
create
(
sys
.
argv
[
1
])
trainer
.
run
()
trainer/local_engine.py
浏览文件 @
9368aec8
...
@@ -38,7 +38,8 @@ def start_procs(args, yaml):
...
@@ -38,7 +38,8 @@ def start_procs(args, yaml):
user_endpoints_ips
=
[
x
.
split
(
":"
)[
0
]
for
x
in
user_endpoints
.
split
(
","
)]
user_endpoints_ips
=
[
x
.
split
(
":"
)[
0
]
for
x
in
user_endpoints
.
split
(
","
)]
user_endpoints_port
=
[
x
.
split
(
":"
)[
1
]
for
x
in
user_endpoints
.
split
(
","
)]
user_endpoints_port
=
[
x
.
split
(
":"
)[
1
]
for
x
in
user_endpoints
.
split
(
","
)]
factory
=
os
.
path
.
join
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)),
"factory.py"
)
factory
=
"eleps.trainer.factory"
cmd
=
[
sys
.
executable
,
"-u"
,
"-m"
,
factory
,
yaml
]
for
i
in
range
(
server_num
):
for
i
in
range
(
server_num
):
current_env
.
update
({
current_env
.
update
({
...
@@ -48,15 +49,14 @@ def start_procs(args, yaml):
...
@@ -48,15 +49,14 @@ def start_procs(args, yaml):
"PADDLE_TRAINERS_NUM"
:
str
(
worker_num
),
"PADDLE_TRAINERS_NUM"
:
str
(
worker_num
),
"POD_IP"
:
user_endpoints_ips
[
i
]
"POD_IP"
:
user_endpoints_ips
[
i
]
})
})
cmd
=
[
sys
.
executable
,
"-u"
,
factory
,
yaml
]
if
args
.
log
_dir
is
not
None
:
if
logs
_dir
is
not
None
:
os
.
system
(
"mkdir -p {}"
.
format
(
logs_dir
))
os
.
system
(
"mkdir -p {}"
.
format
(
logs_dir
))
fn
=
open
(
"%s/server.%d"
%
(
logs_dir
,
i
),
"w"
)
fn
=
open
(
"%s/server.%d"
%
(
logs_dir
,
i
),
"w"
)
log_fns
.
append
(
fn
)
log_fns
.
append
(
fn
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
stdout
=
fn
,
stderr
=
fn
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
stdout
=
fn
,
stderr
=
fn
,
cwd
=
os
.
getcwd
()
)
else
:
else
:
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
cwd
=
os
.
getcwd
()
)
procs
.
append
(
proc
)
procs
.
append
(
proc
)
for
i
in
range
(
worker_num
):
for
i
in
range
(
worker_num
):
...
@@ -66,16 +66,14 @@ def start_procs(args, yaml):
...
@@ -66,16 +66,14 @@ def start_procs(args, yaml):
"TRAINING_ROLE"
:
"TRAINER"
,
"TRAINING_ROLE"
:
"TRAINER"
,
"PADDLE_TRAINER_ID"
:
str
(
i
)
"PADDLE_TRAINER_ID"
:
str
(
i
)
})
})
cmd
=
[
sys
.
executable
,
"-u"
,
args
.
training_script
]
+
args
.
training_script_args
if
args
.
log
_dir
is
not
None
:
if
logs
_dir
is
not
None
:
os
.
system
(
"mkdir -p {}"
.
format
(
logs_dir
))
os
.
system
(
"mkdir -p {}"
.
format
(
logs_dir
))
fn
=
open
(
"%s/worker.%d"
%
(
logs_dir
,
i
),
"w"
)
fn
=
open
(
"%s/worker.%d"
%
(
logs_dir
,
i
),
"w"
)
log_fns
.
append
(
fn
)
log_fns
.
append
(
fn
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
stdout
=
fn
,
stderr
=
fn
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
stdout
=
fn
,
stderr
=
fn
,
cwd
=
os
.
getcwd
()
)
else
:
else
:
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
)
proc
=
subprocess
.
Popen
(
cmd
,
env
=
current_env
,
cwd
=
os
.
getcwd
()
)
procs
.
append
(
proc
)
procs
.
append
(
proc
)
# only wait worker to finish here
# only wait worker to finish here
...
@@ -93,6 +91,11 @@ def start_procs(args, yaml):
...
@@ -93,6 +91,11 @@ def start_procs(args, yaml):
procs
[
i
].
terminate
()
procs
[
i
].
terminate
()
print
(
"all parameter server are killed"
,
file
=
sys
.
stderr
)
print
(
"all parameter server are killed"
,
file
=
sys
.
stderr
)
class
Launch
():
def
__init__
(
self
,
envs
,
trainer
):
self
.
envs
=
envs
self
.
trainer
=
trainer
def
run
(
self
):
start_procs
(
self
.
envs
,
self
.
trainer
)
def
local_launch
(
envs
,
trainer
):
start_procs
(
envs
,
trainer
)
utils/envs.py
浏览文件 @
9368aec8
...
@@ -48,7 +48,7 @@ def get_global_envs():
...
@@ -48,7 +48,7 @@ def get_global_envs():
return
global_envs
return
global_envs
def
pretty_print_envs
(
envs
,
header
):
def
pretty_print_envs
(
envs
,
header
=
None
):
spacing
=
5
spacing
=
5
max_k
=
45
max_k
=
45
max_v
=
20
max_v
=
20
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录