Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
03dc7b79
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看板
未验证
提交
03dc7b79
编写于
9月 17, 2018
作者:
T
Tao Luo
提交者:
GitHub
9月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12966 from jerrywgz/fix_rnn_memory_helper
Add error info & remove data sharing between input and output in rnn_…
上级
437debf4
6033c1a2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
11 addition
and
6 deletion
+11
-6
paddle/fluid/operators/rnn_memory_helper_op.cc
paddle/fluid/operators/rnn_memory_helper_op.cc
+11
-6
未找到文件。
paddle/fluid/operators/rnn_memory_helper_op.cc
浏览文件 @
03dc7b79
...
@@ -42,7 +42,7 @@ class RNNMemoryHelperOp : public framework::OperatorBase {
...
@@ -42,7 +42,7 @@ class RNNMemoryHelperOp : public framework::OperatorBase {
auto
*
out_tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
out_tensor
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
&
mem_tensor
=
mem_var
->
Get
<
framework
::
LoDTensor
>
();
auto
&
mem_tensor
=
mem_var
->
Get
<
framework
::
LoDTensor
>
();
out_tensor
->
ShareDataWith
(
mem
_tensor
);
framework
::
TensorCopySync
(
mem_tensor
,
dev_place
,
out
_tensor
);
out_tensor
->
set_lod
(
mem_tensor
.
lod
());
out_tensor
->
set_lod
(
mem_tensor
.
lod
());
}
}
};
};
...
@@ -50,8 +50,10 @@ class RNNMemoryHelperOp : public framework::OperatorBase {
...
@@ -50,8 +50,10 @@ class RNNMemoryHelperOp : public framework::OperatorBase {
class
RNNMemoryHelperOpShapeInference
:
public
framework
::
InferShapeBase
{
class
RNNMemoryHelperOpShapeInference
:
public
framework
::
InferShapeBase
{
public:
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
""
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
""
);
"Input(X) of rnn_memory_helper op should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output of rnn_memory_helper op should not be null."
);
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
}
...
@@ -107,7 +109,7 @@ class RNNMemoryHelperGradOp : public framework::OperatorBase {
...
@@ -107,7 +109,7 @@ class RNNMemoryHelperGradOp : public framework::OperatorBase {
}
else
{
}
else
{
auto
&
out_grad_tensor
=
out_grad_var
->
Get
<
framework
::
LoDTensor
>
();
auto
&
out_grad_tensor
=
out_grad_var
->
Get
<
framework
::
LoDTensor
>
();
auto
*
in_grad_tensor
=
in_grad_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
in_grad_tensor
=
in_grad_var
->
GetMutable
<
framework
::
LoDTensor
>
();
in_grad_tensor
->
ShareDataWith
(
out
_grad_tensor
);
framework
::
TensorCopySync
(
out_grad_tensor
,
dev_place
,
in
_grad_tensor
);
in_grad_tensor
->
set_lod
(
out_grad_tensor
.
lod
());
in_grad_tensor
->
set_lod
(
out_grad_tensor
.
lod
());
}
}
}
}
...
@@ -133,8 +135,11 @@ class RNNMemoryHelperGradOpShapeInference : public framework::InferShapeBase {
...
@@ -133,8 +135,11 @@ class RNNMemoryHelperGradOpShapeInference : public framework::InferShapeBase {
public:
public:
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
operator
()(
framework
::
InferShapeContext
*
ctx
)
const
override
{
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
x_grad_name
),
""
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
x_grad_name
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
""
);
"Gradient of Input(X) in rnn_memory_helper_grad of should "
"not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"Input(X) of rnn_memory_helper_grad of should not be null."
);
ctx
->
SetOutputDim
(
x_grad_name
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
SetOutputDim
(
x_grad_name
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
x_grad_name
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
x_grad_name
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录