Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b635af71
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
b635af71
编写于
7月 20, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix some compile error
上级
8a5ee462
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
15 deletion
+17
-15
paddle/framework/grad_op_creator.cc
paddle/framework/grad_op_creator.cc
+17
-15
未找到文件。
paddle/framework/grad_op_creator.cc
浏览文件 @
b635af71
...
@@ -12,7 +12,8 @@ OperatorBase* GradOpCreator::Create() {
...
@@ -12,7 +12,8 @@ OperatorBase* GradOpCreator::Create() {
OpInOutArg
*
GradOpCreator
::
BuildArg
(
const
VarProto
&
var
,
OpInOutArg
*
GradOpCreator
::
BuildArg
(
const
VarProto
&
var
,
const
VarIndexMap
&
var_map
,
const
VarIndexMap
&
var_map
,
const
vector
<
int
>&
format
,
InOutType
type
)
{
const
std
::
vector
<
int
>&
format
,
InOutType
type
)
{
int
idx
=
var_map
.
at
(
var
.
name
());
int
idx
=
var_map
.
at
(
var
.
name
());
int
begin_idx
=
format
.
empty
()
?
idx
:
format
.
at
(
idx
);
int
begin_idx
=
format
.
empty
()
?
idx
:
format
.
at
(
idx
);
int
end_idx
=
format
.
empty
()
?
idx
+
1
:
format
.
at
(
idx
+
1
);
int
end_idx
=
format
.
empty
()
?
idx
+
1
:
format
.
at
(
idx
+
1
);
...
@@ -23,11 +24,11 @@ OpInOutArg* GradOpCreator::BuildArg(const VarProto& var,
...
@@ -23,11 +24,11 @@ OpInOutArg* GradOpCreator::BuildArg(const VarProto& var,
void
GradOpCreator
::
BuildOpInOutArgList
()
{
void
GradOpCreator
::
BuildOpInOutArgList
()
{
const
OpProto
&
op_proto
=
OpRegistry
::
protos
().
at
(
op_
->
type
);
const
OpProto
&
op_proto
=
OpRegistry
::
protos
().
at
(
op_
->
type
);
const
auto
&
var_map
=
*
(
OpRegistry
::
VarIndexMaps
().
at
(
op
->
type_
));
const
auto
&
var_map
=
*
(
OpRegistry
::
VarIndexMaps
().
at
(
op
->
type_
));
const
vector
<
int
>&
in_format
=
const
std
::
vector
<
int
>&
in_format
=
op_
->
attrs_
.
count
(
"input_format"
)
op_
->
attrs_
.
count
(
"input_format"
)
?
op
->
GetAttr
<
std
::
vector
<
int
>>
(
"input_format"
)
?
op
->
GetAttr
<
std
::
vector
<
int
>>
(
"input_format"
)
:
std
::
vector
<
int
>
();
:
std
::
vector
<
int
>
();
const
vector
<
int
>&
out_format
=
const
std
::
vector
<
int
>&
out_format
=
op_
->
attrs_
.
count
(
"output_format"
)
op_
->
attrs_
.
count
(
"output_format"
)
?
op
->
GetAttr
<
std
::
vector
<
int
>>
(
"output_format"
)
?
op
->
GetAttr
<
std
::
vector
<
int
>>
(
"output_format"
)
:
std
::
vector
<
int
>
();
:
std
::
vector
<
int
>
();
...
@@ -41,10 +42,11 @@ void GradOpCreator::BuildOpInOutArgList() {
...
@@ -41,10 +42,11 @@ void GradOpCreator::BuildOpInOutArgList() {
}
}
}
}
void
GradOpCreator
::
PushArgIntoGradOp
(
const
OpInOutArg
*
arg
,
void
GradOpCreator
::
AddArgIntoGradOp
(
const
OpInOutArg
*
arg
,
vector
<
std
::
string
>&
in_out
,
std
::
vector
<
std
::
string
>&
in_out
,
vector
<
int
>&
format
,
VarIndexMap
*
varmap
,
std
::
vector
<
int
>&
format
,
int
&
idx
,
bool
is_grad
)
{
VarIndexMap
*
varmap
,
int
&
idx
,
bool
is_grad
)
{
std
::
string
var_name
=
arg
->
proto_name_
;
std
::
string
var_name
=
arg
->
proto_name_
;
if
(
is_grad
)
{
if
(
is_grad
)
{
var_name
+=
OperatorBase
::
GRAD_VAR_SUFFIX
();
var_name
+=
OperatorBase
::
GRAD_VAR_SUFFIX
();
...
@@ -70,22 +72,22 @@ void GradOpCreator::CompleteGradOp(OperatorBase* grad_op) const {
...
@@ -70,22 +72,22 @@ void GradOpCreator::CompleteGradOp(OperatorBase* grad_op) const {
VarIndexMap
*
grad_varmap
=
new
VarIndexMap
();
VarIndexMap
*
grad_varmap
=
new
VarIndexMap
();
int
in_idx
=
0
;
int
in_idx
=
0
;
int
out_idx
=
0
;
int
out_idx
=
0
;
vector
<
int
>
in_format
({
0
});
std
::
vector
<
int
>
in_format
({
0
});
vector
<
int
>
out_format
({
0
});
std
::
vector
<
int
>
out_format
({
0
});
for
(
const
auto
&
arg
:
arg_list_
)
{
for
(
const
auto
&
arg
:
arg_list_
)
{
// op_'s inputs_ and outputs_
// op_'s inputs_ and outputs_
if
(
arg
->
needed_in_grad_
)
{
if
(
arg
->
needed_in_grad_
)
{
Push
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
inputs_
,
in_format
,
grad_varmap
,
Add
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
inputs_
,
in_format
,
grad_varmap
,
in_idx
,
false
);
in_idx
,
false
);
}
}
if
(
arg
->
type_
==
IN
)
{
if
(
arg
->
type_
==
IN
)
{
// gradients of op_'s inputs_
// gradients of op_'s inputs_
Push
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
outputs_
,
out_format
,
grad_varmap
,
Add
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
outputs_
,
out_format
,
grad_varmap
,
out_idx
,
true
);
out_idx
,
true
);
}
else
{
}
else
{
// gradients of op_'s outputs_
// gradients of op_'s outputs_
Push
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
inputs_
,
in_format
,
grad_varmap
,
Add
ArgIntoGradOp
(
arg
.
get
(),
grad_op
->
inputs_
,
in_format
,
grad_varmap
,
in_idx
,
true
);
in_idx
,
true
);
}
}
}
}
grad_op
->
attrs_
[
"input_format"
]
=
in_format
;
grad_op
->
attrs_
[
"input_format"
]
=
in_format
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录