Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0441c2cc
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
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,发现更多精彩内容 >>
提交
0441c2cc
编写于
5月 05, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ci
上级
f9c680c4
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
27 addition
and
22 deletion
+27
-22
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+18
-12
paddle/fluid/framework/details/multi_devices_graph_builder.h
paddle/fluid/framework/details/multi_devices_graph_builder.h
+3
-1
paddle/fluid/framework/details/var_handle.h
paddle/fluid/framework/details/var_handle.h
+6
-9
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
0441c2cc
...
...
@@ -107,6 +107,10 @@ bool MultiDevSSAGraphBuilder::IsDistTrainOp(const OpDesc &op,
std
::
unique_ptr
<
SSAGraph
>
MultiDevSSAGraphBuilder
::
Build
(
const
ProgramDesc
&
program
)
const
{
std
::
unordered_map
<
std
::
string
,
proto
::
VarType
::
Type
>
var_types
;
for
(
auto
*
var
:
program
.
Block
(
0
).
AllVars
())
{
var_types
[
var
->
Name
()]
=
var
->
GetType
();
}
auto
graph
=
new
SSAGraph
();
SSAGraph
&
result
=
*
graph
;
std
::
unordered_set
<
std
::
string
>
og_has_been_broadcast
;
...
...
@@ -116,7 +120,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
VarHandle
>>>>
(
places_
.
size
());
size_t
cur_
update_sparse_gp_
dev_id
=
0
;
size_t
cur_dev_id
=
0
;
std
::
vector
<
std
::
unordered_set
<
std
::
string
>>
sparse_var_name_on_devices
;
std
::
vector
<
std
::
unordered_set
<
std
::
string
>>
bcast_sparse_var_name_set
;
...
...
@@ -156,14 +160,12 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
// broadcast, and each gradient is only broadcast once.
for
(
auto
&
og
:
op
->
OutputArgumentNames
())
{
if
(
IsParameterGradientOnce
(
og
,
&
og_has_been_broadcast
))
{
if
(
IsSparseGradient
(
og
))
{
CreateReduceOp
(
&
result
,
cur_update_sparse_gp_dev_id
,
og
);
sparse_var_name_on_devices
[
cur_update_sparse_gp_dev_id
].
emplace
(
og
);
bcast_sparse_var_name_set
[
cur_update_sparse_gp_dev_id
].
emplace
(
if
(
IsSparseGradient
(
var_types
,
og
))
{
CreateReduceOp
(
&
result
,
cur_dev_id
,
og
);
sparse_var_name_on_devices
[
cur_dev_id
].
emplace
(
og
);
bcast_sparse_var_name_set
[
cur_dev_id
].
emplace
(
og
.
substr
(
0
,
og
.
size
()
-
strlen
(
kGradVarSuffix
)));
cur_update_sparse_gp_dev_id
=
(
cur_update_sparse_gp_dev_id
+
1
)
%
places_
.
size
();
cur_dev_id
=
(
cur_dev_id
+
1
)
%
places_
.
size
();
}
else
{
InsertNCCLAllReduceOp
(
&
result
,
og
);
}
...
...
@@ -201,10 +203,14 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
return
std
::
unique_ptr
<
SSAGraph
>
(
graph
);
}
bool
MultiDevSSAGraphBuilder
::
IsSparseGradient
(
const
std
::
string
&
og
)
const
{
auto
og_var
=
local_scopes_
[
0
]
->
FindVar
(
og
);
PADDLE_ENFORCE_NOT_NULL
(
og_var
);
return
og_var
->
IsType
<
SelectedRows
>
();
bool
MultiDevSSAGraphBuilder
::
IsSparseGradient
(
const
std
::
unordered_map
<
std
::
string
,
proto
::
VarType
::
Type
>
&
var_types
,
const
std
::
string
&
og
)
const
{
PADDLE_ENFORCE
(
var_types
.
count
(
og
)
!=
0
);
if
(
var_types
.
at
(
og
)
==
proto
::
VarType
::
SELECTED_ROWS
)
{
return
true
;
}
return
false
;
}
int
MultiDevSSAGraphBuilder
::
GetOpDeviceID
(
...
...
paddle/fluid/framework/details/multi_devices_graph_builder.h
浏览文件 @
0441c2cc
...
...
@@ -99,7 +99,9 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
*/
OpDesc
*
GetSendOpDesc
(
const
ProgramDesc
&
program
)
const
;
bool
IsSparseGradient
(
const
std
::
string
&
og
)
const
;
bool
IsSparseGradient
(
const
std
::
unordered_map
<
std
::
string
,
proto
::
VarType
::
Type
>
&
var_types
,
const
std
::
string
&
og
)
const
;
};
}
// namespace details
}
// namespace framework
...
...
paddle/fluid/framework/details/var_handle.h
浏览文件 @
0441c2cc
...
...
@@ -63,15 +63,12 @@ struct VarHandle : public VarHandleBase {
platform
::
Place
place_
;
// NOTE(zcd): Strictly speaking, if the two var_handle is equal, the four
// member
// variables(version_, scope_id_, name_, place_) must be equal. But sometimes
// judging whether the two var_handle is equal is actually to determine
// whether
// the two Variables that represented by var_handle is the same. And the same
// Variable may have many different var_handles, the version_ of these
// var_handles
// is different. So I don't take care of version_ temporarily when overloading
// equal.
// member variables(version_, scope_id_, name_, place_) must be equal. But
// sometimes judging whether the two var_handle is equal is actually to
// determine whether the two Variables that represented by var_handle is the
// same. And the same Variable may have many different var_handles, the
// version_ of these var_handles is different. So I don't take care of
// version_ temporarily when overloading equal.
bool
operator
==
(
const
VarHandle
&
o
)
const
{
return
o
.
generated_op_
==
generated_op_
&&
o
.
name_
==
name_
&&
o
.
scope_idx_
==
scope_idx_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录