Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
44c52a8c
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
44c52a8c
编写于
5月 15, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish op_proto_maker
上级
577c19b2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
18 deletion
+39
-18
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+11
-6
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+8
-0
paddle/fluid/framework/op_proto_maker.cc
paddle/fluid/framework/op_proto_maker.cc
+4
-2
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+4
-1
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+12
-9
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
44c52a8c
...
...
@@ -163,8 +163,13 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
if
(
!
is_forwarding
&&
places_
.
size
()
>
1
)
{
// Currently, we assume that once gradient is generated, it can be
// broadcast, and each gradient is only broadcast once.
for
(
auto
&
og
:
op
->
OutputArgumentNames
())
{
if
(
IsParameterGradientOnce
(
og
,
&
og_has_been_broadcast
))
{
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
->
GetAttr
(
OpProtoAndCheckerMaker
::
OpRoleVarAttrName
()));
for
(
auto
&
og
:
backward_vars
)
{
if
(
balance_parameter_opt_between_cards_
)
{
CreateReduceOp
(
&
result
,
og
,
cur_device_id
);
var_name_on_devices
[
cur_device_id
].
emplace
(
og
);
...
...
@@ -399,11 +404,11 @@ void MultiDevSSAGraphBuilder::CreateSendOp(SSAGraph *result,
}
bool
MultiDevSSAGraphBuilder
::
IsScaleLossOp
(
const
OpDesc
&
op
)
const
{
// FIXME(yy): Do not hard code like this
return
op
.
OutputArgumentNames
().
size
()
==
1
&&
op
.
OutputArgumentNames
()[
0
]
==
GradVarName
(
loss_var_name_
);
return
boost
::
get
<
int
>
(
op
.
GetAttr
(
OpProtoAndCheckerMaker
::
OpRoleAttrName
()))
==
(
static_cast
<
int
>
(
OpRole
::
kBackward
)
|
static_cast
<
int
>
(
OpRole
::
kLoss
));
}
}
// namespace details
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/op_desc.cc
浏览文件 @
44c52a8c
...
...
@@ -20,6 +20,7 @@ limitations under the License. */
#include <unordered_map>
#include "glog/logging.h"
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/shape_inference.h"
...
...
@@ -249,6 +250,13 @@ void OpDesc::RenameOutput(const std::string &old_name,
std
::
replace
(
output
.
second
.
begin
(),
output
.
second
.
end
(),
old_name
,
new_name
);
}
auto
it
=
attrs_
.
find
(
framework
::
OpProtoAndCheckerMaker
::
OpRoleVarAttrName
());
if
(
it
!=
attrs_
.
end
())
{
auto
&
op_vars
=
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
it
->
second
);
std
::
replace
(
op_vars
.
begin
(),
op_vars
.
end
(),
old_name
,
new_name
);
}
need_update_
=
true
;
}
...
...
paddle/fluid/framework/op_proto_maker.cc
浏览文件 @
44c52a8c
...
...
@@ -13,6 +13,7 @@ limitations under the License. */
#include "paddle/fluid/framework/op_proto_maker.h"
#include <string>
#include <vector>
namespace
paddle
{
namespace
framework
{
...
...
@@ -69,8 +70,9 @@ void OpProtoAndCheckerMaker::operator()(proto::OpProto* proto,
static_cast
<
int
>
(
OpRole
::
kLoss
)
|
static_cast
<
int
>
(
OpRole
::
kForward
),
static_cast
<
int
>
(
OpRole
::
kLoss
)
|
static_cast
<
int
>
(
OpRole
::
kBackward
)});
AddAttr
<
std
::
string
>
(
OpRoleVarAttrName
(),
"Optimized for variable"
)
.
SetDefault
(
""
);
AddAttr
<
std
::
vector
<
std
::
string
>>
(
OpRoleVarAttrName
(),
"Optimized for variable"
)
.
SetDefault
({});
Validate
();
}
...
...
python/paddle/fluid/backward.py
浏览文件 @
44c52a8c
...
...
@@ -534,7 +534,10 @@ def append_backward(loss, parameter_list=None, no_grad_set=None,
if
g
.
op
is
None
:
raise
ValueError
(
"Unexpected branch"
)
g
.
op
.
set_attr
(
op_role_var_attr_name
,
p
.
name
)
attr_val
=
[
p
.
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
)
return
params_and_grads
...
...
python/paddle/fluid/framework.py
浏览文件 @
44c52a8c
...
...
@@ -410,10 +410,14 @@ class Operator(object):
if
op_maker
.
kOpRoleAttrName
()
not
in
self
.
attrs
:
self
.
attrs
[
op_maker
.
kOpRoleAttrName
()]
=
self
.
block
.
program
.
op_role
if
len
(
self
.
block
.
program
.
op_role_var
)
!=
0
and
op_maker
.
kOpRoleVarAttrName
()
not
in
self
.
attrs
:
self
.
attrs
[
op_maker
.
kOpRoleVarAttrName
(
)]
=
self
.
block
.
program
.
op_role_var
role_var_name
=
op_maker
.
kOpRoleVarAttrName
()
if
len
(
self
.
block
.
program
.
op_role_var
)
!=
0
and
role_var_name
not
in
self
.
attrs
:
self
.
attrs
[
role_var_name
]
=
self
.
block
.
program
.
op_role_var
if
role_var_name
in
self
.
attrs
and
len
(
self
.
attrs
[
role_var_name
])
==
0
:
del
self
.
attrs
[
role_var_name
]
if
len
(
self
.
desc
.
type
())
!=
0
:
return
...
...
@@ -497,7 +501,6 @@ class Operator(object):
attr_name
,
self
.
attrs
[
attr_name
].
serialize_to_string
())
else
:
self
.
desc
.
set_attr
(
attr_name
,
self
.
attrs
[
attr_name
])
self
.
desc
.
check_attrs
()
no_kernel_op_set
=
{
'feed'
,
'fetch'
,
'save'
,
'load'
,
'recurrent'
,
'go'
,
...
...
@@ -1020,7 +1023,7 @@ class Program(object):
self
.
current_block_idx
=
0
self
.
_seed
=
0
self
.
_current_role
=
core
.
op_proto_and_checker_maker
.
OpRole
.
Forward
self
.
_op_role_var
=
""
self
.
_op_role_var
=
[]
@
property
def
op_role
(
self
):
...
...
@@ -1036,15 +1039,15 @@ class Program(object):
@
op_role_var
.
setter
def
set_op_role_var
(
self
,
var_name
):
self
.
_op_role_var
=
var_name
self
.
_op_role_var
=
[
var_name
]
@
contextlib
.
contextmanager
def
optimized_guard
(
self
,
var
):
OpRole
=
core
.
op_proto_and_checker_maker
.
OpRole
self
.
_current_role
=
OpRole
.
Optimize
self
.
_op_role_var
=
var
.
name
if
isinstance
(
var
,
Variable
)
else
var
self
.
_op_role_var
=
[
var
.
name
if
isinstance
(
var
,
Variable
)
else
var
]
yield
self
.
_op_role_var
=
""
self
.
_op_role_var
=
[]
self
.
_current_role
=
OpRole
.
Forward
def
__str__
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录