Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
308491a9
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
提交
308491a9
编写于
12月 11, 2017
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update for simple dist train
上级
1c1fae60
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
20 addition
and
17 deletion
+20
-17
paddle/operators/send_op.cc
paddle/operators/send_op.cc
+7
-7
python/paddle/v2/fluid/distribute_planner.py
python/paddle/v2/fluid/distribute_planner.py
+2
-2
python/paddle/v2/fluid/executor.py
python/paddle/v2/fluid/executor.py
+4
-3
python/paddle/v2/fluid/framework.py
python/paddle/v2/fluid/framework.py
+2
-1
python/paddle/v2/fluid/optimizer.py
python/paddle/v2/fluid/optimizer.py
+1
-1
python/paddle/v2/fluid/tests/book/test_recognize_digits_conv_dist.py
...le/v2/fluid/tests/book/test_recognize_digits_conv_dist.py
+4
-3
未找到文件。
paddle/operators/send_op.cc
浏览文件 @
308491a9
...
@@ -43,15 +43,16 @@ class SendOp : public framework::OperatorBase {
...
@@ -43,15 +43,16 @@ class SendOp : public framework::OperatorBase {
}
}
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
iname
=
Input
(
"X"
);
auto
ins
=
Inputs
(
"X"
);
auto
oname
=
Output
(
"Out"
);
// TODO(typhoonzero): currently it's non-blocking,
// TODO(typhoonzero): currently it's non-blocking,
// should block until server responds.
// should block until server responds.
bool
ret
=
client_
->
SendVariable
(
scope
,
iname
,
oname
);
for
(
auto
in
:
ins
)
{
bool
ret
=
client_
->
SendVariable
(
scope
,
in
,
in
);
if
(
!
ret
)
{
if
(
!
ret
)
{
LOG
(
ERROR
)
<<
"send variable error"
;
LOG
(
ERROR
)
<<
"send variable error"
;
}
}
}
}
}
protected:
protected:
std
::
shared_ptr
<
detail
::
RPCClient
>
client_
{
nullptr
};
std
::
shared_ptr
<
detail
::
RPCClient
>
client_
{
nullptr
};
...
@@ -61,8 +62,7 @@ class SendOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -61,8 +62,7 @@ class SendOpMaker : public framework::OpProtoAndCheckerMaker {
public:
public:
SendOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
SendOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"(Tensor) Input tensor to be saved"
);
AddInput
(
"X"
,
"(Tensor) Input tensor to be send"
).
AsDuplicable
();
AddOutput
(
"Out"
,
"(Tensor) Output fetched from server"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Recv operator
Recv operator
...
...
python/paddle/v2/fluid/distribute_planner.py
浏览文件 @
308491a9
...
@@ -30,7 +30,7 @@ def hash_name_to_server(params_grads, pserver_endpoints):
...
@@ -30,7 +30,7 @@ def hash_name_to_server(params_grads, pserver_endpoints):
def
round_robin
(
parameters
,
pserver_endpoints
):
def
round_robin
(
parameters
,
pserver_endpoints
):
assert
(
len
(
parameters
)
<
len
(
pserver_endpoints
))
assert
(
len
(
parameters
)
>
len
(
pserver_endpoints
))
param_grad_map
=
dict
()
param_grad_map
=
dict
()
pserver_idx
=
0
pserver_idx
=
0
...
@@ -44,6 +44,6 @@ def round_robin(parameters, pserver_endpoints):
...
@@ -44,6 +44,6 @@ def round_robin(parameters, pserver_endpoints):
param_grad_map
[
server_for_param
][
"grads"
].
append
(
param
)
param_grad_map
[
server_for_param
][
"grads"
].
append
(
param
)
pserver_idx
+=
1
pserver_idx
+=
1
if
pserver_idx
>
len
(
pserver_endpoints
):
if
pserver_idx
>
=
len
(
pserver_endpoints
):
pserver_idx
=
0
pserver_idx
=
0
return
param_grad_map
return
param_grad_map
python/paddle/v2/fluid/executor.py
浏览文件 @
308491a9
...
@@ -50,7 +50,7 @@ class Executor(object):
...
@@ -50,7 +50,7 @@ class Executor(object):
self
.
executor
=
core
.
Executor
(
act_places
)
self
.
executor
=
core
.
Executor
(
act_places
)
self
.
places
=
places
self
.
places
=
places
def
optimize
(
self
,
optimize_ops
,
program
=
None
,
**
kwargs
):
def
optimize
(
self
,
optimize_ops
,
p
arams_grads
,
p
rogram
=
None
,
**
kwargs
):
"""
"""
optimize the program for different runtime environment
optimize the program for different runtime environment
...
@@ -67,7 +67,8 @@ class Executor(object):
...
@@ -67,7 +67,8 @@ class Executor(object):
program
=
default_main_program
()
program
=
default_main_program
()
if
kwargs
.
has_key
(
"pservers"
):
if
kwargs
.
has_key
(
"pservers"
):
return
self
.
_optimize_distributed
(
optimize_ops
,
program
,
**
kwargs
)
return
self
.
_optimize_distributed
(
optimize_ops
,
program
,
params_grads
,
**
kwargs
)
def
_optimize_distributed
(
self
,
optimize_ops
,
program
,
params_and_grads
,
def
_optimize_distributed
(
self
,
optimize_ops
,
program
,
params_and_grads
,
**
kwargs
):
**
kwargs
):
...
@@ -92,7 +93,7 @@ class Executor(object):
...
@@ -92,7 +93,7 @@ class Executor(object):
type
=
"send"
,
type
=
"send"
,
inputs
=
{
"X"
:
self
.
param_grad_map
[
ep
][
"params"
]
inputs
=
{
"X"
:
self
.
param_grad_map
[
ep
][
"params"
]
},
# inputs is a list of tensors to be send
},
# inputs is a list of tensors to be send
outputs
=
{
"Out"
:
self
.
param_grad_map
[
ep
][
"params"
]
},
outputs
=
{},
attrs
=
{
"endpoint"
:
ep
})
attrs
=
{
"endpoint"
:
ep
})
# -------------- generate optimize sub program --------------
# -------------- generate optimize sub program --------------
self
.
optimize_sub_program
=
Program
()
self
.
optimize_sub_program
=
Program
()
...
...
python/paddle/v2/fluid/framework.py
浏览文件 @
308491a9
...
@@ -304,7 +304,8 @@ class Operator(object):
...
@@ -304,7 +304,8 @@ class Operator(object):
self
.
desc
.
check_attrs
()
self
.
desc
.
check_attrs
()
no_kernel_op_set
=
{
no_kernel_op_set
=
{
'feed'
,
'fetch'
,
'save'
,
'load'
,
'recurrent'
,
'feed'
,
'fetch'
,
'save'
,
'load'
,
'recurrent'
,
'rnn_memory_helper_grad'
,
'conditional_block'
,
'while'
'rnn_memory_helper_grad'
,
'conditional_block'
,
'while'
,
'send'
,
'recv'
}
}
if
type
not
in
no_kernel_op_set
:
if
type
not
in
no_kernel_op_set
:
self
.
desc
.
infer_var_type
(
self
.
block
.
desc
)
self
.
desc
.
infer_var_type
(
self
.
block
.
desc
)
...
...
python/paddle/v2/fluid/optimizer.py
浏览文件 @
308491a9
...
@@ -202,7 +202,7 @@ class Optimizer(object):
...
@@ -202,7 +202,7 @@ class Optimizer(object):
params_grads
=
append_regularization_ops
(
params_grads
)
params_grads
=
append_regularization_ops
(
params_grads
)
optimize_ops
=
self
.
create_optimization_pass
(
params_grads
,
loss
,
optimize_ops
=
self
.
create_optimization_pass
(
params_grads
,
loss
,
startup_program
)
startup_program
)
return
optimize_ops
return
optimize_ops
,
params_grads
class
SGDOptimizer
(
Optimizer
):
class
SGDOptimizer
(
Optimizer
):
...
...
python/paddle/v2/fluid/tests/book/test_recognize_digits_conv_dist.py
浏览文件 @
308491a9
...
@@ -2,6 +2,7 @@ from __future__ import print_function
...
@@ -2,6 +2,7 @@ from __future__ import print_function
import
numpy
as
np
import
numpy
as
np
import
paddle.v2
as
paddle
import
paddle.v2
as
paddle
import
paddle.v2.fluid
as
fluid
import
paddle.v2.fluid
as
fluid
import
os
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
images
=
fluid
.
layers
.
data
(
name
=
'pixel'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
...
@@ -24,7 +25,7 @@ predict = fluid.layers.fc(input=conv_pool_2, size=10, act="softmax")
...
@@ -24,7 +25,7 @@ predict = fluid.layers.fc(input=conv_pool_2, size=10, act="softmax")
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
predict
,
label
=
label
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.01
)
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.01
)
optimizer
.
minimize
(
avg_cost
)
optimize
_ops
,
params_grads
=
optimize
r
.
minimize
(
avg_cost
)
accuracy
=
fluid
.
evaluator
.
Accuracy
(
input
=
predict
,
label
=
label
)
accuracy
=
fluid
.
evaluator
.
Accuracy
(
input
=
predict
,
label
=
label
)
...
@@ -38,10 +39,10 @@ train_reader = paddle.batch(
...
@@ -38,10 +39,10 @@ train_reader = paddle.batch(
place
=
fluid
.
CPUPlace
()
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
exe
=
fluid
.
Executor
(
place
)
exe
.
optimize
(
pservers
=
"127.0.0.1:6174"
,
trainers
=
1
)
exe
.
optimize
(
optimize_ops
,
params_grads
,
pservers
=
"127.0.0.1:6174"
,
trainers
=
1
)
pserver_endpoint
=
os
.
getenv
(
"PSERVER"
)
pserver_endpoint
=
os
.
getenv
(
"PSERVER"
)
if
is_pserver
:
if
pserver_endpoint
:
pserver_prog
=
exe
.
get_pserver_program
(
pserver_endpoint
)
pserver_prog
=
exe
.
get_pserver_program
(
pserver_endpoint
)
exe
.
run
(
fluid
.
default_startup_program
())
exe
.
run
(
fluid
.
default_startup_program
())
exe
.
run
(
pserver_prog
)
exe
.
run
(
pserver_prog
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录