Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
ee4c51a3
P
Paddle
项目概览
OPTHREE
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ee4c51a3
编写于
12月 03, 2018
作者:
D
dongdaxiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine downpour sgd API with pslib
上级
c583fd34
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
1526 addition
and
25 deletion
+1526
-25
python/paddle/fluid/distributed/__init__.py
python/paddle/fluid/distributed/__init__.py
+0
-0
python/paddle/fluid/distributed/downpour.py
python/paddle/fluid/distributed/downpour.py
+14
-16
python/paddle/fluid/distributed/node.py
python/paddle/fluid/distributed/node.py
+21
-9
python/paddle/fluid/distributed/ps_pb2.py
python/paddle/fluid/distributed/ps_pb2.py
+1491
-0
未找到文件。
python/paddle/fluid/distributed/__init__.py
0 → 100644
浏览文件 @
ee4c51a3
python/paddle/fluid/distributed/downpour.py
浏览文件 @
ee4c51a3
import
paddle.fluid
as
fluid
import
pslib_pb2
as
pslib
from
.node
import
DownpourServer
from
.node
import
DownpourServer
from
.node
import
DownpourWorker
from
.node
import
DownpourWorker
from
..backward
import
append_backward
import
ps_pb2
as
pslib
from
paddle.fluid.distribute_lookup_table
import
find_distributed_lookup_table
from
paddle.fluid.distribute_lookup_table
import
find_distributed_lookup_table
from
google.protobuf
import
text_format
class
DownpourSGD
(
object
):
class
DownpourSGD
(
object
):
def
__init__
(
self
,
optimizer
=
opt
,
learning_rate
=
0.001
,
window
=
1
):
def
__init__
(
self
,
learning_rate
=
0.001
,
window
=
1
):
# todo(guru4elephant): if optimizer is not None, will warning here
# todo(guru4elephant): if optimizer is not None, will warning here
self
.
learning_rate_
=
opt
.
learning_rate
self
.
learning_rate_
=
learning_rate
self
.
window_
=
window
self
.
window_
=
window
def
minimize
(
self
,
loss
,
startup_program
=
None
,
def
minimize
(
self
,
loss
,
startup_program
=
None
,
parameter_list
=
None
,
no_grad_set
=
None
,
parameter_list
=
None
,
no_grad_set
=
None
,
prefetch_slots
=
None
,
prefetch_slots_emb
=
None
):
prefetch_slots
=
None
,
prefetch_slots_emb
=
None
):
params_grads
=
sorted
(
append_backward
(
loss
),
key
=
lambda
x
:
x
[
0
].
name
)
params_grads
=
sorted
(
append_backward
(
loss
),
key
=
lambda
x
:
x
[
0
].
name
)
table_name
=
f
lui
d_distributed_lookup_table
(
loss
.
block
.
program
)
table_name
=
f
in
d_distributed_lookup_table
(
loss
.
block
.
program
)
server
=
DownpourServer
()
server
=
DownpourServer
()
worker
=
DownpourWorker
()
worker
=
DownpourWorker
(
self
.
window_
)
server
.
add_sparse_table
(
0
,
learning_rate
,
server
.
add_sparse_table
(
0
,
learning_rate
,
prefetch_slots
,
prefetch_slots_emb
)
prefetch_slots
,
prefetch_slots_emb
)
server
.
add_dense_table
(
1
,
learning_rate
,
params
,
grads
)
server
.
add_dense_table
(
1
,
learning_rate
,
params
,
grads
)
worker
.
add_sparse_table
(
0
,
learning_rate
,
worker
.
add_sparse_table
(
0
,
learning_rate
,
prefetch_slots
,
prefetch_slots_emb
)
prefetch_slots
,
prefetch_slots_emb
)
worker
.
add_dense_table
(
1
,
learning_rate
,
params
,
grads
)
worker
.
add_dense_table
(
1
,
learning_rate
,
params
,
grads
)
ps_param
=
pslib
.
PSParameter
()
ps_param
=
pslib
.
PSParameter
()
ps_param
.
server_param
.
CopyFrom
(
server
.
get_desc
())
ps_param
.
server_param
.
CopyFrom
(
server
.
get_desc
())
ps_param
.
worker_param
.
CopyFrom
(
worker
.
get_desc
())
#
ps_param.worker_param.CopyFrom(worker.get_desc())
worker_skipped_ops
=
[
"lookup_table"
,
"lookup_table_grad"
]
worker_skipped_ops
=
[
"lookup_table"
,
"lookup_table_grad"
]
ps_param_str
=
text_format
.
MessageToString
(
ps_param
)
return
[
solver_desc
,
parallel_desc
]
return
[
ps_param_str
,
worker_skipped_ops
]
python/paddle/fluid/distributed/node.py
浏览文件 @
ee4c51a3
import
paddle.fluid
as
fluid
import
ps_pb2
as
pslib
import
pslib_pb2
as
pslib
class
Server
(
object
):
class
Server
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -13,11 +12,13 @@ class Worker(object):
...
@@ -13,11 +12,13 @@ class Worker(object):
class
DownpourServer
(
Server
):
class
DownpourServer
(
Server
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
server_
=
pslib
.
ServerParameter
().
downpour_server_param
#self.server_ = pslib.ServerParameter().downpour_server_param
self
.
server_
=
pslib
.
ServerParameter
()
def
add_sparse_table
(
self
,
table_id
,
learning_rate
,
def
add_sparse_table
(
self
,
table_id
,
learning_rate
,
slot_key
,
slot_value_var
,
slot_grad_var
):
slot_key
,
slot_value_var
,
slot_grad_var
):
table
=
self
.
server_
.
downpour_table_param
.
add
()
#table = self.server_.downpour_table_param.add()
table
=
self
.
server_
.
downpour_server_param
.
downpour_table_param
.
add
()
table
.
table_id
=
table_id
table
.
table_id
=
table_id
table
.
type
=
PS_SPARSE_TABLE
table
.
type
=
PS_SPARSE_TABLE
table
.
accessor
.
accessor_class
=
"DownpourFeatureValueAccessor"
table
.
accessor
.
accessor_class
=
"DownpourFeatureValueAccessor"
...
@@ -26,12 +27,14 @@ class DownpourServer(Server):
...
@@ -26,12 +27,14 @@ class DownpourServer(Server):
def
add_dense_table
(
self
,
table_id
,
learning_rate
,
def
add_dense_table
(
self
,
table_id
,
learning_rate
,
param_var
,
grad_var
):
param_var
,
grad_var
):
table
=
self
.
server_
.
downpour_table_param
.
add
()
#table = self.server_.downpour_table_param.add()
table
=
self
.
server_
.
downpour_server_param
.
downpour_table_param
.
add
()
table
.
table_id
=
table_id
table
.
table_id
=
table_id
table
.
type
=
PS_DENSE_TABLE
table
.
type
=
PS_DENSE_TABLE
table
.
accessor
.
accessor_class
=
"DownpourDenseValueAccessor"
table
.
accessor
.
accessor_class
=
"DownpourDenseValueAccessor"
table
.
accessor
.
sparse_sgd_param
.
learning_rate
=
learning_rate
table
.
accessor
.
sparse_sgd_param
.
learning_rate
=
learning_rate
table
.
accessor
.
fea_dim
=
reduce
(
lambda
x
,
y
:
x
.
shape
,
1
for
x
in
param_var
)
table
.
accessor
.
fea_dim
=
1
#table.accessor.fea_dim = reduce(lambda x, y: x.shape, 1 for x in param_var)
def
get_desc
(
self
):
def
get_desc
(
self
):
return
self
.
server_
return
self
.
server_
...
@@ -40,19 +43,28 @@ class DownpourServer(Server):
...
@@ -40,19 +43,28 @@ class DownpourServer(Server):
class
DownpourWorker
(
Worker
):
class
DownpourWorker
(
Worker
):
def
__init__
(
self
,
window
):
def
__init__
(
self
,
window
):
self
.
window
=
window
self
.
window
=
window
self
.
worker_
=
pslib
.
WorkerParameter
().
downpour_worker_param
#self.worker_ = pslib.WorkerParameter().downpour_worker_param
#self.worker_ = pslib.WorkerParameter()
self
.
worker_
=
pslib
.
DownpourTrainerParameter
()
#self.worker_.pull_dense_per_batch = window
#self.worker_.push_dense_per_batch = window
#self.worker_.downpour_worker_param.pull_dense_per_batch = window
#self.worker_.downpour_worker_param.push_dense_per_batch = window
self
.
worker_
.
pull_dense_per_batch
=
window
self
.
worker_
.
pull_dense_per_batch
=
window
self
.
worker_
.
push_dense_per_batch
=
window
self
.
worker_
.
push_dense_per_batch
=
window
print
(
self
.
worker_
)
def
add_sparse_table
(
self
,
table_id
,
def
add_sparse_table
(
self
,
table_id
,
slot_keys
,
slot_value_vars
,
slot_grad_vars
):
slot_keys
,
slot_value_vars
,
slot_grad_vars
):
table
=
self
.
worker_
.
sparse_table
.
add
()
#table = self.worker_.sparse_table.add()
table
=
self
.
worker_
.
downpour_worker_param
.
sparse_table
.
add
()
table
.
table_id
=
table_id
table
.
table_id
=
table_id
table
.
slot
.
extend
(
slot_keys
)
table
.
slot
.
extend
(
slot_keys
)
self
.
worker_
.
extend
([
grad
.
name
for
grad
in
slot_grad_vars
])
self
.
worker_
.
extend
([
grad
.
name
for
grad
in
slot_grad_vars
])
def
add_dense_table
(
self
,
table_id
,
param_vars
,
grad_vars
):
def
add_dense_table
(
self
,
table_id
,
param_vars
,
grad_vars
):
table
=
self
.
worker_
.
dense_table
.
add
()
#table = self.worker_.dense_table.add()
table
=
self
.
worker_
.
downpour_worker_param
.
dense_table
.
add
()
table
.
table_id
=
table_id
table
.
table_id
=
table_id
table
.
dense_variable_name
.
extend
([
p
.
name
for
p
in
param_vars
])
table
.
dense_variable_name
.
extend
([
p
.
name
for
p
in
param_vars
])
table
.
dense_gradient_variable_name
.
extend
([
g
.
name
for
g
in
grad_vars
])
table
.
dense_gradient_variable_name
.
extend
([
g
.
name
for
g
in
grad_vars
])
...
...
python/paddle/fluid/distributed/ps_pb2.py
0 → 100644
浏览文件 @
ee4c51a3
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录