Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
fb370f44
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
fb370f44
编写于
5月 22, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine code
上级
03e4da6d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
26 deletion
+31
-26
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+27
-20
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+2
-3
paddle/fluid/framework/op_desc.h
paddle/fluid/framework/op_desc.h
+1
-2
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+1
-1
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
fb370f44
...
...
@@ -163,27 +163,34 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
if
(
static_cast
<
bool
>
(
boost
::
get
<
int
>
(
op
->
GetAttr
(
OpProtoAndCheckerMaker
::
OpRoleAttrName
()))
&
static_cast
<
int
>
(
OpRole
::
kBackward
)))
{
auto
backward_vars
=
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
op
->
GetAttrOrDefault
(
OpProtoAndCheckerMaker
::
OpRoleVarAttrName
(),
std
::
vector
<
std
::
string
>
()));
for
(
auto
&
og
:
backward_vars
)
{
switch
(
strategy_
.
reduce_
)
{
case
BuildStrategy
::
ReduceStrategy
::
kReduce
:
CreateReduceOp
(
&
result
,
og
,
cur_device_id
);
var_name_on_devices
[
cur_device_id
].
emplace
(
og
);
bcast_var_name_set
[
cur_device_id
].
emplace
(
og
.
substr
(
0
,
og
.
size
()
-
strlen
(
kGradVarSuffix
)));
cur_device_id
=
(
cur_device_id
+
1
)
%
places_
.
size
();
break
;
case
BuildStrategy
::
ReduceStrategy
::
kAllReduce
:
if
(
IsSparseGradient
(
var_types
,
og
))
{
CreateReduceOp
(
&
result
,
og
,
0
);
CreateBroadcastOp
(
&
result
,
og
,
0
);
}
else
{
InsertNCCLAllReduceOp
(
&
result
,
og
);
}
break
;
try
{
auto
backward_vars
=
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
op
->
GetNullableAttr
(
OpProtoAndCheckerMaker
::
OpRoleVarAttrName
()));
PADDLE_ENFORCE_EQ
(
backward_vars
.
size
()
%
2
,
0
);
for
(
size_t
i
=
0
;
i
<
backward_vars
.
size
();
++
i
)
{
auto
&
p_name
=
backward_vars
[
i
];
auto
&
g_name
=
backward_vars
[
i
+
1
];
switch
(
strategy_
.
reduce_
)
{
case
BuildStrategy
::
ReduceStrategy
::
kReduce
:
CreateReduceOp
(
&
result
,
g_name
,
cur_device_id
);
var_name_on_devices
[
cur_device_id
].
emplace
(
g_name
);
bcast_var_name_set
[
cur_device_id
].
emplace
(
p_name
);
cur_device_id
=
(
cur_device_id
+
1
)
%
places_
.
size
();
break
;
case
BuildStrategy
::
ReduceStrategy
::
kAllReduce
:
if
(
IsSparseGradient
(
var_types
,
g_name
))
{
CreateReduceOp
(
&
result
,
g_name
,
0
);
CreateBroadcastOp
(
&
result
,
g_name
,
0
);
}
else
{
InsertNCCLAllReduceOp
(
&
result
,
g_name
);
}
break
;
}
}
}
catch
(
boost
::
bad_get
e
)
{
}
}
}
...
...
paddle/fluid/framework/op_desc.cc
浏览文件 @
fb370f44
...
...
@@ -223,13 +223,12 @@ Attribute OpDesc::GetAttr(const std::string &name) const {
return
it
->
second
;
}
Attribute
OpDesc
::
GetAttrOrDefault
(
const
std
::
string
&
name
,
paddle
::
framework
::
Attribute
default_attr
)
const
{
Attribute
OpDesc
::
GetNullableAttr
(
const
std
::
string
&
name
)
const
{
auto
it
=
attrs_
.
find
(
name
);
if
(
it
!=
attrs_
.
end
())
{
return
it
->
second
;
}
else
{
return
default_attr
;
return
Attribute
()
;
}
}
...
...
paddle/fluid/framework/op_desc.h
浏览文件 @
fb370f44
...
...
@@ -78,8 +78,7 @@ class OpDesc {
Attribute
GetAttr
(
const
std
::
string
&
name
)
const
;
Attribute
GetAttrOrDefault
(
const
std
::
string
&
name
,
Attribute
default_attr
)
const
;
Attribute
GetNullableAttr
(
const
std
::
string
&
name
)
const
;
int
GetBlockAttr
(
const
std
::
string
&
name
)
const
;
...
...
python/paddle/fluid/backward.py
浏览文件 @
fb370f44
...
...
@@ -536,7 +536,7 @@ def append_backward(loss, parameter_list=None, no_grad_set=None,
if
g
.
op
is
None
:
raise
ValueError
(
"Unexpected branch"
)
attr_val
=
[
p
.
name
]
attr_val
=
[
p
.
name
,
g
.
name
]
if
g
.
op
.
has_attr
(
op_role_var_attr_name
):
attr_val
.
extend
(
g
.
op
.
attr
(
op_role_var_attr_name
))
g
.
op
.
set_attr
(
op_role_var_attr_name
,
attr_val
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录