Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
7be79231
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
接近 2 年 前同步成功
通知
707
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7be79231
编写于
12月 18, 2017
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip multi-trainer
上级
1e549563
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
29 deletion
+47
-29
paddle/operators/detail/send_impl.cc
paddle/operators/detail/send_impl.cc
+6
-0
paddle/operators/detail/send_recv_impl.h
paddle/operators/detail/send_recv_impl.h
+1
-0
paddle/operators/recv_op.cc
paddle/operators/recv_op.cc
+3
-2
paddle/operators/send_op.cc
paddle/operators/send_op.cc
+23
-19
python/paddle/v2/fluid/distribute_transpiler.py
python/paddle/v2/fluid/distribute_transpiler.py
+14
-8
未找到文件。
paddle/operators/detail/send_impl.cc
浏览文件 @
7be79231
...
@@ -66,6 +66,12 @@ bool RPCClient::GetVariable(const framework::Scope& scope,
...
@@ -66,6 +66,12 @@ bool RPCClient::GetVariable(const framework::Scope& scope,
return
true
;
return
true
;
}
}
void
RPCClient
::
Wait
()
{
ClientContext
context
;
VoidMessage
call_msg
,
ret_msg
;
stub_
->
Wait
(
&
context
,
call_msg
,
&
ret_msg
);
}
}
// namespace detail
}
// namespace detail
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
paddle/operators/detail/send_recv_impl.h
浏览文件 @
7be79231
...
@@ -81,6 +81,7 @@ class RPCClient {
...
@@ -81,6 +81,7 @@ class RPCClient {
bool
SendVariable
(
const
framework
::
Scope
&
scope
,
const
std
::
string
&
inname
);
bool
SendVariable
(
const
framework
::
Scope
&
scope
,
const
std
::
string
&
inname
);
bool
GetVariable
(
const
framework
::
Scope
&
scope
,
const
std
::
string
&
outname
);
bool
GetVariable
(
const
framework
::
Scope
&
scope
,
const
std
::
string
&
outname
);
void
Wait
();
private:
private:
std
::
unique_ptr
<
SendRecvService
::
Stub
>
stub_
;
std
::
unique_ptr
<
SendRecvService
::
Stub
>
stub_
;
...
...
paddle/operators/recv_op.cc
浏览文件 @
7be79231
...
@@ -76,14 +76,14 @@ class RecvOp : public framework::OperatorBase {
...
@@ -76,14 +76,14 @@ class RecvOp : public framework::OperatorBase {
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
// FIXME(typhoonzero): no new scopes for every run.
// FIXME(typhoonzero): no new scopes for every run.
framework
::
Scope
&
recv_scope
=
scope
.
NewScope
();
framework
::
Scope
&
recv_scope
=
scope
.
NewScope
();
rpc_service_
.
SetScope
(
&
recv_scope
);
rpc_service_
->
SetScope
(
&
recv_scope
);
auto
param_list
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"ParamList"
);
auto
param_list
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"ParamList"
);
auto
grad_list
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"GradList"
);
auto
grad_list
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"GradList"
);
auto
trainer_count
=
Attr
<
int
>
(
"Trainers"
);
auto
trainer_count
=
Attr
<
int
>
(
"Trainers"
);
size_t
param_count
=
param_list
.
size
();
size_t
param_count
=
param_list
.
size
();
// TODO(typhoonzero): change this to a while_op for every cluster-batch.
// TODO(typhoonzero): change this to a while_op for every cluster-batch.
while
(
true
)
{
while
(
true
)
{
rpc_service_
.
Start
();
rpc_service_
->
Start
();
// Get from multiple trainers, we don't care about order in which
// Get from multiple trainers, we don't care about order in which
// the gradient arrives, just add suffix 0~n then average the gradient.
// the gradient arrives, just add suffix 0~n then average the gradient.
for
(
size_t
i
=
0
;
i
<
param_count
*
trainer_count
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
param_count
*
trainer_count
;
++
i
)
{
...
@@ -126,6 +126,7 @@ class RecvOp : public framework::OperatorBase {
...
@@ -126,6 +126,7 @@ class RecvOp : public framework::OperatorBase {
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
LOG
(
ERROR
)
<<
"run sub program error "
<<
e
.
what
();
LOG
(
ERROR
)
<<
"run sub program error "
<<
e
.
what
();
}
}
rpc_service_
->
Done
();
// for (size_t i = 0; i < param_count; ++i) {
// for (size_t i = 0; i < param_count; ++i) {
// auto *out_var = recv_scope.FindVar(param_list[i]);
// auto *out_var = recv_scope.FindVar(param_list[i]);
...
...
paddle/operators/send_op.cc
浏览文件 @
7be79231
...
@@ -34,34 +34,36 @@ class SendOp : public framework::OperatorBase {
...
@@ -34,34 +34,36 @@ class SendOp : public framework::OperatorBase {
const
framework
::
AttributeMap
&
attrs
)
const
framework
::
AttributeMap
&
attrs
)
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{
// init client when the operator is created at runtime.
// init client when the operator is created at runtime.
if
(
!
client_
)
{
std
::
vector
<
std
::
string
>
endpoints
=
std
::
string
endpoint
=
Attr
<
std
::
string
>
(
"endpoint
"
);
Attr
<
std
::
vector
<
std
::
string
>>
(
"endpoints
"
);
client_
.
reset
(
new
detail
::
RPCClient
(
for
(
auto
ep
:
endpoints
)
{
grpc
::
CreateChannel
(
endpoint
,
grpc
::
InsecureChannelCredentials
())));
client_map_
[
ep
].
reset
(
new
detail
::
RPCClient
(
// TODO(typhoonzero): how to call InitVariables
grpc
::
CreateChannel
(
ep
,
grpc
::
InsecureChannelCredentials
())));
}
}
}
}
void
Run
(
const
framework
::
Scope
&
scope
,
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
auto
ins
=
Inputs
(
"X"
);
auto
ins
=
Inputs
(
"X"
);
// TODO(typhoonzero): currently it's non-blocking,
std
::
vector
<
std
::
string
>
epmap
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"epmap"
);
//
should block until server responds
.
//
TODO(typhoonzero): use async calls to send multiple variable asyncly
.
for
(
auto
in
:
ins
)
{
for
(
size_t
i
=
0
;
i
<
ins
.
size
();
++
i
)
{
bool
ret
=
client_
->
SendVariable
(
scope
,
in
);
bool
ret
=
client_
map_
[
epmap
[
i
]]
->
SendVariable
(
scope
,
ins
[
i
]
);
if
(
!
ret
)
{
if
(
!
ret
)
{
LOG
(
ERROR
)
<<
"send variable error
"
;
LOG
(
ERROR
)
<<
"send variable error
: "
<<
ins
[
i
]
;
}
}
}
}
for
(
auto
in
:
ins
)
{
client_map_
[
0
]
->
Wait
();
// TODO(typhoonzero): support async optimization
bool
ret
=
client_
->
GetVariable
(
scope
);
for
(
size_t
i
=
0
;
i
<
ins
.
size
();
++
i
)
{
bool
ret
=
client_map_
[
epmap
[
i
]]
->
GetVariable
(
scope
,
ins
[
i
]);
if
(
!
ret
)
{
if
(
!
ret
)
{
LOG
(
ERROR
)
<<
"GetVariable error
"
;
LOG
(
ERROR
)
<<
"GetVariable error
: "
<<
ins
[
i
]
;
}
}
}
}
}
}
protected:
protected:
std
::
shared_ptr
<
detail
::
RPCClient
>
client_
{
nullptr
};
mutable
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
detail
::
RPCClient
>>
client_map_
;
};
};
class
SendOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
class
SendOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
@@ -74,11 +76,13 @@ Recv operator
...
@@ -74,11 +76,13 @@ Recv operator
This operator will recv tensor from send_op
This operator will recv tensor from send_op
)DOC"
);
)DOC"
);
AddAttr
<
std
::
string
>
(
"endpoint"
,
AddAttr
<
std
::
vector
<
std
::
string
>>
(
"endpoints"
,
"(string, default 127.0.0.1:6164)"
"(string vector, default 127.0.0.1:6164)"
"IP address to listen on."
)
"Server endpoints to send variables to."
);
.
SetDefault
(
"127.0.0.1:6164"
)
AddAttr
<
std
::
vector
<
std
::
string
>>
(
"epmap"
,
.
AddCustomChecker
([](
const
std
::
string
&
ip
)
{
return
!
ip
.
empty
();
});
"(string vector, default 127.0.0.1:6164)"
"Server endpoints in the order of input "
"variables for mapping"
);
}
}
};
};
...
...
python/paddle/v2/fluid/distribute_transpiler.py
浏览文件 @
7be79231
...
@@ -145,14 +145,20 @@ class DistributeTranspiler:
...
@@ -145,14 +145,20 @@ class DistributeTranspiler:
pserver_endpoints
=
kwargs
[
"pservers"
].
split
(
","
)
pserver_endpoints
=
kwargs
[
"pservers"
].
split
(
","
)
self
.
param_grad_map
=
split_method
(
params_and_grads
,
pserver_endpoints
)
self
.
param_grad_map
=
split_method
(
params_and_grads
,
pserver_endpoints
)
for
ep
in
pserver_endpoints
:
send_op_ordered_inputs
=
[]
# FIXME(typhoonzero): send to different servers can run in parrallel.
epmap
=
[]
send_op
=
program
.
global_block
().
append_op
(
for
ep
,
v
in
self
.
param_grad_map
.
iteritems
():
type
=
"send"
,
send_op_ordered_inputs
.
extend
(
v
[
"grads"
])
inputs
=
{
"X"
:
self
.
param_grad_map
[
ep
][
"grads"
]
for
i
in
v
:
},
# inputs is a list of tensors to be send
epmap
.
append
(
ep
)
outputs
=
{},
attrs
=
{
"endpoint"
:
ep
})
send_op
=
program
.
global_block
().
append_op
(
type
=
"send"
,
inputs
=
{
"X"
:
send_op_ordered_inputs
},
# inputs is a list of tensors to be send
outputs
=
{},
attrs
=
{
"endpoints"
:
pserver_endpoints
,
"epmap"
:
epmap
})
def
_create_var_for_trainers
(
self
,
block
,
var
,
trainers
):
def
_create_var_for_trainers
(
self
,
block
,
var
,
trainers
):
var_list
=
[]
var_list
=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录