Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
fd5335c8
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看板
提交
fd5335c8
编写于
3月 03, 2019
作者:
C
chengduozh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine recurrent_op
test=develop
上级
e61d7245
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
32 addition
and
16 deletion
+32
-16
paddle/fluid/operators/recurrent_op.cc
paddle/fluid/operators/recurrent_op.cc
+32
-16
未找到文件。
paddle/fluid/operators/recurrent_op.cc
浏览文件 @
fd5335c8
...
@@ -157,11 +157,13 @@ class RecurrentBase : public framework::OperatorBase {
...
@@ -157,11 +157,13 @@ class RecurrentBase : public framework::OperatorBase {
const
std
::
vector
<
std
::
string
>
&
src_vars
,
const
std
::
vector
<
std
::
string
>
&
src_vars
,
framework
::
Scope
*
dst_scope
,
framework
::
Scope
*
dst_scope
,
const
std
::
vector
<
std
::
string
>
&
dst_vars
,
const
std
::
vector
<
std
::
string
>
&
dst_vars
,
Callback
callback
)
{
Callback
callback
,
bool
is_backward
=
false
)
{
PADDLE_ENFORCE_EQ
(
src_vars
.
size
(),
dst_vars
.
size
());
PADDLE_ENFORCE_EQ
(
src_vars
.
size
(),
dst_vars
.
size
());
for
(
size_t
i
=
0
;
i
<
dst_vars
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
dst_vars
.
size
();
++
i
)
{
VLOG
(
10
)
<<
"Link "
<<
src_vars
[
i
]
<<
" to "
<<
dst_vars
[
i
];
VLOG
(
10
)
<<
"Link "
<<
src_vars
[
i
]
<<
" to "
<<
dst_vars
[
i
];
AccessTensor
(
src_scope
,
src_vars
[
i
],
dst_scope
,
dst_vars
[
i
],
callback
);
AccessTensor
(
src_scope
,
src_vars
[
i
],
dst_scope
,
dst_vars
[
i
],
callback
,
is_backward
);
}
}
}
}
...
@@ -173,11 +175,13 @@ class RecurrentBase : public framework::OperatorBase {
...
@@ -173,11 +175,13 @@ class RecurrentBase : public framework::OperatorBase {
const
std
::
vector
<
std
::
string
>
&
src_vars
,
const
std
::
vector
<
std
::
string
>
&
src_vars
,
const
framework
::
Scope
&
dst_scope
,
const
framework
::
Scope
&
dst_scope
,
const
std
::
vector
<
std
::
string
>
&
dst_vars
,
const
std
::
vector
<
std
::
string
>
&
dst_vars
,
Callback
callback
)
{
Callback
callback
,
bool
is_backward
=
false
)
{
PADDLE_ENFORCE_EQ
(
src_vars
.
size
(),
dst_vars
.
size
());
PADDLE_ENFORCE_EQ
(
src_vars
.
size
(),
dst_vars
.
size
());
for
(
size_t
i
=
0
;
i
<
dst_vars
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
dst_vars
.
size
();
++
i
)
{
VLOG
(
10
)
<<
"Link "
<<
src_vars
[
i
]
<<
" to "
<<
dst_vars
[
i
];
VLOG
(
10
)
<<
"Link "
<<
src_vars
[
i
]
<<
" to "
<<
dst_vars
[
i
];
AccessTensor
(
src_scope
,
src_vars
[
i
],
dst_scope
,
dst_vars
[
i
],
callback
);
AccessTensor
(
src_scope
,
src_vars
[
i
],
dst_scope
,
dst_vars
[
i
],
callback
,
is_backward
);
}
}
}
}
...
@@ -194,9 +198,13 @@ class RecurrentBase : public framework::OperatorBase {
...
@@ -194,9 +198,13 @@ class RecurrentBase : public framework::OperatorBase {
static
void
AccessTensor
(
const
framework
::
Scope
&
src_scope
,
static
void
AccessTensor
(
const
framework
::
Scope
&
src_scope
,
const
std
::
string
&
src_var_name
,
const
std
::
string
&
src_var_name
,
framework
::
Scope
*
dst_scope
,
framework
::
Scope
*
dst_scope
,
const
std
::
string
&
dst_var_name
,
Callback
callback
)
{
const
std
::
string
&
dst_var_name
,
Callback
callback
,
bool
is_backward
=
false
)
{
auto
*
src_var
=
src_scope
.
FindVar
(
src_var_name
);
auto
*
src_var
=
src_scope
.
FindVar
(
src_var_name
);
PADDLE_ENFORCE
(
src_var
!=
nullptr
);
if
(
is_backward
&&
src_var
==
nullptr
)
{
return
;
}
PADDLE_ENFORCE
(
src_var
!=
nullptr
,
"%s is not found."
,
src_var_name
);
auto
&
src_tensor
=
src_var
->
Get
<
framework
::
LoDTensor
>
();
auto
&
src_tensor
=
src_var
->
Get
<
framework
::
LoDTensor
>
();
auto
*
dst_var
=
dst_scope
->
Var
(
dst_var_name
);
auto
*
dst_var
=
dst_scope
->
Var
(
dst_var_name
);
...
@@ -208,12 +216,16 @@ class RecurrentBase : public framework::OperatorBase {
...
@@ -208,12 +216,16 @@ class RecurrentBase : public framework::OperatorBase {
static
void
AccessTensor
(
const
framework
::
Scope
&
src_scope
,
static
void
AccessTensor
(
const
framework
::
Scope
&
src_scope
,
const
std
::
string
&
src_var_name
,
const
std
::
string
&
src_var_name
,
const
framework
::
Scope
&
dst_scope
,
const
framework
::
Scope
&
dst_scope
,
const
std
::
string
&
dst_var_name
,
Callback
callback
)
{
const
std
::
string
&
dst_var_name
,
Callback
callback
,
bool
is_backward
=
false
)
{
auto
*
dst_var
=
dst_scope
.
FindVar
(
dst_var_name
);
if
(
is_backward
&&
dst_var
==
nullptr
)
{
return
;
}
auto
*
src_var
=
src_scope
.
FindVar
(
src_var_name
);
auto
*
src_var
=
src_scope
.
FindVar
(
src_var_name
);
PADDLE_ENFORCE
(
src_var
!=
nullptr
);
PADDLE_ENFORCE
(
src_var
!=
nullptr
,
"%s is not found."
,
src_var_name
);
auto
&
src_tensor
=
src_var
->
Get
<
framework
::
LoDTensor
>
();
auto
&
src_tensor
=
src_var
->
Get
<
framework
::
LoDTensor
>
();
auto
*
dst_var
=
dst_scope
.
FindVar
(
dst_var_name
);
PADDLE_ENFORCE
(
dst_var
!=
nullptr
,
"%s is not found."
,
dst_var_name
);
PADDLE_ENFORCE
(
dst_var
!=
nullptr
);
auto
*
dst_tensor
=
dst_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
dst_tensor
=
dst_var
->
GetMutable
<
framework
::
LoDTensor
>
();
callback
(
src_tensor
,
dst_tensor
);
callback
(
src_tensor
,
dst_tensor
);
}
}
...
@@ -345,7 +357,8 @@ class RecurrentGradOp : public RecurrentBase {
...
@@ -345,7 +357,8 @@ class RecurrentGradOp : public RecurrentBase {
auto
dims
=
framework
::
vectorize
(
inside
->
dims
());
auto
dims
=
framework
::
vectorize
(
inside
->
dims
());
dims
.
erase
(
dims
.
begin
());
dims
.
erase
(
dims
.
begin
());
inside
->
Resize
(
framework
::
make_ddim
(
dims
));
inside
->
Resize
(
framework
::
make_ddim
(
dims
));
});
},
true
/*is_backward*/
);
auto
og_set
=
List2Set
(
Inputs
(
kOutputGrads
));
auto
og_set
=
List2Set
(
Inputs
(
kOutputGrads
));
if
(
VLOG_IS_ON
(
10
))
{
if
(
VLOG_IS_ON
(
10
))
{
...
@@ -454,7 +467,8 @@ class RecurrentGradOp : public RecurrentBase {
...
@@ -454,7 +467,8 @@ class RecurrentGradOp : public RecurrentBase {
auto
dst
=
outside
->
Slice
(
seq_offset
,
seq_offset
+
1
);
auto
dst
=
outside
->
Slice
(
seq_offset
,
seq_offset
+
1
);
framework
::
TensorCopy
(
inside
,
place
,
dev_ctx
,
&
dst
);
framework
::
TensorCopy
(
inside
,
place
,
dev_ctx
,
&
dst
);
});
},
true
/*is_backward*/
);
VLOG
(
5
)
<<
"Link outside gradient finished "
;
VLOG
(
5
)
<<
"Link outside gradient finished "
;
if
(
step_id
+
1
==
seq_len
)
{
// at_end
if
(
step_id
+
1
==
seq_len
)
{
// at_end
...
@@ -467,7 +481,8 @@ class RecurrentGradOp : public RecurrentBase {
...
@@ -467,7 +481,8 @@ class RecurrentGradOp : public RecurrentBase {
outside
->
Resize
(
inside
.
dims
());
outside
->
Resize
(
inside
.
dims
());
outside
->
mutable_data
(
place
,
inside
.
type
());
outside
->
mutable_data
(
place
,
inside
.
type
());
framework
::
TensorCopy
(
inside
,
place
,
dev_ctx
,
outside
);
framework
::
TensorCopy
(
inside
,
place
,
dev_ctx
,
outside
);
});
},
true
/*is_backward*/
);
VLOG
(
5
)
<<
"Link initialize state gradient finished "
;
VLOG
(
5
)
<<
"Link initialize state gradient finished "
;
}
}
scopes
.
Next
();
scopes
.
Next
();
...
@@ -609,9 +624,10 @@ class RecurrentGradOpShapeInference : public framework::InferShapeBase {
...
@@ -609,9 +624,10 @@ class RecurrentGradOpShapeInference : public framework::InferShapeBase {
std
::
vector
<
std
::
string
>
output
{
kOutputs
};
std
::
vector
<
std
::
string
>
output
{
kOutputs
};
for
(
auto
&
s
:
input
)
{
for
(
auto
&
s
:
input
)
{
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
s
));
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
s
));
PADDLE_ENFORCE
(
ctx
->
HasOutputs
(
framework
::
GradVarName
(
s
)),
// NOTE(zcd): In some case, some of kInputs doesn't have gradient.
"Cannot find the gradient variable %s"
,
// PADDLE_ENFORCE(ctx->HasOutputs(framework::GradVarName(s)),
framework
::
GradVarName
(
s
));
// "Cannot find the gradient variable %s",
// framework::GradVarName(s));
}
}
for
(
auto
&
s
:
output
)
{
for
(
auto
&
s
:
output
)
{
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
s
));
PADDLE_ENFORCE
(
ctx
->
HasInputs
(
s
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录