Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
0c5202cb
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看板
提交
0c5202cb
编写于
1月 02, 2018
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tiny enhance of while_op
上级
90a33ddd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
21 deletion
+21
-21
paddle/operators/while_op.cc
paddle/operators/while_op.cc
+21
-21
未找到文件。
paddle/operators/while_op.cc
浏览文件 @
0c5202cb
...
...
@@ -25,12 +25,12 @@ namespace operators {
using
StepScopeVar
=
std
::
vector
<
framework
::
Scope
*>
;
using
LoDTensor
=
framework
::
LoDTensor
;
constexpr
char
kStepBlock
[]
=
"sub_block"
;
constexpr
char
kCondition
[]
=
"Condition"
;
constexpr
char
kStepScopes
[]
=
"StepScopes"
;
constexpr
char
kParameters
[]
=
"X"
;
constexpr
char
kParamGrads
[]
=
"X@GRAD"
;
constexpr
char
kOutputs
[]
=
"Out"
;
static
constexpr
char
kStepBlock
[]
=
"sub_block"
;
static
constexpr
char
kCondition
[]
=
"Condition"
;
static
constexpr
char
kStepScopes
[]
=
"StepScopes"
;
static
constexpr
char
kX
[]
=
"X"
;
static
constexpr
char
kXGRAD
[]
=
"X@GRAD"
;
static
constexpr
char
kOutputs
[]
=
"Out"
;
class
WhileOp
:
public
framework
::
OperatorBase
{
public:
...
...
@@ -67,7 +67,7 @@ class WhileOpMaker : public framework::OpProtoAndCheckerMaker {
public:
WhileOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
k
Parameters
,
AddInput
(
k
X
,
"A set of variables, which are required by operators inside the "
"block of While Op."
)
.
AsDuplicable
();
...
...
@@ -158,8 +158,8 @@ class WhileGradOp : public framework::OperatorBase {
executor
.
Run
(
*
program
,
*
cur_scope_iter
,
block
->
ID
(),
false
);
auto
&
pg_names
=
Outputs
(
k
ParamGrads
);
auto
&
p_names
=
Inputs
(
k
Parameters
);
auto
&
pg_names
=
Outputs
(
k
XGRAD
);
auto
&
p_names
=
Inputs
(
k
X
);
PADDLE_ENFORCE_EQ
(
pg_names
.
size
(),
p_names
.
size
());
for
(
size_t
param_id
=
0
;
param_id
<
pg_names
.
size
();
++
param_id
)
{
if
(
pg_names
[
param_id
]
==
framework
::
kEmptyVarName
)
{
...
...
@@ -213,11 +213,11 @@ class WhileGradOpDescMaker : public framework::SingleGradOpDescMaker {
std
::
unique_ptr
<
framework
::
OpDesc
>
Apply
()
const
override
{
auto
*
grad
=
new
framework
::
OpDesc
();
grad
->
SetType
(
"while_grad"
);
grad
->
SetInput
(
k
Parameters
,
Input
(
kParameters
));
grad
->
SetInput
(
k
X
,
Input
(
kX
));
// Not all of IGs will be generated by inner gradient operators of while op.
// Ignore IGs that is not generated by the inside block.
auto
igs
=
InputGrad
(
k
Parameters
,
/*do not drop empty gradient*/
false
);
auto
igs
=
InputGrad
(
k
X
,
/*do not drop empty gradient*/
false
);
std
::
unordered_set
<
std
::
string
>
all_outs
;
for
(
size_t
i
=
0
;
i
<
grad_block_
[
0
]
->
OpSize
();
++
i
)
{
for
(
auto
&
oname
:
grad_block_
[
0
]
->
Op
(
i
)
->
OutputArgumentNames
())
{
...
...
@@ -231,7 +231,7 @@ class WhileGradOpDescMaker : public framework::SingleGradOpDescMaker {
}
}
grad
->
SetOutput
(
framework
::
GradVarName
(
k
Parameters
),
igs
);
grad
->
SetOutput
(
framework
::
GradVarName
(
k
X
),
igs
);
grad
->
SetInput
(
kOutputs
,
Output
(
kOutputs
));
...
...
@@ -240,7 +240,7 @@ class WhileGradOpDescMaker : public framework::SingleGradOpDescMaker {
std
::
unordered_set
<
std
::
string
>
block_ins
;
auto
*
fwd_block
=
this
->
grad_block_
[
0
]
->
ParentBlock
();
{
for
(
auto
&
p
:
Input
(
k
Parameters
))
{
for
(
auto
&
p
:
Input
(
k
X
))
{
block_ins
.
insert
(
p
);
}
for
(
auto
&
o
:
Output
(
kOutputs
))
{
...
...
@@ -288,8 +288,8 @@ class WhileGradOpVarTypeInference : public framework::VarTypeInference {
public:
void
operator
()(
const
framework
::
OpDesc
&
op_desc
,
framework
::
BlockDesc
*
block
)
const
override
{
auto
p_names
=
op_desc
.
Input
(
k
Parameters
);
auto
pg_names
=
op_desc
.
Output
(
framework
::
GradVarName
(
k
Parameters
));
auto
p_names
=
op_desc
.
Input
(
k
X
);
auto
pg_names
=
op_desc
.
Output
(
framework
::
GradVarName
(
k
X
));
for
(
size_t
i
=
0
;
i
<
p_names
.
size
();
++
i
)
{
auto
&
p_var
=
detail
::
Ref
(
block
->
FindVarRecursive
(
p_names
[
i
]));
...
...
@@ -307,21 +307,21 @@ class WhileGradOpVarTypeInference : public framework::VarTypeInference {
class
WhileGradOpShapeInference
:
public
framework
::
InferShapeBase
{
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
ctx
->
HasInputs
(
k
Parameters
);
ctx
->
HasOutputs
(
framework
::
GradVarName
(
k
Parameters
));
ctx
->
HasInputs
(
k
X
);
ctx
->
HasOutputs
(
framework
::
GradVarName
(
k
X
));
ctx
->
HasInputs
(
kOutputs
);
ctx
->
HasInputs
(
framework
::
GradVarName
(
kOutputs
));
auto
p_names
=
ctx
->
Inputs
(
k
Parameters
);
auto
pg_names
=
ctx
->
Outputs
(
k
ParamGrads
);
auto
var_types
=
ctx
->
GetInputsVarType
(
k
Parameters
);
auto
p_names
=
ctx
->
Inputs
(
k
X
);
auto
pg_names
=
ctx
->
Outputs
(
k
XGRAD
);
auto
var_types
=
ctx
->
GetInputsVarType
(
k
X
);
std
::
vector
<
std
::
string
>
names_to_set
;
std
::
vector
<
framework
::
DDim
>
dims_to_set
;
for
(
size_t
i
=
0
;
i
<
p_names
.
size
();
++
i
)
{
if
(
pg_names
[
i
]
==
framework
::
kEmptyVarName
)
{
continue
;
}
auto
dims
=
ctx
->
GetInputsElementDim
(
k
Parameters
,
i
);
auto
dims
=
ctx
->
GetInputsElementDim
(
k
X
,
i
);
if
(
var_types
[
i
]
==
framework
::
proto
::
VarDesc
::
LOD_TENSOR
)
{
names_to_set
.
push_back
(
pg_names
[
i
]);
dims_to_set
.
push_back
(
dims
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录