Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0e850c74
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
0e850c74
编写于
1月 23, 2018
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP
上级
bcc67401
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
11 deletion
+33
-11
python/paddle/v2/fluid/layers/io.py
python/paddle/v2/fluid/layers/io.py
+17
-6
python/paddle/v2/fluid/tests/test_recv_op.py
python/paddle/v2/fluid/tests/test_recv_op.py
+16
-5
未找到文件。
python/paddle/v2/fluid/layers/io.py
浏览文件 @
0e850c74
...
...
@@ -14,8 +14,10 @@
from
..
import
core
from
..layer_helper
import
LayerHelper
from
control_flow
import
BlockGuard
from
..layer_helper
import
LayerHelper
__all__
=
[
'data'
]
__all__
=
[
'data'
,
'BlockGuardServ'
,
'ListenAndServ'
,
'Send'
]
def
data
(
name
,
...
...
@@ -105,12 +107,14 @@ class ListenAndServ(object):
which can receive variables from clients and run a block.
"""
def
__init__
(
self
,
endpoint
,
fan_in
=
1
):
self
.
helper
=
LayerHelper
(
"recv"
,
name
=
name
)
def
__init__
(
self
,
endpoint
,
fan_in
=
1
,
optimizer_mode
=
True
):
self
.
helper
=
LayerHelper
(
"recv"
)
self
.
inputs
=
[]
self
.
outputs
=
[]
self
.
endpoint
=
endpoint
self
.
fan_in
=
fan_in
# FIXME(typhoonzero): Add this switch is stupid
self
.
optimizer_mode
=
optimizer_mode
def
do
(
self
):
return
BlockGuardServ
(
self
)
...
...
@@ -124,9 +128,16 @@ class ListenAndServ(object):
grads
=
list
()
for
op
in
current_block
.
ops
:
# FIXME(typhoonzero): op.inputs is None if it's cloned.
if
"Grad"
in
op
.
inputs
and
"Param"
in
op
.
inputs
:
params
.
append
(
op
.
inputs
[
"Param"
].
name
)
grads
.
append
(
op
.
inputs
[
"Grad"
].
name
)
if
self
.
optimizer_mode
:
if
"Grad"
in
op
.
inputs
and
"Param"
in
op
.
inputs
:
params
.
append
(
op
.
inputs
[
"Param"
].
name
)
grads
.
append
(
op
.
inputs
[
"Grad"
].
name
)
else
:
# simple recv mode, recv operators inputs.
for
iname
in
op
.
input_names
:
for
in_var_name
in
op
.
input
(
iname
):
params
.
append
(
parent_block
.
var
(
name
))
grads
.
append
(
parent_block
.
var
(
name
))
return
params
,
grads
...
...
python/paddle/v2/fluid/tests/test_recv_op.py
浏览文件 @
0e850c74
...
...
@@ -17,20 +17,27 @@ import unittest
import
paddle.v2.fluid
as
fluid
import
paddle.v2.fluid.layers
as
layers
import
numpy
import
threading
class
TestRecvOp
(
unittest
.
TestCase
):
def
run_test
(
self
):
def
test_send
(
self
):
# Run init_serv in a thread
pass
place
=
fluid
.
CPUPlace
()
t
=
threading
.
Thread
(
target
=
self
.
init_serv
,
args
=
(
place
,
))
t
.
start
()
self
.
init_client
(
place
)
t
.
join
()
def
init_serv
(
self
,
place
):
main
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main
):
x
=
layers
.
data
(
shape
=
[
32
,
32
],
dtype
=
'float32'
,
name
=
'X'
)
serv
=
fluid
.
ListenAndServ
(
"127.0.0.1:6174"
)
i
=
fluid
.
initializer
.
Constant
(
value
=
1.0
)
y
=
i
(
x
,
main
.
global_block
())
serv
=
layers
.
ListenAndServ
(
"127.0.0.1:6174"
)
with
serv
.
do
():
layers
.
scale
(
input
=
x
,
scale
=
1
0
)
layers
.
scale
(
input
=
y
,
scale
=
10.
0
)
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
main
)
...
...
@@ -38,8 +45,12 @@ class TestRecvOp(unittest.TestCase):
main
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main
):
x
=
layers
.
data
(
shape
=
[
32
,
32
],
dtype
=
'float32'
,
name
=
'X'
)
i
=
fluid
.
initializer
.
Constant
(
x
=
1.0
)
i
=
fluid
.
initializer
.
Constant
(
value
=
1.0
)
i
(
x
,
main
.
global_block
())
layers
.
Send
(
"127.0.0.1:6174"
,
[
x
],
[
x
])
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
main
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录