Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
95e90aa1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
95e90aa1
编写于
10月 20, 2019
作者:
1
123malin
提交者:
GitHub
10月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test=develop, add communicator_is_sgd_optimizer flag (#20677)
* test=develop, communicator_is_sgd_optimizer flags
上级
74a28f5e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
33 addition
and
9 deletion
+33
-9
paddle/fluid/operators/distributed/communicator.cc
paddle/fluid/operators/distributed/communicator.cc
+2
-0
paddle/fluid/operators/distributed/communicator.h
paddle/fluid/operators/distributed/communicator.h
+17
-5
paddle/fluid/operators/distributed/communicator_test.cc
paddle/fluid/operators/distributed/communicator_test.cc
+1
-2
paddle/fluid/operators/distributed/parameter_send.cc
paddle/fluid/operators/distributed/parameter_send.cc
+7
-0
paddle/fluid/platform/flags.cc
paddle/fluid/platform/flags.cc
+3
-1
python/paddle/fluid/__init__.py
python/paddle/fluid/__init__.py
+1
-0
python/paddle/fluid/tests/unittests/test_dist_ctr.py
python/paddle/fluid/tests/unittests/test_dist_ctr.py
+2
-1
未找到文件。
paddle/fluid/operators/distributed/communicator.cc
浏览文件 @
95e90aa1
...
@@ -89,6 +89,8 @@ void AsyncCommunicator::InitImpl(const RpcCtxMap &send_varname_to_ctx,
...
@@ -89,6 +89,8 @@ void AsyncCommunicator::InitImpl(const RpcCtxMap &send_varname_to_ctx,
VLOG
(
0
)
<<
"communicator_fake_rpc: "
<<
FLAGS_communicator_fake_rpc
;
VLOG
(
0
)
<<
"communicator_fake_rpc: "
<<
FLAGS_communicator_fake_rpc
;
VLOG
(
0
)
<<
"communicator_merge_sparse_grad: "
VLOG
(
0
)
<<
"communicator_merge_sparse_grad: "
<<
FLAGS_communicator_merge_sparse_grad
;
<<
FLAGS_communicator_merge_sparse_grad
;
VLOG
(
0
)
<<
"communicator_is_sgd_optimizer: "
<<
FLAGS_communicator_is_sgd_optimizer
;
if
(
send_varname_to_ctx
.
size
()
==
0
)
{
if
(
send_varname_to_ctx
.
size
()
==
0
)
{
VLOG
(
0
)
<<
"nothing need to be send, will not start send_thread"
;
VLOG
(
0
)
<<
"nothing need to be send, will not start send_thread"
;
...
...
paddle/fluid/operators/distributed/communicator.h
浏览文件 @
95e90aa1
...
@@ -24,6 +24,7 @@ limitations under the License. */
...
@@ -24,6 +24,7 @@ limitations under the License. */
#include <unordered_set>
#include <unordered_set>
#include <utility>
#include <utility>
#include <vector>
#include <vector>
#include "gflags/gflags.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/variable.h"
#include "paddle/fluid/framework/variable.h"
...
@@ -37,6 +38,8 @@ limitations under the License. */
...
@@ -37,6 +38,8 @@ limitations under the License. */
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/place.h"
DECLARE_bool
(
communicator_is_sgd_optimizer
);
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
namespace
distributed
{
namespace
distributed
{
...
@@ -138,8 +141,10 @@ inline void MergeVars(const std::string& var_name,
...
@@ -138,8 +141,10 @@ inline void MergeVars(const std::string& var_name,
auto
in
=
EigenVector
<
float
>::
Flatten
(
in_t
);
auto
in
=
EigenVector
<
float
>::
Flatten
(
in_t
);
result
.
device
(
*
cpu_ctx
.
eigen_device
())
=
result
+
in
;
result
.
device
(
*
cpu_ctx
.
eigen_device
())
=
result
+
in
;
}
}
result
.
device
(
*
cpu_ctx
.
eigen_device
())
=
if
(
!
FLAGS_communicator_is_sgd_optimizer
)
{
result
/
static_cast
<
float
>
(
vars
.
size
());
result
.
device
(
*
cpu_ctx
.
eigen_device
())
=
result
/
static_cast
<
float
>
(
vars
.
size
());
}
}
else
if
(
var0
->
IsType
<
framework
::
SelectedRows
>
())
{
}
else
if
(
var0
->
IsType
<
framework
::
SelectedRows
>
())
{
auto
&
slr0
=
var0
->
Get
<
framework
::
SelectedRows
>
();
auto
&
slr0
=
var0
->
Get
<
framework
::
SelectedRows
>
();
auto
*
out_slr
=
out_var
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
*
out_slr
=
out_var
->
GetMutable
<
framework
::
SelectedRows
>
();
...
@@ -151,9 +156,16 @@ inline void MergeVars(const std::string& var_name,
...
@@ -151,9 +156,16 @@ inline void MergeVars(const std::string& var_name,
inputs
.
push_back
(
&
var
->
Get
<
framework
::
SelectedRows
>
());
inputs
.
push_back
(
&
var
->
Get
<
framework
::
SelectedRows
>
());
}
}
auto
dev_ctx
=
paddle
::
platform
::
CPUDeviceContext
();
auto
dev_ctx
=
paddle
::
platform
::
CPUDeviceContext
();
math
::
scatter
::
MergeAverage
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
if
(
FLAGS_communicator_is_sgd_optimizer
)
{
merge_average
;
math
::
scatter
::
MergeAdd
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
merge_average
(
dev_ctx
,
inputs
,
out_slr
);
merge_add
;
merge_add
(
dev_ctx
,
inputs
,
out_slr
);
}
else
{
math
::
scatter
::
MergeAverage
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
merge_average
;
merge_average
(
dev_ctx
,
inputs
,
out_slr
);
}
VLOG
(
3
)
<<
"merge "
<<
var_name
<<
" SelectedRows height: "
<<
slr0
.
height
()
VLOG
(
3
)
<<
"merge "
<<
var_name
<<
" SelectedRows height: "
<<
slr0
.
height
()
<<
" dims: "
<<
slr0
.
value
().
dims
();
<<
" dims: "
<<
slr0
.
value
().
dims
();
}
else
{
}
else
{
...
...
paddle/fluid/operators/distributed/communicator_test.cc
浏览文件 @
95e90aa1
...
@@ -42,7 +42,6 @@ TEST(communicator, merge_lod_tensors) {
...
@@ -42,7 +42,6 @@ TEST(communicator, merge_lod_tensors) {
}
}
out_value
+=
static_cast
<
float
>
(
i
);
out_value
+=
static_cast
<
float
>
(
i
);
}
}
out_value
=
out_value
/
10.0
;
const
std
::
string
out_name
=
"Out"
;
const
std
::
string
out_name
=
"Out"
;
std
::
unique_ptr
<
framework
::
Scope
>
scope
;
std
::
unique_ptr
<
framework
::
Scope
>
scope
;
scope
.
reset
(
new
framework
::
Scope
());
scope
.
reset
(
new
framework
::
Scope
());
...
@@ -96,7 +95,7 @@ TEST(communicator, merge_selected_rows) {
...
@@ -96,7 +95,7 @@ TEST(communicator, merge_selected_rows) {
std
::
vector
<
float
>
out_values
;
std
::
vector
<
float
>
out_values
;
out_values
.
reserve
(
10
);
out_values
.
reserve
(
10
);
for
(
auto
i
=
0
;
i
<
10
;
++
i
)
{
for
(
auto
i
=
0
;
i
<
10
;
++
i
)
{
out_values
.
push_back
(
static_cast
<
float
>
(
(
i
*
(
10
-
i
))
/
10.0
));
out_values
.
push_back
(
static_cast
<
float
>
(
i
*
(
10
-
i
)
));
}
}
for
(
auto
i
=
0
;
i
<
out_slr
.
rows
().
size
();
++
i
)
{
for
(
auto
i
=
0
;
i
<
out_slr
.
rows
().
size
();
++
i
)
{
ASSERT_EQ
(
out_slr
.
rows
()[
i
],
i
);
ASSERT_EQ
(
out_slr
.
rows
()[
i
],
i
);
...
...
paddle/fluid/operators/distributed/parameter_send.cc
浏览文件 @
95e90aa1
...
@@ -139,6 +139,13 @@ void ParameterSend<T>::operator()(const RpcContext &rpc_ctx,
...
@@ -139,6 +139,13 @@ void ParameterSend<T>::operator()(const RpcContext &rpc_ctx,
auto
abs_sections
=
ToAbsoluteSection
(
rpc_ctx
.
height_sections
);
auto
abs_sections
=
ToAbsoluteSection
(
rpc_ctx
.
height_sections
);
auto
&
send_rows
=
send_slr
.
rows
();
auto
&
send_rows
=
send_slr
.
rows
();
if
(
send_rows
.
size
()
==
0
)
{
LOG
(
WARNING
)
<<
"WARNING: The variable sent to pserver is empty, which "
"may cause an unknown error. Please check the state of "
"use_double_buffer in pyreader async mode, you need to "
"turn it false."
;
}
std
::
vector
<
std
::
vector
<
size_t
>>
outs_rows_idx
;
std
::
vector
<
std
::
vector
<
size_t
>>
outs_rows_idx
;
std
::
vector
<
std
::
vector
<
size_t
>>
outs_dense_idx
;
std
::
vector
<
std
::
vector
<
size_t
>>
outs_dense_idx
;
...
...
paddle/fluid/platform/flags.cc
浏览文件 @
95e90aa1
...
@@ -199,7 +199,9 @@ DEFINE_bool(
...
@@ -199,7 +199,9 @@ DEFINE_bool(
*/
*/
DEFINE_int32
(
communicator_max_merge_var_num
,
20
,
DEFINE_int32
(
communicator_max_merge_var_num
,
20
,
"max var num to merge and send"
);
"max var num to merge and send"
);
DEFINE_bool
(
communicator_is_sgd_optimizer
,
true
,
"gradient sent to the server is the sum of the gradients "
"calculated by each thread if optimizer is sgd"
);
/**
/**
* Distributed related FLAG
* Distributed related FLAG
* Name: FLAGS_communicator_send_queue_size
* Name: FLAGS_communicator_send_queue_size
...
...
python/paddle/fluid/__init__.py
浏览文件 @
95e90aa1
...
@@ -206,6 +206,7 @@ def __bootstrap__():
...
@@ -206,6 +206,7 @@ def __bootstrap__():
read_env_flags
.
append
(
'communicator_fake_rpc'
)
read_env_flags
.
append
(
'communicator_fake_rpc'
)
read_env_flags
.
append
(
'communicator_send_wait_times'
)
read_env_flags
.
append
(
'communicator_send_wait_times'
)
read_env_flags
.
append
(
'communicator_merge_sparse_grad'
)
read_env_flags
.
append
(
'communicator_merge_sparse_grad'
)
read_env_flags
.
append
(
'communicator_is_sgd_optimizer'
)
if
core
.
is_compiled_with_brpc
():
if
core
.
is_compiled_with_brpc
():
read_env_flags
.
append
(
'max_body_size'
)
read_env_flags
.
append
(
'max_body_size'
)
#set brpc max body size
#set brpc max body size
...
...
python/paddle/fluid/tests/unittests/test_dist_ctr.py
浏览文件 @
95e90aa1
...
@@ -113,7 +113,8 @@ class TestDistCTR2x2_ASYNC2(TestDistBase):
...
@@ -113,7 +113,8 @@ class TestDistCTR2x2_ASYNC2(TestDistBase):
"FLAGS_communicator_send_queue_size"
:
"2"
,
"FLAGS_communicator_send_queue_size"
:
"2"
,
"FLAGS_communicator_max_merge_var_num"
:
"2"
,
"FLAGS_communicator_max_merge_var_num"
:
"2"
,
"FLAGS_communicator_max_send_grad_num_before_recv"
:
"2"
,
"FLAGS_communicator_max_send_grad_num_before_recv"
:
"2"
,
"FLAGS_communicator_independent_recv_thread"
:
"0"
"FLAGS_communicator_independent_recv_thread"
:
"0"
,
"FLAGS_communicator_is_sgd_optimizer"
:
"0"
}
}
self
.
check_with_place
(
self
.
check_with_place
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录