Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
9612c7e5
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看板
提交
9612c7e5
编写于
4月 27, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add comments and polish code
上级
76c4ae85
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
30 deletion
+51
-30
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+29
-29
paddle/fluid/framework/details/multi_devices_graph_builder.h
paddle/fluid/framework/details/multi_devices_graph_builder.h
+10
-1
paddle/fluid/framework/details/ssa_graph.h
paddle/fluid/framework/details/ssa_graph.h
+10
-0
paddle/fluid/framework/details/ssa_graph_builder.h
paddle/fluid/framework/details/ssa_graph_builder.h
+2
-0
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
9612c7e5
...
@@ -58,23 +58,20 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
...
@@ -58,23 +58,20 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
void
MultiDevSSAGraphBuilder
::
CreateOpHandleIOs
(
SSAGraph
*
result
,
void
MultiDevSSAGraphBuilder
::
CreateOpHandleIOs
(
SSAGraph
*
result
,
const
OpDesc
&
op
,
const
OpDesc
&
op
,
const
platform
::
Place
&
p
,
size_t
place_id
)
const
{
const
size_t
&
i
)
const
{
auto
p
=
places_
[
place_id
];
auto
*
op_handle
=
result
->
ops_
.
back
().
get
();
auto
*
op_handle
=
result
->
ops_
.
back
().
get
();
op_handle
->
SetDeviceContext
(
p
,
op_handle
->
SetDeviceContext
(
p
,
platform
::
DeviceContextPool
::
Instance
().
Get
(
p
));
platform
::
DeviceContextPool
::
Instance
().
Get
(
p
));
auto
var_names
=
op
.
InputArgumentNames
();
for
(
auto
&
each_var_name
:
op
.
InputArgumentNames
())
{
VarHandle
*
var
=
for
(
auto
&
each_var_name
:
var_names
)
{
CreateOrGetLatestVarHandle
(
result
,
each_var_name
,
p
,
place_id
);
VarHandle
*
var
=
CreateOrGetLatestVarHandle
(
result
,
each_var_name
,
p
,
i
);
op_handle
->
AddInput
(
var
);
op_handle
->
AddInput
(
var
);
}
}
var_names
=
op
.
OutputArgumentNames
();
for
(
auto
&
each_var_name
:
op
.
OutputArgumentNames
())
{
CreateOpOutput
(
result
,
op_handle
,
each_var_name
,
p
,
place_id
);
for
(
auto
&
each_var_name
:
var_names
)
{
CreateOpOutput
(
result
,
op_handle
,
each_var_name
,
p
,
i
);
}
}
}
}
...
@@ -84,17 +81,18 @@ bool MultiDevSSAGraphBuilder::IsDistTrainOp(const OpDesc &op,
...
@@ -84,17 +81,18 @@ bool MultiDevSSAGraphBuilder::IsDistTrainOp(const OpDesc &op,
return
false
;
return
false
;
}
}
auto
checker
=
[
&
](
const
std
::
vector
<
std
::
string
>
opvars
,
/**
const
std
::
vector
<
std
::
string
>
sendvars
)
->
bool
{
* Check any of opvars contains `.block` and in sendvars
bool
is_dist_train_op
=
false
;
*/
auto
checker
=
[](
const
std
::
vector
<
std
::
string
>
&
opvars
,
const
std
::
vector
<
std
::
string
>
&
sendvars
)
->
bool
{
for
(
auto
&
var
:
opvars
)
{
for
(
auto
&
var
:
opvars
)
{
if
(
var
.
find
(
".block"
)
!=
std
::
string
::
npos
&&
if
(
var
.
find
(
".block"
)
!=
std
::
string
::
npos
&&
std
::
find
(
sendvars
.
begin
(),
sendvars
.
end
(),
var
)
!=
sendvars
.
end
())
{
std
::
find
(
sendvars
.
begin
(),
sendvars
.
end
(),
var
)
!=
sendvars
.
end
())
{
is_dist_train_op
=
true
;
return
true
;
break
;
}
}
}
}
return
is_dist_train_op
;
return
false
;
};
};
if
(
op
.
Type
()
==
"split"
)
{
if
(
op
.
Type
()
==
"split"
)
{
...
@@ -117,13 +115,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -117,13 +115,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
places_
.
size
());
places_
.
size
());
// Find "send" op first for split is in front of send.
// Find "send" op first for split is in front of send.
OpDesc
*
send_op
=
nullptr
;
OpDesc
*
send_op
=
GetSendOpDesc
(
program
);
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
if
(
op
->
Type
()
==
"send"
)
{
send_op
=
op
;
break
;
}
}
bool
is_forwarding
=
true
;
bool
is_forwarding
=
true
;
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
...
@@ -134,6 +126,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -134,6 +126,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
}
else
if
(
IsDistTrainOp
(
*
op
,
send_op
))
{
}
else
if
(
IsDistTrainOp
(
*
op
,
send_op
))
{
CreateComputationalOps
(
&
result
,
*
op
,
1
);
CreateComputationalOps
(
&
result
,
*
op
,
1
);
}
else
if
(
IsScaleLossOp
(
*
op
))
{
}
else
if
(
IsScaleLossOp
(
*
op
))
{
// user can customize loss@grad if skip_scale_loss_
if
(
!
skip_scale_loss_
)
{
if
(
!
skip_scale_loss_
)
{
CreateScaleLossGradOp
(
&
result
);
CreateScaleLossGradOp
(
&
result
);
}
}
...
@@ -142,10 +135,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -142,10 +135,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
CreateComputationalOps
(
&
result
,
*
op
,
places_
.
size
());
CreateComputationalOps
(
&
result
,
*
op
,
places_
.
size
());
if
(
!
is_forwarding
)
{
if
(
!
is_forwarding
)
{
// Currently, we assume that once gradient is generated, it can be
// Currently, we assume that once gradient is generated, it can be
// broadcast, and each gradient is only broadcast once. But there are no
// broadcast, and each gradient is only broadcast once.
// other cases, for example, we need to adjust the gradient according to
// the input when we get the gradient, which is not considered at
// present.
for
(
auto
&
og
:
op
->
OutputArgumentNames
())
{
for
(
auto
&
og
:
op
->
OutputArgumentNames
())
{
if
(
IsParameterGradientOnce
(
og
,
&
og_has_been_broadcast
))
{
if
(
IsParameterGradientOnce
(
og
,
&
og_has_been_broadcast
))
{
InsertNCCLAllReduceOp
(
&
result
,
og
);
InsertNCCLAllReduceOp
(
&
result
,
og
);
...
@@ -175,6 +165,16 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -175,6 +165,16 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
return
std
::
unique_ptr
<
SSAGraph
>
(
graph
);
return
std
::
unique_ptr
<
SSAGraph
>
(
graph
);
}
}
OpDesc
*
MultiDevSSAGraphBuilder
::
GetSendOpDesc
(
const
ProgramDesc
&
program
)
const
{
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
if
(
op
->
Type
()
==
"send"
)
{
return
op
;
}
}
return
nullptr
;
}
void
MultiDevSSAGraphBuilder
::
InsertNCCLAllReduceOp
(
void
MultiDevSSAGraphBuilder
::
InsertNCCLAllReduceOp
(
SSAGraph
*
result
,
const
std
::
string
&
og
)
const
{
SSAGraph
*
result
,
const
std
::
string
&
og
)
const
{
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
...
@@ -243,7 +243,7 @@ void MultiDevSSAGraphBuilder::CreateComputationalOps(SSAGraph *result,
...
@@ -243,7 +243,7 @@ void MultiDevSSAGraphBuilder::CreateComputationalOps(SSAGraph *result,
auto
p
=
places_
[
scope_idx
];
auto
p
=
places_
[
scope_idx
];
auto
s
=
local_scopes_
[
scope_idx
];
auto
s
=
local_scopes_
[
scope_idx
];
result
->
ops_
.
emplace_back
(
new
ComputationOpHandle
(
op
,
s
,
p
));
result
->
ops_
.
emplace_back
(
new
ComputationOpHandle
(
op
,
s
,
p
));
CreateOpHandleIOs
(
result
,
op
,
p
,
scope_idx
);
CreateOpHandleIOs
(
result
,
op
,
scope_idx
);
}
}
}
}
...
@@ -255,7 +255,7 @@ void MultiDevSSAGraphBuilder::CreateSendOp(SSAGraph *result,
...
@@ -255,7 +255,7 @@ void MultiDevSSAGraphBuilder::CreateSendOp(SSAGraph *result,
result
->
ops_
.
emplace_back
(
new
SendOpHandle
(
op
,
s
,
p
));
result
->
ops_
.
emplace_back
(
new
SendOpHandle
(
op
,
s
,
p
));
// Create inputs for output on original place and no ssa output
// Create inputs for output on original place and no ssa output
// is created for send op.
// is created for send op.
CreateOpHandleIOs
(
result
,
op
,
p
,
0
);
CreateOpHandleIOs
(
result
,
op
,
0
);
}
}
bool
MultiDevSSAGraphBuilder
::
IsScaleLossOp
(
const
OpDesc
&
op
)
const
{
bool
MultiDevSSAGraphBuilder
::
IsScaleLossOp
(
const
OpDesc
&
op
)
const
{
...
...
paddle/fluid/framework/details/multi_devices_graph_builder.h
浏览文件 @
9612c7e5
...
@@ -48,7 +48,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
...
@@ -48,7 +48,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
private:
private:
void
CreateOpHandleIOs
(
SSAGraph
*
result
,
const
OpDesc
&
op
,
void
CreateOpHandleIOs
(
SSAGraph
*
result
,
const
OpDesc
&
op
,
const
platform
::
Place
&
p
,
const
size_t
&
i
)
const
;
size_t
place_id
)
const
;
private:
private:
std
::
string
loss_var_name_
;
std
::
string
loss_var_name_
;
...
@@ -65,6 +65,9 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
...
@@ -65,6 +65,9 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
void
CreateSendOp
(
SSAGraph
*
result
,
const
OpDesc
&
op
)
const
;
void
CreateSendOp
(
SSAGraph
*
result
,
const
OpDesc
&
op
)
const
;
/**
* Is this operator as the end-point operator before/after send operator.
*/
bool
IsDistTrainOp
(
const
OpDesc
&
op
,
OpDesc
*
send_op
)
const
;
bool
IsDistTrainOp
(
const
OpDesc
&
op
,
OpDesc
*
send_op
)
const
;
void
CreateComputationalOps
(
SSAGraph
*
result
,
const
OpDesc
&
op
,
void
CreateComputationalOps
(
SSAGraph
*
result
,
const
OpDesc
&
op
,
...
@@ -77,6 +80,12 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
...
@@ -77,6 +80,12 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
std
::
unordered_set
<
std
::
string
>
*
og_has_been_broadcast
)
const
;
std
::
unordered_set
<
std
::
string
>
*
og_has_been_broadcast
)
const
;
void
InsertNCCLAllReduceOp
(
SSAGraph
*
result
,
const
std
::
string
&
og
)
const
;
void
InsertNCCLAllReduceOp
(
SSAGraph
*
result
,
const
std
::
string
&
og
)
const
;
/**
* Get send op in the global block of program.
* nullptr if not found.
*/
OpDesc
*
GetSendOpDesc
(
const
ProgramDesc
&
program
)
const
;
};
};
}
// namespace details
}
// namespace details
}
// namespace framework
}
// namespace framework
...
...
paddle/fluid/framework/details/ssa_graph.h
浏览文件 @
9612c7e5
...
@@ -25,12 +25,22 @@ namespace paddle {
...
@@ -25,12 +25,22 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
details
{
namespace
details
{
// A SSA graph used by parallel executor.
struct
SSAGraph
{
struct
SSAGraph
{
// all variable in each devices.
// The outside vector is the device vector. Each element of this vector is a
// map from variable name to variables. The variables, who have the same name,
// will have a different version. The offset in the
// `std::vector<std::unique_ptr<VarHandle>>` is the version of varaibles.
std
::
vector
<
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
VarHandle
>>>>
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
VarHandle
>>>>
vars_
;
vars_
;
// aux variables to represent dependency. Useful to resolve data hazard.
// aux variables to represent dependency. Useful to resolve data hazard.
std
::
unordered_set
<
std
::
unique_ptr
<
VarHandleBase
>>
dep_vars_
;
std
::
unordered_set
<
std
::
unique_ptr
<
VarHandleBase
>>
dep_vars_
;
// all operators. NOTE that even we use a vector here, the operators is
// unordered.
std
::
vector
<
std
::
unique_ptr
<
OpHandleBase
>>
ops_
;
std
::
vector
<
std
::
unique_ptr
<
OpHandleBase
>>
ops_
;
};
};
...
...
paddle/fluid/framework/details/ssa_graph_builder.h
浏览文件 @
9612c7e5
...
@@ -48,6 +48,8 @@ class SSAGraphBuilder {
...
@@ -48,6 +48,8 @@ class SSAGraphBuilder {
const
platform
::
Place
&
place
,
const
platform
::
Place
&
place
,
size_t
place_offset
);
size_t
place_offset
);
// Add an output variable (each_var_name, place, place_offset) to op_handle,
// which belongs to graph
static
void
CreateOpOutput
(
SSAGraph
*
graph
,
OpHandleBase
*
op_handle
,
static
void
CreateOpOutput
(
SSAGraph
*
graph
,
OpHandleBase
*
op_handle
,
const
std
::
string
&
each_var_name
,
const
std
::
string
&
each_var_name
,
const
platform
::
Place
&
place
,
size_t
place_offset
);
const
platform
::
Place
&
place
,
size_t
place_offset
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录